Index: src/lemon/array_map.h
===================================================================
--- src/lemon/array_map.h	(revision 921)
+++ src/lemon/array_map.h	(revision 946)
@@ -21,5 +21,4 @@
 
 #include <lemon/map_iterator.h>
-#include <lemon/map_bits.h>
 
 ///\ingroup graphmaps
@@ -43,20 +42,30 @@
    */
 
-  template <typename MapRegistry, typename Value> 
-  class ArrayMap : public MapRegistry::MapBase {
-
-    template <typename MR, typename V> friend class ArrayMap;
-		
+  template <typename _Graph, 
+	    typename _Item,
+	    typename _ItemIt,
+	    typename _IdMap,
+	    typename _Value>
+  class ArrayMap : public AlterationObserverRegistry<_Item>::ObserverBase {
+
   public:
 		
     /// The graph type of the maps. 
-    typedef typename MapRegistry::Graph Graph;
+    typedef _Graph Graph;
     /// The key type of the maps.
-    typedef typename MapRegistry::KeyType KeyType;
+    typedef _Item KeyType;
+
+    typedef AlterationObserverRegistry<_Item> Registry;
+
+  private:
     /// The iterator to iterate on the keys.
-    typedef typename MapRegistry::KeyIt KeyIt;
+    typedef _ItemIt KeyIt;
+
+    typedef _IdMap IdMap;
+
+    typedef _Value Value;
 
     /// The MapBase of the Map which imlements the core regisitry function.
-    typedef typename MapRegistry::MapBase MapBase;
+    typedef typename Registry::ObserverBase Parent;
 		
     
@@ -78,25 +87,31 @@
 
 
+  private:
     typedef std::allocator<Value> Allocator;
 
-	
+
+  public:
+
     /** Graph and Registry initialized map constructor.
      */
-    ArrayMap(const Graph& g, MapRegistry& r) : MapBase(g, r) {
+    ArrayMap(const Graph& _g, Registry& _r) : graph(&_g) {
+      attach(_r);
       allocate_memory();
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
+      for (KeyIt it(*graph); it != INVALID; ++it) {
+	int id = IdMap(*graph)[it];
 	allocator.construct(&(values[id]), Value());
       }								
     }
 
-    /** Constructor to use default value to initialize the map. 
-     */
-    ArrayMap(const Graph& g, MapRegistry& r, const Value& v) 
-      : MapBase(g, r) {
+    /// Constructor to use default value to initialize the map. 
+
+    /// It constrates a map and initialize all of the the map. 
+
+    ArrayMap(const Graph& _g, Registry& _r, const Value& _v) : graph(&_g) {
+      attach(_r);
       allocate_memory();
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
-	allocator.construct(&(values[id]), v);
+      for (KeyIt it(*graph); it != INVALID; ++it) {
+	int id = IdMap(*graph)[it];
+	allocator.construct(&(values[id]), _v);
       }								
     }
@@ -104,24 +119,13 @@
     /** Constructor to copy a map of the same map type.
      */
-    ArrayMap(const ArrayMap& copy) : MapBase(copy) {
+    ArrayMap(const ArrayMap& copy) {
+      if (copy.attached()) {
+	attach(*copy.getRegistry());
+      }
       capacity = copy.capacity;
       if (capacity == 0) return;
       values = allocator.allocate(capacity);
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
-	allocator.construct(&(values[id]), copy.values[id]);
-      }
-    }
-
-    /** Constructor to copy a map of an other map type.
-     */
-    template <typename TT>
-    ArrayMap(const ArrayMap<MapRegistry, TT>& copy) 
-      : MapBase(copy) {
-      capacity = copy.capacity;
-      if (capacity == 0) return;
-      values = allocator.allocate(capacity);
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
+      for (KeyIt it(*graph); it != INVALID; ++it) {
+	int id = IdMap(*graph)[it];
 	allocator.construct(&(values[id]), copy.values[id]);
       }
@@ -133,11 +137,12 @@
       if (&copy == this) return *this;
       
-      if (MapBase::getGraph() != copy.getGraph()) {
-	if (capacity != 0) {
-	  MapBase::destroy();
-	  allocator.deallocate(values, capacity);
+      if (graph != copy.graph) {
+	if (attached()) {
+	  clear();
+	  detach();
 	}
-
-	MapBase::operator=(copy);
+	if (copy.attached()) {
+	  attach(*copy.getRegistry());
+	}
 	capacity = copy.capacity;
 	if (capacity == 0) return *this;
@@ -145,6 +150,6 @@
       }
 
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
+      for (KeyIt it(*graph); it != INVALID; ++it) {
+	int id = IdMap(*graph)[it];
 	allocator.construct(&(values[id]), copy.values[id]);
       }
@@ -153,36 +158,10 @@
     }
 
-    /** Assign operator to copy a map of an other map type.
-     */
-    template <typename TT>
-    ArrayMap& operator=(const ArrayMap<MapRegistry, TT>& copy) {
-
-      if (MapBase::getGraph() != copy.getGraph()) {
-	if (capacity != 0) {
-	  MapBase::destroy();
-	  allocator.deallocate(values, capacity);
-	}
-
-	MapBase::operator=(copy);
-
-	capacity = copy.capacity;
-	if (capacity == 0) return *this;
-	values = allocator.allocate(capacity);
-      }
-
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
-	allocator.construct(&(values[id]), copy.values[id]);
-      }
-
-      return *this;
-    }
-				
     /** The destructor of the map.
      */
-    virtual ~ArrayMap() {
-      if (capacity != 0) {
-	MapBase::destroy();
-	allocator.deallocate(values, capacity);
+    virtual ~ArrayMap() {      
+      if (attached()) {
+	clear();
+	detach();
       }
     }
@@ -194,5 +173,5 @@
      */
     ReferenceType operator[](const KeyType& key) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
+      int id = IdMap(*graph)[key];
       return values[id];
     } 
@@ -203,5 +182,5 @@
      */
     ConstReferenceType operator[](const KeyType& key) const {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
+      int id = IdMap(*graph)[key];
       return values[id];
     }
@@ -211,6 +190,5 @@
      */
     void set(const KeyType& key, const ValueType& val) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
-      values[id] = val;
+      (*this)[key] = val;
     }
 		
@@ -218,5 +196,5 @@
      */
     void add(const KeyType& key) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
+      int id = IdMap(*graph)[key];
       if (id >= capacity) {
 	int new_capacity = (capacity == 0 ? 1 : capacity);
@@ -224,7 +202,7 @@
 	  new_capacity <<= 1;
 	}
-	Value* new_values = allocator.allocate(new_capacity);;
-	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	  int jd = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
+	Value* new_values = allocator.allocate(new_capacity);
+	for (KeyIt it(*graph); it != INVALID; ++it) {
+	  int jd = IdMap(*graph)[it];
 	  if (id != jd) {
 	    allocator.construct(&(new_values[jd]), values[jd]);
@@ -242,13 +220,22 @@
      */
     void erase(const KeyType& key) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
+      int id = IdMap(*graph)[key];
       allocator.destroy(&(values[id]));
     }
 
-    /** Clear the data structure.
-     */
+    void build() {
+      allocate_memory();
+      for (KeyIt it(*graph); it != INVALID; ++it) {
+	int id = IdMap(*graph)[it];
+	allocator.construct(&(values[id]), Value());
+      }								
+    }
+
     void clear() {	
       if (capacity != 0) {
-	MapBase::destroy();
+	for (KeyIt it(*graph); it != INVALID; ++it) {
+	  int id = IdMap(*graph)[it];
+	  allocator.destroy(&(values[id]));
+	}								
 	allocator.deallocate(values, capacity);
 	capacity = 0;
@@ -256,61 +243,61 @@
     }
 
-    /// The stl compatible pair iterator of the map.
-    typedef MapIterator<ArrayMap> Iterator;
-    /// The stl compatible const pair iterator of the map.
-    typedef MapConstIterator<ArrayMap> 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<ArrayMap> ConstKeySet;
-
-    /// KeySet getter function.
-    ConstKeySet keySet() const {
-      return ConstKeySet(*this); 
-    }
-
-    /// The ConstValueSet of the Map.
-    typedef MapConstValueSet<ArrayMap> ConstValueSet;
-
-    /// ConstValueSet getter function.
-    ConstValueSet valueSet() const {
-      return ConstValueSet(*this);
-    }
-
-    /// The ValueSet of the Map.
-    typedef MapValueSet<ArrayMap> ValueSet;
-
-    /// ValueSet getter function.
-    ValueSet valueSet() {
-      return ValueSet(*this);
-    }
+//     /// The stl compatible pair iterator of the map.
+//     typedef MapIterator<ArrayMap> Iterator;
+//     /// The stl compatible const pair iterator of the map.
+//     typedef MapConstIterator<ArrayMap> 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<ArrayMap> ConstKeySet;
+
+//     /// KeySet getter function.
+//     ConstKeySet keySet() const {
+//       return ConstKeySet(*this); 
+//     }
+
+//     /// The ConstValueSet of the Map.
+//     typedef MapConstValueSet<ArrayMap> ConstValueSet;
+
+//     /// ConstValueSet getter function.
+//     ConstValueSet valueSet() const {
+//       return ConstValueSet(*this);
+//     }
+
+//     /// The ValueSet of the Map.
+//     typedef MapValueSet<ArrayMap> ValueSet;
+
+//     /// ValueSet getter function.
+//     ValueSet valueSet() {
+//       return ValueSet(*this);
+//     }
 
   private:
       
     void allocate_memory() {
-      int max_id = KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph());
+      int max_id = IdMap(*graph).maxId();
       if (max_id == -1) {
 	capacity = 0;
@@ -325,4 +312,5 @@
     }      
 
+    const Graph* graph;
     int capacity;
     Value* values;
@@ -330,17 +318,80 @@
 
   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;		
+//     // 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;		
   };		
 
+  template <typename _Base> 
+  class ArrayMappableGraphExtender : public _Base {
+  public:
+
+    typedef ArrayMappableGraphExtender<_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 ArrayMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
+    public:
+      typedef ArrayMappableGraphExtender<_Base> Graph;
+
+      typedef typename Graph::Node Node;
+      typedef typename Graph::NodeIt NodeIt;
+      typedef typename Graph::NodeIdMap NodeIdMap;
+
+      typedef ArrayMap<Graph, Node, NodeIt, 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 ArrayMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
+    public:
+      typedef ArrayMappableGraphExtender<_Base> Graph;
+
+      typedef typename Graph::Edge Edge;
+      typedef typename Graph::EdgeIt EdgeIt;
+      typedef typename Graph::EdgeIdMap EdgeIdMap;
+
+      typedef ArrayMap<Graph, Edge, EdgeIt, 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) {}
+
+    };
+    
+  };
+
 /// @}
 
