lemon/bits/alteration_notifier.h
changeset 1053 1c978b5bcc65
parent 440 88ed40ad0d4f
child 1092 dceba191c00d
equal deleted inserted replaced
10:6bedfe744680 11:5f44c2f736bf
    21 
    21 
    22 #include <vector>
    22 #include <vector>
    23 #include <list>
    23 #include <list>
    24 
    24 
    25 #include <lemon/core.h>
    25 #include <lemon/core.h>
       
    26 #include <lemon/bits/lock.h>
    26 
    27 
    27 //\ingroup graphbits
    28 //\ingroup graphbits
    28 //\file
    29 //\file
    29 //\brief Observer notifier for graph alteration observers.
    30 //\brief Observer notifier for graph alteration observers.
    30 
    31 
   249 
   250 
   250     const Container* container;
   251     const Container* container;
   251 
   252 
   252     typedef std::list<ObserverBase*> Observers;
   253     typedef std::list<ObserverBase*> Observers;
   253     Observers _observers;
   254     Observers _observers;
   254 
   255     lemon::bits::Lock _lock;
   255 
   256 
   256   public:
   257   public:
   257 
   258 
   258     // \brief Default constructor.
   259     // \brief Default constructor.
   259     //
   260     //
   330     }
   331     }
   331 
   332 
   332   protected:
   333   protected:
   333 
   334 
   334     void attach(ObserverBase& observer) {
   335     void attach(ObserverBase& observer) {
       
   336       _lock.lock();
   335       observer._index = _observers.insert(_observers.begin(), &observer);
   337       observer._index = _observers.insert(_observers.begin(), &observer);
   336       observer._notifier = this;
   338       observer._notifier = this;
       
   339       _lock.unlock();
   337     }
   340     }
   338 
   341 
   339     void detach(ObserverBase& observer) {
   342     void detach(ObserverBase& observer) {
       
   343       _lock.lock();
   340       _observers.erase(observer._index);
   344       _observers.erase(observer._index);
   341       observer._index = _observers.end();
   345       observer._index = _observers.end();
   342       observer._notifier = 0;
   346       observer._notifier = 0;
       
   347       _lock.unlock();
   343     }
   348     }
   344 
   349 
   345   public:
   350   public:
   346 
   351 
   347     // \brief Notifies all the registed observers about an item added to
   352     // \brief Notifies all the registed observers about an item added to