COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/lemon/map_defines.h @ 1020:f42cb3146ed4

Last change on this file since 1020:f42cb3146ed4 was 987:87f7c54892df, checked in by Alpar Juttner, 16 years ago

Naming changes:

File size: 7.2 KB
Line 
1/* -*- C++ -*-
2 * src/lemon/map_defines.h - Part of LEMON, 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 LEMON_MAP_DEFINES_H
18#define LEMON_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 \
31typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \
32mutable 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 \
38typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \
39mutable NodeMapRegistry node_maps;
40
41/** Creates both map registries.
42 */
43#define CREATE_MAP_REGISTRIES \
44CREATE_NODE_MAP_REGISTRY \
45CREATE_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) \
54template <typename _Value> \
55class NodeMap : public DynMap<NodeMapRegistry, _Value> { \
56public: \
57typedef DynMap<NodeMapRegistry, _Value> Parent; \
58NodeMap(const typename Parent::Graph& g) \
59  : Parent(g, g.node_maps) {} \
60NodeMap(const typename Parent::Graph& g, const _Value& v) \
61  : Parent(g, g.node_maps, v) {} \
62NodeMap(const NodeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
63template <typename TT> \
64NodeMap(const NodeMap<TT>& copy) \
65  : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
66NodeMap& operator=(const NodeMap& copy) { \
67  Parent::operator=(static_cast<const Parent&>(copy));\
68  return *this; \
69} \
70template <typename TT> \
71NodeMap& 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) \
84template <typename _Value> \
85class EdgeMap : public DynMap<EdgeMapRegistry, _Value> { \
86public: \
87typedef DynMap<EdgeMapRegistry, _Value> Parent; \
88\
89EdgeMap(const typename Parent::Graph& g) \
90  : Parent(g, g.edge_maps) {} \
91EdgeMap(const typename Parent::Graph& g, const _Value& v) \
92  : Parent(g, g.edge_maps, v) {} \
93EdgeMap(const EdgeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
94template <typename TT> \
95EdgeMap(const EdgeMap<TT>& copy) \
96  : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
97EdgeMap& operator=(const EdgeMap& copy) { \
98  Parent::operator=(static_cast<const Parent&>(copy));\
99  return *this; \
100} \
101template <typename TT> \
102EdgeMap& 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) \
111CREATE_NODE_MAP(DynMap) \
112CREATE_EDGE_MAP(DynMap)
113
114/** This macro creates MapRegistry for Symmetric Edge Maps.
115 */
116#define CREATE_SYM_EDGE_MAP_REGISTRY \
117typedef MapRegistry<Graph, SymEdge, SymEdgeIt> SymEdgeMapRegistry; \
118mutable SymEdgeMapRegistry sym_edge_maps;
119
120
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.
126 */
127#define CREATE_SYM_EDGE_MAP(DynMap) \
128template <typename _Value> \
129class SymEdgeMap : public DynMap<SymEdgeMapRegistry, _Value> { \
130public: \
131typedef DynMap<SymEdgeMapRegistry, _Value> Parent; \
132\
133SymEdgeMap(const typename Parent::Graph& g) \
134  : Parent(g, g.sym_edge_maps) {} \
135SymEdgeMap(const typename Parent::Graph& g, const _Value& v) \
136  : Parent(g, g.sym_edge_maps, v) {} \
137SymEdgeMap(const SymEdgeMap& copy) \
138  : Parent(static_cast<const Parent&>(copy)) {} \
139template <typename TT> \
140SymEdgeMap(const NodeMap<TT>& copy) \
141  : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \
142SymEdgeMap& operator=(const SymEdgeMap& copy) { \
143  Parent::operator=(static_cast<const Parent&>(copy));\
144  return *this; \
145} \
146template <typename TT> \
147SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \
148  Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\
149  return *this; \
150} \
151};
152
153/** This is a macro to import an node map into a graph class.
154 */
155#define IMPORT_NODE_MAP(From, from, To, to) \
156template <typename _Value> \
157class NodeMap : public From::template NodeMap<_Value> { \
158\
159public: \
160typedef typename From::template NodeMap<_Value> Parent; \
161\
162NodeMap(const To& to) \
163  : Parent(static_cast<const From&>(from)) { } \
164NodeMap(const To& to, const _Value& value) \
165  : Parent(static_cast<const From&>(from), value) { } \
166NodeMap(const NodeMap& copy) \
167  : Parent(static_cast<const Parent&>(copy)) {} \
168template <typename TT> \
169NodeMap(const NodeMap<TT>& copy) \
170  : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
171NodeMap& operator=(const NodeMap& copy) { \
172  Parent::operator=(static_cast<const Parent&>(copy)); \
173  return *this; \
174} \
175template <typename TT> \
176NodeMap& operator=(const NodeMap<TT>& copy) { \
177  Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
178  return *this; \
179} \
180};
181
182/** This is a macro to import an edge map into a graph class.
183 */
184#define IMPORT_EDGE_MAP(From, from, To, to) \
185template <typename _Value> \
186class EdgeMap : public From::template EdgeMap<_Value> { \
187\
188public: \
189typedef typename From::template EdgeMap<_Value> Parent; \
190\
191EdgeMap(const To& to) \
192  : Parent(static_cast<const From&>(from)) { } \
193EdgeMap(const To& to, const _Value& value) \
194  : Parent(static_cast<const From&>(from), value) { } \
195EdgeMap(const EdgeMap& copy) \
196  : Parent(static_cast<const Parent&>(copy)) {} \
197template <typename TT> \
198EdgeMap(const EdgeMap<TT>& copy) \
199  : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
200EdgeMap& operator=(const EdgeMap& copy) { \
201  Parent::operator=(static_cast<const Parent&>(copy)); \
202  return *this; \
203} \
204template <typename TT> \
205EdgeMap& operator=(const EdgeMap<TT>& copy) { \
206  Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
207  return *this; \
208} \
209};
210
211#define KEEP_EDGE_MAP(From, To) \
212IMPORT_EDGE_MAP(From, graph, To, graph)
213
214
215#define KEEP_NODE_MAP(From, To) \
216IMPORT_NODE_MAP(From, graph, To, graph)
217
218/** This is a macro to keep the node and edge maps for a graph class.
219 */
220#define KEEP_MAPS(From, To) \
221KEEP_EDGE_MAP(From, To) \
222KEEP_NODE_MAP(From, To)
223
224 
225/// @}
226 
227#endif
Note: See TracBrowser for help on using the repository browser.