1.1 --- a/src/hugo/map_iterator.h Mon Sep 13 18:00:26 2004 +0000
1.2 +++ b/src/hugo/map_iterator.h Mon Sep 13 20:05:13 2004 +0000
1.3 @@ -2,6 +2,8 @@
1.4 #ifndef MAP_ITERATOR_H
1.5 #define MAP_ITERATOR_H
1.6
1.7 +#include <iterator>
1.8 +
1.9 #include <hugo/extended_pair.h>
1.10
1.11 ///\ingroup graphmaps
1.12 @@ -22,6 +24,7 @@
1.13 class MapIteratorBase {
1.14
1.15 public:
1.16 +
1.17 /// The key type of the iterator.
1.18 typedef typename Map::KeyType KeyType;
1.19 /// The iterator to iterate on the keys.
1.20 @@ -79,8 +82,12 @@
1.21
1.22 friend class MapConstIterator<Map>;
1.23
1.24 +
1.25 public:
1.26
1.27 + /// The iterator base class.
1.28 + typedef MapIteratorBase<Map> Base;
1.29 +
1.30 /// The key type of the iterator.
1.31 typedef typename Map::KeyType KeyType;
1.32 /// The iterator to iterate on the keys.
1.33 @@ -102,6 +109,10 @@
1.34
1.35 public:
1.36
1.37 + /// The value type of the iterator.
1.38 + typedef extended_pair<KeyType, const KeyType&,
1.39 + ValueType, const ValueType&> PairValueType;
1.40 +
1.41 /// The reference type of the iterator.
1.42 typedef extended_pair<const KeyType&, const KeyType&,
1.43 ReferenceType, ReferenceType> PairReferenceType;
1.44 @@ -111,12 +122,11 @@
1.45
1.46 /// Constructor to initalize the iterators returned
1.47 /// by the begin() and end().
1.48 - MapIterator(Map& pmap, const KeyIt& pit)
1.49 - : MapIteratorBase<Map>(pit), map(&pmap) {}
1.50 + MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {}
1.51
1.52 /// Dereference operator for the iterator.
1.53 PairReferenceType operator*() {
1.54 - return PairReferenceType(it, (*map)[it]);
1.55 + return PairReferenceType(Base::it, (*map)[Base::it]);
1.56 }
1.57
1.58 /// The pointer type of the iterator.
1.59 @@ -132,24 +142,32 @@
1.60
1.61 /// Arrow operator for the iterator.
1.62 PairPointerType operator->() {
1.63 - return PairPointerType(it, ((*map)[it]));
1.64 + return PairPointerType(Base::it, ((*map)[Base::it]));
1.65 }
1.66
1.67 /// The pre increment operator of the iterator.
1.68 MapIterator& operator++() {
1.69 - increment();
1.70 + Base::increment();
1.71 return *this;
1.72 }
1.73
1.74 /// The post increment operator of the iterator.
1.75 MapIterator operator++(int) {
1.76 - MapIterator tmp(it);
1.77 - increment();
1.78 + MapIterator tmp(*this);
1.79 + Base::increment();
1.80 return tmp;
1.81 }
1.82
1.83 private:
1.84 Map* map;
1.85 +
1.86 + public:
1.87 + // STL compatibility typedefs.
1.88 + typedef std::forward_iterator_tag iterator_category;
1.89 + typedef int difference_type;
1.90 + typedef PairValueType value_type;
1.91 + typedef PairReferenceType reference;
1.92 + typedef PairPointerType pointer;
1.93 };
1.94
1.95 /** Compatible iterator with the stl maps' iterators.
1.96 @@ -160,6 +178,9 @@
1.97
1.98 public:
1.99
1.100 + /// The iterator base class.
1.101 + typedef MapIteratorBase<Map> Base;
1.102 +
1.103 /// The key type of the iterator.
1.104 typedef typename Map::KeyType KeyType;
1.105 /// The iterator to iterate on the keys.
1.106 @@ -187,21 +208,25 @@
1.107 /// Constructor to initalize the the iterators returned
1.108 /// by the begin() and end().
1.109 MapConstIterator(const Map& pmap, const KeyIt& pit)
1.110 - : MapIteratorBase<Map>(pit), map(&pmap) {}
1.111 + : Base(pit), map(&pmap) {}
1.112
1.113 /// Constructor to create const iterator from a non const.
1.114 MapConstIterator(const MapIterator<Map>& pit) {
1.115 - it = pit.it;
1.116 + Base::it = pit.Base::it;
1.117 map = pit.map;
1.118 }
1.119
1.120 + /// The value type of the iterator.
1.121 + typedef extended_pair<KeyType, const KeyType&,
1.122 + ValueType, const ValueType&> PairValueType;
1.123 +
1.124 /// The reference type of map.
1.125 typedef extended_pair<const KeyType&, const KeyType&,
1.126 ConstReferenceType, ConstReferenceType> PairReferenceType;
1.127
1.128 /// Dereference operator for the iterator.
1.129 PairReferenceType operator*() {
1.130 - return PairReferenceType(it, (*map)[it]);
1.131 + return PairReferenceType(Base::it, (*map)[Base::it]);
1.132 }
1.133
1.134 /// The pointer type of the iterator.
1.135 @@ -217,24 +242,32 @@
1.136
1.137 /// Arrow operator for the iterator.
1.138 PairPointerType operator->() {
1.139 - return PairPointerType(it, ((*map)[it]));
1.140 + return PairPointerType(Base::it, (*map)[Base::it]);
1.141 }
1.142
1.143 /// The pre increment operator of the iterator.
1.144 MapConstIterator& operator++() {
1.145 - increment();
1.146 + Base::increment();
1.147 return *this;
1.148 }
1.149
1.150 /// The post increment operator of the iterator.
1.151 MapConstIterator operator++(int) {
1.152 - MapConstIterator<Map> tmp(it);
1.153 - increment();
1.154 + MapConstIterator tmp(*this);
1.155 + Base::increment();
1.156 return tmp;
1.157 }
1.158
1.159 private:
1.160 const Map* map;
1.161 +
1.162 + public:
1.163 + // STL compatibility typedefs.
1.164 + typedef std::input_iterator_tag iterator_category;
1.165 + typedef int difference_type;
1.166 + typedef PairValueType value_type;
1.167 + typedef PairReferenceType reference;
1.168 + typedef PairPointerType pointer;
1.169 };
1.170
1.171 /** The class makes the KeyIt to an stl compatible iterator
1.172 @@ -245,6 +278,9 @@
1.173
1.174 public:
1.175
1.176 + /// The iterator base class.
1.177 + typedef MapIteratorBase<Map> Base;
1.178 +
1.179 /// The key type of the iterator.
1.180 typedef typename Map::KeyType KeyType;
1.181 /// The iterator to iterate on the keys.
1.182 @@ -256,29 +292,40 @@
1.183 MapKeyIterator() {}
1.184
1.185 /// KeyIt initialized iterator.
1.186 - MapKeyIterator(const KeyIt& pit) : MapIteratorBase<Map>(pit) {}
1.187 + MapKeyIterator(const KeyIt& pit) : Base(pit) {}
1.188
1.189 /// The pre increment operator of the iterator.
1.190 MapKeyIterator& operator++() {
1.191 - increment();
1.192 + Base::increment();
1.193 return *this;
1.194 }
1.195
1.196 /// The post increment operator of the iterator.
1.197 MapKeyIterator operator++(int) {
1.198 MapKeyIterator tmp(*this);
1.199 - increment();
1.200 + Base::increment();
1.201 return tmp;
1.202 }
1.203
1.204 /// The dereferencing operator of the iterator.
1.205 KeyType operator*() const {
1.206 - return static_cast<KeyType>(it);
1.207 + return static_cast<KeyType>(Base::it);
1.208 }
1.209 +
1.210 + public:
1.211 + // STL compatibility typedefs.
1.212 + typedef std::input_iterator_tag iterator_category;
1.213 + typedef int difference_type;
1.214 + typedef KeyType value_type;
1.215 + typedef const KeyType& reference;
1.216 + typedef const KeyType* pointer;
1.217 };
1.218
1.219 template <typename Map> class MapConstValueIterator;
1.220
1.221 + /** MapValueIterator creates an stl compatible iterator
1.222 + * for the values.
1.223 + */
1.224 template <typename Map>
1.225 class MapValueIterator : public MapIteratorBase<Map> {
1.226
1.227 @@ -286,6 +333,9 @@
1.228
1.229 public:
1.230
1.231 + /// The iterator base class.
1.232 + typedef MapIteratorBase<Map> Base;
1.233 +
1.234 /// The key type of the iterator.
1.235 typedef typename Map::KeyType KeyType;
1.236 /// The iterator to iterate on the keys.
1.237 @@ -317,25 +367,25 @@
1.238
1.239 /// Map and KeyIt initialized iterator.
1.240 MapValueIterator(Map& pmap, const KeyIt& pit)
1.241 - : MapIteratorBase<Map>(pit), map(&pmap) {}
1.242 + : Base(pit), map(&pmap) {}
1.243
1.244
1.245 /// The pre increment operator of the iterator.
1.246 MapValueIterator& operator++() {
1.247 - increment();
1.248 + Base::increment();
1.249 return *this;
1.250 }
1.251
1.252 /// The post increment operator of the iterator.
1.253 MapValueIterator operator++(int) {
1.254 MapValueIterator tmp(*this);
1.255 - increment();
1.256 + Base::increment();
1.257 return tmp;
1.258 }
1.259
1.260 /// The dereferencing operator of the iterator.
1.261 ReferenceType operator*() const {
1.262 - return (*map)[it];
1.263 + return (*map)[Base::it];
1.264 }
1.265
1.266 /// The arrow operator of the iterator.
1.267 @@ -343,20 +393,32 @@
1.268 return &(operator*());
1.269 }
1.270
1.271 + public:
1.272 + // STL compatibility typedefs.
1.273 + typedef std::forward_iterator_tag iterator_category;
1.274 + typedef int difference_type;
1.275 + typedef ValueType value_type;
1.276 + typedef ReferenceType reference;
1.277 + typedef PointerType pointer;
1.278 };
1.279
1.280 + /** MapValueIterator creates an stl compatible iterator
1.281 + * for the const values.
1.282 + */
1.283
1.284 template <typename Map>
1.285 class MapConstValueIterator : public MapIteratorBase<Map> {
1.286
1.287 public:
1.288
1.289 + /// The iterator base class.
1.290 + typedef MapIteratorBase<Map> Base;
1.291 +
1.292 /// The key type of the iterator.
1.293 typedef typename Map::KeyType KeyType;
1.294 /// The iterator to iterate on the keys.
1.295 typedef typename Map::KeyIt KeyIt;
1.296
1.297 -
1.298 /// The value type of the iterator.
1.299 typedef typename Map::ValueType ValueType;
1.300 /// The reference type of the iterator.
1.301 @@ -382,30 +444,30 @@
1.302
1.303 /// Constructor to create const iterator from a non const.
1.304 MapConstValueIterator(const MapValueIterator<Map>& pit) {
1.305 - it = pit.it;
1.306 + Base::it = pit.Base::it;
1.307 map = pit.map;
1.308 }
1.309
1.310 /// Map and KeyIt initialized iterator.
1.311 MapConstValueIterator(const Map& pmap, const KeyIt& pit)
1.312 - : MapIteratorBase<Map>(pit), map(&pmap) {}
1.313 + : Base(pit), map(&pmap) {}
1.314
1.315 /// The pre increment operator of the iterator.
1.316 MapConstValueIterator& operator++() {
1.317 - increment();
1.318 + Base::increment();
1.319 return *this;
1.320 }
1.321
1.322 /// The post increment operator of the iterator.
1.323 MapConstValueIterator operator++(int) {
1.324 MapConstValueIterator tmp(*this);
1.325 - increment();
1.326 + Base::increment();
1.327 return tmp;
1.328 }
1.329
1.330 /// The dereferencing operator of the iterator.
1.331 ConstReferenceType operator*() const {
1.332 - return (*map)[it];
1.333 + return (*map)[Base::it];
1.334 }
1.335
1.336 /// The arrow operator of the iterator.
1.337 @@ -413,6 +475,13 @@
1.338 return &(operator*());
1.339 }
1.340
1.341 + public:
1.342 + // STL compatibility typedefs.
1.343 + typedef std::input_iterator_tag iterator_category;
1.344 + typedef int difference_type;
1.345 + typedef ValueType value_type;
1.346 + typedef ConstReferenceType reference;
1.347 + typedef ConstPointerType pointer;
1.348 };
1.349
1.350
1.351 @@ -431,6 +500,21 @@
1.352 /// The iterator to iterate on the keys.
1.353 typedef typename Map::KeyIt KeyIt;
1.354
1.355 +
1.356 + /// The value type of the iterator.
1.357 + typedef typename Map::ValueType ValueType;
1.358 + /// The reference type of the iterator.
1.359 + typedef typename Map::ReferenceType ReferenceType;
1.360 + /// The pointer type of the iterator.
1.361 + typedef typename Map::PointerType PointerType;
1.362 +
1.363 + /// The const value type of the iterator.
1.364 + typedef typename Map::ConstValueType ConstValueType;
1.365 + /// The const reference type of the iterator.
1.366 + typedef typename Map::ConstReferenceType ConstReferenceType;
1.367 + /// The pointer type of the iterator.
1.368 + typedef typename Map::ConstPointerType ConstPointerType;
1.369 +
1.370 /// The map initialized const key set.
1.371 MapConstKeySet(const Map& pmap) : map(&pmap) {}
1.372
1.373 @@ -446,6 +530,14 @@
1.374 ConstIterator end() const {
1.375 return ConstIterator(KeyIt(INVALID));
1.376 }
1.377 +
1.378 + public:
1.379 + // STL compatibility typedefs.
1.380 + typedef ValueType value_type;
1.381 + typedef ConstIterator const_iterator;
1.382 + typedef ConstReferenceType const_reference;
1.383 + typedef ConstPointerType const_pointer;
1.384 + typedef int difference_type;
1.385 };
1.386
1.387 /** This class makes from a map an iteratable set
1.388 @@ -464,6 +556,21 @@
1.389 /// The iterator to iterate on the keys.
1.390 typedef typename Map::KeyIt KeyIt;
1.391
1.392 +
1.393 + /// The value type of the iterator.
1.394 + typedef typename Map::ValueType ValueType;
1.395 + /// The reference type of the iterator.
1.396 + typedef typename Map::ReferenceType ReferenceType;
1.397 + /// The pointer type of the iterator.
1.398 + typedef typename Map::PointerType PointerType;
1.399 +
1.400 + /// The const value type of the iterator.
1.401 + typedef typename Map::ConstValueType ConstValueType;
1.402 + /// The const reference type of the iterator.
1.403 + typedef typename Map::ConstReferenceType ConstReferenceType;
1.404 + /// The pointer type of the iterator.
1.405 + typedef typename Map::ConstPointerType ConstPointerType;
1.406 +
1.407 /// The map initialized const value set.
1.408 MapConstValueSet(const Map& pmap) : map(&pmap) {}
1.409
1.410 @@ -479,6 +586,14 @@
1.411 ConstIterator end() const {
1.412 return ConstIterator(*map, KeyIt(INVALID));
1.413 }
1.414 +
1.415 + public:
1.416 + // STL compatibility typedefs.
1.417 + typedef ValueType value_type;
1.418 + typedef ConstIterator const_iterator;
1.419 + typedef ConstReferenceType const_reference;
1.420 + typedef ConstPointerType const_pointer;
1.421 + typedef int difference_type;
1.422 };
1.423
1.424
1.425 @@ -498,6 +613,21 @@
1.426 /// The iterator to iterate on the keys.
1.427 typedef typename Map::KeyIt KeyIt;
1.428
1.429 +
1.430 + /// The value type of the iterator.
1.431 + typedef typename Map::ValueType ValueType;
1.432 + /// The reference type of the iterator.
1.433 + typedef typename Map::ReferenceType ReferenceType;
1.434 + /// The pointer type of the iterator.
1.435 + typedef typename Map::PointerType PointerType;
1.436 +
1.437 + /// The const value type of the iterator.
1.438 + typedef typename Map::ConstValueType ConstValueType;
1.439 + /// The const reference type of the iterator.
1.440 + typedef typename Map::ConstReferenceType ConstReferenceType;
1.441 + /// The pointer type of the iterator.
1.442 + typedef typename Map::ConstPointerType ConstPointerType;
1.443 +
1.444 /// The map initialized value set.
1.445 MapValueSet(Map& pmap) : map(&pmap) {}
1.446
1.447 @@ -527,6 +657,17 @@
1.448 return Iterator(*map, KeyIt(INVALID));
1.449 }
1.450
1.451 + public:
1.452 + // STL compatibility typedefs.
1.453 + typedef ValueType value_type;
1.454 + typedef Iterator iterator;
1.455 + typedef ConstIterator const_iterator;
1.456 + typedef ReferenceType reference;
1.457 + typedef ConstReferenceType const_reference;
1.458 + typedef PointerType pointer;
1.459 + typedef ConstPointerType const_pointer;
1.460 + typedef int difference_type;
1.461 +
1.462 };
1.463
1.464 /// @}