gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 2 0
merge default
2 files changed with 124 insertions and 67 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
... ...
@@ -3,205 +3,206 @@
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_CONCEPT_MAPS_H
20 20
#define LEMON_CONCEPT_MAPS_H
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 37

	
38 38
    /// Readable map concept.
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]; 
63 64

	
64 65
	  ignore_unused_variable_warning(val);
65 66
	  ignore_unused_variable_warning(own_val);
66 67
	  ignore_unused_variable_warning(key);
67 68
	}
68 69
	Key& key;
69 70
	typename _ReadMap::Key& own_key;
70 71
	_ReadMap& m;
71 72
      };
72 73
      
73 74
    };
74 75

	
75 76

	
76 77
    /// Writable map concept
77 78
    
78 79
    /// Writable map concept.
79 80
    ///
80 81
    template<typename K, typename T>
81 82
    class WriteMap
82 83
    {
83 84
    public:
84 85
      /// The key type of the map.
85 86
      typedef K Key;    
86 87
      /// The value type of the map. (The type of objects associated with the keys).
87 88
      typedef T Value;
88 89

	
89 90
      /// Sets the value associated with a key.
90 91
      void set(const Key &,const Value &) {}
91 92

	
92 93
      ///Default constructor
93 94
      WriteMap() {}
94 95

	
95 96
      template <typename _WriteMap>
96 97
      struct Constraints {
97 98
	void constraints() {
98 99
	  // No constraints for constructor.
99 100
	  m.set(key, val);
100 101
	  m.set(own_key, own_val);
101 102
	  ignore_unused_variable_warning(key);
102 103
	  ignore_unused_variable_warning(val);
103 104
	  ignore_unused_variable_warning(own_key);
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/Writable map concept
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;
129 130

	
130 131
      /// Returns the value associated with a key.
131 132
      Value operator[](const Key &) const {return Value();}
132 133
      /// Sets the value associated with a key.
133 134
      void set(const Key & ,const Value &) {}
134 135

	
135 136
      template<typename _ReadWriteMap>
136 137
      struct Constraints {
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 to a key.
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 to a key.
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;
188 189
	  own_ref = m[own_key];	  	  
189 190
	}
190 191

	
191 192
	typename _ReferenceMap::Key& own_key;
192 193
	typename _ReferenceMap::Value& own_val;
193 194
	typename _ReferenceMap::Reference& own_ref;
194 195
	Key& key;
195 196
	Value& val;
196 197
	Reference& ref;
197 198
	_ReferenceMap& m;
198 199
      };
199 200
    };
200 201

	
201 202
    // @}
202 203

	
203 204
  } //namespace concepts
204 205

	
205 206
} //namespace lemon
206 207

	
207 208
#endif // LEMON_CONCEPT_MAPS_H
Ignore white space 96 line context
... ...
@@ -36,1233 +36,1289 @@
36 36

	
37 37
  /// \addtogroup maps
38 38
  /// @{
39 39

	
40 40
  /// Base class of maps.
41 41

	
42 42
  /// Base class of maps.
43 43
  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
44 44
  template<typename K, typename T>
45 45
  class MapBase {
46 46
  public:
47 47
    /// The key type of the map.
48 48
    typedef K Key;
49 49
    /// The value type of the map. (The type of objects associated with the keys).
50 50
    typedef T Value;
51 51
  };
52 52

	
53 53
  /// Null map. (a.k.a. DoNothingMap)
54 54

	
55 55
  /// This map can be used if you have to provide a map only for
56 56
  /// its type definitions, or if you have to provide a writable map, 
57 57
  /// but data written to it is not required (i.e. it will be sent to 
58 58
  /// <tt>/dev/null</tt>).
59 59
  template<typename K, typename T>
60 60
  class NullMap : public MapBase<K, T> {
61 61
  public:
62 62
    typedef MapBase<K, T> Parent;
63 63
    typedef typename Parent::Key Key;
64 64
    typedef typename Parent::Value Value;
65 65
    
66 66
    /// Gives back a default constructed element.
67 67
    T operator[](const K&) const { return T(); }
68 68
    /// Absorbs the value.
69 69
    void set(const K&, const T&) {}
70 70
  };
71 71

	
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

	
98 99
    /// Default constructor.
