gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Minor doc fixes. Replaced \c by \ref and \ref by \c to work properly and to be uniform.
0 1 0
default
1 file changed with 37 insertions and 36 deletions:
↑ Collapse diff ↑
Ignore white space 13194139533312 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2007
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_MAPS_H
20 20
#define LEMON_MAPS_H
21 21

	
22 22
#include <iterator>
23 23
#include <functional>
24 24
#include <vector>
25 25

	
26 26
#include <lemon/bits/utility.h>
27 27
// #include <lemon/bits/traits.h>
28 28

	
29 29
///\file
30 30
///\ingroup maps
31 31
///\brief Miscellaneous property maps
32 32
///
33 33
#include <map>
34 34

	
35 35
namespace lemon {
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 84
  /// This is a readable map which assigns a specified value to each key.
85 85
  /// In other aspects it is equivalent to the \c NullMap.
86 86
  template<typename K, typename T>
87 87
  class ConstMap : public MapBase<K, T> {
88 88
  private:
89 89
    T v;
90 90
  public:
91 91

	
92 92
    typedef MapBase<K, T> Parent;
93 93
    typedef typename Parent::Key Key;
94 94
    typedef typename Parent::Value Value;
95 95

	
96 96
    /// Default constructor
97 97

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

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

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

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

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

	
123 123
  ///This function just returns a \c ConstMap class.
124 124
  ///\relates ConstMap
125 125
  template<typename K, typename V> 
126 126
  inline ConstMap<K, V> constMap(const V &v) {
127 127
    return ConstMap<K, V>(v);
128 128
  }
129 129

	
130 130

	
131 131
  template<typename T, T v>
132 132
  struct Const { };
133 133

	
134 134
  /// Constant map with inlined constant value.
135 135

	
136 136
  /// This is a readable map which assigns a specified value to each key.
137 137
  /// In other aspects it is equivalent to the \c NullMap.
138 138
  template<typename K, typename V, V v>
139 139
  class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
140 140
  public:
141 141
    typedef MapBase<K, V> Parent;
142 142
    typedef typename Parent::Key Key;
143 143
    typedef typename Parent::Value Value;
144 144

	
145 145
    ConstMap() { }
146 146
    ///\e
147 147
    V operator[](const K&) const { return v; }
148 148
    ///\e
149 149
    void set(const K&, const V&) { }
150 150
  };
151 151

	
152 152
  ///Returns a \c ConstMap class
153 153

	
154 154
  ///This function just returns a \c ConstMap class with inlined value.
155 155
  ///\relates ConstMap
156 156
  template<typename K, typename V, V v> 
157 157
  inline ConstMap<K, Const<V, v> > constMap() {
158 158
    return ConstMap<K, Const<V, v> >();
159 159
  }
160 160

	
161
  ///Map based on std::map
161
  ///Map based on \c std::map
162 162

	
163 163
  ///This is essentially a wrapper for \c std::map with addition that
164 164
  ///you can specify a default value different from \c Value().
165 165
  template <typename K, typename T, typename Compare = std::less<K> >
166 166
  class StdMap : public MapBase<K, T> {
167 167
    template <typename K1, typename T1, typename C1>
168 168
    friend class StdMap;
169 169
  public:
170 170

	
171 171
    typedef MapBase<K, T> Parent;
172 172
    ///\e
173 173
    typedef typename Parent::Key Key;
174 174
    ///\e
175 175
    typedef typename Parent::Value Value;
176 176
    ///\e
177 177
    typedef T& Reference;
178 178
    ///\e
179 179
    typedef const T& ConstReference;
180 180

	
181 181
    typedef True ReferenceMapTag;
182 182

	
183 183
  private:
184 184
    
185 185
    typedef std::map<K, T, Compare> Map;
186 186
    Value _value;
187 187
    Map _map;
188 188

	
189 189
  public:
190 190

	
191 191
    /// Constructor with specified default value
192 192
    StdMap(const T& value = T()) : _value(value) {}
193 193
    /// \brief Constructs the map from an appropriate std::map, and explicitly
194 194
    /// specifies a default value.
195 195
    template <typename T1, typename Comp1>
196 196
    StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) 
197 197
      : _map(map.begin(), map.end()), _value(value) {}
198 198
    
199 199
    /// \brief Constructs a map from an other StdMap.
200 200
    template<typename T1, typename Comp1>
201 201
    StdMap(const StdMap<Key, T1, Comp1> &c) 
202 202
      : _map(c._map.begin(), c._map.end()), _value(c._value) {}
203 203

	
204 204
  private:
205 205

	
206 206
    StdMap& operator=(const StdMap&);
207 207

	
208 208
  public:
209 209

	
210 210
    ///\e
211 211
    Reference operator[](const Key &k) {
212 212
      typename Map::iterator it = _map.lower_bound(k);
213 213
      if (it != _map.end() && !_map.key_comp()(k, it->first))
214 214
	return it->second;
215 215
      else
216 216
	return _map.insert(it, std::make_pair(k, _value))->second;
217 217
    }
218 218

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

	
228 228
    /// \e 
229 229
    void set(const Key &k, const T &t) {
230 230
      typename Map::iterator it = _map.lower_bound(k);
231 231
      if (it != _map.end() && !_map.key_comp()(k, it->first))
232 232
	it->second = t;
233 233
      else
234 234
	_map.insert(it, std::make_pair(k, t));
235 235
    }
236 236

	
237 237
    /// \e
238 238
    void setAll(const T &t) {
239 239
      _value = t;
240 240
      _map.clear();
241 241
    }    
242 242

	
243 243
  };
244 244
  
245
  ///Returns a \ref StdMap class
245
  ///Returns a \c StdMap class
246 246

	
247
  ///This function just returns a \ref StdMap class with specified 
247
  ///This function just returns a \c StdMap class with specified 
248 248
  ///default value.
249 249
  ///\relates StdMap
250 250
  template<typename K, typename V, typename Compare = std::less<K> > 
251 251
  inline StdMap<K, V, Compare> stdMap(const V& value = V()) {
252 252
    return StdMap<K, V, Compare>(value);
253 253
  }
254 254

	
255
  ///Returns a \ref StdMap class created from an appropriate std::map
255
  ///Returns a \c StdMap class created from an appropriate std::map
256 256

	
257
  ///This function just returns a \ref StdMap class created from an 
257
  ///This function just returns a \c StdMap class created from an 
258 258
  ///appropriate std::map.
259 259
  ///\relates StdMap
260 260
  template<typename K, typename V, typename Compare = std::less<K> > 
261 261
  inline StdMap<K, V, Compare> stdMap( const std::map<K, V, Compare> &map, 
262 262
                                       const V& value = V() ) {
263 263
    return StdMap<K, V, Compare>(map, value);
264 264
  }
265 265

	
266 266
  /// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt>
267 267
  ///
268 268
  /// The current map has the <tt>[0..size-1]</tt> keyset and the values
269 269
  /// are stored in a \c std::vector<T>  container. It can be used with
270 270
  /// some data structures, for example \c UnionFind, \c BinHeap, when 
271 271
  /// the used items are small integer numbers. 
272 272
  ///
273 273
  /// \todo Revise its name
274 274
  template <typename T>
