diff -r 236117f60eee -r c03e073b8394 src/work/deba/map_registry.h --- a/src/work/deba/map_registry.h Wed Jul 14 10:05:31 2004 +0000 +++ b/src/work/deba/map_registry.h Wed Jul 14 10:06:27 2004 +0000 @@ -8,10 +8,10 @@ namespace hugo { /** - Registry class to register edge or node maps in the graph. The - registry helps you to implement an observer pattern. If you add - or erase an edge or node you must notify all the maps about the - event. + * Registry class to register edge or node maps into the graph. The + * registry helps you to implement an observer pattern. If you add + * or erase an edge or node you must notify all the maps about the + * event. */ template class MapRegistry { @@ -22,10 +22,11 @@ - ///. - - ///. - /// + /** + * MapBase is the base class of the registered maps. + * It defines the core modification operations on the maps and + * implements some helper functions. + */ class MapBase { public: typedef G Graph; @@ -34,23 +35,23 @@ typedef KIt KeyIt; friend class Registry; + + /** + * Default constructor for MapBase. + */ + + MapBase() : graph(0), registry(0) {} /** - Default constructor. - */ - - MapBase() : graph(0), registry(0) {} - - /** - Simple constructor to register into a graph registry. + * Simple constructor to register into a graph registry. */ - MapBase(Graph& g, Registry& r) : graph(&g), registry(0) { + MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) { r.attach(*this); } /** - Copy constructor with registering into the map. + * Copy constructor to register into the registry. */ MapBase(const MapBase& copy) : registry(0), graph(copy.graph) { @@ -60,7 +61,7 @@ } /** - Assign operator. + * Assign operator. */ const MapBase& operator=(const MapBase& copy) { @@ -75,7 +76,7 @@ /** - Destructor. + * Destructor. */ virtual ~MapBase() { @@ -83,13 +84,21 @@ registry->detach(*this); } } + + /* + * Returns the graph that the map belongs to. + */ + + const Graph* getGraph() const { return graph; } - protected: + private: - Graph* graph; + const Graph* graph; Registry* registry; int registry_index; + + protected: /** Helper function to implement constructors in the subclasses. @@ -106,7 +115,7 @@ */ virtual void destroy() { - for (KeyIt it(*graph); graph->valid(it); graph->next(it)) { + for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) { erase(it); } } @@ -134,19 +143,34 @@ protected: + /** + * The container type of the maps. + */ typedef std::vector Container; + + /** + * The container of the registered maps. + */ Container container; - public: + public: - ///. + /** + * Default Constructor of the MapRegistry. It creates an empty registry. + */ MapRegistry() {} - ///. + /** + * Copy Constructor of the MapRegistry. The new registry does not steal + * the maps from the right value. The new registry will be an empty. + */ MapRegistry(const MapRegistry&) {} - ///. + /** + * Assign operator. The left value does not steal the maps + * from the right value. The left value will be an empty registry. + */ MapRegistry& operator=(const MapRegistry&) { for (it = container.begin(); it != container.end(); ++it) { (*it)->destroy(); @@ -155,7 +179,9 @@ } } - ///. + /** + * Destructor of the MapRegistry. + */ ~MapRegistry() { typename Container::iterator it; for (it = container.begin(); it != container.end(); ++it) { @@ -168,7 +194,10 @@ public: - ///. + /** + * Attach a map into thr registry. If the map has been attached + * into an other registry it is detached from that automaticly. + */ void attach(MapBase& map) { if (map.registry) { map.registry->detach(map); @@ -178,7 +207,9 @@ map.registry_index = container.size()-1; } - ///. + /** + * Detach the map from the registry. + */ void detach(MapBase& map) { container.back()->registry_index = map.registry_index; container[map.registry_index] = container.back(); @@ -188,7 +219,9 @@ } - ///. + /** + * Notify all the registered maps about a Key added. + */ virtual void add(Key& key) { typename Container::iterator it; for (it = container.begin(); it != container.end(); ++it) { @@ -196,7 +229,9 @@ } } - ///. + /** + * Notify all the registered maps about a Key erased. + */ virtual void erase(Key& key) { typename Container::iterator it; for (it = container.begin(); it != container.end(); ++it) {