Index: src/lemon/vector_map.h
===================================================================
--- src/lemon/vector_map.h	(revision 937)
+++ src/lemon/vector_map.h	(revision 946)
@@ -19,7 +19,7 @@
 
 #include <vector>
-
-#include <lemon/map_iterator.h>
-#include <lemon/map_bits.h>
+#include <algorithm>
+
+#include <lemon/alteration_observer_registry.h>
 
 ///\ingroup graphmaps
@@ -32,32 +32,39 @@
   /// @{
   
-  /** The VectorMap template class is graph map structure what
-   *  automatically updates the map when a key is added to or erased from
-   *  the map. This map factory uses the allocators to implement 
-   *  the container functionality. This map factory
-   *  uses the std::vector to implement the container function.
-   *
-   *  \param MapRegistry The MapRegistry that the maps will belong to.
-   *  \param Value The value type of the map.
-   * 
-   *  \author Balazs Dezso
-   */
-	
-  template <typename MapRegistry, typename Value>
-  class VectorMap : public MapRegistry::MapBase {
-    template <typename MR, typename T> friend class VectorMap;
+  /// The VectorMap template class is graph map structure what
+  /// automatically updates the map when a key is added to or erased from
+  /// the map. This map factory uses the allocators to implement 
+  /// the container functionality. This map factory
+  /// uses the std::vector to implement the container function.
+  ///
+  /// \param Registry The AlterationObserverRegistry that will notify this map.
+  /// \param IdMap The IdMap type of the graph items.
+  /// \param Value The value type of the map.
+  /// 
+  /// \author Balazs Dezso
+  	
+
+  template <typename _Graph, 
+	    typename _Item,
+	    typename _IdMap,
+	    typename _Value>
+  class VectorMap : public AlterationObserverRegistry<_Item>::ObserverBase {
   public:
 		
-    /// The graph type of the maps. 
-    typedef typename MapRegistry::Graph Graph;
-    /// The key type of the maps.
-    typedef typename MapRegistry::KeyType KeyType;
-    /// The iterator to iterate on the keys.
-    typedef typename MapRegistry::KeyIt KeyIt;
+    /// The graph type of the map. 
+    typedef _Graph Graph;
+    /// The key type of the map.
+    typedef _Item KeyType;
+    /// The id map type of the map.
+    typedef _IdMap IdMap;
+    /// The registry type of the map.
+    typedef AlterationObserverRegistry<_Item> Registry;
+    /// The value type of the map.
+    typedef _Value Value;
 
     /// The map type.
     typedef VectorMap Map;
-    /// The MapBase of the Map which implements the core regisitry function.
-    typedef typename MapRegistry::MapBase MapBase;
+    /// The base class of the map.
+    typedef typename Registry::ObserverBase Parent;
 
   private:
@@ -67,5 +74,4 @@
 
   public:
-
 
     /// The value type of the map.
@@ -83,93 +89,96 @@
     typedef typename Container::const_pointer ConstPointerType;
 
-    /// Constructor to attach the new map into a registry.
-
-    /** Constructor to attach the new map into a registry.
-     *  It adds all the nodes or edges of the graph to the map.
+    /// Constructor to attach the new map into the registry.
+
+    /// It construates a map and attachs it into the registry.
+    /// It adds all the items of the graph to the map.
+     
+    VectorMap(const Graph& _g, Registry& _r) : graph(&_g) {
+      attach(_r);
+      build();
+    }
+
+    /// Constructor uses given value to initialize the map. 
+
+    /// It construates a map uses a given value to initialize the map. 
+    /// It adds all the items of the graph to the map.
+     
+    VectorMap(const Graph& g, Registry& r, const Value& v) : graph(&g) { 
+      attach(r);
+      container.resize(IdMap(*graph).maxId() + 1, v);
+    }
+
+    VectorMap(const VectorMap& copy) : graph(copy.getGraph()) {
+      if (copy.attached()) {
+	attach(*copy.getRegistry());
+	container = copy.container;
+      }
+    }
+
+
+    /** Assign operator to copy a map of the same map type.
      */
-    VectorMap(const Graph& g, MapRegistry& r) 
-      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1) {}
-
-    /// Constructor uses given value to initialize the map. 
-
-    /** Constructor uses given value to initialize the map. 
-     *  It adds all the nodes or edges of the graph to the map.
-     */
-    VectorMap(const Graph& g, MapRegistry& r, const Value& v) 
-      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
-
-    /// Assign operator to copy a map of an other map type.
-
-    /** Assign operator to copy a map of an other map type.
-     *  This map's value type must be assignable by the other
-     *  map type's value type.
-     */
-    template <typename TT>
-    VectorMap(const VectorMap<MapRegistry, TT>& c) 
-      : MapBase(c), container(c.container.size()) {
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
-	container[id] = c.container[id];
-      }
-    }
-
-    /// Assign operator to copy a map of an other map type.
-
-    /** Assign operator to copy a map of an other map type.
-     *  This map's value type must be assignable by the other
-     *  map type's value type.
-     */
-    template <typename TT>
-    VectorMap& operator=(const VectorMap<MapRegistry, TT>& c) {
-      if (MapBase::getGraph() != c.getGraph()) {
-	MapBase::operator=(c);
-	container.resize(c.container.size());
-      }
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
-	container[id] = c.container[id];
-      }
+    VectorMap& operator=(const VectorMap& copy) {
+      if (&copy == this) return *this;
+      
+      if (graph != copy.graph) {
+	if (attached()) {
+	  detach();
+	}
+	if (copy.attached()) {
+	  attach(*copy.getRegistry());
+	}
+      }
+      container = copy.container;
+
       return *this;
     }
 
