src/work/deba/map_registry.h
changeset 701 c03e073b8394
parent 676 7ec5e7e6c7b4
child 703 32f280a5ed7d
     1.1 --- a/src/work/deba/map_registry.h	Wed Jul 14 10:05:31 2004 +0000
     1.2 +++ b/src/work/deba/map_registry.h	Wed Jul 14 10:06:27 2004 +0000
     1.3 @@ -8,10 +8,10 @@
     1.4  namespace hugo {
     1.5  
     1.6  /** 
     1.7 -    Registry class to register edge or node maps in the graph. The
     1.8 -    registry helps you to implement an observer pattern. If you add
     1.9 -    or erase an edge or node you must notify all the maps about the
    1.10 -    event.
    1.11 + * Registry class to register edge or node maps into the graph. The
    1.12 + * registry helps you to implement an observer pattern. If you add
    1.13 + * or erase an edge or node you must notify all the maps about the
    1.14 + * event.
    1.15  */
    1.16    template <typename G, typename K, typename KIt>
    1.17    class MapRegistry {
    1.18 @@ -22,10 +22,11 @@
    1.19  	
    1.20  
    1.21  
    1.22 -    ///. 
    1.23 -
    1.24 -    ///. 
    1.25 -    /// 
    1.26 +    /**
    1.27 +     * MapBase is the base class of the registered maps.
    1.28 +     * It defines the core modification operations on the maps and
    1.29 +     * implements some helper functions. 
    1.30 +     */
    1.31      class MapBase {
    1.32      public:
    1.33        typedef G Graph;
    1.34 @@ -34,23 +35,23 @@
    1.35        typedef KIt KeyIt;
    1.36  	
    1.37        friend class Registry;
    1.38 +
    1.39 +      /**
    1.40 +       * Default constructor for MapBase.
    1.41 +       */
    1.42 +
    1.43 +      MapBase() : graph(0), registry(0) {}
    1.44  		
    1.45        /** 
    1.46 -	  Default constructor.
    1.47 -      */	
    1.48 -		
    1.49 -      MapBase() : graph(0), registry(0) {}
    1.50 -
    1.51 -      /** 
    1.52 -	  Simple constructor to register into a graph registry.
    1.53 +       * Simple constructor to register into a graph registry.
    1.54        */
    1.55  	
    1.56 -      MapBase(Graph& g, Registry& r) : graph(&g), registry(0) {
    1.57 +      MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
    1.58  	r.attach(*this);
    1.59        }
    1.60  
    1.61        /** 
    1.62 -	  Copy constructor with registering into the map.
    1.63 +       * Copy constructor to register into the registry.
    1.64        */	
    1.65  	
    1.66        MapBase(const MapBase& copy) : registry(0), graph(copy.graph) {
    1.67 @@ -60,7 +61,7 @@
    1.68        } 
    1.69  	
    1.70        /** 
    1.71 -	  Assign operator.
    1.72 +       * Assign operator.
    1.73        */	
    1.74  
    1.75        const MapBase& operator=(const MapBase& copy) {
    1.76 @@ -75,7 +76,7 @@
    1.77  	
    1.78  
    1.79        /** 
    1.80 -	  Destructor.
    1.81 +       * Destructor. 
    1.82        */		
    1.83  
    1.84        virtual ~MapBase() {
    1.85 @@ -83,13 +84,21 @@
    1.86  	  registry->detach(*this);
    1.87  	}
    1.88        }
    1.89 +
    1.90 +      /*
    1.91 +       * Returns the graph that the map belongs to.
    1.92 +      */
    1.93 +
    1.94 +      const Graph* getGraph() const { return graph; }
    1.95  	
    1.96 -    protected:
    1.97 +    private:
    1.98  		
    1.99 -      Graph* graph;
   1.100 +      const Graph* graph;
   1.101        Registry* registry;
   1.102  
   1.103        int registry_index;
   1.104 +
   1.105 +    protected:
   1.106  	
   1.107        /**
   1.108  	 Helper function to implement constructors in the subclasses.
   1.109 @@ -106,7 +115,7 @@
   1.110        */
   1.111  	
   1.112        virtual void destroy() {
   1.113 -	for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
   1.114 +	for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
   1.115  	  erase(it);
   1.116  	}
   1.117        }
   1.118 @@ -134,19 +143,34 @@
   1.119  	
   1.120    protected:
   1.121  	
   1.122 +    /** 
   1.123 +     * The container type of the maps.
   1.124 +     */
   1.125      typedef std::vector<MapBase*> Container; 
   1.126 +
   1.127 +    /**
   1.128 +     * The container of the registered maps.
   1.129 +     */
   1.130      Container container;
   1.131  
   1.132  		
   1.133 -    public:
   1.134 +  public:
   1.135  	
   1.136 -    ///. 
   1.137 +    /**
   1.138 +     * Default Constructor of the MapRegistry. It creates an empty registry.
   1.139 +     */
   1.140      MapRegistry() {}
   1.141  	
   1.142 -    ///.
   1.143 +    /**
   1.144 +     * Copy Constructor of the MapRegistry. The new registry does not steal
   1.145 +     * the maps from the right value. The new registry will be an empty.
   1.146 +     */
   1.147      MapRegistry(const MapRegistry&) {}
   1.148  		
   1.149 -    ///.
   1.150 +    /**
   1.151 +     * Assign operator. The left value does not steal the maps 
   1.152 +     * from the right value. The left value will be an empty registry.
   1.153 +     */
   1.154      MapRegistry& operator=(const MapRegistry&) {
   1.155        for (it = container.begin(); it != container.end(); ++it) {
   1.156  	(*it)->destroy();
   1.157 @@ -155,7 +179,9 @@
   1.158        }
   1.159      }
   1.160  				
   1.161 -    ///.
   1.162 +    /**
   1.163 +     * Destructor of the MapRegistry.
   1.164 +     */
   1.165      ~MapRegistry() {
   1.166        typename Container::iterator it;
   1.167        for (it = container.begin(); it != container.end(); ++it) {
   1.168 @@ -168,7 +194,10 @@
   1.169  	
   1.170      public:
   1.171  	
   1.172 -    ///.
   1.173 +    /**
   1.174 +     * Attach a map into thr registry. If the map has been attached
   1.175 +     * into an other registry it is detached from that automaticly.
   1.176 +     */
   1.177      void attach(MapBase& map) {
   1.178        if (map.registry) {
   1.179  	map.registry->detach(map);
   1.180 @@ -178,7 +207,9 @@
   1.181        map.registry_index = container.size()-1;
   1.182      } 
   1.183  	
   1.184 -    ///.
   1.185 +    /**
   1.186 +     * Detach the map from the registry.
   1.187 +     */
   1.188      void detach(MapBase& map) {
   1.189        container.back()->registry_index = map.registry_index; 
   1.190        container[map.registry_index] = container.back();
   1.191 @@ -188,7 +219,9 @@
   1.192      }
   1.193  	
   1.194  		
   1.195 -    ///. 
   1.196 +    /**
   1.197 +     * Notify all the registered maps about a Key added.
   1.198 +     */
   1.199      virtual void add(Key& key) {
   1.200        typename Container::iterator it;
   1.201        for (it = container.begin(); it != container.end(); ++it) {
   1.202 @@ -196,7 +229,9 @@
   1.203        }
   1.204      }	
   1.205  		
   1.206 -    ///.
   1.207 +    /**
   1.208 +     * Notify all the registered maps about a Key erased.
   1.209 +     */ 
   1.210      virtual void erase(Key& key) {
   1.211        typename Container::iterator it;
   1.212        for (it = container.begin(); it != container.end(); ++it) {