1 /* -*- C++ -*- |
|
2 * src/hugo/map_defines.h - Part of HUGOlib, a generic C++ optimization library |
|
3 * |
|
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
5 * (Egervary Combinatorial Optimization Research Group, EGRES). |
|
6 * |
|
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. |
|
10 * |
|
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 |
|
13 * purpose. |
|
14 * |
|
15 */ |
|
16 |
|
17 #ifndef HUGO_MAP_DEFINES_H |
|
18 #define HUGO_MAP_DEFINES_H |
|
19 |
|
20 ///\ingroup graphmaps |
|
21 ///\file |
|
22 ///\brief Defines to help creating graph maps. |
|
23 |
|
24 /// \addtogroup graphmapfactory |
|
25 /// @{ |
|
26 |
|
27 /** Creates the EdgeMapRegistry type an declare a mutable instance |
|
28 * named edge_maps. |
|
29 */ |
|
30 #define CREATE_EDGE_MAP_REGISTRY \ |
|
31 typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \ |
|
32 mutable EdgeMapRegistry edge_maps; |
|
33 |
|
34 /** Creates the NodeMapRegistry type an declare a mutable instance |
|
35 * named node_maps. |
|
36 */ |
|
37 #define CREATE_NODE_MAP_REGISTRY \ |
|
38 typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \ |
|
39 mutable NodeMapRegistry node_maps; |
|
40 |
|
41 /** Creates both map registries. |
|
42 */ |
|
43 #define CREATE_MAP_REGISTRIES \ |
|
44 CREATE_NODE_MAP_REGISTRY \ |
|
45 CREATE_EDGE_MAP_REGISTRY |
|
46 |
|
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. |
|
52 */ |
|
53 #define CREATE_NODE_MAP(DynMap) \ |
|
54 template <typename Value> \ |
|
55 class NodeMap : public DynMap<NodeMapRegistry, Value> { \ |
|
56 public: \ |
|
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));\ |
|
68 return *this; \ |
|
69 } \ |
|
70 template <typename TT> \ |
|
71 NodeMap& operator=(const NodeMap<TT>& copy) { \ |
|
72 Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\ |
|
73 return *this; \ |
|
74 } \ |
|
75 }; |
|
76 |
|
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. |
|
82 */ |
|
83 #define CREATE_EDGE_MAP(DynMap) \ |
|
84 template <typename Value> \ |
|
85 class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \ |
|
86 public: \ |
|
87 typedef DynMap<EdgeMapRegistry, Value> Parent; \ |
|
88 \ |
|
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));\ |
|
99 return *this; \ |
|
100 } \ |
|
101 template <typename TT> \ |
|
102 EdgeMap& operator=(const EdgeMap<TT>& copy) { \ |
|
103 Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\ |
|
104 return *this; \ |
|
105 } \ |
|
106 }; |
|
107 |
|
108 /** This macro creates both maps. |
|
109 */ |
|
110 #define CREATE_MAPS(DynMap) \ |
|
111 CREATE_NODE_MAP(DynMap) \ |
|
112 CREATE_EDGE_MAP(DynMap) |
|
113 |
|
114 /** This macro creates MapRegistry for Symmetric Edge Maps. |
|
115 */ |
|
116 #define CREATE_SYM_EDGE_MAP_REGISTRY \ |
|
117 typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \ |
|
118 typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \ |
|
119 mutable SymEdgeMapRegistry sym_edge_maps; |
|
120 |
|
121 |
|
122 /** Creates a map from a template map. The import method is |
|
123 * an overloading of the map type. |
|
124 * The reason to use these macro is that the c++ does not support |
|
125 * the template typedefs. If a future release of the c++ |
|
126 * supports this feature it should be fixed. |
|
127 */ |
|
128 #define CREATE_SYM_EDGE_MAP(DynMap) \ |
|
129 template <typename Value> \ |
|
130 class SymEdgeMap : public SymMap<DynMap, SymEdgeMapRegistry, Value> { \ |
|
131 public: \ |
|
132 typedef SymMap<DynMap, SymEdgeMapRegistry, Value> Parent; \ |
|
133 \ |
|
134 SymEdgeMap(const typename Parent::Graph& g) \ |
|
135 : Parent(g, g.sym_edge_maps) {} \ |
|
136 SymEdgeMap(const typename Parent::Graph& g, const Value& v) \ |
|
137 : Parent(g, g.sym_edge_maps, v) {} \ |
|
138 SymEdgeMap(const SymEdgeMap& copy) \ |
|
139 : Parent(static_cast<const Parent&>(copy)) {} \ |
|
140 template <typename TT> \ |
|
141 SymEdgeMap(const NodeMap<TT>& copy) \ |
|
142 : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \ |
|
143 SymEdgeMap& operator=(const SymEdgeMap& copy) { \ |
|
144 Parent::operator=(static_cast<const Parent&>(copy));\ |
|
145 return *this; \ |
|
146 } \ |
|
147 template <typename TT> \ |
|
148 SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \ |
|
149 Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\ |
|
150 return *this; \ |
|
151 } \ |
|
152 }; |
|
153 |
|
154 /** This is a macro to import an node map into a graph class. |
|
155 */ |
|
156 #define IMPORT_NODE_MAP(From, from, To, to) \ |
|
157 template <typename Value> \ |
|
158 class NodeMap : public From::template NodeMap<Value> { \ |
|
159 \ |
|
160 public: \ |
|
161 typedef typename From::template NodeMap<Value> Parent; \ |
|
162 \ |
|
163 NodeMap(const To& to) \ |
|
164 : Parent(static_cast<const From&>(from)) { } \ |
|
165 NodeMap(const To& to, const Value& value) \ |
|
166 : Parent(static_cast<const From&>(from), value) { } \ |
|
167 NodeMap(const NodeMap& copy) \ |
|
168 : Parent(static_cast<const Parent&>(copy)) {} \ |
|
169 template <typename TT> \ |
|
170 NodeMap(const NodeMap<TT>& copy) \ |
|
171 : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \ |
|
172 NodeMap& operator=(const NodeMap& copy) { \ |
|
173 Parent::operator=(static_cast<const Parent&>(copy)); \ |
|
174 return *this; \ |
|
175 } \ |
|
176 template <typename TT> \ |
|
177 NodeMap& operator=(const NodeMap<TT>& copy) { \ |
|
178 Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\ |
|
179 return *this; \ |
|
180 } \ |
|
181 }; |
|
182 |
|
183 /** This is a macro to import an edge map into a graph class. |
|
184 */ |
|
185 #define IMPORT_EDGE_MAP(From, from, To, to) \ |
|
186 template <typename Value> \ |
|
187 class EdgeMap : public From::template EdgeMap<Value> { \ |
|
188 \ |
|
189 public: \ |
|
190 typedef typename From::template EdgeMap<Value> Parent; \ |
|
191 \ |
|
192 EdgeMap(const To& to) \ |
|
193 : Parent(static_cast<const From&>(from)) { } \ |
|
194 EdgeMap(const To& to, const Value& value) \ |
|
195 : Parent(static_cast<const From&>(from), value) { } \ |
|
196 EdgeMap(const EdgeMap& copy) \ |
|
197 : Parent(static_cast<const Parent&>(copy)) {} \ |
|
198 template <typename TT> \ |
|
199 EdgeMap(const EdgeMap<TT>& copy) \ |
|
200 : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \ |
|
201 EdgeMap& operator=(const EdgeMap& copy) { \ |
|
202 Parent::operator=(static_cast<const Parent&>(copy)); \ |
|
203 return *this; \ |
|
204 } \ |
|
205 template <typename TT> \ |
|
206 EdgeMap& operator=(const EdgeMap<TT>& copy) { \ |
|
207 Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\ |
|
208 return *this; \ |
|
209 } \ |
|
210 }; |
|
211 |
|
212 #define KEEP_EDGE_MAP(From, To) \ |
|
213 IMPORT_EDGE_MAP(From, graph, To, graph) |
|
214 |
|
215 |
|
216 #define KEEP_NODE_MAP(From, To) \ |
|
217 IMPORT_NODE_MAP(From, graph, To, graph) |
|
218 |
|
219 /** This is a macro to keep the node and edge maps for a graph class. |
|
220 */ |
|
221 #define KEEP_MAPS(From, To) \ |
|
222 KEEP_EDGE_MAP(From, To) \ |
|
223 KEEP_NODE_MAP(From, To) |
|
224 |
|
225 |
|
226 /// @} |
|
227 |
|
228 #endif |
|