+
+    virtual ~VectorMap() {
+      if (attached()) {
+	detach();
+      }
+    }
+
+    const Graph* getGraph() const {
+      return graph;
+    }
+
     /// The subcript operator.
 
-    /**
-     * The subscript operator. The map can be subscripted by the
-     * actual keys of the graph. 
-     */
+    /// The subscript operator. The map can be subscripted by the
+    /// actual items of the graph. 
+     
     ReferenceType operator[](const KeyType& key) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
-      return container[id];
+      return container[IdMap(*graph)[key]];
     } 
 		
     /// The const subcript operator.
 
-    /**
-     * The const subscript operator. The map can be subscripted by the
-     * actual keys of the graph. 
-     */
+    /// The const subscript operator. The map can be subscripted by the
+    /// actual items of the graph. 
+     
     ConstReferenceType operator[](const KeyType& key) const {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
-      return container[id];
-    }
-
-    ///Setter function of the map.
-
-    /** Setter function of the map. Equivalent with map[key] = val.
-     *  This is a compatibility feature with the not dereferable maps.
-     */
-    void set(const KeyType& key, const ValueType& val) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
-      container[id] = val;
-    }
+      return container[IdMap(*graph)[key]];
+    }
+
+
+    /// The setter function of the map.
+
+    /// It the same as operator[](key) = value expression.
+    ///
+     
+    void set(const KeyType& key, const ValueType& value) {
+      (*this)[key] = value;
+    }
+
     /// Adds a new key to the map.
 		
-    /** Adds a new key to the map. It called by the map registry
-     *  and it overrides the \ref MapRegistry::MapBase MapBase's
-     *  add() member function.
-     */
+    /// It adds a new key to the map. It called by the observer registry
+    /// and it overrides the add() member function of the observer base.
+     
     void add(const KeyType& key) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
