COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/map_defines.h @ 843:d56fad02dc55

Last change on this file since 843:d56fad02dc55 was 822:88226d9fe821, checked in by Balazs Dezso, 20 years ago

The MapFactories? have been removed from the code because
if we use macros then they increases only the complexity.

The pair iterators of the maps are separeted from the maps.

Some macros and comments has been changed.

File size: 6.3 KB
RevLine 
[782]1// -*- c++ -*-
2#ifndef MAP_DEFINES_H
3#define MAP_DEFINES_H
4
[822]5///\ingroup graphmaps
[785]6///\file
7///\brief Defines to help creating graph maps.
8
9/// \addtogroup graphmapfactory
10/// @{
11
[782]12/** Creates the EdgeMapRegistry type an declare a mutable instance
13 *  named edge_maps.
14 */
15#define CREATE_EDGE_MAP_REGISTRY \
16typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \
17mutable 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 \
23typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \
24mutable NodeMapRegistry node_maps;
25
26/** Creates both map registries.
27 */
28#define CREATE_MAP_REGISTRIES \
29CREATE_NODE_MAP_REGISTRY \
30CREATE_EDGE_MAP_REGISTRY
31
[822]32/** Creates a map from a template map. The import method is
[782]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 */
[822]38#define CREATE_NODE_MAP(DynMap) \
39template <typename Value> \
40class NodeMap : public DynMap<NodeMapRegistry, Value> { \
41typedef DynMap<NodeMapRegistry, Value> MapImpl; \
[782]42public: \
43NodeMap() {} \
[822]44NodeMap(const typename MapImpl::Graph& g) \
45  : MapImpl(g, g.node_maps) {} \
46NodeMap(const typename MapImpl::Graph& g, const Value& v) \
47  : MapImpl(g, g.node_maps, v) {} \
[782]48NodeMap(const NodeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
49template <typename CMap> NodeMap(const CMap& copy) : MapImpl(copy) {} \
50NodeMap& operator=(const NodeMap& copy) { \
51  MapImpl::operator=(static_cast<const MapImpl&>(copy));\
52  return *this; \
53} \
54template <typename CMap> NodeMap& operator=(const CMap& copy) { \
55  MapImpl::operator=(copy);\
56  return *this; \
57} \
58};
59
[822]60/** Creates a map from a template map. The import method is
[782]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 */
[822]66#define CREATE_EDGE_MAP(DynMap) \
67template <typename Value> \
68class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \
69typedef DynMap<EdgeMapRegistry, Value> MapImpl; \
[782]70public: \
71EdgeMap() {} \
[822]72EdgeMap(const typename MapImpl::Graph& g) \
73  : MapImpl(g, g.edge_maps) {} \
74EdgeMap(const typename MapImpl::Graph& g, const Value& v) \
75  : MapImpl(g, g.edge_maps, v) {} \
[782]76EdgeMap(const EdgeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
77template <typename CMap> EdgeMap(const CMap& copy) : MapImpl(copy) {} \
78EdgeMap& operator=(const EdgeMap& copy) { \
79  MapImpl::operator=(static_cast<const MapImpl&>(copy));\
80  return *this; \
81} \
82template <typename CMap> EdgeMap& operator=(const CMap& copy) { \
83  MapImpl::operator=(copy);\
84  return *this; \
85} \
86};
87
[822]88/** This macro creates both maps.
[782]89 */
[822]90#define CREATE_MAPS(DynMap) \
91CREATE_NODE_MAP(DynMap) \
92CREATE_EDGE_MAP(DynMap)
[782]93
94/** This macro creates MapRegistry for Symmetric Edge Maps.
95 */
96#define CREATE_SYM_EDGE_MAP_REGISTRY \
97typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
98typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
99mutable EdgeMapRegistry sym_edge_maps;
100
101
[822]102/** Creates a map from a template map. The import method is
[782]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 */
[822]108#define CREATE_SYM_EDGE_MAP(DynMap) \
109template <typename Value> \
110class 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  } \
[782]135};
136
137
[822]138/** This is a macro to import an node map into a graph class.
139 */
140#define IMPORT_NODE_MAP(From, from, To, to) \
141template <typename Value> \
142class NodeMap \
143  : public From::template NodeMap<Value> { \
144  typedef typename From::template NodeMap<Value> MapImpl; \
145 public: \
146   NodeMap() : MapImpl() {} \
[782]147\
[822]148   NodeMap(const To& to) \
149     : MapImpl(static_cast<const From&>(from)) { } \
[782]150\
[822]151   NodeMap(const To& to, const Value& value) \
152     : MapImpl(static_cast<const From&>(from), value) { } \
[782]153\
[822]154   NodeMap(const NodeMap& copy) \
155     : MapImpl(static_cast<const MapImpl&>(copy)) {} \
[782]156\
[822]157   template<typename CMap> \
158   NodeMap(const CMap& copy) \
159     : MapImpl(copy) {} \
[782]160\
[822]161   NodeMap& operator=(const NodeMap& copy) { \
162     MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
163     return *this; \
164   } \
[782]165\
[822]166   template <typename CMap> \
167   NodeMap& operator=(const CMap& copy) { \
168     MapImpl::operator=(copy); \
169     return *this; \
170   } \
171};
[782]172
[822]173/** This is a macro to import an edge map into a graph class.
174 */
175#define IMPORT_EDGE_MAP(From, from, To, to) \
176template <typename Value> \
177class EdgeMap \
178  : public From::template EdgeMap<Value> { \
179  typedef typename From::template EdgeMap<Value> MapImpl; \
180 public: \
181   EdgeMap() : MapImpl() {} \
[782]182\
[822]183   EdgeMap(const To& to) \
184     : MapImpl(static_cast<const From&>(from)) { } \
[782]185\
[822]186   EdgeMap(const To& to, const Value& value) \
187     : MapImpl(static_cast<const From&>(from), value) { } \
[782]188\
[822]189   EdgeMap(const EdgeMap& copy) \
190     : MapImpl(static_cast<const MapImpl&>(copy)) {} \
[782]191\
[822]192   template<typename CMap> \
193   EdgeMap(const CMap& copy) \
194     : MapImpl(copy) {} \
[782]195\
[822]196   EdgeMap& operator=(const EdgeMap& copy) { \
197     MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
198     return *this; \
199   } \
[782]200\
[822]201   template <typename CMap> \
202   EdgeMap& operator=(const CMap& copy) { \
203     MapImpl::operator=(copy); \
204     return *this; \
205   } \
206};
[782]207
[822]208
209/** This is a macro to keep the node and edge maps for a graph class.
210 */
211#define KEEP_MAPS(From, To) \
212IMPORT_EDGE_MAP(From, graph, To, graph) \
213IMPORT_NODE_MAP(From, graph, To, graph)
[785]214 
215/// @}
216 
[782]217#endif
Note: See TracBrowser for help on using the repository browser.