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