6 #include <hugo/array_map.h>
7 #include <hugo/vector_map.h>
11 ///\brief Graph maps that construates and destruates
12 ///their elements dynamically.
16 /// \addtogroup graphmaps
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.
24 * The template parameter is the MapRegistry that the maps
25 * will belong to and the ValueType.
29 /** Macro to implement the DefaultMap.
31 #define DEFAULT_MAP_BODY(DynMap, Value) \
36 typedef DynMap<MapRegistry, Value> Parent; \
38 typedef typename MapRegistry::Graph Graph; \
40 DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
41 DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
42 : Parent(g, r, v) {} \
43 DefaultMap(const DefaultMap& copy) \
44 : Parent(static_cast<const Parent&>(copy)) {} \
45 template <typename TT> \
46 DefaultMap(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) {\
53 Parent::operator[](it) = copy[it]; \
57 DefaultMap& operator=(const DefaultMap& copy) { \
58 Parent::operator=(static_cast<const Parent&>(copy)); \
61 template <typename TT> \
62 DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
63 if (Parent::getGraph() != copy.getGraph()) { \
65 Parent::MapBase::operator=(copy); \
66 Parent::construct(); \
68 if (Parent::getGraph()) { \
69 for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
70 Parent::operator[](it) = copy[it]; \
78 template <typename MapRegistry, typename Type>
79 class DefaultMap : public ArrayMap<MapRegistry, Type>
80 DEFAULT_MAP_BODY(ArrayMap, Type);
82 template <typename MapRegistry>
83 class DefaultMap<MapRegistry, bool>
84 : public VectorMap<MapRegistry, bool>
85 DEFAULT_MAP_BODY(VectorMap, bool);
87 template <typename MapRegistry>
88 class DefaultMap<MapRegistry, char>
89 : public VectorMap<MapRegistry, char>
90 DEFAULT_MAP_BODY(VectorMap, char);
92 template <typename MapRegistry>
93 class DefaultMap<MapRegistry, int>
94 : public VectorMap<MapRegistry, int>
95 DEFAULT_MAP_BODY(VectorMap, int);
97 template <typename MapRegistry>
98 class DefaultMap<MapRegistry, short>
99 : public VectorMap<MapRegistry, short>
100 DEFAULT_MAP_BODY(VectorMap, short);
102 template <typename MapRegistry>
103 class DefaultMap<MapRegistry, long>
104 : public VectorMap<MapRegistry, long>
105 DEFAULT_MAP_BODY(VectorMap, long);
107 template <typename MapRegistry>
108 class DefaultMap<MapRegistry, float>
109 : public VectorMap<MapRegistry, float>
110 DEFAULT_MAP_BODY(VectorMap, float);
112 template <typename MapRegistry>
113 class DefaultMap<MapRegistry, double>
114 : public VectorMap<MapRegistry, double>
115 DEFAULT_MAP_BODY(VectorMap, double);
117 template <typename MapRegistry>
118 class DefaultMap<MapRegistry, long double>
119 : public VectorMap<MapRegistry, long double>
120 DEFAULT_MAP_BODY(VectorMap, long double);
122 template <typename MapRegistry, typename Type>
123 class DefaultMap<MapRegistry, Type*>
124 : public VectorMap<MapRegistry, Type*>
125 DEFAULT_MAP_BODY(VectorMap, Type*);