COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/lemon/map_defines.h @ 1021:fd1d073b6557

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

Naming changes:

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) \
[987]54template <typename _Value> \
55class NodeMap : public DynMap<NodeMapRegistry, _Value> { \
[782]56public: \
[987]57typedef DynMap<NodeMapRegistry, _Value> Parent; \
[891]58NodeMap(const typename Parent::Graph& g) \
59  : Parent(g, g.node_maps) {} \
[987]60NodeMap(const typename Parent::Graph& g, const _Value& v) \
[891]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) \
[987]84template <typename _Value> \
85class EdgeMap : public DynMap<EdgeMapRegistry, _Value> { \
[782]86public: \
[987]87typedef DynMap<EdgeMapRegistry, _Value> Parent; \
[891]88\
89EdgeMap(const typename Parent::Graph& g) \
90  : Parent(g, g.edge_maps) {} \
[987]91EdgeMap(const typename Parent::Graph& g, const _Value& v) \
[891]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 \
[937]117typedef MapRegistry<Graph, SymEdge, SymEdgeIt> SymEdgeMapRegistry; \
[844]118mutable SymEdgeMapRegistry sym_edge_maps;
[782]119
120
[822]121/** Creates a map from a template map. The import method is
[782]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 */
[822]127#define CREATE_SYM_EDGE_MAP(DynMap) \
[987]128template <typename _Value> \
129class SymEdgeMap : public DynMap<SymEdgeMapRegistry, _Value> { \
[891]130public: \
[987]131typedef DynMap<SymEdgeMapRegistry, _Value> Parent; \
[822]132\
[891]133SymEdgeMap(const typename Parent::Graph& g) \
134  : Parent(g, g.sym_edge_maps) {} \
[987]135SymEdgeMap(const typename Parent::Graph& g, const _Value& v) \
[891]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} \
[782]151};
152
[822]153/** This is a macro to import an node map into a graph class.
154 */
155#define IMPORT_NODE_MAP(From, from, To, to) \
[987]156template <typename _Value> \
157class NodeMap : public From::template NodeMap<_Value> { \
[782]158\
[891]159public: \
[987]160typedef typename From::template NodeMap<_Value> Parent; \
[782]161\
[891]162NodeMap(const To& to) \
163  : Parent(static_cast<const From&>(from)) { } \
[987]164NodeMap(const To& to, const _Value& value) \
[891]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} \
[822]180};
[782]181
[822]182/** This is a macro to import an edge map into a graph class.
183 */
184#define IMPORT_EDGE_MAP(From, from, To, to) \
[987]185template <typename _Value> \
186class EdgeMap : public From::template EdgeMap<_Value> { \
[782]187\
[891]188public: \
[987]189typedef typename From::template EdgeMap<_Value> Parent; \
[782]190\
[891]191EdgeMap(const To& to) \
192  : Parent(static_cast<const From&>(from)) { } \
[987]193EdgeMap(const To& to, const _Value& value) \
[891]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} \
[822]209};
[782]210
[877]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)
[822]217
218/** This is a macro to keep the node and edge maps for a graph class.
219 */
220#define KEEP_MAPS(From, To) \
[877]221KEEP_EDGE_MAP(From, To) \
222KEEP_NODE_MAP(From, To)
223
[785]224 
225/// @}
226 
[782]227#endif
Note: See TracBrowser for help on using the repository browser.