99 100
    /// The value of the map will be uninitialized. 
100 101
    /// (More exactly it will be default constructed.)
101 102
    ConstMap() {}
102 103
    
103 104
    /// Constructor with specified initial value
104 105

	
105 106
    /// Constructor with specified initial value.
106 107
    /// \param _v is the initial value of the map.
107 108
    ConstMap(const T &_v) : v(_v) {}
108 109
    
109 110
    ///\e
110 111
    T operator[](const K&) const { return v; }
111 112

	
112 113
    ///\e
113 114
    void setAll(const T &t) {
114 115
      v = t;
115 116
    }    
116 117

	
117 118
    template<typename T1>
118 119
    ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
119 120
  };
120 121

	
121 122
  ///Returns a \c ConstMap class
122 123

	
123 124
  ///This function just returns a \c ConstMap class.
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 True ReferenceMapTag;
174
    typedef MapBase<K, T> Parent;
172 175
    ///Key type
173
    typedef K Key;
176
    typedef typename Parent::Key Key;
174 177
    ///Value type
175
    typedef T Value;
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) {
210 215
      typename Map::iterator it = _map.lower_bound(k);
211 216
      if (it != _map.end() && !_map.key_comp()(k, it->first))
212 217
	return it->second;
213 218
      else
214 219
	return _map.insert(it, std::make_pair(k, _value))->second;
215 220
    }
216 221

	
217 222
    /// \e 
218 223
    ConstReference operator[](const Key &k) const {
219 224
      typename Map::const_iterator it = _map.find(k);
220 225
      if (it != _map.end())
221 226
	return it->second;
222 227
      else
223 228
	return _value;
224 229
    }
225 230

	
226 231
    /// \e 
227 232
    void set(const Key &k, const T &t) {
228 233
      typename Map::iterator it = _map.lower_bound(k);
229 234
      if (it != _map.end() && !_map.key_comp()(k, it->first))
230 235
	it->second = t;
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
  };
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
  }
242 268

	
243 269
  /// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt>
244 270
  ///
245
  /// The current map has the <tt>[0..size-1]</tt> keyset and the values
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
  /// the used items are small integer numbers. 
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 True ReferenceMapTag;
286
    typedef MapBase<int, T> Parent;
260 287
    ///\e
261
    typedef int Key;
288
    typedef typename Parent::Key Key;
262 289
    ///\e
263
    typedef T Value;
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&);
297 326

	
298 327
  public:
299 328

	
300 329
    ///\e
301 330
    Reference operator[](Key k) {
302 331
      return _vector[k];
303 332
    }
304 333

	
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
  };
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
  }
316 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:
329 367
    typedef MapBase<T, T> Parent;
330 368
    typedef typename Parent::Key Key;
331 369
    typedef typename Parent::Value Value;
332 370

	
333 371
    /// \e
334 372
    const T& operator[](const T& t) const {
335 373
      return t;
336 374
    }
337 375
  };
338 376

	
339 377
  ///Returns an \c IdentityMap class
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 \c concepts::ReadMap "read only map"
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
    /// The subscript operator.
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

	
384 420
  ///Simple wrapping of a map
385 421

	
386 422
  ///This \ref concepts::ReadMap "read only map" returns the simple
387 423
  ///wrapping of the given map. Sometimes the reference maps cannot be
388 424
  ///combined with simple read maps. This map adaptor wraps the given
389 425
  ///map to simple read map.
390 426
  ///
391 427
  ///\sa SimpleWriteMap
392 428
  ///
393 429
  /// \todo Revise the misleading name 
394 430
  template<typename M> 
395 431
  class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
396 432
    const M& m;
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
  };
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
  }
408 453

	
409 454
  ///Simple writable wrapping of a map
410 455

	
411
  ///This \ref concepts::WriteMap "write map" returns the simple
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 \c concepts::ReadMap "read only map" returns the sum of the two
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 How to call these type of functions?
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 \c concepts::ReadMap "read only map" returns the sum of the
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
484 538
  ///
485 539
  ///\sa ShiftWriteMap
486 540
  template<typename M, typename C = typename M::Value> 
487 541
  class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
488 542
    const M& m;
489 543
    C v;
490 544
  public:
