lemon/bits/map_iterator.h
author deba
Mon, 17 Oct 2005 10:28:48 +0000
changeset 1729 06f939455cb1
parent 1587 8f1c317ebeb4
permissions -rw-r--r--
Removing signal/commit Change from alteration notifier

It makes slower the change Target/Source functions
and used only by the In/Out DegMap
alpar@906
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * lemon/map_iterator.h - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@1164
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     5
 * (Egervary Research Group on Combinatorial Optimization, 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
deba@1307
    22
#include <lemon/bits/extended_pair.h>
alpar@1402
    23
#include <lemon/graph_utils.h>
deba@822
    24
alpar@1587
    25
///\ingroup graphmapfactory
deba@830
    26
///\file
deba@830
    27
///\brief Iterators on the maps.
deba@830
    28
alpar@921
    29
namespace lemon {
deba@822
    30
alpar@1587
    31
  /// \addtogroup graphmapfactory
deba@830
    32
  /// @{
deba@830
    33
deba@830
    34
  /** The base class all of the map iterators.
deba@830
    35
   *  The class defines the typedefs of the iterators,
deba@830
    36
   *  simple step functions and equality operators.
deba@830
    37
   */ 
deba@822
    38
deba@1267
    39
  template <
deba@1267
    40
    typename _Graph,
deba@1267
    41
    typename _Item>
deba@830
    42
  class MapIteratorBase {
deba@822
    43
deba@830
    44
  protected:
deba@830
    45
deba@1267
    46
    /// The key type of the iterator.
deba@1267
    47
    typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
deba@1267
    48
deba@1267
    49
    ItemIt it;
deba@830
    50
deba@830
    51
    /// Default constructor.
deba@830
    52
    MapIteratorBase() {}
deba@830
    53
deba@1267
    54
    /// ItemIt initialized MapIteratorBase constructor.
deba@1267
    55
    MapIteratorBase(const ItemIt _it) : it(_it) {}
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@1267
    65
    bool operator==(const MapIteratorBase& _it) const {
deba@1267
    66
      return _it.it == it;
deba@830
    67
    }
deba@830
    68
	
deba@830
    69
    /// The not-equality operator of the map.
deba@1267
    70
    bool operator!=(const MapIteratorBase& _it) const {
deba@1267
    71
      return !(*this == _it);
deba@830
    72
    }
deba@830
    73
  };
deba@830
    74
deba@1267
    75
deba@1267
    76
  template <
deba@1267
    77
    typename _Graph,
deba@1267
    78
    typename _Item,
deba@1267
    79
    typename _Map>
deba@1267
    80
  class MapConstIterator;
deba@822
    81
deba@822
    82
  /** Compatible iterator with the stl maps' iterators.
deba@830
    83
   * It iterates on pairs of a key and a value.
deba@822
    84
   */
deba@1267
    85
  template <
deba@1267
    86
    typename _Graph,
deba@1267
    87
    typename _Item,
deba@1267
    88
    typename _Map>
deba@1267
    89
  class MapIterator : public MapIteratorBase<_Graph, _Item> {
deba@830
    90
deba@1267
    91
    friend class MapConstIterator<_Graph, _Item, _Map>;
deba@822
    92
deba@844
    93
deba@822
    94
  public:
deba@822
    95
deba@844
    96
    /// The iterator base class.
deba@1267
    97
    typedef MapIteratorBase<_Graph, _Item> Parent;
deba@844
    98
deba@1267
    99
    typedef _Item Item;
deba@1267
   100
    typedef _Map Map;
deba@1267
   101
    typedef _Graph Graph;
deba@822
   102
deba@1267
   103
  protected:
deba@822
   104
deba@1267
   105
    typedef typename Parent::ItemIt ItemIt;
deba@1267
   106
deba@1719
   107
    typedef typename _Map::Value MapValue;
deba@1719
   108
    typedef typename _Map::Reference MapReference;
deba@822
   109
    
deba@822
   110
  public:
deba@822
   111
deba@844
   112
    /// The value type of the iterator.
deba@1267
   113
    typedef extended_pair<Item, const Item&,
deba@1267
   114
      MapValue, const MapValue&> Value;
deba@844
   115
deba@830
   116
    /// The reference type of the iterator. 
deba@1267
   117
    typedef extended_pair<const Item&, const Item&, 
deba@1267
   118
      MapReference, MapReference> Reference;
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@1267
   125
    MapIterator(Map& _map, const ItemIt& _it) 
deba@1267
   126
      : Parent(_it), map(&_map) {}
deba@830
   127
deba@830
   128
    /// Dereference operator for the iterator.
deba@1267
   129
    Reference operator*() {
deba@1267
   130
      return Reference(Parent::it, (*map)[Parent::it]);
deba@822
   131
    }
deba@822
   132
deba@830
   133
    /// The pointer type of the iterator.
deba@1267
   134
    class Pointer {
deba@822
   135
      friend class MapIterator;
deba@1267
   136
    protected:
deba@1267
   137
      Reference data;
deba@1267
   138
      Pointer(const Item& item, MapReference val) 
deba@1267
   139
	: data(item, val) {}
deba@822
   140
    public:
deba@1267
   141
      Reference* operator->() {return &data;}
deba@822
   142
    };
deba@822
   143
deba@830
   144
    /// Arrow operator for the iterator.
deba@1267
   145
    Pointer operator->() {
deba@1267
   146
      return Pointer(Parent::it, (*map)[Parent::it]); 
deba@822
   147
    }
deba@830
   148
	
deba@830
   149
    /// The pre increment operator of the iterator.
deba@822
   150
    MapIterator& operator++() { 
deba@1267
   151
      Parent::increment(); 
deba@822
   152
      return *this; 
deba@822
   153
    }
deba@822
   154
deba@830
   155
    /// The post increment operator of the iterator.
deba@822
   156
    MapIterator operator++(int) { 
deba@844
   157
      MapIterator tmp(*this); 
deba@1267
   158
      Parent::increment(); 
deba@822
   159
      return tmp; 
deba@822
   160
    }
deba@822
   161
deba@1267
   162
  protected:
deba@1267
   163
deba@822
   164
    Map* map;
deba@844
   165
deba@844
   166
  public:
deba@844
   167
    // STL  compatibility typedefs.
deba@844
   168
    typedef std::forward_iterator_tag iterator_category;
deba@844
   169
    typedef int difference_type;
deba@1267
   170
    typedef Value value_type;
deba@1267
   171
    typedef Reference reference;
deba@1267
   172
    typedef Pointer pointer;
deba@822
   173
  };
deba@822
   174
deba@822
   175
  /** Compatible iterator with the stl maps' iterators.
deba@822
   176
   *  It iterates on pairs of a key and a value.
deba@822
   177
   */
deba@1267
   178
  template <
deba@1267
   179
    typename _Graph,
deba@1267
   180
    typename _Item,
deba@1267
   181
    typename _Map>
deba@1267
   182
  class MapConstIterator : public MapIteratorBase<_Graph, _Item> {
deba@1267
   183
deba@1267
   184
  public:
deba@1267
   185
deba@1267
   186
    /// The iterator base class.
deba@1267
   187
    typedef MapIteratorBase<_Graph, _Item> Parent;
deba@1267
   188
deba@1267
   189
    typedef _Graph Graph;
deba@1267
   190
    typedef _Item Item;
deba@1267
   191
    typedef _Map Map;
deba@1267
   192
deba@1267
   193
  protected:
deba@1267
   194
deba@1267
   195
    typedef typename Parent::ItemIt ItemIt;
deba@1267
   196
deba@1719
   197
    typedef typename _Map::Value MapValue;
deba@1719
   198
    typedef typename _Map::ConstReference MapReference;
deba@830
   199
    
deba@822
   200
  public:
deba@822
   201
deba@1267
   202
    /// The value type of the iterator.
deba@1267
   203
    typedef extended_pair<Item, const Item&,
deba@1267
   204
      MapValue, const MapValue&> Value;
deba@844
   205
deba@1267
   206
    /// The reference type of the iterator. 
deba@1267
   207
    typedef extended_pair<const Item&, const Item&, 
deba@1267
   208
      MapReference, MapReference> Reference;
deba@822
   209
deba@830
   210
    /// Default constructor. 
deba@822
   211
    MapConstIterator() {}
deba@822
   212
deba@1267
   213
    /// Constructor to initalize the iterators returned 
deba@1267
   214
    /// by the begin() and end().
deba@1267
   215
    MapConstIterator(const Map& _map, const ItemIt& _it) 
deba@1267
   216
      : Parent(_it), map(&_map) {}
deba@822
   217
deba@830
   218
    /// Dereference operator for the iterator.
deba@1267
   219
    Reference operator*() {
deba@1267
   220
      return Reference(Parent::it, (*map)[Parent::it]);
deba@822
   221
    }
deba@822
   222
deba@830
   223
    /// The pointer type of the iterator.
deba@1267
   224
    class Pointer {
deba@822
   225
      friend class MapConstIterator;
deba@1267
   226
    protected:
deba@1267
   227
      Reference data;
deba@1267
   228
      Pointer(const Item& item, MapReference val) 
deba@1267
   229
	: data(item, val) {}
deba@822
   230
    public:
deba@1267
   231
      Reference* operator->() {return &data;}
deba@822
   232
    };
deba@822
   233
deba@830
   234
    /// Arrow operator for the iterator.
deba@1267
   235
    Pointer operator->() {
deba@1267
   236
      return Pointer(Parent::it, ((*map)[Parent::it])); 
deba@822
   237
    }
deba@1267
   238
	
deba@830
   239
    /// The pre increment operator of the iterator.
deba@822
   240
    MapConstIterator& operator++() { 
deba@1267
   241
      Parent::increment(); 
deba@822
   242
      return *this; 
deba@822
   243
    }
deba@822
   244
deba@830
   245
    /// The post increment operator of the iterator.
deba@822
   246
    MapConstIterator operator++(int) { 
deba@844
   247
      MapConstIterator tmp(*this); 
deba@1267
   248
      Parent::increment(); 
deba@822
   249
      return tmp; 
deba@822
   250
    }
deba@822
   251
deba@1267
   252
  protected:
deba@830
   253
    const Map* map;
deba@844
   254
deba@844
   255
  public:
deba@844
   256
    // STL  compatibility typedefs.
deba@1267
   257
    typedef std::forward_iterator_tag iterator_category;
deba@844
   258
    typedef int difference_type;
deba@1267
   259
    typedef Value value_type;
deba@1267
   260
    typedef Reference reference;
deba@1267
   261
    typedef Pointer pointer;
deba@830
   262
  };
deba@1267
   263
 
deba@1267
   264
  /** The class makes the ItemIt to an stl compatible iterator
deba@830
   265
   *  with dereferencing operator.
deba@830
   266
   */
deba@1267
   267
  template <
deba@1267
   268
    typename _Graph,
deba@1267
   269
    typename _Item>
deba@1267
   270
  class MapConstKeyIterator : public MapIteratorBase<_Graph, _Item> {
deba@830
   271
deba@830
   272
  public:
deba@830
   273
deba@844
   274
    /// The iterator base class.
deba@1267
   275
    typedef MapIteratorBase<_Graph, _Item> Parent;
deba@844
   276
 
deba@1267
   277
    typedef _Graph Graph;
deba@1267
   278
    typedef _Item Item;
deba@1267
   279
deba@1267
   280
  protected:
deba@830
   281
    /// The iterator to iterate on the keys.
deba@1267
   282
    typedef typename Parent::ItemIt ItemIt;
deba@830
   283
deba@830
   284
  public:
deba@830
   285
deba@1267
   286
    typedef Item Value;
deba@1267
   287
    typedef const Item& Reference;
deba@1267
   288
    typedef const Item* Pointer;
deba@1267
   289
deba@830
   290
    /// Default constructor.
deba@1267
   291
    MapConstKeyIterator() {}
deba@830
   292
deba@1267
   293
    /// ItemIt initialized iterator.
deba@1267
   294
    MapConstKeyIterator(const ItemIt& pit) : Parent(pit) {}
deba@830
   295
deba@830
   296
    /// The pre increment operator of the iterator.
deba@1267
   297
    MapConstKeyIterator& operator++() {
deba@1267
   298
      Parent::increment(); 
deba@830
   299
      return *this; 
deba@822
   300
    }
deba@822
   301
deba@830
   302
    /// The post increment operator of the iterator.
deba@1267
   303
    MapConstKeyIterator operator++(int) {
deba@1267
   304
      MapConstKeyIterator tmp(*this);
deba@1267
   305
      Parent::increment();
deba@830
   306
      return tmp;
deba@822
   307
    }
deba@830
   308
deba@830
   309
    /// The dereferencing operator of the iterator.
deba@1267
   310
    Item operator*() const {
deba@1267
   311
      return static_cast<Item>(Parent::it);
deba@822
   312
    }
deba@844
   313
deba@844
   314
  public:
deba@844
   315
    // STL  compatibility typedefs.
deba@844
   316
    typedef std::input_iterator_tag iterator_category;
deba@844
   317
    typedef int difference_type;
deba@1267
   318
    typedef Value value_type;
deba@1267
   319
    typedef Reference reference;
deba@1267
   320
    typedef Pointer pointer;
deba@830
   321
  };
deba@830
   322
deba@1267
   323
  template <
deba@1267
   324
    typename _Graph, 
deba@1267
   325
    typename _Item,
deba@1267
   326
    typename _Map>
deba@1267
   327
  class MapConstValueIterator;
deba@830
   328
deba@844
   329
  /** MapValueIterator creates an stl compatible iterator
deba@844
   330
   *  for the values.
deba@844
   331
   */
deba@1267
   332
  template <
deba@1267
   333
    typename _Graph,
deba@1267
   334
    typename _Item,
deba@1267
   335
    typename _Map>
deba@1267
   336
  class MapValueIterator : public MapIteratorBase<_Graph, _Item> {
deba@830
   337
deba@1267
   338
    friend class MapConstValueIterator<_Graph, _Item, _Map>;
deba@830
   339
deba@830
   340
  public:
deba@830
   341
deba@844
   342
    /// The iterator base class.
deba@1267
   343
    typedef MapIteratorBase<_Graph, _Item> Parent;
deba@844
   344
deba@1267
   345
    typedef _Graph Graph;
deba@1267
   346
    typedef _Item Item;
deba@1267
   347
    typedef _Map Map;
deba@1267
   348
deba@1267
   349
  protected:
deba@1267
   350
deba@830
   351
    /// The iterator to iterate on the keys.
deba@1267
   352
    typedef typename Parent::ItemIt ItemIt;
deba@830
   353
deba@830
   354
    /// The value type of the iterator.
deba@1719
   355
    typedef typename Map::Value MapValue;
deba@830
   356
    /// The reference type of the iterator.
deba@1719
   357
    typedef typename Map::Reference MapReference;
deba@830
   358
    /// The pointer type of the iterator.
deba@1719
   359
    typedef typename Map::Pointer MapPointer;
deba@830
   360
deba@830
   361
  public:
deba@830
   362
deba@1267
   363
    typedef MapValue Value;
deba@1267
   364
    typedef MapReference Reference;
deba@1267
   365
    typedef MapPointer Pointer;
deba@1267
   366
deba@830
   367
    /// Default constructor.
deba@830
   368
    MapValueIterator() {}
deba@830
   369
deba@1267
   370
    /// Map and ItemIt initialized iterator.
deba@1267
   371
    MapValueIterator(Map& _map, const ItemIt& _it) 
deba@1267
   372
      : Parent(_it), map(&_map) {}
deba@830
   373
    
deba@830
   374
deba@830
   375
    /// The pre increment operator of the iterator.
deba@830
   376
    MapValueIterator& operator++() {
deba@1267
   377
      Parent::increment(); 
deba@830
   378
      return *this; 
deba@830
   379
    }
deba@830
   380
deba@830
   381
    /// The post increment operator of the iterator.
deba@830
   382
    MapValueIterator operator++(int) {
deba@830
   383
      MapValueIterator tmp(*this);
deba@1267
   384
      Parent::increment();
deba@830
   385
      return tmp;
deba@830
   386
    }
deba@830
   387
deba@830
   388
    /// The dereferencing operator of the iterator.
alpar@987
   389
    Reference operator*() const {
deba@1267
   390
      return (*map)[Parent::it];
deba@830
   391
    }
deba@830
   392
deba@830
   393
    /// The arrow operator of the iterator.
alpar@987
   394
    Pointer operator->() const {
deba@830
   395
      return &(operator*());
deba@830
   396
    }
deba@830
   397
deba@1267
   398
  protected:
deba@1267
   399
deba@1267
   400
    Map* map;
deba@1267
   401
deba@844
   402
  public:
deba@844
   403
    // STL  compatibility typedefs.
deba@844
   404
    typedef std::forward_iterator_tag iterator_category;
deba@844
   405
    typedef int difference_type;
alpar@987
   406
    typedef Value value_type;
alpar@987
   407
    typedef Reference reference;
alpar@987
   408
    typedef Pointer pointer;
deba@830
   409
  };
deba@830
   410
deba@844
   411
  /** MapValueIterator creates an stl compatible iterator
deba@1267
   412
   *  for the values.
deba@844
   413
   */
deba@1267
   414
  template <
deba@1267
   415
    typename _Graph,
deba@1267
   416
    typename _Item,
deba@1267
   417
    typename _Map>
deba@1267
   418
  class MapConstValueIterator : public MapIteratorBase<_Graph, _Item> {
deba@830
   419
deba@830
   420
  public:
deba@830
   421
deba@844
   422
    /// The iterator base class.
deba@1267
   423
    typedef MapIteratorBase<_Graph, _Item> Parent;
deba@844
   424
deba@1267
   425
    typedef _Graph Graph;
deba@1267
   426
    typedef _Item Item;
deba@1267
   427
    typedef _Map Map;
deba@1267
   428
deba@1267
   429
  protected:
deba@1267
   430
deba@830
   431
    /// The iterator to iterate on the keys.
deba@1267
   432
    typedef typename Parent::ItemIt ItemIt;
deba@830
   433
deba@830
   434
    /// The value type of the iterator.
deba@1719
   435
    typedef typename Map::Value MapValue;
deba@830
   436
    /// The reference type of the iterator.
deba@1719
   437
    typedef typename Map::ConstReference MapReference;
deba@830
   438
    /// The pointer type of the iterator.
deba@1719
   439
    typedef typename Map::ConstPointer MapPointer;
deba@830
   440
deba@830
   441
  public:
deba@830
   442
deba@1267
   443
    typedef MapValue Value;
deba@1267
   444
    typedef MapReference Reference;
deba@1267
   445
    typedef MapPointer Pointer;
deba@1267
   446
deba@830
   447
    /// Default constructor.
deba@830
   448
    MapConstValueIterator() {}
deba@830
   449
deba@1267
   450
    /// Map and ItemIt initialized iterator.
deba@1267
   451
    MapConstValueIterator(const Map& _map, const ItemIt& _it) 
deba@1267
   452
      : Parent(_it), map(&_map) {}
deba@1267
   453
    
deba@830
   454
deba@830
   455
    /// The pre increment operator of the iterator.
deba@830
   456
    MapConstValueIterator& operator++() {
deba@1267
   457
      Parent::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@1267
   464
      Parent::increment();
deba@830
   465
      return tmp;
deba@830
   466
    }
deba@830
   467
deba@830
   468
    /// The dereferencing operator of the iterator.
deba@1267
   469
    Reference operator*() const {
deba@1267
   470
      return (*map)[Parent::it];
deba@830
   471
    }
deba@830
   472
deba@830
   473
    /// The arrow operator of the iterator.
deba@1267
   474
    Pointer operator->() const {
deba@830
   475
      return &(operator*());
deba@830
   476
    }
deba@830
   477
deba@1267
   478
  protected:
deba@1267
   479
deba@1267
   480
    const Map* map;
deba@1267
   481
deba@844
   482
  public:
deba@844
   483
    // STL  compatibility typedefs.
deba@1267
   484
    typedef std::forward_iterator_tag iterator_category;
deba@844
   485
    typedef int difference_type;
alpar@987
   486
    typedef Value value_type;
deba@1267
   487
    typedef Reference reference;
deba@1267
   488
    typedef Pointer pointer;
deba@822
   489
  };
deba@822
   490
deba@830
   491
deba@830
   492
  /** This class makes from a map an iteratable set
deba@830
   493
   *  which contains all the keys of the map.
deba@830
   494
   */
deba@1267
   495
  template <typename _Graph, typename _Item>
deba@830
   496
  class MapConstKeySet {
deba@830
   497
deba@830
   498
  public:
deba@830
   499
deba@1267
   500
    typedef _Graph Graph;
deba@830
   501
    /// The key type of the iterator.
deba@1267
   502
    typedef _Item Item;
deba@830
   503
    /// The iterator to iterate on the keys.
deba@830
   504
deba@1267
   505
  protected:
deba@844
   506
deba@1267
   507
    typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
deba@844
   508
deba@1267
   509
  public:
deba@844
   510
deba@830
   511
    /// The map initialized const key set.
deba@1267
   512
    MapConstKeySet(const Graph& _graph) : graph(&_graph) {}
deba@830
   513
deba@830
   514
    /// The const iterator of the set.
deba@1267
   515
    typedef MapConstKeyIterator<_Graph, _Item> ConstIterator;
deba@1267
   516
deba@1267
   517
    typedef typename ConstIterator::Value Value;
deba@1267
   518
    /// The reference type of the iterator.
deba@1267
   519
    typedef typename ConstIterator::Reference ConstReference;
deba@1267
   520
    /// The pointer type of the iterator.
deba@1267
   521
    typedef typename ConstIterator::Pointer ConstPointer;
deba@830
   522
deba@830
   523
    /// It gives back the const iterator pointed to the first element.
deba@830
   524
    ConstIterator begin() const {
deba@1267
   525
      return ConstIterator(ItemIt(*graph));
deba@830
   526
    }
deba@830
   527
            
deba@830
   528
    /// It gives back the const iterator pointed to the first ivalid element.
deba@830
   529
    ConstIterator end() const {
deba@1267
   530
      return ConstIterator(ItemIt(INVALID));
deba@830
   531
    }
deba@1267
   532
deba@1267
   533
  protected:
deba@1267
   534
deba@1267
   535
    const Graph* graph;
deba@844
   536
 
deba@844
   537
  public:
deba@844
   538
    // STL  compatibility typedefs.
alpar@987
   539
    typedef Value value_type;
deba@844
   540
    typedef ConstIterator const_iterator;
alpar@987
   541
    typedef ConstReference const_reference;
alpar@987
   542
    typedef ConstPointer const_pointer;
deba@844
   543
    typedef int difference_type;
deba@830
   544
  };
deba@830
   545
deba@830
   546
  /** This class makes from a map an iteratable set
deba@830
   547
   *  which contains all the values of the map.
deba@830
   548
   *  The values cannot be modified.
deba@830
   549
   */
deba@1267
   550
  template <typename _Graph, typename _Item, typename _Map>
deba@830
   551
  class MapConstValueSet {
deba@830
   552
deba@1267
   553
  public:
deba@1267
   554
    
deba@1267
   555
    typedef _Graph Graph;
deba@1267
   556
    typedef _Item Item;
deba@1267
   557
    typedef _Map Map;
deba@1267
   558
deba@1267
   559
  protected:
deba@1267
   560
deba@1267
   561
    /// The iterator to iterate on the keys.
deba@1267
   562
    typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
deba@830
   563
deba@830
   564
  public:
deba@830
   565
deba@830
   566
    /// The map initialized const value set.
deba@1267
   567
    MapConstValueSet(const Graph& _graph, const Map& _map) 
deba@1267
   568
      : graph(&_graph), map(&_map) {}
deba@830
   569
deba@830
   570
    /// The const iterator of the set.
deba@1267
   571
    typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
deba@1267
   572
deba@1267
   573
    typedef typename ConstIterator::Value Value;
deba@1267
   574
    typedef typename ConstIterator::Reference ConstReference;
deba@1267
   575
    typedef typename ConstIterator::Pointer ConstPointer;
deba@830
   576
deba@830
   577
    /// It gives back the const iterator pointed to the first element.
deba@830
   578
    ConstIterator begin() const {
deba@1267
   579
      return ConstIterator(*map, ItemIt(*graph));
deba@830
   580
    }
deba@830
   581
deba@830
   582
    /// It gives back the const iterator pointed to the first invalid element.
deba@830
   583
    ConstIterator end() const {
deba@1267
   584
      return ConstIterator(*map, ItemIt(INVALID));
deba@830
   585
    }
deba@844
   586
deba@1267
   587
  protected:
deba@1267
   588
    
deba@1267
   589
    const Map* map;
deba@1267
   590
    const Graph * graph;
deba@1267
   591
deba@844
   592
  public:
deba@844
   593
    // STL  compatibility typedefs.
alpar@987
   594
    typedef Value value_type;
deba@844
   595
    typedef ConstIterator const_iterator;
alpar@987
   596
    typedef ConstReference const_reference;
alpar@987
   597
    typedef ConstPointer const_pointer;
deba@844
   598
    typedef int difference_type;
deba@830
   599
  };
deba@830
   600
deba@830
   601
deba@830
   602
  /** This class makes from a map an iteratable set
deba@830
   603
   *  which contains all the values of the map.
deba@830
   604
   *  The values can be modified.
deba@830
   605
   */
deba@1267
   606
  template <typename _Graph, typename _Item, typename _Map>
deba@830
   607
  class MapValueSet {
deba@830
   608
deba@1267
   609
  public:
deba@1267
   610
    
deba@1267
   611
    typedef _Graph Graph;
deba@1267
   612
    typedef _Item Item;
deba@1267
   613
    typedef _Map Map;
deba@1267
   614
deba@1267
   615
  protected:
deba@1267
   616
deba@1267
   617
    /// The iterator to iterate on the keys.
deba@1267
   618
    typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
deba@830
   619
deba@830
   620
  public:
deba@830
   621
deba@1267
   622
    /// The map initialized const value set.
deba@1267
   623
    MapValueSet(const Graph& _graph, Map& _map) 
deba@1271
   624
      : map(&_map), graph(&_graph) {}
deba@830
   625
deba@830
   626
    /// The const iterator of the set.
deba@1267
   627
    typedef MapValueIterator<_Graph, _Item, _Map> Iterator;
deba@1267
   628
    /// The const iterator of the set.
deba@1267
   629
    typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
deba@1267
   630
deba@1267
   631
    typedef typename ConstIterator::Value Value;
deba@1267
   632
    typedef typename Iterator::Reference Reference;
deba@1267
   633
    typedef typename Iterator::Pointer Pointer;
deba@1267
   634
    typedef typename ConstIterator::Reference ConstReference;
deba@1267
   635
    typedef typename ConstIterator::Pointer ConstPointer;
deba@830
   636
deba@830
   637
    /// It gives back the const iterator pointed to the first element.
deba@830
   638
    ConstIterator begin() const {
deba@1267
   639
      return ConstIterator(*map, ItemIt(*graph));
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@1267
   644
      return ConstIterator(*map, ItemIt(INVALID));
deba@830
   645
    }
deba@830
   646
deba@830
   647
    /// It gives back the iterator pointed to the first element.
deba@830
   648
    Iterator begin() {
deba@1267
   649
      return Iterator(*map, ItemIt(*graph));
deba@830
   650
    }
deba@830
   651
deba@830
   652
    /// It gives back the iterator pointed to the first invalid element.
deba@830
   653
    Iterator end() {
deba@1267
   654
      return Iterator(*map, ItemIt(INVALID));
deba@830
   655
    }
deba@1267
   656
deba@1267
   657
  protected:
deba@1267
   658
    
deba@1267
   659
    Map* map;
deba@1267
   660
    const Graph * graph;
deba@1267
   661
deba@1267
   662
  public:
deba@1267
   663
    // STL  compatibility typedefs.
deba@1267
   664
    typedef Value value_type;
deba@1267
   665
    typedef Iterator iterator;
deba@1267
   666
    typedef ConstIterator const_iterator;
deba@1267
   667
    typedef Reference reference;
deba@1267
   668
    typedef ConstReference const_reference;
deba@1267
   669
    typedef Pointer pointer;
deba@1267
   670
    typedef ConstPointer const_pointer;
deba@1267
   671
    typedef int difference_type;
deba@1267
   672
deba@1267
   673
  };
deba@1267
   674
deba@1267
   675
  /** This class makes from a map an iteratable set
deba@1267
   676
   *  which contains all the values of the map.
deba@1267
   677
   *  The values can be modified.
deba@1267
   678
   */
deba@1267
   679
  template <
deba@1267
   680
    typename _Graph, 
deba@1267
   681
    typename _Item,
deba@1267
   682
    typename _Map
deba@1267
   683
    >
deba@1267
   684
  class MapSet {
deba@1267
   685
  public:    
deba@1267
   686
deba@1267
   687
    typedef _Graph Graph;
deba@1267
   688
    typedef _Item Item;
deba@1267
   689
    typedef _Map Map;
deba@1267
   690
deba@1267
   691
  protected:
deba@1267
   692
deba@1267
   693
    typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
deba@1267
   694
deba@1267
   695
  public:
deba@1267
   696
deba@1267
   697
    /// The map initialized value set.
deba@1267
   698
    MapSet(const Graph& _graph, Map& _map) : graph(&_graph), map(&_map) {}
deba@1267
   699
deba@1267
   700
    /// The const iterator of the set.
deba@1267
   701
    typedef MapIterator<_Graph, _Item, _Map> Iterator;
deba@1267
   702
    typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
deba@1267
   703
deba@1267
   704
    typedef typename ConstIterator::Value Value;
deba@1267
   705
    typedef typename Iterator::Reference Reference;
deba@1267
   706
    typedef typename Iterator::Pointer Pointer;
deba@1267
   707
    typedef typename ConstIterator::Reference ConstReference;
deba@1267
   708
    typedef typename ConstIterator::Pointer ConstPointer;
deba@1267
   709
deba@1267
   710
deba@1267
   711
    /// It gives back the const iterator pointed to the first element.
deba@1267
   712
    ConstIterator begin() const {
deba@1267
   713
      return ConstIterator(*map, ItemIt(*graph));
deba@1267
   714
    }
deba@1267
   715
deba@1267
   716
    /// It gives back the const iterator pointed to the first invalid element.
deba@1267
   717
    ConstIterator end() const {
deba@1267
   718
      return ConstIterator(*map, ItemIt(INVALID));
deba@1267
   719
    }
deba@1267
   720
deba@1267
   721
    /// The iterator of the set.
deba@1267
   722
deba@1267
   723
    /// It gives back the iterator pointed to the first element.
deba@1267
   724
    Iterator begin() {
deba@1267
   725
      return Iterator(*map, ItemIt(*graph));
deba@1267
   726
    }
deba@1267
   727
deba@1267
   728
    /// It gives back the iterator pointed to the first invalid element.
deba@1267
   729
    Iterator end() {
deba@1267
   730
      return Iterator(*map, ItemIt(INVALID));
deba@1267
   731
    }
deba@1267
   732
deba@1267
   733
  protected:
deba@1267
   734
    
deba@1267
   735
    const Graph* graph;
deba@1267
   736
    Map* map;
deba@830
   737
            
deba@844
   738
  public:
deba@844
   739
    // STL  compatibility typedefs.
alpar@987
   740
    typedef Value value_type;
deba@844
   741
    typedef Iterator iterator;
deba@844
   742
    typedef ConstIterator const_iterator;
alpar@987
   743
    typedef Reference reference;
alpar@987
   744
    typedef ConstReference const_reference;
alpar@987
   745
    typedef Pointer pointer;
alpar@987
   746
    typedef ConstPointer const_pointer;
deba@844
   747
    typedef int difference_type;
deba@844
   748
deba@830
   749
  };
deba@830
   750
deba@1267
   751
  template <
deba@1267
   752
    typename _Graph, 
deba@1267
   753
    typename _Item,
deba@1267
   754
    typename _Map
deba@1267
   755
    >
deba@1267
   756
  class ConstMapSet {
deba@1267
   757
    
deba@1267
   758
    typedef _Graph Graph;
deba@1267
   759
    typedef _Map Map;
deba@1267
   760
deba@1267
   761
    const Graph* graph;
deba@1267
   762
    const Map* map;
deba@1267
   763
deba@1267
   764
  public:
deba@1267
   765
deba@1267
   766
    typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
deba@1267
   767
deba@1267
   768
deba@1267
   769
    /// The map initialized value set.
deba@1267
   770
    ConstMapSet(const Graph& _graph, const Map& _map) 
deba@1267
   771
      : graph(&_graph), map(&_map) {}
deba@1267
   772
deba@1267
   773
    /// The const iterator of the set.
deba@1267
   774
    typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
deba@1267
   775
deba@1267
   776
    typedef typename ConstIterator::Value Value;
deba@1267
   777
    typedef typename ConstIterator::Reference ConstReference;
deba@1267
   778
    typedef typename ConstIterator::Pointer ConstPointer;
deba@1267
   779
deba@1267
   780
deba@1267
   781
    /// It gives back the const iterator pointed to the first element.
deba@1267
   782
    ConstIterator begin() const {
deba@1267
   783
      return ConstIterator(*map, ItemIt(*graph));
deba@1267
   784
    }
deba@1267
   785
deba@1267
   786
    /// It gives back the const iterator pointed to the first invalid element.
deba@1267
   787
    ConstIterator end() const {
deba@1267
   788
      return ConstIterator(*map, ItemIt(INVALID));
deba@1267
   789
    }
deba@1267
   790
            
deba@1267
   791
  public:
deba@1267
   792
    // STL  compatibility typedefs.
deba@1267
   793
    typedef Value value_type;
deba@1267
   794
    typedef ConstIterator const_iterator;
deba@1267
   795
    typedef ConstReference const_reference;
deba@1267
   796
    typedef ConstPointer const_pointer;
deba@1267
   797
    typedef int difference_type;
deba@1267
   798
deba@1267
   799
  };
deba@1267
   800
deba@1267
   801
  template <typename _Map>
deba@1267
   802
  class IterableMapExtender : public _Map {
deba@1267
   803
  public:
deba@1267
   804
deba@1267
   805
    typedef _Map Parent;
deba@1267
   806
    typedef Parent Map;
deba@1267
   807
    typedef typename Map::Graph Graph;
deba@1267
   808
    typedef typename Map::Key Item;
deba@1267
   809
    typedef typename Map::Value Value;
deba@1267
   810
deba@1267
   811
    typedef MapSet<Graph, Item, Map> MapSet;
deba@1267
   812
deba@1267
   813
    IterableMapExtender() : Parent() {}
deba@1267
   814
deba@1267
   815
    IterableMapExtender(const Graph& graph) : Parent(graph) {}
deba@1267
   816
deba@1267
   817
    IterableMapExtender(const Graph& graph, const Value& value) 
deba@1267
   818
      : Parent(graph, value) {}
deba@1267
   819
deba@1267
   820
    MapSet mapSet() { 
deba@1267
   821
      return MapSet(*Parent::getGraph(), *this); 
deba@1267
   822
    }
deba@1267
   823
deba@1267
   824
    typedef ConstMapSet<Graph, Item, Map> ConstMapSet;
deba@1267
   825
deba@1267
   826
    ConstMapSet mapSet() const { 
deba@1267
   827
      return ConstMapSet(*Parent::getGraph(), *this); 
deba@1267
   828
    }
deba@1267
   829
deba@1267
   830
    typedef MapConstKeySet<Graph, Item> ConstKeySet;
deba@1267
   831
 
deba@1267
   832
    ConstKeySet keySet() const {
deba@1267
   833
      return ConstKeySet(*Parent::getGraph());
deba@1267
   834
    }
deba@1267
   835
deba@1267
   836
    typedef MapValueSet<Graph, Item, Map> ValueSet;
deba@1267
   837
 
deba@1267
   838
    ValueSet valueSet() {
deba@1267
   839
      return ValueSet(*Parent::getGraph(), *this);
deba@1267
   840
    }
deba@1267
   841
deba@1267
   842
    typedef MapConstValueSet<Graph, Item, Map> ConstValueSet;
deba@1267
   843
 
deba@1267
   844
    ConstValueSet valueSet() const {
deba@1267
   845
      return ConstValueSet(*Parent::getGraph(), *this);
deba@1267
   846
    }
deba@1267
   847
deba@1267
   848
  };
deba@1267
   849
deba@830
   850
  /// @}
deba@830
   851
deba@822
   852
}
deba@822
   853
deba@822
   854
#endif