COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/lemon/map_defines.h @ 932:ade3cdb9b45d

Last change on this file since 932:ade3cdb9b45d was 921:818510fa3d99, checked in by Alpar Juttner, 16 years ago

hugo -> lemon

File size: 7.2 KB
RevLine 
[906]1/* -*- C++ -*-
[921]2 * src/lemon/map_defines.h - Part of LEMON, a generic C++ optimization library
[906]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
[921]17#ifndef LEMON_MAP_DEFINES_H
18#define LEMON_MAP_DEFINES_H
[782]19
[822]20///\ingroup graphmaps
[785]21///\file
22///\brief Defines to help creating graph maps.
23
24/// \addtogroup graphmapfactory
25/// @{
26
[782]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
[822]47/** Creates a map from a template map. The import method is
[782]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 */
[822]53#define CREATE_NODE_MAP(DynMap) \
54template <typename Value> \
55class NodeMap : public DynMap<NodeMapRegistry, Value> { \
[782]56public: \
[891]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)) {} \
[782]66NodeMap& operator=(const NodeMap& copy) { \
[891]67  Parent::operator=(static_cast<const Parent&>(copy));\
[782]68  return *this; \
69} \
[891]70template <typename TT> \
71NodeMap& operator=(const NodeMap<TT>& copy) { \
72  Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
[782]73  return *this; \
74} \
75};
76
[822]77/** Creates a map from a template map. The import method is
[782]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 */
[822]83#define CREATE_EDGE_MAP(DynMap) \
84template <typename Value> \
85class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \
[782]86public: \
[891]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)) {} \
[782]97EdgeMap& operator=(const EdgeMap& copy) { \
[891]98  Parent::operator=(static_cast<const Parent&>(copy));\
[782]99  return *this; \
100} \
[891]101template <typename TT> \
102EdgeMap& operator=(const EdgeMap<TT>& copy) { \
103  Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
[782]104  return *this; \
105} \
106};
107
[822]108/** This macro creates both maps.
[782]109 */
[822]110#define CREATE_MAPS(DynMap) \
111CREATE_NODE_MAP(DynMap) \
112CREATE_EDGE_MAP(DynMap)
[782]113
114/** This macro creates MapRegistry for Symmetric Edge Maps.
115 */
116#define CREATE_SYM_EDGE_MAP_REGISTRY \
[919]117typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
118typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
[844]119mutable SymEdgeMapRegistry sym_edge_maps;
[782]120
121
[822]122/** Creates a map from a template map. The import method is
[782]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 */
[822]128#define CREATE_SYM_EDGE_MAP(DynMap) \
129template <typename Value> \
[919]130class SymEdgeMap : public SymMap<DynMap, SymEdgeMapRegistry, Value> { \
[891]131public: \
[919]132typedef SymMap<DynMap, SymEdgeMapRegistry, Value> Parent; \
[822]133\
[891]134SymEdgeMap(const typename Parent::Graph& g) \
135  : Parent(g, g.sym_edge_maps) {} \
136SymEdgeMap(const typename Parent::Graph& g, const Value& v) \
137  : Parent(g, g.sym_edge_maps, v) {} \
138SymEdgeMap(const SymEdgeMap& copy) \
139  : Parent(static_cast<const Parent&>(copy)) {} \
140template <typename TT> \
141SymEdgeMap(const NodeMap<TT>& copy) \
142  : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \
143SymEdgeMap& operator=(const SymEdgeMap& copy) { \
144  Parent::operator=(static_cast<const Parent&>(copy));\
145  return *this; \
146} \
147template <typename TT> \
148SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \
149  Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\
150  return *this; \
151} \
[782]152};
153
[822]154/** This is a macro to import an node map into a graph class.
155 */
156#define IMPORT_NODE_MAP(From, from, To, to) \
157template <typename Value> \
[891]158class NodeMap : public From::template NodeMap<Value> { \
[782]159\
[891]160public: \
161typedef typename From::template NodeMap<Value> Parent; \
[782]162\
[891]163NodeMap(const To& to) \
164  : Parent(static_cast<const From&>(from)) { } \
165NodeMap(const To& to, const Value& value) \
166  : Parent(static_cast<const From&>(from), value) { } \
167NodeMap(const NodeMap& copy) \
168  : Parent(static_cast<const Parent&>(copy)) {} \
169template <typename TT> \
170NodeMap(const NodeMap<TT>& copy) \
171  : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
172NodeMap& operator=(const NodeMap& copy) { \
173  Parent::operator=(static_cast<const Parent&>(copy)); \
174  return *this; \
175} \
176template <typename TT> \
177NodeMap& operator=(const NodeMap<TT>& copy) { \
178  Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
179  return *this; \
180} \
[822]181};
[782]182
[822]183/** This is a macro to import an edge map into a graph class.
184 */
185#define IMPORT_EDGE_MAP(From, from, To, to) \
186template <typename Value> \
[891]187class EdgeMap : public From::template EdgeMap<Value> { \
[782]188\
[891]189public: \
190typedef typename From::template EdgeMap<Value> Parent; \
[782]191\
[891]192EdgeMap(const To& to) \
193  : Parent(static_cast<const From&>(from)) { } \
194EdgeMap(const To& to, const Value& value) \
195  : Parent(static_cast<const From&>(from), value) { } \
196EdgeMap(const EdgeMap& copy) \
197  : Parent(static_cast<const Parent&>(copy)) {} \
198template <typename TT> \
199EdgeMap(const EdgeMap<TT>& copy) \
200  : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
201EdgeMap& operator=(const EdgeMap& copy) { \
202  Parent::operator=(static_cast<const Parent&>(copy)); \
203  return *this; \
204} \
205template <typename TT> \
206EdgeMap& operator=(const EdgeMap<TT>& copy) { \
207  Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
208  return *this; \
209} \
[822]210};
[782]211
[877]212#define KEEP_EDGE_MAP(From, To) \
213IMPORT_EDGE_MAP(From, graph, To, graph)
214
215
216#define KEEP_NODE_MAP(From, To) \
217IMPORT_NODE_MAP(From, graph, To, graph)
[822]218
219/** This is a macro to keep the node and edge maps for a graph class.
220 */
221#define KEEP_MAPS(From, To) \
[877]222KEEP_EDGE_MAP(From, To) \
223KEEP_NODE_MAP(From, To)
224
[785]225 
226/// @}
227 
[782]228#endif
Note: See TracBrowser for help on using the repository browser.