491 545
    typedef MapBase<typename M::Key, typename M::Value> Parent;
492 546
    typedef typename Parent::Key Key;
493 547
    typedef typename Parent::Value Value;
494 548

	
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 \c concepts::ReadWriteMap "read-write map" returns the sum of the
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;
520 574

	
521 575
    ///Constructor
522 576

	
523 577
    ///Constructor.
524 578
    ///\param _m is the undelying map.
525 579
    ///\param _v is the shift value.
526 580
    ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
527 581
    /// \e
528 582
    Value operator[](Key k) const {return m[k] + v;}
529 583
    /// \e
530 584
    void set(Key k, const Value& c) { m.set(k, c - v); }
531 585
  };
532 586
  
533 587
  ///Returns a \c ShiftMap class
534 588

	
535 589
  ///This function just returns a \c ShiftMap class.
536 590
  ///\relates ShiftMap
537 591
  template<typename M, typename C> 
538 592
  inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
539 593
    return ShiftMap<M, C>(m,v);
540 594
  }
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 \c concepts::ReadMap "read only map" returns the difference
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;
566 620
    typedef typename Parent::Value Value;
567 621

	
568 622
    ///Constructor
569 623
    SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
570 624
    /// \e
571 625
    Value operator[](Key k) const {return m1[k]-m2[k];}
572 626
  };
573 627
  
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 \c concepts::ReadMap "read only map" returns the product of the
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

	
599 653
    ///Constructor
600 654
    MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
601 655
    /// \e
602 656
    Value operator[](Key k) const {return m1[k]*m2[k];}
603 657
  };
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 \c concepts::ReadMap "read only map" returns the value of the
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
629 683
  ///
630 684
  ///\sa ScaleWriteMap
631 685
  template<typename M, typename C = typename M::Value> 
632 686
  class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
633 687
    const M& m;
634 688
    C v;
635 689
  public:
636 690
    typedef MapBase<typename M::Key, typename M::Value> Parent;
637 691
    typedef typename Parent::Key Key;
638 692
    typedef typename Parent::Value Value;
639 693

	
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 \c concepts::ReadWriteMap "read-write map" returns the value of the
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;
665 719
    typedef typename Parent::Key Key;
666 720
    typedef typename Parent::Value Value;
667 721

	
668 722
    ///Constructor
669 723

	
670 724
    ///Constructor.
671 725
    ///\param _m is the undelying map.
672 726
    ///\param _v is the scaling value.
673 727
    ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
674 728
    /// \e
675 729
    Value operator[](Key k) const {return v * m[k];}
676 730
    /// \e
677 731
    void set(Key k, const Value& c) { m.set(k, c / v);}
678 732
  };
679 733
  
680 734
  ///Returns a \c ScaleMap class
681 735

	
682 736
  ///This function just returns a \c ScaleMap class.
683 737
  ///\relates ScaleMap
684 738
  template<typename M, typename C> 
685 739
  inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
686 740
    return ScaleMap<M, C>(m,v);
687 741
  }
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 \c concepts::ReadMap "read only map" returns the quotient of the
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

	
713 767
    ///Constructor
714 768
    DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
715 769
    /// \e
716 770
    Value operator[](Key k) const {return m1[k]/m2[k];}
717 771
  };
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 \c concepts::ReadMap "read only map" returns the composition of
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
743 797
  ///
744 798
  ///\todo Check the requirements.
745 799
  template <typename M1, typename M2> 
746 800
  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
747 801
    const M1& m1;
748 802
    const M2& m2;
749 803
  public:
750 804
    typedef MapBase<typename M2::Key, typename M1::Value> Parent;
751 805
    typedef typename Parent::Key Key;
752 806
    typedef typename Parent::Value Value;
753 807

	
754 808
    ///Constructor
755 809
    ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
756 810
    
757 811
    /// \e
758 812

	
759 813

	
760 814
    /// \todo Use the  MapTraits once it is ported.
761 815
    ///
762 816

	
763 817
    //typename MapTraits<M1>::ConstReturnValue
764 818
    typename M1::Value
765 819
    operator[](Key k) const {return m1[m2[k]];}
766 820
  };
767 821

	
768 822
  ///Returns a \c ComposeMap class
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 \c concepts::ReadMap "read only map" takes two maps and a
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
794 848
  ///to \c V.
