[Lemon-commits] [lemon_svn] deba: r1308 - in hugo/branches/graph_factory/src: lemon test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:44:31 CET 2006


Author: deba
Date: Sun Oct 24 23:16:19 2004
New Revision: 1308

Added:
   hugo/branches/graph_factory/src/test/map_test.h
Modified:
   hugo/branches/graph_factory/src/lemon/alteration_observer_registry.h
   hugo/branches/graph_factory/src/lemon/array_map.h
   hugo/branches/graph_factory/src/lemon/default_map.h
   hugo/branches/graph_factory/src/lemon/full_graph.h
   hugo/branches/graph_factory/src/lemon/list_graph.h
   hugo/branches/graph_factory/src/lemon/smart_graph.h
   hugo/branches/graph_factory/src/test/graph_test.cc

Log:
redesign array and default maps
graph maps changed to default map
map_test.h to implement functionality test on graph maps



Modified: hugo/branches/graph_factory/src/lemon/alteration_observer_registry.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/alteration_observer_registry.h	(original)
+++ hugo/branches/graph_factory/src/lemon/alteration_observer_registry.h	Sun Oct 24 23:16:19 2004
@@ -34,19 +34,17 @@
   /// Registry class to register objects observes alterations in the graph.
 
 
-  /// This class is a registry for the objects observes the alterations in 
-  /// the graph. The alteration observers can be attached to and detached 
+  /// This class is a registry for the objects which observe the alterations in 
+  /// a container. The alteration observers can be attached to and detached 
   /// from the registry. The observers have to inherit from the /ref 
   /// AlterationObserverRegistry::ObserverBase and override the virtual functions
-  /// in that. The registry observes only one item type by example edge or node 
-  /// alterations.         
+  /// in that.
   ///
   /// The most important application of the alteration observing is the dynamic 
-  /// map implementation.
+  /// map implementation when the observers are observing the alterations in the
+  /// graph.
   ///
-  /// \param G The graph type to be observed.
-  /// \param K The key type alteration will be observed.
-  /// \param KIt The key iterator type iterates on the keys.
+  /// \param _Item The item type what the observers are observing, usually edge or node.
   ///
   /// \author Balazs Dezso
 
@@ -55,7 +53,7 @@
   public:
     typedef _Item Item;
 
-    /// ObserverBase is the base class of the dynamic maps.
+    /// ObserverBase is the base class of the observers.
 	
     /// ObserverBase is the base class of the observers.
     /// It will be notified about an item was inserted into or
@@ -64,8 +62,13 @@
     /// The observer interface contains some virtual function
     /// to override it. The add() and erase() functions are
     /// to notify the oberver about one item is added or