275 275
  class IntegerMap : public MapBase<int, T> {
276 276

	
277 277
    template <typename T1>
278 278
    friend class IntegerMap;
279 279

	
280 280
  public:
281 281

	
282 282
    typedef MapBase<int, T> Parent;
283 283
    ///\e
284 284
    typedef typename Parent::Key Key;
285 285
    ///\e
286 286
    typedef typename Parent::Value Value;
287 287
    ///\e
288 288
    typedef T& Reference;
289 289
    ///\e
290 290
    typedef const T& ConstReference;
291 291

	
292 292
    typedef True ReferenceMapTag;
293 293

	
294 294
  private:
295 295
    
296 296
    typedef std::vector<T> Vector;
297 297
    Vector _vector;
298 298

	
299 299
  public:
300 300

	
301 301
    /// Constructor with specified default value
302 302
    IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {}
303 303

	
304 304
    /// \brief Constructs the map from an appropriate std::vector.
305 305
    template <typename T1>
306 306
    IntegerMap(const std::vector<T1>& vector) 
307 307
      : _vector(vector.begin(), vector.end()) {}
308 308
    
309 309
    /// \brief Constructs a map from an other IntegerMap.
310 310
    template <typename T1>
311 311
    IntegerMap(const IntegerMap<T1> &c) 
312 312
      : _vector(c._vector.begin(), c._vector.end()) {}
313 313

	
314 314
    /// \brief Resize the container
315 315
    void resize(int size, const T& value = T()) {
316 316
      _vector.resize(size, value);
317 317
    }
318 318

	
319 319
  private:
320 320

	
321 321
    IntegerMap& operator=(const IntegerMap&);
322 322

	
323 323
  public:
324 324

	
325 325
    ///\e
326 326
    Reference operator[](Key k) {
327 327
      return _vector[k];
328 328
    }
329 329

	
330 330
    /// \e 
331 331
    ConstReference operator[](Key k) const {
332 332
      return _vector[k];
333 333
    }
334 334

	
335 335
    /// \e 
336 336
    void set(const Key &k, const T& t) {
337 337
      _vector[k] = t;
338 338
    }
339 339

	
340 340
  };
341 341
  
342
  ///Returns an \ref IntegerMap class
342
  ///Returns an \c IntegerMap class
343 343

	
344
  ///This function just returns an \ref IntegerMap class.
344
  ///This function just returns an \c IntegerMap class.
345 345
  ///\relates IntegerMap
346 346
  template<typename T>
347 347
  inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) {
348 348
    return IntegerMap<T>(size, value);
349 349
  }
350 350

	
351 351
  /// @}
352 352

	
353 353
  /// \addtogroup map_adaptors
354 354
  /// @{
355 355

	
356 356
  /// \brief Identity map.
357 357
  ///
358 358
  /// This map gives back the given key as value without any
359 359
  /// modification. 
360 360
  template <typename T>
361 361
  class IdentityMap : public MapBase<T, T> {
362 362
  public:
363 363
    typedef MapBase<T, T> Parent;
364 364
    typedef typename Parent::Key Key;
365 365
    typedef typename Parent::Value Value;
366 366

	
367 367
    /// \e
368 368
    const T& operator[](const T& t) const {
369 369
      return t;
370 370
    }
371 371
  };
372 372

	
373 373
  ///Returns an \c IdentityMap class
374 374

	
375 375
  ///This function just returns an \c IdentityMap class.
376 376
  ///\relates IdentityMap
377 377
  template<typename T>
378 378
  inline IdentityMap<T> identityMap() {
379 379
    return IdentityMap<T>();
380 380
  }
381 381
  
382 382

	
383 383
  ///\brief Convert the \c Value of a map to another type using
384 384
  ///the default conversion.
385 385
  ///
386
  ///This \c concepts::ReadMap "read only map"
386
  ///This \ref concepts::ReadMap "read only map"
387 387
  ///converts the \c Value of a map to type \c T.
388 388
  ///Its \c Key is inherited from \c M.
389 389
  template <typename M, typename T> 
390 390
  class ConvertMap : public MapBase<typename M::Key, T> {
391 391
    const M& m;
392 392
  public:
393 393
    typedef MapBase<typename M::Key, T> Parent;
394 394
    typedef typename Parent::Key Key;
395 395
    typedef typename Parent::Value Value;
396 396

	
397 397
    ///Constructor
398 398

	
399 399
    ///Constructor.
400 400
    ///\param _m is the underlying map.
401 401
    ConvertMap(const M &_m) : m(_m) {};
402 402

	
403 403
    /// \brief The subscript operator.
404 404
    ///
405 405
    /// The subscript operator.
406 406
    Value operator[](const Key& k) const {return m[k];}
407 407
  };
408 408
  
409 409
  ///Returns a \c ConvertMap class
410 410

	
411 411
  ///This function just returns a \c ConvertMap class.
412 412
  ///\relates ConvertMap
413 413
  template<typename T, typename M>
414 414
  inline ConvertMap<M, T> convertMap(const M &m) {
415 415
    return ConvertMap<M, T>(m);
416 416
  }
417 417

	
418 418
  ///Simple wrapping of a map
419 419

	
420 420
  ///This \ref concepts::ReadMap "read only map" returns the simple
421 421
  ///wrapping of the given map. Sometimes the reference maps cannot be
422 422
  ///combined with simple read maps. This map adaptor wraps the given
423 423
  ///map to simple read map.
424 424
  ///
425 425
  ///\sa SimpleWriteMap
426 426
  ///
427 427
  /// \todo Revise the misleading name 
428 428
  template<typename M> 
429 429
  class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
430 430
    const M& m;
431 431

	
432 432
  public:
433 433
    typedef MapBase<typename M::Key, typename M::Value> Parent;
434 434
    typedef typename Parent::Key Key;
435 435
    typedef typename Parent::Value Value;
436 436

	
437 437
    ///Constructor
438 438
    SimpleMap(const M &_m) : m(_m) {};
439 439
    ///\e
440 440
    Value operator[](Key k) const {return m[k];}
441 441
  };
442 442
  
443
  ///Returns a \ref SimpleMap class
443
  ///Returns a \c SimpleMap class
444 444

	
445
  ///This function just returns a \ref SimpleMap class.
445
  ///This function just returns a \c SimpleMap class.
446 446
  ///\relates SimpleMap
447 447
  template<typename M>
448 448
  inline SimpleMap<M> simpleMap(const M &m) {
449 449
    return SimpleMap<M>(m);
450 450
  }
451 451

	
452 452
  ///Simple writable wrapping of a map
453 453

	
454
  ///This \ref concepts::WriteMap "write map" returns the simple
454
  ///This \ref concepts::ReadWriteMap "read-write map" returns the simple
455 455
  ///wrapping of the given map. Sometimes the reference maps cannot be
456 456
  ///combined with simple read-write maps. This map adaptor wraps the
457 457
  ///given map to simple read-write map.
458 458
  ///
459 459
  ///\sa SimpleMap
460 460
  ///
461 461
  /// \todo Revise the misleading name
462 462
  template<typename M> 
463 463
  class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
464 464
    M& m;
465 465

	
466 466
  public:
467 467
    typedef MapBase<typename M::Key, typename M::Value> Parent;
468 468
    typedef typename Parent::Key Key;
469 469
    typedef typename Parent::Value Value;
470 470

	
471 471
    ///Constructor
472 472
    SimpleWriteMap(M &_m) : m(_m) {};
473 473
    ///\e
474 474
    Value operator[](Key k) const {return m[k];}
475 475
    ///\e
476 476
    void set(Key k, const Value& c) { m.set(k, c); }
477 477
  };
478 478

	
479
  ///Returns a \ref SimpleWriteMap class
479
  ///Returns a \c SimpleWriteMap class
480 480

	
481
  ///This function just returns a \ref SimpleWriteMap class.
481
  ///This function just returns a \c SimpleWriteMap class.
482 482
  ///\relates SimpleWriteMap
483 483
  template<typename M>
484 484
  inline SimpleWriteMap<M> simpleWriteMap(M &m) {
485 485
    return SimpleWriteMap<M>(m);
486 486
  }
487 487

	
488 488
  ///Sum of two maps
489 489

	
490
  ///This \c concepts::ReadMap "read only map" returns the sum of the two
490
  ///This \ref concepts::ReadMap "read only map" returns the sum of the two
491 491
  ///given maps.
492 492
  ///Its \c Key and \c Value are inherited from \c M1.
493 493
  ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
494 494
  template<typename M1, typename M2> 
495 495
  class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
496 496
    const M1& m1;
497 497
    const M2& m2;
498 498

	
499 499
  public:
500 500
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
501 501
    typedef typename Parent::Key Key;
502 502
    typedef typename Parent::Value Value;
503 503

	
504 504
    ///Constructor
505 505
    AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
