Index: src/hugo/smart_graph.h
===================================================================
--- src/hugo/smart_graph.h	(revision 774)
+++ src/hugo/smart_graph.h	(revision 782)
@@ -9,7 +9,13 @@
 
 #include <vector>
-#include <limits.h>
+#include <climits>
 
 #include <hugo/invalid.h>
+
+#include <hugo/array_map_factory.h>
+#include <hugo/sym_map_factory.h>
+#include <hugo/map_registry.h>
+
+#include <hugo/map_defines.h>
 
 namespace hugo {
@@ -17,5 +23,5 @@
 /// \addtogroup graphs
 /// @{
-  class SymSmartGraph;
+//  class SymSmartGraph;
 
   ///A smart graph class.
@@ -54,37 +60,11 @@
     std::vector<EdgeT> edges;
     
-    protected:
-    
-    template <typename Key> class DynMapBase
-    {
-    protected:
-      const SmartGraph* G; 
-    public:
-      virtual void add(const Key k) = 0;
-      virtual void erase(const Key k) = 0;
-      DynMapBase(const SmartGraph &_G) : G(&_G) {}
-      virtual ~DynMapBase() {}
-      friend class SmartGraph;
-    };
     
   public:
-    template <typename T> class EdgeMap;
-    template <typename T> class NodeMap;
+
+    typedef SmartGraph Graph;
 
     class Node;
     class Edge;
-
-    //  protected:
-    // HELPME:
-  protected:
-    ///\bug It must be public because of SymEdgeMap.
-    ///
-    mutable std::vector<DynMapBase<Node> * > dyn_node_maps;
-    ///\bug It must be public because of SymEdgeMap.
-    ///
-    mutable std::vector<DynMapBase<Edge> * > dyn_edge_maps;
-    
-  public:
-
 
     class NodeIt;
@@ -93,6 +73,6 @@
     class InEdgeIt;
     
-    template <typename T> class NodeMap;
-    template <typename T> class EdgeMap;
+    CREATE_MAP_REGISTRIES;
+    CREATE_MAPS(ArrayMapFactory);
     
   public:
@@ -101,12 +81,4 @@
     SmartGraph(const SmartGraph &_g) : nodes(_g.nodes), edges(_g.edges) { }
     
-    ~SmartGraph()
-    {
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).G=NULL;
-      for(std::vector<DynMapBase<Edge> * >::iterator i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).G=NULL;
-    }
-
     int nodeNum() const { return nodes.size(); }  //FIXME: What is this?
     int edgeNum() const { return edges.size(); }  //FIXME: What is this?
@@ -138,7 +110,6 @@
       nodes.push_back(NodeT()); //FIXME: Hmmm...
 
-      for(std::vector<DynMapBase<Node> * >::iterator i=dyn_node_maps.begin();
-	  i!=dyn_node_maps.end(); ++i) (**i).add(n);
-
+      
+      node_maps.add(n);
       return n;
     }
@@ -151,6 +122,5 @@
       nodes[u.n].first_out=nodes[v.n].first_in=e.n;
 
-      for(std::vector<DynMapBase<Edge> * >::iterator i=dyn_edge_maps.begin();
-	  i!=dyn_edge_maps.end(); ++i) (**i).add(e);
+      edge_maps.add(e);
 
       return e;
@@ -173,5 +143,10 @@
     }
     