-    /// erased. The build() member function notifies the
-    /// observer.
+    /// erased. 
+    ///
+    /// The build() and clear() members are to notify the observer
+    /// about the container is builded from an empty container or
+    /// the observer is cleared to an empty container. 
+    /// 
+    /// \author Balazs Dezso
 
     class ObserverBase {
     protected:
@@ -87,22 +90,34 @@
 
       virtual ~ObserverBase() {}
 
+      /// Attaches the observer into an AlterationObserverRegistry.
+
+      /// This member attaches the observer into an AlterationObserverRegistry.
+      ///
       void attach(AlterationObserverRegistry& r) {
-	if (registry) {
-	  registry->detach(*this);
-	}
 	registry = &r;
 	registry->attach(*this);
       }
 
+      /// Detaches the observer into an AlterationObserverRegistry.
+
+
+      /// This member detaches the observer from an AlterationObserverRegistry.
+      ///
       void detach() {
 	if (registry) {
 	  registry->detach(*this);
 	}
       }
 	
+
+      /// Gives back a pointer to the registry what the map attached into.
+
+      /// This function gives back a pointer to the registry what the map attached into.
+      ///
       Registry* getRegistry() const { return registry; }
       
+      /// Gives back true when the observer is attached into a registry.
       bool attached() const { return registry != 0; }
 	
     protected:
@@ -117,39 +132,39 @@
 
     protected:
 
-      /// The member function to notificate the observer about an item is added to the graph. 
+      /// The member function to notificate the observer about an item is added to the container. 
 
-      /// The add member function notificates the observer about 
-      /// an item is added to the graph. It have to be overrided in the subclasses.
+      /// The add() member function notificates the observer about 
+      /// an item is added to the container. It have to be overrided in the subclasses.
 	
       virtual void add(const Item&) = 0;	
 
 
-      /// The member function to notificate the observer about an item is erased from the graph. 
+      /// The member function to notificate the observer about an item is erased from the container. 
 
-      /// The erase member function notificates the observer about 
-      /// an item is erased from the graph. It have to be overrided in the subclasses.
+      /// The erase() member function notificates the observer about 
+      /// an item is erased from the container. It have to be overrided in the subclasses.
 	
       virtual void erase(const Item&) = 0;
 
-      /// The member function to notificate the observer about the graph is builded. 
+      /// The member function to notificate the observer about the container is builded. 
 
-      /// The build member function notificates the observer about 
-      /// the graph is builded. It have to be overrided in the subclasses.
+      /// The build() member function notificates the observer about 
+      /// the container is builded from an empty container. It have to be overrided in the subclasses.
 
       virtual void build() = 0;
 
-      /// The member function to notificate the observer about all items are erased from the graph. 
+      /// The member function to notificate the observer about all items are erased from the container. 
 
-      /// The clear member function notificates the observer about 
-      /// all items are erased from the graph. It have to be overrided in the subclasses.
+      /// The clear() member function notificates the observer about 
+      /// all items are erased from the container. It have to be overrided in the subclasses.
       
       virtual void clear() = 0;
 
       /// Exception class to throw at unsupported operation.
 	
       /// Exception class to throw at unsupported operation.
-      /// If the map does not support erasing or adding new
+      /// If the observer does not support erasing or adding new
       /// item then this exception have to be throwed.
 	
       class NotSupportedOperationException {};
@@ -175,7 +190,6 @@
 
     /// Copy Constructor of the AlterationObserverRegistry. 
 	
-
     /// Copy constructor of the AlterationObserverRegistry. 
     /// It creates only an empty registry because the copiable
     /// registry's observers have to be registered still into that registry.
@@ -195,8 +209,8 @@
 
     /// Destructor.
 				
-    /// Destructor of the AlterationObserverRegistry. It calls first the clear() 
-    /// member function of the attached observers and then detachs them.
+    /// Destructor of the AlterationObserverRegistry.
+    ///
     ~AlterationObserverRegistry() {
       typename Container::iterator it;
       for (it = container.begin(); it != container.end(); ++it) {
@@ -207,22 +221,12 @@
 	
   protected:
 
-    /// Attaches the observer into the registry.
-	
-    /// This function attaches the observer into the registry. 
-    /// It is not allowed to call the attach() function when
-    /// observer is already registered into an other registry.
     void attach(ObserverBase& observer) {
       container.push_back(&observer);
       observer.registry = this;
       observer.registry_index = container.size()-1;
     } 
 
-    /// Detaches a observer from the \e AlterationObserverRegistry.
-	
-    /**
-     * Detachs a observer from the \e AlterationObserverRegistry.
-     */
     void detach(ObserverBase& base) {
       container.back()->registry_index = base.registry_index; 
       container[base.registry_index] = container.back();
@@ -232,13 +236,10 @@
 
   public:
 	
-    /// Notify all the registered observers about a Key added.
+    /// Notifies all the registered observers about an Item added to the container.
 		
-    /**
-     * Notify all the registered observers about a Key added.
-     * This member should be called whenever a node or edge
-     * is added to the graph.
-     */
+    /// It notifies all the registered observers about an Item added to the container.
+    /// 
     void add(const Item& key) {
       typename Container::iterator it;
       for (it = container.begin(); it != container.end(); ++it) {
@@ -246,11 +247,10 @@
       }
     }	
 
-    /// Notify all the registered observers about a Key erased.
+    /// Notifies all the registered observers about an Item erased from the container.
 		
-    /// Notify all the registered observers about a Key erased.
-    /// This member should be called whenever a node or edge
-    /// is erased from the graph.
+    /// It notifies all the registered observers about an Item erased from the container.
+    /// 
     void erase(const Item& key) {
       typename Container::iterator it;
       for (it = container.begin(); it != container.end(); ++it) {
@@ -259,6 +259,10 @@
     }
     
 
+    /// Notifies all the registered observers about the container is builded.
+		
+    /// Notifies all the registered observers about the container is builded
+    /// from an empty container.
     void build() {
       typename Container::iterator it;
       for (it = container.begin(); it != container.end(); ++it) {
@@ -267,13 +271,10 @@
     }
 
 
-    /// Notify all the registered observers about all the Keys are erased.
+    /// Notifies all the registered observers about all Items are erased.
 
-    /**
-     * Notify all the registered observers about the observer should be cleared.
-     * This member should be called whenever all of the nodes or edges
-     * are erased from the graph.
-     */ 
+    /// Notifies all the registered observers about all Items are erased
+    /// from the container.
     void clear() {
       typename Container::iterator it;
       for (it = container.begin(); it != container.end(); ++it) {
@@ -282,6 +283,20 @@
     }
   };
 
+
+  /// Class to extend a graph functionality with the possibility of alteration observing.
+
+  /// AlterableGraphExtender extends the _Base graphs functionality with the possibility of 
+  /// alteration observing. It defines two observer registrys for the nodes and mapes.
+  ///
+  /// \param _Base is the base class to extend.
+  ///
+  /// \pre _Base is conform to the BaseGraphComponent concept.
+  ///
+  /// \post AlterableGraphExtender<_Base> is conform to the AlterableGraphComponent concept.
+  ///
+  /// \author Balazs Dezso
+
   template <typename _Base> 
   class AlterableGraphExtender : public _Base {
   public:
@@ -290,15 +305,18 @@
     typedef _Base Parent;
 
     typedef typename Parent::Node Node;
-
     typedef typename Parent::Edge Edge;
 
+    /// The node observer registry.
+    typedef AlterationObserverRegistry<Edge> EdgeObserverRegistry;
+    /// The edge observer registry.
+    typedef AlterationObserverRegistry<Node> NodeObserverRegistry;
+
+
   protected:
 
-    typedef AlterationObserverRegistry<Edge> EdgeObserverRegistry;
     mutable EdgeObserverRegistry edge_observers;
 
-    typedef AlterationObserverRegistry<Node> NodeObserverRegistry;
     mutable NodeObserverRegistry node_observers;
 
   public:

Modified: hugo/branches/graph_factory/src/lemon/array_map.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/array_map.h	(original)
+++ hugo/branches/graph_factory/src/lemon/array_map.h	Sun Oct 24 23:16:19 2004
@@ -54,7 +54,7 @@
     /// The graph type of the maps. 
     typedef _Graph Graph;
     /// The key type of the maps.
-    typedef _Item Key;
+    typedef _Item KeyType;
     /// The iterator to iterate on the keys.
     typedef _ItemIt KeyIt;
 
@@ -92,44 +92,37 @@
      */
     ArrayMap(const Graph& _g, Registry& _r) : graph(&_g) {
       attach(_r);
-      build();
+      allocate_memory();
+      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. 
 
     /// It constrates a map and initialize all of the the map. 
 
-    ArrayMap(const Graph& _g, MapRegistry& _r, const Value& _v) 
-      : graph(&_g) {
+    ArrayMap(const Graph& _g, Registry& _r, const Value& _v) : graph(&_g) {
+      attach(_r);
       allocate_memory();
       for (KeyIt it(*graph); it != INVALID; ++it) {
 	int id = IdMap(*graph)[it];
-	allocator.construct(&(values[id]), v);
+	allocator.construct(&(values[id]), _v);
       }								
     }
 
     /** Constructor to copy a map of the same map type.
      */
-    ArrayMap(const ArrayMap& copy) : MapBase(copy) {
-      capacity = copy.capacity;
-      if (capacity == 0) return;
-      values = allocator.allocate(capacity);
-      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
-	int id = IdMap(*graph)[it];
-	allocator.construct(&(values[id]), copy.values[id]);
+    ArrayMap(const ArrayMap& copy) {
+      if (copy.attached()) {
+	attach(copy.getRegistry());
       }
-    }
-
-    /** 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]);
       }
     }
@@ -139,58 +132,33 @@
     ArrayMap& operator=(const ArrayMap& copy) {
       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();
+	}
+	if (copy.attached()) {
+	  attach(copy.getRegistry());
 	}
-
-	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);
+      for (KeyIt it(*graph); it != INVALID; ++it) {
+	int id = IdMap(*graph)[it];
 	allocator.construct(&(values[id]), copy.values[id]);
       }
 
       return *this;
     }
 
-    /** 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();
       }
     }
 	
@@ -200,7 +168,7 @@
      * actual keys of the graph. 
      */
     ReferenceType operator[](const KeyType& key) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
+      int id = IdMap(*graph)[key];
       return values[id];
     } 
 		
@@ -209,7 +177,7 @@
      * actual keys of the graph. 
      */
     ConstReferenceType operator[](const KeyType& key) const {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
+      int id = IdMap(*graph)[key];
       return values[id];
     }
 	
@@ -217,22 +185,21 @@
      *  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);
-      values[id] = val;
+      (*this)[key] = val;
     }
 		
     /** Add a new key to the map. It called by the map registry.
      */
     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);
 	while (new_capacity <= id) {
 	  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);
+	for (KeyIt it(*graph); it != INVALID; ++it) {
+	  int jd = IdMap(*graph)[it];
 	  if (id != jd) {
 	    allocator.construct(&(new_values[jd]), values[jd]);
 	    allocator.destroy(&(values[jd]));
@@ -248,7 +215,7 @@
     /** Erase a key from the map. It called by the map registry.
      */
     void erase(const KeyType& key) {
-      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
+      int id = IdMap(*graph)[key];
       allocator.destroy(&(values[id]));
     }
 
@@ -264,65 +231,65 @@
       if (capacity != 0) {
 	for (KeyIt it(*graph); it != INVALID; ++it) {
 	  int id = IdMap(*graph)[it];
-	  allocator.destroy(&(values[id]), Value());
+	  allocator.destroy(&(values[id]));
 	}								
 	allocator.deallocate(values, capacity);
 	capacity = 0;
       }
     }
 
-    /// 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:
       
@@ -346,19 +313,82 @@
     Allocator allocator;
 
   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) {}
+
+    };
+    
+  };
+
 /// @}
 
 }

Modified: hugo/branches/graph_factory/src/lemon/default_map.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/default_map.h	(original)
+++ hugo/branches/graph_factory/src/lemon/default_map.h	Sun Oct 24 23:16:19 2004
@@ -41,100 +41,185 @@
    */
 
 
-  /** Macro to implement the DefaultMap.
-   */
-#define DEFAULT_MAP_BODY(DynMap, Value) \
-{ \
-\
-public: \
-\
-typedef DynMap<MapRegistry, Value> Parent; \
-\
-typedef typename MapRegistry::Graph Graph; \
-\
-DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
-DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
-  : Parent(g, r, v) {} \
-DefaultMap(const DefaultMap& copy) \
-  : Parent(static_cast<const Parent&>(copy)) {} \
-template <typename TT> \
-DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
-  : Parent(*copy.getGraph()) { \
-  if (Parent::getGraph()) { \
-    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
-      Parent::operator[](it) = copy[it]; \
-    } \
-  } \
-} \
-DefaultMap& operator=(const DefaultMap& copy) { \
-  Parent::operator=(static_cast<const Parent&>(copy)); \
-  return *this; \
-} \
-template <typename TT> \
-DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
-  if (Parent::getGraph() != copy.getGraph()) { \
-    Parent::clear(); \
-    Parent::MapBase::operator=(copy); \
-    Parent::construct(); \
-  } \
-  if (Parent::getGraph()) { \
-    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
-      Parent::operator[](it) = copy[it]; \
-    } \
-  } \
-  return *this; \
-} \
-};
-
-
-  template <typename MapRegistry, typename Type>
-  class DefaultMap : public ArrayMap<MapRegistry, Type> 
-  DEFAULT_MAP_BODY(ArrayMap, Type);
-
-  template <typename MapRegistry>
-  class DefaultMap<MapRegistry, bool> 
-    : public VectorMap<MapRegistry, bool> 
-  DEFAULT_MAP_BODY(VectorMap, bool);
-
-  template <typename MapRegistry>
-  class DefaultMap<MapRegistry, char> 
-    : public VectorMap<MapRegistry, char> 
-  DEFAULT_MAP_BODY(VectorMap, char);
-
-  template <typename MapRegistry>
-  class DefaultMap<MapRegistry, int> 
-    : public VectorMap<MapRegistry, int> 
-  DEFAULT_MAP_BODY(VectorMap, int);
-
-  template <typename MapRegistry>
-  class DefaultMap<MapRegistry, short> 
-    : public VectorMap<MapRegistry, short> 
-  DEFAULT_MAP_BODY(VectorMap, short);
-
-  template <typename MapRegistry>
-  class DefaultMap<MapRegistry, long> 
-    : public VectorMap<MapRegistry, long> 
-  DEFAULT_MAP_BODY(VectorMap, long);
-
-  template <typename MapRegistry>
-  class DefaultMap<MapRegistry, float> 
-    : public VectorMap<MapRegistry, float> 
-  DEFAULT_MAP_BODY(VectorMap, float);
-
-  template <typename MapRegistry>
-  class DefaultMap<MapRegistry, double> 
-    : public VectorMap<MapRegistry, double> 
-  DEFAULT_MAP_BODY(VectorMap, double);
-
-  template <typename MapRegistry>
-  class DefaultMap<MapRegistry, long double> 
-    : public VectorMap<MapRegistry, long double> 
-  DEFAULT_MAP_BODY(VectorMap, long double);
-
-  template <typename MapRegistry, typename Type>
-  class DefaultMap<MapRegistry, Type*>
-    : public VectorMap<MapRegistry, Type*> 
-  DEFAULT_MAP_BODY(VectorMap, Type*);
+
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Value>
+  struct DefaultMapSelector {
+    typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map;
+  };
+
+  // bool
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> {
+    typedef VectorMap<_Graph, _Item, _IdMap, bool> Map;
+  };
+
+  // char
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> {
+    typedef VectorMap<_Graph, _Item, _IdMap, char> Map;
+  };
+
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> {
+    typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map;
+  };
+
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> {
+    typedef VectorMap<_Graph, _Item, _IdMap, unsigned char> Map;
+  };
+
+
+  // int
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> {
+    typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map;
+  };
+
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> {
+    typedef VectorMap<_Graph, _Item, _IdMap, unsigned int> Map;
+  };
+
+
+  // short
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> {
+    typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map;
+  };
+
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned short> {
+    typedef VectorMap<_Graph, _Item, _IdMap, unsigned short> Map;
+  };
+
+
+  // long
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed long> {
+    typedef VectorMap<_Graph, _Item, _IdMap, signed long> Map;
+  };
+
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned long> {
+    typedef VectorMap<_Graph, _Item, _IdMap, unsigned long> Map;
+  };
+
+  // \todo handling long long type
+
+
+  // float
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, float> {
+    typedef VectorMap<_Graph, _Item, _IdMap, float> Map;
+  };
+
+
+  // double
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, double> {
+    typedef VectorMap<_Graph, _Item, _IdMap,  double> Map;
+  };
+
+
+  // long double
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, long double> {
+    typedef VectorMap<_Graph, _Item, _IdMap, long double> Map;
+  };
+
+
+  // pointer
+  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Ptr>
+  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Ptr*> {
+    typedef VectorMap<_Graph, _Item, _IdMap, _Ptr*> Map;
+  };
+
+
+
+  template <typename _Graph, 
+	    typename _Item,
+	    typename _ItemIt,
+	    typename _IdMap,
+	    typename _Value>
+  class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map {
+  public:
+    typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map Parent;
+    typedef DefaultMap<_Graph, _Item, _ItemIt, _IdMap, bool> Map;
+    
+    typedef typename Parent::Graph Graph;
+    typedef typename Parent::Registry Registry;
+    typedef typename Parent::ValueType ValueType;
+
+    DefaultMap(const Graph& _g, Registry& _r) : Parent(_g, _r) {}
+    DefaultMap(const Graph& _g, Registry& _r, const ValueType& _v) : Parent(_g, _r, _v) {}
+  };
+
+
+
+  template <typename _Base> 
+  class DefaultMappableGraphExtender : public _Base {
+  public:
+
+    typedef DefaultMappableGraphExtender<_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 DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
+    public:
+      typedef DefaultMappableGraphExtender<_Base> Graph;
+
+      typedef typename Graph::Node Node;
+      typedef typename Graph::NodeIt NodeIt;
+      typedef typename Graph::NodeIdMap NodeIdMap;
+
+      typedef DefaultMap<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 DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
+    public:
+      typedef DefaultMappableGraphExtender<_Base> Graph;
+
+      typedef typename Graph::Edge Edge;
+      typedef typename Graph::EdgeIt EdgeIt;
+      typedef typename Graph::EdgeIdMap EdgeIdMap;
+
+      typedef DefaultMap<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) {}
+
+    };
+    
+  };
+
 
 }
 