506 506
    ///\e
507 507
    Value operator[](Key k) const {return m1[k]+m2[k];}
508 508
  };
509 509
  
510 510
  ///Returns an \c AddMap class
511 511

	
512 512
  ///This function just returns an \c AddMap class.
513 513
  ///\todo How to call these type of functions?
514 514
  ///
515 515
  ///\relates AddMap
516 516
  template<typename M1, typename M2> 
517 517
  inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
518 518
    return AddMap<M1, M2>(m1,m2);
519 519
  }
520 520

	
521 521
  ///Shift a map with a constant.
522 522

	
523
  ///This \c concepts::ReadMap "read only map" returns the sum of the
523
  ///This \ref concepts::ReadMap "read only map" returns the sum of the
524 524
  ///given map and a constant value.
525 525
  ///Its \c Key and \c Value are inherited from \c M.
526 526
  ///
527 527
  ///Actually,
528 528
  ///\code
529 529
  ///  ShiftMap<X> sh(x,v);
530 530
  ///\endcode
531 531
  ///is equivalent to
532 532
  ///\code
533 533
  ///  ConstMap<X::Key, X::Value> c_tmp(v);
534 534
  ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
535 535
  ///\endcode
536 536
  ///
537 537
  ///\sa ShiftWriteMap
538 538
  template<typename M, typename C = typename M::Value> 
539 539
  class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
540 540
    const M& m;
541 541
    C v;
542 542
  public:
543 543
    typedef MapBase<typename M::Key, typename M::Value> Parent;
544 544
    typedef typename Parent::Key Key;
545 545
    typedef typename Parent::Value Value;
546 546

	
547 547
    ///Constructor
548 548

	
549 549
    ///Constructor.
550 550
    ///\param _m is the undelying map.
551 551
    ///\param _v is the shift value.
552 552
    ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
553 553
    ///\e
554 554
    Value operator[](Key k) const {return m[k] + v;}
555 555
  };
556 556

	
557 557
  ///Shift a map with a constant (ReadWrite version).
558 558

	
559
  ///This \c concepts::ReadWriteMap "read-write map" returns the sum of the
559
  ///This \ref concepts::ReadWriteMap "read-write map" returns the sum of the
560 560
  ///given map and a constant value. It makes also possible to write the map.
561 561
  ///Its \c Key and \c Value are inherited from \c M.
562 562
  ///
563 563
  ///\sa ShiftMap
564 564
  template<typename M, typename C = typename M::Value> 
565 565
  class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
566 566
    M& m;
567 567
    C v;
568 568
  public:
569 569
    typedef MapBase<typename M::Key, typename M::Value> Parent;
570 570
    typedef typename Parent::Key Key;
571 571
    typedef typename Parent::Value Value;
572 572

	
573 573
    ///Constructor
574 574

	
575 575
    ///Constructor.
576 576
    ///\param _m is the undelying map.
577 577
    ///\param _v is the shift value.
578 578
    ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
579 579
    /// \e
580 580
    Value operator[](Key k) const {return m[k] + v;}
581 581
    /// \e
582 582
    void set(Key k, const Value& c) { m.set(k, c - v); }
583 583
  };
584 584
  
585 585
  ///Returns a \c ShiftMap class
586 586

	
587 587
  ///This function just returns a \c ShiftMap class.
588 588
  ///\relates ShiftMap
589 589
  template<typename M, typename C> 
590 590
  inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
591 591
    return ShiftMap<M, C>(m,v);
592 592
  }
593 593

	
594 594
  ///Returns a \c ShiftWriteMap class
595 595

	
596 596
  ///This function just returns a \c ShiftWriteMap class.
597 597
  ///\relates ShiftWriteMap
598 598
  template<typename M, typename C> 
599 599
  inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) {
600 600
    return ShiftWriteMap<M, C>(m,v);
601 601
  }
602 602

	
603 603
  ///Difference of two maps
604 604

	
605
  ///This \c concepts::ReadMap "read only map" returns the difference
605
  ///This \ref concepts::ReadMap "read only map" returns the difference
606 606
  ///of the values of the two given maps.
607 607
  ///Its \c Key and \c Value are inherited from \c M1.
608 608
  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
609 609
  ///
610 610
  /// \todo Revise the misleading name
611 611
  template<typename M1, typename M2> 
612 612
  class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
613 613
    const M1& m1;
614 614
    const M2& m2;
615 615
  public:
616 616
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
617 617
    typedef typename Parent::Key Key;
618 618
    typedef typename Parent::Value Value;
619 619

	
620 620
    ///Constructor
621 621
    SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
622 622
    /// \e
623 623
    Value operator[](Key k) const {return m1[k]-m2[k];}
624 624
  };
625 625
  
626 626
  ///Returns a \c SubMap class
627 627

	
628 628
  ///This function just returns a \c SubMap class.
629 629
  ///
630 630
  ///\relates SubMap
631 631
  template<typename M1, typename M2> 
632 632
  inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
633 633
    return SubMap<M1, M2>(m1, m2);
634 634
  }
635 635

	
636 636
  ///Product of two maps
637 637

	
638
  ///This \c concepts::ReadMap "read only map" returns the product of the
638
  ///This \ref concepts::ReadMap "read only map" returns the product of the
639 639
  ///values of the two given maps.
640 640
  ///Its \c Key and \c Value are inherited from \c M1.
641 641
  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
642 642
  template<typename M1, typename M2> 
643 643
  class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
644 644
    const M1& m1;
645 645
    const M2& m2;
646 646
  public:
647 647
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
648 648
    typedef typename Parent::Key Key;
649 649
    typedef typename Parent::Value Value;
650 650

	
651 651
    ///Constructor
652 652
    MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
653 653
    /// \e
654 654
    Value operator[](Key k) const {return m1[k]*m2[k];}
655 655
  };
656 656
  
657 657
  ///Returns a \c MulMap class
658 658

	
659 659
  ///This function just returns a \c MulMap class.
660 660
  ///\relates MulMap
661 661
  template<typename M1, typename M2> 
662 662
  inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
663 663
    return MulMap<M1, M2>(m1,m2);
664 664
  }
665 665
 
666 666
  ///Scales a map with a constant.
667 667

	
668
  ///This \c concepts::ReadMap "read only map" returns the value of the
668
  ///This \ref concepts::ReadMap "read only map" returns the value of the
669 669
  ///given map multiplied from the left side with a constant value.
670 670
  ///Its \c Key and \c Value are inherited from \c M.
671 671
  ///
672 672
  ///Actually,
673 673
  ///\code
674 674
  ///  ScaleMap<X> sc(x,v);
675 675
  ///\endcode
676 676
  ///is equivalent to
677 677
  ///\code
678 678
  ///  ConstMap<X::Key, X::Value> c_tmp(v);
679 679
  ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
680 680
  ///\endcode
681 681
  ///
682 682
  ///\sa ScaleWriteMap
683 683
  template<typename M, typename C = typename M::Value> 
684 684
  class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
685 685
    const M& m;
686 686
    C v;
687 687
  public:
688 688
    typedef MapBase<typename M::Key, typename M::Value> Parent;
689 689
    typedef typename Parent::Key Key;
690 690
    typedef typename Parent::Value Value;
691 691

	
692 692
    ///Constructor
693 693

	
694 694
    ///Constructor.
695 695
    ///\param _m is the undelying map.
696 696
    ///\param _v is the scaling value.
697 697
    ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
698 698
    /// \e
699 699
    Value operator[](Key k) const {return v * m[k];}
700 700
  };
701 701

	
702 702
  ///Scales a map with a constant (ReadWrite version).
703 703

	
704
  ///This \c concepts::ReadWriteMap "read-write map" returns the value of the
704
  ///This \ref concepts::ReadWriteMap "read-write map" returns the value of the
705 705
  ///given map multiplied from the left side with a constant value. It can
706 706
  ///also be used as write map if the \c / operator is defined between
707 707
  ///\c Value and \c C and the given multiplier is not zero.
708 708
  ///Its \c Key and \c Value are inherited from \c M.
