[Lemon-commits] [lemon_svn] deba: r2355 - in hugo/trunk/lemon: . bits
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:52:01 CET 2006
Author: deba
Date: Wed Nov 16 19:58:10 2005
New Revision: 2355
Added:
hugo/trunk/lemon/bits/map_extender.h
- copied, changed from r2345, /hugo/trunk/lemon/bits/map_iterator.h
hugo/trunk/lemon/map_iterator.h
- copied, changed from r2345, /hugo/trunk/lemon/bits/map_iterator.h
Removed:
hugo/trunk/lemon/bits/map_iterator.h
Modified:
hugo/trunk/lemon/bits/array_map.h
hugo/trunk/lemon/bits/static_map.h
hugo/trunk/lemon/bits/vector_map.h
hugo/trunk/lemon/iterable_maps.h
hugo/trunk/lemon/lp_base.h
Log:
Modified iterators on graph maps
Other iterators for not graph maps
Modified: hugo/trunk/lemon/bits/array_map.h
==============================================================================
--- hugo/trunk/lemon/bits/array_map.h (original)
+++ hugo/trunk/lemon/bits/array_map.h Wed Nov 16 19:58:10 2005
@@ -18,7 +18,7 @@
#define LEMON_ARRAY_MAP_H
#include <memory>
-#include <lemon/bits/map_iterator.h>
+#include <lemon/bits/map_extender.h>
#include <lemon/concept_check.h>
#include <lemon/concept/maps.h>
Copied: hugo/trunk/lemon/bits/map_extender.h (from r2345, /hugo/trunk/lemon/bits/map_iterator.h)
==============================================================================
--- /hugo/trunk/lemon/bits/map_iterator.h (original)
+++ hugo/trunk/lemon/bits/map_extender.h Wed Nov 16 19:58:10 2005
@@ -1,5 +1,5 @@
/* -*- C++ -*-
- * lemon/map_iterator.h - Part of LEMON, a generic C++ optimization library
+ * lemon/map_extender.h - Part of LEMON, a generic C++ optimization library
*
* Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
@@ -14,841 +14,102 @@
*
*/
-#ifndef LEMON_MAP_ITERATOR_H
-#define LEMON_MAP_ITERATOR_H
+#ifndef LEMON_BITS_MAP_EXTENDER_H
+#define LEMON_BITS_MAP_EXTENDER_H
#include <iterator>
-#include <lemon/bits/extended_pair.h>
-#include <lemon/graph_utils.h>
+#include <lemon/traits.h>
-///\ingroup graphmapfactory
///\file
-///\brief Iterators on the maps.
+///\brief Extenders for iterable maps.
namespace lemon {
- /// \addtogroup graphmapfactory
- /// @{
-
- /** The base class all of the map iterators.
- * The class defines the typedefs of the iterators,
- * simple step functions and equality operators.
- */
-
- template <
- typename _Graph,
- typename _Item>
- class MapIteratorBase {
-
- protected:
-
- /// The key type of the iterator.
- typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
-
- ItemIt it;
-
- /// Default constructor.
- MapIteratorBase() {}
-
- /// ItemIt initialized MapIteratorBase constructor.
- MapIteratorBase(const ItemIt _it) : it(_it) {}
-
- public:
-
- /// Stepping forward in the map.
- void increment() {
- ++it;
- }
-
- /// The equality operator of the map.
- bool operator==(const MapIteratorBase& _it) const {
- return _it.it == it;
- }
-
- /// The not-equality operator of the map.
- bool operator!=(const MapIteratorBase& _it) const {
- return !(*this == _it);
- }
- };
-
-
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapConstIterator;
-
- /** Compatible iterator with the stl maps' iterators.
- * It iterates on pairs of a key and a value.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapIterator : public MapIteratorBase<_Graph, _Item> {
-
- friend class MapConstIterator<_Graph, _Item, _Map>;
-
-
+ template <typename _Map>
+ class IterableMapExtender : public _Map {
public:
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Item Item;
- typedef _Map Map;
- typedef _Graph Graph;
+ typedef _Map Parent;
+ typedef IterableMapExtender Map;
- protected:
- typedef typename Parent::ItemIt ItemIt;
+ typedef typename Map::Graph Graph;
+ typedef typename Map::Key Item;
- typedef typename _Map::Value MapValue;
- typedef typename _Map::Reference MapReference;
-
- public:
+ typedef typename Map::Key Key;
+ typedef typename Map::Value Value;
- /// The value type of the iterator.
- typedef extended_pair<Item, const Item&,
- MapValue, const MapValue&> Value;
-
- /// The reference type of the iterator.
- typedef extended_pair<const Item&, const Item&,
- MapReference, MapReference> Reference;
-
- /// Default constructor.
- MapIterator() {}
-
- /// Constructor to initalize the iterators returned
- /// by the begin() and end().
- MapIterator(Map& _map, const ItemIt& _it)
- : Parent(_it), map(&_map) {}
-
- /// Dereference operator for the iterator.
- Reference operator*() {
- return Reference(Parent::it, (*map)[Parent::it]);
- }
-
- /// The pointer type of the iterator.
- class Pointer {
- friend class MapIterator;
- protected:
- Reference data;
- Pointer(const Item& item, MapReference val)
- : data(item, val) {}
- public:
- Reference* operator->() {return &data;}
- };
+ class MapIt;
+ class ConstMapIt;
- /// Arrow operator for the iterator.
- Pointer operator->() {
- return Pointer(Parent::it, (*map)[Parent::it]);
- }
-
- /// The pre increment operator of the iterator.
- MapIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapIterator operator++(int) {
- MapIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
+ friend class MapIt;
+ friend class ConstMapIt;
protected:
- Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef std::forward_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
- /** Compatible iterator with the stl maps' iterators.
- * It iterates on pairs of a key and a value.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapConstIterator : public MapIteratorBase<_Graph, _Item> {
+ using Parent::getGraph;
public:
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
+ IterableMapExtender(const Graph& graph) : Parent(graph) {}
- protected:
+ IterableMapExtender(const Graph& graph, const Value& value)
+ : Parent(graph, value) {}
- typedef typename Parent::ItemIt ItemIt;
- typedef typename _Map::Value MapValue;
- typedef typename _Map::ConstReference MapReference;
-
- public:
+ class MapIt : public ItemSetTraits<Graph, Item>::ItemIt {
+ public:
+
+ typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
- /// The value type of the iterator.
- typedef extended_pair<Item, const Item&,
- MapValue, const MapValue&> Value;
-
- /// The reference type of the iterator.
- typedef extended_pair<const Item&, const Item&,
- MapReference, MapReference> Reference;
-
- /// Default constructor.
- MapConstIterator() {}
-
- /// Constructor to initalize the iterators returned
- /// by the begin() and end().
- MapConstIterator(const Map& _map, const ItemIt& _it)
- : Parent(_it), map(&_map) {}
-
- /// Dereference operator for the iterator.
- Reference operator*() {
- return Reference(Parent::it, (*map)[Parent::it]);
- }
-
- /// The pointer type of the iterator.
- class Pointer {
- friend class MapConstIterator;
+ typedef typename Map::Value Value;
+
+ MapIt(Map& _map) : Parent(*_map.getGraph()), map(_map) {}
+
+ typename MapTraits<Map>::ConstReturnValue operator*() const {
+ return map[*this];
+ }
+
+ typename MapTraits<Map>::ReturnValue operator*() {
+ return map[*this];
+ }
+
+ void set(const Value& value) {
+ map.set(*this, value);
+ }
+
protected:
- Reference data;
- Pointer(const Item& item, MapReference val)
- : data(item, val) {}
- public:
- Reference* operator->() {return &data;}
+ Map& map;
+
};
- /// Arrow operator for the iterator.
- Pointer operator->() {
- return Pointer(Parent::it, ((*map)[Parent::it]));
- }
-
- /// The pre increment operator of the iterator.
- MapConstIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapConstIterator operator++(int) {
- MapConstIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
-
- protected:
- const Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef std::forward_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
- /** The class makes the ItemIt to an stl compatible iterator
- * with dereferencing operator.
- */
- template <
- typename _Graph,
- typename _Item>
- class MapConstKeyIterator : public MapIteratorBase<_Graph, _Item> {
-
- public:
-
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Graph Graph;
- typedef _Item Item;
-
- protected:
- /// The iterator to iterate on the keys.
- typedef typename Parent::ItemIt ItemIt;
-
- public:
-
- typedef Item Value;
- typedef const Item& Reference;
- typedef const Item* Pointer;
-
- /// Default constructor.
- MapConstKeyIterator() {}
-
- /// ItemIt initialized iterator.
- MapConstKeyIterator(const ItemIt& pit) : Parent(pit) {}
-
- /// The pre increment operator of the iterator.
- MapConstKeyIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapConstKeyIterator operator++(int) {
- MapConstKeyIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
-
- /// The dereferencing operator of the iterator.
- Item operator*() const {
- return static_cast<Item>(Parent::it);
- }
-
- public:
- // STL compatibility typedefs.
- typedef std::input_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapConstValueIterator;
-
- /** MapValueIterator creates an stl compatible iterator
- * for the values.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapValueIterator : public MapIteratorBase<_Graph, _Item> {
-
- friend class MapConstValueIterator<_Graph, _Item, _Map>;
-
- public:
-
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- /// The iterator to iterate on the keys.
- typedef typename Parent::ItemIt ItemIt;
-
- /// The value type of the iterator.
- typedef typename Map::Value MapValue;
- /// The reference type of the iterator.
- typedef typename Map::Reference MapReference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer MapPointer;
-
- public:
-
- typedef MapValue Value;
- typedef MapReference Reference;
- typedef MapPointer Pointer;
-
- /// Default constructor.
- MapValueIterator() {}
-
- /// Map and ItemIt initialized iterator.
- MapValueIterator(Map& _map, const ItemIt& _it)
- : Parent(_it), map(&_map) {}
-
-
- /// The pre increment operator of the iterator.
- MapValueIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapValueIterator operator++(int) {
- MapValueIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
-
- /// The dereferencing operator of the iterator.
- Reference operator*() const {
- return (*map)[Parent::it];
- }
-
- /// The arrow operator of the iterator.
- Pointer operator->() const {
- return &(operator*());
- }
-
- protected:
-
- Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef std::forward_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
- /** MapValueIterator creates an stl compatible iterator
- * for the values.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapConstValueIterator : public MapIteratorBase<_Graph, _Item> {
-
- public:
-
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- /// The iterator to iterate on the keys.
- typedef typename Parent::ItemIt ItemIt;
-
- /// The value type of the iterator.
- typedef typename Map::Value MapValue;
- /// The reference type of the iterator.
- typedef typename Map::ConstReference MapReference;
- /// The pointer type of the iterator.
- typedef typename Map::ConstPointer MapPointer;
-
- public:
-
- typedef MapValue Value;
- typedef MapReference Reference;
- typedef MapPointer Pointer;
-
- /// Default constructor.
- MapConstValueIterator() {}
-
- /// Map and ItemIt initialized iterator.
- MapConstValueIterator(const Map& _map, const ItemIt& _it)
- : Parent(_it), map(&_map) {}
-
-
- /// The pre increment operator of the iterator.
- MapConstValueIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapConstValueIterator operator++(int) {
- MapConstValueIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
-
- /// The dereferencing operator of the iterator.
- Reference operator*() const {
- return (*map)[Parent::it];
- }
-
- /// The arrow operator of the iterator.
- Pointer operator->() const {
- return &(operator*());
- }
-
- protected:
-
- const Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef std::forward_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
-
- /** This class makes from a map an iteratable set
- * which contains all the keys of the map.
- */
- template <typename _Graph, typename _Item>
- class MapConstKeySet {
-
- public:
-
- typedef _Graph Graph;
- /// The key type of the iterator.
- typedef _Item Item;
- /// The iterator to iterate on the keys.
-
- protected:
-
- typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
-
- public:
-
- /// The map initialized const key set.
- MapConstKeySet(const Graph& _graph) : graph(&_graph) {}
-
- /// The const iterator of the set.
- typedef MapConstKeyIterator<_Graph, _Item> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- /// The reference type of the iterator.
- typedef typename ConstIterator::Reference ConstReference;
- /// The pointer type of the iterator.
- typedef typename ConstIterator::Pointer ConstPointer;
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first ivalid element.
- ConstIterator end() const {
- return ConstIterator(ItemIt(INVALID));
- }
-
- protected:
-
- const Graph* graph;
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef ConstIterator const_iterator;
- typedef ConstReference const_reference;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
- };
-
- /** This class makes from a map an iteratable set
- * which contains all the values of the map.
- * The values cannot be modified.
- */
- template <typename _Graph, typename _Item, typename _Map>
- class MapConstValueSet {
-
- public:
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- /// The iterator to iterate on the keys.
- typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
-
- public:
-
- /// The map initialized const value set.
- MapConstValueSet(const Graph& _graph, const Map& _map)
- : graph(&_graph), map(&_map) {}
-
- /// The const iterator of the set.
- typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- typedef typename ConstIterator::Reference ConstReference;
- typedef typename ConstIterator::Pointer ConstPointer;
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first invalid element.
- ConstIterator end() const {
- return ConstIterator(*map, ItemIt(INVALID));
- }
-
- protected:
-
- const Map* map;
- const Graph * graph;
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef ConstIterator const_iterator;
- typedef ConstReference const_reference;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
- };
-
-
- /** This class makes from a map an iteratable set
- * which contains all the values of the map.
- * The values can be modified.
- */
- template <typename _Graph, typename _Item, typename _Map>
- class MapValueSet {
-
- public:
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- /// The iterator to iterate on the keys.
- typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
-
- public:
-
- /// The map initialized const value set.
- MapValueSet(const Graph& _graph, Map& _map)
- : map(&_map), graph(&_graph) {}
-
- /// The const iterator of the set.
- typedef MapValueIterator<_Graph, _Item, _Map> Iterator;
- /// The const iterator of the set.
- typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- typedef typename Iterator::Reference Reference;
- typedef typename Iterator::Pointer Pointer;
- typedef typename ConstIterator::Reference ConstReference;
- typedef typename ConstIterator::Pointer ConstPointer;
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first invalid element.
- ConstIterator end() const {
- return ConstIterator(*map, ItemIt(INVALID));
- }
-
- /// It gives back the iterator pointed to the first element.
- Iterator begin() {
- return Iterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the iterator pointed to the first invalid element.
- Iterator end() {
- return Iterator(*map, ItemIt(INVALID));
- }
-
- protected:
-
- Map* map;
- const Graph * graph;
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef Iterator iterator;
- typedef ConstIterator const_iterator;
- typedef Reference reference;
- typedef ConstReference const_reference;
- typedef Pointer pointer;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
-
- };
-
- /** This class makes from a map an iteratable set
- * which contains all the values of the map.
- * The values can be modified.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map
- >
- class MapSet {
- public:
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
-
- public:
-
- /// The map initialized value set.
- MapSet(const Graph& _graph, Map& _map) : graph(&_graph), map(&_map) {}
-
- /// The const iterator of the set.
- typedef MapIterator<_Graph, _Item, _Map> Iterator;
- typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- typedef typename Iterator::Reference Reference;
- typedef typename Iterator::Pointer Pointer;
- typedef typename ConstIterator::Reference ConstReference;
- typedef typename ConstIterator::Pointer ConstPointer;
-
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first invalid element.
- ConstIterator end() const {
- return ConstIterator(*map, ItemIt(INVALID));
- }
-
- /// The iterator of the set.
-
- /// It gives back the iterator pointed to the first element.
- Iterator begin() {
- return Iterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the iterator pointed to the first invalid element.
- Iterator end() {
- return Iterator(*map, ItemIt(INVALID));
- }
-
- protected:
-
- const Graph* graph;
- Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef Iterator iterator;
- typedef ConstIterator const_iterator;
- typedef Reference reference;
- typedef ConstReference const_reference;
- typedef Pointer pointer;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
-
- };
-
- template <
- typename _Graph,
- typename _Item,
- typename _Map
- >
- class ConstMapSet {
-
- typedef _Graph Graph;
- typedef _Map Map;
-
- const Graph* graph;
- const Map* map;
-
- public:
-
- typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
-
-
- /// The map initialized value set.
- ConstMapSet(const Graph& _graph, const Map& _map)
- : graph(&_graph), map(&_map) {}
-
- /// The const iterator of the set.
- typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- typedef typename ConstIterator::Reference ConstReference;
- typedef typename ConstIterator::Pointer ConstPointer;
-
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first invalid element.
- ConstIterator end() const {
- return ConstIterator(*map, ItemIt(INVALID));
- }
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef ConstIterator const_iterator;
- typedef ConstReference const_reference;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
-
- };
-
- template <typename _Map>
- class IterableMapExtender : public _Map {
- public:
-
- typedef _Map Parent;
- typedef Parent Map;
- typedef typename Map::Graph Graph;
- typedef typename Map::Key Item;
- typedef typename Map::Value Value;
+ class ConstMapIt : public ItemSetTraits<Graph, Key>::ItemIt {
+ public:
- typedef MapSet<Graph, Item, Map> MapSet;
+ typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
- IterableMapExtender() : Parent() {}
+ typedef typename Map::Value Value;
- IterableMapExtender(const Graph& graph) : Parent(graph) {}
+ ConstMapIt(const Map& _map) : Parent(*_map.getGraph()), map(_map) {}
- IterableMapExtender(const Graph& graph, const Value& value)
- : Parent(graph, value) {}
+ typename MapTraits<Map>::ConstReturnValue operator*() const {
+ return map[*this];
+ }
+ protected:
+ const Map& map;
+ };
- MapSet mapSet() {
- return MapSet(*Parent::getGraph(), *this);
- }
-
- typedef ConstMapSet<Graph, Item, Map> ConstMapSet;
-
- ConstMapSet mapSet() const {
- return ConstMapSet(*Parent::getGraph(), *this);
- }
-
- typedef MapConstKeySet<Graph, Item> ConstKeySet;
-
- ConstKeySet keySet() const {
- return ConstKeySet(*Parent::getGraph());
- }
-
- typedef MapValueSet<Graph, Item, Map> ValueSet;
-
- ValueSet valueSet() {
- return ValueSet(*Parent::getGraph(), *this);
- }
-
- typedef MapConstValueSet<Graph, Item, Map> ConstValueSet;
-
- ConstValueSet valueSet() const {
- return ConstValueSet(*Parent::getGraph(), *this);
- }
+ class ItemIt : public ItemSetTraits<Graph, Key>::ItemIt {
+ public:
+
+ typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
+ ItemIt(Map& _map) : Parent(*_map.getGraph()) {}
+
+ };
};
- /// @}
-
}
#endif
Modified: hugo/trunk/lemon/bits/static_map.h
==============================================================================
--- hugo/trunk/lemon/bits/static_map.h (original)
+++ hugo/trunk/lemon/bits/static_map.h Wed Nov 16 19:58:10 2005
@@ -21,7 +21,7 @@
#include <iostream>
#include <lemon/utility.h>
-#include <lemon/bits/map_iterator.h>
+#include <lemon/bits/map_extender.h>
#include <lemon/bits/alteration_notifier.h>
#include <lemon/error.h>
#include <lemon/concept_check.h>
Modified: hugo/trunk/lemon/bits/vector_map.h
==============================================================================
--- hugo/trunk/lemon/bits/vector_map.h (original)
+++ hugo/trunk/lemon/bits/vector_map.h Wed Nov 16 19:58:10 2005
@@ -21,7 +21,7 @@
#include <algorithm>
#include <lemon/utility.h>
-#include <lemon/bits/map_iterator.h>
+#include <lemon/bits/map_extender.h>
#include <lemon/bits/alteration_notifier.h>
#include <lemon/concept_check.h>
#include <lemon/concept/maps.h>
Modified: hugo/trunk/lemon/iterable_maps.h
==============================================================================
--- hugo/trunk/lemon/iterable_maps.h (original)
+++ hugo/trunk/lemon/iterable_maps.h Wed Nov 16 19:58:10 2005
@@ -136,11 +136,9 @@
explicit IterableBoolMap(BaseMap &_m,bool init=false) : cref(_m)
{
sep=0;
- for(typename BaseMap::MapSet::iterator i=cref.mapSet().begin();
- i!=cref.mapSet().end();
- ++i) {
- i->second=sep;
- vals.push_back(i->first);
+ for(typename BaseMap::MapIt i(cref);i!=INVALID; ++i) {
+ i.set(sep);
+ vals.push_back(i);
sep++;
}
if(init) sep=0;
@@ -303,7 +301,8 @@
namespace _iterable_maps_bits {
template <typename Item>
struct IterableIntMapNode {
- IterableIntMapNode() : value(-1) {}
+ IterableIntMapNode() {}
+ IterableIntMapNode(int _value) : value(_value) {}
Item prev, next;
int value;
};
@@ -313,7 +312,13 @@
///
/// \brief Dynamic iterable integer map.
///
- /// \todo Document please
+ /// This class provides a special graph map type which can store
+ /// for each graph item(node, edge, etc.) an integer value. For each
+ /// non negative value it is possible to iterate on the keys which
+ /// mapped to the given value.
+ ///
+ /// \param _Graph The graph type.
+ /// \param _Item One of the graph's item type, the key of the map.
template <typename _Graph, typename _Item>
class IterableIntMap : protected ItemSetTraits<_Graph, _Item>
::template Map<_iterable_maps_bits::IterableIntMapNode<_Item> >::Parent {
@@ -322,11 +327,30 @@
::template Map<_iterable_maps_bits::IterableIntMapNode<_Item> >
::Parent Parent;
+ /// The key type
typedef _Item Key;
+ /// The value type
typedef int Value;
+ /// The graph type
typedef _Graph Graph;
- explicit IterableIntMap(const Graph& graph) : Parent(graph) {}
+ /// \brief Constructor of the Map.
+ ///
+ /// Constructor of the Map. It set all values -1.
+ explicit IterableIntMap(const Graph& graph)
+ : Parent(graph, _iterable_maps_bits::IterableIntMapNode<_Item>(-1)) {}
+
+ /// \brief Constructor of the Map with a given value.
+ ///
+ /// Constructor of the Map with a given value.
+ explicit IterableIntMap(const Graph& graph, int value)
+ : Parent(graph, _iterable_maps_bits::IterableIntMapNode<_Item>(value)) {
+ if (value >= 0) {
+ for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
+ lace(it);
+ }
+ }
+ }
private:
@@ -362,8 +386,13 @@
public:
+ /// Indicates that the map if reference map.
typedef True ReferenceMapTag;
+ /// \brief Refernce to the value of the map.
+ ///
+ /// This class is near to similar to the int type. It can
+ /// be converted to int and it has the same operators.
class Reference {
friend class IterableIntMap;
private:
@@ -447,33 +476,63 @@
Key _key;
IterableIntMap& _map;
};
-
+
+ /// The const reference type.
typedef const Value& ConstReference;
+ /// \brief Gives back the maximal value plus one.
+ ///
+ /// Gives back the maximal value plus one.
int size() const {
return (int)first.size();
}
+ /// \brief Set operation of the map.
+ ///
+ /// Set operation of the map.
void set(const Key& key, const Value& value) {
unlace(key);
Parent::operator[](key).value = value;
lace(key);
}
+ /// \brief Const subscript operator of the map.
+ ///
+ /// Const subscript operator of the map.
const Value& operator[](const Key& key) const {
return Parent::operator[](key).value;
}
+ /// \brief Subscript operator of the map.
+ ///
+ /// Subscript operator of the map.
Reference operator[](const Key& key) {
return Reference(*this, key);
}
+ /// \brief Iterator for the keys with the same value.
+ ///
+ /// Iterator for the keys with the same value. It works
+ /// like a graph item iterator in the map, it can be converted
+ /// the item type of the map, incremented with \c ++ operator, and
+ /// if the iterator leave the last valid item it will be equal to
+ /// \c INVALID.
class ItemIt : public _Item {
public:
typedef _Item Parent;
+ /// \brief Invalid constructor \& conversion.
+ ///
+ /// This constructor initializes the item to be invalid.
+ /// \sa Invalid for more details.
ItemIt(Invalid) : Parent(INVALID), _map(0) {}
+ /// \brief Creates an iterator with a value.
+ ///
+ /// Creates an iterator with a value. It iterates on the
+ /// keys which have the given value.
+ /// \param map The IterableIntMap
+ /// \param value The value
ItemIt(const IterableIntMap& map, int value) : _map(&map) {
if (value < 0 || value >= (int)_map->first.size()) {
Parent::operator=(INVALID);
@@ -482,6 +541,9 @@
}
}
+ /// \brief Increment operator.
+ ///
+ /// Increment Operator.
ItemIt& operator++() {
Parent::operator=(_map->IterableIntMap::Parent::
operator[](static_cast<Parent&>(*this)).next);
Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h (original)
+++ hugo/trunk/lemon/lp_base.h Wed Nov 16 19:58:10 2005
@@ -681,16 +681,13 @@
return s;
}
template<class T>
- typename enable_if<typename T::ValueSet::value_type::LpSolverCol,
+ typename enable_if<typename T::MapIt::Value::LpSolverCol,
int>::type
addColSet(T &t,dummy<2> = 2) {
- ///\bug <tt>return addColSet(t.valueSet());</tt> should also work.
int s=0;
- for(typename T::ValueSet::iterator i=t.valueSet().begin();
- i!=t.valueSet().end();
- ++i)
+ for(typename T::MapIt i(t); i!=INVALID; ++i)
{
- *i=addCol();
+ i.set(addCol());
s++;
}
return s;
@@ -787,16 +784,13 @@
return s;
}
template<class T>
- typename enable_if<typename T::ValueSet::value_type::LpSolverRow,
+ typename enable_if<typename T::MapIt::Value::LpSolverRow,
int>::type
addRowSet(T &t,dummy<2> = 2) {
- ///\bug <tt>return addRowSet(t.valueSet());</tt> should also work.
int s=0;
- for(typename T::ValueSet::iterator i=t.valueSet().begin();
- i!=t.valueSet().end();
- ++i)
+ for(typename T::MapIt i(t); i!=INVALID; ++i)
{
- *i=addRow();
+ i.set(addRow());
s++;
}
return s;
Copied: hugo/trunk/lemon/map_iterator.h (from r2345, /hugo/trunk/lemon/bits/map_iterator.h)
==============================================================================
--- /hugo/trunk/lemon/bits/map_iterator.h (original)
+++ hugo/trunk/lemon/map_iterator.h Wed Nov 16 19:58:10 2005
@@ -17,838 +17,129 @@
#ifndef LEMON_MAP_ITERATOR_H
#define LEMON_MAP_ITERATOR_H
-#include <iterator>
+#include <lemon/traits.h>
+#include <lemon/utility.h>
-#include <lemon/bits/extended_pair.h>
-#include <lemon/graph_utils.h>
-
-///\ingroup graphmapfactory
-///\file
-///\brief Iterators on the maps.
+/// \ingroup gutils
+/// \file
+/// \brief Iterators on the maps.
namespace lemon {
- /// \addtogroup graphmapfactory
- /// @{
-
- /** The base class all of the map iterators.
- * The class defines the typedefs of the iterators,
- * simple step functions and equality operators.
- */
-
- template <
- typename _Graph,
- typename _Item>
- class MapIteratorBase {
-
- protected:
-
- /// The key type of the iterator.
- typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
-
- ItemIt it;
-
- /// Default constructor.
- MapIteratorBase() {}
-
- /// ItemIt initialized MapIteratorBase constructor.
- MapIteratorBase(const ItemIt _it) : it(_it) {}
-
+ /// \ingroup gutils
+ ///
+ /// \brief Iterator for maps with possibility of changing values.
+ ///
+ /// Iterator for maps with possibility of changing values.
+ template <typename Graph, typename Item, typename Map>
+ class MapIt : public ItemSetTraits<Graph, Item>::ItemIt {
public:
-
- /// Stepping forward in the map.
- void increment() {
- ++it;
- }
-
- /// The equality operator of the map.
- bool operator==(const MapIteratorBase& _it) const {
- return _it.it == it;
- }
-
- /// The not-equality operator of the map.
- bool operator!=(const MapIteratorBase& _it) const {
- return !(*this == _it);
- }
- };
-
-
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapConstIterator;
-
- /** Compatible iterator with the stl maps' iterators.
- * It iterates on pairs of a key and a value.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapIterator : public MapIteratorBase<_Graph, _Item> {
-
- friend class MapConstIterator<_Graph, _Item, _Map>;
-
-
- public:
-
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Item Item;
- typedef _Map Map;
- typedef _Graph Graph;
-
- protected:
-
- typedef typename Parent::ItemIt ItemIt;
-
- typedef typename _Map::Value MapValue;
- typedef typename _Map::Reference MapReference;
+
+ typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
- public:
-
- /// The value type of the iterator.
- typedef extended_pair<Item, const Item&,
- MapValue, const MapValue&> Value;
-
- /// The reference type of the iterator.
- typedef extended_pair<const Item&, const Item&,
- MapReference, MapReference> Reference;
-
- /// Default constructor.
- MapIterator() {}
-
- /// Constructor to initalize the iterators returned
- /// by the begin() and end().
- MapIterator(Map& _map, const ItemIt& _it)
- : Parent(_it), map(&_map) {}
-
- /// Dereference operator for the iterator.
- Reference operator*() {
- return Reference(Parent::it, (*map)[Parent::it]);
- }
-
- /// The pointer type of the iterator.
- class Pointer {
- friend class MapIterator;
- protected:
- Reference data;
- Pointer(const Item& item, MapReference val)
- : data(item, val) {}
- public:
- Reference* operator->() {return &data;}
- };
-
- /// Arrow operator for the iterator.
- Pointer operator->() {
- return Pointer(Parent::it, (*map)[Parent::it]);
- }
-
- /// The pre increment operator of the iterator.
- MapIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapIterator operator++(int) {
- MapIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
-
- protected:
-
- Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef std::forward_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
- /** Compatible iterator with the stl maps' iterators.
- * It iterates on pairs of a key and a value.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapConstIterator : public MapIteratorBase<_Graph, _Item> {
-
- public:
-
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- typedef typename Parent::ItemIt ItemIt;
-
- typedef typename _Map::Value MapValue;
- typedef typename _Map::ConstReference MapReference;
+ typedef typename Map::Value Value;
- public:
-
- /// The value type of the iterator.
- typedef extended_pair<Item, const Item&,
- MapValue, const MapValue&> Value;
-
- /// The reference type of the iterator.
- typedef extended_pair<const Item&, const Item&,
- MapReference, MapReference> Reference;
-
- /// Default constructor.
- MapConstIterator() {}
-
- /// Constructor to initalize the iterators returned
- /// by the begin() and end().
- MapConstIterator(const Map& _map, const ItemIt& _it)
- : Parent(_it), map(&_map) {}
-
- /// Dereference operator for the iterator.
- Reference operator*() {
- return Reference(Parent::it, (*map)[Parent::it]);
- }
-
- /// The pointer type of the iterator.
- class Pointer {
- friend class MapConstIterator;
- protected:
- Reference data;
- Pointer(const Item& item, MapReference val)
- : data(item, val) {}
- public:
- Reference* operator->() {return &data;}
- };
-
- /// Arrow operator for the iterator.
- Pointer operator->() {
- return Pointer(Parent::it, ((*map)[Parent::it]));
- }
-
- /// The pre increment operator of the iterator.
- MapConstIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapConstIterator operator++(int) {
- MapConstIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
-
- protected:
- const Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef std::forward_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
- /** The class makes the ItemIt to an stl compatible iterator
- * with dereferencing operator.
- */
- template <
- typename _Graph,
- typename _Item>
- class MapConstKeyIterator : public MapIteratorBase<_Graph, _Item> {
-
- public:
-
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Graph Graph;
- typedef _Item Item;
-
- protected:
- /// The iterator to iterate on the keys.
- typedef typename Parent::ItemIt ItemIt;
-
- public:
-
- typedef Item Value;
- typedef const Item& Reference;
- typedef const Item* Pointer;
-
- /// Default constructor.
- MapConstKeyIterator() {}
-
- /// ItemIt initialized iterator.
- MapConstKeyIterator(const ItemIt& pit) : Parent(pit) {}
-
- /// The pre increment operator of the iterator.
- MapConstKeyIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapConstKeyIterator operator++(int) {
- MapConstKeyIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
-
- /// The dereferencing operator of the iterator.
- Item operator*() const {
- return static_cast<Item>(Parent::it);
- }
-
- public:
- // STL compatibility typedefs.
- typedef std::input_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapConstValueIterator;
-
- /** MapValueIterator creates an stl compatible iterator
- * for the values.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapValueIterator : public MapIteratorBase<_Graph, _Item> {
-
- friend class MapConstValueIterator<_Graph, _Item, _Map>;
-
- public:
-
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- /// The iterator to iterate on the keys.
- typedef typename Parent::ItemIt ItemIt;
-
- /// The value type of the iterator.
- typedef typename Map::Value MapValue;
- /// The reference type of the iterator.
- typedef typename Map::Reference MapReference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer MapPointer;
-
- public:
-
- typedef MapValue Value;
- typedef MapReference Reference;
- typedef MapPointer Pointer;
-
- /// Default constructor.
- MapValueIterator() {}
-
- /// Map and ItemIt initialized iterator.
- MapValueIterator(Map& _map, const ItemIt& _it)
- : Parent(_it), map(&_map) {}
-
-
- /// The pre increment operator of the iterator.
- MapValueIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapValueIterator operator++(int) {
- MapValueIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
-
- /// The dereferencing operator of the iterator.
- Reference operator*() const {
- return (*map)[Parent::it];
- }
-
- /// The arrow operator of the iterator.
- Pointer operator->() const {
- return &(operator*());
- }
-
- protected:
-
- Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef std::forward_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
- /** MapValueIterator creates an stl compatible iterator
- * for the values.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map>
- class MapConstValueIterator : public MapIteratorBase<_Graph, _Item> {
-
- public:
-
- /// The iterator base class.
- typedef MapIteratorBase<_Graph, _Item> Parent;
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- /// The iterator to iterate on the keys.
- typedef typename Parent::ItemIt ItemIt;
-
- /// The value type of the iterator.
- typedef typename Map::Value MapValue;
- /// The reference type of the iterator.
- typedef typename Map::ConstReference MapReference;
- /// The pointer type of the iterator.
- typedef typename Map::ConstPointer MapPointer;
-
- public:
-
- typedef MapValue Value;
- typedef MapReference Reference;
- typedef MapPointer Pointer;
-
- /// Default constructor.
- MapConstValueIterator() {}
-
- /// Map and ItemIt initialized iterator.
- MapConstValueIterator(const Map& _map, const ItemIt& _it)
- : Parent(_it), map(&_map) {}
-
-
- /// The pre increment operator of the iterator.
- MapConstValueIterator& operator++() {
- Parent::increment();
- return *this;
- }
-
- /// The post increment operator of the iterator.
- MapConstValueIterator operator++(int) {
- MapConstValueIterator tmp(*this);
- Parent::increment();
- return tmp;
- }
+ /// \brief Creates an iterator
+ ///
+ /// Creates an iterator for the map, which iterates on the
+ /// given graph item set.
+ MapIt(const Graph& _graph, Map& _map) : Parent(_graph), map(_map) {}
- /// The dereferencing operator of the iterator.
- Reference operator*() const {
- return (*map)[Parent::it];
+ /// \brief Gives back the map's value on the current position.
+ ///
+ /// Gives back the map's value on the current position.
+ typename MapTraits<Map>::ConstReturnValue operator*() const {
+ return map[*this];
}
- /// The arrow operator of the iterator.
- Pointer operator->() const {
- return &(operator*());
+ /// \brief Gives back a reference to the map's value.
+ ///
+ /// Gives back a reference to the map's value on the current position.
+ typename MapTraits<Map>::ReturnValue operator*() {
+ return map[*this];
}
-
- protected:
-
- const Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef std::forward_iterator_tag iterator_category;
- typedef int difference_type;
- typedef Value value_type;
- typedef Reference reference;
- typedef Pointer pointer;
- };
-
-
- /** This class makes from a map an iteratable set
- * which contains all the keys of the map.
- */
- template <typename _Graph, typename _Item>
- class MapConstKeySet {
-
- public:
-
- typedef _Graph Graph;
- /// The key type of the iterator.
- typedef _Item Item;
- /// The iterator to iterate on the keys.
-
- protected:
-
- typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
-
- public:
-
- /// The map initialized const key set.
- MapConstKeySet(const Graph& _graph) : graph(&_graph) {}
-
- /// The const iterator of the set.
- typedef MapConstKeyIterator<_Graph, _Item> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- /// The reference type of the iterator.
- typedef typename ConstIterator::Reference ConstReference;
- /// The pointer type of the iterator.
- typedef typename ConstIterator::Pointer ConstPointer;
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first ivalid element.
- ConstIterator end() const {
- return ConstIterator(ItemIt(INVALID));
+
+ /// \brief Sets the value on the current position
+ ///
+ /// Sets the value on the current position.
+ void set(const Value& value) {
+ map.set(*this, value);
}
-
+
protected:
-
- const Graph* graph;
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef ConstIterator const_iterator;
- typedef ConstReference const_reference;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
+ Map& map;
+
};
- /** This class makes from a map an iteratable set
- * which contains all the values of the map.
- * The values cannot be modified.
- */
- template <typename _Graph, typename _Item, typename _Map>
- class MapConstValueSet {
-
+ /// \ingroup gutils
+ ///
+ /// \brief Iterator for maps with possibility of getting values.
+ ///
+ /// Iterator for maps with possibility of getting values.
+ template <typename Graph, typename Item, typename Map>
+ class ConstMapIt : public ItemSetTraits<Graph, Item>::ItemIt {
public:
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- /// The iterator to iterate on the keys.
- typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
-
- public:
-
- /// The map initialized const value set.
- MapConstValueSet(const Graph& _graph, const Map& _map)
- : graph(&_graph), map(&_map) {}
-
- /// The const iterator of the set.
- typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- typedef typename ConstIterator::Reference ConstReference;
- typedef typename ConstIterator::Pointer ConstPointer;
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first invalid element.
- ConstIterator end() const {
- return ConstIterator(*map, ItemIt(INVALID));
- }
+ typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
- protected:
+ typedef typename Map::Value Value;
- const Map* map;
- const Graph * graph;
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef ConstIterator const_iterator;
- typedef ConstReference const_reference;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
- };
-
-
- /** This class makes from a map an iteratable set
- * which contains all the values of the map.
- * The values can be modified.
- */
- template <typename _Graph, typename _Item, typename _Map>
- class MapValueSet {
-
- public:
+ /// \brief Creates an iterator
+ ///
+ /// Creates an iterator for the map, which iterates on the
+ /// given graph item set.
+ ConstMapIt(const Graph& _graph, const Map& _map)
+ : Parent(_graph), map(_map) {}
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- /// The iterator to iterate on the keys.
- typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
-
- public:
-
- /// The map initialized const value set.
- MapValueSet(const Graph& _graph, Map& _map)
- : map(&_map), graph(&_graph) {}
-
- /// The const iterator of the set.
- typedef MapValueIterator<_Graph, _Item, _Map> Iterator;
- /// The const iterator of the set.
- typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- typedef typename Iterator::Reference Reference;
- typedef typename Iterator::Pointer Pointer;
- typedef typename ConstIterator::Reference ConstReference;
- typedef typename ConstIterator::Pointer ConstPointer;
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first invalid element.
- ConstIterator end() const {
- return ConstIterator(*map, ItemIt(INVALID));
+ /// \brief Gives back the map's value on the current position.
+ ///
+ /// Gives back the map's value on the current position.
+ typename MapTraits<Map>::ConstReturnValue operator*() const {
+ return map[*this];
}
-
- /// It gives back the iterator pointed to the first element.
- Iterator begin() {
- return Iterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the iterator pointed to the first invalid element.
- Iterator end() {
- return Iterator(*map, ItemIt(INVALID));
- }
-
- protected:
- Map* map;
- const Graph * graph;
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef Iterator iterator;
- typedef ConstIterator const_iterator;
- typedef Reference reference;
- typedef ConstReference const_reference;
- typedef Pointer pointer;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
-
- };
-
- /** This class makes from a map an iteratable set
- * which contains all the values of the map.
- * The values can be modified.
- */
- template <
- typename _Graph,
- typename _Item,
- typename _Map
- >
- class MapSet {
- public:
-
- typedef _Graph Graph;
- typedef _Item Item;
- typedef _Map Map;
-
- protected:
-
- typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
-
- public:
-
- /// The map initialized value set.
- MapSet(const Graph& _graph, Map& _map) : graph(&_graph), map(&_map) {}
-
- /// The const iterator of the set.
- typedef MapIterator<_Graph, _Item, _Map> Iterator;
- typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
-
- typedef typename ConstIterator::Value Value;
- typedef typename Iterator::Reference Reference;
- typedef typename Iterator::Pointer Pointer;
- typedef typename ConstIterator::Reference ConstReference;
- typedef typename ConstIterator::Pointer ConstPointer;
-
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first invalid element.
- ConstIterator end() const {
- return ConstIterator(*map, ItemIt(INVALID));
- }
-
- /// The iterator of the set.
-
- /// It gives back the iterator pointed to the first element.
- Iterator begin() {
- return Iterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the iterator pointed to the first invalid element.
- Iterator end() {
- return Iterator(*map, ItemIt(INVALID));
- }
-
protected:
-
- const Graph* graph;
- Map* map;
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef Iterator iterator;
- typedef ConstIterator const_iterator;
- typedef Reference reference;
- typedef ConstReference const_reference;
- typedef Pointer pointer;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
-
+ const Map& map;
};
- template <
- typename _Graph,
- typename _Item,
- typename _Map
- >
- class ConstMapSet {
-
- typedef _Graph Graph;
- typedef _Map Map;
-
- const Graph* graph;
- const Map* map;
-
- public:
-
- typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
-
-
- /// The map initialized value set.
- ConstMapSet(const Graph& _graph, const Map& _map)
- : graph(&_graph), map(&_map) {}
-
- /// The const iterator of the set.
- typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
- typedef typename ConstIterator::Value Value;
- typedef typename ConstIterator::Reference ConstReference;
- typedef typename ConstIterator::Pointer ConstPointer;
-
-
- /// It gives back the const iterator pointed to the first element.
- ConstIterator begin() const {
- return ConstIterator(*map, ItemIt(*graph));
- }
-
- /// It gives back the const iterator pointed to the first invalid element.
- ConstIterator end() const {
- return ConstIterator(*map, ItemIt(INVALID));
- }
-
- public:
- // STL compatibility typedefs.
- typedef Value value_type;
- typedef ConstIterator const_iterator;
- typedef ConstReference const_reference;
- typedef ConstPointer const_pointer;
- typedef int difference_type;
-
- };
-
- template <typename _Map>
- class IterableMapExtender : public _Map {
+ /// \ingroup gutils
+ ///
+ /// \brief Iterator for maps which filters items by the values.
+ ///
+ /// Iterator for maps which gives back only that items which mapped
+ /// to an given value.
+ template <typename Graph, typename Item, typename Map>
+ class FilterMapIt
+ : public ItemSetTraits<Graph, Item>::ItemIt {
public:
+
+ typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
- typedef _Map Parent;
- typedef Parent Map;
- typedef typename Map::Graph Graph;
- typedef typename Map::Key Item;
typedef typename Map::Value Value;
-
- typedef MapSet<Graph, Item, Map> MapSet;
-
- IterableMapExtender() : Parent() {}
-
- IterableMapExtender(const Graph& graph) : Parent(graph) {}
-
- IterableMapExtender(const Graph& graph, const Value& value)
- : Parent(graph, value) {}
-
- MapSet mapSet() {
- return MapSet(*Parent::getGraph(), *this);
- }
-
- typedef ConstMapSet<Graph, Item, Map> ConstMapSet;
-
- ConstMapSet mapSet() const {
- return ConstMapSet(*Parent::getGraph(), *this);
- }
-
- typedef MapConstKeySet<Graph, Item> ConstKeySet;
-
- ConstKeySet keySet() const {
- return ConstKeySet(*Parent::getGraph());
- }
-
- typedef MapValueSet<Graph, Item, Map> ValueSet;
-
- ValueSet valueSet() {
- return ValueSet(*Parent::getGraph(), *this);
- }
-
- typedef MapConstValueSet<Graph, Item, Map> ConstValueSet;
-
- ConstValueSet valueSet() const {
- return ConstValueSet(*Parent::getGraph(), *this);
+
+ /// \brief Creates an iterator
+ ///
+ /// Creates an iterator for the map, which iterates on the
+ /// given graph item set and filters all items which mapped value
+ /// differ from \c _value.
+ FilterMapIt(const Graph& _graph, const Map& _map, const Value& _value)
+ : Parent(_graph), map(_map), value(_value) {}
+
+ /// \brief Increment operator
+ ///
+ /// Skips items which has not the given value.
+ FilterMapIt& operator++() {
+ Parent::operator++();
+ while (*this != INVALID && map[*this] != value) Parent::operator++();
}
-
+
+ protected:
+ const Map& map;
+ Value value;
};
- /// @}
-
+
}
#endif
More information about the Lemon-commits
mailing list