COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/default_map.h @ 898:c46cfb2651ec

Last change on this file since 898:c46cfb2651ec was 897:ef09eee53b09, checked in by Balazs Dezso, 20 years ago

The default constructors are removed from the maps.
The ArrayMap? is the map structure of the graphs.

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(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
41DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
42  : Parent(g, r, v) {} \
43DefaultMap(const DefaultMap& copy) \
44  : Parent(static_cast<const Parent&>(copy)) {} \
45template <typename TT> \
46DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
47  : { \
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  if (Parent::getGraph() != copy.getGraph()) { \
64    Parent::clear(); \
65    Parent::MapBase::operator=(copy); \
66    Parent::construct(); \
67  } \
68  if (Parent::getGraph()) { \
69    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
70      Parent::operator[](it) = copy[it]; \
71    } \
72  } \
73  return *this; \
74} \
75};
76
77
78  template <typename MapRegistry, typename Type>
79  class DefaultMap : public ArrayMap<MapRegistry, Type>
80  DEFAULT_MAP_BODY(ArrayMap, Type);
81
82  template <typename MapRegistry>
83  class DefaultMap<MapRegistry, bool>
84    : public VectorMap<MapRegistry, bool>
85  DEFAULT_MAP_BODY(VectorMap, bool);
86
87  template <typename MapRegistry>
88  class DefaultMap<MapRegistry, char>
89    : public VectorMap<MapRegistry, char>
90  DEFAULT_MAP_BODY(VectorMap, char);
91
92  template <typename MapRegistry>
93  class DefaultMap<MapRegistry, int>
94    : public VectorMap<MapRegistry, int>
95  DEFAULT_MAP_BODY(VectorMap, int);
96
97  template <typename MapRegistry>
98  class DefaultMap<MapRegistry, short>
99    : public VectorMap<MapRegistry, short>
100  DEFAULT_MAP_BODY(VectorMap, short);
101
102  template <typename MapRegistry>
103  class DefaultMap<MapRegistry, long>
104    : public VectorMap<MapRegistry, long>
105  DEFAULT_MAP_BODY(VectorMap, long);
106
107  template <typename MapRegistry>
108  class DefaultMap<MapRegistry, float>
109    : public VectorMap<MapRegistry, float>
110  DEFAULT_MAP_BODY(VectorMap, float);
111
112  template <typename MapRegistry>
113  class DefaultMap<MapRegistry, double>
114    : public VectorMap<MapRegistry, double>
115  DEFAULT_MAP_BODY(VectorMap, double);
116
117  template <typename MapRegistry>
118  class DefaultMap<MapRegistry, long double>
119    : public VectorMap<MapRegistry, long double>
120  DEFAULT_MAP_BODY(VectorMap, long double);
121
122  template <typename MapRegistry, typename Type>
123  class DefaultMap<MapRegistry, Type*>
124    : public VectorMap<MapRegistry, Type*>
125  DEFAULT_MAP_BODY(VectorMap, Type*);
126
127}
128
129#endif
Note: See TracBrowser for help on using the repository browser.