709 709
  ///
710 710
  ///\sa ScaleMap
711 711
  template<typename M, typename C = typename M::Value> 
712 712
  class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
713 713
    M& m;
714 714
    C v;
715 715
  public:
716 716
    typedef MapBase<typename M::Key, typename M::Value> Parent;
717 717
    typedef typename Parent::Key Key;
718 718
    typedef typename Parent::Value Value;
719 719

	
720 720
    ///Constructor
721 721

	
722 722
    ///Constructor.
723 723
    ///\param _m is the undelying map.
724 724
    ///\param _v is the scaling value.
725 725
    ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
726 726
    /// \e
727 727
    Value operator[](Key k) const {return v * m[k];}
728 728
    /// \e
729 729
    void set(Key k, const Value& c) { m.set(k, c / v);}
730 730
  };
731 731
  
732 732
  ///Returns a \c ScaleMap class
733 733

	
734 734
  ///This function just returns a \c ScaleMap class.
735 735
  ///\relates ScaleMap
736 736
  template<typename M, typename C> 
737 737
  inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
738 738
    return ScaleMap<M, C>(m,v);
739 739
  }
740 740

	
741 741
  ///Returns a \c ScaleWriteMap class
742 742

	
743 743
  ///This function just returns a \c ScaleWriteMap class.
744 744
  ///\relates ScaleWriteMap
745 745
  template<typename M, typename C> 
746 746
  inline ScaleWriteMap<M, C> scaleMap(M &m,const C &v) {
747 747
    return ScaleWriteMap<M, C>(m,v);
748 748
  }
749 749

	
750 750
  ///Quotient of two maps
751 751

	
752
  ///This \c concepts::ReadMap "read only map" returns the quotient of the
752
  ///This \ref concepts::ReadMap "read only map" returns the quotient of the
753 753
  ///values of the two given maps.
754 754
  ///Its \c Key and \c Value are inherited from \c M1.
755 755
  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
756 756
  template<typename M1, typename M2> 
757 757
  class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
758 758
    const M1& m1;
759 759
    const M2& m2;
760 760
  public:
761 761
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
762 762
    typedef typename Parent::Key Key;
763 763
    typedef typename Parent::Value Value;
764 764

	
765 765
    ///Constructor
766 766
    DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
767 767
    /// \e
768 768
    Value operator[](Key k) const {return m1[k]/m2[k];}
769 769
  };
770 770
  
771 771
  ///Returns a \c DivMap class
772 772

	
773 773
  ///This function just returns a \c DivMap class.
774 774
  ///\relates DivMap
775 775
  template<typename M1, typename M2> 
776 776
  inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
777 777
    return DivMap<M1, M2>(m1,m2);
778 778
  }
779 779
  
780 780
  ///Composition of two maps
781 781

	
782
  ///This \c concepts::ReadMap "read only map" returns the composition of
782
  ///This \ref concepts::ReadMap "read only map" returns the composition of
783 783
  ///two given maps.
784 784
  ///That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2,
785 785
  ///then for
786 786
  ///\code
787 787
  ///  ComposeMap<M1, M2> cm(m1,m2);
788 788
  ///\endcode
789 789
  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>.
790 790
  ///
791 791
  ///Its \c Key is inherited from \c M2 and its \c Value is from \c M1.
792 792
  ///\c M2::Value must be convertible to \c M1::Key.
793 793
  ///
794 794
  ///\sa CombineMap
795 795
  ///
796 796
  ///\todo Check the requirements.
797 797
  template <typename M1, typename M2> 
798 798
  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
799 799
    const M1& m1;
800 800
    const M2& m2;
801 801
  public:
802 802
    typedef MapBase<typename M2::Key, typename M1::Value> Parent;
803 803
    typedef typename Parent::Key Key;
804 804
    typedef typename Parent::Value Value;
805 805

	
806 806
    ///Constructor
807 807
    ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
808 808
    
809 809
    /// \e
810 810

	
811 811

	
812 812
    /// \todo Use the  MapTraits once it is ported.
813 813
    ///
814 814

	
815 815
    //typename MapTraits<M1>::ConstReturnValue
816 816
    typename M1::Value
817 817
    operator[](Key k) const {return m1[m2[k]];}
818 818
  };
819 819

	
820 820
  ///Returns a \c ComposeMap class
821 821

	
822 822
  ///This function just returns a \c ComposeMap class.
823 823
  ///\relates ComposeMap
824 824
  template <typename M1, typename M2> 
825 825
  inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
826 826
    return ComposeMap<M1, M2>(m1,m2);
827 827
  }
828 828
  
829 829
  ///Combine of two maps using an STL (binary) functor.
830 830

	
831 831
  ///Combine of two maps using an STL (binary) functor.
832 832
  ///
833
  ///This \c concepts::ReadMap "read only map" takes two maps and a
833
  ///This \ref concepts::ReadMap "read only map" takes two maps and a
834 834
  ///binary functor and returns the composition of the two
835 835
  ///given maps unsing the functor. 
836 836
  ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
837 837
  ///and \c f is of \c F, then for
838 838
  ///\code
839 839
  ///  CombineMap<M1,M2,F,V> cm(m1,m2,f);
840 840
  ///\endcode
841 841
  /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
842 842
  ///
843 843
  ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
844 844
  ///\c M2::Value and \c M1::Value must be convertible to the corresponding
845 845
  ///input parameter of \c F and the return type of \c F must be convertible
846 846
  ///to \c V.
847 847
  ///
848 848
  ///\sa ComposeMap
849 849
  ///
850 850
  ///\todo Check the requirements.
851 851
  template<typename M1, typename M2, typename F,
852 852
	   typename V = typename F::result_type> 
853 853
  class CombineMap : public MapBase<typename M1::Key, V> {
854 854
    const M1& m1;
855 855
    const M2& m2;
856 856
    F f;
857 857
  public:
858 858
    typedef MapBase<typename M1::Key, V> Parent;
859 859
    typedef typename Parent::Key Key;
860 860
    typedef typename Parent::Value Value;
861 861

	
862 862
    ///Constructor
863 863
    CombineMap(const M1 &_m1,const M2 &_m2,const F &_f = F())
864 864
      : m1(_m1), m2(_m2), f(_f) {};
865 865
    /// \e
866 866
    Value operator[](Key k) const {return f(m1[k],m2[k]);}
867 867
  };
868 868
  
869 869
  ///Returns a \c CombineMap class
870 870

	
871 871
  ///This function just returns a \c CombineMap class.
872 872
  ///
873 873
  ///For example if \c m1 and \c m2 are both \c double valued maps, then 
874 874
  ///\code
875 875
  ///combineMap(m1,m2,std::plus<double>())
876 876
  ///\endcode
877 877
  ///is equivalent to
878 878
  ///\code
879 879
  ///addMap(m1,m2)
880 880
  ///\endcode
881 881
  ///
882 882
  ///This function is specialized for adaptable binary function
883 883
  ///classes and C++ functions.
884 884
  ///
885 885
  ///\relates CombineMap
886 886
  template<typename M1, typename M2, typename F, typename V> 
887 887
  inline CombineMap<M1, M2, F, V> 
888 888
  combineMap(const M1& m1,const M2& m2, const F& f) {
889 889
    return CombineMap<M1, M2, F, V>(m1,m2,f);
890 890
  }
891 891

	
892 892
  template<typename M1, typename M2, typename F> 
893 893
  inline CombineMap<M1, M2, F, typename F::result_type> 
894 894
  combineMap(const M1& m1, const M2& m2, const F& f) {
895 895
    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
896 896
  }
897 897

	
898 898
  template<typename M1, typename M2, typename K1, typename K2, typename V> 
899 899
  inline CombineMap<M1, M2, V (*)(K1, K2), V> 
900 900
  combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
901 901
    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
902 902
  }
903 903

	
904 904
  ///Negative value of a map
905 905

	
906
  ///This \c concepts::ReadMap "read only map" returns the negative
906
  ///This \ref concepts::ReadMap "read only map" returns the negative