795 849
  ///
796 850
  ///\sa ComposeMap
797 851
  ///
798 852
  ///\todo Check the requirements.
799 853
  template<typename M1, typename M2, typename F,
800 854
	   typename V = typename F::result_type> 
801 855
  class CombineMap : public MapBase<typename M1::Key, V> {
802 856
    const M1& m1;
803 857
    const M2& m2;
804 858
    F f;
805 859
  public:
806 860
    typedef MapBase<typename M1::Key, V> Parent;
807 861
    typedef typename Parent::Key Key;
808 862
    typedef typename Parent::Value Value;
809 863

	
810 864
    ///Constructor
811 865
    CombineMap(const M1 &_m1,const M2 &_m2,const F &_f = F())
812 866
      : m1(_m1), m2(_m2), f(_f) {};
813 867
    /// \e
814 868
    Value operator[](Key k) const {return f(m1[k],m2[k]);}
815 869
  };
816 870
  
817 871
  ///Returns a \c CombineMap class
818 872

	
819 873
  ///This function just returns a \c CombineMap class.
820 874
  ///
821 875
  ///For example if \c m1 and \c m2 are both \c double valued maps, then 
822 876
  ///\code
823 877
  ///combineMap(m1,m2,std::plus<double>())
824 878
  ///\endcode
825 879
  ///is equivalent to
826 880
  ///\code
827 881
  ///addMap(m1,m2)
828 882
  ///\endcode
829 883
  ///
830 884
  ///This function is specialized for adaptable binary function
831 885
  ///classes and C++ functions.
832 886
  ///
833 887
  ///\relates CombineMap
834 888
  template<typename M1, typename M2, typename F, typename V> 
835 889
  inline CombineMap<M1, M2, F, V> 
836 890
  combineMap(const M1& m1,const M2& m2, const F& f) {
837 891
    return CombineMap<M1, M2, F, V>(m1,m2,f);
838 892
  }
839 893

	
840 894
  template<typename M1, typename M2, typename F> 
841 895
  inline CombineMap<M1, M2, F, typename F::result_type> 
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 \c concepts::ReadMap "read only map" returns the negative
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 \c concepts::ReadWriteMap "read-write map" returns the negative
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;
889 943

	
890 944
    ///Constructor
891 945
    NegWriteMap(M &_m) : m(_m) {};
892 946
    /// \e
893 947
    Value operator[](Key k) const {return -m[k];}
894 948
    /// \e
895 949
    void set(Key k, const Value& v) { m.set(k, -v); }
896 950
  };
897 951

	
898 952
  ///Returns a \c NegMap class
899 953

	
900 954
  ///This function just returns a \c NegMap class.
901 955
  ///\relates NegMap
902 956
  template <typename M> 
903 957
  inline NegMap<M> negMap(const M &m) {
904 958
    return NegMap<M>(m);
905 959
  }
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 \c concepts::ReadMap "read only map" returns the absolute value
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

	
931 985
    ///Constructor
932 986
    AbsMap(const M &_m) : m(_m) {};
933 987
    /// \e
934 988
    Value operator[](Key k) const {
935 989
      Value tmp = m[k]; 
936 990
      return tmp >= 0 ? tmp : -tmp;
937 991
    }
938 992

	
939 993
  };
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 \c concepts::ReadMap "read only map" returns the value
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 such typedefs.
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
  ///that is it provides an <tt>operator()</tt> to read its values.
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 \c concepts::ReadMap "readable map",
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;
1023 1079
    typedef typename M::Value result_type;
1024 1080

	
1025 1081
    ///Constructor
1026 1082
    MapFunctor(const M &_m) : m(_m) {};
1027 1083
    ///\e
1028 1084
    Value operator()(Key k) const {return m[k];}
1029 1085
    ///\e
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
  ///Applies all map setting operations to two maps
1098
  ///Just readable version of \ref ForkWriteMap
1043 1099

	
1044
  ///This map has two \c concepts::ReadMap "readable map"
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 the ForkWriteMap.
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 \c concepts::WriteMap "writable map"
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 \c concepts::ReadMap "readable",
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
1092 1148
    ForkWriteMap(M1 &_m1, M2 &_m2) : m1(_m1), m2(_m2) {};
