... | ... |
@@ -21,32 +21,35 @@ |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/utility.h> |
23 | 23 |
#include <lemon/concept_check.h> |
24 | 24 |
|
25 | 25 |
///\ingroup concept |
26 | 26 |
///\file |
27 | 27 |
///\brief Map concepts checking classes for testing and documenting. |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup concept |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// Readable map concept |
37 |
|
|
38 |
/// Readable map concept. |
|
39 |
/// |
|
37 | 40 |
template<typename K, typename T> |
38 | 41 |
class ReadMap |
39 | 42 |
{ |
40 | 43 |
public: |
41 | 44 |
/// Map's key type. |
42 | 45 |
typedef K Key; |
43 | 46 |
/// Map's value type. (The type of objects associated with the keys). |
44 | 47 |
typedef T Value; |
45 | 48 |
|
46 | 49 |
/// Returns the value associated with a key. |
47 | 50 |
|
48 | 51 |
/// \bug Value should n't need to be default constructible. |
49 | 52 |
/// |
50 | 53 |
Value operator[](const Key &) const {return Value();} |
51 | 54 |
|
52 | 55 |
template<typename _ReadMap> |
... | ... |
@@ -58,32 +61,35 @@ |
58 | 61 |
typename _ReadMap::Value own_val = m[own_key]; |
59 | 62 |
own_val = m[own_key]; |
60 | 63 |
|
61 | 64 |
ignore_unused_variable_warning(val); |
62 | 65 |
ignore_unused_variable_warning(own_val); |
63 | 66 |
ignore_unused_variable_warning(key); |
64 | 67 |
} |
65 | 68 |
Key& key; |
66 | 69 |
typename _ReadMap::Key& own_key; |
67 | 70 |
_ReadMap& m; |
68 | 71 |
}; |
69 | 72 |
|
70 | 73 |
}; |
71 | 74 |
|
72 | 75 |
|
73 | 76 |
/// Writable map concept |
77 |
|
|
78 |
/// Writable map concept. |
|
79 |
/// |
|
74 | 80 |
template<typename K, typename T> |
75 | 81 |
class WriteMap |
76 | 82 |
{ |
77 | 83 |
public: |
78 | 84 |
/// Map's key type. |
79 | 85 |
typedef K Key; |
80 | 86 |
/// Map's value type. (The type of objects associated with the keys). |
81 | 87 |
typedef T Value; |
82 | 88 |
|
83 | 89 |
/// Sets the value associated with a key. |
84 | 90 |
void set(const Key &,const Value &) {} |
85 | 91 |
|
86 | 92 |
///Default constructor |
87 | 93 |
WriteMap() {} |
88 | 94 |
|
89 | 95 |
template <typename _WriteMap> |
... | ... |
@@ -95,100 +101,107 @@ |
95 | 101 |
ignore_unused_variable_warning(key); |
96 | 102 |
ignore_unused_variable_warning(val); |
97 | 103 |
ignore_unused_variable_warning(own_key); |
98 | 104 |
ignore_unused_variable_warning(own_val); |
99 | 105 |
} |
100 | 106 |
|
101 | 107 |
Value& val; |
102 | 108 |
typename _WriteMap::Value own_val; |
103 | 109 |
Key& key; |
104 | 110 |
typename _WriteMap::Key& own_key; |
105 | 111 |
_WriteMap& m; |
106 | 112 |
|
107 | 113 |
}; |
108 | 114 |
}; |
109 | 115 |
|
110 | 116 |
///Read/Writable map concept |
117 |
|
|
118 |
/// Read/writable map concept. |
|
119 |
/// |
|
111 | 120 |
template<typename K, typename T> |
112 | 121 |
class ReadWriteMap : public ReadMap<K,T>, |
113 | 122 |
public WriteMap<K,T> |
114 | 123 |
{ |
115 | 124 |
public: |
116 | 125 |
/// Map's key type. |
117 | 126 |
typedef K Key; |
118 | 127 |
/// Map's value type. (The type of objects associated with the keys). |
119 | 128 |
typedef T Value; |
120 | 129 |
|
121 | 130 |
/// Returns the value associated with a key. |
122 | 131 |
Value operator[](const Key &) const {return Value();} |
123 | 132 |
/// Sets the value associated with a key. |
124 | 133 |
void set(const Key & ,const Value &) {} |
125 | 134 |
|
126 | 135 |
template<typename _ReadWriteMap> |
127 | 136 |
struct Constraints { |
128 | 137 |
void constraints() { |
129 | 138 |
checkConcept<ReadMap<K, T>, _ReadWriteMap >(); |
130 | 139 |
checkConcept<WriteMap<K, T>, _ReadWriteMap >(); |
131 | 140 |
} |
132 | 141 |
}; |
133 | 142 |
}; |
134 | 143 |
|
135 | 144 |
|
136 | 145 |
///Dereferable map concept |
146 |
|
|
147 |
/// Dereferable map concept. |
|
148 |
/// |
|
137 | 149 |
template<typename K, typename T, typename R, typename CR> |
138 | 150 |
class ReferenceMap : public ReadWriteMap<K,T> |
139 | 151 |
{ |
140 | 152 |
public: |
141 | 153 |
/// Tag for reference maps. |
142 | 154 |
typedef True ReferenceMapTag; |
143 | 155 |
/// Map's key type. |
144 | 156 |
typedef K Key; |
145 | 157 |
/// Map's value type. (The type of objects associated with the keys). |
146 | 158 |
typedef T Value; |
147 | 159 |
/// Map's reference type. |
148 | 160 |
typedef R Reference; |
149 | 161 |
/// Map's const reference type. |
150 | 162 |
typedef CR ConstReference; |
151 | 163 |
|
152 | 164 |
protected: |
153 | 165 |
Value tmp; |
154 | 166 |
public: |
155 | 167 |
|
156 | 168 |
///Returns a reference to the value associated to a key. |
157 | 169 |
Reference operator[](const Key &) { return tmp; } |
158 | 170 |
///Returns a const reference to the value associated to a key. |
159 |
ConstReference operator[](const Key &) const |
|
160 |
{ return tmp; } |
|
171 |
ConstReference operator[](const Key &) const { return tmp; } |
|
161 | 172 |
/// Sets the value associated with a key. |
162 | 173 |
void set(const Key &k,const Value &t) { operator[](k)=t; } |
163 | 174 |
|
164 |
// \todo |
|
175 |
/// \todo Rethink this concept. |
|
165 | 176 |
template<typename _ReferenceMap> |
166 | 177 |
struct ReferenceMapConcept { |
167 | 178 |
|
168 | 179 |
void constraints() { |
169 | 180 |
checkConcept<ReadWriteMap, _ReferenceMap >(); |
170 | 181 |
m[key] = val; |
171 | 182 |
val = m[key]; |
172 | 183 |
m[key] = ref; |
173 | 184 |
ref = m[key]; |
174 | 185 |
m[own_key] = own_val; |
175 | 186 |
own_val = m[own_key]; |
176 | 187 |
m[own_key] = own_ref; |
177 | 188 |
own_ref = m[own_key]; |
178 | 189 |
} |
179 | 190 |
|
180 | 191 |
typename _ReferenceMap::Key& own_key; |
181 | 192 |
typename _ReferenceMap::Value& own_val; |
182 | 193 |
typename _ReferenceMap::Reference& own_ref; |
183 | 194 |
Key& key; |
184 | 195 |
Value& val; |
185 | 196 |
Reference& ref; |
186 | 197 |
_ReferenceMap& m; |
187 | 198 |
}; |
188 | 199 |
}; |
189 | 200 |
|
190 | 201 |
// @} |
191 | 202 |
|
192 | 203 |
} //namespace concepts |
204 |
|
|
193 | 205 |
} //namespace lemon |
206 |
|
|
194 | 207 |
#endif // LEMON_CONCEPT_MAPS_H |
0 comments (0 inline)