907 907
  ///value of the value returned by the given map.
908 908
  ///Its \c Key and \c Value are inherited from \c M.
909 909
  ///The unary \c - operator must be defined for \c Value, of course.
910 910
  ///
911 911
  ///\sa NegWriteMap
912 912
  template<typename M> 
913 913
  class NegMap : public MapBase<typename M::Key, typename M::Value> {
914 914
    const M& m;
915 915
  public:
916 916
    typedef MapBase<typename M::Key, typename M::Value> Parent;
917 917
    typedef typename Parent::Key Key;
918 918
    typedef typename Parent::Value Value;
919 919

	
920 920
    ///Constructor
921 921
    NegMap(const M &_m) : m(_m) {};
922 922
    /// \e
923 923
    Value operator[](Key k) const {return -m[k];}
924 924
  };
925 925
  
926 926
  ///Negative value of a map (ReadWrite version)
927 927

	
928
  ///This \c concepts::ReadWriteMap "read-write map" returns the negative
928
  ///This \ref concepts::ReadWriteMap "read-write map" returns the negative
929 929
  ///value of the value returned by the given map.
930 930
  ///Its \c Key and \c Value are inherited from \c M.
931 931
  ///The unary \c - operator must be defined for \c Value, of course.
932 932
  ///
933 933
  /// \sa NegMap
934 934
  template<typename M> 
935 935
  class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
936 936
    M& m;
937 937
  public:
938 938
    typedef MapBase<typename M::Key, typename M::Value> Parent;
939 939
    typedef typename Parent::Key Key;
940 940
    typedef typename Parent::Value Value;
941 941

	
942 942
    ///Constructor
943 943
    NegWriteMap(M &_m) : m(_m) {};
944 944
    /// \e
945 945
    Value operator[](Key k) const {return -m[k];}
946 946
    /// \e
947 947
    void set(Key k, const Value& v) { m.set(k, -v); }
948 948
  };
949 949

	
950 950
  ///Returns a \c NegMap class
951 951

	
952 952
  ///This function just returns a \c NegMap class.
953 953
  ///\relates NegMap
954 954
  template <typename M> 
955 955
  inline NegMap<M> negMap(const M &m) {
956 956
    return NegMap<M>(m);
957 957
  }
958 958

	
959 959
  ///Returns a \c NegWriteMap class
960 960

	
961 961
  ///This function just returns a \c NegWriteMap class.
962 962
  ///\relates NegWriteMap
963 963
  template <typename M> 
964 964
  inline NegWriteMap<M> negMap(M &m) {
965 965
    return NegWriteMap<M>(m);
966 966
  }
967 967

	
968 968
  ///Absolute value of a map
969 969

	
970
  ///This \c concepts::ReadMap "read only map" returns the absolute value
970
  ///This \ref concepts::ReadMap "read only map" returns the absolute value
971 971
  ///of the value returned by the given map.
972 972
  ///Its \c Key and \c Value are inherited from \c M. 
973 973
  ///\c Value must be comparable to \c 0 and the unary \c -
974 974
  ///operator must be defined for it, of course.
975 975
  template<typename M> 
976 976
  class AbsMap : public MapBase<typename M::Key, typename M::Value> {
977 977
    const M& m;
978 978
  public:
979 979
    typedef MapBase<typename M::Key, typename M::Value> Parent;
980 980
    typedef typename Parent::Key Key;
981 981
    typedef typename Parent::Value Value;
982 982

	
983 983
    ///Constructor
984 984
    AbsMap(const M &_m) : m(_m) {};
985 985
    /// \e
986 986
    Value operator[](Key k) const {
987 987
      Value tmp = m[k]; 
988 988
      return tmp >= 0 ? tmp : -tmp;
989 989
    }
990 990

	
991 991
  };
992 992
  
993 993
  ///Returns an \c AbsMap class
994 994

	
995 995
  ///This function just returns an \c AbsMap class.
996 996
  ///\relates AbsMap
997 997
  template<typename M> 
998 998
  inline AbsMap<M> absMap(const M &m) {
999 999
    return AbsMap<M>(m);
1000 1000
  }
1001 1001

	
1002 1002
  ///Converts an STL style functor to a map
1003 1003

	
1004
  ///This \c concepts::ReadMap "read only map" returns the value
1004
  ///This \ref concepts::ReadMap "read only map" returns the value
1005 1005
  ///of a given functor.
1006 1006
  ///
1007 1007
  ///Template parameters \c K and \c V will become its
1008 1008
  ///\c Key and \c Value. 
1009 1009
  ///In most cases they have to be given explicitly because a 
1010 1010
  ///functor typically does not provide such typedefs.
1011 1011
  ///
1012 1012
  ///Parameter \c F is the type of the used functor.
1013 1013
  ///
1014 1014
  ///\sa MapFunctor
1015 1015
  template<typename F, 
1016 1016
	   typename K = typename F::argument_type, 
1017 1017
	   typename V = typename F::result_type> 
1018 1018
  class FunctorMap : public MapBase<K, V> {
1019 1019
    F f;
1020 1020
  public:
1021 1021
    typedef MapBase<K, V> Parent;
1022 1022
    typedef typename Parent::Key Key;
1023 1023
    typedef typename Parent::Value Value;
1024 1024

	
1025 1025
    ///Constructor
1026 1026
    FunctorMap(const F &_f = F()) : f(_f) {}
1027 1027
    /// \e
1028 1028
    Value operator[](Key k) const { return f(k);}
1029 1029
  };
1030 1030
  
1031 1031
  ///Returns a \c FunctorMap class
1032 1032

	
1033 1033
  ///This function just returns a \c FunctorMap class.
1034 1034
  ///
1035 1035
  ///It is specialized for adaptable function classes and
1036 1036
  ///C++ functions.
1037 1037
  ///\relates FunctorMap
1038 1038
  template<typename K, typename V, typename F> inline 
1039 1039
  FunctorMap<F, K, V> functorMap(const F &f) {
1040 1040
    return FunctorMap<F, K, V>(f);
1041 1041
  }
1042 1042

	
1043 1043
  template <typename F> inline 
1044 1044
  FunctorMap<F, typename F::argument_type, typename F::result_type> 
1045 1045
  functorMap(const F &f) {
1046 1046
    return FunctorMap<F, typename F::argument_type, 
1047 1047
      typename F::result_type>(f);
1048 1048
  }
1049 1049

	
1050 1050
  template <typename K, typename V> inline 
1051 1051
  FunctorMap<V (*)(K), K, V> functorMap(V (*f)(K)) {
1052 1052
    return FunctorMap<V (*)(K), K, V>(f);
1053 1053
  }
1054 1054

	
1055 1055

	
1056 1056
  ///Converts a map to an STL style (unary) functor
1057 1057

	
1058 1058
  ///This class Converts a map to an STL style (unary) functor.
1059 1059
  ///that is it provides an <tt>operator()</tt> to read its values.
1060 1060
  ///
1061 1061
  ///For the sake of convenience it also works as
1062
  ///a ususal \c concepts::ReadMap "readable map",
1062
  ///a ususal \ref concepts::ReadMap "readable map",
1063 1063
  ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
1064 1064
  ///
1065 1065
  ///\sa FunctorMap
1066 1066
  template <typename M> 
1067 1067
  class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
1068 1068
    const M& m;
1069 1069
  public:
1070 1070
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1071 1071
    typedef typename Parent::Key Key;
1072 1072
    typedef typename Parent::Value Value;
1073 1073

	
1074 1074
    typedef typename M::Key argument_type;
1075 1075
    typedef typename M::Value result_type;
1076 1076

	
1077 1077
    ///Constructor
1078 1078
    MapFunctor(const M &_m) : m(_m) {};
1079 1079
    ///\e
1080 1080
    Value operator()(Key k) const {return m[k];}
1081 1081
    ///\e
1082 1082
    Value operator[](Key k) const {return m[k];}
1083 1083
  };
1084 1084
  
1085 1085
  ///Returns a \c MapFunctor class
