... | ... |
@@ -154,39 +154,41 @@ |
154 | 154 |
///This function just returns a \c ConstMap class with inlined value. |
155 | 155 |
///\relates ConstMap |
156 | 156 |
template<typename K, typename V, V v> |
157 | 157 |
inline ConstMap<K, Const<V, v> > constMap() { |
158 | 158 |
return ConstMap<K, Const<V, v> >(); |
159 | 159 |
} |
160 | 160 |
|
161 | 161 |
///Map based on std::map |
162 | 162 |
|
163 | 163 |
///This is essentially a wrapper for \c std::map with addition that |
164 | 164 |
///you can specify a default value different from \c Value(). |
165 | 165 |
template <typename K, typename T, typename Compare = std::less<K> > |
166 |
class StdMap { |
|
166 |
class StdMap : public MapBase<K, T> { |
|
167 | 167 |
template <typename K1, typename T1, typename C1> |
168 | 168 |
friend class StdMap; |
169 | 169 |
public: |
170 | 170 |
|
171 |
typedef |
|
171 |
typedef MapBase<K, T> Parent; |
|
172 | 172 |
///\e |
173 |
typedef |
|
173 |
typedef typename Parent::Key Key; |
|
174 | 174 |
///\e |
175 |
typedef |
|
175 |
typedef typename Parent::Value Value; |
|
176 | 176 |
///\e |
177 | 177 |
typedef T& Reference; |
178 | 178 |
///\e |
179 | 179 |
typedef const T& ConstReference; |
180 | 180 |
|
181 |
typedef True ReferenceMapTag; |
|
182 |
|
|
181 | 183 |
private: |
182 | 184 |
|
183 | 185 |
typedef std::map<K, T, Compare> Map; |
184 | 186 |
Value _value; |
185 | 187 |
Map _map; |
186 | 188 |
|
187 | 189 |
public: |
188 | 190 |
|
189 | 191 |
/// Constructor with specified default value |
190 | 192 |
StdMap(const T& value = T()) : _value(value) {} |
191 | 193 |
/// \brief Constructs the map from an appropriate std::map, and explicitly |
192 | 194 |
/// specifies a default value. |
... | ... |
@@ -230,51 +232,74 @@ |
230 | 232 |
it->second = t; |
231 | 233 |
else |
232 | 234 |
_map.insert(it, std::make_pair(k, t)); |
233 | 235 |
} |
234 | 236 |
|
235 | 237 |
/// \e |
236 | 238 |
void setAll(const T &t) { |
237 | 239 |
_value = t; |
238 | 240 |
_map.clear(); |
239 | 241 |
} |
240 | 242 |
|
241 | 243 |
}; |
244 |
|
|
245 |
///Returns a \ref StdMap class |
|
246 |
|
|
247 |
///This function just returns a \ref StdMap class with specified |
|
248 |
///default value. |
|
249 |
///\relates StdMap |
|
250 |
template<typename K, typename V, typename Compare = std::less<K> > |
|
251 |
inline StdMap<K, V, Compare> stdMap(const V& value = V()) { |
|
252 |
return StdMap<K, V, Compare>(value); |
|
253 |
} |
|
254 |
|
|
255 |
///Returns a \ref StdMap class created from an appropriate std::map |
|
256 |
|
|
257 |
///This function just returns a \ref StdMap class created from an |
|
258 |
///appropriate std::map. |
|
259 |
///\relates StdMap |
|
260 |
template<typename K, typename V, typename Compare = std::less<K> > |
|
261 |
inline StdMap<K, V, Compare> stdMap( const std::map<K, V, Compare> &map, |
|
262 |
const V& value = V() ) { |
|
263 |
return StdMap<K, V, Compare>(map, value); |
|
264 |
} |
|
242 | 265 |
|
243 | 266 |
/// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt> |
244 | 267 |
/// |
245 | 268 |
/// The current map has the <tt>[0..size-1]</tt> keyset and the values |
246 | 269 |
/// are stored in a \c std::vector<T> container. It can be used with |
247 | 270 |
/// some data structures, for example \c UnionFind, \c BinHeap, when |
248 | 271 |
/// the used items are small integer numbers. |
249 | 272 |
/// |
250 | 273 |
/// \todo Revise its name |
251 | 274 |
template <typename T> |
252 |
class IntegerMap { |
|
275 |
class IntegerMap : public MapBase<int, T> { |
|
253 | 276 |
|
254 | 277 |
template <typename T1> |
255 | 278 |
friend class IntegerMap; |
256 | 279 |
|
257 | 280 |
public: |
258 | 281 |
|
259 |
typedef |
|
282 |
typedef MapBase<int, T> Parent; |
|
260 | 283 |
///\e |
261 |
typedef |
|
284 |
typedef typename Parent::Key Key; |
|
262 | 285 |
///\e |
263 |
typedef |
|
286 |
typedef typename Parent::Value Value; |
|
264 | 287 |
///\e |
265 | 288 |
typedef T& Reference; |
266 | 289 |
///\e |
267 | 290 |
typedef const T& ConstReference; |
268 | 291 |
|
292 |
typedef True ReferenceMapTag; |
|
293 |
|
|
269 | 294 |
private: |
270 | 295 |
|
271 | 296 |
typedef std::vector<T> Vector; |
272 | 297 |
Vector _vector; |
273 | 298 |
|
274 | 299 |
public: |
275 | 300 |
|
276 | 301 |
/// Constructor with specified default value |
277 | 302 |
IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {} |
278 | 303 |
|
279 | 304 |
/// \brief Constructs the map from an appropriate std::vector. |
280 | 305 |
template <typename T1> |
... | ... |
@@ -304,24 +329,33 @@ |
304 | 329 |
|
305 | 330 |
/// \e |
306 | 331 |
ConstReference operator[](Key k) const { |
307 | 332 |
return _vector[k]; |
308 | 333 |
} |
309 | 334 |
|
310 | 335 |
/// \e |
311 | 336 |
void set(const Key &k, const T& t) { |
312 | 337 |
_vector[k] = t; |
313 | 338 |
} |
314 | 339 |
|
315 | 340 |
}; |
341 |
|
|
342 |
///Returns an \ref IntegerMap class |
|
343 |
|
|
344 |
///This function just returns an \ref IntegerMap class. |
|
345 |
///\relates IntegerMap |
|
346 |
template<typename T> |
|
347 |
inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) { |
|
348 |
return IntegerMap<T>(size, value); |
|
349 |
} |
|
316 | 350 |
|
317 | 351 |
/// @} |
318 | 352 |
|
319 | 353 |
/// \addtogroup map_adaptors |
320 | 354 |
/// @{ |
321 | 355 |
|
322 | 356 |
/// \brief Identity map. |
323 | 357 |
/// |
324 | 358 |
/// This map gives back the given key as value without any |
325 | 359 |
/// modification. |
326 | 360 |
template <typename T> |
327 | 361 |
class IdentityMap : public MapBase<T, T> { |
... | ... |
@@ -396,24 +430,33 @@ |
396 | 430 |
const M& m; |
397 | 431 |
|
398 | 432 |
public: |
399 | 433 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
400 | 434 |
typedef typename Parent::Key Key; |
401 | 435 |
typedef typename Parent::Value Value; |
402 | 436 |
|
403 | 437 |
///Constructor |
404 | 438 |
SimpleMap(const M &_m) : m(_m) {}; |
405 | 439 |
///\e |
406 | 440 |
Value operator[](Key k) const {return m[k];} |
407 | 441 |
}; |
442 |
|
|
443 |
///Returns a \ref SimpleMap class |
|
444 |
|
|
445 |
///This function just returns a \ref SimpleMap class. |
|
446 |
///\relates SimpleMap |
|
447 |
template<typename M> |
|
448 |
inline SimpleMap<M> simpleMap(const M &m) { |
|
449 |
return SimpleMap<M>(m); |
|
450 |
} |
|
408 | 451 |
|
409 | 452 |
///Simple writable wrapping of a map |
410 | 453 |
|
411 | 454 |
///This \ref concepts::WriteMap "write map" returns the simple |
412 | 455 |
///wrapping of the given map. Sometimes the reference maps cannot be |
413 | 456 |
///combined with simple read-write maps. This map adaptor wraps the |
414 | 457 |
///given map to simple read-write map. |
415 | 458 |
/// |
416 | 459 |
///\sa SimpleMap |
417 | 460 |
/// |
418 | 461 |
/// \todo Revise the misleading name |
419 | 462 |
template<typename M> |
... | ... |
@@ -424,24 +467,33 @@ |
424 | 467 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
425 | 468 |
typedef typename Parent::Key Key; |
426 | 469 |
typedef typename Parent::Value Value; |
427 | 470 |
|
428 | 471 |
///Constructor |
429 | 472 |
SimpleWriteMap(M &_m) : m(_m) {}; |
430 | 473 |
///\e |
431 | 474 |
Value operator[](Key k) const {return m[k];} |
432 | 475 |
///\e |
433 | 476 |
void set(Key k, const Value& c) { m.set(k, c); } |
434 | 477 |
}; |
435 | 478 |
|
479 |
///Returns a \ref SimpleWriteMap class |
|
480 |
|
|
481 |
///This function just returns a \ref SimpleWriteMap class. |
|
482 |
///\relates SimpleWriteMap |
|
483 |
template<typename M> |
|
484 |
inline SimpleWriteMap<M> simpleWriteMap(M &m) { |
|
485 |
return SimpleWriteMap<M>(m); |
|
486 |
} |
|
487 |
|
|
436 | 488 |
///Sum of two maps |
437 | 489 |
|
438 | 490 |
///This \c concepts::ReadMap "read only map" returns the sum of the two |
439 | 491 |
///given maps. |
440 | 492 |
///Its \c Key and \c Value are inherited from \c M1. |
441 | 493 |
///The \c Key and \c Value of M2 must be convertible to those of \c M1. |
442 | 494 |
template<typename M1, typename M2> |
443 | 495 |
class AddMap : public MapBase<typename M1::Key, typename M1::Value> { |
444 | 496 |
const M1& m1; |
445 | 497 |
const M2& m2; |
446 | 498 |
|
447 | 499 |
public: |
0 comments (0 inline)