Changeset 314:2cc60866a0c9 in lemon for lemon/bits
- Timestamp:
- 10/09/08 13:27:35 (16 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- lemon/bits
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/alteration_notifier.h
r313 r314 25 25 #include <lemon/core.h> 26 26 27 // /\ingroup graphbits28 // /\file29 // /\brief Observer notifier for graph alteration observers.27 //\ingroup graphbits 28 //\file 29 //\brief Observer notifier for graph alteration observers. 30 30 31 31 namespace lemon { 32 32 33 // /\ingroup graphbits34 // /35 // /\brief Notifier class to notify observes about alterations in36 // /a container.37 // /38 // /The simple graph's can be refered as two containers, one node container39 // /and one edge container. But they are not standard containers they40 // /does not store values directly they are just key continars for more41 // /value containers which are the node and edge maps.42 // /43 // /The graph's node and edge sets can be changed as we add or erase44 // /nodes and edges in the graph. LEMON would like to handle easily45 // /that the node and edge maps should contain values for all nodes or46 // /edges. If we want to check on every indicing if the map contains47 // /the current indicing key that cause a drawback in the performance48 // /in the library. We use another solution we notify all maps about49 // /an alteration in the graph, which cause only drawback on the50 // /alteration of the graph.51 // /52 // /This class provides an interface to the container. The \e first() and \e53 // /next() member functions make possible to iterate on the keys of the54 // /container. The \e id() function returns an integer id for each key.55 // /The \e maxId() function gives back an upper bound of the ids.56 // /57 // /For the proper functonality of this class, we should notify it58 // /about each alteration in the container. The alterations have four type59 // /as \e add(), \e erase(), \e build() and \e clear(). The \e add() and60 // /\e erase() signals that only one or few items added or erased to or61 // /from the graph. If all items are erased from the graph or from an empty62 // /graph a new graph is builded then it can be signaled with the63 // /clear() and build() members. Important rule that if we erase items64 // /from graph we should first signal the alteration and after that erase65 // /them from the container, on the other way on item addition we should66 // /first extend the container and just after that signal the alteration.67 // /68 // /The alteration can be observed with a class inherited from the69 // /\e ObserverBase nested class. The signals can be handled with70 // /overriding the virtual functions defined in the base class. The71 // /observer base can be attached to the notifier with the72 // /\e attach() member and can be detached with detach() function. The73 // /alteration handlers should not call any function which signals74 // /an other alteration in the same notifier and should not75 // /detach any observer from the notifier.76 // /77 // /Alteration observers try to be exception safe. If an \e add() or78 // /a \e clear() function throws an exception then the remaining79 // /observeres will not be notified and the fulfilled additions will80 // /be rolled back by calling the \e erase() or \e clear()81 // /functions. Thence the \e erase() and \e clear() should not throw82 // / exception. Actullay, it can be throw only \ref ImmediateDetach83 // /exception which detach the observer from the notifier.84 // /85 // /There are some place when the alteration observing is not completly86 // /reliable. If we want to carry out the node degree in the graph87 // /as in the \ref InDegMap and we use the reverseEdge that cause88 // /unreliable functionality. Because the alteration observing signals89 // /only erasing and adding but not the reversing it will stores bad90 // /degrees. The sub graph adaptors cannot signal the alterations because91 // /just a setting in the filter map can modify the graph and this cannot92 // /be watched in any way.93 // /94 // /\param _Container The container which is observed.95 // /\param _Item The item type which is obserbved.33 // \ingroup graphbits 34 // 35 // \brief Notifier class to notify observes about alterations in 36 // a container. 37 // 38 // The simple graph's can be refered as two containers, one node container 39 // and one edge container. But they are not standard containers they 40 // does not store values directly they are just key continars for more 41 // value containers which are the node and edge maps. 42 // 43 // The graph's node and edge sets can be changed as we add or erase 44 // nodes and edges in the graph. LEMON would like to handle easily 45 // that the node and edge maps should contain values for all nodes or 46 // edges. If we want to check on every indicing if the map contains 47 // the current indicing key that cause a drawback in the performance 48 // in the library. We use another solution we notify all maps about 49 // an alteration in the graph, which cause only drawback on the 50 // alteration of the graph. 51 // 52 // This class provides an interface to the container. The \e first() and \e 53 // next() member functions make possible to iterate on the keys of the 54 // container. The \e id() function returns an integer id for each key. 55 // The \e maxId() function gives back an upper bound of the ids. 56 // 57 // For the proper functonality of this class, we should notify it 58 // about each alteration in the container. The alterations have four type 59 // as \e add(), \e erase(), \e build() and \e clear(). The \e add() and 60 // \e erase() signals that only one or few items added or erased to or 61 // from the graph. If all items are erased from the graph or from an empty 62 // graph a new graph is builded then it can be signaled with the 63 // clear() and build() members. Important rule that if we erase items 64 // from graph we should first signal the alteration and after that erase 65 // them from the container, on the other way on item addition we should 66 // first extend the container and just after that signal the alteration. 67 // 68 // The alteration can be observed with a class inherited from the 69 // \e ObserverBase nested class. The signals can be handled with 70 // overriding the virtual functions defined in the base class. The 71 // observer base can be attached to the notifier with the 72 // \e attach() member and can be detached with detach() function. The 73 // alteration handlers should not call any function which signals 74 // an other alteration in the same notifier and should not 75 // detach any observer from the notifier. 76 // 77 // Alteration observers try to be exception safe. If an \e add() or 78 // a \e clear() function throws an exception then the remaining 79 // observeres will not be notified and the fulfilled additions will 80 // be rolled back by calling the \e erase() or \e clear() 81 // functions. Thence the \e erase() and \e clear() should not throw 82 // exception. Actullay, it can be throw only \ref ImmediateDetach 83 // exception which detach the observer from the notifier. 84 // 85 // There are some place when the alteration observing is not completly 86 // reliable. If we want to carry out the node degree in the graph 87 // as in the \ref InDegMap and we use the reverseEdge that cause 88 // unreliable functionality. Because the alteration observing signals 89 // only erasing and adding but not the reversing it will stores bad 90 // degrees. The sub graph adaptors cannot signal the alterations because 91 // just a setting in the filter map can modify the graph and this cannot 92 // be watched in any way. 93 // 94 // \param _Container The container which is observed. 95 // \param _Item The item type which is obserbved. 96 96 97 97 template <typename _Container, typename _Item> … … 104 104 typedef _Item Item; 105 105 106 // /\brief Exception which can be called from \e clear() and107 // /\e erase().108 // /109 // /From the \e clear() and \e erase() function only this110 // /exception is allowed to throw. The exception immediatly111 // /detaches the current observer from the notifier. Because the112 // /\e clear() and \e erase() should not throw other exceptions113 // /it can be used to invalidate the observer.106 // \brief Exception which can be called from \e clear() and 107 // \e erase(). 108 // 109 // From the \e clear() and \e erase() function only this 110 // exception is allowed to throw. The exception immediatly 111 // detaches the current observer from the notifier. Because the 112 // \e clear() and \e erase() should not throw other exceptions 113 // it can be used to invalidate the observer. 114 114 struct ImmediateDetach {}; 115 115 116 /// \brief ObserverBase is the base class for the observers. 117 /// 118 /// ObserverBase is the abstract base class for the observers. 119 /// It will be notified about an item was inserted into or 120 /// erased from the graph. 121 /// 122 /// The observer interface contains some pure virtual functions 123 /// to override. The add() and erase() functions are 124 /// to notify the oberver when one item is added or 125 /// erased. 126 /// 127 /// The build() and clear() members are to notify the observer 128 /// about the container is built from an empty container or 129 /// is cleared to an empty container. 130 116 // \brief ObserverBase is the base class for the observers. 117 // 118 // ObserverBase is the abstract base class for the observers. 119 // It will be notified about an item was inserted into or 120 // erased from the graph. 121 // 122 // The observer interface contains some pure virtual functions 123 // to override. The add() and erase() functions are 124 // to notify the oberver when one item is added or 125 // erased. 126 // 127 // The build() and clear() members are to notify the observer 128 // about the container is built from an empty container or 129 // is cleared to an empty container. 131 130 class ObserverBase { 132 131 protected: … … 135 134 friend class AlterationNotifier; 136 135 137 /// \brief Default constructor. 138 /// 139 /// Default constructor for ObserverBase. 140 /// 136 // \brief Default constructor. 137 // 138 // Default constructor for ObserverBase. 141 139 ObserverBase() : _notifier(0) {} 142 140 143 // /\brief Constructor which attach the observer into notifier.144 // /145 // /Constructor which attach the observer into notifier.141 // \brief Constructor which attach the observer into notifier. 142 // 143 // Constructor which attach the observer into notifier. 146 144 ObserverBase(AlterationNotifier& nf) { 147 145 attach(nf); 148 146 } 149 147 150 // /\brief Constructor which attach the obserever to the same notifier.151 // /152 // /Constructor which attach the obserever to the same notifier as153 // /the other observer is attached to.148 // \brief Constructor which attach the obserever to the same notifier. 149 // 150 // Constructor which attach the obserever to the same notifier as 151 // the other observer is attached to. 154 152 ObserverBase(const ObserverBase& copy) { 155 153 if (copy.attached()) { … … 158 156 } 159 157 160 // /\brief Destructor158 // \brief Destructor 161 159 virtual ~ObserverBase() { 162 160 if (attached()) { … … 165 163 } 166 164 167 /// \brief Attaches the observer into an AlterationNotifier. 168 /// 169 /// This member attaches the observer into an AlterationNotifier. 170 /// 165 // \brief Attaches the observer into an AlterationNotifier. 166 // 167 // This member attaches the observer into an AlterationNotifier. 171 168 void attach(AlterationNotifier& nf) { 172 169 nf.attach(*this); 173 170 } 174 171 175 /// \brief Detaches the observer into an AlterationNotifier. 176 /// 177 /// This member detaches the observer from an AlterationNotifier. 178 /// 172 // \brief Detaches the observer into an AlterationNotifier. 173 // 174 // This member detaches the observer from an AlterationNotifier. 179 175 void detach() { 180 176 _notifier->detach(*this); 181 177 } 182 178 183 /// \brief Gives back a pointer to the notifier which the map 184 /// attached into. 185 /// 186 /// This function gives back a pointer to the notifier which the map 187 /// attached into. 188 /// 179 // \brief Gives back a pointer to the notifier which the map 180 // attached into. 181 // 182 // This function gives back a pointer to the notifier which the map 183 // attached into. 189 184 Notifier* notifier() const { return const_cast<Notifier*>(_notifier); } 190 185 191 // /Gives back true when the observer is attached into a notifier.186 // Gives back true when the observer is attached into a notifier. 192 187 bool attached() const { return _notifier != 0; } 193 188 … … 201 196 typename std::list<ObserverBase*>::iterator _index; 202 197 203 // /\brief The member function to notificate the observer about an204 // /item is added to the container.205 // /206 // /The add() member function notificates the observer about an item207 // /is added to the container. It have to be overrided in the208 // /subclasses.198 // \brief The member function to notificate the observer about an 199 // item is added to the container. 200 // 201 // The add() member function notificates the observer about an item 202 // is added to the container. It have to be overrided in the 203 // subclasses. 209 204 virtual void add(const Item&) = 0; 210 205 211 // /\brief The member function to notificate the observer about212 // /more item is added to the container.213 // /214 // /The add() member function notificates the observer about more item215 // /is added to the container. It have to be overrided in the216 // /subclasses.206 // \brief The member function to notificate the observer about 207 // more item is added to the container. 208 // 209 // The add() member function notificates the observer about more item 210 // is added to the container. It have to be overrided in the 211 // subclasses. 217 212 virtual void add(const std::vector<Item>& items) = 0; 218 213 219 // /\brief The member function to notificate the observer about an220 // /item is erased from the container.221 // /222 // /The erase() member function notificates the observer about an223 // /item is erased from the container. It have to be overrided in224 // /the subclasses.214 // \brief The member function to notificate the observer about an 215 // item is erased from the container. 216 // 217 // The erase() member function notificates the observer about an 218 // item is erased from the container. It have to be overrided in 219 // the subclasses. 225 220 virtual void erase(const Item&) = 0; 226 221 227 // /\brief The member function to notificate the observer about228 // /more item is erased from the container.229 // /230 // /The erase() member function notificates the observer about more item231 // /is erased from the container. It have to be overrided in the232 // /subclasses.222 // \brief The member function to notificate the observer about 223 // more item is erased from the container. 224 // 225 // The erase() member function notificates the observer about more item 226 // is erased from the container. It have to be overrided in the 227 // subclasses. 233 228 virtual void erase(const std::vector<Item>& items) = 0; 234 229 235 /// \brief The member function to notificate the observer about the 236 /// container is built. 237 /// 238 /// The build() member function notificates the observer about the 239 /// container is built from an empty container. It have to be 240 /// overrided in the subclasses. 241 230 // \brief The member function to notificate the observer about the 231 // container is built. 232 // 233 // The build() member function notificates the observer about the 234 // container is built from an empty container. It have to be 235 // overrided in the subclasses. 242 236 virtual void build() = 0; 243 237 244 // /\brief The member function to notificate the observer about all245 // /items are erased from the container.246 // /247 // /The clear() member function notificates the observer about all248 // /items are erased from the container. It have to be overrided in249 // /the subclasses.238 // \brief The member function to notificate the observer about all 239 // items are erased from the container. 240 // 241 // The clear() member function notificates the observer about all 242 // items are erased from the container. It have to be overrided in 243 // the subclasses. 250 244 virtual void clear() = 0; 251 245 … … 262 256 public: 263 257 264 // /\brief Default constructor.265 // /266 // /The default constructor of the AlterationNotifier.267 // /It creates an empty notifier.258 // \brief Default constructor. 259 // 260 // The default constructor of the AlterationNotifier. 261 // It creates an empty notifier. 268 262 AlterationNotifier() 269 263 : container(0) {} 270 264 271 // /\brief Constructor.272 // /273 // /Constructor with the observed container parameter.265 // \brief Constructor. 266 // 267 // Constructor with the observed container parameter. 274 268 AlterationNotifier(const Container& _container) 275 269 : container(&_container) {} 276 270 277 // /\brief Copy Constructor of the AlterationNotifier.278 // /279 // /Copy constructor of the AlterationNotifier.280 // /It creates only an empty notifier because the copiable281 // /notifier's observers have to be registered still into that notifier.271 // \brief Copy Constructor of the AlterationNotifier. 272 // 273 // Copy constructor of the AlterationNotifier. 274 // It creates only an empty notifier because the copiable 275 // notifier's observers have to be registered still into that notifier. 282 276 AlterationNotifier(const AlterationNotifier& _notifier) 283 277 : container(_notifier.container) {} 284 278 285 /// \brief Destructor. 286 /// 287 /// Destructor of the AlterationNotifier. 288 /// 279 // \brief Destructor. 280 // 281 // Destructor of the AlterationNotifier. 289 282 ~AlterationNotifier() { 290 283 typename Observers::iterator it; … … 294 287 } 295 288 296 // /\brief Sets the container.297 // /298 // /Sets the container.289 // \brief Sets the container. 290 // 291 // Sets the container. 299 292 void setContainer(const Container& _container) { 300 293 container = &_container; … … 307 300 public: 308 301 309 310 311 /// \brief First item in the container. 312 /// 313 /// Returns the first item in the container. It is 314 /// for start the iteration on the container. 302 // \brief First item in the container. 303 // 304 // Returns the first item in the container. It is 305 // for start the iteration on the container. 315 306 void first(Item& item) const { 316 307 container->first(item); 317 308 } 318 309 319 // /\brief Next item in the container.320 // /321 // /Returns the next item in the container. It is322 // /for iterate on the container.310 // \brief Next item in the container. 311 // 312 // Returns the next item in the container. It is 313 // for iterate on the container. 323 314 void next(Item& item) const { 324 315 container->next(item); 325 316 } 326 317 327 // /\brief Returns the id of the item.328 // /329 // /Returns the id of the item provided by the container.318 // \brief Returns the id of the item. 319 // 320 // Returns the id of the item provided by the container. 330 321 int id(const Item& item) const { 331 322 return container->id(item); 332 323 } 333 324 334 // /\brief Returns the maximum id of the container.335 // /336 // /Returns the maximum id of the container.325 // \brief Returns the maximum id of the container. 326 // 327 // Returns the maximum id of the container. 337 328 int maxId() const { 338 329 return container->maxId(Item()); … … 354 345 public: 355 346 356 /// \brief Notifies all the registed observers about an item added to 357 /// the container. 358 /// 359 /// It notifies all the registed observers about an item added to 360 /// the container. 361 /// 347 // \brief Notifies all the registed observers about an item added to 348 // the container. 349 // 350 // It notifies all the registed observers about an item added to 351 // the container. 362 352 void add(const Item& item) { 363 353 typename Observers::reverse_iterator it; … … 375 365 } 376 366 377 /// \brief Notifies all the registed observers about more item added to 378 /// the container. 379 /// 380 /// It notifies all the registed observers about more item added to 381 /// the container. 382 /// 367 // \brief Notifies all the registed observers about more item added to 368 // the container. 369 // 370 // It notifies all the registed observers about more item added to 371 // the container. 383 372 void add(const std::vector<Item>& items) { 384 373 typename Observers::reverse_iterator it; … … 396 385 } 397 386 398 /// \brief Notifies all the registed observers about an item erased from 399 /// the container. 400 /// 401 /// It notifies all the registed observers about an item erased from 402 /// the container. 403 /// 387 // \brief Notifies all the registed observers about an item erased from 388 // the container. 389 // 390 // It notifies all the registed observers about an item erased from 391 // the container. 404 392 void erase(const Item& item) throw() { 405 393 typename Observers::iterator it = _observers.begin(); … … 416 404 } 417 405 418 /// \brief Notifies all the registed observers about more item erased 419 /// from the container. 420 /// 421 /// It notifies all the registed observers about more item erased from 422 /// the container. 423 /// 406 // \brief Notifies all the registed observers about more item erased 407 // from the container. 408 // 409 // It notifies all the registed observers about more item erased from 410 // the container. 424 411 void erase(const std::vector<Item>& items) { 425 412 typename Observers::iterator it = _observers.begin(); … … 436 423 } 437 424 438 // /\brief Notifies all the registed observers about the container is439 // /built.440 // /441 // /Notifies all the registed observers about the container is built442 // /from an empty container.425 // \brief Notifies all the registed observers about the container is 426 // built. 427 // 428 // Notifies all the registed observers about the container is built 429 // from an empty container. 443 430 void build() { 444 431 typename Observers::reverse_iterator it; … … 456 443 } 457 444 458 // /\brief Notifies all the registed observers about all items are459 // /erased.460 // /461 // /Notifies all the registed observers about all items are erased462 // /from the container.445 // \brief Notifies all the registed observers about all items are 446 // erased. 447 // 448 // Notifies all the registed observers about all items are erased 449 // from the container. 463 450 void clear() { 464 451 typename Observers::iterator it = _observers.begin(); -
lemon/bits/array_map.h
r263 r314 27 27 #include <lemon/concepts/maps.h> 28 28 29 // /\ingroup graphbits30 // /\file31 // /\brief Graph map based on the array storage.29 // \ingroup graphbits 30 // \file 31 // \brief Graph map based on the array storage. 32 32 33 33 namespace lemon { 34 34 35 // /\ingroup graphbits36 // /37 // /\brief Graph map based on the array storage.38 // /39 // /The ArrayMap template class is graph map structure what40 // /automatically updates the map when a key is added to or erased from41 // /the map. This map uses the allocators to implement42 // /the container functionality.43 // /44 // /The template parameters are the Graph the current Item type and45 // /the Value type of the map.35 // \ingroup graphbits 36 // 37 // \brief Graph map based on the array storage. 38 // 39 // The ArrayMap template class is graph map structure what 40 // automatically updates the map when a key is added to or erased from 41 // the map. This map uses the allocators to implement 42 // the container functionality. 43 // 44 // The template parameters are the Graph the current Item type and 45 // the Value type of the map. 46 46 template <typename _Graph, typename _Item, typename _Value> 47 47 class ArrayMap 48 48 : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { 49 49 public: 50 // /The graph type of the maps.50 // The graph type of the maps. 51 51 typedef _Graph Graph; 52 // /The item type of the map.52 // The item type of the map. 53 53 typedef _Item Item; 54 // /The reference map tag.54 // The reference map tag. 55 55 typedef True ReferenceMapTag; 56 56 57 // /The key type of the maps.57 // The key type of the maps. 58 58 typedef _Item Key; 59 // /The value type of the map.59 // The value type of the map. 60 60 typedef _Value Value; 61 61 62 // /The const reference type of the map.62 // The const reference type of the map. 63 63 typedef const _Value& ConstReference; 64 // /The reference type of the map.64 // The reference type of the map. 65 65 typedef _Value& Reference; 66 66 67 // /The notifier type.67 // The notifier type. 68 68 typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; 69 69 70 // /The MapBase of the Map which imlements the core regisitry function.70 // The MapBase of the Map which imlements the core regisitry function. 71 71 typedef typename Notifier::ObserverBase Parent; 72 72 … … 76 76 public: 77 77 78 // /\brief Graph initialized map constructor.79 // /80 // /Graph initialized map constructor.78 // \brief Graph initialized map constructor. 79 // 80 // Graph initialized map constructor. 81 81 explicit ArrayMap(const Graph& graph) { 82 82 Parent::attach(graph.notifier(Item())); … … 90 90 } 91 91 92 // /\brief Constructor to use default value to initialize the map.93 // /94 // /It constructs a map and initialize all of the the map.92 // \brief Constructor to use default value to initialize the map. 93 // 94 // It constructs a map and initialize all of the the map. 95 95 ArrayMap(const Graph& graph, const Value& value) { 96 96 Parent::attach(graph.notifier(Item())); … … 105 105 106 106 private: 107 // /\brief Constructor to copy a map of the same map type.108 // /109 // /Constructor to copy a map of the same map type.107 // \brief Constructor to copy a map of the same map type. 108 // 109 // Constructor to copy a map of the same map type. 110 110 ArrayMap(const ArrayMap& copy) : Parent() { 111 111 if (copy.attached()) { … … 123 123 } 124 124 125 // /\brief Assign operator.126 // /127 // /This operator assigns for each item in the map the128 // /value mapped to the same item in the copied map.129 // /The parameter map should be indiced with the same130 // /itemset because this assign operator does not change131 // /the container of the map.125 // \brief Assign operator. 126 // 127 // This operator assigns for each item in the map the 128 // value mapped to the same item in the copied map. 129 // The parameter map should be indiced with the same 130 // itemset because this assign operator does not change 131 // the container of the map. 132 132 ArrayMap& operator=(const ArrayMap& cmap) { 133 133 return operator=<ArrayMap>(cmap); … … 135 135 136 136 137 // /\brief Template assign operator.138 // /139 // /The given parameter should be conform to the ReadMap140 // /concecpt and could be indiced by the current item set of141 // /the NodeMap. In this case the value for each item142 // /is assigned by the value of the given ReadMap.137 // \brief Template assign operator. 138 // 139 // The given parameter should be conform to the ReadMap 140 // concecpt and could be indiced by the current item set of 141 // the NodeMap. In this case the value for each item 142 // is assigned by the value of the given ReadMap. 143 143 template <typename CMap> 144 144 ArrayMap& operator=(const CMap& cmap) { … … 153 153 154 154 public: 155 // /\brief The destructor of the map.156 // /157 // /The destructor of the map.155 // \brief The destructor of the map. 156 // 157 // The destructor of the map. 158 158 virtual ~ArrayMap() { 159 159 if (attached()) { … … 171 171 public: 172 172 173 // /\brief The subscript operator.174 // /175 // /The subscript operator. The map can be subscripted by the176 // /actual keys of the graph.173 // \brief The subscript operator. 174 // 175 // The subscript operator. The map can be subscripted by the 176 // actual keys of the graph. 177 177 Value& operator[](const Key& key) { 178 178 int id = Parent::notifier()->id(key); … … 180 180 } 181 181 182 // /\brief The const subscript operator.183 // /184 // /The const subscript operator. The map can be subscripted by the185 // /actual keys of the graph.182 // \brief The const subscript operator. 183 // 184 // The const subscript operator. The map can be subscripted by the 185 // actual keys of the graph. 186 186 const Value& operator[](const Key& key) const { 187 187 int id = Parent::notifier()->id(key); … … 189 189 } 190 190 191 // /\brief Setter function of the map.192 // /193 // /Setter function of the map. Equivalent with map[key] = val.194 // /This is a compatibility feature with the not dereferable maps.191 // \brief Setter function of the map. 192 // 193 // Setter function of the map. Equivalent with map[key] = val. 194 // This is a compatibility feature with the not dereferable maps. 195 195 void set(const Key& key, const Value& val) { 196 196 (*this)[key] = val; … … 199 199 protected: 200 200 201 // /\brief Adds a new key to the map.202 // /203 // /It adds a new key to the map. It called by the observer notifier204 // /and it overrides the add() member function of the observer base.201 // \brief Adds a new key to the map. 202 // 203 // It adds a new key to the map. It called by the observer notifier 204 // and it overrides the add() member function of the observer base. 205 205 virtual void add(const Key& key) { 206 206 Notifier* nf = Parent::notifier(); … … 227 227 } 228 228 229 // /\brief Adds more new keys to the map.230 // /231 // /It adds more new keys to the map. It called by the observer notifier232 // /and it overrides the add() member function of the observer base.229 // \brief Adds more new keys to the map. 230 // 231 // It adds more new keys to the map. It called by the observer notifier 232 // and it overrides the add() member function of the observer base. 233 233 virtual void add(const std::vector<Key>& keys) { 234 234 Notifier* nf = Parent::notifier(); … … 271 271 } 272 272 273 // /\brief Erase a key from the map.274 // /275 // /Erase a key from the map. It called by the observer notifier276 // /and it overrides the erase() member function of the observer base.273 // \brief Erase a key from the map. 274 // 275 // Erase a key from the map. It called by the observer notifier 276 // and it overrides the erase() member function of the observer base. 277 277 virtual void erase(const Key& key) { 278 278 int id = Parent::notifier()->id(key); … … 280 280 } 281 281 282 // /\brief Erase more keys from the map.283 // /284 // /Erase more keys from the map. It called by the observer notifier285 // /and it overrides the erase() member function of the observer base.282 // \brief Erase more keys from the map. 283 // 284 // Erase more keys from the map. It called by the observer notifier 285 // and it overrides the erase() member function of the observer base. 286 286 virtual void erase(const std::vector<Key>& keys) { 287 287 for (int i = 0; i < int(keys.size()); ++i) { … … 291 291 } 292 292 293 // /\brief Buildes the map.294 // /295 // /It buildes the map. It called by the observer notifier296 // /and it overrides the build() member function of the observer base.293 // \brief Buildes the map. 294 // 295 // It buildes the map. It called by the observer notifier 296 // and it overrides the build() member function of the observer base. 297 297 virtual void build() { 298 298 Notifier* nf = Parent::notifier(); … … 305 305 } 306 306 307 // /\brief Clear the map.308 // /309 // /It erase all items from the map. It called by the observer notifier310 // /and it overrides the clear() member function of the observer base.307 // \brief Clear the map. 308 // 309 // It erase all items from the map. It called by the observer notifier 310 // and it overrides the clear() member function of the observer base. 311 311 virtual void clear() { 312 312 Notifier* nf = Parent::notifier(); -
lemon/bits/base_extender.h
r289 r314 29 29 #include <lemon/concepts/maps.h> 30 30 31 // /\ingroup digraphbits32 // /\file33 // /\brief Extenders for the digraph types31 //\ingroup digraphbits 32 //\file 33 //\brief Extenders for the digraph types 34 34 namespace lemon { 35 35 36 // /\ingroup digraphbits37 // /38 // /\brief BaseDigraph to BaseGraph extender36 // \ingroup digraphbits 37 // 38 // \brief BaseDigraph to BaseGraph extender 39 39 template <typename Base> 40 40 class UndirDigraphExtender : public Base { … … 75 75 }; 76 76 77 // /First node of the edge77 // First node of the edge 78 78 Node u(const Edge &e) const { 79 79 return Parent::source(e); 80 80 } 81 81 82 // /Source of the given arc82 // Source of the given arc 83 83 Node source(const Arc &e) const { 84 84 return e.forward ? Parent::source(e) : Parent::target(e); 85 85 } 86 86 87 // /Second node of the edge87 // Second node of the edge 88 88 Node v(const Edge &e) const { 89 89 return Parent::target(e); 90 90 } 91 91 92 // /Target of the given arc92 // Target of the given arc 93 93 Node target(const Arc &e) const { 94 94 return e.forward ? Parent::target(e) : Parent::source(e); 95 95 } 96 96 97 // /\brief Directed arc from an edge.98 // /99 // /Returns a directed arc corresponding to the specified edge.100 // /If the given bool is true, the first node of the given edge and101 // /the source node of the returned arc are the same.97 // \brief Directed arc from an edge. 98 // 99 // Returns a directed arc corresponding to the specified edge. 100 // If the given bool is true, the first node of the given edge and 101 // the source node of the returned arc are the same. 102 102 static Arc direct(const Edge &e, bool d) { 103 103 return Arc(e, d); 104 104 } 105 105 106 // /Returns whether the given directed arc has the same orientation107 // /as the corresponding edge.106 // Returns whether the given directed arc has the same orientation 107 // as the corresponding edge. 108 108 static bool direction(const Arc &a) { return a.forward; } 109 109 -
lemon/bits/bezier.h
r209 r314 20 20 #define LEMON_BEZIER_H 21 21 22 // /\ingroup misc23 // /\file24 // /\brief Classes to compute with Bezier curves.25 // /26 // /Up to now this file is used internally by \ref graph_to_eps.h22 //\ingroup misc 23 //\file 24 //\brief Classes to compute with Bezier curves. 25 // 26 //Up to now this file is used internally by \ref graph_to_eps.h 27 27 28 28 #include<lemon/dim2.h> -
lemon/bits/default_map.h
r313 r314 20 20 #define LEMON_BITS_DEFAULT_MAP_H 21 21 22 23 22 #include <lemon/bits/array_map.h> 24 23 #include <lemon/bits/vector_map.h> 25 24 //#include <lemon/bits/debug_map.h> 26 25 27 // /\ingroup graphbits28 // /\file29 // /\brief Graph maps that construct and destruct their elements dynamically.26 //\ingroup graphbits 27 //\file 28 //\brief Graph maps that construct and destruct their elements dynamically. 30 29 31 30 namespace lemon { … … 150 149 // #endif 151 150 152 // /DefaultMap class151 // DefaultMap class 153 152 template <typename _Graph, typename _Item, typename _Value> 154 153 class DefaultMap -
lemon/bits/enable_if.h
r220 r314 36 36 #define LEMON_BITS_ENABLE_IF_H 37 37 38 // /\file39 // /\brief Miscellaneous basic utilities38 //\file 39 //\brief Miscellaneous basic utilities 40 40 41 41 namespace lemon 42 42 { 43 43 44 // /Basic type for defining "tags". A "YES" condition for \c enable_if.44 // Basic type for defining "tags". A "YES" condition for \c enable_if. 45 45 46 // /Basic type for defining "tags". A "YES" condition for \c enable_if.47 // /48 // /\sa False46 // Basic type for defining "tags". A "YES" condition for \c enable_if. 47 // 48 //\sa False 49 49 struct True { 50 // /\e50 //\e 51 51 static const bool value = true; 52 52 }; 53 53 54 // /Basic type for defining "tags". A "NO" condition for \c enable_if.54 // Basic type for defining "tags". A "NO" condition for \c enable_if. 55 55 56 // /Basic type for defining "tags". A "NO" condition for \c enable_if.57 // /58 // /\sa True56 // Basic type for defining "tags". A "NO" condition for \c enable_if. 57 // 58 //\sa True 59 59 struct False { 60 // /\e60 //\e 61 61 static const bool value = false; 62 62 }; -
lemon/bits/graph_extender.h
r263 r314 28 28 #include <lemon/concepts/maps.h> 29 29 30 // /\ingroup graphbits31 // /\file32 // /\brief Extenders for the digraph types30 //\ingroup graphbits 31 //\file 32 //\brief Extenders for the digraph types 33 33 namespace lemon { 34 34 35 // /\ingroup graphbits36 // /37 // /\brief Extender for the Digraphs35 // \ingroup graphbits 36 // 37 // \brief Extender for the Digraphs 38 38 template <typename Base> 39 39 class DigraphExtender : public Base { … … 187 187 }; 188 188 189 // /\brief Base node of the iterator190 // /191 // /Returns the base node (i.e. the source in this case) of the iterator189 // \brief Base node of the iterator 190 // 191 // Returns the base node (i.e. the source in this case) of the iterator 192 192 Node baseNode(const OutArcIt &arc) const { 193 193 return Parent::source(arc); 194 194 } 195 // /\brief Running node of the iterator196 // /197 // /Returns the running node (i.e. the target in this case) of the198 // /iterator195 // \brief Running node of the iterator 196 // 197 // Returns the running node (i.e. the target in this case) of the 198 // iterator 199 199 Node runningNode(const OutArcIt &arc) const { 200 200 return Parent::target(arc); 201 201 } 202 202 203 // /\brief Base node of the iterator204 // /205 // /Returns the base node (i.e. the target in this case) of the iterator203 // \brief Base node of the iterator 204 // 205 // Returns the base node (i.e. the target in this case) of the iterator 206 206 Node baseNode(const InArcIt &arc) const { 207 207 return Parent::target(arc); 208 208 } 209 // /\brief Running node of the iterator210 // /211 // /Returns the running node (i.e. the source in this case) of the212 // /iterator209 // \brief Running node of the iterator 210 // 211 // Returns the running node (i.e. the source in this case) of the 212 // iterator 213 213 Node runningNode(const InArcIt &arc) const { 214 214 return Parent::source(arc); … … 326 326 }; 327 327 328 // /\ingroup _graphbits329 // /330 // /\brief Extender for the Graphs328 // \ingroup _graphbits 329 // 330 // \brief Extender for the Graphs 331 331 template <typename Base> 332 332 class GraphExtender : public Base { … … 556 556 }; 557 557 558 // /\brief Base node of the iterator559 // /560 // /Returns the base node (ie. the source in this case) of the iterator558 // \brief Base node of the iterator 559 // 560 // Returns the base node (ie. the source in this case) of the iterator 561 561 Node baseNode(const OutArcIt &arc) const { 562 562 return Parent::source(static_cast<const Arc&>(arc)); 563 563 } 564 // /\brief Running node of the iterator565 // /566 // /Returns the running node (ie. the target in this case) of the567 // /iterator564 // \brief Running node of the iterator 565 // 566 // Returns the running node (ie. the target in this case) of the 567 // iterator 568 568 Node runningNode(const OutArcIt &arc) const { 569 569 return Parent::target(static_cast<const Arc&>(arc)); 570 570 } 571 571 572 // /\brief Base node of the iterator573 // /574 // /Returns the base node (ie. the target in this case) of the iterator572 // \brief Base node of the iterator 573 // 574 // Returns the base node (ie. the target in this case) of the iterator 575 575 Node baseNode(const InArcIt &arc) const { 576 576 return Parent::target(static_cast<const Arc&>(arc)); 577 577 } 578 // /\brief Running node of the iterator579 // /580 // /Returns the running node (ie. the source in this case) of the581 // /iterator578 // \brief Running node of the iterator 579 // 580 // Returns the running node (ie. the source in this case) of the 581 // iterator 582 582 Node runningNode(const InArcIt &arc) const { 583 583 return Parent::source(static_cast<const Arc&>(arc)); 584 584 } 585 585 586 // /Base node of the iterator587 // /588 // /Returns the base node of the iterator586 // Base node of the iterator 587 // 588 // Returns the base node of the iterator 589 589 Node baseNode(const IncEdgeIt &edge) const { 590 590 return edge._direction ? u(edge) : v(edge); 591 591 } 592 // /Running node of the iterator593 // /594 // /Returns the running node of the iterator592 // Running node of the iterator 593 // 594 // Returns the running node of the iterator 595 595 Node runningNode(const IncEdgeIt &edge) const { 596 596 return edge._direction ? v(edge) : u(edge); -
lemon/bits/map_extender.h
r263 r314 27 27 #include <lemon/concepts/maps.h> 28 28 29 // /\file30 // /\brief Extenders for iterable maps.29 //\file 30 //\brief Extenders for iterable maps. 31 31 32 32 namespace lemon { 33 33 34 // /\ingroup graphbits35 // /36 // /\brief Extender for maps34 // \ingroup graphbits 35 // 36 // \brief Extender for maps 37 37 template <typename _Map> 38 38 class MapExtender : public _Map { … … 172 172 }; 173 173 174 // /\ingroup graphbits175 // /176 // /\brief Extender for maps which use a subset of the items.174 // \ingroup graphbits 175 // 176 // \brief Extender for maps which use a subset of the items. 177 177 template <typename _Graph, typename _Map> 178 178 class SubMapExtender : public _Map { -
lemon/bits/traits.h
r220 r314 20 20 #define LEMON_BITS_TRAITS_H 21 21 22 // /\file23 // /\brief Traits for graphs and maps24 // /22 //\file 23 //\brief Traits for graphs and maps 24 // 25 25 26 26 #include <lemon/bits/enable_if.h> -
lemon/bits/vector_map.h
r280 r314 29 29 #include <lemon/concepts/maps.h> 30 30 31 // /\ingroup graphbits32 // /33 // /\file34 // /\brief Vector based graph maps.31 //\ingroup graphbits 32 // 33 //\file 34 //\brief Vector based graph maps. 35 35 namespace lemon { 36 36 37 // /\ingroup graphbits38 // /39 // /\brief Graph map based on the std::vector storage.40 // /41 // /The VectorMap template class is graph map structure what42 // /automatically updates the map when a key is added to or erased from43 // /the map. This map type uses the std::vector to store the values.44 // /45 // /\tparam _Graph The graph this map is attached to.46 // /\tparam _Item The item type of the graph items.47 // /\tparam _Value The value type of the map.37 // \ingroup graphbits 38 // 39 // \brief Graph map based on the std::vector storage. 40 // 41 // The VectorMap template class is graph map structure what 42 // automatically updates the map when a key is added to or erased from 43 // the map. This map type uses the std::vector to store the values. 44 // 45 // \tparam _Graph The graph this map is attached to. 46 // \tparam _Item The item type of the graph items. 47 // \tparam _Value The value type of the map. 48 48 template <typename _Graph, typename _Item, typename _Value> 49 49 class VectorMap … … 51 51 private: 52 52 53 // /The container type of the map.53 // The container type of the map. 54 54 typedef std::vector<_Value> Container; 55 55 56 56 public: 57 57 58 // /The graph type of the map.58 // The graph type of the map. 59 59 typedef _Graph Graph; 60 // /The item type of the map.60 // The item type of the map. 61 61 typedef _Item Item; 62 // /The reference map tag.62 // The reference map tag. 63 63 typedef True ReferenceMapTag; 64 64 65 // /The key type of the map.65 // The key type of the map. 66 66 typedef _Item Key; 67 // /The value type of the map.67 // The value type of the map. 68 68 typedef _Value Value; 69 69 70 // /The notifier type.70 // The notifier type. 71 71 typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; 72 72 73 // /The map type.73 // The map type. 74 74 typedef VectorMap Map; 75 // /The base class of the map.75 // The base class of the map. 76 76 typedef typename Notifier::ObserverBase Parent; 77 77 78 // /The reference type of the map;78 // The reference type of the map; 79 79 typedef typename Container::reference Reference; 80 // /The const reference type of the map;80 // The const reference type of the map; 81 81 typedef typename Container::const_reference ConstReference; 82 82 83 83 84 // /\brief Constructor to attach the new map into the notifier.85 // /86 // /It constructs a map and attachs it into the notifier.87 // /It adds all the items of the graph to the map.84 // \brief Constructor to attach the new map into the notifier. 85 // 86 // It constructs a map and attachs it into the notifier. 87 // It adds all the items of the graph to the map. 88 88 VectorMap(const Graph& graph) { 89 89 Parent::attach(graph.notifier(Item())); … … 91 91 } 92 92 93 // /\brief Constructor uses given value to initialize the map.94 // /95 // /It constructs a map uses a given value to initialize the map.96 // /It adds all the items of the graph to the map.93 // \brief Constructor uses given value to initialize the map. 94 // 95 // It constructs a map uses a given value to initialize the map. 96 // It adds all the items of the graph to the map. 97 97 VectorMap(const Graph& graph, const Value& value) { 98 98 Parent::attach(graph.notifier(Item())); … … 101 101 102 102 private: 103 // /\brief Copy constructor104 // /105 // /Copy constructor.103 // \brief Copy constructor 104 // 105 // Copy constructor. 106 106 VectorMap(const VectorMap& _copy) : Parent() { 107 107 if (_copy.attached()) { … … 111 111 } 112 112 113 // /\brief Assign operator.114 // /115 // /This operator assigns for each item in the map the116 // /value mapped to the same item in the copied map.117 // /The parameter map should be indiced with the same118 // /itemset because this assign operator does not change119 // /the container of the map.113 // \brief Assign operator. 114 // 115 // This operator assigns for each item in the map the 116 // value mapped to the same item in the copied map. 117 // The parameter map should be indiced with the same 118 // itemset because this assign operator does not change 119 // the container of the map. 120 120 VectorMap& operator=(const VectorMap& cmap) { 121 121 return operator=<VectorMap>(cmap); … … 123 123 124 124 125 // /\brief Template assign operator.126 // /127 // /The given parameter should be conform to the ReadMap128 // /concecpt and could be indiced by the current item set of129 // /the NodeMap. In this case the value for each item130 // /is assigned by the value of the given ReadMap.125 // \brief Template assign operator. 126 // 127 // The given parameter should be conform to the ReadMap 128 // concecpt and could be indiced by the current item set of 129 // the NodeMap. In this case the value for each item 130 // is assigned by the value of the given ReadMap. 131 131 template <typename CMap> 132 132 VectorMap& operator=(const CMap& cmap) { … … 142 142 public: 143 143 144 // /\brief The subcript operator.145 // /146 // /The subscript operator. The map can be subscripted by the147 // /actual items of the graph.144 // \brief The subcript operator. 145 // 146 // The subscript operator. The map can be subscripted by the 147 // actual items of the graph. 148 148 Reference operator[](const Key& key) { 149 149 return container[Parent::notifier()->id(key)]; 150 150 } 151 151 152 // /\brief The const subcript operator.153 // /154 // /The const subscript operator. The map can be subscripted by the155 // /actual items of the graph.152 // \brief The const subcript operator. 153 // 154 // The const subscript operator. The map can be subscripted by the 155 // actual items of the graph. 156 156 ConstReference operator[](const Key& key) const { 157 157 return container[Parent::notifier()->id(key)]; … … 159 159 160 160 161 // /\brief The setter function of the map.162 // /163 // /It the same as operator[](key) = value expression.161 // \brief The setter function of the map. 162 // 163 // It the same as operator[](key) = value expression. 164 164 void set(const Key& key, const Value& value) { 165 165 (*this)[key] = value; … … 168 168 protected: 169 169 170 // /\brief Adds a new key to the map.171 // /172 // /It adds a new key to the map. It called by the observer notifier173 // /and it overrides the add() member function of the observer base.170 // \brief Adds a new key to the map. 171 // 172 // It adds a new key to the map. It called by the observer notifier 173 // and it overrides the add() member function of the observer base. 174 174 virtual void add(const Key& key) { 175 175 int id = Parent::notifier()->id(key); … … 179 179 } 180 180 181 // /\brief Adds more new keys to the map.182 // /183 // /It adds more new keys to the map. It called by the observer notifier184 // /and it overrides the add() member function of the observer base.181 // \brief Adds more new keys to the map. 182 // 183 // It adds more new keys to the map. It called by the observer notifier 184 // and it overrides the add() member function of the observer base. 185 185 virtual void add(const std::vector<Key>& keys) { 186 186 int max = container.size() - 1; … … 194 194 } 195 195 196 // /\brief Erase a key from the map.197 // /198 // /Erase a key from the map. It called by the observer notifier199 // /and it overrides the erase() member function of the observer base.196 // \brief Erase a key from the map. 197 // 198 // Erase a key from the map. It called by the observer notifier 199 // and it overrides the erase() member function of the observer base. 200 200 virtual void erase(const Key& key) { 201 201 container[Parent::notifier()->id(key)] = Value(); 202 202 } 203 203 204 // /\brief Erase more keys from the map.205 // /206 // /Erase more keys from the map. It called by the observer notifier207 // /and it overrides the erase() member function of the observer base.204 // \brief Erase more keys from the map. 205 // 206 // Erase more keys from the map. It called by the observer notifier 207 // and it overrides the erase() member function of the observer base. 208 208 virtual void erase(const std::vector<Key>& keys) { 209 209 for (int i = 0; i < int(keys.size()); ++i) { … … 212 212 } 213 213 214 // /\brief Buildes the map.215 // /216 // /It buildes the map. It called by the observer notifier217 // /and it overrides the build() member function of the observer base.214 // \brief Buildes the map. 215 // 216 // It buildes the map. It called by the observer notifier 217 // and it overrides the build() member function of the observer base. 218 218 virtual void build() { 219 219 int size = Parent::notifier()->maxId() + 1; … … 222 222 } 223 223 224 // /\brief Clear the map.225 // /226 // /It erase all items from the map. It called by the observer notifier227 // /and it overrides the clear() member function of the observer base.224 // \brief Clear the map. 225 // 226 // It erase all items from the map. It called by the observer notifier 227 // and it overrides the clear() member function of the observer base. 228 228 virtual void clear() { 229 229 container.clear();
Note: See TracChangeset
for help on using the changeset viewer.