src/lemon/map_iterator.h
author marci
Wed, 01 Dec 2004 14:08:37 +0000
changeset 1026 bd7ea1a718e2
parent 921 818510fa3d99
child 1164 80bb73097736
permissions -rw-r--r--
More rational structure of classes in MergeGraphWrappers
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/lemon/map_iterator.h - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@906
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@906
     6
 *
alpar@906
     7
 * Permission to use, modify and distribute this software is granted
alpar@906
     8
 * provided that this copyright notice appears in all copies. For
alpar@906
     9
 * precise terms see the accompanying LICENSE file.
alpar@906
    10
 *
alpar@906
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    12
 * express or implied, and with no claim as to its suitability for any
alpar@906
    13
 * purpose.
alpar@906
    14
 *
alpar@906
    15
 */
alpar@906
    16
alpar@921
    17
#ifndef LEMON_MAP_ITERATOR_H
alpar@921
    18
#define LEMON_MAP_ITERATOR_H
deba@822
    19
deba@844
    20
#include <iterator>
deba@844
    21
alpar@921
    22
#include <lemon/extended_pair.h>
deba@822
    23
deba@830
    24
///\ingroup graphmaps
deba@830
    25
///\file
deba@830
    26
///\brief Iterators on the maps.
deba@830
    27
alpar@921
    28