1086 1086

	
1087 1087
  ///This function just returns a \c MapFunctor class.
1088 1088
  ///\relates MapFunctor
1089 1089
  template<typename M> 
1090 1090
  inline MapFunctor<M> mapFunctor(const M &m) {
1091 1091
    return MapFunctor<M>(m);
1092 1092
  }
1093 1093

	
1094 1094
  ///Applies all map setting operations to two maps
1095 1095

	
1096
  ///This map has two \c concepts::ReadMap "readable map"
1096
  ///This map has two \ref concepts::ReadMap "readable map"
1097 1097
  ///parameters and each read request will be passed just to the
1098
  ///first map. This class is the just readable map type of the ForkWriteMap.
1098
  ///first map. This class is the just readable map type of the \c ForkWriteMap.
1099 1099
  ///
1100 1100
  ///The \c Key and \c Value are inherited from \c M1.
1101 1101
  ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
1102 1102
  ///
1103 1103
  ///\sa ForkWriteMap
1104 1104
  ///
1105 1105
  /// \todo Why is it needed?
1106 1106
  template<typename  M1, typename M2> 
1107 1107
  class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
1108 1108
    const M1& m1;
1109 1109
    const M2& m2;
1110 1110
  public:
1111 1111
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
1112 1112
    typedef typename Parent::Key Key;
1113 1113
    typedef typename Parent::Value Value;
1114 1114

	
1115 1115
    ///Constructor
1116 1116
    ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {};
1117 1117
    /// \e
1118 1118
    Value operator[](Key k) const {return m1[k];}
1119 1119
  };
1120 1120

	
1121 1121

	
1122 1122
  ///Applies all map setting operations to two maps
1123 1123

	
1124
  ///This map has two \c concepts::WriteMap "writable map"
1124
  ///This map has two \ref concepts::WriteMap "writable map"
1125 1125
  ///parameters and each write request will be passed to both of them.
1126
  ///If \c M1 is also \c concepts::ReadMap "readable",
1126
  ///If \c M1 is also \ref concepts::ReadMap "readable",
1127 1127
  ///then the read operations will return the
1128 1128
  ///corresponding values of \c M1.
1129 1129
  ///
1130 1130
  ///The \c Key and \c Value are inherited from \c M1.
1131 1131
  ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
1132 1132
  ///
1133 1133
  ///\sa ForkMap
1134 1134
  template<typename  M1, typename M2> 
1135 1135
  class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
1136 1136
    M1& m1;
1137 1137
    M2& m2;
1138 1138
  public:
1139 1139
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
1140 1140
    typedef typename Parent::Key Key;
1141 1141
    typedef typename Parent::Value Value;
1142 1142

	
1143 1143
    ///Constructor
1144 1144
    ForkWriteMap(M1 &_m1, M2 &_m2) : m1(_m1), m2(_m2) {};
1145 1145
    ///\e
1146 1146
    Value operator[](Key k) const {return m1[k];}
1147 1147
    ///\e
1148 1148
    void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
1149 1149
  };
1150 1150
  
1151 1151
  ///Returns a \c ForkMap class
1152 1152

	
1153 1153
  ///This function just returns a \c ForkMap class.
1154 1154
  ///\relates ForkMap
1155 1155
  template <typename M1, typename M2> 
1156 1156
  inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
1157 1157
    return ForkMap<M1, M2>(m1,m2);
1158 1158
  }
1159 1159

	
1160 1160
  ///Returns a \c ForkWriteMap class
1161 1161

	
1162 1162
  ///This function just returns a \c ForkWriteMap class.
1163 1163
  ///\relates ForkWriteMap
1164 1164
  template <typename M1, typename M2> 
1165 1165
  inline ForkWriteMap<M1, M2> forkMap(M1 &m1, M2 &m2) {
1166 1166
    return ForkWriteMap<M1, M2>(m1,m2);
1167 1167
  }
1168 1168

	
1169 1169

	
1170 1170
  
1171 1171
  /* ************* BOOL MAPS ******************* */
1172 1172
  
1173 1173
  ///Logical 'not' of a map
1174 1174
  
1175
  ///This bool \c concepts::ReadMap "read only map" returns the 
1175
  ///This bool \ref concepts::ReadMap "read only map" returns the 
1176 1176
  ///logical negation of the value returned by the given map.
1177 1177
  ///Its \c Key is inherited from \c M, its Value is \c bool.
1178 1178
  ///
1179 1179
  ///\sa NotWriteMap
1180 1180
  template <typename M> 
1181 1181
  class NotMap : public MapBase<typename M::Key, bool> {
1182 1182
    const M& m;
1183 1183
  public:
1184 1184
    typedef MapBase<typename M::Key, bool> Parent;
1185 1185
    typedef typename Parent::Key Key;
1186 1186
    typedef typename Parent::Value Value;
1187 1187

	
1188 1188
    /// Constructor
1189 1189
    NotMap(const M &_m) : m(_m) {};
1190 1190
    ///\e
1191 1191
    Value operator[](Key k) const {return !m[k];}
1192 1192
  };
1193 1193

	
1194 1194
  ///Logical 'not' of a map (ReadWrie version)
1195 1195
  
1196
  ///This bool \c concepts::ReadWriteMap "read-write map" returns the 
1196
  ///This bool \ref concepts::ReadWriteMap "read-write map" returns the 
1197 1197
  ///logical negation of the value returned by the given map. When it is set,
1198 1198
  ///the opposite value is set to the original map.
1199 1199
  ///Its \c Key is inherited from \c M, its Value is \c bool.
1200 1200
  ///
1201 1201
  ///\sa NotMap
1202 1202
  template <typename M> 
1203 1203
  class NotWriteMap : public MapBase<typename M::Key, bool> {
1204 1204
    M& m;
1205 1205
  public:
1206 1206
    typedef MapBase<typename M::Key, bool> Parent;
1207 1207
    typedef typename Parent::Key Key;
1208 1208
    typedef typename Parent::Value Value;
1209 1209

	
1210 1210
    /// Constructor
1211 1211
    NotWriteMap(M &_m) : m(_m) {};
1212 1212
    ///\e
1213 1213
    Value operator[](Key k) const {return !m[k];}
1214 1214
    ///\e
1215 1215
    void set(Key k, bool v) { m.set(k, !v); }
1216 1216
  };
1217 1217
  
1218 1218
  ///Returns a \c NotMap class
1219 1219
  
1220 1220
  ///This function just returns a \c NotMap class.
1221 1221
  ///\relates NotMap
1222 1222
  template <typename M> 
1223 1223
  inline NotMap<M> notMap(const M &m) {
1224 1224
    return NotMap<M>(m);
1225 1225
  }
1226 1226
  
1227 1227
  ///Returns a \c NotWriteMap class
1228 1228
  
1229 1229
  ///This function just returns a \c NotWriteMap class.
1230 1230
  ///\relates NotWriteMap
1231 1231
  template <typename M> 
1232 1232
  inline NotWriteMap<M> notMap(M &m) {
1233 1233
    return NotWriteMap<M>(m);
1234 1234
  }
1235 1235

	
1236 1236
  namespace _maps_bits {
1237 1237

	
1238 1238
    template <typename Value>
1239 1239
    struct Identity {
1240 1240
      typedef Value argument_type;
1241 1241
      typedef Value result_type;
1242 1242
      Value operator()(const Value& val) const {
1243 1243
	return val;
1244 1244
      }
1245 1245
    };
1246 1246

	
1247 1247
    template <typename _Iterator, typename Enable = void>
1248 1248
    struct IteratorTraits {
1249 1249
      typedef typename std::iterator_traits<_Iterator>::value_type Value;
1250 1250
    };
1251 1251

	
1252 1252
    template <typename _Iterator>
1253 1253
    struct IteratorTraits<_Iterator,
1254 1254
      typename exists<typename _Iterator::container_type>::type> 
1255 1255
    {
1256 1256
      typedef typename _Iterator::container_type::value_type Value;
1257 1257
    };
1258 1258

	
1259 1259
  }
1260 1260
  
