1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lemon/bits/map_iterator.h Mon May 23 04:48:14 2005 +0000
1.3 @@ -0,0 +1,855 @@
1.4 +/* -*- C++ -*-
1.5 + * lemon/map_iterator.h - Part of LEMON, a generic C++ optimization library
1.6 + *
1.7 + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.8 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.9 + *
1.10 + * Permission to use, modify and distribute this software is granted
1.11 + * provided that this copyright notice appears in all copies. For
1.12 + * precise terms see the accompanying LICENSE file.
1.13 + *
1.14 + * This software is provided "AS IS" with no warranty of any kind,
1.15 + * express or implied, and with no claim as to its suitability for any
1.16 + * purpose.
1.17 + *
1.18 + */
1.19 +
1.20 +#ifndef LEMON_MAP_ITERATOR_H
1.21 +#define LEMON_MAP_ITERATOR_H
1.22 +
1.23 +#include <iterator>
1.24 +
1.25 +#include <lemon/bits/extended_pair.h>
1.26 +#include <lemon/graph_utils.h>
1.27 +
1.28 +///\ingroup graphmaps
1.29 +///\file
1.30 +///\brief Iterators on the maps.
1.31 +
1.32 +namespace lemon {
1.33 +
1.34 + /// \addtogroup graphmaps
1.35 + /// @{
1.36 +
1.37 + /** The base class all of the map iterators.
1.38 + * The class defines the typedefs of the iterators,
1.39 + * simple step functions and equality operators.
1.40 + */
1.41 +
1.42 + template <
1.43 + typename _Graph,
1.44 + typename _Item>
1.45 + class MapIteratorBase {
1.46 +
1.47 + protected:
1.48 +
1.49 + /// The key type of the iterator.
1.50 + typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
1.51 +
1.52 + ItemIt it;
1.53 +
1.54 + /// Default constructor.
1.55 + MapIteratorBase() {}
1.56 +
1.57 + /// ItemIt initialized MapIteratorBase constructor.
1.58 + MapIteratorBase(const ItemIt _it) : it(_it) {}
1.59 +
1.60 + public:
1.61 +
1.62 + /// Stepping forward in the map.
1.63 + void increment() {
1.64 + ++it;
1.65 + }
1.66 +
1.67 + /// The equality operator of the map.
1.68 + bool operator==(const MapIteratorBase& _it) const {
1.69 + return _it.it == it;
1.70 + }
1.71 +
1.72 + /// The not-equality operator of the map.
1.73 + bool operator!=(const MapIteratorBase& _it) const {
1.74 + return !(*this == _it);
1.75 + }
1.76 + };
1.77 +
1.78 +
1.79 + template <
1.80 + typename _Graph,
1.81 + typename _Item,
1.82 + typename _Map>
1.83 + class MapConstIterator;
1.84 +
1.85 + /** Compatible iterator with the stl maps' iterators.
1.86 + * It iterates on pairs of a key and a value.
1.87 + */
1.88 + template <
1.89 + typename _Graph,
1.90 + typename _Item,
1.91 + typename _Map>
1.92 + class MapIterator : public MapIteratorBase<_Graph, _Item> {
1.93 +
1.94 + friend class MapConstIterator<_Graph, _Item, _Map>;
1.95 +
1.96 +
1.97 + public:
1.98 +
1.99 + /// The iterator base class.
1.100 + typedef MapIteratorBase<_Graph, _Item> Parent;
1.101 +
1.102 + typedef _Item Item;
1.103 + typedef _Map Map;
1.104 + typedef _Graph Graph;
1.105 +
1.106 + protected:
1.107 +
1.108 + typedef typename Parent::ItemIt ItemIt;
1.109 +
1.110 + typedef typename ReferenceMapTraits<_Map>::Value MapValue;
1.111 + typedef typename ReferenceMapTraits<_Map>::Reference MapReference;
1.112 +
1.113 + public:
1.114 +
1.115 + /// The value type of the iterator.
1.116 + typedef extended_pair<Item, const Item&,
1.117 + MapValue, const MapValue&> Value;
1.118 +
1.119 + /// The reference type of the iterator.
1.120 + typedef extended_pair<const Item&, const Item&,
1.121 + MapReference, MapReference> Reference;
1.122 +
1.123 + /// Default constructor.
1.124 + MapIterator() {}
1.125 +
1.126 + /// Constructor to initalize the iterators returned
1.127 + /// by the begin() and end().
1.128 + MapIterator(Map& _map, const ItemIt& _it)
1.129 + : Parent(_it), map(&_map) {}
1.130 +
1.131 + /// Dereference operator for the iterator.
1.132 + Reference operator*() {
1.133 + return Reference(Parent::it, (*map)[Parent::it]);
1.134 + }
1.135 +
1.136 + /// The pointer type of the iterator.
1.137 + class Pointer {
1.138 + friend class MapIterator;
1.139 + protected:
1.140 + Reference data;
1.141 + Pointer(const Item& item, MapReference val)
1.142 + : data(item, val) {}
1.143 + public:
1.144 + Reference* operator->() {return &data;}
1.145 + };
1.146 +
1.147 + /// Arrow operator for the iterator.
1.148 + Pointer operator->() {
1.149 + return Pointer(Parent::it, (*map)[Parent::it]);
1.150 + }
1.151 +
1.152 + /// The pre increment operator of the iterator.
1.153 + MapIterator& operator++() {
1.154 + Parent::increment();
1.155 + return *this;
1.156 + }
1.157 +
1.158 + /// The post increment operator of the iterator.
1.159 + MapIterator operator++(int) {
1.160 + MapIterator tmp(*this);
1.161 + Parent::increment();
1.162 + return tmp;
1.163 + }
1.164 +
1.165 + protected:
1.166 +
1.167 + Map* map;
1.168 +
1.169 + public:
1.170 + // STL compatibility typedefs.
1.171 + typedef std::forward_iterator_tag iterator_category;
1.172 + typedef int difference_type;
1.173 + typedef Value value_type;
1.174 + typedef Reference reference;
1.175 + typedef Pointer pointer;
1.176 + };
1.177 +
1.178 + /** Compatible iterator with the stl maps' iterators.
1.179 + * It iterates on pairs of a key and a value.
1.180 + */
1.181 + template <
1.182 + typename _Graph,
1.183 + typename _Item,
1.184 + typename _Map>
1.185 + class MapConstIterator : public MapIteratorBase<_Graph, _Item> {
1.186 +
1.187 + public:
1.188 +
1.189 + /// The iterator base class.
1.190 + typedef MapIteratorBase<_Graph, _Item> Parent;
1.191 +
1.192 + typedef _Graph Graph;
1.193 + typedef _Item Item;
1.194 + typedef _Map Map;
1.195 +
1.196 + protected:
1.197 +
1.198 + typedef typename Parent::ItemIt ItemIt;
1.199 +
1.200 + typedef typename ReferenceMapTraits<_Map>::Value MapValue;
1.201 + typedef typename ReferenceMapTraits<_Map>::ConstReference
1.202 + MapReference;
1.203 +
1.204 + public:
1.205 +
1.206 + /// The value type of the iterator.
1.207 + typedef extended_pair<Item, const Item&,
1.208 + MapValue, const MapValue&> Value;
1.209 +
1.210 + /// The reference type of the iterator.
1.211 + typedef extended_pair<const Item&, const Item&,
1.212 + MapReference, MapReference> Reference;
1.213 +
1.214 + /// Default constructor.
1.215 + MapConstIterator() {}
1.216 +
1.217 + /// Constructor to initalize the iterators returned
1.218 + /// by the begin() and end().
1.219 + MapConstIterator(const Map& _map, const ItemIt& _it)
1.220 + : Parent(_it), map(&_map) {}
1.221 +
1.222 + /// Dereference operator for the iterator.
1.223 + Reference operator*() {
1.224 + return Reference(Parent::it, (*map)[Parent::it]);
1.225 + }
1.226 +
1.227 + /// The pointer type of the iterator.
1.228 + class Pointer {
1.229 + friend class MapConstIterator;
1.230 + protected:
1.231 + Reference data;
1.232 + Pointer(const Item& item, MapReference val)
1.233 + : data(item, val) {}
1.234 + public:
1.235 + Reference* operator->() {return &data;}
1.236 + };
1.237 +
1.238 + /// Arrow operator for the iterator.
1.239 + Pointer operator->() {
1.240 + return Pointer(Parent::it, ((*map)[Parent::it]));
1.241 + }
1.242 +
1.243 + /// The pre increment operator of the iterator.
1.244 + MapConstIterator& operator++() {
1.245 + Parent::increment();
1.246 + return *this;
1.247 + }
1.248 +
1.249 + /// The post increment operator of the iterator.
1.250 + MapConstIterator operator++(int) {
1.251 + MapConstIterator tmp(*this);
1.252 + Parent::increment();
1.253 + return tmp;
1.254 + }
1.255 +
1.256 + protected:
1.257 + const Map* map;
1.258 +
1.259 + public:
1.260 + // STL compatibility typedefs.
1.261 + typedef std::forward_iterator_tag iterator_category;
1.262 + typedef int difference_type;
1.263 + typedef Value value_type;
1.264 + typedef Reference reference;
1.265 + typedef Pointer pointer;
1.266 + };
1.267 +
1.268 + /** The class makes the ItemIt to an stl compatible iterator
1.269 + * with dereferencing operator.
1.270 + */
1.271 + template <
1.272 + typename _Graph,
1.273 + typename _Item>
1.274 + class MapConstKeyIterator : public MapIteratorBase<_Graph, _Item> {
1.275 +
1.276 + public:
1.277 +
1.278 + /// The iterator base class.
1.279 + typedef MapIteratorBase<_Graph, _Item> Parent;
1.280 +
1.281 + typedef _Graph Graph;
1.282 + typedef _Item Item;
1.283 +
1.284 + protected:
1.285 + /// The iterator to iterate on the keys.
1.286 + typedef typename Parent::ItemIt ItemIt;
1.287 +
1.288 + public:
1.289 +
1.290 + typedef Item Value;
1.291 + typedef const Item& Reference;
1.292 + typedef const Item* Pointer;
1.293 +
1.294 + /// Default constructor.
1.295 + MapConstKeyIterator() {}
1.296 +
1.297 + /// ItemIt initialized iterator.
1.298 + MapConstKeyIterator(const ItemIt& pit) : Parent(pit) {}
1.299 +
1.300 + /// The pre increment operator of the iterator.
1.301 + MapConstKeyIterator& operator++() {
1.302 + Parent::increment();
1.303 + return *this;
1.304 + }
1.305 +
1.306 + /// The post increment operator of the iterator.
1.307 + MapConstKeyIterator operator++(int) {
1.308 + MapConstKeyIterator tmp(*this);
1.309 + Parent::increment();
1.310 + return tmp;
1.311 + }
1.312 +
1.313 + /// The dereferencing operator of the iterator.
1.314 + Item operator*() const {
1.315 + return static_cast<Item>(Parent::it);
1.316 + }
1.317 +
1.318 + public:
1.319 + // STL compatibility typedefs.
1.320 + typedef std::input_iterator_tag iterator_category;
1.321 + typedef int difference_type;
1.322 + typedef Value value_type;
1.323 + typedef Reference reference;
1.324 + typedef Pointer pointer;
1.325 + };
1.326 +
1.327 + template <
1.328 + typename _Graph,
1.329 + typename _Item,
1.330 + typename _Map>
1.331 + class MapConstValueIterator;
1.332 +
1.333 + /** MapValueIterator creates an stl compatible iterator
1.334 + * for the values.
1.335 + */
1.336 + template <
1.337 + typename _Graph,
1.338 + typename _Item,
1.339 + typename _Map>
1.340 + class MapValueIterator : public MapIteratorBase<_Graph, _Item> {
1.341 +
1.342 + friend class MapConstValueIterator<_Graph, _Item, _Map>;
1.343 +
1.344 + public:
1.345 +
1.346 + /// The iterator base class.
1.347 + typedef MapIteratorBase<_Graph, _Item> Parent;
1.348 +
1.349 + typedef _Graph Graph;
1.350 + typedef _Item Item;
1.351 + typedef _Map Map;
1.352 +
1.353 + protected:
1.354 +
1.355 + /// The iterator to iterate on the keys.
1.356 + typedef typename Parent::ItemIt ItemIt;
1.357 +
1.358 + /// The value type of the iterator.
1.359 + typedef typename ReferenceMapTraits<Map>::Value MapValue;
1.360 + /// The reference type of the iterator.
1.361 + typedef typename ReferenceMapTraits<Map>::Reference MapReference;
1.362 + /// The pointer type of the iterator.
1.363 + typedef typename ReferenceMapTraits<Map>::Pointer MapPointer;
1.364 +
1.365 + public:
1.366 +
1.367 + typedef MapValue Value;
1.368 + typedef MapReference Reference;
1.369 + typedef MapPointer Pointer;
1.370 +
1.371 + /// Default constructor.
1.372 + MapValueIterator() {}
1.373 +
1.374 + /// Map and ItemIt initialized iterator.
1.375 + MapValueIterator(Map& _map, const ItemIt& _it)
1.376 + : Parent(_it), map(&_map) {}
1.377 +
1.378 +
1.379 + /// The pre increment operator of the iterator.
1.380 + MapValueIterator& operator++() {
1.381 + Parent::increment();
1.382 + return *this;
1.383 + }
1.384 +
1.385 + /// The post increment operator of the iterator.
1.386 + MapValueIterator operator++(int) {
1.387 + MapValueIterator tmp(*this);
1.388 + Parent::increment();
1.389 + return tmp;
1.390 + }
1.391 +
1.392 + /// The dereferencing operator of the iterator.
1.393 + Reference operator*() const {
1.394 + return (*map)[Parent::it];
1.395 + }
1.396 +
1.397 + /// The arrow operator of the iterator.
1.398 + Pointer operator->() const {
1.399 + return &(operator*());
1.400 + }
1.401 +
1.402 + protected:
1.403 +
1.404 + Map* map;
1.405 +
1.406 + public:
1.407 + // STL compatibility typedefs.
1.408 + typedef std::forward_iterator_tag iterator_category;
1.409 + typedef int difference_type;
1.410 + typedef Value value_type;
1.411 + typedef Reference reference;
1.412 + typedef Pointer pointer;
1.413 + };
1.414 +
1.415 + /** MapValueIterator creates an stl compatible iterator
1.416 + * for the values.
1.417 + */
1.418 + template <
1.419 + typename _Graph,
1.420 + typename _Item,
1.421 + typename _Map>
1.422 + class MapConstValueIterator : public MapIteratorBase<_Graph, _Item> {
1.423 +
1.424 + public:
1.425 +
1.426 + /// The iterator base class.
1.427 + typedef MapIteratorBase<_Graph, _Item> Parent;
1.428 +
1.429 + typedef _Graph Graph;
1.430 + typedef _Item Item;
1.431 + typedef _Map Map;
1.432 +
1.433 + protected:
1.434 +
1.435 + /// The iterator to iterate on the keys.
1.436 + typedef typename Parent::ItemIt ItemIt;
1.437 +
1.438 + /// The value type of the iterator.
1.439 + typedef typename ReferenceMapTraits<Map>::Value MapValue;
1.440 + /// The reference type of the iterator.
1.441 + typedef typename ReferenceMapTraits<Map>::ConstReference MapReference;
1.442 + /// The pointer type of the iterator.
1.443 + typedef typename ReferenceMapTraits<Map>::ConstPointer MapPointer;
1.444 +
1.445 + public:
1.446 +
1.447 + typedef MapValue Value;
1.448 + typedef MapReference Reference;
1.449 + typedef MapPointer Pointer;
1.450 +
1.451 + /// Default constructor.
1.452 + MapConstValueIterator() {}
1.453 +
1.454 + /// Map and ItemIt initialized iterator.
1.455 + MapConstValueIterator(const Map& _map, const ItemIt& _it)
1.456 + : Parent(_it), map(&_map) {}
1.457 +
1.458 +
1.459 + /// The pre increment operator of the iterator.
1.460 + MapConstValueIterator& operator++() {
1.461 + Parent::increment();
1.462 + return *this;
1.463 + }
1.464 +
1.465 + /// The post increment operator of the iterator.
1.466 + MapConstValueIterator operator++(int) {
1.467 + MapConstValueIterator tmp(*this);
1.468 + Parent::increment();
1.469 + return tmp;
1.470 + }
1.471 +
1.472 + /// The dereferencing operator of the iterator.
1.473 + Reference operator*() const {
1.474 + return (*map)[Parent::it];
1.475 + }
1.476 +
1.477 + /// The arrow operator of the iterator.
1.478 + Pointer operator->() const {
1.479 + return &(operator*());
1.480 + }
1.481 +
1.482 + protected:
1.483 +
1.484 + const Map* map;
1.485 +
1.486 + public:
1.487 + // STL compatibility typedefs.
1.488 + typedef std::forward_iterator_tag iterator_category;
1.489 + typedef int difference_type;
1.490 + typedef Value value_type;
1.491 + typedef Reference reference;
1.492 + typedef Pointer pointer;
1.493 + };
1.494 +
1.495 +
1.496 + /** This class makes from a map an iteratable set
1.497 + * which contains all the keys of the map.
1.498 + */
1.499 + template <typename _Graph, typename _Item>
1.500 + class MapConstKeySet {
1.501 +
1.502 + public:
1.503 +
1.504 + typedef _Graph Graph;
1.505 + /// The key type of the iterator.
1.506 + typedef _Item Item;
1.507 + /// The iterator to iterate on the keys.
1.508 +
1.509 + protected:
1.510 +
1.511 + typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
1.512 +
1.513 + public:
1.514 +
1.515 + /// The map initialized const key set.
1.516 + MapConstKeySet(const Graph& _graph) : graph(&_graph) {}
1.517 +
1.518 + /// The const iterator of the set.
1.519 + typedef MapConstKeyIterator<_Graph, _Item> ConstIterator;
1.520 +
1.521 + typedef typename ConstIterator::Value Value;
1.522 + /// The reference type of the iterator.
1.523 + typedef typename ConstIterator::Reference ConstReference;
1.524 + /// The pointer type of the iterator.
1.525 + typedef typename ConstIterator::Pointer ConstPointer;
1.526 +
1.527 + /// It gives back the const iterator pointed to the first element.
1.528 + ConstIterator begin() const {
1.529 + return ConstIterator(ItemIt(*graph));
1.530 + }
1.531 +
1.532 + /// It gives back the const iterator pointed to the first ivalid element.
1.533 + ConstIterator end() const {
1.534 + return ConstIterator(ItemIt(INVALID));
1.535 + }
1.536 +
1.537 + protected:
1.538 +
1.539 + const Graph* graph;
1.540 +
1.541 + public:
1.542 + // STL compatibility typedefs.
1.543 + typedef Value value_type;
1.544 + typedef ConstIterator const_iterator;
1.545 + typedef ConstReference const_reference;
1.546 + typedef ConstPointer const_pointer;
1.547 + typedef int difference_type;
1.548 + };
1.549 +
1.550 + /** This class makes from a map an iteratable set
1.551 + * which contains all the values of the map.
1.552 + * The values cannot be modified.
1.553 + */
1.554 + template <typename _Graph, typename _Item, typename _Map>
1.555 + class MapConstValueSet {
1.556 +
1.557 + public:
1.558 +
1.559 + typedef _Graph Graph;
1.560 + typedef _Item Item;
1.561 + typedef _Map Map;
1.562 +
1.563 + protected:
1.564 +
1.565 + /// The iterator to iterate on the keys.
1.566 + typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
1.567 +
1.568 + public:
1.569 +
1.570 + /// The map initialized const value set.
1.571 + MapConstValueSet(const Graph& _graph, const Map& _map)
1.572 + : graph(&_graph), map(&_map) {}
1.573 +
1.574 + /// The const iterator of the set.
1.575 + typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
1.576 +
1.577 + typedef typename ConstIterator::Value Value;
1.578 + typedef typename ConstIterator::Reference ConstReference;
1.579 + typedef typename ConstIterator::Pointer ConstPointer;
1.580 +
1.581 + /// It gives back the const iterator pointed to the first element.
1.582 + ConstIterator begin() const {
1.583 + return ConstIterator(*map, ItemIt(*graph));
1.584 + }
1.585 +
1.586 + /// It gives back the const iterator pointed to the first invalid element.
1.587 + ConstIterator end() const {
1.588 + return ConstIterator(*map, ItemIt(INVALID));
1.589 + }
1.590 +
1.591 + protected:
1.592 +
1.593 + const Map* map;
1.594 + const Graph * graph;
1.595 +
1.596 + public:
1.597 + // STL compatibility typedefs.
1.598 + typedef Value value_type;
1.599 + typedef ConstIterator const_iterator;
1.600 + typedef ConstReference const_reference;
1.601 + typedef ConstPointer const_pointer;
1.602 + typedef int difference_type;
1.603 + };
1.604 +
1.605 +
1.606 + /** This class makes from a map an iteratable set
1.607 + * which contains all the values of the map.
1.608 + * The values can be modified.
1.609 + */
1.610 + template <typename _Graph, typename _Item, typename _Map>
1.611 + class MapValueSet {
1.612 +
1.613 + public:
1.614 +
1.615 + typedef _Graph Graph;
1.616 + typedef _Item Item;
1.617 + typedef _Map Map;
1.618 +
1.619 + protected:
1.620 +
1.621 + /// The iterator to iterate on the keys.
1.622 + typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
1.623 +
1.624 + public:
1.625 +
1.626 + /// The map initialized const value set.
1.627 + MapValueSet(const Graph& _graph, Map& _map)
1.628 + : map(&_map), graph(&_graph) {}
1.629 +
1.630 + /// The const iterator of the set.
1.631 + typedef MapValueIterator<_Graph, _Item, _Map> Iterator;
1.632 + /// The const iterator of the set.
1.633 + typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
1.634 +
1.635 + typedef typename ConstIterator::Value Value;
1.636 + typedef typename Iterator::Reference Reference;
1.637 + typedef typename Iterator::Pointer Pointer;
1.638 + typedef typename ConstIterator::Reference ConstReference;
1.639 + typedef typename ConstIterator::Pointer ConstPointer;
1.640 +
1.641 + /// It gives back the const iterator pointed to the first element.
1.642 + ConstIterator begin() const {
1.643 + return ConstIterator(*map, ItemIt(*graph));
1.644 + }
1.645 +
1.646 + /// It gives back the const iterator pointed to the first invalid element.
1.647 + ConstIterator end() const {
1.648 + return ConstIterator(*map, ItemIt(INVALID));
1.649 + }
1.650 +
1.651 + /// It gives back the iterator pointed to the first element.
1.652 + Iterator begin() {
1.653 + return Iterator(*map, ItemIt(*graph));
1.654 + }
1.655 +
1.656 + /// It gives back the iterator pointed to the first invalid element.
1.657 + Iterator end() {
1.658 + return Iterator(*map, ItemIt(INVALID));
1.659 + }
1.660 +
1.661 + protected:
1.662 +
1.663 + Map* map;
1.664 + const Graph * graph;
1.665 +
1.666 + public:
1.667 + // STL compatibility typedefs.
1.668 + typedef Value value_type;
1.669 + typedef Iterator iterator;
1.670 + typedef ConstIterator const_iterator;
1.671 + typedef Reference reference;
1.672 + typedef ConstReference const_reference;
1.673 + typedef Pointer pointer;
1.674 + typedef ConstPointer const_pointer;
1.675 + typedef int difference_type;
1.676 +
1.677 + };
1.678 +
1.679 + /** This class makes from a map an iteratable set
1.680 + * which contains all the values of the map.
1.681 + * The values can be modified.
1.682 + */
1.683 + template <
1.684 + typename _Graph,
1.685 + typename _Item,
1.686 + typename _Map
1.687 + >
1.688 + class MapSet {
1.689 + public:
1.690 +
1.691 + typedef _Graph Graph;
1.692 + typedef _Item Item;
1.693 + typedef _Map Map;
1.694 +
1.695 + protected:
1.696 +
1.697 + typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
1.698 +
1.699 + public:
1.700 +
1.701 + /// The map initialized value set.
1.702 + MapSet(const Graph& _graph, Map& _map) : graph(&_graph), map(&_map) {}
1.703 +
1.704 + /// The const iterator of the set.
1.705 + typedef MapIterator<_Graph, _Item, _Map> Iterator;
1.706 + typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
1.707 +
1.708 + typedef typename ConstIterator::Value Value;
1.709 + typedef typename Iterator::Reference Reference;
1.710 + typedef typename Iterator::Pointer Pointer;
1.711 + typedef typename ConstIterator::Reference ConstReference;
1.712 + typedef typename ConstIterator::Pointer ConstPointer;
1.713 +
1.714 +
1.715 + /// It gives back the const iterator pointed to the first element.
1.716 + ConstIterator begin() const {
1.717 + return ConstIterator(*map, ItemIt(*graph));
1.718 + }
1.719 +
1.720 + /// It gives back the const iterator pointed to the first invalid element.
1.721 + ConstIterator end() const {
1.722 + return ConstIterator(*map, ItemIt(INVALID));
1.723 + }
1.724 +
1.725 + /// The iterator of the set.
1.726 +
1.727 + /// It gives back the iterator pointed to the first element.
1.728 + Iterator begin() {
1.729 + return Iterator(*map, ItemIt(*graph));
1.730 + }
1.731 +
1.732 + /// It gives back the iterator pointed to the first invalid element.
1.733 + Iterator end() {
1.734 + return Iterator(*map, ItemIt(INVALID));
1.735 + }
1.736 +
1.737 + protected:
1.738 +
1.739 + const Graph* graph;
1.740 + Map* map;
1.741 +
1.742 + public:
1.743 + // STL compatibility typedefs.
1.744 + typedef Value value_type;
1.745 + typedef Iterator iterator;
1.746 + typedef ConstIterator const_iterator;
1.747 + typedef Reference reference;
1.748 + typedef ConstReference const_reference;
1.749 + typedef Pointer pointer;
1.750 + typedef ConstPointer const_pointer;
1.751 + typedef int difference_type;
1.752 +
1.753 + };
1.754 +
1.755 + template <
1.756 + typename _Graph,
1.757 + typename _Item,
1.758 + typename _Map
1.759 + >
1.760 + class ConstMapSet {
1.761 +
1.762 + typedef _Graph Graph;
1.763 + typedef _Map Map;
1.764 +
1.765 + const Graph* graph;
1.766 + const Map* map;
1.767 +
1.768 + public:
1.769 +
1.770 + typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
1.771 +
1.772 +
1.773 + /// The map initialized value set.
1.774 + ConstMapSet(const Graph& _graph, const Map& _map)
1.775 + : graph(&_graph), map(&_map) {}
1.776 +
1.777 + /// The const iterator of the set.
1.778 + typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
1.779 +
1.780 + typedef typename ConstIterator::Value Value;
1.781 + typedef typename ConstIterator::Reference ConstReference;
1.782 + typedef typename ConstIterator::Pointer ConstPointer;
1.783 +
1.784 +
1.785 + /// It gives back the const iterator pointed to the first element.
1.786 + ConstIterator begin() const {
1.787 + return ConstIterator(*map, ItemIt(*graph));
1.788 + }
1.789 +
1.790 + /// It gives back the const iterator pointed to the first invalid element.
1.791 + ConstIterator end() const {
1.792 + return ConstIterator(*map, ItemIt(INVALID));
1.793 + }
1.794 +
1.795 + public:
1.796 + // STL compatibility typedefs.
1.797 + typedef Value value_type;
1.798 + typedef ConstIterator const_iterator;
1.799 + typedef ConstReference const_reference;
1.800 + typedef ConstPointer const_pointer;
1.801 + typedef int difference_type;
1.802 +
1.803 + };
1.804 +
1.805 + template <typename _Map>
1.806 + class IterableMapExtender : public _Map {
1.807 + public:
1.808 +
1.809 + typedef _Map Parent;
1.810 + typedef Parent Map;
1.811 + typedef typename Map::Graph Graph;
1.812 + typedef typename Map::Key Item;
1.813 + typedef typename Map::Value Value;
1.814 +
1.815 + typedef MapSet<Graph, Item, Map> MapSet;
1.816 +
1.817 + IterableMapExtender() : Parent() {}
1.818 +
1.819 + IterableMapExtender(const Graph& graph) : Parent(graph) {}
1.820 +
1.821 + IterableMapExtender(const Graph& graph, const Value& value)
1.822 + : Parent(graph, value) {}
1.823 +
1.824 + MapSet mapSet() {
1.825 + return MapSet(*Parent::getGraph(), *this);
1.826 + }
1.827 +
1.828 + typedef ConstMapSet<Graph, Item, Map> ConstMapSet;
1.829 +
1.830 + ConstMapSet mapSet() const {
1.831 + return ConstMapSet(*Parent::getGraph(), *this);
1.832 + }
1.833 +
1.834 + typedef MapConstKeySet<Graph, Item> ConstKeySet;
1.835 +
1.836 + ConstKeySet keySet() const {
1.837 + return ConstKeySet(*Parent::getGraph());
1.838 + }
1.839 +
1.840 + typedef MapValueSet<Graph, Item, Map> ValueSet;
1.841 +
1.842 + ValueSet valueSet() {
1.843 + return ValueSet(*Parent::getGraph(), *this);
1.844 + }
1.845 +
1.846 + typedef MapConstValueSet<Graph, Item, Map> ConstValueSet;
1.847 +
1.848 + ConstValueSet valueSet() const {
1.849 + return ConstValueSet(*Parent::getGraph(), *this);
1.850 + }
1.851 +
1.852 + };
1.853 +
1.854 + /// @}
1.855 +
1.856 +}
1.857 +
1.858 +#endif