+      int id = IdMap(*graph)[key];
       if (id >= (int)container.size()) {
 	container.resize(id + 1);
@@ -179,91 +188,92 @@
     /// Erases a key from the map.
 		
-    /** Erase a key from the map. It called by the map registry 
-     *  and it overrides the \ref MapRegistry::MapBase MapBase's
-     *  erase() member function.
-     */
+    /// Erase a key from the map. It called by the observer registry
+    /// and it overrides the erase() member function of the observer base.     
     void erase(const KeyType& key) {}
 
-    /// Makes empty the map.
-
-    /** Makes empty the map. It called by the map registry 
-     *  and it overrides the \ref MapRegistry::MapBase MapBase's
-     *  clear() member function.
-     */
-
+    /// Buildes the map.
+		
+    /// It buildes the map. It called by the observer registry
+    /// and it overrides the build() member function of the observer base.
+
+    void build() { 
+      container.resize(IdMap(*graph).maxId() + 1);
+    }
+
+    /// Clear the map.
+
+    /// It erase all items from the map. It called by the observer registry
+    /// and it overrides the clear() member function of the observer base.     
     void clear() { 
       container.clear();
     }
 
-    /// The stl compatible pair iterator of the map.
-    typedef MapIterator<VectorMap> Iterator;
-    /// The stl compatible const pair iterator of the map.
-    typedef MapConstIterator<VectorMap> ConstIterator;
-
-    /** Returns the begin iterator of the map.
-     */
-    Iterator begin() {
-      return Iterator(*this, KeyIt(*MapBase::getGraph()));
-    }
-
-    /** Returns the end iterator of the map.
-     */
-    Iterator end() {
-      return Iterator(*this, INVALID);
-    }
-
-    /** Returns the begin ConstIterator of the map.
-     */
-    ConstIterator begin() const {
-      return ConstIterator(*this, KeyIt(*MapBase::getGraph()));
-    }
-
-    /** Returns the end const_iterator of the map.
-     */
-    ConstIterator end() const {
-      return ConstIterator(*this, INVALID);
-    }
-
-    /// The KeySet of the Map.
-    typedef MapConstKeySet<VectorMap> ConstKeySet;
-
-    /// KeySet getter function.
-    ConstKeySet keySet() const {
-      return ConstKeySet(*this); 
-    }
-
-    /// The ConstValueSet of the Map.
-    typedef MapConstValueSet<VectorMap> ConstValueSet;
-
-    /// ConstValueSet getter function.
-    ConstValueSet valueSet() const {
-      return ConstValueSet(*this);
-    }
-
-    /// The ValueSet of the Map.
-    typedef MapValueSet<VectorMap> ValueSet;
-
-    /// ValueSet getter function.
-    ValueSet valueSet() {
-      return ValueSet(*this);
-    }
-
-
   private:
 		
     Container container;
-
+    const Graph *graph;
+
+  };
+
+
+  template <typename _Base> 
+  class VectorMappableGraphExtender : public _Base {
   public:
-    // STL  compatibility typedefs.
-    typedef Iterator iterator;
-    typedef ConstIterator const_iterator;
-    typedef typename Iterator::PairValueType value_type;
-    typedef typename Iterator::KeyType key_type;
-    typedef typename Iterator::ValueType data_type;
-    typedef typename Iterator::PairReferenceType reference;
-    typedef typename Iterator::PairPointerType pointer;
-    typedef typename ConstIterator::PairReferenceType const_reference;
-    typedef typename ConstIterator::PairPointerType const_pointer;
-    typedef int difference_type;		
+
+    typedef VectorMappableGraphExtender<_Base> Graph;
+    typedef _Base Parent;
+
+    typedef typename Parent::Node Node;
+    typedef typename Parent::NodeIt NodeIt;
+    typedef typename Parent::NodeIdMap NodeIdMap;
+    typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
+
+    typedef typename Parent::Edge Edge;
+    typedef typename Parent::EdgeIt EdgeIt;
+    typedef typename Parent::EdgeIdMap EdgeIdMap;
+    typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
+
+    
+
+    template <typename _Value>
+    class NodeMap : public VectorMap<Graph, Node, NodeIdMap, _Value> {
+    public:
+      typedef VectorMappableGraphExtender<_Base> Graph;
+
+      typedef typename Graph::Node Node;
+      typedef typename Graph::NodeIdMap NodeIdMap;
+
+      typedef VectorMap<Graph, Node, NodeIdMap, _Value> Parent;
+
+      typedef typename Parent::Graph Graph;
+      typedef typename Parent::Value Value;
+
+      NodeMap(const Graph& g) 
+	: Parent(g, g.getNodeObserverRegistry()) {}
+      NodeMap(const Graph& g, const Value& v) 
+	: Parent(g, g.getNodeObserverRegistry(), v) {}
+
+    };
+
+    template <typename _Value>
+    class EdgeMap : public VectorMap<Graph, Edge, EdgeIdMap, _Value> {
+    public:
+      typedef VectorMappableGraphExtender<_Base> Graph;
+
+      typedef typename Graph::Edge Edge;
+      typedef typename Graph::EdgeIdMap EdgeIdMap;
+
+      typedef VectorMap<Graph, Edge, EdgeIdMap, _Value> Parent;
+
+      typedef typename Parent::Graph Graph;
+      typedef typename Parent::Value Value;
+
+      EdgeMap(const Graph& g) 
+	: Parent(g, g.getEdgeObserverRegistry()) {}
+      EdgeMap(const Graph& g, const Value& v) 
+	: Parent(g, g.getEdgeObserverRegistry(), v) {}
+
+    };
+    
   };
   