1261 1261

	
1262 1262
  /// \brief Writable bool map for logging each \c true assigned element
1263 1263
  ///
1264
  /// Writable bool map for logging each \c true assigned element, i.e it
1265
  /// copies all the keys set to \c true to the given iterator.
1264
  /// A \ref concepts::ReadWriteMap "read-write" bool map for logging 
1265
  /// each \c true assigned element, i.e it/ copies all the keys set 
1266
  /// to \c true to the given iterator.
1266 1267
  ///
1267 1268
  /// \note The container of the iterator should contain space 
1268 1269
  /// for each element.
1269 1270
  ///
1270 1271
  /// The following example shows how you can write the edges found by the Prim
1271 1272
  /// algorithm directly
1272 1273
  /// to the standard output.
1273 1274
  ///\code
1274 1275
  /// typedef IdMap<Graph, Edge> EdgeIdMap;
1275 1276
  /// EdgeIdMap edgeId(graph);
1276 1277
  ///
1277 1278
  /// typedef MapFunctor<EdgeIdMap> EdgeIdFunctor;
1278 1279
  /// EdgeIdFunctor edgeIdFunctor(edgeId);
1279 1280
  ///
1280 1281
  /// StoreBoolMap<ostream_iterator<int>, EdgeIdFunctor> 
1281 1282
  ///   writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor);
1282 1283
  ///
1283 1284
  /// prim(graph, cost, writerMap);
1284 1285
  ///\endcode
1285 1286
  ///
1286 1287
  ///\sa BackInserterBoolMap 
1287 1288
  ///\sa FrontInserterBoolMap 
1288 1289
  ///\sa InserterBoolMap 
1289 1290
  ///
1290 1291
  ///\todo Revise the name of this class and the related ones.
1291 1292
  template <typename _Iterator, 
1292 1293
            typename _Functor =
1293 1294
            _maps_bits::Identity<typename _maps_bits::
1294 1295
                                 IteratorTraits<_Iterator>::Value> >
1295 1296
  class StoreBoolMap {
1296 1297
  public:
1297 1298
    typedef _Iterator Iterator;
1298 1299

	
1299 1300
    typedef typename _Functor::argument_type Key;
1300 1301
    typedef bool Value;
1301 1302

	
1302 1303
    typedef _Functor Functor;
1303 1304

	
1304 1305
    /// Constructor
1305 1306
    StoreBoolMap(Iterator it, const Functor& functor = Functor()) 
1306 1307
      : _begin(it), _end(it), _functor(functor) {}
1307 1308

	
1308 1309
    /// Gives back the given iterator set for the first key
1309 1310
    Iterator begin() const {
1310 1311
      return _begin;
1311 1312
    }
1312 1313
 
1313 1314
    /// Gives back the the 'after the last' iterator
1314 1315
    Iterator end() const {
1315 1316
      return _end;
1316 1317
    }
1317 1318

	
1318 1319
    /// The \c set function of the map
1319 1320
    void set(const Key& key, Value value) const {
1320 1321
      if (value) {
1321 1322
	*_end++ = _functor(key);
1322 1323
      }
1323 1324
    }
1324 1325
    
1325 1326
  private:
1326 1327
    Iterator _begin;
1327 1328
    mutable Iterator _end;
1328 1329
    Functor _functor;
1329 1330
  };
1330 1331

	
1331 1332
  /// \brief Writable bool map for logging each \c true assigned element in 
1332 1333
  /// a back insertable container.
1333 1334
  ///
1334 1335
  /// Writable bool map for logging each \c true assigned element by pushing
1335 1336
  /// them into a back insertable container.
1336 1337
  /// It can be used to retrieve the items into a standard
1337 1338
  /// container. The next example shows how you can store the
1338 1339
  /// edges found by the Prim algorithm in a vector.
1339 1340
  ///
1340 1341
  ///\code
1341 1342
  /// vector<Edge> span_tree_edges;
1342 1343
  /// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges);
1343 1344
  /// prim(graph, cost, inserter_map);
1344 1345
  ///\endcode
1345 1346
  ///
1346 1347
  ///\sa StoreBoolMap
1347 1348
  ///\sa FrontInserterBoolMap
1348 1349
  ///\sa InserterBoolMap
1349 1350
  template <typename Container,
1350 1351
            typename Functor =
1351 1352
            _maps_bits::Identity<typename Container::value_type> >
1352 1353
  class BackInserterBoolMap {
1353 1354
  public:
1354 1355
    typedef typename Functor::argument_type Key;
1355 1356
    typedef bool Value;
1356 1357

	
1357 1358
    /// Constructor
1358 1359
    BackInserterBoolMap(Container& _container, 
1359 1360
                        const Functor& _functor = Functor()) 
1360 1361
      : container(_container), functor(_functor) {}
1361 1362

	
1362 1363
    /// The \c set function of the map
1363 1364
    void set(const Key& key, Value value) {
1364 1365
      if (value) {
1365 1366
	container.push_back(functor(key));
1366 1367
      }
1367 1368
    }
1368 1369
    
1369 1370
  private:
1370 1371
    Container& container;
1371 1372
    Functor functor;
1372 1373
  };
1373 1374

	
1374 1375
  /// \brief Writable bool map for logging each \c true assigned element in 
1375 1376
  /// a front insertable container.
1376 1377
  ///
1377 1378
  /// Writable bool map for logging each \c true assigned element by pushing
1378 1379
  /// them into a front insertable container.
1379 1380
  /// It can be used to retrieve the items into a standard
1380 1381
  /// container. For example see \ref BackInserterBoolMap.
1381 1382
  ///
1382 1383
  ///\sa BackInserterBoolMap
1383 1384
  ///\sa InserterBoolMap
1384 1385
  template <typename Container,
1385 1386
            typename Functor =
1386 1387
            _maps_bits::Identity<typename Container::value_type> >
1387 1388
  class FrontInserterBoolMap {
1388 1389
  public:
1389 1390
    typedef typename Functor::argument_type Key;
1390 1391
    typedef bool Value;
1391 1392

	
1392 1393
    /// Constructor
1393 1394
    FrontInserterBoolMap(Container& _container,
1394 1395
                         const Functor& _functor = Functor()) 
1395 1396
      : container(_container), functor(_functor) {}
1396 1397

	
1397 1398
    /// The \c set function of the map
1398 1399
    void set(const Key& key, Value value) {
1399 1400
      if (value) {
1400 1401
	container.push_front(functor(key));
1401 1402
      }
1402 1403
    }
1403 1404
    
1404 1405
  private:
1405 1406
    Container& container;    
1406 1407
    Functor functor;
1407 1408
  };
1408 1409

	
1409 1410
  /// \brief Writable bool map for storing each \c true assigned element in 
1410 1411
  /// an insertable container.
1411 1412
  ///
1412 1413
  /// Writable bool map for storing each \c true assigned element in an 
1413 1414
  /// insertable container. It will insert all the keys set to \c true into
1414 1415
  /// the container.
1415 1416
  ///
1416 1417
  /// For example, if you want to store the cut arcs of the strongly
1417 1418
  /// connected components in a set you can use the next code:
1418 1419
  ///
1419 1420
  ///\code
1420 1421
  /// set<Arc> cut_arcs;
1421 1422
  /// InserterBoolMap<set<Arc> > inserter_map(cut_arcs);
1422 1423
  /// stronglyConnectedCutArcs(digraph, cost, inserter_map);
1423 1424
  ///\endcode
1424 1425
  ///
1425 1426
  ///\sa BackInserterBoolMap
1426 1427
  ///\sa FrontInserterBoolMap
1427 1428
  template <typename Container,
1428 1429
            typename Functor =
1429 1430
            _maps_bits::Identity<typename Container::value_type> >