Modified: hugo/branches/graph_factory/src/lemon/full_graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/full_graph.h	(original)
+++ hugo/branches/graph_factory/src/lemon/full_graph.h	Sun Oct 24 23:16:19 2004
@@ -23,7 +23,7 @@
 #include <lemon/iterable_graph_extender.h>
 
 #include <lemon/alteration_observer_registry.h>
-#include <lemon/vector_map.h>
+#include <lemon/default_map.h>
 
 ///\ingroup graphs
 ///\file
@@ -198,7 +198,7 @@
   typedef AlterableGraphExtender<FullGraphBase> AlterableFullGraphBase;
   typedef IterableGraphExtender<AlterableFullGraphBase> IterableFullGraphBase;
   typedef IdMappableGraphExtender<IterableFullGraphBase> IdMappableFullGraphBase;
-  typedef VectorMappableGraphExtender<IdMappableFullGraphBase> MappableFullGraphBase;
+  typedef DefaultMappableGraphExtender<IdMappableFullGraphBase> MappableFullGraphBase;
 
   class FullGraph : public MappableFullGraphBase {
   public:

Modified: hugo/branches/graph_factory/src/lemon/list_graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/list_graph.h	(original)
+++ hugo/branches/graph_factory/src/lemon/list_graph.h	Sun Oct 24 23:16:19 2004
@@ -12,7 +12,8 @@
 #include <lemon/iterable_graph_extender.h>
 
 #include <lemon/alteration_observer_registry.h>
-#include <lemon/vector_map.h>
+
+#include <lemon/default_map.h>
 
 
 namespace lemon {
@@ -265,7 +266,7 @@
   typedef AlterableGraphExtender<ListGraphBase> AlterableListGraphBase;
   typedef IterableGraphExtender<AlterableListGraphBase> IterableListGraphBase;
   typedef IdMappableGraphExtender<IterableListGraphBase> IdMappableListGraphBase;
-  typedef VectorMappableGraphExtender<IdMappableListGraphBase> MappableListGraphBase;
+  typedef DefaultMappableGraphExtender<IdMappableListGraphBase> MappableListGraphBase;
   typedef ExtendableGraphExtender<MappableListGraphBase> ExtendableListGraphBase;
   typedef ClearableGraphExtender<ExtendableListGraphBase> ClearableListGraphBase;
   typedef ErasableGraphExtender<ClearableListGraphBase> ErasableListGraphBase;

Modified: hugo/branches/graph_factory/src/lemon/smart_graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/smart_graph.h	(original)
+++ hugo/branches/graph_factory/src/lemon/smart_graph.h	Sun Oct 24 23:16:19 2004
@@ -34,7 +34,7 @@
 #include <lemon/iterable_graph_extender.h>
 
 #include <lemon/alteration_observer_registry.h>
-#include <lemon/vector_map.h>
+#include <lemon/default_map.h>
 
 
 #include <lemon/graph_utils.h>
@@ -245,7 +245,7 @@
   typedef AlterableGraphExtender<SmartGraphBase> AlterableSmartGraphBase;
   typedef IterableGraphExtender<AlterableSmartGraphBase> IterableSmartGraphBase;
   typedef IdMappableGraphExtender<IterableSmartGraphBase> IdMappableSmartGraphBase;
-  typedef VectorMappableGraphExtender<IdMappableSmartGraphBase> MappableSmartGraphBase;
+  typedef DefaultMappableGraphExtender<IdMappableSmartGraphBase> MappableSmartGraphBase;
   typedef ExtendableGraphExtender<MappableSmartGraphBase> ExtendableSmartGraphBase;
   typedef ClearableGraphExtender<ExtendableSmartGraphBase> ClearableSmartGraphBase;
 

Modified: hugo/branches/graph_factory/src/test/graph_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/graph_test.cc	(original)
+++ hugo/branches/graph_factory/src/test/graph_test.cc	Sun Oct 24 23:16:19 2004
@@ -10,6 +10,7 @@
 
 #include "test_tools.h"
 #include "graph_test.h"
+#include "map_test.h"
 
 
 using namespace lemon;
@@ -84,6 +85,7 @@
     addPetersen(G);
     bidirPetersen(G);
     checkPetersen(G);
+    checkGraphNodeMap<ListGraph>();
   }
   { // checking smart graph
     function_requires<ExtendableGraphConcept<SmartGraph> >();
@@ -92,6 +94,7 @@
     addPetersen(G);
     bidirPetersen(G);
     checkPetersen(G);
+    checkGraphNodeMap<SmartGraph>();
   }
   { // checking full graph
     function_requires<StaticGraphConcept<FullGraph> >();

Added: hugo/branches/graph_factory/src/test/map_test.h
==============================================================================
--- (empty file)
+++ hugo/branches/graph_factory/src/test/map_test.h	Sun Oct 24 23:16:19 2004
@@ -0,0 +1,91 @@
+/* -*- C++ -*-
+ * src/test/map_test.h - Part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Combinatorial Optimization Research Group, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+#ifndef LEMON_TEST_MAP_TEST_H
+#define LEMON_TEST_MAP_TEST_H
+
+
+#include <vector>
+
+#include "test_tools.h"
+
+
+//! \ingroup misc
+//! \file
+//! \brief Some utility to test map classes.
+
+namespace lemon {
+
+
+  template <typename Graph>
+  void checkGraphNodeMap() {
+    Graph graph;
+    const int num = 16;
+    
+    typedef typename Graph::Node Node;
+
+    std::vector<Node> nodes;
+    for (int i = 0; i < num; ++i) {
+      nodes.push_back(graph.addNode());      
+    }
+    typedef typename Graph::template NodeMap<int> IntNodeMap;
+    IntNodeMap map(graph, 42);
+    for (int i = 0; i < (int)nodes.size(); ++i) {
+      check(map[nodes[i]] == 42, "Wrong map constructor.");      
+    }
+    for (int i = 0; i < num; ++i) {
+      nodes.push_back(graph.addNode());
+      map[nodes.back()] = 23;
+    }
+    graph.clear();
+    nodes.clear();
+  }
+
+  template <typename Graph>
+  void checkGraphEdgeMap() {
+    Graph graph;
+    const int num = 16;
+    
+    typedef typename Graph::Node Node;
+    typedef typename Graph::Edge Edge;
+
+    std::vector<Node> nodes;
+    for (int i = 0; i < num; ++i) {
+      nodes.push_back();
+    }
+    std::vector<Edge> edges;
+    for (int i = 0; i < num; ++i) {
+      for (int j = 0; j < i; ++i) {
+	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
+      }
+    }
+    typedef typename Graph::template EdgeMap<int> IntEdgeMap;
+    IntEdgeMap map(graph, 42);
+    for (int i = 0; i < (int)edges.size(); ++i) {
+      check(map[edges[i]] == 42, "Wrong map constructor.");      
+    }
+    for (int i = 0; i < num; ++i) {
+      for (int j = i + 1; j < num; ++i) {
+	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
+	map[edges.back()] = 23;
+      }
+    }
+    graph.clear();
+    edges.clear();    
+  }
+
+}
+
+#endif



More information about the Lemon-commits mailing list