-    void clear() {nodes.clear();edges.clear();}
+    void clear() {
+      edge_maps.clear();
+      edges.clear();
+      node_maps.clear();
+      nodes.clear();
+    }
 
     class Node {
@@ -289,182 +264,4 @@
 //       ///Validity check
 //       operator bool() { return Edge::operator bool(); }      
-    };
-
-    template <typename T> class NodeMap : public DynMapBase<Node>
-    {
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Node KeyType;
-
-      NodeMap(const SmartGraph &_G) :
-	DynMapBase<Node>(_G), container(_G.maxNodeId())
-      {
-	G->dyn_node_maps.push_back(this);
-      }
-      NodeMap(const SmartGraph &_G,const T &t) :
-	DynMapBase<Node>(_G), container(_G.maxNodeId(),t)
-      {
-	G->dyn_node_maps.push_back(this);
-      }
-      
-      NodeMap(const NodeMap<T> &m) :
- 	DynMapBase<Node>(*m.G), container(m.container)
-      {
- 	G->dyn_node_maps.push_back(this);
-      }
-
-      template<typename TT> friend class NodeMap;
- 
-      ///\todo It can copy between different types.
-      ///\todo We could use 'copy'
-      template<typename TT> NodeMap(const NodeMap<TT> &m) :
-	DynMapBase<Node>(*m.G), container(m.container.size())
-      {
-	G->dyn_node_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      ~NodeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Node>* >::iterator i;
-	  for(i=G->dyn_node_maps.begin();
-	      i!=G->dyn_node_maps.end() && *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_node_maps.erase(i); //FIXME: Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=G->dyn_node_maps.back();
-	    G->dyn_node_maps.pop_back();
-	  }
-	}
-      }
-
-      void add(const Node k) 
-      {
-	if(k.n>=int(container.size())) container.resize(k.n+1);
-      }
-
-      void erase(const Node) { }
-      
-      void set(Node n, T a) { container[n.n]=a; }
-      //'T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::reference
-      operator[](Node n) { return container[n.n]; }
-      //'const T& operator[](Node n)' would be wrong here
-      typename std::vector<T>::const_reference 
-      operator[](Node n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const NodeMap<T>& operator=(const NodeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const NodeMap<T>& operator=(const NodeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for Dynamic Maps
-      void update(T a) {}  //Useless for Dynamic Maps
-    };
-    
-    template <typename T> class EdgeMap : public DynMapBase<Edge>
-    {
-      std::vector<T> container;
-
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
-
-      EdgeMap(const SmartGraph &_G) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId())
-      {
-	//FIXME: What if there are empty Id's?
-	//FIXME: Can I use 'this' in a constructor?
-	G->dyn_edge_maps.push_back(this);
-      }
-      EdgeMap(const SmartGraph &_G,const T &t) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId(),t)
-      {
-	G->dyn_edge_maps.push_back(this);
-      } 
-      EdgeMap(const EdgeMap<T> &m) :
- 	DynMapBase<Edge>(*m.G), container(m.container)
-      {
- 	G->dyn_edge_maps.push_back(this);
-      }
-
-      template<typename TT> friend class EdgeMap;
-
-      ///\todo It can copy between different types.
-      template<typename TT> EdgeMap(const EdgeMap<TT> &m)
-	: DynMapBase<Edge>(*m.G), container(m.container.size())
-      {
-	G->dyn_edge_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
-      ~EdgeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Edge>* >::iterator i;
-	  for(i=G->dyn_edge_maps.begin();
-	      i!=G->dyn_edge_maps.end() && *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=G->dyn_edge_maps.back();
-	    G->dyn_edge_maps.pop_back();
-	  }
-	}
-      }
-      
-      void add(const Edge k) 
-      {
-	if(k.n>=int(container.size())) container.resize(k.n+1);
-      }
-      void erase(const Edge) { }
-      
-      void set(Edge n, T a) { container[n.n]=a; }
-      //T get(Edge n) const { return container[n.n]; }
-      typename std::vector<T>::reference
-      operator[](Edge n) { return container[n.n]; }
-      typename std::vector<T>::const_reference
-      operator[](Edge n) const { return container[n.n]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const EdgeMap<T>& operator=(const EdgeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const EdgeMap<T>& operator=(const EdgeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for DynMaps
-      void update(T a) {}  //Useless for DynMaps
     };
 
@@ -494,6 +291,12 @@
   {
   public:
-    template<typename T> class SymEdgeMap;
-    template<typename T> friend class SymEdgeMap;
+    typedef SymSmartGraph Graph;
+
+    KEEP_NODE_MAP(SmartGraph);
+    KEEP_EDGE_MAP(SmartGraph);
+
+    CREATE_SYM_EDGE_MAP_REGISTRY;
+    CREATE_SYM_EDGE_MAP_FACTORY(ArrayMapFactory);
+    IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
 
     SymSmartGraph() : SmartGraph() { }
@@ -518,105 +321,8 @@
     }
     
-    ///Common data storage for the edge pairs.
-
-    ///This map makes it possible to store data shared by the oppositely
-    ///directed pairs of edges.
-    template <typename T> class SymEdgeMap : public DynMapBase<Edge>
-    {
-      std::vector<T> container;
-      
-    public:
-      typedef T ValueType;
-      typedef Edge KeyType;
-
-      SymEdgeMap(const SymSmartGraph &_G) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId()/2)
-      {
-	static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.push_back(this);
-      }
-      SymEdgeMap(const SymSmartGraph &_G,const T &t) :
-	DynMapBase<Edge>(_G), container(_G.maxEdgeId()/2,t)
-      {
-	G->dyn_edge_maps.push_back(this);
-      }
-
-      SymEdgeMap(const SymEdgeMap<T> &m) :
- 	DynMapBase<SymEdge>(*m.G), container(m.container)
-      {
- 	G->dyn_node_maps.push_back(this);
-      }
-
-      //      template<typename TT> friend class SymEdgeMap;
-
-      ///\todo It can copy between different types.
-      ///
-
-      template<typename TT> SymEdgeMap(const SymEdgeMap<TT> &m)
-	: DynMapBase<SymEdge>(*m.G), container(m.container.size())
-      {
-	G->dyn_node_maps.push_back(this);
-	typename std::vector<TT>::const_iterator i;
-	for(typename std::vector<TT>::const_iterator i=m.container.begin();
-	    i!=m.container.end();
-	    i++)
-	  container.push_back(*i);
-      }
- 
-      ~SymEdgeMap()
-      {
-	if(G) {
-	  std::vector<DynMapBase<Edge>* >::iterator i;
-	  for(i=static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.begin();
-	      i!=static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.end()
-		&& *i!=this; ++i) ;
-	  //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow...
-	  //A better way to do that: (Is this really important?)
-	  if(*i==this) {
-	    *i=static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.back();
-	    static_cast<const SymSmartGraph*>(G)->dyn_edge_maps.pop_back();
-	  }
-	}
-      }
-      
-      void add(const Edge k) 
-      {
-	if(!k.idref()%2&&k.idref()/2>=int(container.size()))
-	  container.resize(k.idref()/2+1);
-      }
-      void erase(const Edge k) { }
-      
-      void set(Edge n, T a) { container[n.idref()/2]=a; }
-      //T get(Edge n) const { return container[n.idref()/2]; }
-      typename std::vector<T>::reference
-      operator[](Edge n) { return container[n.idref()/2]; }
-      typename std::vector<T>::const_reference
-      operator[](Edge n) const { return container[n.idref()/2]; }
-
-      ///\warning There is no safety check at all!
-      ///Using operator = between maps attached to different graph may
-      ///cause serious problem.
-      ///\todo Is this really so?
-      ///\todo It can copy between different types.
-      const SymEdgeMap<T>& operator=(const SymEdgeMap<T> &m)
-      {
-	container = m.container;
-	return *this;
-      }
-      template<typename TT>
-      const SymEdgeMap<T>& operator=(const SymEdgeMap<TT> &m)
-      {
-	std::copy(m.container.begin(), m.container.end(), container.begin());
-	return *this;
-      }
-      
-      void update() {}    //Useless for DynMaps
-      void update(T a) {}  //Useless for DynMaps
-
-    };
 
   };
   
   /// @}  
-
 } //namespace hugo
 
