COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/default_map.h @ 891:74589d20dbc3

Last change on this file since 891:74589d20dbc3 was 891:74589d20dbc3, checked in by Balazs Dezso, 20 years ago

template<typename CMap> Map(const CMap&) like constructors and
assigns are removed.

File size: 3.5 KB
Line 
1// -*- c++ -*-
2#ifndef DEFAULT_MAP_H
3#define DEFAULT_MAP_H
4
5
6#include <hugo/array_map.h>
7#include <hugo/vector_map.h>
8
9///\ingroup graphmaps
10///\file
11///\brief Graph maps that construates and destruates
12///their elements dynamically.
13
14namespace hugo {
15
16/// \addtogroup graphmaps
17/// @{
18
19  /** The ArrayMap template class is graph map structure what
20   *  automatically updates the map when a key is added to or erased from
21   *  the map. This map uses the VectorMap if the ValueType is a primitive
22   *  type and the ArrayMap for the other cases.
23   *
24   *  The template parameter is the MapRegistry that the maps
25   *  will belong to and the ValueType.
26   */
27
28
29  /** Macro to implement the DefaultMap.
30   */
31#define DEFAULT_MAP_BODY(DynMap, Value) \
32{ \
33\
34public: \
35\
36typedef DynMap<MapRegistry, Value> Parent; \
37\
38typedef typename MapRegistry::Graph Graph; \
39\
40DefaultMap() : Parent() {} \
41DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
42DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
43  : Parent(g, r, v) {} \
44DefaultMap(const DefaultMap& copy) \
45  : Parent(static_cast<const Parent&>(copy)) {} \
46template <typename TT> \
47DefaultMap(const DefaultMap<MapRegistry, TT>& copy) { \
48  Parent::MapBase::operator= \
49    (static_cast<const typename Parent::MapBase&>(copy)); \
50  if (Parent::getGraph()) { \
51    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
52      Parent::add(it); \
53      Parent::operator[](it) = copy[it]; \
54    } \
55  } \
56} \
57DefaultMap& operator=(const DefaultMap& copy) { \
58  Parent::operator=(static_cast<const Parent&>(copy)); \
59  return *this; \
60} \
61template <typename TT> \
62DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
63  Parent::clear(); \
64  Parent::MapBase::operator=(copy); \
65  if (Parent::getGraph()) { \
66    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
67      Parent::add(it); \
68      Parent::operator[](it) = copy[it]; \
69    } \
70  } \
71  return *this; \
72} \
73};
74
75
76  template <typename MapRegistry, typename Type>
77  class DefaultMap : public ArrayMap<MapRegistry, Type>
78  DEFAULT_MAP_BODY(ArrayMap, Type);
79
80  template <typename MapRegistry>
81  class DefaultMap<MapRegistry, bool>
82    : public VectorMap<MapRegistry, bool>
83  DEFAULT_MAP_BODY(VectorMap, bool);
84
85  template <typename MapRegistry>
86  class DefaultMap<MapRegistry, char>
87    : public VectorMap<MapRegistry, char>
88  DEFAULT_MAP_BODY(VectorMap, char);
89
90  template <typename MapRegistry>
91  class DefaultMap<MapRegistry, int>
92    : public VectorMap<MapRegistry, int>
93  DEFAULT_MAP_BODY(VectorMap, int);
94
95  template <typename MapRegistry>
96  class DefaultMap<MapRegistry, short>
97    : public VectorMap<MapRegistry, short>
98  DEFAULT_MAP_BODY(VectorMap, short);
99
100  template <typename MapRegistry>
101  class DefaultMap<MapRegistry, long>
102    : public VectorMap<MapRegistry, long>
103  DEFAULT_MAP_BODY(VectorMap, long);
104
105  template <typename MapRegistry>
106  class DefaultMap<MapRegistry, float>
107    : public VectorMap<MapRegistry, float>
108  DEFAULT_MAP_BODY(VectorMap, float);
109
110  template <typename MapRegistry>
111  class DefaultMap<MapRegistry, double>
112    : public VectorMap<MapRegistry, double>
113  DEFAULT_MAP_BODY(VectorMap, double);
114
115  template <typename MapRegistry>
116  class DefaultMap<MapRegistry, long double>
117    : public VectorMap<MapRegistry, long double>
118  DEFAULT_MAP_BODY(VectorMap, long double);
119
120  template <typename MapRegistry, typename Type>
121  class DefaultMap<MapRegistry, Type*>
122    : public VectorMap<MapRegistry, Type*>
123  DEFAULT_MAP_BODY(VectorMap, Type*);
124
125}
126
127#endif
Note: See TracBrowser for help on using the repository browser.