[946] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
[1956] | 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
[946] | 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[1999] | 19 | #ifndef LEMON_BITS_ALTERATION_NOTIFIER_H |
---|
| 20 | #define LEMON_BITS_ALTERATION_NOTIFIER_H |
---|
[946] | 21 | |
---|
| 22 | #include <vector> |
---|
[1999] | 23 | |
---|
| 24 | #include <lemon/bits/utility.h> |
---|
[946] | 25 | |
---|
[1996] | 26 | ///\ingroup graphbits |
---|
[946] | 27 | ///\file |
---|
[1999] | 28 | ///\brief Observer notifier for graph alteration observers. |
---|
[946] | 29 | |
---|
| 30 | namespace lemon { |
---|
| 31 | |
---|
[1999] | 32 | /// \ingroup graphbits |
---|
[1414] | 33 | /// |
---|
[1999] | 34 | /// \brief Notifier class to notify observes about alterations in |
---|
| 35 | /// a container. |
---|
[946] | 36 | /// |
---|
[1999] | 37 | /// The simple graph's can be refered as two containers, one node container |
---|
| 38 | /// and one edge container. But they are not standard containers they |
---|
| 39 | /// does not store values directly they are just key continars for more |
---|
| 40 | /// value containers which are the node and edge maps. |
---|
[946] | 41 | /// |
---|
[1999] | 42 | /// The graph's node and edge sets can be changed as we add or erase |
---|
| 43 | /// nodes and edges in the graph. Lemon would like to handle easily |
---|
| 44 | /// that the node and edge maps should contain values for all nodes or |
---|
| 45 | /// edges. If we want to check on every indicing if the map contains |
---|
| 46 | /// the current indicing key that cause a drawback in the performance |
---|
[2006] | 47 | /// in the library. We use another solution we notify all maps about |
---|
[1999] | 48 | /// an alteration in the graph, which cause only drawback on the |
---|
| 49 | /// alteration of the graph. |
---|
| 50 | /// |
---|
| 51 | /// This class provides an interface to the container. The \e first() and \e |
---|
| 52 | /// next() member functions make possible to iterate on the keys of the |
---|
| 53 | /// container. The \e id() function returns an integer id for each key. |
---|
| 54 | /// The \e maxId() function gives back an upper bound of the ids. |
---|
| 55 | /// |
---|
| 56 | /// For the proper functonality of this class, we should notify it |
---|
| 57 | /// about each alteration in the container. The alterations have four type |
---|
| 58 | /// as \e add(), \e erase(), \e build() and \e clear(). The \e add() and |
---|
| 59 | /// \e erase() signals that only one or few items added or erased to or |
---|
| 60 | /// from the graph. If all items are erased from the graph or from an empty |
---|
| 61 | /// graph a new graph is builded then it can be signaled with the |
---|
| 62 | /// clear() and build() members. Important rule that if we erase items |
---|
| 63 | /// from graph we should first signal the alteration and after that erase |
---|
| 64 | /// them from the container, on the other way on item addition we should |
---|
| 65 | /// first extend the container and just after that signal the alteration. |
---|
| 66 | /// |
---|
| 67 | /// The alteration can be observed with a class inherited from the |
---|
| 68 | /// \e ObserverBase nested class. The signals can be handled with |
---|
[2188] | 69 | /// overriding the virtual functions defined in the base class. The |
---|
| 70 | /// observer base can be attached to the notifier with the |
---|
| 71 | /// \e attach() member and can be detached with detach() function. The |
---|
| 72 | /// alteration handlers should not call any function which signals |
---|
| 73 | /// an other alteration in the same notifier and should not |
---|
| 74 | /// detach any observer from the notifier. |
---|
[1999] | 75 | /// |
---|
[2188] | 76 | /// Alteration observers try to be exception safe. If an \e add() or |
---|
| 77 | /// a \e clear() function throws an exception then the remaining |
---|
| 78 | /// observeres will not be notified and the fulfilled additions will |
---|
| 79 | /// be rolled back by calling the \e erase() or \e clear() |
---|
| 80 | /// functions. Thence the \e erase() and \e clear() should not throw |
---|
| 81 | /// exception. Actullay, it can be throw only |
---|
| 82 | /// \ref AlterationObserver::ImmediateDetach ImmediateDetach |
---|
| 83 | /// exception which detach the observer from the notifier. |
---|
[1999] | 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. |
---|
[946] | 96 | /// |
---|
| 97 | /// \author Balazs Dezso |
---|
| 98 | |
---|
[1999] | 99 | template <typename _Container, typename _Item> |
---|
[1038] | 100 | class AlterationNotifier { |
---|
[946] | 101 | public: |
---|
[1989] | 102 | |
---|
| 103 | typedef True Notifier; |
---|
| 104 | |
---|
[1999] | 105 | typedef _Container Container; |
---|
[946] | 106 | typedef _Item Item; |
---|
| 107 | |
---|
[2188] | 108 | /// \brief Exception which can be called from \e clear() and |
---|
| 109 | /// \e erase(). |
---|
| 110 | /// |
---|
| 111 | /// From the \e clear() and \e erase() function only this |
---|
| 112 | /// exception is allowed to throw. The exception immediatly |
---|
| 113 | /// detaches the current observer from the notifier. Because the |
---|
| 114 | /// \e clear() and \e erase() should not throw other exceptions |
---|
| 115 | /// it can be used to invalidate the observer. |
---|
| 116 | struct ImmediateDetach {}; |
---|
| 117 | |
---|
[1999] | 118 | /// \brief ObserverBase is the base class for the observers. |
---|
| 119 | /// |
---|
[946] | 120 | /// ObserverBase is the abstract base class for the observers. |
---|
| 121 | /// It will be notified about an item was inserted into or |
---|
| 122 | /// erased from the graph. |
---|
| 123 | /// |
---|
| 124 | /// The observer interface contains some pure virtual functions |
---|
| 125 | /// to override. The add() and erase() functions are |
---|
| 126 | /// to notify the oberver when one item is added or |
---|
| 127 | /// erased. |
---|
| 128 | /// |
---|
| 129 | /// The build() and clear() members are to notify the observer |
---|
[1204] | 130 | /// about the container is built from an empty container or |
---|
[946] | 131 | /// is cleared to an empty container. |
---|
| 132 | /// |
---|
| 133 | /// \author Balazs Dezso |
---|
| 134 | |
---|
| 135 | class ObserverBase { |
---|
| 136 | protected: |
---|
[1999] | 137 | typedef AlterationNotifier Notifier; |
---|
[946] | 138 | |
---|
[1038] | 139 | friend class AlterationNotifier; |
---|
[946] | 140 | |
---|
[1414] | 141 | /// \brief Default constructor. |
---|
| 142 | /// |
---|
[946] | 143 | /// Default constructor for ObserverBase. |
---|
| 144 | /// |
---|
[1999] | 145 | ObserverBase() : notifier(0) {} |
---|
[946] | 146 | |
---|
[1999] | 147 | /// \brief Constructor which attach the observer into notifier. |
---|
| 148 | /// |
---|
| 149 | /// Constructor which attach the observer into notifier. |
---|
| 150 | ObserverBase(AlterationNotifier& _notifier) { |
---|
| 151 | attach(_notifier); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /// \brief Constructor which attach the obserever to the same notifier. |
---|
| 155 | /// |
---|
| 156 | /// Constructor which attach the obserever to the same notifier as |
---|
| 157 | /// the other observer is attached to. |
---|
[1685] | 158 | ObserverBase(const ObserverBase& copy) { |
---|
| 159 | if (copy.attached()) { |
---|
[1999] | 160 | attach(*copy.getNotifier()); |
---|
[1685] | 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
[1999] | 164 | /// \brief Destructor |
---|
| 165 | virtual ~ObserverBase() { |
---|
| 166 | if (attached()) { |
---|
| 167 | detach(); |
---|
| 168 | } |
---|
| 169 | } |
---|
[946] | 170 | |
---|
[1414] | 171 | /// \brief Attaches the observer into an AlterationNotifier. |
---|
| 172 | /// |
---|
[1038] | 173 | /// This member attaches the observer into an AlterationNotifier. |
---|
[946] | 174 | /// |
---|
[1999] | 175 | void attach(AlterationNotifier& _notifier) { |
---|
| 176 | notifier = &_notifier; |
---|
| 177 | notifier->attach(*this); |
---|
[946] | 178 | } |
---|
[2188] | 179 | |
---|
[1414] | 180 | /// \brief Detaches the observer into an AlterationNotifier. |
---|
| 181 | /// |
---|
[1038] | 182 | /// This member detaches the observer from an AlterationNotifier. |
---|
[946] | 183 | /// |
---|
| 184 | void detach() { |
---|
[1999] | 185 | notifier->detach(*this); |
---|
[946] | 186 | } |
---|
[2188] | 187 | |
---|
[1999] | 188 | /// \brief Gives back a pointer to the notifier which the map |
---|
[946] | 189 | /// attached into. |
---|
| 190 | /// |
---|
[1999] | 191 | /// This function gives back a pointer to the notifier which the map |
---|
| 192 | /// attached into. |
---|
| 193 | /// |
---|
| 194 | Notifier* getNotifier() const { return const_cast<Notifier*>(notifier); } |
---|
[946] | 195 | |
---|
[1999] | 196 | /// Gives back true when the observer is attached into a notifier. |
---|
| 197 | bool attached() const { return notifier != 0; } |
---|
[1685] | 198 | |
---|
[946] | 199 | private: |
---|
| 200 | |
---|
| 201 | ObserverBase& operator=(const ObserverBase& copy); |
---|
| 202 | |
---|
| 203 | protected: |
---|
| 204 | |
---|
[1999] | 205 | Notifier* notifier; |
---|
| 206 | int notifier_index; |
---|
[946] | 207 | |
---|
| 208 | /// \brief The member function to notificate the observer about an |
---|
| 209 | /// item is added to the container. |
---|
| 210 | /// |
---|
| 211 | /// The add() member function notificates the observer about an item |
---|
| 212 | /// is added to the container. It have to be overrided in the |
---|
| 213 | /// subclasses. |
---|
| 214 | |
---|
[1414] | 215 | virtual void add(const Item&) = 0; |
---|
[946] | 216 | |
---|
[1414] | 217 | /// \brief The member function to notificate the observer about |
---|
[1718] | 218 | /// more item is added to the container. |
---|
[1414] | 219 | /// |
---|
[1718] | 220 | /// The add() member function notificates the observer about more item |
---|
[1414] | 221 | /// is added to the container. It have to be overrided in the |
---|
| 222 | /// subclasses. |
---|
| 223 | |
---|
| 224 | virtual void add(const std::vector<Item>& items) { |
---|
[1999] | 225 | int i; |
---|
| 226 | try { |
---|
| 227 | for (i = 0; i < (int)items.size(); ++i) { |
---|
| 228 | add(items[i]); |
---|
| 229 | } |
---|
| 230 | } catch (...) { |
---|
| 231 | for (int j = 0; j < i; ++j) { |
---|
| 232 | add(items[j]); |
---|
| 233 | } |
---|
| 234 | throw; |
---|
| 235 | } |
---|
[1414] | 236 | } |
---|
[946] | 237 | |
---|
| 238 | /// \brief The member function to notificate the observer about an |
---|
| 239 | /// item is erased from the container. |
---|
| 240 | /// |
---|
| 241 | /// The erase() member function notificates the observer about an |
---|
| 242 | /// item is erased from the container. It have to be overrided in |
---|
| 243 | /// the subclasses. |
---|
| 244 | |
---|
| 245 | virtual void erase(const Item&) = 0; |
---|
| 246 | |
---|
[1718] | 247 | /// \brief The member function to notificate the observer about |
---|
| 248 | /// more item is erased from the container. |
---|
| 249 | /// |
---|
| 250 | /// The erase() member function notificates the observer about more item |
---|
| 251 | /// is erased from the container. It have to be overrided in the |
---|
| 252 | /// subclasses. |
---|
[1414] | 253 | virtual void erase(const std::vector<Item>& items) { |
---|
[1999] | 254 | for (int i = 0; i < (int)items.size(); ++i) { |
---|
| 255 | erase(items[i]); |
---|
| 256 | } |
---|
[1414] | 257 | } |
---|
| 258 | |
---|
[946] | 259 | /// \brief The member function to notificate the observer about the |
---|
[1204] | 260 | /// container is built. |
---|
[946] | 261 | /// |
---|
| 262 | /// The build() member function notificates the observer about the |
---|
[1204] | 263 | /// container is built from an empty container. It have to be |
---|
[946] | 264 | /// overrided in the subclasses. |
---|
| 265 | |
---|
[1999] | 266 | virtual void build() { |
---|
| 267 | Item it; |
---|
| 268 | try { |
---|
| 269 | for (notifier->first(it); it != INVALID; notifier->next(it)) { |
---|
| 270 | add(it); |
---|
| 271 | } |
---|
| 272 | } catch (...) { |
---|
| 273 | Item jt; |
---|
| 274 | for (notifier->first(jt); jt != it; notifier->next(jt)) { |
---|
| 275 | erase(jt); |
---|
| 276 | } |
---|
| 277 | throw; |
---|
| 278 | } |
---|
| 279 | } |
---|
[946] | 280 | |
---|
| 281 | /// \brief The member function to notificate the observer about all |
---|
| 282 | /// items are erased from the container. |
---|
| 283 | /// |
---|
| 284 | /// The clear() member function notificates the observer about all |
---|
| 285 | /// items are erased from the container. It have to be overrided in |
---|
[1999] | 286 | /// the subclasses. |
---|
| 287 | virtual void clear() { |
---|
| 288 | Item it; |
---|
| 289 | for (notifier->first(it); it != INVALID; notifier->next(it)) { |
---|
| 290 | erase(it); |
---|
| 291 | } |
---|
| 292 | } |
---|
[946] | 293 | |
---|
| 294 | }; |
---|
| 295 | |
---|
| 296 | protected: |
---|
| 297 | |
---|
[1999] | 298 | const Container* container; |
---|
[946] | 299 | |
---|
[1999] | 300 | typedef std::vector<ObserverBase*> Observers; |
---|
| 301 | Observers observers; |
---|
[946] | 302 | |
---|
| 303 | |
---|
| 304 | public: |
---|
| 305 | |
---|
[1999] | 306 | /// \brief Default constructor. |
---|
[946] | 307 | /// |
---|
[1038] | 308 | /// The default constructor of the AlterationNotifier. |
---|
[1999] | 309 | /// It creates an empty notifier. |
---|
| 310 | AlterationNotifier() |
---|
| 311 | : container(0) {} |
---|
[946] | 312 | |
---|
[1999] | 313 | /// \brief Constructor. |
---|
| 314 | /// |
---|
| 315 | /// Constructor with the observed container parameter. |
---|
| 316 | AlterationNotifier(const Container& _container) |
---|
| 317 | : container(&_container) {} |
---|
| 318 | |
---|
| 319 | /// \brief Copy Constructor of the AlterationNotifier. |
---|
| 320 | /// |
---|
[1038] | 321 | /// Copy constructor of the AlterationNotifier. |
---|
[1999] | 322 | /// It creates only an empty notifier because the copiable |
---|
| 323 | /// notifier's observers have to be registered still into that notifier. |
---|
| 324 | AlterationNotifier(const AlterationNotifier& _notifier) |
---|
| 325 | : container(_notifier.container) {} |
---|
[946] | 326 | |
---|
[1999] | 327 | /// \brief Destructor. |
---|
| 328 | /// |
---|
| 329 | /// Destructor of the AlterationNotifier. |
---|
| 330 | /// |
---|
| 331 | ~AlterationNotifier() { |
---|
| 332 | typename Observers::iterator it; |
---|
| 333 | for (it = observers.begin(); it != observers.end(); ++it) { |
---|
| 334 | (*it)->notifier = 0; |
---|
[946] | 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
[1999] | 338 | /// \brief Sets the container. |
---|
[946] | 339 | /// |
---|
[1999] | 340 | /// Sets the container. |
---|
| 341 | void setContainer(const Container& _container) { |
---|
| 342 | container = &_container; |
---|
[946] | 343 | } |
---|
[1999] | 344 | |
---|
| 345 | protected: |
---|
| 346 | |
---|
| 347 | AlterationNotifier& operator=(const AlterationNotifier&); |
---|
| 348 | |
---|
| 349 | public: |
---|
| 350 | |
---|
| 351 | |
---|
| 352 | |
---|
| 353 | /// \brief First item in the container. |
---|
| 354 | /// |
---|
| 355 | /// Returns the first item in the container. It is |
---|
| 356 | /// for start the iteration on the container. |
---|
| 357 | void first(Item& item) const { |
---|
| 358 | container->first(item); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | /// \brief Next item in the container. |
---|
| 362 | /// |
---|
| 363 | /// Returns the next item in the container. It is |
---|
| 364 | /// for iterate on the container. |
---|
| 365 | void next(Item& item) const { |
---|
| 366 | container->next(item); |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | /// \brief Returns the id of the item. |
---|
| 370 | /// |
---|
| 371 | /// Returns the id of the item provided by the container. |
---|
| 372 | int id(const Item& item) const { |
---|
| 373 | return container->id(item); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | /// \brief Returns the maximum id of the container. |
---|
| 377 | /// |
---|
| 378 | /// Returns the maximum id of the container. |
---|
| 379 | int maxId() const { |
---|
| 380 | return container->maxId(Item()); |
---|
| 381 | } |
---|
| 382 | |
---|
[946] | 383 | protected: |
---|
| 384 | |
---|
| 385 | void attach(ObserverBase& observer) { |
---|
[1999] | 386 | observers.push_back(&observer); |
---|
| 387 | observer.notifier = this; |
---|
| 388 | observer.notifier_index = observers.size() - 1; |
---|
[946] | 389 | } |
---|
| 390 | |
---|
[1999] | 391 | void detach(ObserverBase& observer) { |
---|
| 392 | observers.back()->notifier_index = observer.notifier_index; |
---|
| 393 | observers[observer.notifier_index] = observers.back(); |
---|
| 394 | observers.pop_back(); |
---|
| 395 | observer.notifier = 0; |
---|
[946] | 396 | } |
---|
| 397 | |
---|
| 398 | public: |
---|
| 399 | |
---|
[1999] | 400 | /// \brief Notifies all the registed observers about an item added to |
---|
[1414] | 401 | /// the container. |
---|
| 402 | /// |
---|
[1999] | 403 | /// It notifies all the registed observers about an item added to |
---|
[1414] | 404 | /// the container. |
---|
[946] | 405 | /// |
---|
[1414] | 406 | void add(const Item& item) { |
---|
[1999] | 407 | typename Observers::iterator it; |
---|
[1979] | 408 | try { |
---|
[1999] | 409 | for (it = observers.begin(); it != observers.end(); ++it) { |
---|
[1979] | 410 | (*it)->add(item); |
---|
| 411 | } |
---|
| 412 | } catch (...) { |
---|
[1999] | 413 | typename Observers::iterator jt; |
---|
| 414 | for (jt = observers.begin(); jt != it; ++jt) { |
---|
[1979] | 415 | (*it)->erase(item); |
---|
| 416 | } |
---|
| 417 | throw; |
---|
[946] | 418 | } |
---|
| 419 | } |
---|
| 420 | |
---|
[1999] | 421 | /// \brief Notifies all the registed observers about more item added to |
---|
[1414] | 422 | /// the container. |
---|
| 423 | /// |
---|
[1999] | 424 | /// It notifies all the registed observers about more item added to |
---|
[1414] | 425 | /// the container. |
---|
| 426 | /// |
---|
| 427 | void add(const std::vector<Item>& items) { |
---|
[1999] | 428 | typename Observers::iterator it; |
---|
[1979] | 429 | try { |
---|
[1999] | 430 | for (it = observers.begin(); it != observers.end(); ++it) { |
---|
[1979] | 431 | (*it)->add(items); |
---|
| 432 | } |
---|
| 433 | } catch (...) { |
---|
[1999] | 434 | typename Observers::iterator jt; |
---|
| 435 | for (jt = observers.begin(); jt != it; ++jt) { |
---|
[1979] | 436 | (*it)->erase(items); |
---|
| 437 | } |
---|
| 438 | throw; |
---|
[1414] | 439 | } |
---|
| 440 | } |
---|
| 441 | |
---|
[1999] | 442 | /// \brief Notifies all the registed observers about an item erased from |
---|
[1414] | 443 | /// the container. |
---|
| 444 | /// |
---|
[1999] | 445 | /// It notifies all the registed observers about an item erased from |
---|
[1414] | 446 | /// the container. |
---|
[946] | 447 | /// |
---|
[2188] | 448 | void erase(const Item& key) throw() { |
---|
| 449 | int i = 0; |
---|
| 450 | while (i != (int)observers.size()) { |
---|
| 451 | try { |
---|
| 452 | observers[i]->erase(key); |
---|
| 453 | ++i; |
---|
| 454 | } catch (const ImmediateDetach&) { |
---|
| 455 | observers[i]->detach(); |
---|
| 456 | } |
---|
[946] | 457 | } |
---|
| 458 | } |
---|
[1414] | 459 | |
---|
[1999] | 460 | /// \brief Notifies all the registed observers about more item erased |
---|
[1414] | 461 | /// from the container. |
---|
| 462 | /// |
---|
[1999] | 463 | /// It notifies all the registed observers about more item erased from |
---|
[1414] | 464 | /// the container. |
---|
| 465 | /// |
---|
| 466 | void erase(const std::vector<Item>& items) { |
---|
[2188] | 467 | int i = 0; |
---|
| 468 | while (i != (int)observers.size()) { |
---|
| 469 | try { |
---|
| 470 | observers[i]->erase(items); |
---|
| 471 | ++i; |
---|
| 472 | } catch (const ImmediateDetach&) { |
---|
| 473 | observers[i]->detach(); |
---|
| 474 | } |
---|
[1414] | 475 | } |
---|
| 476 | } |
---|
[946] | 477 | |
---|
[1999] | 478 | /// \brief Notifies all the registed observers about the container is |
---|
[1414] | 479 | /// built. |
---|
| 480 | /// |
---|
[1999] | 481 | /// Notifies all the registed observers about the container is built |
---|
[946] | 482 | /// from an empty container. |
---|
| 483 | void build() { |
---|
[1999] | 484 | typename Observers::iterator it; |
---|
[1979] | 485 | try { |
---|
[1999] | 486 | for (it = observers.begin(); it != observers.end(); ++it) { |
---|
[1979] | 487 | (*it)->build(); |
---|
| 488 | } |
---|
| 489 | } catch (...) { |
---|
[1999] | 490 | typename Observers::iterator jt; |
---|
| 491 | for (jt = observers.begin(); jt != it; ++jt) { |
---|
[1979] | 492 | (*it)->clear(); |
---|
| 493 | } |
---|
| 494 | throw; |
---|
[946] | 495 | } |
---|
| 496 | } |
---|
| 497 | |
---|
[1999] | 498 | /// \brief Notifies all the registed observers about all items are |
---|
[1414] | 499 | /// erased. |
---|
| 500 | /// |
---|
[1999] | 501 | /// Notifies all the registed observers about all items are erased |
---|
[946] | 502 | /// from the container. |
---|
| 503 | void clear() { |
---|
[2188] | 504 | int i = 0; |
---|
| 505 | while (i != (int)observers.size()) { |
---|
| 506 | try { |
---|
| 507 | observers[i]->clear(); |
---|
| 508 | ++i; |
---|
| 509 | } catch (const ImmediateDetach&) { |
---|
| 510 | observers[i]->detach(); |
---|
| 511 | } |
---|
[946] | 512 | } |
---|
| 513 | } |
---|
| 514 | }; |
---|
| 515 | |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | #endif |
---|