1430 1431
  class InserterBoolMap {
1431 1432
  public:
1432 1433
    typedef typename Container::value_type Key;
1433 1434
    typedef bool Value;
1434 1435

	
1435 1436
    /// Constructor with specified iterator
1436 1437
    
1437 1438
    /// Constructor with specified iterator.
1438 1439
    /// \param _container The container for storing the elements.
1439 1440
    /// \param _it The elements will be inserted before this iterator.
1440 1441
    /// \param _functor The functor that is used when an element is stored.
1441 1442
    InserterBoolMap(Container& _container, typename Container::iterator _it,
1442 1443
                    const Functor& _functor = Functor()) 
1443 1444
      : container(_container), it(_it), functor(_functor) {}
1444 1445

	
1445 1446
    /// Constructor
1446 1447

	
1447 1448
    /// Constructor without specified iterator.
1448 1449
    /// The elements will be inserted before <tt>_container.end()</tt>.
1449 1450
    /// \param _container The container for storing the elements.
1450 1451
    /// \param _functor The functor that is used when an element is stored.
1451 1452
    InserterBoolMap(Container& _container, const Functor& _functor = Functor())
1452 1453
      : container(_container), it(_container.end()), functor(_functor) {}
1453 1454

	
1454 1455
    /// The \c set function of the map
1455 1456
    void set(const Key& key, Value value) {
1456 1457
      if (value) {
1457 1458
	it = container.insert(it, functor(key));
1458 1459
        ++it;
1459 1460
      }
1460 1461
    }
1461 1462
    
1462 1463
  private:
1463 1464
    Container& container;
1464 1465
    typename Container::iterator it;
1465 1466
    Functor functor;
1466 1467
  };
1467 1468

	
1468 1469
  /// \brief Writable bool map for filling each \c true assigned element with a 
1469 1470
  /// given value.
1470 1471
  ///
1471 1472
  /// Writable bool map for filling each \c true assigned element with a 
1472 1473
  /// given value. The value can set the container.
1473 1474
  ///
1474 1475
  /// The following code finds the connected components of a graph
1475 1476
  /// and stores it in the \c comp map:
1476 1477
  ///\code
1477 1478
  /// typedef Graph::NodeMap<int> ComponentMap;
1478 1479
  /// ComponentMap comp(graph);
1479 1480
  /// typedef FillBoolMap<Graph::NodeMap<int> > ComponentFillerMap;
1480 1481
  /// ComponentFillerMap filler(comp, 0);
1481 1482
  ///
1482 1483
  /// Dfs<Graph>::DefProcessedMap<ComponentFillerMap>::Create dfs(graph);
1483 1484
  /// dfs.processedMap(filler);
1484 1485
  /// dfs.init();
1485 1486
  /// for (NodeIt it(graph); it != INVALID; ++it) {
1486 1487
  ///   if (!dfs.reached(it)) {
1487 1488
  ///     dfs.addSource(it);
1488 1489
  ///     dfs.start();
1489 1490
  ///     ++filler.fillValue();
1490 1491
  ///   }
1491 1492
  /// }
1492 1493
  ///\endcode
1493 1494
  template <typename Map>
1494 1495
  class FillBoolMap {
1495 1496
  public:
1496 1497
    typedef typename Map::Key Key;
1497 1498
    typedef bool Value;
1498 1499

	
1499 1500
    /// Constructor
1500 1501
    FillBoolMap(Map& _map, const typename Map::Value& _fill) 
1501 1502
      : map(_map), fill(_fill) {}
1502 1503

	
1503 1504
    /// Constructor
1504 1505
    FillBoolMap(Map& _map) 
1505 1506
      : map(_map), fill() {}
1506 1507

	
1507 1508
    /// Gives back the current fill value
1508 1509
    const typename Map::Value& fillValue() const {
1509 1510
      return fill;
1510 1511
    } 
1511 1512

	
1512 1513
    /// Gives back the current fill value
1513 1514
    typename Map::Value& fillValue() {
1514 1515
      return fill;
1515 1516
    } 
1516 1517

	
1517 1518
    /// Sets the current fill value
1518 1519
    void fillValue(const typename Map::Value& _fill) {
1519 1520
      fill = _fill;
1520 1521
    } 
1521 1522

	
1522 1523
    /// The \c set function of the map
1523 1524
    void set(const Key& key, Value value) {
1524 1525
      if (value) {
1525 1526
	map.set(key, fill);
1526 1527
      }
1527 1528
    }
1528 1529
    
1529 1530
  private:
1530 1531
    Map& map;
1531 1532
    typename Map::Value fill;
1532 1533
  };
1533 1534

	
1534 1535

	
1535 1536
  /// \brief Writable bool map for storing the sequence number of 
1536 1537
  /// \c true assignments.  
1537 1538
  /// 
1538 1539
  /// Writable bool map that stores for each \c true assigned elements  
1539 1540
  /// the sequence number of this setting.
1540 1541
  /// It makes it easy to calculate the leaving
1541 1542
  /// order of the nodes in the \c Dfs algorithm.
1542 1543
  ///
1543 1544
  ///\code
1544 1545
  /// typedef Digraph::NodeMap<int> OrderMap;
1545 1546
  /// OrderMap order(digraph);
1546 1547
  /// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap;
1547 1548
  /// OrderSetterMap setter(order);
1548 1549
  /// Dfs<Digraph>::DefProcessedMap<OrderSetterMap>::Create dfs(digraph);
1549 1550
  /// dfs.processedMap(setter);
1550 1551
  /// dfs.init();
1551 1552
  /// for (NodeIt it(digraph); it != INVALID; ++it) {
1552 1553
  ///   if (!dfs.reached(it)) {
1553 1554
  ///     dfs.addSource(it);
1554 1555
  ///     dfs.start();
1555 1556
  ///   }
1556 1557
  /// }
1557 1558
  ///\endcode
1558 1559
  ///
1559 1560
  /// The storing of the discovering order is more difficult because the
1560 1561
  /// ReachedMap should be readable in the dfs algorithm but the setting
1561 1562
  /// order map is not readable. Thus we must use the fork map:
1562 1563
  ///
1563 1564
  ///\code
1564 1565
  /// typedef Digraph::NodeMap<int> OrderMap;
1565 1566
  /// OrderMap order(digraph);
1566 1567
  /// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap;
1567 1568
  /// OrderSetterMap setter(order);
1568 1569
  /// typedef Digraph::NodeMap<bool> StoreMap;
1569 1570
  /// StoreMap store(digraph);
1570 1571
  ///
1571 1572
  /// typedef ForkWriteMap<StoreMap, OrderSetterMap> ReachedMap;
1572 1573
  /// ReachedMap reached(store, setter);
1573 1574
  ///
1574 1575
  /// Dfs<Digraph>::DefReachedMap<ReachedMap>::Create dfs(digraph);
1575 1576
  /// dfs.reachedMap(reached);
1576 1577
  /// dfs.init();
1577 1578
  /// for (NodeIt it(digraph); it != INVALID; ++it) {
1578 1579
  ///   if (!dfs.reached(it)) {
1579 1580
  ///     dfs.addSource(it);
1580 1581
  ///     dfs.start();
1581 1582
  ///   }
1582 1583
  /// }
1583 1584
  ///\endcode
1584 1585
  template <typename Map>
1585 1586
  class SettingOrderBoolMap {
1586 1587
  public:
1587 1588
    typedef typename Map::Key Key;
1588 1589
    typedef bool Value;
1589 1590

	
1590 1591
    /// Constructor
1591 1592
    SettingOrderBoolMap(Map& _map) 
1592 1593
      : map(_map), counter(0) {}
1593 1594

	
1594 1595
    /// Number of set operations.
1595 1596
    int num() const {
1596 1597
      return counter;
1597 1598
    }
1598 1599

	
1599 1600
    /// The \c set function of the map
1600 1601
    void set(const Key& key, Value value) {
1601 1602
      if (value) {
1602 1603
	map.set(key, counter++);
1603 1604
      }
1604 1605
    }
1605 1606
    
1606 1607
  private:
1607 1608
    Map& map;
1608 1609
    int counter;
1609 1610
  };
1610 1611

	
1611 1612
  /// @}
1612 1613
}
1613 1614

	
1614 1615
#endif // LEMON_MAPS_H
0 comments (0 inline)