1093 1149
    ///\e
1094 1150
    Value operator[](Key k) const {return m1[k];}
1095 1151
    ///\e
1096 1152
    void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
1097 1153
  };
1098 1154
  
1099 1155
  ///Returns a \c ForkMap class
1100 1156

	
1101 1157
  ///This function just returns a \c ForkMap class.
1102 1158
  ///\relates ForkMap
1103 1159
  template <typename M1, typename M2> 
1104 1160
  inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
1105 1161
    return ForkMap<M1, M2>(m1,m2);
1106 1162
  }
1107 1163

	
1108 1164
  ///Returns a \c ForkWriteMap class
1109 1165

	
1110 1166
  ///This function just returns a \c ForkWriteMap class.
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 \c concepts::ReadMap "read only map" returns the 
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 \c concepts::ReadWriteMap "read-write map" returns the 
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) {};
1160 1216
    ///\e
1161 1217
    Value operator[](Key k) const {return !m[k];}
1162 1218
    ///\e
1163 1219
    void set(Key k, bool v) { m.set(k, !v); }
1164 1220
  };
1165 1221
  
1166 1222
  ///Returns a \c NotMap class
1167 1223
  
1168 1224
  ///This function just returns a \c NotMap class.
1169 1225
  ///\relates NotMap
1170 1226
  template <typename M> 
1171 1227
  inline NotMap<M> notMap(const M &m) {
1172 1228
    return NotMap<M>(m);
1173 1229
  }
1174 1230
  
1175 1231
  ///Returns a \c NotWriteMap class
1176 1232
  
1177 1233
  ///This function just returns a \c NotWriteMap class.
1178 1234
  ///\relates NotWriteMap
1179 1235
  template <typename M> 
1180 1236
  inline NotWriteMap<M> notMap(M &m) {
1181 1237
    return NotWriteMap<M>(m);
1182 1238
  }
1183 1239

	
1184 1240
  namespace _maps_bits {
1185 1241

	
1186 1242
    template <typename Value>
1187 1243
    struct Identity {
1188 1244
      typedef Value argument_type;
1189 1245
      typedef Value result_type;
1190 1246
      Value operator()(const Value& val) const {
1191 1247
	return val;
1192 1248
      }
1193 1249
    };
1194 1250

	
1195 1251
    template <typename _Iterator, typename Enable = void>
1196 1252
    struct IteratorTraits {
1197 1253
      typedef typename std::iterator_traits<_Iterator>::value_type Value;
1198 1254
    };
1199 1255

	
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
  /// to the standard output.
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
1233 1289
  ///
1234 1290
  ///\sa BackInserterBoolMap 
1235 1291
  ///\sa FrontInserterBoolMap 
1236 1292
  ///\sa InserterBoolMap 
1237 1293
  ///
1238 1294
  ///\todo Revise the name of this class and the related ones.
1239 1295
  template <typename _Iterator, 
1240 1296
            typename _Functor =
1241 1297
            _maps_bits::Identity<typename _maps_bits::
1242 1298
                                 IteratorTraits<_Iterator>::Value> >
1243 1299
  class StoreBoolMap {
1244 1300
  public:
1245 1301
    typedef _Iterator Iterator;
1246 1302

	
1247 1303
    typedef typename _Functor::argument_type Key;
1248 1304
    typedef bool Value;
1249 1305

	
1250 1306
    typedef _Functor Functor;
1251 1307

	
1252 1308
    /// Constructor
1253 1309
    StoreBoolMap(Iterator it, const Functor& functor = Functor()) 
1254 1310
      : _begin(it), _end(it), _functor(functor) {}
1255 1311

	
1256 1312
    /// Gives back the given iterator set for the first key
1257 1313
    Iterator begin() const {
1258 1314
      return _begin;
1259 1315
    }
1260 1316
 
1261 1317
    /// Gives back the the 'after the last' iterator
1262 1318
    Iterator end() const {
1263 1319
      return _end;
1264 1320
    }
1265 1321

	
1266 1322
    /// The \c set function of the map
1267 1323
    void set(const Key& key, Value value) const {
1268 1324
      if (value) {
0 comments (0 inline)