COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/map_defines.h @ 798:6d1abeb62dd3

Last change on this file since 798:6d1abeb62dd3 was 785:a9b0863c2265, checked in by Alpar Juttner, 20 years ago

Changes in doc. (New module name for array/vector maps added.)

File size: 6.8 KB
Line 
1// -*- c++ -*-
2#ifndef MAP_DEFINES_H
3#define MAP_DEFINES_H
4
5///\ingroup graphmapfactory
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 concrete factory type from a template map
33 *  factory to use as node map factory.
34 */
35#define CREATE_NODE_MAP_FACTORY(TemplateFactory) \
36typedef TemplateFactory<NodeMapRegistry> NodeMapFactory;
37
38/** Creates a concrete factory type from a template map
39 *  factory to use as edge map factory.
40 */
41#define CREATE_EDGE_MAP_FACTORY(TemplateFactory) \
42typedef TemplateFactory<EdgeMapRegistry> EdgeMapFactory;
43
44/** Creates both map factories.
45 */
46#define CREATE_MAP_FACTORIES(TemplateFactory) \
47CREATE_NODE_MAP_FACTORY(TemplateFactory) \
48CREATE_EDGE_MAP_FACTORY(TemplateFactory)
49
50/** Import a map from a concrete map factory. The import method is
51 *  an overloading of the map type.
52 *  The reason to use these macro is that the c++ does not support
53 *  the template typedefs. If a future release of the c++
54 *  supports this feature it should be fixed.
55 */
56#define IMPORT_NODE_MAP(Factory) \
57template <typename V> \
58class NodeMap : public Factory::template Map<V> { \
59typedef typename Factory::template Map<V> MapImpl; \
60public: \
61NodeMap() {} \
62NodeMap(const Graph& g) : MapImpl(g, g.node_maps) {} \
63NodeMap(const Graph& g, const V& v) : MapImpl(g, g.node_maps, v) {} \
64NodeMap(const NodeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
65template <typename CMap> NodeMap(const CMap& copy) : MapImpl(copy) {} \
66NodeMap& operator=(const NodeMap& copy) { \
67  MapImpl::operator=(static_cast<const MapImpl&>(copy));\
68  return *this; \
69} \
70template <typename CMap> NodeMap& operator=(const CMap& copy) { \
71  MapImpl::operator=(copy);\
72  return *this; \
73} \
74};
75
76/** Import a map from a concrete map factory. The import method is
77 *  an overloading of the map type.
78 *  The reason to use these macro is that the c++ does not support
79 *  the template typedefs. If a future release of the c++
80 *  supports this feature it should be fixed.
81 */
82#define IMPORT_EDGE_MAP(Factory) \
83template <typename V> \
84class EdgeMap : public Factory::template Map<V> { \
85typedef typename Factory::template Map<V> MapImpl; \
86public: \
87EdgeMap() {} \
88EdgeMap(const Graph& g) : MapImpl(g, g.edge_maps) {} \
89EdgeMap(const Graph& g, const V& v) : MapImpl(g, g.edge_maps, v) {} \
90EdgeMap(const EdgeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
91template <typename CMap> EdgeMap(const CMap& copy) : MapImpl(copy) {} \
92EdgeMap& operator=(const EdgeMap& copy) { \
93  MapImpl::operator=(static_cast<const MapImpl&>(copy));\
94  return *this; \
95} \
96template <typename CMap> EdgeMap& operator=(const CMap& copy) { \
97  MapImpl::operator=(copy);\
98  return *this; \
99} \
100};
101
102/** This macro creates both map factories and imports both maps.
103 */
104#define CREATE_MAPS(TemplateFactory) \
105CREATE_MAP_FACTORIES(TemplateFactory) \
106IMPORT_NODE_MAP(NodeMapFactory) \
107IMPORT_EDGE_MAP(EdgeMapFactory)
108
109/** This macro creates MapRegistry for Symmetric Edge Maps.
110 */
111#define CREATE_SYM_EDGE_MAP_REGISTRY \
112typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
113typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
114mutable EdgeMapRegistry sym_edge_maps;
115
116/** Creates a concrete factory type from a template map
117 *  factory to use as edge map factory.
118 */
119#define CREATE_SYM_EDGE_MAP_FACTORY(TemplateFactory) \
120typedef SymMapFactory<SymEdgeMapRegistry, TemplateFactory > \
121SymEdgeMapFactory;
122
123/** Import a map from a concrete map factory. The import method is
124 *  an overloading of the map type.
125 *  The reason to use these macro is that the c++ does not support
126 *  the template typedefs. If a future release of the c++
127 *  supports this feature it should be fixed.
128 */
129#define IMPORT_SYM_EDGE_MAP(Factory) \
130template <typename V> \
131class SymEdgeMap : public Factory::template Map<V> { \
132typedef typename Factory::template Map<V> MapImpl; \
133public: \
134SymEdgeMap() {} \
135SymEdgeMap(const Graph& g) : MapImpl(g, g.sym_edge_maps) {} \
136SymEdgeMap(const Graph& g, const V& v) : MapImpl(g, g.sym_edge_maps, v) {} \
137SymEdgeMap(const SymEdgeMap& copy) \
138  : MapImpl(static_cast<const MapImpl&>(copy)) {} \
139template <typename CMap> SymEdgeMap(const CMap& copy) : MapImpl(copy) {} \
140SymEdgeMap& operator=(const SymEdgeMap& copy) { \
141  MapImpl::operator=(static_cast<const MapImpl&>(copy));\
142  return *this; \
143} \
144template <typename CMap> SymEdgeMap& operator=(const CMap& copy) { \
145  MapImpl::operator=(copy);\
146  return *this; \
147} \
148};
149
150
151#define KEEP_NODE_MAP(GraphBase) \
152    template <typename V> class NodeMap \
153      : public GraphBase::template NodeMap<V> \
154    { \
155      typedef typename GraphBase::template NodeMap<V> MapImpl; \
156      typedef V Value; \
157    public: \
158      NodeMap() : MapImpl() {} \
159\
160      NodeMap(const Graph& graph) \
161        : MapImpl(static_cast<const GraphBase&>(graph)) { } \
162\
163      NodeMap(const Graph& graph, const Value& value) \
164        : MapImpl(static_cast<const GraphBase&>(graph), value) { } \
165\
166      NodeMap(const NodeMap& copy) \
167        : MapImpl(static_cast<const MapImpl&>(copy)) {} \
168\
169      template<typename CMap> \
170      NodeMap(const CMap& copy) \
171        : MapImpl(copy) {} \
172\
173      NodeMap& operator=(const NodeMap& copy) { \
174        MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
175        return *this; \
176      } \
177\
178      template <typename CMap> \
179      NodeMap& operator=(const CMap& copy) { \
180        MapImpl::operator=(copy); \
181        return *this; \
182      } \
183    };
184
185#define KEEP_EDGE_MAP(GraphBase) \
186    template <typename V> class EdgeMap \
187      : public GraphBase::template EdgeMap<V> \
188    { \
189      typedef typename GraphBase::template EdgeMap<V> MapImpl; \
190      typedef V Value; \
191    public: \
192      EdgeMap() : MapImpl() {} \
193\
194      EdgeMap(const Graph& graph) \
195        : MapImpl(static_cast<const GraphBase&>(graph)) { } \
196\
197      EdgeMap(const Graph& graph, const Value& value) \
198        : MapImpl(static_cast<const GraphBase&>(graph), value) { } \
199\
200      EdgeMap(const EdgeMap& copy) \
201        : MapImpl(static_cast<const MapImpl&>(copy)) {} \
202\
203      template<typename CMap> \
204      EdgeMap(const CMap& copy) \
205        : MapImpl(copy) {} \
206\
207      EdgeMap& operator=(const EdgeMap& copy) { \
208        MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
209        return *this; \
210      } \
211\
212      template <typename CMap> \
213      EdgeMap& operator=(const CMap& copy) { \
214        MapImpl::operator=(copy); \
215        return *this; \
216      } \
217    };
218
219 
220/// @}
221 
222#endif
Note: See TracBrowser for help on using the repository browser.