Initial revision.
2 * src/hugo/map_defines.h - Part of HUGOlib, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef HUGO_MAP_DEFINES_H
18 #define HUGO_MAP_DEFINES_H
22 ///\brief Defines to help creating graph maps.
24 /// \addtogroup graphmapfactory
27 /** Creates the EdgeMapRegistry type an declare a mutable instance
30 #define CREATE_EDGE_MAP_REGISTRY \
31 typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \
32 mutable EdgeMapRegistry edge_maps;
34 /** Creates the NodeMapRegistry type an declare a mutable instance
37 #define CREATE_NODE_MAP_REGISTRY \
38 typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \
39 mutable NodeMapRegistry node_maps;
41 /** Creates both map registries.
43 #define CREATE_MAP_REGISTRIES \
44 CREATE_NODE_MAP_REGISTRY \
45 CREATE_EDGE_MAP_REGISTRY
47 /** Creates a map from a template map. The import method is
48 * an overloading of the map type.
49 * The reason to use these macro is that the c++ does not support
50 * the template typedefs. If a future release of the c++
51 * supports this feature it should be fixed.
53 #define CREATE_NODE_MAP(DynMap) \
54 template <typename Value> \
55 class NodeMap : public DynMap<NodeMapRegistry, Value> { \
57 typedef DynMap<NodeMapRegistry, Value> Parent; \
58 NodeMap(const typename Parent::Graph& g) \
59 : Parent(g, g.node_maps) {} \
60 NodeMap(const typename Parent::Graph& g, const Value& v) \
61 : Parent(g, g.node_maps, v) {} \
62 NodeMap(const NodeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
63 template <typename TT> \
64 NodeMap(const NodeMap<TT>& copy) \
65 : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
66 NodeMap& operator=(const NodeMap& copy) { \
67 Parent::operator=(static_cast<const Parent&>(copy));\
70 template <typename TT> \
71 NodeMap& operator=(const NodeMap<TT>& copy) { \
72 Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
77 /** Creates a map from a template map. The import method is
78 * an overloading of the map type.
79 * The reason to use these macro is that the c++ does not support
80 * the template typedefs. If a future release of the c++
81 * supports this feature it should be fixed.
83 #define CREATE_EDGE_MAP(DynMap) \
84 template <typename Value> \
85 class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \
87 typedef DynMap<EdgeMapRegistry, Value> Parent; \
89 EdgeMap(const typename Parent::Graph& g) \
90 : Parent(g, g.edge_maps) {} \
91 EdgeMap(const typename Parent::Graph& g, const Value& v) \
92 : Parent(g, g.edge_maps, v) {} \
93 EdgeMap(const EdgeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
94 template <typename TT> \
95 EdgeMap(const EdgeMap<TT>& copy) \
96 : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
97 EdgeMap& operator=(const EdgeMap& copy) { \
98 Parent::operator=(static_cast<const Parent&>(copy));\
101 template <typename TT> \
102 EdgeMap& operator=(const EdgeMap<TT>& copy) { \
103 Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
108 /** This macro creates both maps.
110 #define CREATE_MAPS(DynMap) \
111 CREATE_NODE_MAP(DynMap) \
112 CREATE_EDGE_MAP(DynMap)
114 /** This macro creates MapRegistry for Symmetric Edge Maps.
116 #define CREATE_SYM_EDGE_MAP_REGISTRY \
117 typedef MapRegistry<Graph, SymEdge, SymEdgeIt> SymEdgeMapRegistry; \
118 mutable SymEdgeMapRegistry sym_edge_maps;
121 /** Creates a map from a template map. The import method is
122 * an overloading of the map type.
123 * The reason to use these macro is that the c++ does not support
124 * the template typedefs. If a future release of the c++
125 * supports this feature it should be fixed.
127 #define CREATE_SYM_EDGE_MAP(DynMap) \
128 template <typename Value> \
129 class SymEdgeMap : public DynMap<SymEdgeMapRegistry, Value> { \
131 typedef DynMap<SymEdgeMapRegistry, Value> Parent; \
133 SymEdgeMap(const typename Parent::Graph& g) \
134 : Parent(g, g.sym_edge_maps) {} \
135 SymEdgeMap(const typename Parent::Graph& g, const Value& v) \
136 : Parent(g, g.sym_edge_maps, v) {} \
137 SymEdgeMap(const SymEdgeMap& copy) \
138 : Parent(static_cast<const Parent&>(copy)) {} \
139 template <typename TT> \
140 SymEdgeMap(const NodeMap<TT>& copy) \
141 : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \
142 SymEdgeMap& operator=(const SymEdgeMap& copy) { \
143 Parent::operator=(static_cast<const Parent&>(copy));\
146 template <typename TT> \
147 SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \
148 Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\
153 /** This is a macro to import an node map into a graph class.
155 #define IMPORT_NODE_MAP(From, from, To, to) \
156 template <typename Value> \
157 class NodeMap : public From::template NodeMap<Value> { \
160 typedef typename From::template NodeMap<Value> Parent; \
162 NodeMap(const To& to) \
163 : Parent(static_cast<const From&>(from)) { } \
164 NodeMap(const To& to, const Value& value) \
165 : Parent(static_cast<const From&>(from), value) { } \
166 NodeMap(const NodeMap& copy) \
167 : Parent(static_cast<const Parent&>(copy)) {} \
168 template <typename TT> \
169 NodeMap(const NodeMap<TT>& copy) \
170 : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
171 NodeMap& operator=(const NodeMap& copy) { \
172 Parent::operator=(static_cast<const Parent&>(copy)); \
175 template <typename TT> \
176 NodeMap& operator=(const NodeMap<TT>& copy) { \
177 Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
182 /** This is a macro to import an edge map into a graph class.
184 #define IMPORT_EDGE_MAP(From, from, To, to) \
185 template <typename Value> \
186 class EdgeMap : public From::template EdgeMap<Value> { \
189 typedef typename From::template EdgeMap<Value> Parent; \
191 EdgeMap(const To& to) \
192 : Parent(static_cast<const From&>(from)) { } \
193 EdgeMap(const To& to, const Value& value) \
194 : Parent(static_cast<const From&>(from), value) { } \
195 EdgeMap(const EdgeMap& copy) \
196 : Parent(static_cast<const Parent&>(copy)) {} \
197 template <typename TT> \
198 EdgeMap(const EdgeMap<TT>& copy) \
199 : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
200 EdgeMap& operator=(const EdgeMap& copy) { \
201 Parent::operator=(static_cast<const Parent&>(copy)); \
204 template <typename TT> \
205 EdgeMap& operator=(const EdgeMap<TT>& copy) { \
206 Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
211 #define KEEP_EDGE_MAP(From, To) \
212 IMPORT_EDGE_MAP(From, graph, To, graph)
215 #define KEEP_NODE_MAP(From, To) \
216 IMPORT_NODE_MAP(From, graph, To, graph)
218 /** This is a macro to keep the node and edge maps for a graph class.
220 #define KEEP_MAPS(From, To) \
221 KEEP_EDGE_MAP(From, To) \
222 KEEP_NODE_MAP(From, To)