Changeset 937:d4e911acef3d in lemon-0.x for src/lemon/map_registry.h
- Timestamp:
- 10/04/04 19:13:21 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1264
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/lemon/map_registry.h
r921 r937 28 28 namespace lemon { 29 29 30 /// \addtogroup graphmapfactory 31 /// @{ 32 33 /** 34 * Registry class to register edge or node maps into the graph. The 35 * registry helps you to implement an observer pattern. If you add 36 * or erase an edge or node you must notify all the maps about the 37 * event. 38 */ 30 /// \addtogroup graphmapfactory 31 /// @{ 32 33 /// Map registry for graph maps. 34 35 /** 36 * Registry class to register edge or node maps into the graph. The 37 * registry helps you to implement an observer pattern. If you add 38 * or erase an edge or node you must notify all the maps about the 39 * event. 40 * 41 * \param G The graph type to register maps. 42 * \param K The key type of the maps registered into the registry. 43 * \param KIt The key iterator type iterates on the keys. 44 * 45 * \author Balazs Dezso 46 */ 47 39 48 template <typename G, typename K, typename KIt> 40 49 class MapRegistry { … … 43 52 typedef K KeyType; 44 53 typedef KIt KeyIt; 45 46 /** 47 * MapBase is the base class of the registered maps. 54 55 /// MapBase is the base class of the dynamic maps. 56 57 /** 58 * MapBase is the base class of the dynamic maps. 48 59 * It defines the core modification operations on the maps and 49 60 * implements some helper functions. … … 59 70 friend class MapRegistry<G, K, KIt>; 60 71 72 /// Default constructor. 73 61 74 /** 62 75 * Default constructor for MapBase. … … 64 77 65 78 MapBase() : graph(0), registry(0) {} 66 67 /** 68 * Simple constructor to register into a graph registry. 79 80 /// Constructor to register map into a graph registry. 81 82 /** 83 * Simple constructor to register dynamic map into a graph registry. 69 84 */ 70 85 … … 73 88 } 74 89 90 /// Copy constructor. 91 75 92 /** 76 93 * Copy constructor to register into the registry. 94 * If the copiable map is registered into a registry 95 * the construated map will be registered to the same registry. 77 96 */ 78 97 … … 82 101 } 83 102 } 84 85 /** 86 * Assign operator. 103 104 /// Assign operator. 105 106 /** 107 * Assign operator. This member detach first the map 108 * from the current registry and then it attach to the 109 * copiable map's registry if it exists. 87 110 */ 88 111 const MapBase& operator=(const MapBase& copy) { … … 97 120 } 98 121 99 100 /** 101 * Destructor. 122 /// Destructor 123 124 /** 125 * This member detach the map from the its registry if the 126 * registry exists. 102 127 */ 103 128 … … 108 133 } 109 134 135 /// The graph of the map. 136 110 137 /* 111 138 * Returns the graph that the map belongs to. … … 122 149 123 150 protected: 124 125 /** 126 Helper function to implement constructors in the subclasses. 151 152 /// Helper function to implement constructors in the subclasses. 153 154 /** 155 * Helper function to implement constructors in the subclasses. 156 * It adds all of the nodes or edges to the map via the 157 * \ref MapRegistry::MapBase::add add 158 * member function. 127 159 */ 128 160 … … 133 165 } 134 166 135 /** 136 Helper function to implement the destructor in the subclasses. 167 168 /// Helper function to implement destructors in the subclasses. 169 170 /** 171 * Helper function to implement destructors in the subclasses. 172 * It erases all of the nodes or edges of the map via the 173 * \ref MapRegistry::MapBase::erase erase 174 * member function. It can be used by the clear function also. 137 175 */ 138 176 … … 142 180 } 143 181 } 182 183 /// The member function to add new node or edge to the map. 144 184 145 185 /** 146 186 The add member function should be overloaded in the subclasses. 147 \e Add extends the map with the new node .187 \e Add extends the map with the new node or edge. 148 188 */ 149 189 150 190 virtual void add(const KeyType&) = 0; 191 192 193 /// The member function to erase a node or edge from the map. 194 151 195 /** 152 196 The erase member function should be overloaded in the subclasses. 153 \e Erase removes the node from the map.197 \e Erase removes the node or edge from the map. 154 198 */ 155 199 … … 162 206 163 207 virtual void clear() = 0; 164 165 /** 166 Exception class to throw at unsupported operation. 208 209 /// Exception class to throw at unsupported operation. 210 211 /** 212 * Exception class to throw at unsupported operation. 213 * If the map does not support erasing or adding new 214 * node or key it must be throwed. 167 215 */ 168 216 … … 173 221 protected: 174 222 175 /** 176 * The container type of the maps. 177 */ 223 178 224 typedef std::vector<MapBase*> Container; 179 225 180 /**181 * The container of the registered maps.182 */183 226 Container container; 184 227 185 228 186 229 public: 187 188 /** 189 * Default Constructor of the MapRegistry. It creates an empty registry. 230 231 /// Default constructor. 232 233 /** 234 * Default constructor of the \e MapRegistry. 235 * It creates an empty registry. 190 236 */ 191 237 MapRegistry() {} 192 193 /** 194 * Copy Constructor of the MapRegistry. The new registry does not steal 195 * the maps from the right value. The new registry will be an empty. 238 239 /// Copy Constructor of the MapRegistry. 240 241 /** 242 * Copy constructor of the \e MapRegistry. 243 * The new registry does not steal 244 * the maps from the copiable registry. 245 * The new registry will be empty. 196 246 */ 197 247 MapRegistry(const MapRegistry&) {} 198 199 /** 200 * Assign operator. The left value does not steal the maps 201 * from the right value. The left value will be an empty registry. 248 249 /// Assign operator. 250 251 /** 252 * Assign operator. This registry does not steal the maps 253 * from the copiable registry. This registry will be an empty registry. 254 * This operator will be called when a graph is assigned. 202 255 */ 203 256 MapRegistry& operator=(const MapRegistry&) { 204 257 typename Container::iterator it; 205 258 for (it = container.begin(); it != container.end(); ++it) { 206 (*it)-> destroy();259 (*it)->clear(); 207 260 (*it)->graph = 0; 208 261 (*it)->registry = 0; 209 262 } 210 263 } 264 265 /// Destructor. 211 266 212 267 /** 213 * Destructor of the MapRegistry. 268 * Destructor of the MapRegistry. It makes empty the attached map 269 * first then detachs them. 214 270 */ 215 271 ~MapRegistry() { 216 272 typename Container::iterator it; 217 273 for (it = container.begin(); it != container.end(); ++it) { 218 (*it)-> destroy();274 (*it)->clear(); 219 275 (*it)->registry = 0; 220 276 (*it)->graph = 0; … … 224 280 225 281 public: 226 227 /** 228 * Attach a map into thr registry. If the map has been attached 282 283 /// Attachs a map to the \e MapRegistry. 284 285 /** 286 * Attachs a map into thr registry. If the map has been attached 229 287 * into an other registry it is detached from that automaticly. 230 288 */ … … 237 295 map.registry_index = container.size()-1; 238 296 } 239 240 /** 241 * Detach the map from the registry. 297 298 /// Detachs a map from the \e MapRegistry. 299 300 /** 301 * Detachs a map from the \e MapRegistry. 242 302 */ 243 303 void detach(MapBase& map) { … … 249 309 } 250 310 311 /// Notify all the registered maps about a Key added. 251 312 252 313 /** 253 314 * Notify all the registered maps about a Key added. 254 */ 255 void add(KeyType& key) { 315 * This member should be called whenever a node or edge 316 * is added to the graph. 317 */ 318 void add(const KeyType& key) { 256 319 typename Container::iterator it; 257 320 for (it = container.begin(); it != container.end(); ++it) { … … 259 322 } 260 323 } 324 325 /// Notify all the registered maps about a Key erased. 261 326 262 327 /** 263 328 * Notify all the registered maps about a Key erased. 329 * This member should be called whenever a node or edge 330 * is erased from the graph. 264 331 */ 265 void erase( KeyType& key) {332 void erase(const KeyType& key) { 266 333 typename Container::iterator it; 267 334 for (it = container.begin(); it != container.end(); ++it) { … … 270 337 } 271 338 339 340 /// Notify all the registered maps about all the Keys are erased. 341 272 342 /** 273 343 * Notify all the registered maps about the map should be cleared. 344 * This member should be called whenever all of the nodes or edges 345 * are erased from the graph. 274 346 */ 275 347 void clear() {
Note: See TracChangeset
for help on using the changeset viewer.