Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/bits/alteration_notifier.h
- Timestamp:
- 07/13/08 20:51:02 (16 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/alteration_notifier.h
r157 r209 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 3 * This file is a part of LEMON, a generic C++ optimization library 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 33 33 /// \ingroup graphbits 34 34 /// 35 /// \brief Notifier class to notify observes about alterations in 35 /// \brief Notifier class to notify observes about alterations in 36 36 /// a container. 37 37 /// … … 50 50 /// alteration of the graph. 51 51 /// 52 /// This class provides an interface to the container. The \e first() and \e 52 /// This class provides an interface to the container. The \e first() and \e 53 53 /// next() member functions make possible to iterate on the keys of the 54 54 /// container. The \e id() function returns an integer id for each key. … … 61 61 /// from the graph. If all items are erased from the graph or from an empty 62 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 63 /// clear() and build() members. Important rule that if we erase items 64 64 /// from graph we should first signal the alteration and after that erase 65 65 /// them from the container, on the other way on item addition we should … … 69 69 /// \e ObserverBase nested class. The signals can be handled with 70 70 /// overriding the virtual functions defined in the base class. The 71 /// observer base can be attached to the notifier with the 71 /// observer base can be attached to the notifier with the 72 72 /// \e attach() member and can be detached with detach() function. The 73 73 /// alteration handlers should not call any function which signals … … 80 80 /// be rolled back by calling the \e erase() or \e clear() 81 81 /// functions. Thence the \e erase() and \e clear() should not throw 82 /// exception. Actullay, it can be throw only 82 /// exception. Actullay, it can be throw only 83 83 /// \ref AlterationObserver::ImmediateDetach ImmediateDetach 84 84 /// exception which detach the observer from the notifier. … … 86 86 /// There are some place when the alteration observing is not completly 87 87 /// reliable. If we want to carry out the node degree in the graph 88 /// as in the \ref InDegMap and we use the reverseEdge that cause 88 /// as in the \ref InDegMap and we use the reverseEdge that cause 89 89 /// unreliable functionality. Because the alteration observing signals 90 90 /// only erasing and adding but not the reversing it will stores bad … … 105 105 typedef _Item Item; 106 106 107 /// \brief Exception which can be called from \e clear() and 107 /// \brief Exception which can be called from \e clear() and 108 108 /// \e erase(). 109 109 /// … … 128 128 /// The build() and clear() members are to notify the observer 129 129 /// about the container is built from an empty container or 130 /// is cleared to an empty container. 130 /// is cleared to an empty container. 131 131 132 132 class ObserverBase { … … 139 139 /// 140 140 /// Default constructor for ObserverBase. 141 /// 141 /// 142 142 ObserverBase() : _notifier(0) {} 143 143 … … 152 152 /// 153 153 /// Constructor which attach the obserever to the same notifier as 154 /// the other observer is attached to. 154 /// the other observer is attached to. 155 155 ObserverBase(const ObserverBase& copy) { 156 156 if (copy.attached()) { 157 157 attach(*copy.notifier()); 158 159 } 160 158 } 159 } 160 161 161 /// \brief Destructor 162 162 virtual ~ObserverBase() { … … 171 171 /// 172 172 void attach(AlterationNotifier& nf) { 173 174 } 175 173 nf.attach(*this); 174 } 175 176 176 /// \brief Detaches the observer into an AlterationNotifier. 177 177 /// … … 181 181 _notifier->detach(*this); 182 182 } 183 184 /// \brief Gives back a pointer to the notifier which the map 183 184 /// \brief Gives back a pointer to the notifier which the map 185 185 /// attached into. 186 186 /// … … 189 189 /// 190 190 Notifier* notifier() const { return const_cast<Notifier*>(_notifier); } 191 191 192 192 /// Gives back true when the observer is attached into a notifier. 193 193 bool attached() const { return _notifier != 0; } … … 198 198 199 199 protected: 200 200 201 201 Notifier* _notifier; 202 202 typename std::list<ObserverBase*>::iterator _index; … … 210 210 virtual void add(const Item&) = 0; 211 211 212 /// \brief The member function to notificate the observer about 212 /// \brief The member function to notificate the observer about 213 213 /// more item is added to the container. 214 214 /// … … 223 223 /// The erase() member function notificates the observer about an 224 224 /// item is erased from the container. It have to be overrided in 225 /// the subclasses. 225 /// the subclasses. 226 226 virtual void erase(const Item&) = 0; 227 227 228 /// \brief The member function to notificate the observer about 228 /// \brief The member function to notificate the observer about 229 229 /// more item is erased from the container. 230 230 /// … … 248 248 /// The clear() member function notificates the observer about all 249 249 /// items are erased from the container. It have to be overrided in 250 /// the subclasses. 250 /// the subclasses. 251 251 virtual void clear() = 0; 252 252 253 253 }; 254 254 255 255 protected: 256 256 257 257 const Container* container; 258 258 259 typedef std::list<ObserverBase*> Observers; 259 typedef std::list<ObserverBase*> Observers; 260 260 Observers _observers; 261 261 262 262 263 263 public: 264 264 265 265 /// \brief Default constructor. 266 266 /// 267 /// The default constructor of the AlterationNotifier. 267 /// The default constructor of the AlterationNotifier. 268 268 /// It creates an empty notifier. 269 AlterationNotifier() 269 AlterationNotifier() 270 270 : container(0) {} 271 271 … … 273 273 /// 274 274 /// Constructor with the observed container parameter. 275 AlterationNotifier(const Container& _container) 275 AlterationNotifier(const Container& _container) 276 276 : container(&_container) {} 277 277 278 /// \brief Copy Constructor of the AlterationNotifier. 279 /// 280 /// Copy constructor of the AlterationNotifier. 278 /// \brief Copy Constructor of the AlterationNotifier. 279 /// 280 /// Copy constructor of the AlterationNotifier. 281 281 /// It creates only an empty notifier because the copiable 282 282 /// notifier's observers have to be registered still into that notifier. 283 AlterationNotifier(const AlterationNotifier& _notifier) 283 AlterationNotifier(const AlterationNotifier& _notifier) 284 284 : container(_notifier.container) {} 285 285 286 286 /// \brief Destructor. 287 /// 287 /// 288 288 /// Destructor of the AlterationNotifier. 289 289 /// … … 291 291 typename Observers::iterator it; 292 292 for (it = _observers.begin(); it != _observers.end(); ++it) { 293 293 (*it)->_notifier = 0; 294 294 } 295 295 } … … 339 339 return container->maxId(Item()); 340 340 } 341 341 342 342 protected: 343 343 … … 345 345 observer._index = _observers.insert(_observers.begin(), &observer); 346 346 observer._notifier = this; 347 } 347 } 348 348 349 349 void detach(ObserverBase& observer) { … … 354 354 355 355 public: 356 357 /// \brief Notifies all the registed observers about an item added to 358 /// the container. 359 /// 360 /// It notifies all the registed observers about an item added to 361 /// the container. 362 /// 356 357 /// \brief Notifies all the registed observers about an item added to 358 /// the container. 359 /// 360 /// It notifies all the registed observers about an item added to 361 /// the container. 362 /// 363 363 void add(const Item& item) { 364 364 typename Observers::reverse_iterator it; … … 374 374 throw; 375 375 } 376 } 377 378 /// \brief Notifies all the registed observers about more item added to 379 /// the container. 380 /// 381 /// It notifies all the registed observers about more item added to 382 /// the container. 383 /// 376 } 377 378 /// \brief Notifies all the registed observers about more item added to 379 /// the container. 380 /// 381 /// It notifies all the registed observers about more item added to 382 /// the container. 383 /// 384 384 void add(const std::vector<Item>& items) { 385 385 typename Observers::reverse_iterator it; … … 395 395 throw; 396 396 } 397 } 398 399 /// \brief Notifies all the registed observers about an item erased from 400 /// the container. 401 /// 402 /// It notifies all the registed observers about an item erased from 403 /// the container. 404 /// 397 } 398 399 /// \brief Notifies all the registed observers about an item erased from 400 /// the container. 401 /// 402 /// It notifies all the registed observers about an item erased from 403 /// the container. 404 /// 405 405 void erase(const Item& item) throw() { 406 406 typename Observers::iterator it = _observers.begin(); … … 417 417 } 418 418 419 /// \brief Notifies all the registed observers about more item erased 419 /// \brief Notifies all the registed observers about more item erased 420 420 /// from the container. 421 /// 422 /// It notifies all the registed observers about more item erased from 423 /// the container. 424 /// 421 /// 422 /// It notifies all the registed observers about more item erased from 423 /// the container. 424 /// 425 425 void erase(const std::vector<Item>& items) { 426 426 typename Observers::iterator it = _observers.begin(); … … 437 437 } 438 438 439 /// \brief Notifies all the registed observers about the container is 439 /// \brief Notifies all the registed observers about the container is 440 440 /// built. 441 /// 441 /// 442 442 /// Notifies all the registed observers about the container is built 443 443 /// from an empty container. … … 457 457 } 458 458 459 /// \brief Notifies all the registed observers about all items are 459 /// \brief Notifies all the registed observers about all items are 460 460 /// erased. 461 461 ///
Note: See TracChangeset
for help on using the changeset viewer.