First version of iterable maps.
authordeba
Fri, 25 Mar 2005 23:31:57 +0000
changeset 1267a93f94dbe3d3
parent 1266 74d616d081f0
child 1268 a1f9a4d4ea0c
First version of iterable maps.
src/lemon/array_map.h
src/lemon/default_map.h
src/lemon/graph_utils.h
src/lemon/map_iterator.h
src/lemon/map_utils.h
src/lemon/vector_map.h
src/work/deba/iterator_test.cpp
src/work/deba/test.cpp
     1.1 --- a/src/lemon/array_map.h	Fri Mar 25 22:11:28 2005 +0000
     1.2 +++ b/src/lemon/array_map.h	Fri Mar 25 23:31:57 2005 +0000
     1.3 @@ -18,6 +18,7 @@
     1.4  #define LEMON_ARRAY_MAP_H
     1.5  
     1.6  #include <memory>
     1.7 +#include <lemon/map_iterator.h>
     1.8  
     1.9  ///\ingroup graphmaps
    1.10  ///\file
    1.11 @@ -35,16 +36,16 @@
    1.12     *  the map. This map factory uses the allocators to implement 
    1.13     *  the container functionality.
    1.14     *
    1.15 -   *  The template parameter is the MapRegistry that the maps
    1.16 +   *  The template parameter is the AlterationNotifier that the maps
    1.17     *  will belong to and the Value.
    1.18     */
    1.19  
    1.20    template <typename _Graph, 
    1.21  	    typename _Item,
    1.22 -	    typename _ItemIt,
    1.23  	    typename _Value>
    1.24    class ArrayMap : public AlterationNotifier<_Item>::ObserverBase {
    1.25  
    1.26 +    typedef _Item Item;
    1.27    public:
    1.28  		
    1.29      /// The graph type of the maps. 
    1.30 @@ -54,29 +55,11 @@
    1.31  
    1.32      typedef AlterationNotifier<_Item> Registry;
    1.33  
    1.34 -  private:
    1.35 -    /// The iterator to iterate on the keys.
    1.36 -    typedef _ItemIt KeyIt;
    1.37 -
    1.38      /// The MapBase of the Map which imlements the core regisitry function.
    1.39      typedef typename Registry::ObserverBase Parent;
    1.40  		
    1.41 -    
    1.42 -  public:
    1.43 -
    1.44      /// The value type of the map.
    1.45      typedef _Value Value;
    1.46 -    /// The reference type of the map;
    1.47 -    typedef Value& Reference;
    1.48 -    /// The pointer type of the map;
    1.49 -    typedef Value* Pointer;
    1.50 -
    1.51 -    /// The const value type of the map.
    1.52 -    typedef const Value ConstValue;
    1.53 -    /// The const reference type of the map;
    1.54 -    typedef const Value& ConstReference;
    1.55 -    /// The pointer type of the map;
    1.56 -    typedef const Value* ConstPointer;
    1.57  
    1.58  
    1.59    private:
    1.60 @@ -88,9 +71,10 @@
    1.61      /** Graph and Registry initialized map constructor.
    1.62       */
    1.63      ArrayMap(const Graph& _g) : graph(&_g) {
    1.64 -      attach(_g.getNotifier(_Item()));
    1.65 +      Item it;
    1.66 +      attach(_g.getNotifier(Item()));
    1.67        allocate_memory();
    1.68 -      for (KeyIt it(*graph); it != INVALID; ++it) {
    1.69 +      for (graph->first(it); it != INVALID; graph->next(it)) {
    1.70  	int id = graph->id(it);;
    1.71  	allocator.construct(&(values[id]), Value());
    1.72        }								
    1.73 @@ -101,9 +85,10 @@
    1.74      /// It constrates a map and initialize all of the the map. 
    1.75  
    1.76      ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) {
    1.77 +      Item it;
    1.78        attach(_g.getNotifier(_Item()));
    1.79        allocate_memory();
    1.80 -      for (KeyIt it(*graph); it != INVALID; ++it) {
    1.81 +      for (graph->first(it); it != INVALID; graph->next(it)) {
    1.82  	int id = graph->id(it);;
    1.83  	allocator.construct(&(values[id]), _v);
    1.84        }								
    1.85 @@ -118,7 +103,8 @@
    1.86        capacity = copy.capacity;
    1.87        if (capacity == 0) return;
    1.88        values = allocator.allocate(capacity);
    1.89 -      for (KeyIt it(*graph); it != INVALID; ++it) {
    1.90 +      Item it;
    1.91 +      for (graph->first(it); it != INVALID; graph->next(it)) {
    1.92  	int id = graph->id(it);;
    1.93  	allocator.construct(&(values[id]), copy.values[id]);
    1.94        }
    1.95 @@ -146,7 +132,8 @@
    1.96  	values = allocator.allocate(capacity);      
    1.97        }
    1.98  
    1.99 -      for (KeyIt it(*graph); it != INVALID; ++it) {
   1.100 +      Item it;
   1.101 +      for (graph->first(it); it != INVALID; graph->next(it)) {
   1.102  	int id = graph->id(it);;
   1.103  	allocator.construct(&(values[id]), copy.values[id]);
   1.104        }
   1.105 @@ -168,7 +155,7 @@
   1.106       * The subscript operator. The map can be subscripted by the
   1.107       * actual keys of the graph. 
   1.108       */
   1.109 -    Reference operator[](const Key& key) {
   1.110 +    Value& operator[](const Key& key) {
   1.111        int id = graph->id(key);
   1.112        return values[id];
   1.113      } 
   1.114 @@ -177,7 +164,7 @@
   1.115       * The const subscript operator. The map can be subscripted by the
   1.116       * actual keys of the graph. 
   1.117       */
   1.118 -    ConstReference operator[](const Key& key) const {
   1.119 +    const Value& operator[](const Key& key) const {
   1.120        int id = graph->id(key);
   1.121        return values[id];
   1.122      }
   1.123 @@ -199,7 +186,8 @@
   1.124  	  new_capacity <<= 1;
   1.125  	}
   1.126  	Value* new_values = allocator.allocate(new_capacity);
   1.127 -	for (KeyIt it(*graph); it != INVALID; ++it) {
   1.128 +	Item it;
   1.129 +	for (graph->first(it); it != INVALID; graph->next(it)) {
   1.130  	  int jd = graph->id(it);;
   1.131  	  if (id != jd) {
   1.132  	    allocator.construct(&(new_values[jd]), values[jd]);
   1.133 @@ -222,7 +210,8 @@
   1.134  
   1.135      void build() {
   1.136        allocate_memory();
   1.137 -      for (KeyIt it(*graph); it != INVALID; ++it) {
   1.138 +      Item it;
   1.139 +      for (graph->first(it); it != INVALID; graph->next(it)) {
   1.140  	int id = graph->id(it);;
   1.141  	allocator.construct(&(values[id]), Value());
   1.142        }								
   1.143 @@ -230,7 +219,8 @@
   1.144  
   1.145      void clear() {	
   1.146        if (capacity != 0) {
   1.147 -	for (KeyIt it(*graph); it != INVALID; ++it) {
   1.148 +	Item it;
   1.149 +	for (graph->first(it); it != INVALID; graph->next(it)) {
   1.150  	  int id = graph->id(it);;
   1.151  	  allocator.destroy(&(values[id]));
   1.152  	}								
   1.153 @@ -313,18 +303,6 @@
   1.154      Value* values;
   1.155      Allocator allocator;
   1.156  
   1.157 -  public:
   1.158 -//     // STL  compatibility typedefs.
   1.159 -//     typedef Iterator iterator;
   1.160 -//     typedef ConstIterator const_iterator;
   1.161 -//     typedef typename Iterator::PairValue value_type;
   1.162 -//     typedef typename Iterator::Key key_type;
   1.163 -//     typedef typename Iterator::Value data_type;
   1.164 -//     typedef typename Iterator::PairReference reference;
   1.165 -//     typedef typename Iterator::PairPointer pointer;
   1.166 -//     typedef typename ConstIterator::PairReference const_reference;
   1.167 -//     typedef typename ConstIterator::PairPointer const_pointer;
   1.168 -//     typedef int difference_type;		
   1.169    };		
   1.170  
   1.171    template <typename _Base> 
   1.172 @@ -345,14 +323,15 @@
   1.173      
   1.174  
   1.175      template <typename _Value>
   1.176 -    class NodeMap : public ArrayMap<Graph, Node, NodeIt, _Value> {
   1.177 +    class NodeMap 
   1.178 +      : public IterableMapExtender<ArrayMap<Graph, Node, _Value> > {
   1.179      public:
   1.180        typedef ArrayMappableGraphExtender<_Base> Graph;
   1.181  
   1.182        typedef typename Graph::Node Node;
   1.183        typedef typename Graph::NodeIt NodeIt;
   1.184  
   1.185 -      typedef ArrayMap<Graph, Node, NodeIt, _Value> Parent;
   1.186 +      typedef IterableMapExtender<ArrayMap<Graph, Node, _Value> > Parent;
   1.187  
   1.188        //typedef typename Parent::Graph Graph;
   1.189        typedef typename Parent::Value Value;
   1.190 @@ -365,14 +344,15 @@
   1.191      };
   1.192  
   1.193      template <typename _Value>
   1.194 -    class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, _Value> {
   1.195 +    class EdgeMap 
   1.196 +      : public IterableMapExtender<ArrayMap<Graph, Edge, _Value> > {
   1.197      public:
   1.198        typedef ArrayMappableGraphExtender<_Base> Graph;
   1.199  
   1.200        typedef typename Graph::Edge Edge;
   1.201        typedef typename Graph::EdgeIt EdgeIt;
   1.202  
   1.203 -      typedef ArrayMap<Graph, Edge, EdgeIt, _Value> Parent;
   1.204 +      typedef IterableMapExtender<ArrayMap<Graph, Edge, _Value> > Parent;
   1.205  
   1.206        //typedef typename Parent::Graph Graph;
   1.207        typedef typename Parent::Value Value;
     2.1 --- a/src/lemon/default_map.h	Fri Mar 25 22:11:28 2005 +0000
     2.2 +++ b/src/lemon/default_map.h	Fri Mar 25 23:31:57 2005 +0000
     2.3 @@ -42,66 +42,66 @@
     2.4  
     2.5  
     2.6  
     2.7 -  template <typename _Graph, typename _Item, typename _ItemIt, typename _Value>
     2.8 +  template <typename _Graph, typename _Item, typename _Value>
     2.9    struct DefaultMapSelector {
    2.10 -    typedef ArrayMap<_Graph, _Item, _ItemIt, _Value> Map;
    2.11 +    typedef ArrayMap<_Graph, _Item, _Value> Map;
    2.12    };
    2.13  
    2.14    // bool
    2.15 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.16 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, bool> {
    2.17 +  template <typename _Graph, typename _Item>
    2.18 +  struct DefaultMapSelector<_Graph, _Item, bool> {
    2.19      typedef VectorMap<_Graph, _Item, bool> Map;
    2.20    };
    2.21  
    2.22    // char
    2.23 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.24 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, char> {
    2.25 +  template <typename _Graph, typename _Item>
    2.26 +  struct DefaultMapSelector<_Graph, _Item, char> {
    2.27      typedef VectorMap<_Graph, _Item, char> Map;
    2.28    };
    2.29  
    2.30 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.31 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed char> {
    2.32 +  template <typename _Graph, typename _Item>
    2.33 +  struct DefaultMapSelector<_Graph, _Item, signed char> {
    2.34      typedef VectorMap<_Graph, _Item, signed char> Map;
    2.35    };
    2.36  
    2.37 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.38 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned char> {
    2.39 +  template <typename _Graph, typename _Item>
    2.40 +  struct DefaultMapSelector<_Graph, _Item, unsigned char> {
    2.41      typedef VectorMap<_Graph, _Item, unsigned char> Map;
    2.42    };
    2.43  
    2.44  
    2.45    // int
    2.46 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.47 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed int> {
    2.48 +  template <typename _Graph, typename _Item>
    2.49 +  struct DefaultMapSelector<_Graph, _Item, signed int> {
    2.50      typedef VectorMap<_Graph, _Item, signed int> Map;
    2.51    };
    2.52  
    2.53 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.54 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned int> {
    2.55 +  template <typename _Graph, typename _Item>
    2.56 +  struct DefaultMapSelector<_Graph, _Item, unsigned int> {
    2.57      typedef VectorMap<_Graph, _Item, unsigned int> Map;
    2.58    };
    2.59  
    2.60  
    2.61    // short
    2.62 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.63 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed short> {
    2.64 +  template <typename _Graph, typename _Item>
    2.65 +  struct DefaultMapSelector<_Graph, _Item, signed short> {
    2.66      typedef VectorMap<_Graph, _Item, signed short> Map;
    2.67    };
    2.68  
    2.69 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.70 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned short> {
    2.71 +  template <typename _Graph, typename _Item>
    2.72 +  struct DefaultMapSelector<_Graph, _Item, unsigned short> {
    2.73      typedef VectorMap<_Graph, _Item, unsigned short> Map;
    2.74    };
    2.75  
    2.76  
    2.77    // long
    2.78 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.79 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed long> {
    2.80 +  template <typename _Graph, typename _Item>
    2.81 +  struct DefaultMapSelector<_Graph, _Item, signed long> {
    2.82      typedef VectorMap<_Graph, _Item, signed long> Map;
    2.83    };
    2.84  
    2.85 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.86 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned long> {
    2.87 +  template <typename _Graph, typename _Item>
    2.88 +  struct DefaultMapSelector<_Graph, _Item, unsigned long> {
    2.89      typedef VectorMap<_Graph, _Item, unsigned long> Map;
    2.90    };
    2.91  
    2.92 @@ -109,42 +109,43 @@
    2.93  
    2.94  
    2.95    // float
    2.96 -  template <typename _Graph, typename _Item, typename _ItemIt>
    2.97 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, float> {
    2.98 +  template <typename _Graph, typename _Item>
    2.99 +  struct DefaultMapSelector<_Graph, _Item, float> {
   2.100      typedef VectorMap<_Graph, _Item, float> Map;
   2.101    };
   2.102  
   2.103  
   2.104    // double
   2.105 -  template <typename _Graph, typename _Item, typename _ItemIt>
   2.106 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, double> {
   2.107 +  template <typename _Graph, typename _Item>
   2.108 +  struct DefaultMapSelector<_Graph, _Item, double> {
   2.109      typedef VectorMap<_Graph, _Item,  double> Map;
   2.110    };
   2.111  
   2.112  
   2.113    // long double
   2.114 -  template <typename _Graph, typename _Item, typename _ItemIt>
   2.115 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, long double> {
   2.116 +  template <typename _Graph, typename _Item>
   2.117 +  struct DefaultMapSelector<_Graph, _Item, long double> {
   2.118      typedef VectorMap<_Graph, _Item, long double> Map;
   2.119    };
   2.120  
   2.121  
   2.122    // pointer
   2.123 -  template <typename _Graph, typename _Item, typename _ItemIt, typename _Ptr>
   2.124 -  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _Ptr*> {
   2.125 +  template <typename _Graph, typename _Item, typename _Ptr>
   2.126 +  struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
   2.127      typedef VectorMap<_Graph, _Item, _Ptr*> Map;
   2.128    };
   2.129  
   2.130  
   2.131  
   2.132 -  template <typename _Graph, 
   2.133 -	    typename _Item,
   2.134 -	    typename _ItemIt,
   2.135 -	    typename _Value>
   2.136 -  class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map {
   2.137 +  template <
   2.138 +    typename _Graph, 
   2.139 +    typename _Item,
   2.140 +    typename _Value>
   2.141 +  class DefaultMap 
   2.142 +    : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
   2.143    public:
   2.144 -    typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map Parent;
   2.145 -    typedef DefaultMap<_Graph, _Item, _ItemIt, _Value> Map;
   2.146 +    typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
   2.147 +    typedef DefaultMap<_Graph, _Item, _Value> Map;
   2.148      
   2.149      typedef typename Parent::Graph Graph;
   2.150      typedef typename Parent::Value Value;
   2.151 @@ -170,10 +171,11 @@
   2.152  
   2.153      
   2.154      template <typename _Value>
   2.155 -    class NodeMap : public DefaultMap<Graph, Node, NodeIt, _Value> {
   2.156 +    class NodeMap 
   2.157 +      : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
   2.158      public:
   2.159        typedef DefaultMappableGraphExtender Graph;
   2.160 -      typedef DefaultMap<Graph, Node, NodeIt, _Value> Parent;
   2.161 +      typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
   2.162  
   2.163        NodeMap(const Graph& _g) 
   2.164  	: Parent(_g) {}
   2.165 @@ -182,10 +184,11 @@
   2.166      };
   2.167  
   2.168      template <typename _Value>
   2.169 -    class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, _Value> {
   2.170 +    class EdgeMap 
   2.171 +      : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
   2.172      public:
   2.173        typedef DefaultMappableGraphExtender Graph;
   2.174 -      typedef DefaultMap<Graph, Edge, EdgeIt, _Value> Parent;
   2.175 +      typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
   2.176  
   2.177        EdgeMap(const Graph& _g) 
   2.178  	: Parent(_g) {}
   2.179 @@ -204,14 +207,14 @@
   2.180      typedef DefaultMappableGraphExtender<_Base> Parent;
   2.181  
   2.182      typedef typename Parent::UndirEdge UndirEdge;
   2.183 -    typedef typename Parent::UndirEdgeIt UndirEdgeIt;
   2.184  
   2.185      template <typename _Value>
   2.186 -    class UndirEdgeMap :
   2.187 -      public DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> {
   2.188 +    class UndirEdgeMap 
   2.189 +      : public IterableMapExtender<DefaultMap<Graph, UndirEdge, _Value> > {
   2.190      public:
   2.191        typedef MappableUndirGraphExtender Graph;
   2.192 -      typedef DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> Parent;
   2.193 +      typedef IterableMapExtender<
   2.194 +	DefaultMap<Graph, UndirEdge, _Value> > Parent;
   2.195  
   2.196        UndirEdgeMap(const Graph& _g) 
   2.197  	: Parent(_g) {}
     3.1 --- a/src/lemon/graph_utils.h	Fri Mar 25 22:11:28 2005 +0000
     3.2 +++ b/src/lemon/graph_utils.h	Fri Mar 25 23:31:57 2005 +0000
     3.3 @@ -21,7 +21,6 @@
     3.4  
     3.5  #include <lemon/invalid.h>
     3.6  #include <lemon/utility.h>
     3.7 -#include <lemon/map_utils.h>
     3.8  
     3.9  ///\ingroup gutils
    3.10  ///\file
    3.11 @@ -34,8 +33,8 @@
    3.12  
    3.13  namespace lemon {
    3.14  
    3.15 -/// \addtogroup gutils
    3.16 -/// @{
    3.17 +  /// \addtogroup gutils
    3.18 +  /// @{
    3.19  
    3.20    /// \brief Function to count the items in the graph.
    3.21    ///
    3.22 @@ -160,8 +159,8 @@
    3.23    /// \bug Untested ...
    3.24    template <typename Graph>
    3.25    typename Graph::Edge findEdge(const Graph &g,
    3.26 -		typename Graph::Node u, typename Graph::Node v,
    3.27 -		typename Graph::Edge prev = INVALID) 
    3.28 +				typename Graph::Node u, typename Graph::Node v,
    3.29 +				typename Graph::Edge prev = INVALID) 
    3.30    {
    3.31      typename Graph::OutEdgeIt e(g,prev);
    3.32      //    if(prev==INVALID) g.first(e,u);
    3.33 @@ -225,46 +224,51 @@
    3.34      edgeCopy(_d, _s, _nb, _eb);
    3.35    }
    3.36   
    3.37 -   template <
    3.38 +  template <
    3.39      typename _DestinationGraph, 
    3.40      typename _SourceGraph, 
    3.41      typename _NodeBijection 
    3.42      =typename _SourceGraph::template NodeMap<typename _DestinationGraph::Node>,
    3.43      typename _EdgeBijection 
    3.44 -    =typename _SourceGraph::template EdgeMap<typename _DestinationGraph::Edge>
    3.45 -   >
    3.46 -   class GraphCopy {
    3.47 -   public:
    3.48 +    = typename _SourceGraph::template EdgeMap<typename _DestinationGraph::Edge>
    3.49 +  >
    3.50 +  class GraphCopy {
    3.51 +  public:
    3.52 +    
    3.53 +    typedef _DestinationGraph DestinationGraph;
    3.54 +    typedef _SourceGraph SourceGraph;
    3.55  
    3.56 -     typedef _DestinationGraph DestinationGraph;
    3.57 -     typedef _SourceGraph SourceGraph;
    3.58 +    typedef _NodeBijection NodeBijection;
    3.59 +    typedef _EdgeBijection EdgeBijection;
    3.60 +    
    3.61 +  protected:          
    3.62 +    
    3.63 +    NodeBijection node_bijection;
    3.64 +    EdgeBijection edge_bijection;     
    3.65  
    3.66 -     typedef _NodeBijection NodeBijection;
    3.67 -     typedef _EdgeBijection EdgeBijection;
    3.68 +  public:
    3.69 +     
    3.70 +    GraphCopy(DestinationGraph& _d, const SourceGraph& _s) {
    3.71 +      copyGraph(_d, _s, node_bijection, edge_bijection);
    3.72 +    }
    3.73 +    
    3.74 +    const NodeBijection& getNodeBijection() const {
    3.75 +      return node_bijection;
    3.76 +    }
    3.77  
    3.78 -   protected:          
    3.79 +    const EdgeBijection& getEdgeBijection() const {
    3.80 +      return edge_bijection;
    3.81 +    }
    3.82 +     
    3.83 +  };
    3.84  
    3.85 -     NodeBijection node_bijection;
    3.86 -     EdgeBijection edge_bijection;     
    3.87  
    3.88 -   public:
    3.89 -     
    3.90 -     GraphCopy(DestinationGraph& _d, const SourceGraph& _s) {
    3.91 -       copyGraph(_d, _s, node_bijection, edge_bijection);
    3.92 -     }
    3.93 -
    3.94 -     const NodeBijection& getNodeBijection() const {
    3.95 -       return node_bijection;
    3.96 -     }
    3.97 -
    3.98 -     const EdgeBijection& getEdgeBijection() const {
    3.99 -       return edge_bijection;
   3.100 -     }
   3.101 -     
   3.102 -   };
   3.103 +  template <typename _Graph, typename _Item>
   3.104 +  class ItemSetTraits {
   3.105 +  };
   3.106    
   3.107    template <typename _Graph>
   3.108 -  class GraphNodeSet {
   3.109 +  class ItemSetTraits<_Graph, typename _Graph::Node> {
   3.110    public:
   3.111      
   3.112      typedef _Graph Graph;
   3.113 @@ -283,14 +287,10 @@
   3.114  	: Parent(_graph, _value) {}
   3.115      };
   3.116  
   3.117 -    typedef IdMap<Graph, Item> IdMap;
   3.118 -    
   3.119 -  private:
   3.120 -    Graph* graph;
   3.121    };
   3.122  
   3.123    template <typename _Graph>
   3.124 -  class GraphEdgeSet {
   3.125 +  class ItemSetTraits<_Graph, typename _Graph::Edge> {
   3.126    public:
   3.127      
   3.128      typedef _Graph Graph;
   3.129 @@ -309,12 +309,29 @@
   3.130  	: Parent(_graph, _value) {}
   3.131      };
   3.132  
   3.133 -    typedef IdMap<Graph, Item> IdMap;
   3.134 -    
   3.135 -  private:
   3.136 -    Graph* graph;
   3.137    };
   3.138  
   3.139 +  template <typename _Graph>
   3.140 +  class ItemSetTraits<_Graph, typename _Graph::UndirEdge> {
   3.141 +  public:
   3.142 +    
   3.143 +    typedef _Graph Graph;
   3.144 +
   3.145 +    typedef typename Graph::UndirEdge Item;
   3.146 +    typedef typename Graph::UndirEdgeIt ItemIt;
   3.147 +
   3.148 +    template <typename _Value>
   3.149 +    class Map : public Graph::template UndirEdgeMap<_Value> {
   3.150 +    public:
   3.151 +      typedef typename Graph::template UndirEdgeMap<_Value> Parent; 
   3.152 +      typedef typename Parent::Value Value;
   3.153 +
   3.154 +      Map(const Graph& _graph) : Parent(_graph) {}
   3.155 +      Map(const Graph& _graph, const Value& _value) 
   3.156 +	: Parent(_graph, _value) {}
   3.157 +    };
   3.158 +
   3.159 +  };
   3.160  
   3.161    /// @}
   3.162    
     4.1 --- a/src/lemon/map_iterator.h	Fri Mar 25 22:11:28 2005 +0000
     4.2 +++ b/src/lemon/map_iterator.h	Fri Mar 25 23:31:57 2005 +0000
     4.3 @@ -20,6 +20,7 @@
     4.4  #include <iterator>
     4.5  
     4.6  #include <lemon/extended_pair.h>
     4.7 +#include <lemon/map_utils.h>
     4.8  
     4.9  ///\ingroup graphmaps
    4.10  ///\file
    4.11 @@ -35,39 +36,23 @@
    4.12     *  simple step functions and equality operators.
    4.13     */ 
    4.14  
    4.15 -  template <typename Map>
    4.16 +  template <
    4.17 +    typename _Graph,
    4.18 +    typename _Item>
    4.19    class MapIteratorBase {
    4.20  
    4.21 -  public:
    4.22 -
    4.23 -    /// The key type of the iterator.
    4.24 -    typedef typename Map::Key Key;
    4.25 -    /// The iterator to iterate on the keys.
    4.26 -    typedef typename Map::KeyIt KeyIt;
    4.27 -
    4.28 -    /// The value type of the iterator.
    4.29 -    typedef typename Map::Value Value;
    4.30 -    /// The reference type of the iterator.
    4.31 -    typedef typename Map::Reference Reference;
    4.32 -    /// The pointer type of the iterator.
    4.33 -    typedef typename Map::Pointer Pointer;
    4.34 -
    4.35 -    /// The const value type of the iterator.
    4.36 -    typedef typename Map::ConstValue ConstValue;
    4.37 -    /// The const reference type of the iterator.
    4.38 -    typedef typename Map::ConstReference ConstReference;
    4.39 -    /// The pointer type of the iterator.
    4.40 -    typedef typename Map::ConstPointer ConstPointer;
    4.41 -
    4.42    protected:
    4.43  
    4.44 -    KeyIt it;
    4.45 +    /// The key type of the iterator.
    4.46 +    typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
    4.47 +
    4.48 +    ItemIt it;
    4.49  
    4.50      /// Default constructor.
    4.51      MapIteratorBase() {}
    4.52  
    4.53 -    /// KeyIt initialized MapIteratorBase constructor.
    4.54 -    MapIteratorBase(const KeyIt pit) : it(pit) {}
    4.55 +    /// ItemIt initialized MapIteratorBase constructor.
    4.56 +    MapIteratorBase(const ItemIt _it) : it(_it) {}
    4.57  
    4.58    public:
    4.59  
    4.60 @@ -77,330 +62,333 @@
    4.61      }
    4.62  
    4.63      /// The equality operator of the map.
    4.64 -    bool operator==(const MapIteratorBase& pit) const {
    4.65 -      return pit.it == it;
    4.66 +    bool operator==(const MapIteratorBase& _it) const {
    4.67 +      return _it.it == it;
    4.68      }
    4.69  	
    4.70      /// The not-equality operator of the map.
    4.71 -    bool operator!=(const MapIteratorBase& pit) const {
    4.72 -      return !(*this == pit);
    4.73 +    bool operator!=(const MapIteratorBase& _it) const {
    4.74 +      return !(*this == _it);
    4.75      }
    4.76    };
    4.77  
    4.78 -  template <typename Map> class MapConstIterator;
    4.79 +
    4.80 +  template <
    4.81 +    typename _Graph,
    4.82 +    typename _Item,
    4.83 +    typename _Map>
    4.84 +  class MapConstIterator;
    4.85  
    4.86    /** Compatible iterator with the stl maps' iterators.
    4.87     * It iterates on pairs of a key and a value.
    4.88     */
    4.89 -  template <typename Map>  
    4.90 -  class MapIterator : public MapIteratorBase<Map> {
    4.91 +  template <
    4.92 +    typename _Graph,
    4.93 +    typename _Item,
    4.94 +    typename _Map>
    4.95 +  class MapIterator : public MapIteratorBase<_Graph, _Item> {
    4.96  
    4.97 -    friend class MapConstIterator<Map>;
    4.98 +    friend class MapConstIterator<_Graph, _Item, _Map>;
    4.99  
   4.100  
   4.101    public:
   4.102  
   4.103      /// The iterator base class.
   4.104 -    typedef MapIteratorBase<Map> Base;
   4.105 +    typedef MapIteratorBase<_Graph, _Item> Parent;
   4.106  
   4.107 -    /// The key type of the iterator.
   4.108 -    typedef typename Map::Key Key;
   4.109 -    /// The iterator to iterate on the keys.
   4.110 -    typedef typename Map::KeyIt KeyIt;
   4.111 +    typedef _Item Item;
   4.112 +    typedef _Map Map;
   4.113 +    typedef _Graph Graph;
   4.114  
   4.115 -    /// The value type of the iterator.
   4.116 -    typedef typename Map::Value Value;
   4.117 -    /// The reference type of the iterator.
   4.118 -    typedef typename Map::Reference Reference;
   4.119 -    /// The pointer type of the iterator.
   4.120 -    typedef typename Map::Pointer Pointer;
   4.121 +  protected:
   4.122  
   4.123 -    /// The const value type of the iterator.
   4.124 -    typedef typename Map::ConstValue ConstValue;
   4.125 -    /// The const reference type of the iterator.
   4.126 -    typedef typename Map::ConstReference ConstReference;
   4.127 -    /// The pointer type of the iterator.
   4.128 -    typedef typename Map::ConstPointer ConstPointer;
   4.129 +    typedef typename Parent::ItemIt ItemIt;
   4.130 +
   4.131 +    typedef typename ReferenceMapTraits<_Map>::Value MapValue;
   4.132 +    typedef typename ReferenceMapTraits<_Map>::Reference MapReference;
   4.133      
   4.134    public:
   4.135  
   4.136      /// The value type of the iterator.
   4.137 -    typedef extended_pair<Key, const Key&,
   4.138 -      Value, const Value&> PairValue;
   4.139 +    typedef extended_pair<Item, const Item&,
   4.140 +      MapValue, const MapValue&> Value;
   4.141  
   4.142      /// The reference type of the iterator. 
   4.143 -    typedef extended_pair<const Key&, const Key&, 
   4.144 -      Reference, Reference> PairReference;
   4.145 +    typedef extended_pair<const Item&, const Item&, 
   4.146 +      MapReference, MapReference> Reference;
   4.147  
   4.148      /// Default constructor. 
   4.149      MapIterator() {}
   4.150  
   4.151      /// Constructor to initalize the iterators returned 
   4.152      /// by the begin() and end().
   4.153 -    MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {}
   4.154 +    MapIterator(Map& _map, const ItemIt& _it) 
   4.155 +      : Parent(_it), map(&_map) {}
   4.156  
   4.157      /// Dereference operator for the iterator.
   4.158 -    PairReference operator*() {
   4.159 -      return PairReference(Base::it, (*map)[Base::it]);
   4.160 +    Reference operator*() {
   4.161 +      return Reference(Parent::it, (*map)[Parent::it]);
   4.162      }
   4.163  
   4.164      /// The pointer type of the iterator.
   4.165 -    class PairPointer {
   4.166 +    class Pointer {
   4.167        friend class MapIterator;
   4.168 -    private:
   4.169 -      PairReference data;
   4.170 -      PairPointer(const Key& key, Reference val) 
   4.171 -	: data(key, val) {}
   4.172 +    protected:
   4.173 +      Reference data;
   4.174 +      Pointer(const Item& item, MapReference val) 
   4.175 +	: data(item, val) {}
   4.176      public:
   4.177 -      PairReference* operator->() {return &data;}
   4.178 +      Reference* operator->() {return &data;}
   4.179      };
   4.180  
   4.181      /// Arrow operator for the iterator.
   4.182 -    PairPointer operator->() {
   4.183 -      return PairPointer(Base::it, ((*map)[Base::it])); 
   4.184 +    Pointer operator->() {
   4.185 +      return Pointer(Parent::it, (*map)[Parent::it]); 
   4.186      }
   4.187  	
   4.188      /// The pre increment operator of the iterator.
   4.189      MapIterator& operator++() { 
   4.190 -      Base::increment(); 
   4.191 +      Parent::increment(); 
   4.192        return *this; 
   4.193      }
   4.194  
   4.195      /// The post increment operator of the iterator.
   4.196      MapIterator operator++(int) { 
   4.197        MapIterator tmp(*this); 
   4.198 -      Base::increment(); 
   4.199 +      Parent::increment(); 
   4.200        return tmp; 
   4.201      }
   4.202  
   4.203 -  private:
   4.204 +  protected:
   4.205 +
   4.206      Map* map;
   4.207  
   4.208    public:
   4.209      // STL  compatibility typedefs.
   4.210      typedef std::forward_iterator_tag iterator_category;
   4.211      typedef int difference_type;
   4.212 -    typedef PairValue value_type;
   4.213 -    typedef PairReference reference;
   4.214 -    typedef PairPointer pointer;
   4.215 +    typedef Value value_type;
   4.216 +    typedef Reference reference;
   4.217 +    typedef Pointer pointer;
   4.218    };
   4.219  
   4.220    /** Compatible iterator with the stl maps' iterators.
   4.221     *  It iterates on pairs of a key and a value.
   4.222     */
   4.223 -  template <typename Map>
   4.224 -  class MapConstIterator : public MapIteratorBase<Map> {
   4.225 +  template <
   4.226 +    typename _Graph,
   4.227 +    typename _Item,
   4.228 +    typename _Map>
   4.229 +  class MapConstIterator : public MapIteratorBase<_Graph, _Item> {
   4.230 +
   4.231 +  public:
   4.232 +
   4.233 +    /// The iterator base class.
   4.234 +    typedef MapIteratorBase<_Graph, _Item> Parent;
   4.235 +
   4.236 +    typedef _Graph Graph;
   4.237 +    typedef _Item Item;
   4.238 +    typedef _Map Map;
   4.239 +
   4.240 +  protected:
   4.241 +
   4.242 +    typedef typename Parent::ItemIt ItemIt;
   4.243 +
   4.244 +    typedef typename ReferenceMapTraits<_Map>::Value MapValue;
   4.245 +    typedef typename ReferenceMapTraits<_Map>::ConstReference
   4.246 +    MapReference;
   4.247      
   4.248    public:
   4.249  
   4.250 -    /// The iterator base class.
   4.251 -    typedef MapIteratorBase<Map> Base;
   4.252 +    /// The value type of the iterator.
   4.253 +    typedef extended_pair<Item, const Item&,
   4.254 +      MapValue, const MapValue&> Value;
   4.255  
   4.256 -    /// The key type of the iterator.
   4.257 -    typedef typename Map::Key Key;
   4.258 -    /// The iterator to iterate on the keys.
   4.259 -    typedef typename Map::KeyIt KeyIt;
   4.260 -
   4.261 -    /// The value type of the iterator.
   4.262 -    typedef typename Map::Value Value;
   4.263 -    /// The reference type of the iterator.
   4.264 -    typedef typename Map::Reference Reference;
   4.265 -    /// The pointer type of the iterator.
   4.266 -    typedef typename Map::Pointer Pointer;
   4.267 -
   4.268 -    /// The const value type of the iterator.
   4.269 -    typedef typename Map::ConstValue ConstValue;
   4.270 -    /// The const reference type of the iterator.
   4.271 -    typedef typename Map::ConstReference ConstReference;
   4.272 -    /// The pointer type of the iterator.
   4.273 -    typedef typename Map::ConstPointer ConstPointer;
   4.274 -
   4.275 -  public:    
   4.276 +    /// The reference type of the iterator. 
   4.277 +    typedef extended_pair<const Item&, const Item&, 
   4.278 +      MapReference, MapReference> Reference;
   4.279  
   4.280      /// Default constructor. 
   4.281      MapConstIterator() {}
   4.282  
   4.283 -    /// Constructor to initalize the the iterators returned
   4.284 -    ///  by the begin() and end().
   4.285 -    MapConstIterator(const Map& pmap, const KeyIt& pit) 
   4.286 -      : Base(pit), map(&pmap) {}
   4.287 -
   4.288 -    /// Constructor to create const iterator from a non const.
   4.289 -    MapConstIterator(const MapIterator<Map>& pit) {
   4.290 -      Base::it = pit.Base::it;
   4.291 -      map = pit.map;
   4.292 -    }
   4.293 -
   4.294 -    /// The value type of the iterator.
   4.295 -    typedef extended_pair<Key, const Key&,
   4.296 -      Value, const Value&> PairValue;
   4.297 -
   4.298 -    /// The reference type of map.
   4.299 -    typedef extended_pair<const Key&, const Key&, 
   4.300 -      ConstReference, ConstReference> PairReference;
   4.301 +    /// Constructor to initalize the iterators returned 
   4.302 +    /// by the begin() and end().
   4.303 +    MapConstIterator(const Map& _map, const ItemIt& _it) 
   4.304 +      : Parent(_it), map(&_map) {}
   4.305  
   4.306      /// Dereference operator for the iterator.
   4.307 -    PairReference operator*() {
   4.308 -      return PairReference(Base::it, (*map)[Base::it]);
   4.309 +    Reference operator*() {
   4.310 +      return Reference(Parent::it, (*map)[Parent::it]);
   4.311      }
   4.312  
   4.313      /// The pointer type of the iterator.
   4.314 -    class PairPointer {
   4.315 +    class Pointer {
   4.316        friend class MapConstIterator;
   4.317 -    private:
   4.318 -      PairReference data;
   4.319 -      PairPointer(const Key& key, ConstReference val) 
   4.320 -	: data(key, val) {}
   4.321 +    protected:
   4.322 +      Reference data;
   4.323 +      Pointer(const Item& item, MapReference val) 
   4.324 +	: data(item, val) {}
   4.325      public:
   4.326 -      PairReference* operator->() {return &data;}
   4.327 +      Reference* operator->() {return &data;}
   4.328      };
   4.329  
   4.330      /// Arrow operator for the iterator.
   4.331 -    PairPointer operator->() {
   4.332 -      return PairPointer(Base::it, (*map)[Base::it]); 
   4.333 +    Pointer operator->() {
   4.334 +      return Pointer(Parent::it, ((*map)[Parent::it])); 
   4.335      }
   4.336 -
   4.337 +	
   4.338      /// The pre increment operator of the iterator.
   4.339      MapConstIterator& operator++() { 
   4.340 -      Base::increment(); 
   4.341 +      Parent::increment(); 
   4.342        return *this; 
   4.343      }
   4.344  
   4.345      /// The post increment operator of the iterator.
   4.346      MapConstIterator operator++(int) { 
   4.347        MapConstIterator tmp(*this); 
   4.348 -      Base::increment(); 
   4.349 +      Parent::increment(); 
   4.350        return tmp; 
   4.351      }
   4.352  
   4.353 -  private:
   4.354 +  protected:
   4.355      const Map* map;
   4.356  
   4.357    public:
   4.358      // STL  compatibility typedefs.
   4.359 -    typedef std::input_iterator_tag iterator_category;
   4.360 +    typedef std::forward_iterator_tag iterator_category;
   4.361      typedef int difference_type;
   4.362 -    typedef PairValue value_type;
   4.363 -    typedef PairReference reference;
   4.364 -    typedef PairPointer pointer;
   4.365 +    typedef Value value_type;
   4.366 +    typedef Reference reference;
   4.367 +    typedef Pointer pointer;
   4.368    };
   4.369 -
   4.370 -  /** The class makes the KeyIt to an stl compatible iterator
   4.371 + 
   4.372 +  /** The class makes the ItemIt to an stl compatible iterator
   4.373     *  with dereferencing operator.
   4.374     */
   4.375 -  template <typename Map>
   4.376 -  class MapKeyIterator : public MapIteratorBase<Map> {
   4.377 +  template <
   4.378 +    typename _Graph,
   4.379 +    typename _Item>
   4.380 +  class MapConstKeyIterator : public MapIteratorBase<_Graph, _Item> {
   4.381  
   4.382    public:
   4.383  
   4.384      /// The iterator base class.
   4.385 -    typedef MapIteratorBase<Map> Base;
   4.386 +    typedef MapIteratorBase<_Graph, _Item> Parent;
   4.387   
   4.388 -    /// The key type of the iterator.
   4.389 -    typedef typename Map::Key Key;
   4.390 +    typedef _Graph Graph;
   4.391 +    typedef _Item Item;
   4.392 +
   4.393 +  protected:
   4.394      /// The iterator to iterate on the keys.
   4.395 -    typedef typename Map::KeyIt KeyIt;
   4.396 +    typedef typename Parent::ItemIt ItemIt;
   4.397  
   4.398    public:
   4.399  
   4.400 +    typedef Item Value;
   4.401 +    typedef const Item& Reference;
   4.402 +    typedef const Item* Pointer;
   4.403 +
   4.404      /// Default constructor.
   4.405 -    MapKeyIterator() {}
   4.406 +    MapConstKeyIterator() {}
   4.407  
   4.408 -    /// KeyIt initialized iterator.
   4.409 -    MapKeyIterator(const KeyIt& pit) : Base(pit) {}
   4.410 +    /// ItemIt initialized iterator.
   4.411 +    MapConstKeyIterator(const ItemIt& pit) : Parent(pit) {}
   4.412  
   4.413      /// The pre increment operator of the iterator.
   4.414 -    MapKeyIterator& operator++() {
   4.415 -      Base::increment(); 
   4.416 +    MapConstKeyIterator& operator++() {
   4.417 +      Parent::increment(); 
   4.418        return *this; 
   4.419      }
   4.420  
   4.421      /// The post increment operator of the iterator.
   4.422 -    MapKeyIterator operator++(int) {
   4.423 -      MapKeyIterator tmp(*this);
   4.424 -      Base::increment();
   4.425 +    MapConstKeyIterator operator++(int) {
   4.426 +      MapConstKeyIterator tmp(*this);
   4.427 +      Parent::increment();
   4.428        return tmp;
   4.429      }
   4.430  
   4.431      /// The dereferencing operator of the iterator.
   4.432 -    Key operator*() const {
   4.433 -      return static_cast<Key>(Base::it);
   4.434 +    Item operator*() const {
   4.435 +      return static_cast<Item>(Parent::it);
   4.436      }
   4.437  
   4.438    public:
   4.439      // STL  compatibility typedefs.
   4.440      typedef std::input_iterator_tag iterator_category;
   4.441      typedef int difference_type;
   4.442 -    typedef Key value_type;
   4.443 -    typedef const Key& reference;
   4.444 -    typedef const Key* pointer;
   4.445 +    typedef Value value_type;
   4.446 +    typedef Reference reference;
   4.447 +    typedef Pointer pointer;
   4.448    };
   4.449  
   4.450 -  template <typename Map> class MapConstValueIterator;
   4.451 +  template <
   4.452 +    typename _Graph, 
   4.453 +    typename _Item,
   4.454 +    typename _Map>
   4.455 +  class MapConstValueIterator;
   4.456  
   4.457    /** MapValueIterator creates an stl compatible iterator
   4.458     *  for the values.
   4.459     */
   4.460 -  template <typename Map>
   4.461 -  class MapValueIterator : public MapIteratorBase<Map> {
   4.462 +  template <
   4.463 +    typename _Graph,
   4.464 +    typename _Item,
   4.465 +    typename _Map>
   4.466 +  class MapValueIterator : public MapIteratorBase<_Graph, _Item> {
   4.467  
   4.468 -    friend class MapConstValueIterator<Map>;
   4.469 +    friend class MapConstValueIterator<_Graph, _Item, _Map>;
   4.470  
   4.471    public:
   4.472  
   4.473      /// The iterator base class.
   4.474 -    typedef MapIteratorBase<Map> Base;
   4.475 +    typedef MapIteratorBase<_Graph, _Item> Parent;
   4.476  
   4.477 -    /// The key type of the iterator.
   4.478 -    typedef typename Map::Key Key;
   4.479 +    typedef _Graph Graph;
   4.480 +    typedef _Item Item;
   4.481 +    typedef _Map Map;
   4.482 +
   4.483 +  protected:
   4.484 +
   4.485      /// The iterator to iterate on the keys.
   4.486 -    typedef typename Map::KeyIt KeyIt;
   4.487 -
   4.488 +    typedef typename Parent::ItemIt ItemIt;
   4.489  
   4.490      /// The value type of the iterator.
   4.491 -    typedef typename Map::Value Value;
   4.492 +    typedef typename ReferenceMapTraits<Map>::Value MapValue;
   4.493      /// The reference type of the iterator.
   4.494 -    typedef typename Map::Reference Reference;
   4.495 +    typedef typename ReferenceMapTraits<Map>::Reference MapReference;
   4.496      /// The pointer type of the iterator.
   4.497 -    typedef typename Map::Pointer Pointer;
   4.498 -
   4.499 -    /// The const value type of the iterator.
   4.500 -    typedef typename Map::ConstValue ConstValue;
   4.501 -    /// The const reference type of the iterator.
   4.502 -    typedef typename Map::ConstReference ConstReference;
   4.503 -    /// The pointer type of the iterator.
   4.504 -    typedef typename Map::ConstPointer ConstPointer;
   4.505 -
   4.506 -  private:
   4.507 -
   4.508 -    Map* map;
   4.509 +    typedef typename ReferenceMapTraits<Map>::Pointer MapPointer;
   4.510  
   4.511    public:
   4.512  
   4.513 +    typedef MapValue Value;
   4.514 +    typedef MapReference Reference;
   4.515 +    typedef MapPointer Pointer;
   4.516 +
   4.517      /// Default constructor.
   4.518      MapValueIterator() {}
   4.519  
   4.520 -    /// Map and KeyIt initialized iterator.
   4.521 -    MapValueIterator(Map& pmap, const KeyIt& pit) 
   4.522 -      : Base(pit), map(&pmap) {}
   4.523 +    /// Map and ItemIt initialized iterator.
   4.524 +    MapValueIterator(Map& _map, const ItemIt& _it) 
   4.525 +      : Parent(_it), map(&_map) {}
   4.526      
   4.527  
   4.528      /// The pre increment operator of the iterator.
   4.529      MapValueIterator& operator++() {
   4.530 -      Base::increment(); 
   4.531 +      Parent::increment(); 
   4.532        return *this; 
   4.533      }
   4.534  
   4.535      /// The post increment operator of the iterator.
   4.536      MapValueIterator operator++(int) {
   4.537        MapValueIterator tmp(*this);
   4.538 -      Base::increment();
   4.539 +      Parent::increment();
   4.540        return tmp;
   4.541      }
   4.542  
   4.543      /// The dereferencing operator of the iterator.
   4.544      Reference operator*() const {
   4.545 -      return (*map)[Base::it];
   4.546 +      return (*map)[Parent::it];
   4.547      }
   4.548  
   4.549      /// The arrow operator of the iterator.
   4.550 @@ -408,6 +396,10 @@
   4.551        return &(operator*());
   4.552      }
   4.553  
   4.554 +  protected:
   4.555 +
   4.556 +    Map* map;
   4.557 +
   4.558    public:
   4.559      // STL  compatibility typedefs.
   4.560      typedef std::forward_iterator_tag iterator_category;
   4.561 @@ -418,133 +410,130 @@
   4.562    };
   4.563  
   4.564    /** MapValueIterator creates an stl compatible iterator
   4.565 -   *  for the const values.
   4.566 +   *  for the values.
   4.567     */
   4.568 -
   4.569 -  template <typename Map>
   4.570 -  class MapConstValueIterator : public MapIteratorBase<Map> {
   4.571 +  template <
   4.572 +    typename _Graph,
   4.573 +    typename _Item,
   4.574 +    typename _Map>
   4.575 +  class MapConstValueIterator : public MapIteratorBase<_Graph, _Item> {
   4.576  
   4.577    public:
   4.578  
   4.579      /// The iterator base class.
   4.580 -    typedef MapIteratorBase<Map> Base;
   4.581 +    typedef MapIteratorBase<_Graph, _Item> Parent;
   4.582  
   4.583 -    /// The key type of the iterator.
   4.584 -    typedef typename Map::Key Key;
   4.585 +    typedef _Graph Graph;
   4.586 +    typedef _Item Item;
   4.587 +    typedef _Map Map;
   4.588 +
   4.589 +  protected:
   4.590 +
   4.591      /// The iterator to iterate on the keys.
   4.592 -    typedef typename Map::KeyIt KeyIt;
   4.593 +    typedef typename Parent::ItemIt ItemIt;
   4.594  
   4.595      /// The value type of the iterator.
   4.596 -    typedef typename Map::Value Value;
   4.597 +    typedef typename ReferenceMapTraits<Map>::Value MapValue;
   4.598      /// The reference type of the iterator.
   4.599 -    typedef typename Map::Reference Reference;
   4.600 +    typedef typename ReferenceMapTraits<Map>::ConstReference MapReference;
   4.601      /// The pointer type of the iterator.
   4.602 -    typedef typename Map::Pointer Pointer;
   4.603 -
   4.604 -    /// The const value type of the iterator.
   4.605 -    typedef typename Map::ConstValue ConstValue;
   4.606 -    /// The const reference type of the iterator.
   4.607 -    typedef typename Map::ConstReference ConstReference;
   4.608 -    /// The pointer type of the iterator.
   4.609 -    typedef typename Map::ConstPointer ConstPointer;
   4.610 -
   4.611 -  private:
   4.612 -
   4.613 -    const Map* map;
   4.614 +    typedef typename ReferenceMapTraits<Map>::ConstPointer MapPointer;
   4.615  
   4.616    public:
   4.617  
   4.618 +    typedef MapValue Value;
   4.619 +    typedef MapReference Reference;
   4.620 +    typedef MapPointer Pointer;
   4.621 +
   4.622      /// Default constructor.
   4.623      MapConstValueIterator() {}
   4.624  
   4.625 -    /// Constructor to create const iterator from a non const.
   4.626 -    MapConstValueIterator(const MapValueIterator<Map>& pit) {
   4.627 -      Base::it = pit.Base::it;
   4.628 -      map = pit.map;
   4.629 -    }
   4.630 -
   4.631 -    /// Map and KeyIt initialized iterator.
   4.632 -    MapConstValueIterator(const Map& pmap, const KeyIt& pit) 
   4.633 -      : Base(pit), map(&pmap) {}
   4.634 +    /// Map and ItemIt initialized iterator.
   4.635 +    MapConstValueIterator(const Map& _map, const ItemIt& _it) 
   4.636 +      : Parent(_it), map(&_map) {}
   4.637 +    
   4.638  
   4.639      /// The pre increment operator of the iterator.
   4.640      MapConstValueIterator& operator++() {
   4.641 -      Base::increment(); 
   4.642 +      Parent::increment(); 
   4.643        return *this; 
   4.644      }
   4.645  
   4.646      /// The post increment operator of the iterator.
   4.647      MapConstValueIterator operator++(int) {
   4.648        MapConstValueIterator tmp(*this);
   4.649 -      Base::increment();
   4.650 +      Parent::increment();
   4.651        return tmp;
   4.652      }
   4.653  
   4.654      /// The dereferencing operator of the iterator.
   4.655 -    ConstReference operator*() const {
   4.656 -      return (*map)[Base::it];
   4.657 +    Reference operator*() const {
   4.658 +      return (*map)[Parent::it];
   4.659      }
   4.660  
   4.661      /// The arrow operator of the iterator.
   4.662 -    ConstPointer operator->() const {
   4.663 +    Pointer operator->() const {
   4.664        return &(operator*());
   4.665      }
   4.666  
   4.667 +  protected:
   4.668 +
   4.669 +    const Map* map;
   4.670 +
   4.671    public:
   4.672      // STL  compatibility typedefs.
   4.673 -    typedef std::input_iterator_tag iterator_category;
   4.674 +    typedef std::forward_iterator_tag iterator_category;
   4.675      typedef int difference_type;
   4.676      typedef Value value_type;
   4.677 -    typedef ConstReference reference;
   4.678 -    typedef ConstPointer pointer;
   4.679 +    typedef Reference reference;
   4.680 +    typedef Pointer pointer;
   4.681    };
   4.682  
   4.683  
   4.684    /** This class makes from a map an iteratable set
   4.685     *  which contains all the keys of the map.
   4.686     */
   4.687 -  template <typename Map>
   4.688 +  template <typename _Graph, typename _Item>
   4.689    class MapConstKeySet {
   4.690  
   4.691 -    const Map* map;
   4.692 -
   4.693    public:
   4.694  
   4.695 +    typedef _Graph Graph;
   4.696      /// The key type of the iterator.
   4.697 -    typedef typename Map::Key Key;
   4.698 +    typedef _Item Item;
   4.699      /// The iterator to iterate on the keys.
   4.700 -    typedef typename Map::KeyIt KeyIt;
   4.701  
   4.702 +  protected:
   4.703  
   4.704 -    /// The value type of the iterator.
   4.705 -    typedef typename Map::Value Value;
   4.706 -    /// The reference type of the iterator.
   4.707 -    typedef typename Map::Reference Reference;
   4.708 -    /// The pointer type of the iterator.
   4.709 -    typedef typename Map::Pointer Pointer;
   4.710 +    typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
   4.711  
   4.712 -    /// The const value type of the iterator.
   4.713 -    typedef typename Map::ConstValue ConstValue;
   4.714 -    /// The const reference type of the iterator.
   4.715 -    typedef typename Map::ConstReference ConstReference;
   4.716 -    /// The pointer type of the iterator.
   4.717 -    typedef typename Map::ConstPointer ConstPointer;
   4.718 +  public:
   4.719  
   4.720      /// The map initialized const key set.
   4.721 -    MapConstKeySet(const Map& pmap) : map(&pmap) {}
   4.722 +    MapConstKeySet(const Graph& _graph) : graph(&_graph) {}
   4.723  
   4.724      /// The const iterator of the set.
   4.725 -    typedef MapKeyIterator<Map> ConstIterator;
   4.726 +    typedef MapConstKeyIterator<_Graph, _Item> ConstIterator;
   4.727 +
   4.728 +    typedef typename ConstIterator::Value Value;
   4.729 +    /// The reference type of the iterator.
   4.730 +    typedef typename ConstIterator::Reference ConstReference;
   4.731 +    /// The pointer type of the iterator.
   4.732 +    typedef typename ConstIterator::Pointer ConstPointer;
   4.733  
   4.734      /// It gives back the const iterator pointed to the first element.
   4.735      ConstIterator begin() const {
   4.736 -      return ConstIterator(KeyIt(*map->getGraph()));
   4.737 +      return ConstIterator(ItemIt(*graph));
   4.738      }
   4.739              
   4.740      /// It gives back the const iterator pointed to the first ivalid element.
   4.741      ConstIterator end() const {
   4.742 -      return ConstIterator(KeyIt(INVALID));
   4.743 +      return ConstIterator(ItemIt(INVALID));
   4.744      }
   4.745 +
   4.746 +  protected:
   4.747 +
   4.748 +    const Graph* graph;
   4.749   
   4.750    public:
   4.751      // STL  compatibility typedefs.
   4.752 @@ -559,49 +548,48 @@
   4.753     *  which contains all the values of the map.
   4.754     *  The values cannot be modified.
   4.755     */
   4.756 -  template <typename Map>
   4.757 +  template <typename _Graph, typename _Item, typename _Map>
   4.758    class MapConstValueSet {
   4.759  
   4.760 -    const Map* map;
   4.761 +  public:
   4.762 +    
   4.763 +    typedef _Graph Graph;
   4.764 +    typedef _Item Item;
   4.765 +    typedef _Map Map;
   4.766 +
   4.767 +  protected:
   4.768 +
   4.769 +    /// The iterator to iterate on the keys.
   4.770 +    typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
   4.771  
   4.772    public:
   4.773  
   4.774 -    /// The key type of the iterator.
   4.775 -    typedef typename Map::Key Key;
   4.776 -    /// The iterator to iterate on the keys.
   4.777 -    typedef typename Map::KeyIt KeyIt;
   4.778 -
   4.779 -
   4.780 -    /// The value type of the iterator.
   4.781 -    typedef typename Map::Value Value;
   4.782 -    /// The reference type of the iterator.
   4.783 -    typedef typename Map::Reference Reference;
   4.784 -    /// The pointer type of the iterator.
   4.785 -    typedef typename Map::Pointer Pointer;
   4.786 -
   4.787 -    /// The const value type of the iterator.
   4.788 -    typedef typename Map::ConstValue ConstValue;
   4.789 -    /// The const reference type of the iterator.
   4.790 -    typedef typename Map::ConstReference ConstReference;
   4.791 -    /// The pointer type of the iterator.
   4.792 -    typedef typename Map::ConstPointer ConstPointer;
   4.793 -
   4.794      /// The map initialized const value set.
   4.795 -    MapConstValueSet(const Map& pmap) : map(&pmap) {}
   4.796 +    MapConstValueSet(const Graph& _graph, const Map& _map) 
   4.797 +      : graph(&_graph), map(&_map) {}
   4.798  
   4.799      /// The const iterator of the set.
   4.800 -    typedef MapConstValueIterator<Map> ConstIterator;
   4.801 +    typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
   4.802 +
   4.803 +    typedef typename ConstIterator::Value Value;
   4.804 +    typedef typename ConstIterator::Reference ConstReference;
   4.805 +    typedef typename ConstIterator::Pointer ConstPointer;
   4.806  
   4.807      /// It gives back the const iterator pointed to the first element.
   4.808      ConstIterator begin() const {
   4.809 -      return ConstIterator(*map, KeyIt(*map->getGraph()));
   4.810 +      return ConstIterator(*map, ItemIt(*graph));
   4.811      }
   4.812  
   4.813      /// It gives back the const iterator pointed to the first invalid element.
   4.814      ConstIterator end() const {
   4.815 -      return ConstIterator(*map, KeyIt(INVALID));
   4.816 +      return ConstIterator(*map, ItemIt(INVALID));
   4.817      }
   4.818  
   4.819 +  protected:
   4.820 +    
   4.821 +    const Map* map;
   4.822 +    const Graph * graph;
   4.823 +
   4.824    public:
   4.825      // STL  compatibility typedefs.
   4.826      typedef Value value_type;
   4.827 @@ -616,61 +604,137 @@
   4.828     *  which contains all the values of the map.
   4.829     *  The values can be modified.
   4.830     */
   4.831 -  template <typename Map>
   4.832 +  template <typename _Graph, typename _Item, typename _Map>
   4.833    class MapValueSet {
   4.834  
   4.835 -    Map* map;
   4.836 +  public:
   4.837 +    
   4.838 +    typedef _Graph Graph;
   4.839 +    typedef _Item Item;
   4.840 +    typedef _Map Map;
   4.841 +
   4.842 +  protected:
   4.843 +
   4.844 +    /// The iterator to iterate on the keys.
   4.845 +    typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
   4.846  
   4.847    public:
   4.848  
   4.849 -    /// The key type of the iterator.
   4.850 -    typedef typename Map::Key Key;
   4.851 -    /// The iterator to iterate on the keys.
   4.852 -    typedef typename Map::KeyIt KeyIt;
   4.853 -
   4.854 -
   4.855 -    /// The value type of the iterator.
   4.856 -    typedef typename Map::Value Value;
   4.857 -    /// The reference type of the iterator.
   4.858 -    typedef typename Map::Reference Reference;
   4.859 -    /// The pointer type of the iterator.
   4.860 -    typedef typename Map::Pointer Pointer;
   4.861 -
   4.862 -    /// The const value type of the iterator.
   4.863 -    typedef typename Map::ConstValue ConstValue;
   4.864 -    /// The const reference type of the iterator.
   4.865 -    typedef typename Map::ConstReference ConstReference;
   4.866 -    /// The pointer type of the iterator.
   4.867 -    typedef typename Map::ConstPointer ConstPointer;
   4.868 -
   4.869 -    /// The map initialized value set.
   4.870 -    MapValueSet(Map& pmap) : map(&pmap) {}
   4.871 +    /// The map initialized const value set.
   4.872 +    MapValueSet(const Graph& _graph, Map& _map) 
   4.873 +      : graph(&_graph), map(&_map) {}
   4.874  
   4.875      /// The const iterator of the set.
   4.876 -    typedef MapConstValueIterator<Map> ConstIterator;
   4.877 +    typedef MapValueIterator<_Graph, _Item, _Map> Iterator;
   4.878 +    /// The const iterator of the set.
   4.879 +    typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
   4.880 +
   4.881 +    typedef typename ConstIterator::Value Value;
   4.882 +    typedef typename Iterator::Reference Reference;
   4.883 +    typedef typename Iterator::Pointer Pointer;
   4.884 +    typedef typename ConstIterator::Reference ConstReference;
   4.885 +    typedef typename ConstIterator::Pointer ConstPointer;
   4.886  
   4.887      /// It gives back the const iterator pointed to the first element.
   4.888      ConstIterator begin() const {
   4.889 -      return ConstIterator(*map, KeyIt(*map->getGraph()));
   4.890 +      return ConstIterator(*map, ItemIt(*graph));
   4.891      }
   4.892  
   4.893      /// It gives back the const iterator pointed to the first invalid element.
   4.894      ConstIterator end() const {
   4.895 -      return ConstIterator(*map, KeyIt(INVALID));
   4.896 +      return ConstIterator(*map, ItemIt(INVALID));
   4.897      }
   4.898  
   4.899 -    /// The iterator of the set.
   4.900 -    typedef MapValueIterator<Map> Iterator;
   4.901 -
   4.902      /// It gives back the iterator pointed to the first element.
   4.903      Iterator begin() {
   4.904 -      return Iterator(*map, KeyIt(*map->getGraph()));
   4.905 +      return Iterator(*map, ItemIt(*graph));
   4.906      }
   4.907  
   4.908      /// It gives back the iterator pointed to the first invalid element.
   4.909      Iterator end() {
   4.910 -      return Iterator(*map, KeyIt(INVALID));
   4.911 +      return Iterator(*map, ItemIt(INVALID));
   4.912      }
   4.913 +
   4.914 +  protected:
   4.915 +    
   4.916 +    Map* map;
   4.917 +    const Graph * graph;
   4.918 +
   4.919 +  public:
   4.920 +    // STL  compatibility typedefs.
   4.921 +    typedef Value value_type;
   4.922 +    typedef Iterator iterator;
   4.923 +    typedef ConstIterator const_iterator;
   4.924 +    typedef Reference reference;
   4.925 +    typedef ConstReference const_reference;
   4.926 +    typedef Pointer pointer;
   4.927 +    typedef ConstPointer const_pointer;
   4.928 +    typedef int difference_type;
   4.929 +
   4.930 +  };
   4.931 +
   4.932 +  /** This class makes from a map an iteratable set
   4.933 +   *  which contains all the values of the map.
   4.934 +   *  The values can be modified.
   4.935 +   */
   4.936 +  template <
   4.937 +    typename _Graph, 
   4.938 +    typename _Item,
   4.939 +    typename _Map
   4.940 +    >
   4.941 +  class MapSet {
   4.942 +  public:    
   4.943 +
   4.944 +    typedef _Graph Graph;
   4.945 +    typedef _Item Item;
   4.946 +    typedef _Map Map;
   4.947 +
   4.948 +  protected:
   4.949 +
   4.950 +    typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
   4.951 +
   4.952 +  public:
   4.953 +
   4.954 +    /// The map initialized value set.
   4.955 +    MapSet(const Graph& _graph, Map& _map) : graph(&_graph), map(&_map) {}
   4.956 +
   4.957 +    /// The const iterator of the set.
   4.958 +    typedef MapIterator<_Graph, _Item, _Map> Iterator;
   4.959 +    typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
   4.960 +
   4.961 +    typedef typename ConstIterator::Value Value;
   4.962 +    typedef typename Iterator::Reference Reference;
   4.963 +    typedef typename Iterator::Pointer Pointer;
   4.964 +    typedef typename ConstIterator::Reference ConstReference;
   4.965 +    typedef typename ConstIterator::Pointer ConstPointer;
   4.966 +
   4.967 +
   4.968 +    /// It gives back the const iterator pointed to the first element.
   4.969 +    ConstIterator begin() const {
   4.970 +      return ConstIterator(*map, ItemIt(*graph));
   4.971 +    }
   4.972 +
   4.973 +    /// It gives back the const iterator pointed to the first invalid element.
   4.974 +    ConstIterator end() const {
   4.975 +      return ConstIterator(*map, ItemIt(INVALID));
   4.976 +    }
   4.977 +
   4.978 +    /// The iterator of the set.
   4.979 +
   4.980 +    /// It gives back the iterator pointed to the first element.
   4.981 +    Iterator begin() {
   4.982 +      return Iterator(*map, ItemIt(*graph));
   4.983 +    }
   4.984 +
   4.985 +    /// It gives back the iterator pointed to the first invalid element.
   4.986 +    Iterator end() {
   4.987 +      return Iterator(*map, ItemIt(INVALID));
   4.988 +    }
   4.989 +
   4.990 +  protected:
   4.991 +    
   4.992 +    const Graph* graph;
   4.993 +    Map* map;
   4.994              
   4.995    public:
   4.996      // STL  compatibility typedefs.
   4.997 @@ -685,6 +749,105 @@
   4.998  
   4.999    };
  4.1000  
  4.1001 +  template <
  4.1002 +    typename _Graph, 
  4.1003 +    typename _Item,
  4.1004 +    typename _Map
  4.1005 +    >
  4.1006 +  class ConstMapSet {
  4.1007 +    
  4.1008 +    typedef _Graph Graph;
  4.1009 +    typedef _Map Map;
  4.1010 +
  4.1011 +    const Graph* graph;
  4.1012 +    const Map* map;
  4.1013 +
  4.1014 +  public:
  4.1015 +
  4.1016 +    typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
  4.1017 +
  4.1018 +
  4.1019 +    /// The map initialized value set.
  4.1020 +    ConstMapSet(const Graph& _graph, const Map& _map) 
  4.1021 +      : graph(&_graph), map(&_map) {}
  4.1022 +
  4.1023 +    /// The const iterator of the set.
  4.1024 +    typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
  4.1025 +
  4.1026 +    typedef typename ConstIterator::Value Value;
  4.1027 +    typedef typename ConstIterator::Reference ConstReference;
  4.1028 +    typedef typename ConstIterator::Pointer ConstPointer;
  4.1029 +
  4.1030 +
  4.1031 +    /// It gives back the const iterator pointed to the first element.
  4.1032 +    ConstIterator begin() const {
  4.1033 +      return ConstIterator(*map, ItemIt(*graph));
  4.1034 +    }
  4.1035 +
  4.1036 +    /// It gives back the const iterator pointed to the first invalid element.
  4.1037 +    ConstIterator end() const {
  4.1038 +      return ConstIterator(*map, ItemIt(INVALID));
  4.1039 +    }
  4.1040 +            
  4.1041 +  public:
  4.1042 +    // STL  compatibility typedefs.
  4.1043 +    typedef Value value_type;
  4.1044 +    typedef ConstIterator const_iterator;
  4.1045 +    typedef ConstReference const_reference;
  4.1046 +    typedef ConstPointer const_pointer;
  4.1047 +    typedef int difference_type;
  4.1048 +
  4.1049 +  };
  4.1050 +
  4.1051 +  template <typename _Map>
  4.1052 +  class IterableMapExtender : public _Map {
  4.1053 +  public:
  4.1054 +
  4.1055 +    typedef _Map Parent;
  4.1056 +    typedef Parent Map;
  4.1057 +    typedef typename Map::Graph Graph;
  4.1058 +    typedef typename Map::Key Item;
  4.1059 +    typedef typename Map::Value Value;
  4.1060 +
  4.1061 +    typedef MapSet<Graph, Item, Map> MapSet;
  4.1062 +
  4.1063 +    IterableMapExtender() : Parent() {}
  4.1064 +
  4.1065 +    IterableMapExtender(const Graph& graph) : Parent(graph) {}
  4.1066 +
  4.1067 +    IterableMapExtender(const Graph& graph, const Value& value) 
  4.1068 +      : Parent(graph, value) {}
  4.1069 +
  4.1070 +    MapSet mapSet() { 
  4.1071 +      return MapSet(*Parent::getGraph(), *this); 
  4.1072 +    }
  4.1073 +
  4.1074 +    typedef ConstMapSet<Graph, Item, Map> ConstMapSet;
  4.1075 +
  4.1076 +    ConstMapSet mapSet() const { 
  4.1077 +      return ConstMapSet(*Parent::getGraph(), *this); 
  4.1078 +    }
  4.1079 +
  4.1080 +    typedef MapConstKeySet<Graph, Item> ConstKeySet;
  4.1081 + 
  4.1082 +    ConstKeySet keySet() const {
  4.1083 +      return ConstKeySet(*Parent::getGraph());
  4.1084 +    }
  4.1085 +
  4.1086 +    typedef MapValueSet<Graph, Item, Map> ValueSet;
  4.1087 + 
  4.1088 +    ValueSet valueSet() {
  4.1089 +      return ValueSet(*Parent::getGraph(), *this);
  4.1090 +    }
  4.1091 +
  4.1092 +    typedef MapConstValueSet<Graph, Item, Map> ConstValueSet;
  4.1093 + 
  4.1094 +    ConstValueSet valueSet() const {
  4.1095 +      return ConstValueSet(*Parent::getGraph(), *this);
  4.1096 +    }
  4.1097 +
  4.1098 +  };
  4.1099 +
  4.1100    /// @}
  4.1101  
  4.1102  }
     5.1 --- a/src/lemon/map_utils.h	Fri Mar 25 22:11:28 2005 +0000
     5.2 +++ b/src/lemon/map_utils.h	Fri Mar 25 23:31:57 2005 +0000
     5.3 @@ -25,11 +25,35 @@
     5.4  #include <map>
     5.5  #include <vector>
     5.6  
     5.7 +#include <lemon/graph_utils.h>
     5.8 +
     5.9  namespace lemon {
    5.10  
    5.11    /// \addtogroup mutils
    5.12    /// @{
    5.13  
    5.14 +
    5.15 +  template <typename Map, typename Enable = void>
    5.16 +  struct ReferenceMapTraits {
    5.17 +    typedef typename Map::Value Value;
    5.18 +    typedef typename Map::Value& Reference;
    5.19 +    typedef const typename Map::Value& ConstReference;
    5.20 +    typedef typename Map::Value* Pointer;
    5.21 +    typedef const typename Map::Value* ConstPointer;
    5.22 +  };
    5.23 +
    5.24 +  template <typename Map>
    5.25 +  struct ReferenceMapTraits<
    5.26 +    Map, 
    5.27 +    typename enable_if<typename Map::FullTypeTag, void>::type
    5.28 +  > {
    5.29 +    typedef typename Map::Value Value;
    5.30 +    typedef typename Map::Reference Reference;
    5.31 +    typedef typename Map::ConstReference ConstReference;
    5.32 +    typedef typename Map::Pointer Pointer;
    5.33 +    typedef typename Map::ConstPointer ConstPointer;
    5.34 +  };
    5.35 +
    5.36    /// \brief General inversable map type.
    5.37  
    5.38    /// This type provides simple inversable map functions. 
    5.39 @@ -39,19 +63,23 @@
    5.40    /// \param _Graph The graph type.
    5.41    /// \param _Map The map to extend with inversable functionality. 
    5.42    template <
    5.43 -    typename _Graph, 
    5.44 -    typename _Map
    5.45 +    typename _Graph,
    5.46 +    typename _Item, 
    5.47 +    typename _Value,
    5.48 +    typename _Map 
    5.49 +    = typename ItemSetTraits<_Graph, _Item>::template Map<_Value> 
    5.50    >
    5.51    class InversableMap : protected _Map {
    5.52  
    5.53    public:
    5.54 + 
    5.55 +    typedef _Map Map;
    5.56      typedef _Graph Graph;
    5.57 -
    5.58 -    typedef _Map Map;
    5.59 -    /// The key type of InversableMap (Node, Edge, UndirEdge).
    5.60 +   /// The key type of InversableMap (Node, Edge, UndirEdge).
    5.61      typedef typename _Map::Key Key;
    5.62      /// The value type of the InversableMap.
    5.63      typedef typename _Map::Value Value;
    5.64 +
    5.65      typedef std::map<Value, Key> InverseMap;
    5.66      
    5.67      typedef typename _Map::ConstReference ConstReference;
    5.68 @@ -64,7 +92,7 @@
    5.69      
    5.70      /// \brief The setter function of the map.
    5.71      ///
    5.72 -    /// It sets the map and the inverse map to given key-value pair.
    5.73 +
    5.74      void set(const Key& key, const Value& val) {
    5.75        Value oldval = Map::operator[](key);
    5.76        typename InverseMap::iterator it = invMap.find(oldval);
    5.77 @@ -140,7 +168,7 @@
    5.78    template <
    5.79      typename _Graph,   
    5.80      typename _Item,
    5.81 -    typename _Map
    5.82 +    typename _Map = typename ItemSetTraits<_Graph, _Item>::template Map<int>
    5.83    >
    5.84    class DescriptorMap : protected _Map {
    5.85  
    5.86 @@ -237,6 +265,7 @@
    5.87      typedef _Graph Graph;
    5.88      typedef int Value;
    5.89      typedef _Item Item;
    5.90 +    typedef _Item Key;
    5.91  
    5.92      /// \brief The class represents the inverse of the map.
    5.93      ///
     6.1 --- a/src/lemon/vector_map.h	Fri Mar 25 22:11:28 2005 +0000
     6.2 +++ b/src/lemon/vector_map.h	Fri Mar 25 23:31:57 2005 +0000
     6.3 @@ -20,6 +20,8 @@
     6.4  #include <vector>
     6.5  #include <algorithm>
     6.6  
     6.7 +#include <lemon/utility.h>
     6.8 +#include <lemon/map_iterator.h>
     6.9  #include <lemon/alteration_notifier.h>
    6.10  
    6.11  ///\ingroup graphmaps
    6.12 @@ -44,9 +46,11 @@
    6.13    /// \author Balazs Dezso
    6.14    	
    6.15  
    6.16 -  template <typename _Graph, 
    6.17 -	    typename _Item,
    6.18 -	    typename _Value>
    6.19 +  template <
    6.20 +    typename _Graph, 
    6.21 +    typename _Item,    
    6.22 +    typename _Value
    6.23 +    >
    6.24    class VectorMap : public AlterationNotifier<_Item>::ObserverBase {
    6.25    public:
    6.26  		
    6.27 @@ -83,6 +87,8 @@
    6.28      /// The pointer type of the map;
    6.29      typedef typename Container::const_pointer ConstPointer;
    6.30  
    6.31 +    typedef True FullTypeTag;
    6.32 +
    6.33      /// Constructor to attach the new map into the registry.
    6.34  
    6.35      /// It construates a map and attachs it into the registry.
    6.36 @@ -205,7 +211,7 @@
    6.37      void clear() { 
    6.38        container.clear();
    6.39      }
    6.40 -
    6.41 +    
    6.42    private:
    6.43  		
    6.44      Container container;
    6.45 @@ -232,15 +238,15 @@
    6.46      typedef typename Parent::EdgeNotifier EdgeObserverRegistry;
    6.47  
    6.48      
    6.49 -
    6.50      template <typename _Value>
    6.51 -    class NodeMap : public VectorMap<Graph, Node, _Value> {
    6.52 +    class NodeMap : 
    6.53 +      public IterableMapExtender<VectorMap<Graph, Node, _Value> > {
    6.54      public:
    6.55        typedef VectorMappableGraphExtender<_Base> Graph;
    6.56  
    6.57        typedef typename Graph::Node Node;
    6.58  
    6.59 -      typedef VectorMap<Graph, Node, _Value> Parent;
    6.60 +      typedef IterableMapExtender<VectorMap<Graph, Node, _Value> > Parent;
    6.61  
    6.62        //typedef typename Parent::Graph Graph;
    6.63        typedef typename Parent::Value Value;
    6.64 @@ -253,13 +259,14 @@
    6.65      };
    6.66  
    6.67      template <typename _Value>
    6.68 -    class EdgeMap : public VectorMap<Graph, Edge, _Value> {
    6.69 +    class EdgeMap 
    6.70 +      : public IterableMapExtender<VectorMap<Graph, Edge, _Value> > {
    6.71      public:
    6.72        typedef VectorMappableGraphExtender<_Base> Graph;
    6.73  
    6.74        typedef typename Graph::Edge Edge;
    6.75  
    6.76 -      typedef VectorMap<Graph, Edge, _Value> Parent;
    6.77 +      typedef IterableMapExtender<VectorMap<Graph, Edge, _Value> > Parent;
    6.78  
    6.79        //typedef typename Parent::Graph Graph;
    6.80        typedef typename Parent::Value Value;
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/work/deba/iterator_test.cpp	Fri Mar 25 23:31:57 2005 +0000
     7.3 @@ -0,0 +1,115 @@
     7.4 +#include <iostream>
     7.5 +#include <algorithm>
     7.6 +#include <iterator>
     7.7 +#include <functional>
     7.8 +#include <lemon/list_graph.h>
     7.9 +#include <lemon/map_iterator.h>
    7.10 +#include <lemon/graph_reader.h>
    7.11 +#include <lemon/maps.h>
    7.12 +
    7.13 +using namespace std;
    7.14 +using namespace lemon;
    7.15 +
    7.16 +template <typename F, typename G>
    7.17 +struct unary_compose {
    7.18 +  typedef typename G::argument_type argument_type;
    7.19 +  typedef typename F::result_type result_type;
    7.20 +  
    7.21 +  unary_compose(const F& _f, const G& _g) : f(_f), g(_g) {}
    7.22 +
    7.23 +  result_type operator()(const argument_type& x) {
    7.24 +    return f(g(x));
    7.25 +  }
    7.26 +
    7.27 +private:
    7.28 +  F f;
    7.29 +  G g;
    7.30 +};
    7.31 +
    7.32 +template <typename F, typename G>
    7.33 +unary_compose<F, G> compose1(const F& f, const G& g) {
    7.34 +  return unary_compose<F, G>(f, g);
    7.35 +}
    7.36 +
    7.37 +
    7.38 +
    7.39 +
    7.40 +template <typename T>
    7.41 +struct Second {
    7.42 +  typedef T argument_type;
    7.43 +  typedef typename T::second_type result_type;
    7.44 +
    7.45 +  typename T::second_type operator()(const T& t) const {
    7.46 +    return t.second;
    7.47 +  }
    7.48 +};
    7.49 +
    7.50 +template <typename T>
    7.51 +struct First {
    7.52 +  typedef T argument_type;
    7.53 +  typedef typename T::first_type result_type;
    7.54 +  typename T::first_type operator()(const T& t) const {
    7.55 +    return t.first;
    7.56 +  }
    7.57 +};
    7.58 +
    7.59 +
    7.60 +int main() {
    7.61 +
    7.62 +  typedef ListGraph Graph;
    7.63 +
    7.64 +  typedef Graph::Edge Edge;
    7.65 +  typedef Graph::Node Node;
    7.66 +  typedef Graph::EdgeIt EdgeIt;
    7.67 +  typedef Graph::NodeIt NodeIt;
    7.68 +  typedef Graph::EdgeMap<int> LengthMap;
    7.69 +
    7.70 +  typedef IdMap<Graph, Edge> EdgeIdMap;
    7.71 +
    7.72 +  Graph graph;
    7.73 +  LengthMap length(graph);
    7.74 +
    7.75 +  readGraph(std::cin, graph, length);
    7.76 +
    7.77 +  const LengthMap& constLength = length;
    7.78 +
    7.79 +  copy(length.valueSet().begin(), length.valueSet().end(), 
    7.80 +       ostream_iterator<int>(cout, " "));
    7.81 +  cout << endl;
    7.82 +
    7.83 +
    7.84 +  copy(constLength.valueSet().begin(), constLength.valueSet().end(), 
    7.85 +       ostream_iterator<int>(cout, " "));
    7.86 +  cout << endl;
    7.87 +
    7.88 +
    7.89 +  transform(constLength.keySet().begin(), constLength.keySet().end(), 
    7.90 +	    ostream_iterator<int>(cout, " "), 
    7.91 +	    MapFunctor<EdgeIdMap>(EdgeIdMap(graph)));
    7.92 +  cout << endl;
    7.93 +
    7.94 +
    7.95 +  transform(constLength.mapSet().begin(), constLength.mapSet().end(), 
    7.96 +	    ostream_iterator<int>(cout, " "), 
    7.97 +	    Second<LengthMap::MapSet::Value>());
    7.98 +  cout << endl;
    7.99 +
   7.100 +  transform(constLength.mapSet().begin(), constLength.mapSet().end(), 
   7.101 +	    ostream_iterator<int>(cout, " "), 
   7.102 +	    compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)), 
   7.103 +		     First<LengthMap::MapSet::Value>() ));
   7.104 +  cout << endl;
   7.105 +
   7.106 +  transform(length.mapSet().begin(), length.mapSet().end(), 
   7.107 +	    ostream_iterator<int>(cout, " "), 
   7.108 +	    Second<LengthMap::MapSet::Value>());
   7.109 +  cout << endl;
   7.110 +
   7.111 +  transform(length.mapSet().begin(), length.mapSet().end(), 
   7.112 +	    ostream_iterator<int>(cout, " "), 
   7.113 +	    compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)), 
   7.114 +		     First<LengthMap::MapSet::Value>() ));
   7.115 +  cout << endl;
   7.116 +
   7.117 +  return 0;
   7.118 +}
     8.1 --- a/src/work/deba/test.cpp	Fri Mar 25 22:11:28 2005 +0000
     8.2 +++ b/src/work/deba/test.cpp	Fri Mar 25 23:31:57 2005 +0000
     8.3 @@ -4,7 +4,7 @@
     8.4  
     8.5  #include <lemon/utility.h>
     8.6  
     8.7 -using namespace std;
     8.8 +using namespace lemon;
     8.9  /*
    8.10  struct _EmptyList {
    8.11    void write() const {}
    8.12 @@ -57,31 +57,28 @@
    8.13  class A {
    8.14  public:
    8.15    typedef int X;
    8.16 +  typedef True XD;
    8.17  };
    8.18  
    8.19  class C {
    8.20  };
    8.21  
    8.22 -template <typename A> 
    8.23 -class TRUE {
    8.24 +
    8.25 +template <typename _A, bool _B = false> 
    8.26 +class B {
    8.27 +public:
    8.28 +  static const bool state = false;
    8.29 +};
    8.30 +
    8.31 +template <typename _A> 
    8.32 +class B<_A, typename enable_if<typename _A::XD, void>::type> {
    8.33  public:
    8.34    static const bool state = true;
    8.35  };
    8.36  
    8.37 -template <typename _A> 
    8.38 -class B {
    8.39 -public:
    8.40 -  typedef enable_if<A::X, int> state;
    8.41 -};
    8.42 -
    8.43 -template <typename _A>
    8.44 -class B<_A, void> {
    8.45 -public:
    8.46 -  static const bool state = true;
    8.47 -};
    8.48  
    8.49  int main() {
    8.50 -  printf("%s\n", B<A>::state(), true ? "true" : "false");
    8.51 -  printf("%s\n", B<C>::state(), true ? "true" : "false");
    8.52 +  printf("%s\n", B<A>::state ? "true" : "false");
    8.53 +  printf("%s\n", B<C>::state ? "true" : "false");
    8.54    return 0;
    8.55  }