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() : Parent() {} \
41 DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
42 DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
43 : Parent(g, r, v) {} \
44 DefaultMap(const DefaultMap& copy) \
45 : Parent(static_cast<const Parent&>(copy)) {} \
46 template <typename TT> \
47 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) { \
64 Parent::MapBase::operator=(copy); \
65 if (Parent::getGraph()) { \
66 for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
68 Parent::operator[](it) = copy[it]; \
76 template <typename MapRegistry, typename Type>
77 class DefaultMap : public ArrayMap<MapRegistry, Type>
78 DEFAULT_MAP_BODY(ArrayMap, Type);
80 template <typename MapRegistry>
81 class DefaultMap<MapRegistry, bool>
82 : public VectorMap<MapRegistry, bool>
83 DEFAULT_MAP_BODY(VectorMap, bool);
85 template <typename MapRegistry>
86 class DefaultMap<MapRegistry, char>
87 : public VectorMap<MapRegistry, char>
88 DEFAULT_MAP_BODY(VectorMap, char);
90 template <typename MapRegistry>
91 class DefaultMap<MapRegistry, int>
92 : public VectorMap<MapRegistry, int>
93 DEFAULT_MAP_BODY(VectorMap, int);
95 template <typename MapRegistry>
96 class DefaultMap<MapRegistry, short>
97 : public VectorMap<MapRegistry, short>
98 DEFAULT_MAP_BODY(VectorMap, short);
100 template <typename MapRegistry>
101 class DefaultMap<MapRegistry, long>
102 : public VectorMap<MapRegistry, long>
103 DEFAULT_MAP_BODY(VectorMap, long);
105 template <typename MapRegistry>
106 class DefaultMap<MapRegistry, float>
107 : public VectorMap<MapRegistry, float>
108 DEFAULT_MAP_BODY(VectorMap, float);
110 template <typename MapRegistry>
111 class DefaultMap<MapRegistry, double>
112 : public VectorMap<MapRegistry, double>
113 DEFAULT_MAP_BODY(VectorMap, double);
115 template <typename MapRegistry>
116 class DefaultMap<MapRegistry, long double>
117 : public VectorMap<MapRegistry, long double>
118 DEFAULT_MAP_BODY(VectorMap, long double);
120 template <typename MapRegistry, typename Type>
121 class DefaultMap<MapRegistry, Type*>
122 : public VectorMap<MapRegistry, Type*>
123 DEFAULT_MAP_BODY(VectorMap, Type*);