COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/map_defines.h @ 858:acc83957ee4a

Last change on this file since 858:acc83957ee4a was 844:9bf990cb066d, checked in by Balazs Dezso, 20 years ago

Bug fix in the symmetric maps.
Faster map initialization.
Iterators and Containers STL compatible.

File size: 6.3 KB
Line 
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 \
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
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) \
39template <typename Value> \
40class NodeMap : public DynMap<NodeMapRegistry, Value> { \
41typedef DynMap<NodeMapRegistry, Value> MapImpl; \
42public: \
43NodeMap() {} \
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) {} \
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
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) \
67template <typename Value> \
68class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \
69typedef DynMap<EdgeMapRegistry, Value> MapImpl; \
70public: \
71EdgeMap() {} \
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) {} \
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
88/** This macro creates both maps.
89 */
90#define CREATE_MAPS(DynMap) \
91CREATE_NODE_MAP(DynMap) \
92CREATE_EDGE_MAP(DynMap)
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 SymEdgeMapRegistry 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) \
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  } \
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) \
141template <typename Value> \
142class 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) \
176template <typename Value> \
177class 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) \
212IMPORT_EDGE_MAP(From, graph, To, graph) \
213IMPORT_NODE_MAP(From, graph, To, graph)
214 
215/// @}
216 
217#endif
Note: See TracBrowser for help on using the repository browser.