namespace lemon {
deba@822
    29
deba@830
    30
  /// \addtogroup graphmaps
deba@830
    31
  /// @{
deba@830
    32
deba@830
    33
  /** The base class all of the map iterators.
deba@830
    34
   *  The class defines the typedefs of the iterators,
deba@830
    35
   *  simple step functions and equality operators.
deba@830
    36
   */ 
deba@822
    37
deba@822
    38
  template <typename Map>
deba@830
    39
  class MapIteratorBase {
deba@822
    40
deba@830
    41
  public:
deba@844
    42
deba@830
    43
    /// The key type of the iterator.
alpar@987
    44
    typedef typename Map::Key Key;
deba@830
    45
    /// The iterator to iterate on the keys.
deba@830
    46
    typedef typename Map::KeyIt KeyIt;
deba@830
    47
deba@830
    48
    /// The value type of the iterator.
alpar@987
    49
    typedef typename Map::Value Value;
deba@830
    50
    /// The reference type of the iterator.
alpar@987
    51
    typedef typename Map::Reference Reference;
deba@830
    52
    /// The pointer type of the iterator.
alpar@987
    53
    typedef typename Map::Pointer Pointer;
deba@830
    54
deba@830
    55
    /// The const value type of the iterator.
alpar@987
    56
    typedef typename Map::ConstValue ConstValue;
deba@830
    57
    /// The const reference type of the iterator.
alpar@987
    58
    typedef typename Map::ConstReference ConstReference;
deba@830
    59
    /// The pointer type of the iterator.
alpar@987
    60
    typedef typename Map::ConstPointer ConstPointer;
deba@830
    61
deba@830
    62
  protected:
deba@830
    63
deba@830
    64
    KeyIt it;
deba@830
    65
deba@830
    66
    /// Default constructor.
deba@830
    67
    MapIteratorBase() {}
deba@830
    68
deba@830
    69
    /// KeyIt initialized MapIteratorBase constructor.
deba@830
    70
    MapIteratorBase(const KeyIt pit) : it(pit) {}
deba@830
    71
deba@830
    72
  public:
deba@830
    73
deba@830
    74
    /// Stepping forward in the map.   
deba@830
    75
    void increment() { 
deba@830
    76
      ++it; 
deba@830
    77
    }
deba@830
    78
deba@830
    79
    /// The equality operator of the map.
deba@830
    80
    bool operator==(const MapIteratorBase& pit) const {
deba@830
    81
      return pit.it == it;
deba@830
    82
    }
deba@830
    83
	
deba@830
    84
    /// The not-equality operator of the map.
deba@830
    85
    bool operator!=(const MapIteratorBase& pit) const {
deba@830
    86
      return !(*this == pit);
deba@830
    87
    }
deba@830
    88
  };
deba@830
    89
deba@830
    90
  template <typename Map> class MapConstIterator;
deba@822
    91
deba@822
    92
  /** Compatible iterator with the stl maps' iterators.
deba@830
    93
   * It iterates on pairs of a key and a value.
deba@822
    94
   */
deba@822
    95
  template <typename Map>  
deba@830
    96
  class MapIterator : public MapIteratorBase<Map> {
deba@830
    97
deba@822
    98
    friend class MapConstIterator<Map>;
deba@822
    99
deba@844
   100
deba@822
   101
  public:
deba@822
   102
deba@844
   103
    /// The iterator base class.
deba@844
   104
    typedef MapIteratorBase<Map> Base;
deba@844
   105
deba@822
   106
    /// The key type of the iterator.
alpar@987
   107
    typedef typename Map::Key Key;
deba@822
   108
    /// The iterator to iterate on the keys.
deba@822
   109
    typedef typename Map::KeyIt KeyIt;
deba@822
   110
deba@822
   111
    /// The value type of the iterator.
alpar@987
   112
    typedef typename Map::Value Value;
deba@822
   113
    /// The reference type of the iterator.
alpar@987
   114
    typedef typename Map::Reference Reference;
deba@822
   115
    /// The pointer type of the iterator.
alpar@987
   116
    typedef typename Map::Pointer Pointer;
deba@822
   117
deba@822
   118
    /// The const value type of the iterator.
alpar@987
   119
    typedef typename Map::ConstValue ConstValue;
deba@822
   120
    /// The const reference type of the iterator.
alpar@987
   121
    typedef typename Map::ConstReference ConstReference;
deba@822
   122
    /// The pointer type of the iterator.
alpar@987
   123
    typedef typename Map::ConstPointer ConstPointer;
deba@822
   124
    
deba@822
   125
  public:
deba@822
   126
deba@844
   127
    /// The value type of the iterator.
alpar@987
   128
    typedef extended_pair<Key, const Key&,
alpar@987
   129
      Value, const Value&> PairValue;
deba@844
   130
deba@830
   131
    /// The reference type of the iterator. 
alpar@987
   132
    typedef extended_pair<const Key&, const Key&, 
alpar@987
   133
      Reference, Reference> PairReference;
deba@822
   134
deba@830
   135
    /// Default constructor. 
deba@830
   136
    MapIterator() {}
deba@830
   137
deba@830
   138
    /// Constructor to initalize the iterators returned 
deba@830
   139
    /// by the begin() and end().
deba@844
   140
    MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {}
deba@830
   141
deba@830
   142
    /// Dereference operator for the iterator.
alpar@987
   143
    PairReference operator*() {
alpar@987
   144
      return PairReference(Base::it, (*map)[Base::it]);
deba@822
   145
    }
deba@822
   146
deba@830
   147
    /// The pointer type of the iterator.
alpar@987
   148
    class PairPointer {
deba@822
   149
      friend class MapIterator;
deba@822
   150
    private:
alpar@987
   151
      PairReference data;
alpar@987
   152
      PairPointer(const Key& key, Reference val) 
deba@822
   153
	: data(key, val) {}
deba@822
   154
    public:
alpar@987
   155
      PairReference* operator->() {return &data;}
deba@822
   156
    };
deba@822
   157
deba@830
   158
    /// Arrow operator for the iterator.
alpar@987
   159
    PairPointer operator->() {
alpar@987
   160
      return PairPointer(Base::it, ((*map)[Base::it])); 
deba@822
   161
    }
deba@830
   162
	
deba@830
   163
    /// The pre increment operator of the iterator.
deba@822
   164
    MapIterator& operator++() { 
deba@844
   165
      Base::increment(); 
deba@822
   166
      return *this; 
deba@822
   167
    }
deba@822
   168
deba@830
   169
    /// The post increment operator of the iterator.
deba@822
   170
    MapIterator operator++(int) { 
deba@844
   171
      MapIterator tmp(*this); 
deba@844
   172
      Base::increment(); 
deba@822
   173
      return tmp; 
deba@822
   174
    }
deba@822
   175
deba@822
   176
  private:
deba@822
   177
    Map* map;
deba@844
   178
deba@844
   179
  public:
deba@844
   180
    // STL  compatibility typedefs.
deba@844
   181
    typedef std::forward_iterator_tag iterator_category;
deba@844
   182
    typedef int difference_type;
alpar@987
   183
    typedef PairValue value_type;
alpar@987
   184
    typedef PairReference reference;
alpar@987
   185
    typedef PairPointer pointer;
deba@822
   186
  };
deba@822
   187
deba@822
   188
  /** Compatible iterator with the stl maps' iterators.
deba@822
   189
   *  It iterates on pairs of a key and a value.
deba@822
   190
   */
deba@822
   191
  template <typename Map>
deba@830
   192
  class MapConstIterator : public MapIteratorBase<Map> {
deba@830
   193
    
deba@822
   194
  public:
deba@822
   195
deba@844
   196
    /// The iterator base class.
deba@844
   197
    typedef MapIteratorBase<Map> Base;
deba@844
   198
deba@822
   199
    /// The key type of the iterator.
alpar@987
   200
    typedef typename Map::Key Key;
deba@822
   201
    /// The iterator to iterate on the keys.
deba@822
   202
    typedef typename Map::KeyIt KeyIt;
deba@822
   203
deba@822
   204
    /// The value type of the iterator.
alpar@987
   205
    typedef typename Map::Value Value;
deba@822
   206
    /// The reference type of the iterator.
alpar@987
   207
    typedef typename Map::Reference Reference;
deba@822
   208
    /// The pointer type of the iterator.
alpar@987
   209
    typedef typename Map::Pointer Pointer;
deba@822
   210
deba@822
   211
    /// The const value type of the iterator.
alpar@987
   212
    typedef typename Map::ConstValue ConstValue;
deba@822
   213
    /// The const reference type of the iterator.
alpar@987
   214
    typedef typename Map::ConstReference ConstReference;
deba@822
   215
    /// The pointer type of the iterator.
alpar@987
   216
    typedef typename Map::ConstPointer ConstPointer;
deba@822
   217
deba@822
   218
  public:    
deba@822
   219
deba@830
   220
    /// Default constructor. 
deba@822
   221
    MapConstIterator() {}
deba@822
   222
deba@830
   223
    /// Constructor to initalize the the iterators returned
deba@830
   224
    ///  by the begin() and end().
deba@830
   225
    MapConstIterator(const Map& pmap, const KeyIt& pit) 
deba@844
   226
      : Base(pit), map(&pmap) {}
deba@830
   227
deba@830
   228
    /// Constructor to create const iterator from a non const.
deba@830
   229
    MapConstIterator(const MapIterator<Map>& pit) {
deba@844
   230
      Base::it = pit.Base::it;
deba@830
   231
      map = pit.map;
deba@830
   232
    }
deba@830
   233
deba@844
   234
    /// The value type of the iterator.
alpar@987
   235
    typedef extended_pair<Key, const Key&,
alpar@987
   236
      Value, const Value&> PairValue;
deba@844
   237
deba@830
   238
    /// The reference type of map.
alpar@987
   239
    typedef extended_pair<const Key&, const Key&, 
alpar@987
   240
      ConstReference, ConstReference> PairReference;
deba@822
   241
deba@830
   242
    /// Dereference operator for the iterator.
alpar@987
   243
    PairReference operator*() {
alpar@987
   244
      return PairReference(Base::it, (*map)[Base::it]);
deba@822
   245
    }
deba@822
   246
deba@830
   247
    /// The pointer type of the iterator.
alpar@987
   248
    class PairPointer {
deba@822
   249
      friend class MapConstIterator;
deba@822
   250
    private:
alpar@987
   251
      PairReference data;
alpar@987
   252
      PairPointer(const Key& key, ConstReference val) 
deba@822
   253
	: data(key, val) {}
deba@822
   254
    public:
alpar@987
   255
      PairReference* operator->() {return &data;}
deba@822
   256
    };
deba@822
   257
deba@830
   258
    /// Arrow operator for the iterator.
alpar@987
   259
    PairPointer operator->() {
alpar@987
   260
      return PairPointer(Base::it, (*map)[Base::it]); 
deba@822
   261
    }
deba@822
   262
deba@830
   263
    /// The pre increment operator of the iterator.
deba@822
   264
    MapConstIterator& operator++() { 
deba@844
   265
      Base::increment(); 
deba@822
   266
      return *this; 
deba@822
   267
    }
deba@822
   268
deba@830
   269
    /// The post increment operator of the iterator.
deba@822
   270
    MapConstIterator operator++(int) { 
deba@844
   271
      MapConstIterator tmp(*this); 
deba@844
   272
      Base::increment(); 
deba@822
   273
      return tmp; 
deba@822
   274
    }
deba@822
   275
deba@830
   276
  private:
deba@830
   277
    const Map* map;
deba@844
   278
deba@844
   279
  public:
deba@844
   280
    // STL  compatibility typedefs.
deba@844
   281
    typedef std::input_iterator_tag iterator_category;
deba@844
   282
    typedef int difference_type;
alpar@987
   283
    typedef PairValue value_type;
alpar@987
   284
    typedef PairReference reference;
alpar@987
   285
    typedef PairPointer pointer;
deba@830
   286
  };
deba@830
   287
deba@830
   288
  /** The class makes the KeyIt to an stl compatible iterator
deba@830
   289
   *  with dereferencing operator.
deba@830
   290
   */
deba@830
   291
  template <typename Map>
deba@830
   292
  class MapKeyIterator : public MapIteratorBase<Map> {
deba@830
   293
deba@830
   294
  public:
deba@830
   295
deba@844
   296
    /// The iterator base class.
deba@844
   297
    typedef MapIteratorBase<Map> Base;
deba@844
   298
 
deba@830
   299
    /// The key type of the iterator.
alpar@987
   300
    typedef typename Map::Key Key;
deba@830
   301
    /// The iterator to iterate on the keys.
deba@830
   302
    typedef typename Map::KeyIt KeyIt;
deba@830
   303
deba@830
   304
  public:
deba@830
   305
deba@830
   306
    /// Default constructor.
deba@830
   307
    MapKeyIterator() {}
deba@830
   308
deba@830
   309
    /// KeyIt initialized iterator.
deba@844
   310
    MapKeyIterator(const KeyIt& pit) : Base(pit) {}
deba@830
   311
deba@830
   312
    /// The pre increment operator of the iterator.
deba@830
   313
    MapKeyIterator& operator++() {
deba@844
   314
      Base::increment(); 
deba@830
   315
      return *this; 
deba@822
   316
    }
deba@822
   317
deba@830
   318
    /// The post increment operator of the iterator.
deba@830
   319
    MapKeyIterator operator++(int) {
deba@830
   320
      MapKeyIterator tmp(*this);
deba@844
   321
      Base::increment();
deba@830
   322
      return tmp;
deba@822
   323
    }
deba@830
   324
deba@830
   325
    /// The dereferencing operator of the iterator.
alpar@987
   326
    Key operator*() const {
alpar@987
   327
      return static_cast<Key>(Base::it);
deba@822
   328
    }
deba@844
   329
deba@844
   330
  public:
deba@844
   331
    // STL  compatibility typedefs.
deba@844
   332
    typedef std::input_iterator_tag iterator_category;
deba@844
   333
    typedef int difference_type;
alpar@987
   334
    typedef Key value_type;
alpar@987
   335
    typedef const Key& reference;
alpar@987
   336
    typedef const Key* pointer;
deba@830
   337
  };
deba@830
   338
deba@830
   339
  template <typename Map> class MapConstValueIterator;
deba@830
   340
deba@844
   341
  /** MapValueIterator creates an stl compatible iterator
deba@844
   342
   *  for the values.
deba@844
   343
   */
deba@830
   344
  template <typename Map>
deba@830
   345
  class MapValueIterator : public MapIteratorBase<Map> {
deba@830
   346
deba@830
   347
    friend class MapConstValueIterator<Map>;
deba@830
   348
deba@830
   349
  public:
deba@830
   350
deba@844
   351
    /// The iterator base class.
deba@844
   352
    typedef MapIteratorBase<Map> Base;
deba@844
   353
deba@830
   354
    /// The key type of the iterator.
alpar@987
   355
    typedef typename Map::Key Key;
deba@830
   356
    /// The iterator to iterate on the keys.
deba@830
   357
    typedef typename Map::KeyIt KeyIt;
deba@830
   358
deba@830
   359
deba@830
   360
    /// The value type of the iterator.
alpar@987
   361
    typedef typename Map::Value Value;
deba@830
   362
    /// The reference type of the iterator.
alpar@987
   363
    typedef typename Map::Reference Reference;
deba@830
   364
    /// The pointer type of the iterator.
alpar@987
   365
    typedef typename Map::Pointer Pointer;
deba@830
   366
deba@830
   367
    /// The const value type of the iterator.
alpar@987
   368
    typedef typename Map::ConstValue ConstValue;
deba@830
   369
    /// The const reference type of the iterator.
alpar@987
   370
    typedef typename Map::ConstReference ConstReference;
deba@830
   371
    /// The pointer type of the iterator.
alpar@987
   372
    typedef typename Map::ConstPointer ConstPointer;
deba@830
   373
deba@822
   374
  private:
deba@830
   375
deba@830
   376
    Map* map;
deba@830
   377
deba@830
   378
  public:
deba@830
   379
deba@830
   380
    /// Default constructor.
deba@830
   381
    MapValueIterator() {}
deba@830
   382
deba@830
   383
    /// Map and KeyIt initialized iterator.
deba@830
   384
    MapValueIterator(Map& pmap, const KeyIt& pit) 
deba@844
   385
      : Base(pit), map(&pmap) {}
deba@830
   386
    
deba@830
   387
deba@830
   388
    /// The pre increment operator of the iterator.
deba@830
   389
    MapValueIterator& operator++() {
deba@844
   390
      Base::increment(); 
deba@830
   391
      return *this; 
deba@830
   392
    }
deba@830
   393
deba@830
   394
    /// The post increment operator of the iterator.
deba@830
   395
    MapValueIterator operator++(int) {
deba@830
   396
      MapValueIterator tmp(*this);
deba@844
   397
      Base::increment();
deba@830
   398
      return tmp;
deba@830
   399
    }
deba@830
   400
deba@830
   401
    /// The dereferencing operator of the iterator.
alpar@987
   402
    Reference operator*() const {
deba@844
   403
      return (*map)[Base::it];
deba@830
   404
    }
deba@830
   405
deba@830
   406
    /// The arrow operator of the iterator.
alpar@987
   407
    Pointer operator->() const {
deba@830
   408
      return &(operator*());
deba@830
   409
    }
deba@830
   410
deba@844
   411
  public:
deba@844
   412
    // STL  compatibility typedefs.
deba@844
   413
    typedef std::forward_iterator_tag iterator_category;
deba@844
   414
    typedef int difference_type;
alpar@987
   415
    typedef Value value_type;
alpar@987
   416
    typedef Reference reference;
alpar@987
   417
    typedef Pointer pointer;
deba@830
   418
  };
deba@830
   419
deba@844
   420
  /** MapValueIterator creates an stl compatible iterator
deba@844
   421
   *  for the const values.
deba@844
   422
   */
deba@830
   423
deba@830
   424
  template <typename Map>
deba@830
   425
  class MapConstValueIterator : public MapIteratorBase<Map> {
deba@830
   426
deba@830
   427
  public:
deba@830
   428
deba@844
   429
    /// The iterator base class.
deba@844
   430
    typedef MapIteratorBase<Map> Base;
deba@844
   431
deba@830
   432
    /// The key type of the iterator.
alpar@987
   433
    typedef typename Map::Key Key;
deba@830
   434
    /// The iterator to iterate on the keys.
deba@830
   435
    typedef typename Map::KeyIt KeyIt;
deba@830
   436
deba@830
   437
    /// The value type of the iterator.
alpar@987
   438
    typedef typename Map::Value Value;
deba@830
   439
    /// The reference type of the iterator.
alpar@987
   440
    typedef typename Map::Reference Reference;
deba@830
   441
    /// The pointer type of the iterator.
alpar@987
   442
    typedef typename Map::Pointer Pointer;
deba@830
   443
deba@830
   444
    /// The const value type of the iterator.
alpar@987
   445
    typedef typename Map::ConstValue ConstValue;
deba@830
   446
    /// The const reference type of the iterator.
alpar@987
   447
    typedef typename Map::ConstReference ConstReference;
deba@830
   448
    /// The pointer type of the iterator.
alpar@987
   449
    typedef typename Map::ConstPointer ConstPointer;
deba@830
   450
deba@830
   451
  private:
deba@830
   452
deba@822
   453
    const Map* map;
deba@830
   454
deba@830
   455
  public:
deba@830
   456
deba@830
   457
    /// Default constructor.
deba@830
   458
    MapConstValueIterator() {}
deba@830
   459
deba@830
   460
    /// Constructor to create const iterator from a non const.
deba@830
   461
    MapConstValueIterator(const MapValueIterator<Map>& pit) {
deba@844
   462
      Base::it = pit.Base::it;
deba@830
   463
      map = pit.map;
deba@830
   464
    }
deba@830
   465
deba@830
   466
    /// Map and KeyIt initialized iterator.
deba@830
   467
    MapConstValueIterator(const Map& pmap, const KeyIt& pit) 
deba@844
   468
      : Base(pit), map(&pmap) {}
deba@830
   469
deba@830
   470
    /// The pre increment operator of the iterator.
deba@830
   471
    MapConstValueIterator& operator++() {
deba@844
   472
      Base::increment(); 
deba@830
   473
      return *this; 
deba@830
   474
    }
deba@830
   475
deba@830
   476
    /// The post increment operator of the iterator.
deba@830
   477
    MapConstValueIterator operator++(int) {
deba@830
   478
      MapConstValueIterator tmp(*this);
deba@844
   479
      Base::increment();
deba@830
   480
      return tmp;
deba@830
   481
    }
deba@830
   482
deba@830
   483
    /// The dereferencing operator of the iterator.
alpar@987
   484
    ConstReference operator*() const {
deba@844
   485
      return (*map)[Base::it];
deba@830
   486
    }
deba@830
   487
deba@830
   488
    /// The arrow operator of the iterator.
alpar@987
   489
    ConstPointer operator->() const {
deba@830
   490
      return &(operator*());
deba@830
   491
    }
deba@830
   492
deba@844
   493
  public:
deba@844
   494
    // STL  compatibility typedefs.
deba@844
   495
    typedef std::input_iterator_tag iterator_category;
deba@844
   496
    typedef int difference_type;
alpar@987
   497
    typedef Value value_type;
alpar@987
   498
    typedef ConstReference reference;
alpar@987
   499
    typedef ConstPointer pointer;
deba@822
   500
  };
deba@822
   501
deba@830
   502
deba@830
   503
  /** This class makes from a map an iteratable set
deba@830
   504
   *  which contains all the keys of the map.
deba@830
   505
   */
deba@830
   506
  template <typename Map>
deba@830
   507
  class MapConstKeySet {
deba@830
   508
deba@830
   509
    const Map* map;
deba@830
   510
deba@830
   511
  public:
deba@830
   512
deba@830
   513
    /// The key type of the iterator.
alpar@987
   514
    typedef typename Map::Key Key;
deba@830
   515
    /// The iterator to iterate on the keys.
deba@830
   516
    typedef typename Map::KeyIt KeyIt;
deba@830
   517
deba@844
   518
deba@844
   519
    /// The value type of the iterator.
alpar@987
   520
    typedef typename Map::Value Value;
deba@844
   521
    /// The reference type of the iterator.
alpar@987
   522
    typedef typename Map::Reference Reference;
deba@844
   523
    /// The pointer type of the iterator.
alpar@987
   524
    typedef typename Map::Pointer Pointer;
deba@844
   525
deba@844
   526
    /// The const value type of the iterator.
alpar@987
   527
    typedef typename Map::ConstValue ConstValue;
deba@844
   528
    /// The const reference type of the iterator.
alpar@987
   529
    typedef typename Map::ConstReference ConstReference;
deba@844
   530
    /// The pointer type of the iterator.
alpar@987
   531
    typedef typename Map::ConstPointer ConstPointer;
deba@844
   532
deba@830
   533
    /// The map initialized const key set.
deba@830
   534
    MapConstKeySet(const Map& pmap) : map(&pmap) {}
deba@830
   535
deba@830
   536
    /// The const iterator of the set.
deba@830
   537
    typedef MapKeyIterator<Map> ConstIterator;
deba@830
   538
deba@830
   539
    /// It gives back the const iterator pointed to the first element.
deba@830
   540
    ConstIterator begin() const {
deba@830
   541
      return ConstIterator(KeyIt(*map->getGraph()));
deba@830
   542
    }
deba@830
   543
            
deba@830
   544
    /// It gives back the const iterator pointed to the first ivalid element.
deba@830
   545
    ConstIterator end() const {
deba@830
   546
      return ConstIterator(KeyIt(INVALID));
deba@830
   547
    }
deba@844
   548
 
deba@844
   549
  public:
deba@844
   550
    // STL  compatibility typedefs.
alpar@987
   551
    typedef Value value_type;
deba@844
   552
    typedef ConstIterator const_iterator;
alpar@987
   553
    typedef ConstReference const_reference;
alpar@987
   554
    typedef ConstPointer const_pointer;
deba@844
   555
    typedef int difference_type;
deba@830
   556
  };
deba@830
   557
deba@830
   558
  /** This class makes from a map an iteratable set
deba@830
   559
   *  which contains all the values of the map.
deba@830
   560
   *  The values cannot be modified.
deba@830
   561
   */
deba@830
   562
  template <typename Map>
deba@830
   563
  class MapConstValueSet {
deba@830
   564
deba@830
   565
    const Map* map;
deba@830
   566
deba@830
   567
  public:
deba@830
   568
deba@830
   569
    /// The key type of the iterator.
alpar@987
   570
    typedef typename Map::Key Key;
deba@830
   571
    /// The iterator to iterate on the keys.
deba@830
   572
    typedef typename Map::KeyIt KeyIt;
deba@830
   573
deba@844
   574
deba@844
   575
    /// The value type of the iterator.
alpar@987
   576
    typedef typename Map::Value Value;
deba@844
   577
    /// The reference type of the iterator.
alpar@987
   578
    typedef typename Map::Reference Reference;
deba@844
   579
    /// The pointer type of the iterator.
alpar@987
   580
    typedef typename Map::Pointer Pointer;
deba@844
   581
deba@844
   582
    /// The const value type of the iterator.
alpar@987
   583
    typedef typename Map::ConstValue ConstValue;
deba@844
   584
    /// The const reference type of the iterator.
alpar@987
   585
    typedef typename Map::ConstReference ConstReference;
deba@844
   586
    /// The pointer type of the iterator.
alpar@987
   587
    typedef typename Map::ConstPointer ConstPointer;
deba@844
   588
deba@830
   589
    /// The map initialized const value set.
deba@830
   590
    MapConstValueSet(const Map& pmap) : map(&pmap) {}
deba@830
   591
deba@830
   592
    /// The const iterator of the set.
deba@830
   593
    typedef MapConstValueIterator<Map> ConstIterator;
deba@830
   594
deba@830
   595
    /// It gives back the const iterator pointed to the first element.
deba@830
   596
    ConstIterator begin() const {
deba@830
   597
      return ConstIterator(*map, KeyIt(*map->getGraph()));
deba@830
   598
    }
deba@830
   599
deba@830
   600
    /// It gives back the const iterator pointed to the first invalid element.
deba@830
   601
    ConstIterator end() const {
deba@830
   602
      return ConstIterator(*map, KeyIt(INVALID));
deba@830
   603
    }
deba@844
   604
deba@844
   605
  public:
deba@844
   606
    // STL  compatibility typedefs.
alpar@987
   607
    typedef Value value_type;
deba@844
   608
    typedef ConstIterator const_iterator;
alpar@987
   609
    typedef ConstReference const_reference;
alpar@987
   610
    typedef ConstPointer const_pointer;
deba@844
   611
    typedef int difference_type;
deba@830
   612
  };
deba@830
   613
deba@830
   614
deba@830
   615
  /** This class makes from a map an iteratable set
deba@830
   616
   *  which contains all the values of the map.
deba@830
   617
   *  The values can be modified.
deba@830
   618
   */
deba@830
   619
  template <typename Map>
deba@830
   620
  class MapValueSet {
deba@830
   621
deba@830
   622
    Map* map;
deba@830
   623
deba@830
   624
  public:
deba@830
   625
deba@830
   626
    /// The key type of the iterator.
alpar@987
   627
    typedef typename Map::Key Key;
deba@830
   628
    /// The iterator to iterate on the keys.
deba@830
   629
    typedef typename Map::KeyIt KeyIt;
deba@830
   630
deba@844
   631
deba@844
   632
    /// The value type of the iterator.
alpar@987
   633
    typedef typename Map::Value Value;
deba@844
   634
    /// The reference type of the iterator.
alpar@987
   635
    typedef typename Map::Reference Reference;
deba@844
   636
    /// The pointer type of the iterator.
alpar@987
   637
    typedef typename Map::Pointer Pointer;
deba@844
   638
deba@844
   639
    /// The const value type of the iterator.
alpar@987
   640
    typedef typename Map::ConstValue ConstValue;
deba@844
   641
    /// The const reference type of the iterator.
alpar@987
   642
    typedef typename Map::ConstReference ConstReference;
deba@844
   643
    /// The pointer type of the iterator.
alpar@987
   644
    typedef typename Map::ConstPointer ConstPointer;
deba@844
   645
deba@830
   646
    /// The map initialized value set.
deba@830
   647
    MapValueSet(Map& pmap) : map(&pmap) {}
deba@830
   648
deba@830
   649
    /// The const iterator of the set.
deba@830
   650
    typedef MapConstValueIterator<Map> ConstIterator;
deba@830
   651
deba@830
   652
    /// It gives back the const iterator pointed to the first element.
deba@830
   653
    ConstIterator begin() const {
deba@830
   654
      return ConstIterator(*map, KeyIt(*map->getGraph()));
deba@830
   655
    }
deba@830
   656
deba@830
   657
    /// It gives back the const iterator pointed to the first invalid element.
deba@830
   658
    ConstIterator end() const {
deba@830
   659
      return ConstIterator(*map, KeyIt(INVALID));
deba@830
   660
    }
deba@830
   661
deba@830
   662
    /// The iterator of the set.
deba@830
   663
    typedef MapValueIterator<Map> Iterator;
deba@830
   664
deba@830
   665
    /// It gives back the iterator pointed to the first element.
deba@830
   666
    Iterator begin() {
deba@830
   667
      return Iterator(*map, KeyIt(*map->getGraph()));
deba@830
   668
    }
deba@830
   669
deba@830
   670
    /// It gives back the iterator pointed to the first invalid element.
deba@830
   671
    Iterator end() {
deba@830
   672
      return Iterator(*map, KeyIt(INVALID));
deba@830
   673
    }
deba@830
   674
            
deba@844
   675
  public:
deba@844
   676
    // STL  compatibility typedefs.
alpar@987
   677
    typedef Value value_type;
deba@844
   678
    typedef Iterator iterator;
deba@844
   679
    typedef ConstIterator const_iterator;
alpar@987
   680
    typedef Reference reference;
alpar@987
   681
    typedef ConstReference const_reference;
alpar@987
   682
    typedef Pointer pointer;
alpar@987
   683
    typedef ConstPointer const_pointer;
deba@844
   684
    typedef int difference_type;
deba@844
   685
deba@830
   686
  };
deba@830
   687
deba@830
   688
  /// @}
deba@830
   689
deba@822
   690
}
deba@822
   691
deba@822
   692
#endif