12 |
12 |
13 namespace hugo { |
13 namespace hugo { |
14 |
14 |
15 /// Base class of maps. |
15 /// Base class of maps. |
16 |
16 |
|
17 /// Base class of maps. |
|
18 /// It provides the necessary <tt>typedef</tt>s required by the map concept. |
17 template<typename K, typename T> |
19 template<typename K, typename T> |
18 class MapBase |
20 class MapBase |
19 { |
21 { |
20 public: |
22 public: |
21 /// |
23 /// . |
22 typedef K KeyType; |
24 typedef K KeyType; |
23 /// |
25 /// . |
24 typedef T ValueType; |
26 typedef T ValueType; |
25 }; |
27 }; |
26 |
28 |
27 /// Null map. (aka DoNothingMap) |
29 /// Null map. (a.k.a. DoNothingMap) |
28 |
30 |
29 /// If you have to provide a map only for its type definitions, |
31 /// If you have to provide a map only for its type definitions, |
30 /// or if you have to provide a writable map, but will not use the |
32 /// or if you have to provide a writable map, but |
31 /// data written to it... |
33 /// data written to it will sent to <tt>/dev/null</tt>... |
32 template<typename K, typename T> |
34 template<typename K, typename T> |
33 class NullMap : public MapBase<K,T> |
35 class NullMap : public MapBase<K,T> |
34 { |
36 { |
35 public: |
37 public: |
36 |
38 |
|
39 /// Gives back a default constructed element. |
37 T operator[](const K&) const { return T(); } |
40 T operator[](const K&) const { return T(); } |
|
41 /// Absorbs the value. |
38 void set(const K&, const T&) {} |
42 void set(const K&, const T&) {} |
39 ///\bug when update is removed from map concepts by being dynamic |
|
40 ///stuffs, this line have to be removed. |
|
41 void update() { } |
|
42 }; |
43 }; |
43 |
44 |
44 |
45 |
45 /// Constant map. |
46 /// Constant map. |
46 |
47 |
47 /// This is a readable map which assignes a specified value to each key. |
48 /// This is a readable map which assigns a specified value to each key. |
48 /// In other aspects it is equivalent to the \ref NullMap |
49 /// In other aspects it is equivalent to the \ref NullMap. |
|
50 /// \todo set could be used to set the value. |
49 template<typename K, typename T> |
51 template<typename K, typename T> |
50 class ConstMap : public MapBase<K,T> |
52 class ConstMap : public MapBase<K,T> |
51 { |
53 { |
52 T v; |
54 T v; |
53 public: |
55 public: |
54 |
56 |
|
57 /// Default constructor |
|
58 |
|
59 /// The value of the map will be uninitialized. |
|
60 /// (More exactly it will be default constructed.) |
55 ConstMap() {} |
61 ConstMap() {} |
|
62 /// . |
|
63 |
|
64 /// \param _v The initial value of the map. |
56 ConstMap(const T &_v) : v(_v) {} |
65 ConstMap(const T &_v) : v(_v) {} |
57 |
66 |
58 T operator[](const K&) const { return v; } |
67 T operator[](const K&) const { return v; } |
59 void set(const K&, const T&) {} |
68 void set(const K&, const T&) {} |
60 |
69 |
121 } |
130 } |
122 |
131 |
123 /// Changes the default value of the map. |
132 /// Changes the default value of the map. |
124 /// \return Returns the previous default value. |
133 /// \return Returns the previous default value. |
125 /// |
134 /// |
126 /// \warning The value of some keys (which has alredy been queried, but |
135 /// \warning The value of some keys (which has already been queried, but |
127 /// the value has been unchanged from the default) may change! |
136 /// the value has been unchanged from the default) may change! |
128 T setDefault(const T &_v) { T old=v; v=_v; return old; } |
137 T setDefault(const T &_v) { T old=v; v=_v; return old; } |
129 |
138 |
130 template<typename T1> |
139 template<typename T1> |
131 struct rebind { |
140 struct rebind { |