0
2
0
118
62
| ... | ... |
@@ -39,24 +39,25 @@ |
| 39 | 39 |
/// |
| 40 | 40 |
template<typename K, typename T> |
| 41 | 41 |
class ReadMap |
| 42 | 42 |
{
|
| 43 | 43 |
public: |
| 44 | 44 |
/// The key type of the map. |
| 45 | 45 |
typedef K Key; |
| 46 | 46 |
/// The value type of the map. (The type of objects associated with the keys). |
| 47 | 47 |
typedef T Value; |
| 48 | 48 |
|
| 49 | 49 |
/// Returns the value associated with a key. |
| 50 | 50 |
|
| 51 |
/// Returns the value associated with a key. |
|
| 51 | 52 |
/// \bug Value shouldn't need to be default constructible. |
| 52 | 53 |
/// |
| 53 | 54 |
Value operator[](const Key &) const {return Value();}
|
| 54 | 55 |
|
| 55 | 56 |
template<typename _ReadMap> |
| 56 | 57 |
struct Constraints {
|
| 57 | 58 |
|
| 58 | 59 |
void constraints() {
|
| 59 | 60 |
Value val = m[key]; |
| 60 | 61 |
val = m[key]; |
| 61 | 62 |
typename _ReadMap::Value own_val = m[own_key]; |
| 62 | 63 |
own_val = m[own_key]; |
| ... | ... |
@@ -104,25 +105,25 @@ |
| 104 | 105 |
ignore_unused_variable_warning(own_val); |
| 105 | 106 |
} |
| 106 | 107 |
|
| 107 | 108 |
Value& val; |
| 108 | 109 |
typename _WriteMap::Value own_val; |
| 109 | 110 |
Key& key; |
| 110 | 111 |
typename _WriteMap::Key& own_key; |
| 111 | 112 |
_WriteMap& m; |
| 112 | 113 |
|
| 113 | 114 |
}; |
| 114 | 115 |
}; |
| 115 | 116 |
|
| 116 |
/// Read/ |
|
| 117 |
/// Read/writable map concept |
|
| 117 | 118 |
|
| 118 | 119 |
/// Read/writable map concept. |
| 119 | 120 |
/// |
| 120 | 121 |
template<typename K, typename T> |
| 121 | 122 |
class ReadWriteMap : public ReadMap<K,T>, |
| 122 | 123 |
public WriteMap<K,T> |
| 123 | 124 |
{
|
| 124 | 125 |
public: |
| 125 | 126 |
/// The key type of the map. |
| 126 | 127 |
typedef K Key; |
| 127 | 128 |
/// The value type of the map. (The type of objects associated with the keys). |
| 128 | 129 |
typedef T Value; |
| ... | ... |
@@ -137,51 +138,51 @@ |
| 137 | 138 |
void constraints() {
|
| 138 | 139 |
checkConcept<ReadMap<K, T>, _ReadWriteMap >(); |
| 139 | 140 |
checkConcept<WriteMap<K, T>, _ReadWriteMap >(); |
| 140 | 141 |
} |
| 141 | 142 |
}; |
| 142 | 143 |
}; |
| 143 | 144 |
|
| 144 | 145 |
|
| 145 | 146 |
/// Dereferable map concept |
| 146 | 147 |
|
| 147 | 148 |
/// Dereferable map concept. |
| 148 | 149 |
/// |
| 150 |
/// \todo Rethink this concept. |
|
| 149 | 151 |
template<typename K, typename T, typename R, typename CR> |
| 150 | 152 |
class ReferenceMap : public ReadWriteMap<K,T> |
| 151 | 153 |
{
|
| 152 | 154 |
public: |
| 153 | 155 |
/// Tag for reference maps. |
| 154 | 156 |
typedef True ReferenceMapTag; |
| 155 | 157 |
/// The key type of the map. |
| 156 | 158 |
typedef K Key; |
| 157 | 159 |
/// The value type of the map. (The type of objects associated with the keys). |
| 158 | 160 |
typedef T Value; |
| 159 | 161 |
/// The reference type of the map. |
| 160 | 162 |
typedef R Reference; |
| 161 | 163 |
/// The const reference type of the map. |
| 162 | 164 |
typedef CR ConstReference; |
| 163 | 165 |
|
| 164 | 166 |
protected: |
| 165 | 167 |
Value tmp; |
| 166 | 168 |
public: |
| 167 | 169 |
|
| 168 |
///Returns a reference to the value associated |
|
| 170 |
///Returns a reference to the value associated with a key. |
|
| 169 | 171 |
Reference operator[](const Key &) { return tmp; }
|
| 170 |
///Returns a const reference to the value associated |
|
| 172 |
///Returns a const reference to the value associated with a key. |
|
| 171 | 173 |
ConstReference operator[](const Key &) const { return tmp; }
|
| 172 | 174 |
/// Sets the value associated with a key. |
| 173 | 175 |
void set(const Key &k,const Value &t) { operator[](k)=t; }
|
| 174 | 176 |
|
| 175 |
/// \todo Rethink this concept. |
|
| 176 | 177 |
template<typename _ReferenceMap> |
| 177 | 178 |
struct ReferenceMapConcept {
|
| 178 | 179 |
|
| 179 | 180 |
void constraints() {
|
| 180 | 181 |
checkConcept<ReadWriteMap, _ReferenceMap >(); |
| 181 | 182 |
m[key] = val; |
| 182 | 183 |
val = m[key]; |
| 183 | 184 |
m[key] = ref; |
| 184 | 185 |
ref = m[key]; |
| 185 | 186 |
m[own_key] = own_val; |
| 186 | 187 |
own_val = m[own_key]; |
| 187 | 188 |
m[own_key] = own_ref; |
| ... | ... |
@@ -72,26 +72,27 @@ |
| 72 | 72 |
///Returns a \c NullMap class |
| 73 | 73 |
|
| 74 | 74 |
///This function just returns a \c NullMap class. |
| 75 | 75 |
///\relates NullMap |
| 76 | 76 |
template <typename K, typename V> |
| 77 | 77 |
NullMap<K, V> nullMap() {
|
| 78 | 78 |
return NullMap<K, V>(); |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
|
| 82 | 82 |
/// Constant map. |
| 83 | 83 |
|
| 84 |
/// This is a readable map which assigns a specified value to each key. |
|
| 85 |
/// In other aspects it is equivalent to the \c NullMap. |
|
| 84 |
/// This is a \ref concepts::ReadMap "readable" map which assigns a |
|
| 85 |
/// specified value to each key. |
|
| 86 |
/// In other aspects it is equivalent to \c NullMap. |
|
| 86 | 87 |
template<typename K, typename T> |
| 87 | 88 |
class ConstMap : public MapBase<K, T> {
|
| 88 | 89 |
private: |
| 89 | 90 |
T v; |
| 90 | 91 |
public: |
| 91 | 92 |
|
| 92 | 93 |
typedef MapBase<K, T> Parent; |
| 93 | 94 |
typedef typename Parent::Key Key; |
| 94 | 95 |
typedef typename Parent::Value Value; |
| 95 | 96 |
|
| 96 | 97 |
/// Default constructor |
| 97 | 98 |
|
| ... | ... |
@@ -124,86 +125,90 @@ |
| 124 | 125 |
///\relates ConstMap |
| 125 | 126 |
template<typename K, typename V> |
| 126 | 127 |
inline ConstMap<K, V> constMap(const V &v) {
|
| 127 | 128 |
return ConstMap<K, V>(v); |
| 128 | 129 |
} |
| 129 | 130 |
|
| 130 | 131 |
|
| 131 | 132 |
template<typename T, T v> |
| 132 | 133 |
struct Const { };
|
| 133 | 134 |
|
| 134 | 135 |
/// Constant map with inlined constant value. |
| 135 | 136 |
|
| 136 |
/// This is a readable map which assigns a specified value to each key. |
|
| 137 |
/// In other aspects it is equivalent to the \c NullMap. |
|
| 137 |
/// This is a \ref concepts::ReadMap "readable" map which assigns a |
|
| 138 |
/// specified value to each key. |
|
| 139 |
/// In other aspects it is equivalent to \c NullMap. |
|
| 138 | 140 |
template<typename K, typename V, V v> |
| 139 | 141 |
class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
|
| 140 | 142 |
public: |
| 141 | 143 |
typedef MapBase<K, V> Parent; |
| 142 | 144 |
typedef typename Parent::Key Key; |
| 143 | 145 |
typedef typename Parent::Value Value; |
| 144 | 146 |
|
| 145 | 147 |
ConstMap() { }
|
| 146 | 148 |
///\e |
| 147 | 149 |
V operator[](const K&) const { return v; }
|
| 148 | 150 |
///\e |
| 149 | 151 |
void set(const K&, const V&) { }
|
| 150 | 152 |
}; |
| 151 | 153 |
|
| 152 |
///Returns a \c ConstMap class |
|
| 154 |
///Returns a \c ConstMap class with inlined value |
|
| 153 | 155 |
|
| 154 | 156 |
///This function just returns a \c ConstMap class with inlined value. |
| 155 | 157 |
///\relates ConstMap |
| 156 | 158 |
template<typename K, typename V, V v> |
| 157 | 159 |
inline ConstMap<K, Const<V, v> > constMap() {
|
| 158 | 160 |
return ConstMap<K, Const<V, v> >(); |
| 159 | 161 |
} |
| 160 | 162 |
|
| 161 |
///Map based on std::map |
|
| 163 |
///Map based on \c std::map |
|
| 162 | 164 |
|
| 163 | 165 |
///This is essentially a wrapper for \c std::map with addition that |
| 164 | 166 |
///you can specify a default value different from \c Value(). |
| 167 |
///It meets the \ref concepts::ReferenceMap "ReferenceMap" concept. |
|
| 165 | 168 |
template <typename K, typename T, typename Compare = std::less<K> > |
| 166 |
class StdMap {
|
|
| 169 |
class StdMap : public MapBase<K, T> {
|
|
| 167 | 170 |
template <typename K1, typename T1, typename C1> |
| 168 | 171 |
friend class StdMap; |
| 169 | 172 |
public: |
| 170 | 173 |
|
| 171 |
typedef |
|
| 174 |
typedef MapBase<K, T> Parent; |
|
| 172 | 175 |
///Key type |
| 173 |
typedef |
|
| 176 |
typedef typename Parent::Key Key; |
|
| 174 | 177 |
///Value type |
| 175 |
typedef |
|
| 178 |
typedef typename Parent::Value Value; |
|
| 176 | 179 |
///Reference Type |
| 177 | 180 |
typedef T& Reference; |
| 178 | 181 |
///Const reference type |
| 179 | 182 |
typedef const T& ConstReference; |
| 180 | 183 |
|
| 184 |
typedef True ReferenceMapTag; |
|
| 185 |
|
|
| 181 | 186 |
private: |
| 182 | 187 |
|
| 183 | 188 |
typedef std::map<K, T, Compare> Map; |
| 184 | 189 |
Value _value; |
| 185 | 190 |
Map _map; |
| 186 | 191 |
|
| 187 | 192 |
public: |
| 188 | 193 |
|
| 189 | 194 |
/// Constructor with specified default value |
| 190 | 195 |
StdMap(const T& value = T()) : _value(value) {}
|
| 191 |
/// \brief Constructs the map from an appropriate std::map, and explicitly |
|
| 192 |
/// specifies a default value. |
|
| 196 |
/// \brief Constructs the map from an appropriate \c std::map, and |
|
| 197 |
/// explicitly specifies a default value. |
|
| 193 | 198 |
template <typename T1, typename Comp1> |
| 194 | 199 |
StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) |
| 195 | 200 |
: _map(map.begin(), map.end()), _value(value) {}
|
| 196 | 201 |
|
| 197 |
/// \brief Constructs a map from an other StdMap. |
|
| 202 |
/// \brief Constructs a map from an other \ref StdMap. |
|
| 198 | 203 |
template<typename T1, typename Comp1> |
| 199 | 204 |
StdMap(const StdMap<Key, T1, Comp1> &c) |
| 200 | 205 |
: _map(c._map.begin(), c._map.end()), _value(c._value) {}
|
| 201 | 206 |
|
| 202 | 207 |
private: |
| 203 | 208 |
|
| 204 | 209 |
StdMap& operator=(const StdMap&); |
| 205 | 210 |
|
| 206 | 211 |
public: |
| 207 | 212 |
|
| 208 | 213 |
///\e |
| 209 | 214 |
Reference operator[](const Key &k) {
|
| ... | ... |
@@ -231,66 +236,90 @@ |
| 231 | 236 |
else |
| 232 | 237 |
_map.insert(it, std::make_pair(k, t)); |
| 233 | 238 |
} |
| 234 | 239 |
|
| 235 | 240 |
/// \e |
| 236 | 241 |
void setAll(const T &t) {
|
| 237 | 242 |
_value = t; |
| 238 | 243 |
_map.clear(); |
| 239 | 244 |
} |
| 240 | 245 |
|
| 241 | 246 |
}; |
| 242 | 247 |
|
| 248 |
///Returns a \c StdMap class |
|
| 249 |
|
|
| 250 |
///This function just returns a \c StdMap class with specified |
|
| 251 |
///default value. |
|
| 252 |
///\relates StdMap |
|
| 253 |
template<typename K, typename V, typename Compare = std::less<K> > |
|
| 254 |
inline StdMap<K, V, Compare> stdMap(const V& value = V()) {
|
|
| 255 |
return StdMap<K, V, Compare>(value); |
|
| 256 |
} |
|
| 257 |
|
|
| 258 |
///Returns a \c StdMap class created from an appropriate std::map |
|
| 259 |
|
|
| 260 |
///This function just returns a \c StdMap class created from an |
|
| 261 |
///appropriate std::map. |
|
| 262 |
///\relates StdMap |
|
| 263 |
template<typename K, typename V, typename Compare = std::less<K> > |
|
| 264 |
inline StdMap<K, V, Compare> stdMap( const std::map<K, V, Compare> &map, |
|
| 265 |
const V& value = V() ) {
|
|
| 266 |
return StdMap<K, V, Compare>(map, value); |
|
| 267 |
} |
|
| 268 |
|
|
| 243 | 269 |
/// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt> |
| 244 | 270 |
/// |
| 245 |
/// |
|
| 271 |
/// This map has the <tt>[0..size-1]</tt> keyset and the values |
|
| 246 | 272 |
/// are stored in a \c std::vector<T> container. It can be used with |
| 247 | 273 |
/// some data structures, for example \c UnionFind, \c BinHeap, when |
| 248 | 274 |
/// the used items are small integer numbers. |
| 275 |
/// This map meets the \ref concepts::ReferenceMap "ReferenceMap" concept. |
|
| 249 | 276 |
/// |
| 250 | 277 |
/// \todo Revise its name |
| 251 | 278 |
template <typename T> |
| 252 |
class IntegerMap {
|
|
| 279 |
class IntegerMap : public MapBase<int, T> {
|
|
| 253 | 280 |
|
| 254 | 281 |
template <typename T1> |
| 255 | 282 |
friend class IntegerMap; |
| 256 | 283 |
|
| 257 | 284 |
public: |
| 258 | 285 |
|
| 259 |
typedef |
|
| 286 |
typedef MapBase<int, T> Parent; |
|
| 260 | 287 |
///\e |
| 261 |
typedef |
|
| 288 |
typedef typename Parent::Key Key; |
|
| 262 | 289 |
///\e |
| 263 |
typedef |
|
| 290 |
typedef typename Parent::Value Value; |
|
| 264 | 291 |
///\e |
| 265 | 292 |
typedef T& Reference; |
| 266 | 293 |
///\e |
| 267 | 294 |
typedef const T& ConstReference; |
| 268 | 295 |
|
| 296 |
typedef True ReferenceMapTag; |
|
| 297 |
|
|
| 269 | 298 |
private: |
| 270 | 299 |
|
| 271 | 300 |
typedef std::vector<T> Vector; |
| 272 | 301 |
Vector _vector; |
| 273 | 302 |
|
| 274 | 303 |
public: |
| 275 | 304 |
|
| 276 | 305 |
/// Constructor with specified default value |
| 277 | 306 |
IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {}
|
| 278 | 307 |
|
| 279 |
/// \brief Constructs the map from an appropriate std::vector. |
|
| 308 |
/// \brief Constructs the map from an appropriate \c std::vector. |
|
| 280 | 309 |
template <typename T1> |
| 281 | 310 |
IntegerMap(const std::vector<T1>& vector) |
| 282 | 311 |
: _vector(vector.begin(), vector.end()) {}
|
| 283 | 312 |
|
| 284 |
/// \brief Constructs a map from an other IntegerMap. |
|
| 313 |
/// \brief Constructs a map from an other \ref IntegerMap. |
|
| 285 | 314 |
template <typename T1> |
| 286 | 315 |
IntegerMap(const IntegerMap<T1> &c) |
| 287 | 316 |
: _vector(c._vector.begin(), c._vector.end()) {}
|
| 288 | 317 |
|
| 289 | 318 |
/// \brief Resize the container |
| 290 | 319 |
void resize(int size, const T& value = T()) {
|
| 291 | 320 |
_vector.resize(size, value); |
| 292 | 321 |
} |
| 293 | 322 |
|
| 294 | 323 |
private: |
| 295 | 324 |
|
| 296 | 325 |
IntegerMap& operator=(const IntegerMap&); |
| ... | ... |
@@ -305,24 +334,33 @@ |
| 305 | 334 |
/// \e |
| 306 | 335 |
ConstReference operator[](Key k) const {
|
| 307 | 336 |
return _vector[k]; |
| 308 | 337 |
} |
| 309 | 338 |
|
| 310 | 339 |
/// \e |
| 311 | 340 |
void set(const Key &k, const T& t) {
|
| 312 | 341 |
_vector[k] = t; |
| 313 | 342 |
} |
| 314 | 343 |
|
| 315 | 344 |
}; |
| 316 | 345 |
|
| 346 |
///Returns an \c IntegerMap class |
|
| 347 |
|
|
| 348 |
///This function just returns an \c IntegerMap class. |
|
| 349 |
///\relates IntegerMap |
|
| 350 |
template<typename T> |
|
| 351 |
inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) {
|
|
| 352 |
return IntegerMap<T>(size, value); |
|
| 353 |
} |
|
| 354 |
|
|
| 317 | 355 |
/// @} |
| 318 | 356 |
|
| 319 | 357 |
/// \addtogroup map_adaptors |
| 320 | 358 |
/// @{
|
| 321 | 359 |
|
| 322 | 360 |
/// \brief Identity map. |
| 323 | 361 |
/// |
| 324 | 362 |
/// This map gives back the given key as value without any |
| 325 | 363 |
/// modification. |
| 326 | 364 |
template <typename T> |
| 327 | 365 |
class IdentityMap : public MapBase<T, T> {
|
| 328 | 366 |
public: |
| ... | ... |
@@ -340,44 +378,42 @@ |
| 340 | 378 |
|
| 341 | 379 |
///This function just returns an \c IdentityMap class. |
| 342 | 380 |
///\relates IdentityMap |
| 343 | 381 |
template<typename T> |
| 344 | 382 |
inline IdentityMap<T> identityMap() {
|
| 345 | 383 |
return IdentityMap<T>(); |
| 346 | 384 |
} |
| 347 | 385 |
|
| 348 | 386 |
|
| 349 | 387 |
///\brief Convert the \c Value of a map to another type using |
| 350 | 388 |
///the default conversion. |
| 351 | 389 |
/// |
| 352 |
///This \ |
|
| 390 |
///This \ref concepts::ReadMap "read only map" |
|
| 353 | 391 |
///converts the \c Value of a map to type \c T. |
| 354 | 392 |
///Its \c Key is inherited from \c M. |
| 355 | 393 |
template <typename M, typename T> |
| 356 | 394 |
class ConvertMap : public MapBase<typename M::Key, T> {
|
| 357 | 395 |
const M& m; |
| 358 | 396 |
public: |
| 359 | 397 |
typedef MapBase<typename M::Key, T> Parent; |
| 360 | 398 |
typedef typename Parent::Key Key; |
| 361 | 399 |
typedef typename Parent::Value Value; |
| 362 | 400 |
|
| 363 | 401 |
///Constructor |
| 364 | 402 |
|
| 365 | 403 |
///Constructor. |
| 366 | 404 |
///\param _m is the underlying map. |
| 367 | 405 |
ConvertMap(const M &_m) : m(_m) {};
|
| 368 | 406 |
|
| 369 |
/// \brief The subscript operator. |
|
| 370 |
/// |
|
| 371 |
/// |
|
| 407 |
///\e |
|
| 372 | 408 |
Value operator[](const Key& k) const {return m[k];}
|
| 373 | 409 |
}; |
| 374 | 410 |
|
| 375 | 411 |
///Returns a \c ConvertMap class |
| 376 | 412 |
|
| 377 | 413 |
///This function just returns a \c ConvertMap class. |
| 378 | 414 |
///\relates ConvertMap |
| 379 | 415 |
template<typename T, typename M> |
| 380 | 416 |
inline ConvertMap<M, T> convertMap(const M &m) {
|
| 381 | 417 |
return ConvertMap<M, T>(m); |
| 382 | 418 |
} |
| 383 | 419 |
|
| ... | ... |
@@ -397,87 +433,105 @@ |
| 397 | 433 |
|
| 398 | 434 |
public: |
| 399 | 435 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 400 | 436 |
typedef typename Parent::Key Key; |
| 401 | 437 |
typedef typename Parent::Value Value; |
| 402 | 438 |
|
| 403 | 439 |
///Constructor |
| 404 | 440 |
SimpleMap(const M &_m) : m(_m) {};
|
| 405 | 441 |
///\e |
| 406 | 442 |
Value operator[](Key k) const {return m[k];}
|
| 407 | 443 |
}; |
| 408 | 444 |
|
| 445 |
///Returns a \c SimpleMap class |
|
| 446 |
|
|
| 447 |
///This function just returns a \c SimpleMap class. |
|
| 448 |
///\relates SimpleMap |
|
| 449 |
template<typename M> |
|
| 450 |
inline SimpleMap<M> simpleMap(const M &m) {
|
|
| 451 |
return SimpleMap<M>(m); |
|
| 452 |
} |
|
| 453 |
|
|
| 409 | 454 |
///Simple writable wrapping of a map |
| 410 | 455 |
|
| 411 |
///This \ref concepts:: |
|
| 456 |
///This \ref concepts::ReadWriteMap "read-write map" returns the simple |
|
| 412 | 457 |
///wrapping of the given map. Sometimes the reference maps cannot be |
| 413 | 458 |
///combined with simple read-write maps. This map adaptor wraps the |
| 414 | 459 |
///given map to simple read-write map. |
| 415 | 460 |
/// |
| 416 | 461 |
///\sa SimpleMap |
| 417 | 462 |
/// |
| 418 | 463 |
/// \todo Revise the misleading name |
| 419 | 464 |
template<typename M> |
| 420 | 465 |
class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
| 421 | 466 |
M& m; |
| 422 | 467 |
|
| 423 | 468 |
public: |
| 424 | 469 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 425 | 470 |
typedef typename Parent::Key Key; |
| 426 | 471 |
typedef typename Parent::Value Value; |
| 427 | 472 |
|
| 428 | 473 |
///Constructor |
| 429 | 474 |
SimpleWriteMap(M &_m) : m(_m) {};
|
| 430 | 475 |
///\e |
| 431 | 476 |
Value operator[](Key k) const {return m[k];}
|
| 432 | 477 |
///\e |
| 433 | 478 |
void set(Key k, const Value& c) { m.set(k, c); }
|
| 434 | 479 |
}; |
| 435 | 480 |
|
| 481 |
///Returns a \c SimpleWriteMap class |
|
| 482 |
|
|
| 483 |
///This function just returns a \c SimpleWriteMap class. |
|
| 484 |
///\relates SimpleWriteMap |
|
| 485 |
template<typename M> |
|
| 486 |
inline SimpleWriteMap<M> simpleWriteMap(M &m) {
|
|
| 487 |
return SimpleWriteMap<M>(m); |
|
| 488 |
} |
|
| 489 |
|
|
| 436 | 490 |
///Sum of two maps |
| 437 | 491 |
|
| 438 |
///This \ |
|
| 492 |
///This \ref concepts::ReadMap "read only map" returns the sum of the two |
|
| 439 | 493 |
///given maps. |
| 440 | 494 |
///Its \c Key and \c Value are inherited from \c M1. |
| 441 |
///The \c Key and \c Value of M2 must be convertible to those of \c M1. |
|
| 495 |
///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
|
| 442 | 496 |
template<typename M1, typename M2> |
| 443 | 497 |
class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 444 | 498 |
const M1& m1; |
| 445 | 499 |
const M2& m2; |
| 446 | 500 |
|
| 447 | 501 |
public: |
| 448 | 502 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 449 | 503 |
typedef typename Parent::Key Key; |
| 450 | 504 |
typedef typename Parent::Value Value; |
| 451 | 505 |
|
| 452 | 506 |
///Constructor |
| 453 | 507 |
AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
|
| 454 | 508 |
///\e |
| 455 | 509 |
Value operator[](Key k) const {return m1[k]+m2[k];}
|
| 456 | 510 |
}; |
| 457 | 511 |
|
| 458 | 512 |
///Returns an \c AddMap class |
| 459 | 513 |
|
| 460 | 514 |
///This function just returns an \c AddMap class. |
| 461 |
///\todo |
|
| 515 |
///\todo Extend the documentation: how to call these type of functions? |
|
| 462 | 516 |
/// |
| 463 | 517 |
///\relates AddMap |
| 464 | 518 |
template<typename M1, typename M2> |
| 465 | 519 |
inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
|
| 466 | 520 |
return AddMap<M1, M2>(m1,m2); |
| 467 | 521 |
} |
| 468 | 522 |
|
| 469 | 523 |
///Shift a map with a constant. |
| 470 | 524 |
|
| 471 |
///This \ |
|
| 525 |
///This \ref concepts::ReadMap "read only map" returns the sum of the |
|
| 472 | 526 |
///given map and a constant value. |
| 473 | 527 |
///Its \c Key and \c Value are inherited from \c M. |
| 474 | 528 |
/// |
| 475 | 529 |
///Actually, |
| 476 | 530 |
///\code |
| 477 | 531 |
/// ShiftMap<X> sh(x,v); |
| 478 | 532 |
///\endcode |
| 479 | 533 |
///is equivalent to |
| 480 | 534 |
///\code |
| 481 | 535 |
/// ConstMap<X::Key, X::Value> c_tmp(v); |
| 482 | 536 |
/// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v); |
| 483 | 537 |
///\endcode |
| ... | ... |
@@ -495,25 +549,25 @@ |
| 495 | 549 |
///Constructor |
| 496 | 550 |
|
| 497 | 551 |
///Constructor. |
| 498 | 552 |
///\param _m is the undelying map. |
| 499 | 553 |
///\param _v is the shift value. |
| 500 | 554 |
ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
|
| 501 | 555 |
///\e |
| 502 | 556 |
Value operator[](Key k) const {return m[k] + v;}
|
| 503 | 557 |
}; |
| 504 | 558 |
|
| 505 | 559 |
///Shift a map with a constant (ReadWrite version). |
| 506 | 560 |
|
| 507 |
///This \ |
|
| 561 |
///This \ref concepts::ReadWriteMap "read-write map" returns the sum of the |
|
| 508 | 562 |
///given map and a constant value. It makes also possible to write the map. |
| 509 | 563 |
///Its \c Key and \c Value are inherited from \c M. |
| 510 | 564 |
/// |
| 511 | 565 |
///\sa ShiftMap |
| 512 | 566 |
template<typename M, typename C = typename M::Value> |
| 513 | 567 |
class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
| 514 | 568 |
M& m; |
| 515 | 569 |
C v; |
| 516 | 570 |
public: |
| 517 | 571 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 518 | 572 |
typedef typename Parent::Key Key; |
| 519 | 573 |
typedef typename Parent::Value Value; |
| ... | ... |
@@ -541,25 +595,25 @@ |
| 541 | 595 |
|
| 542 | 596 |
///Returns a \c ShiftWriteMap class |
| 543 | 597 |
|
| 544 | 598 |
///This function just returns a \c ShiftWriteMap class. |
| 545 | 599 |
///\relates ShiftWriteMap |
| 546 | 600 |
template<typename M, typename C> |
| 547 | 601 |
inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) {
|
| 548 | 602 |
return ShiftWriteMap<M, C>(m,v); |
| 549 | 603 |
} |
| 550 | 604 |
|
| 551 | 605 |
///Difference of two maps |
| 552 | 606 |
|
| 553 |
///This \ |
|
| 607 |
///This \ref concepts::ReadMap "read only map" returns the difference |
|
| 554 | 608 |
///of the values of the two given maps. |
| 555 | 609 |
///Its \c Key and \c Value are inherited from \c M1. |
| 556 | 610 |
///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
| 557 | 611 |
/// |
| 558 | 612 |
/// \todo Revise the misleading name |
| 559 | 613 |
template<typename M1, typename M2> |
| 560 | 614 |
class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 561 | 615 |
const M1& m1; |
| 562 | 616 |
const M2& m2; |
| 563 | 617 |
public: |
| 564 | 618 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 565 | 619 |
typedef typename Parent::Key Key; |
| ... | ... |
@@ -574,25 +628,25 @@ |
| 574 | 628 |
///Returns a \c SubMap class |
| 575 | 629 |
|
| 576 | 630 |
///This function just returns a \c SubMap class. |
| 577 | 631 |
/// |
| 578 | 632 |
///\relates SubMap |
| 579 | 633 |
template<typename M1, typename M2> |
| 580 | 634 |
inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
|
| 581 | 635 |
return SubMap<M1, M2>(m1, m2); |
| 582 | 636 |
} |
| 583 | 637 |
|
| 584 | 638 |
///Product of two maps |
| 585 | 639 |
|
| 586 |
///This \ |
|
| 640 |
///This \ref concepts::ReadMap "read only map" returns the product of the |
|
| 587 | 641 |
///values of the two given maps. |
| 588 | 642 |
///Its \c Key and \c Value are inherited from \c M1. |
| 589 | 643 |
///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
| 590 | 644 |
template<typename M1, typename M2> |
| 591 | 645 |
class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 592 | 646 |
const M1& m1; |
| 593 | 647 |
const M2& m2; |
| 594 | 648 |
public: |
| 595 | 649 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 596 | 650 |
typedef typename Parent::Key Key; |
| 597 | 651 |
typedef typename Parent::Value Value; |
| 598 | 652 |
|
| ... | ... |
@@ -604,25 +658,25 @@ |
| 604 | 658 |
|
| 605 | 659 |
///Returns a \c MulMap class |
| 606 | 660 |
|
| 607 | 661 |
///This function just returns a \c MulMap class. |
| 608 | 662 |
///\relates MulMap |
| 609 | 663 |
template<typename M1, typename M2> |
| 610 | 664 |
inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
|
| 611 | 665 |
return MulMap<M1, M2>(m1,m2); |
| 612 | 666 |
} |
| 613 | 667 |
|
| 614 | 668 |
///Scales a map with a constant. |
| 615 | 669 |
|
| 616 |
///This \ |
|
| 670 |
///This \ref concepts::ReadMap "read only map" returns the value of the |
|
| 617 | 671 |
///given map multiplied from the left side with a constant value. |
| 618 | 672 |
///Its \c Key and \c Value are inherited from \c M. |
| 619 | 673 |
/// |
| 620 | 674 |
///Actually, |
| 621 | 675 |
///\code |
| 622 | 676 |
/// ScaleMap<X> sc(x,v); |
| 623 | 677 |
///\endcode |
| 624 | 678 |
///is equivalent to |
| 625 | 679 |
///\code |
| 626 | 680 |
/// ConstMap<X::Key, X::Value> c_tmp(v); |
| 627 | 681 |
/// MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v); |
| 628 | 682 |
///\endcode |
| ... | ... |
@@ -640,25 +694,25 @@ |
| 640 | 694 |
///Constructor |
| 641 | 695 |
|
| 642 | 696 |
///Constructor. |
| 643 | 697 |
///\param _m is the undelying map. |
| 644 | 698 |
///\param _v is the scaling value. |
| 645 | 699 |
ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
|
| 646 | 700 |
/// \e |
| 647 | 701 |
Value operator[](Key k) const {return v * m[k];}
|
| 648 | 702 |
}; |
| 649 | 703 |
|
| 650 | 704 |
///Scales a map with a constant (ReadWrite version). |
| 651 | 705 |
|
| 652 |
///This \ |
|
| 706 |
///This \ref concepts::ReadWriteMap "read-write map" returns the value of the |
|
| 653 | 707 |
///given map multiplied from the left side with a constant value. It can |
| 654 | 708 |
///also be used as write map if the \c / operator is defined between |
| 655 | 709 |
///\c Value and \c C and the given multiplier is not zero. |
| 656 | 710 |
///Its \c Key and \c Value are inherited from \c M. |
| 657 | 711 |
/// |
| 658 | 712 |
///\sa ScaleMap |
| 659 | 713 |
template<typename M, typename C = typename M::Value> |
| 660 | 714 |
class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
| 661 | 715 |
M& m; |
| 662 | 716 |
C v; |
| 663 | 717 |
public: |
| 664 | 718 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| ... | ... |
@@ -688,25 +742,25 @@ |
| 688 | 742 |
|
| 689 | 743 |
///Returns a \c ScaleWriteMap class |
| 690 | 744 |
|
| 691 | 745 |
///This function just returns a \c ScaleWriteMap class. |
| 692 | 746 |
///\relates ScaleWriteMap |
| 693 | 747 |
template<typename M, typename C> |
| 694 | 748 |
inline ScaleWriteMap<M, C> scaleMap(M &m,const C &v) {
|
| 695 | 749 |
return ScaleWriteMap<M, C>(m,v); |
| 696 | 750 |
} |
| 697 | 751 |
|
| 698 | 752 |
///Quotient of two maps |
| 699 | 753 |
|
| 700 |
///This \ |
|
| 754 |
///This \ref concepts::ReadMap "read only map" returns the quotient of the |
|
| 701 | 755 |
///values of the two given maps. |
| 702 | 756 |
///Its \c Key and \c Value are inherited from \c M1. |
| 703 | 757 |
///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
| 704 | 758 |
template<typename M1, typename M2> |
| 705 | 759 |
class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 706 | 760 |
const M1& m1; |
| 707 | 761 |
const M2& m2; |
| 708 | 762 |
public: |
| 709 | 763 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 710 | 764 |
typedef typename Parent::Key Key; |
| 711 | 765 |
typedef typename Parent::Value Value; |
| 712 | 766 |
|
| ... | ... |
@@ -718,25 +772,25 @@ |
| 718 | 772 |
|
| 719 | 773 |
///Returns a \c DivMap class |
| 720 | 774 |
|
| 721 | 775 |
///This function just returns a \c DivMap class. |
| 722 | 776 |
///\relates DivMap |
| 723 | 777 |
template<typename M1, typename M2> |
| 724 | 778 |
inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
|
| 725 | 779 |
return DivMap<M1, M2>(m1,m2); |
| 726 | 780 |
} |
| 727 | 781 |
|
| 728 | 782 |
///Composition of two maps |
| 729 | 783 |
|
| 730 |
///This \ |
|
| 784 |
///This \ref concepts::ReadMap "read only map" returns the composition of |
|
| 731 | 785 |
///two given maps. |
| 732 | 786 |
///That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2, |
| 733 | 787 |
///then for |
| 734 | 788 |
///\code |
| 735 | 789 |
/// ComposeMap<M1, M2> cm(m1,m2); |
| 736 | 790 |
///\endcode |
| 737 | 791 |
/// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>. |
| 738 | 792 |
/// |
| 739 | 793 |
///Its \c Key is inherited from \c M2 and its \c Value is from \c M1. |
| 740 | 794 |
///\c M2::Value must be convertible to \c M1::Key. |
| 741 | 795 |
/// |
| 742 | 796 |
///\sa CombineMap |
| ... | ... |
@@ -769,25 +823,25 @@ |
| 769 | 823 |
|
| 770 | 824 |
///This function just returns a \c ComposeMap class. |
| 771 | 825 |
///\relates ComposeMap |
| 772 | 826 |
template <typename M1, typename M2> |
| 773 | 827 |
inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
|
| 774 | 828 |
return ComposeMap<M1, M2>(m1,m2); |
| 775 | 829 |
} |
| 776 | 830 |
|
| 777 | 831 |
///Combine of two maps using an STL (binary) functor. |
| 778 | 832 |
|
| 779 | 833 |
///Combine of two maps using an STL (binary) functor. |
| 780 | 834 |
/// |
| 781 |
///This \ |
|
| 835 |
///This \ref concepts::ReadMap "read only map" takes two maps and a |
|
| 782 | 836 |
///binary functor and returns the composition of the two |
| 783 | 837 |
///given maps unsing the functor. |
| 784 | 838 |
///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2 |
| 785 | 839 |
///and \c f is of \c F, then for |
| 786 | 840 |
///\code |
| 787 | 841 |
/// CombineMap<M1,M2,F,V> cm(m1,m2,f); |
| 788 | 842 |
///\endcode |
| 789 | 843 |
/// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt> |
| 790 | 844 |
/// |
| 791 | 845 |
///Its \c Key is inherited from \c M1 and its \c Value is \c V. |
| 792 | 846 |
///\c M2::Value and \c M1::Value must be convertible to the corresponding |
| 793 | 847 |
///input parameter of \c F and the return type of \c F must be convertible |
| ... | ... |
@@ -842,47 +896,47 @@ |
| 842 | 896 |
combineMap(const M1& m1, const M2& m2, const F& f) {
|
| 843 | 897 |
return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f); |
| 844 | 898 |
} |
| 845 | 899 |
|
| 846 | 900 |
template<typename M1, typename M2, typename K1, typename K2, typename V> |
| 847 | 901 |
inline CombineMap<M1, M2, V (*)(K1, K2), V> |
| 848 | 902 |
combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
|
| 849 | 903 |
return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f); |
| 850 | 904 |
} |
| 851 | 905 |
|
| 852 | 906 |
///Negative value of a map |
| 853 | 907 |
|
| 854 |
///This \ |
|
| 908 |
///This \ref concepts::ReadMap "read only map" returns the negative |
|
| 855 | 909 |
///value of the value returned by the given map. |
| 856 | 910 |
///Its \c Key and \c Value are inherited from \c M. |
| 857 | 911 |
///The unary \c - operator must be defined for \c Value, of course. |
| 858 | 912 |
/// |
| 859 | 913 |
///\sa NegWriteMap |
| 860 | 914 |
template<typename M> |
| 861 | 915 |
class NegMap : public MapBase<typename M::Key, typename M::Value> {
|
| 862 | 916 |
const M& m; |
| 863 | 917 |
public: |
| 864 | 918 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 865 | 919 |
typedef typename Parent::Key Key; |
| 866 | 920 |
typedef typename Parent::Value Value; |
| 867 | 921 |
|
| 868 | 922 |
///Constructor |
| 869 | 923 |
NegMap(const M &_m) : m(_m) {};
|
| 870 | 924 |
/// \e |
| 871 | 925 |
Value operator[](Key k) const {return -m[k];}
|
| 872 | 926 |
}; |
| 873 | 927 |
|
| 874 | 928 |
///Negative value of a map (ReadWrite version) |
| 875 | 929 |
|
| 876 |
///This \ |
|
| 930 |
///This \ref concepts::ReadWriteMap "read-write map" returns the negative |
|
| 877 | 931 |
///value of the value returned by the given map. |
| 878 | 932 |
///Its \c Key and \c Value are inherited from \c M. |
| 879 | 933 |
///The unary \c - operator must be defined for \c Value, of course. |
| 880 | 934 |
/// |
| 881 | 935 |
/// \sa NegMap |
| 882 | 936 |
template<typename M> |
| 883 | 937 |
class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
| 884 | 938 |
M& m; |
| 885 | 939 |
public: |
| 886 | 940 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 887 | 941 |
typedef typename Parent::Key Key; |
| 888 | 942 |
typedef typename Parent::Value Value; |
| ... | ... |
@@ -906,25 +960,25 @@ |
| 906 | 960 |
|
| 907 | 961 |
///Returns a \c NegWriteMap class |
| 908 | 962 |
|
| 909 | 963 |
///This function just returns a \c NegWriteMap class. |
| 910 | 964 |
///\relates NegWriteMap |
| 911 | 965 |
template <typename M> |
| 912 | 966 |
inline NegWriteMap<M> negMap(M &m) {
|
| 913 | 967 |
return NegWriteMap<M>(m); |
| 914 | 968 |
} |
| 915 | 969 |
|
| 916 | 970 |
///Absolute value of a map |
| 917 | 971 |
|
| 918 |
///This \ |
|
| 972 |
///This \ref concepts::ReadMap "read only map" returns the absolute value |
|
| 919 | 973 |
///of the value returned by the given map. |
| 920 | 974 |
///Its \c Key and \c Value are inherited from \c M. |
| 921 | 975 |
///\c Value must be comparable to \c 0 and the unary \c - |
| 922 | 976 |
///operator must be defined for it, of course. |
| 923 | 977 |
template<typename M> |
| 924 | 978 |
class AbsMap : public MapBase<typename M::Key, typename M::Value> {
|
| 925 | 979 |
const M& m; |
| 926 | 980 |
public: |
| 927 | 981 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 928 | 982 |
typedef typename Parent::Key Key; |
| 929 | 983 |
typedef typename Parent::Value Value; |
| 930 | 984 |
|
| ... | ... |
@@ -940,83 +994,85 @@ |
| 940 | 994 |
|
| 941 | 995 |
///Returns an \c AbsMap class |
| 942 | 996 |
|
| 943 | 997 |
///This function just returns an \c AbsMap class. |
| 944 | 998 |
///\relates AbsMap |
| 945 | 999 |
template<typename M> |
| 946 | 1000 |
inline AbsMap<M> absMap(const M &m) {
|
| 947 | 1001 |
return AbsMap<M>(m); |
| 948 | 1002 |
} |
| 949 | 1003 |
|
| 950 | 1004 |
///Converts an STL style functor to a map |
| 951 | 1005 |
|
| 952 |
///This \ |
|
| 1006 |
///This \ref concepts::ReadMap "read only map" returns the value |
|
| 953 | 1007 |
///of a given functor. |
| 954 | 1008 |
/// |
| 955 | 1009 |
///Template parameters \c K and \c V will become its |
| 956 | 1010 |
///\c Key and \c Value. |
| 957 | 1011 |
///In most cases they have to be given explicitly because a |
| 958 |
///functor typically does not provide |
|
| 1012 |
///functor typically does not provide \c argument_type and |
|
| 1013 |
///\c result_type typedefs. |
|
| 959 | 1014 |
/// |
| 960 | 1015 |
///Parameter \c F is the type of the used functor. |
| 961 | 1016 |
/// |
| 962 | 1017 |
///\sa MapFunctor |
| 963 | 1018 |
template<typename F, |
| 964 | 1019 |
typename K = typename F::argument_type, |
| 965 | 1020 |
typename V = typename F::result_type> |
| 966 | 1021 |
class FunctorMap : public MapBase<K, V> {
|
| 967 | 1022 |
F f; |
| 968 | 1023 |
public: |
| 969 | 1024 |
typedef MapBase<K, V> Parent; |
| 970 | 1025 |
typedef typename Parent::Key Key; |
| 971 | 1026 |
typedef typename Parent::Value Value; |
| 972 | 1027 |
|
| 973 | 1028 |
///Constructor |
| 974 | 1029 |
FunctorMap(const F &_f = F()) : f(_f) {}
|
| 975 | 1030 |
/// \e |
| 976 | 1031 |
Value operator[](Key k) const { return f(k);}
|
| 977 | 1032 |
}; |
| 978 | 1033 |
|
| 979 | 1034 |
///Returns a \c FunctorMap class |
| 980 | 1035 |
|
| 981 | 1036 |
///This function just returns a \c FunctorMap class. |
| 982 | 1037 |
/// |
| 983 |
///It is specialized for adaptable function classes and |
|
| 984 |
///C++ functions. |
|
| 1038 |
///This function is specialized for adaptable binary function |
|
| 1039 |
///classes and C++ functions. |
|
| 1040 |
/// |
|
| 985 | 1041 |
///\relates FunctorMap |
| 986 | 1042 |
template<typename K, typename V, typename F> inline |
| 987 | 1043 |
FunctorMap<F, K, V> functorMap(const F &f) {
|
| 988 | 1044 |
return FunctorMap<F, K, V>(f); |
| 989 | 1045 |
} |
| 990 | 1046 |
|
| 991 | 1047 |
template <typename F> inline |
| 992 | 1048 |
FunctorMap<F, typename F::argument_type, typename F::result_type> |
| 993 | 1049 |
functorMap(const F &f) {
|
| 994 | 1050 |
return FunctorMap<F, typename F::argument_type, |
| 995 | 1051 |
typename F::result_type>(f); |
| 996 | 1052 |
} |
| 997 | 1053 |
|
| 998 | 1054 |
template <typename K, typename V> inline |
| 999 | 1055 |
FunctorMap<V (*)(K), K, V> functorMap(V (*f)(K)) {
|
| 1000 | 1056 |
return FunctorMap<V (*)(K), K, V>(f); |
| 1001 | 1057 |
} |
| 1002 | 1058 |
|
| 1003 | 1059 |
|
| 1004 | 1060 |
///Converts a map to an STL style (unary) functor |
| 1005 | 1061 |
|
| 1006 | 1062 |
///This class Converts a map to an STL style (unary) functor. |
| 1007 |
/// |
|
| 1063 |
///That is it provides an <tt>operator()</tt> to read its values. |
|
| 1008 | 1064 |
/// |
| 1009 | 1065 |
///For the sake of convenience it also works as |
| 1010 |
///a ususal \ |
|
| 1066 |
///a ususal \ref concepts::ReadMap "readable map", |
|
| 1011 | 1067 |
///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. |
| 1012 | 1068 |
/// |
| 1013 | 1069 |
///\sa FunctorMap |
| 1014 | 1070 |
template <typename M> |
| 1015 | 1071 |
class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
|
| 1016 | 1072 |
const M& m; |
| 1017 | 1073 |
public: |
| 1018 | 1074 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 1019 | 1075 |
typedef typename Parent::Key Key; |
| 1020 | 1076 |
typedef typename Parent::Value Value; |
| 1021 | 1077 |
|
| 1022 | 1078 |
typedef typename M::Key argument_type; |
| ... | ... |
@@ -1030,62 +1086,62 @@ |
| 1030 | 1086 |
Value operator[](Key k) const {return m[k];}
|
| 1031 | 1087 |
}; |
| 1032 | 1088 |
|
| 1033 | 1089 |
///Returns a \c MapFunctor class |
| 1034 | 1090 |
|
| 1035 | 1091 |
///This function just returns a \c MapFunctor class. |
| 1036 | 1092 |
///\relates MapFunctor |
| 1037 | 1093 |
template<typename M> |
| 1038 | 1094 |
inline MapFunctor<M> mapFunctor(const M &m) {
|
| 1039 | 1095 |
return MapFunctor<M>(m); |
| 1040 | 1096 |
} |
| 1041 | 1097 |
|
| 1042 |
/// |
|
| 1098 |
///Just readable version of \ref ForkWriteMap |
|
| 1043 | 1099 |
|
| 1044 |
///This map has two \ |
|
| 1100 |
///This map has two \ref concepts::ReadMap "readable map" |
|
| 1045 | 1101 |
///parameters and each read request will be passed just to the |
| 1046 |
///first map. This class is the just readable map type of |
|
| 1102 |
///first map. This class is the just readable map type of \c ForkWriteMap. |
|
| 1047 | 1103 |
/// |
| 1048 | 1104 |
///The \c Key and \c Value are inherited from \c M1. |
| 1049 |
///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
|
| 1105 |
///The \c Key and \c Value of \c M2 must be convertible from those of \c M1. |
|
| 1050 | 1106 |
/// |
| 1051 | 1107 |
///\sa ForkWriteMap |
| 1052 | 1108 |
/// |
| 1053 | 1109 |
/// \todo Why is it needed? |
| 1054 | 1110 |
template<typename M1, typename M2> |
| 1055 | 1111 |
class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 1056 | 1112 |
const M1& m1; |
| 1057 | 1113 |
const M2& m2; |
| 1058 | 1114 |
public: |
| 1059 | 1115 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 1060 | 1116 |
typedef typename Parent::Key Key; |
| 1061 | 1117 |
typedef typename Parent::Value Value; |
| 1062 | 1118 |
|
| 1063 | 1119 |
///Constructor |
| 1064 | 1120 |
ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {};
|
| 1065 | 1121 |
/// \e |
| 1066 | 1122 |
Value operator[](Key k) const {return m1[k];}
|
| 1067 | 1123 |
}; |
| 1068 | 1124 |
|
| 1069 | 1125 |
|
| 1070 | 1126 |
///Applies all map setting operations to two maps |
| 1071 | 1127 |
|
| 1072 |
///This map has two \ |
|
| 1128 |
///This map has two \ref concepts::WriteMap "writable map" |
|
| 1073 | 1129 |
///parameters and each write request will be passed to both of them. |
| 1074 |
///If \c M1 is also \ |
|
| 1130 |
///If \c M1 is also \ref concepts::ReadMap "readable", |
|
| 1075 | 1131 |
///then the read operations will return the |
| 1076 | 1132 |
///corresponding values of \c M1. |
| 1077 | 1133 |
/// |
| 1078 | 1134 |
///The \c Key and \c Value are inherited from \c M1. |
| 1079 |
///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
|
| 1135 |
///The \c Key and \c Value of \c M2 must be convertible from those of \c M1. |
|
| 1080 | 1136 |
/// |
| 1081 | 1137 |
///\sa ForkMap |
| 1082 | 1138 |
template<typename M1, typename M2> |
| 1083 | 1139 |
class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 1084 | 1140 |
M1& m1; |
| 1085 | 1141 |
M2& m2; |
| 1086 | 1142 |
public: |
| 1087 | 1143 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 1088 | 1144 |
typedef typename Parent::Key Key; |
| 1089 | 1145 |
typedef typename Parent::Value Value; |
| 1090 | 1146 |
|
| 1091 | 1147 |
///Constructor |
| ... | ... |
@@ -1111,49 +1167,49 @@ |
| 1111 | 1167 |
///\relates ForkWriteMap |
| 1112 | 1168 |
template <typename M1, typename M2> |
| 1113 | 1169 |
inline ForkWriteMap<M1, M2> forkMap(M1 &m1, M2 &m2) {
|
| 1114 | 1170 |
return ForkWriteMap<M1, M2>(m1,m2); |
| 1115 | 1171 |
} |
| 1116 | 1172 |
|
| 1117 | 1173 |
|
| 1118 | 1174 |
|
| 1119 | 1175 |
/* ************* BOOL MAPS ******************* */ |
| 1120 | 1176 |
|
| 1121 | 1177 |
///Logical 'not' of a map |
| 1122 | 1178 |
|
| 1123 |
///This bool \ |
|
| 1179 |
///This bool \ref concepts::ReadMap "read only map" returns the |
|
| 1124 | 1180 |
///logical negation of the value returned by the given map. |
| 1125 |
///Its \c Key is inherited from \c M, its Value is \c bool. |
|
| 1181 |
///Its \c Key is inherited from \c M, its \c Value is \c bool. |
|
| 1126 | 1182 |
/// |
| 1127 | 1183 |
///\sa NotWriteMap |
| 1128 | 1184 |
template <typename M> |
| 1129 | 1185 |
class NotMap : public MapBase<typename M::Key, bool> {
|
| 1130 | 1186 |
const M& m; |
| 1131 | 1187 |
public: |
| 1132 | 1188 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1133 | 1189 |
typedef typename Parent::Key Key; |
| 1134 | 1190 |
typedef typename Parent::Value Value; |
| 1135 | 1191 |
|
| 1136 | 1192 |
/// Constructor |
| 1137 | 1193 |
NotMap(const M &_m) : m(_m) {};
|
| 1138 | 1194 |
///\e |
| 1139 | 1195 |
Value operator[](Key k) const {return !m[k];}
|
| 1140 | 1196 |
}; |
| 1141 | 1197 |
|
| 1142 | 1198 |
///Logical 'not' of a map (ReadWrie version) |
| 1143 | 1199 |
|
| 1144 |
///This bool \ |
|
| 1200 |
///This bool \ref concepts::ReadWriteMap "read-write map" returns the |
|
| 1145 | 1201 |
///logical negation of the value returned by the given map. When it is set, |
| 1146 | 1202 |
///the opposite value is set to the original map. |
| 1147 |
///Its \c Key is inherited from \c M, its Value is \c bool. |
|
| 1203 |
///Its \c Key is inherited from \c M, its \c Value is \c bool. |
|
| 1148 | 1204 |
/// |
| 1149 | 1205 |
///\sa NotMap |
| 1150 | 1206 |
template <typename M> |
| 1151 | 1207 |
class NotWriteMap : public MapBase<typename M::Key, bool> {
|
| 1152 | 1208 |
M& m; |
| 1153 | 1209 |
public: |
| 1154 | 1210 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1155 | 1211 |
typedef typename Parent::Key Key; |
| 1156 | 1212 |
typedef typename Parent::Value Value; |
| 1157 | 1213 |
|
| 1158 | 1214 |
/// Constructor |
| 1159 | 1215 |
NotWriteMap(M &_m) : m(_m) {};
|
| ... | ... |
@@ -1200,33 +1256,33 @@ |
| 1200 | 1256 |
template <typename _Iterator> |
| 1201 | 1257 |
struct IteratorTraits<_Iterator, |
| 1202 | 1258 |
typename exists<typename _Iterator::container_type>::type> |
| 1203 | 1259 |
{
|
| 1204 | 1260 |
typedef typename _Iterator::container_type::value_type Value; |
| 1205 | 1261 |
}; |
| 1206 | 1262 |
|
| 1207 | 1263 |
} |
| 1208 | 1264 |
|
| 1209 | 1265 |
|
| 1210 | 1266 |
/// \brief Writable bool map for logging each \c true assigned element |
| 1211 | 1267 |
/// |
| 1212 |
/// Writable bool map for logging each \c true assigned element, i.e it |
|
| 1213 |
/// copies all the keys set to \c true to the given iterator. |
|
| 1268 |
/// A \ref concepts::ReadWriteMap "read-write" bool map for logging |
|
| 1269 |
/// each \c true assigned element, i.e it copies all the keys set |
|
| 1270 |
/// to \c true to the given iterator. |
|
| 1214 | 1271 |
/// |
| 1215 | 1272 |
/// \note The container of the iterator should contain space |
| 1216 | 1273 |
/// for each element. |
| 1217 | 1274 |
/// |
| 1218 |
/// The following example shows how you can write the edges found by the Prim |
|
| 1219 |
/// algorithm directly |
|
| 1220 |
/// |
|
| 1275 |
/// The following example shows how you can write the edges found by |
|
| 1276 |
/// the \ref Prim algorithm directly to the standard output. |
|
| 1221 | 1277 |
///\code |
| 1222 | 1278 |
/// typedef IdMap<Graph, Edge> EdgeIdMap; |
| 1223 | 1279 |
/// EdgeIdMap edgeId(graph); |
| 1224 | 1280 |
/// |
| 1225 | 1281 |
/// typedef MapFunctor<EdgeIdMap> EdgeIdFunctor; |
| 1226 | 1282 |
/// EdgeIdFunctor edgeIdFunctor(edgeId); |
| 1227 | 1283 |
/// |
| 1228 | 1284 |
/// StoreBoolMap<ostream_iterator<int>, EdgeIdFunctor> |
| 1229 | 1285 |
/// writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor); |
| 1230 | 1286 |
/// |
| 1231 | 1287 |
/// prim(graph, cost, writerMap); |
| 1232 | 1288 |
///\endcode |
0 comments (0 inline)