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