Changeset 701:c03e073b8394 in lemon-0.x for src/work/deba/map_registry.h
- Timestamp:
- 07/14/04 12:06:27 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@952
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/map_registry.h
r676 r701 9 9 10 10 /** 11 Registry class to register edge or node maps inthe graph. The12 13 14 11 * Registry class to register edge or node maps into the graph. The 12 * registry helps you to implement an observer pattern. If you add 13 * or erase an edge or node you must notify all the maps about the 14 * event. 15 15 */ 16 16 template <typename G, typename K, typename KIt> … … 23 23 24 24 25 ///. 26 27 ///. 28 /// 25 /** 26 * MapBase is the base class of the registered maps. 27 * It defines the core modification operations on the maps and 28 * implements some helper functions. 29 */ 29 30 class MapBase { 30 31 public: … … 35 36 36 37 friend class Registry; 37 38 /** 39 Default constructor.40 */41 38 39 /** 40 * Default constructor for MapBase. 41 */ 42 42 43 MapBase() : graph(0), registry(0) {} 43 44 /** 45 46 */ 47 48 MapBase( Graph& g, Registry& r) : graph(&g), registry(0) {44 45 /** 46 * Simple constructor to register into a graph registry. 47 */ 48 49 MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) { 49 50 r.attach(*this); 50 51 } 51 52 52 53 /** 53 Copy constructor with registering into the map.54 * Copy constructor to register into the registry. 54 55 */ 55 56 … … 61 62 62 63 /** 63 64 * Assign operator. 64 65 */ 65 66 … … 76 77 77 78 /** 78 Destructor. 79 * Destructor. 79 80 */ 80 81 … … 84 85 } 85 86 } 86 87 88 /* 89 * Returns the graph that the map belongs to. 90 */ 91 92 const Graph* getGraph() const { return graph; } 93 94 private: 95 96 const Graph* graph; 97 Registry* registry; 98 99 int registry_index; 100 87 101 protected: 88 89 Graph* graph;90 Registry* registry;91 92 int registry_index;93 102 94 103 /** … … 107 116 108 117 virtual void destroy() { 109 for (KeyIt it(*g raph); graph->valid(it); graph->next(it)) {118 for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) { 110 119 erase(it); 111 120 } … … 135 144 protected: 136 145 146 /** 147 * The container type of the maps. 148 */ 137 149 typedef std::vector<MapBase*> Container; 150 151 /** 152 * The container of the registered maps. 153 */ 138 154 Container container; 139 155 140 156 141 public: 142 143 ///. 157 public: 158 159 /** 160 * Default Constructor of the MapRegistry. It creates an empty registry. 161 */ 144 162 MapRegistry() {} 145 163 146 ///. 164 /** 165 * Copy Constructor of the MapRegistry. The new registry does not steal 166 * the maps from the right value. The new registry will be an empty. 167 */ 147 168 MapRegistry(const MapRegistry&) {} 148 169 149 ///. 170 /** 171 * Assign operator. The left value does not steal the maps 172 * from the right value. The left value will be an empty registry. 173 */ 150 174 MapRegistry& operator=(const MapRegistry&) { 151 175 for (it = container.begin(); it != container.end(); ++it) { … … 156 180 } 157 181 158 ///. 182 /** 183 * Destructor of the MapRegistry. 184 */ 159 185 ~MapRegistry() { 160 186 typename Container::iterator it; … … 169 195 public: 170 196 171 ///. 197 /** 198 * Attach a map into thr registry. If the map has been attached 199 * into an other registry it is detached from that automaticly. 200 */ 172 201 void attach(MapBase& map) { 173 202 if (map.registry) { … … 179 208 } 180 209 181 ///. 210 /** 211 * Detach the map from the registry. 212 */ 182 213 void detach(MapBase& map) { 183 214 container.back()->registry_index = map.registry_index; … … 189 220 190 221 191 ///. 222 /** 223 * Notify all the registered maps about a Key added. 224 */ 192 225 virtual void add(Key& key) { 193 226 typename Container::iterator it; … … 197 230 } 198 231 199 ///. 232 /** 233 * Notify all the registered maps about a Key erased. 234 */ 200 235 virtual void erase(Key& key) { 201 236 typename Container::iterator it;
Note: See TracChangeset
for help on using the changeset viewer.