src/hugo/map_defines.h
author marci
Mon, 13 Sep 2004 16:15:12 +0000
changeset 838 51dcd224455c
parent 785 a9b0863c2265
child 844 9bf990cb066d
permissions -rw-r--r--
(none)
     1 // -*- c++ -*-
     2 #ifndef MAP_DEFINES_H
     3 #define MAP_DEFINES_H
     4 
     5 ///\ingroup graphmaps
     6 ///\file
     7 ///\brief Defines to help creating graph maps.
     8 
     9 /// \addtogroup graphmapfactory
    10 /// @{
    11 
    12 /** Creates the EdgeMapRegistry type an declare a mutable instance 
    13  *  named edge_maps.
    14  */
    15 #define CREATE_EDGE_MAP_REGISTRY \
    16 typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \
    17 mutable EdgeMapRegistry edge_maps;
    18 
    19 /** Creates the NodeMapRegistry type an declare a mutable instance 
    20  *  named node_maps.
    21  */
    22 #define CREATE_NODE_MAP_REGISTRY \
    23 typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \
    24 mutable NodeMapRegistry node_maps;
    25 
    26 /** Creates both map registries.
    27  */
    28 #define CREATE_MAP_REGISTRIES \
    29 CREATE_NODE_MAP_REGISTRY \
    30 CREATE_EDGE_MAP_REGISTRY
    31 
    32 /** Creates a map from a template map. The import method is
    33  *  an overloading of the map type.
    34  *  The reason to use these macro is that the c++ does not support
    35  *  the template typedefs. If a future release of the c++ 
    36  *  supports this feature it should be fixed.
    37  */
    38 #define CREATE_NODE_MAP(DynMap) \
    39 template <typename Value> \
    40 class NodeMap : public DynMap<NodeMapRegistry, Value> { \
    41 typedef DynMap<NodeMapRegistry, Value> MapImpl; \
    42 public: \
    43 NodeMap() {} \
    44 NodeMap(const typename MapImpl::Graph& g) \
    45   : MapImpl(g, g.node_maps) {} \
    46 NodeMap(const typename MapImpl::Graph& g, const Value& v) \
    47   : MapImpl(g, g.node_maps, v) {} \
    48 NodeMap(const NodeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    49 template <typename CMap> NodeMap(const CMap& copy) : MapImpl(copy) {} \
    50 NodeMap& operator=(const NodeMap& copy) { \
    51   MapImpl::operator=(static_cast<const MapImpl&>(copy));\
    52   return *this; \
    53 } \
    54 template <typename CMap> NodeMap& operator=(const CMap& copy) { \
    55   MapImpl::operator=(copy);\
    56   return *this; \
    57 } \
    58 };
    59 
    60 /** Creates a map from a template map. The import method is
    61  *  an overloading of the map type.
    62  *  The reason to use these macro is that the c++ does not support
    63  *  the template typedefs. If a future release of the c++ 
    64  *  supports this feature it should be fixed.
    65  */
    66 #define CREATE_EDGE_MAP(DynMap) \
    67 template <typename Value> \
    68 class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \
    69 typedef DynMap<EdgeMapRegistry, Value> MapImpl; \
    70 public: \
    71 EdgeMap() {} \
    72 EdgeMap(const typename MapImpl::Graph& g) \
    73   : MapImpl(g, g.edge_maps) {} \
    74 EdgeMap(const typename MapImpl::Graph& g, const Value& v) \
    75   : MapImpl(g, g.edge_maps, v) {} \
    76 EdgeMap(const EdgeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    77 template <typename CMap> EdgeMap(const CMap& copy) : MapImpl(copy) {} \
    78 EdgeMap& operator=(const EdgeMap& copy) { \
    79   MapImpl::operator=(static_cast<const MapImpl&>(copy));\
    80   return *this; \
    81 } \
    82 template <typename CMap> EdgeMap& operator=(const CMap& copy) { \
    83   MapImpl::operator=(copy);\
    84   return *this; \
    85 } \
    86 };
    87 
    88 /** This macro creates both maps.
    89  */
    90 #define CREATE_MAPS(DynMap) \
    91 CREATE_NODE_MAP(DynMap) \
    92 CREATE_EDGE_MAP(DynMap)
    93 
    94 /** This macro creates MapRegistry for Symmetric Edge Maps.
    95  */
    96 #define CREATE_SYM_EDGE_MAP_REGISTRY \
    97 typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
    98 typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
    99 mutable EdgeMapRegistry sym_edge_maps;
   100 
   101 
   102 /** Creates a map from a template map. The import method is
   103  *  an overloading of the map type.
   104  *  The reason to use these macro is that the c++ does not support
   105  *  the template typedefs. If a future release of the c++ 
   106  *  supports this feature it should be fixed.
   107  */
   108 #define CREATE_SYM_EDGE_MAP(DynMap) \
   109 template <typename Value> \
   110 class SymEdgeMap : public SymMap<DynMap, SymEdgeMapRegistry, Value> { \
   111   typedef SymMap<DynMap, SymEdgeMapRegistry, Value> MapImpl; \
   112  public: \
   113 \
   114   SymEdgeMap() {} \
   115 \
   116   SymEdgeMap(const typename MapImpl::Graph& g) \
   117     : MapImpl(g, g.sym_edge_maps) {} \
   118 \
   119   SymEdgeMap(const typename MapImpl::Graph& g, const Value& v) \
   120     : MapImpl(g, g.sym_edge_maps, v) {} \
   121 \
   122   SymEdgeMap(const SymEdgeMap& copy) \
   123     : MapImpl(static_cast<const MapImpl&>(copy)) {} \
   124 \
   125   template <typename CMap> SymEdgeMap(const CMap& copy) : MapImpl(copy) {} \
   126   SymEdgeMap& operator=(const SymEdgeMap& copy) { \
   127     MapImpl::operator=(static_cast<const MapImpl&>(copy));\
   128     return *this; \
   129   } \
   130 \
   131   template <typename CMap> SymEdgeMap& operator=(const CMap& copy) { \
   132     MapImpl::operator=(copy);\
   133     return *this; \
   134   } \
   135 };
   136 
   137 
   138 /** This is a macro to import an node map into a graph class.
   139  */
   140 #define IMPORT_NODE_MAP(From, from, To, to) \
   141 template <typename Value> \
   142 class NodeMap \
   143   : public From::template NodeMap<Value> { \
   144   typedef typename From::template NodeMap<Value> MapImpl; \
   145  public: \
   146    NodeMap() : MapImpl() {} \
   147 \
   148    NodeMap(const To& to) \
   149      : MapImpl(static_cast<const From&>(from)) { } \
   150 \
   151    NodeMap(const To& to, const Value& value) \
   152      : MapImpl(static_cast<const From&>(from), value) { } \
   153 \
   154    NodeMap(const NodeMap& copy) \
   155      : MapImpl(static_cast<const MapImpl&>(copy)) {} \
   156 \
   157    template<typename CMap> \
   158    NodeMap(const CMap& copy) \
   159      : MapImpl(copy) {} \
   160 \
   161    NodeMap& operator=(const NodeMap& copy) { \
   162      MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
   163      return *this; \
   164    } \
   165 \
   166    template <typename CMap> \
   167    NodeMap& operator=(const CMap& copy) { \
   168      MapImpl::operator=(copy); \
   169      return *this; \
   170    } \
   171 };
   172 
   173 /** This is a macro to import an edge map into a graph class.
   174  */
   175 #define IMPORT_EDGE_MAP(From, from, To, to) \
   176 template <typename Value> \
   177 class EdgeMap \
   178   : public From::template EdgeMap<Value> { \
   179   typedef typename From::template EdgeMap<Value> MapImpl; \
   180  public: \
   181    EdgeMap() : MapImpl() {} \
   182 \
   183    EdgeMap(const To& to) \
   184      : MapImpl(static_cast<const From&>(from)) { } \
   185 \
   186    EdgeMap(const To& to, const Value& value) \
   187      : MapImpl(static_cast<const From&>(from), value) { } \
   188 \
   189    EdgeMap(const EdgeMap& copy) \
   190      : MapImpl(static_cast<const MapImpl&>(copy)) {} \
   191 \
   192    template<typename CMap> \
   193    EdgeMap(const CMap& copy) \
   194      : MapImpl(copy) {} \
   195 \
   196    EdgeMap& operator=(const EdgeMap& copy) { \
   197      MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
   198      return *this; \
   199    } \
   200 \
   201    template <typename CMap> \
   202    EdgeMap& operator=(const CMap& copy) { \
   203      MapImpl::operator=(copy); \
   204      return *this; \
   205    } \
   206 };
   207 
   208 
   209 /** This is a macro to keep the node and edge maps for a graph class.
   210  */
   211 #define KEEP_MAPS(From, To) \
   212 IMPORT_EDGE_MAP(From, graph, To, graph) \
   213 IMPORT_NODE_MAP(From, graph, To, graph)
   214   
   215 /// @}
   216   
   217 #endif