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