COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
07/13/08 20:51:02 (16 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Apply unify-sources.sh to the source tree

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/alteration_notifier.h

    r157 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    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.
    44 *
    55 * Copyright (C) 2003-2008
     
    3333  /// \ingroup graphbits
    3434  ///
    35   /// \brief Notifier class to notify observes about alterations in 
     35  /// \brief Notifier class to notify observes about alterations in
    3636  /// a container.
    3737  ///
     
    5050  /// alteration of the graph.
    5151  ///
    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
    5353  /// next() member functions make possible to iterate on the keys of the
    5454  /// container. The \e id() function returns an integer id for each key.
     
    6161  /// from the graph. If all items are erased from the graph or from an empty
    6262  /// 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
    6464  /// from graph we should first signal the alteration and after that erase
    6565  /// them from the container, on the other way on item addition we should
     
    6969  /// \e ObserverBase nested class. The signals can be handled with
    7070  /// 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
    7272  /// \e attach() member and can be detached with detach() function. The
    7373  /// alteration handlers should not call any function which signals
     
    8080  /// be rolled back by calling the \e erase() or \e clear()
    8181  /// 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
    8383  /// \ref AlterationObserver::ImmediateDetach ImmediateDetach
    8484  /// exception which detach the observer from the notifier.
     
    8686  /// There are some place when the alteration observing is not completly
    8787  /// 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
    8989  /// unreliable functionality. Because the alteration observing signals
    9090  /// only erasing and adding but not the reversing it will stores bad
     
    105105    typedef _Item Item;
    106106
    107     /// \brief Exception which can be called from \e clear() and 
     107    /// \brief Exception which can be called from \e clear() and
    108108    /// \e erase().
    109109    ///
     
    128128    /// The build() and clear() members are to notify the observer
    129129    /// about the container is built from an empty container or
    130     /// is cleared to an empty container. 
     130    /// is cleared to an empty container.
    131131
    132132    class ObserverBase {
     
    139139      ///
    140140      /// Default constructor for ObserverBase.
    141       /// 
     141      ///
    142142      ObserverBase() : _notifier(0) {}
    143143
     
    152152      ///
    153153      /// Constructor which attach the obserever to the same notifier as
    154       /// the other observer is attached to. 
     154      /// the other observer is attached to.
    155155      ObserverBase(const ObserverBase& copy) {
    156         if (copy.attached()) {
     156        if (copy.attached()) {
    157157          attach(*copy.notifier());
    158         }
    159       }
    160        
     158        }
     159      }
     160
    161161      /// \brief Destructor
    162162      virtual ~ObserverBase() {
     
    171171      ///
    172172      void attach(AlterationNotifier& nf) {
    173         nf.attach(*this);
    174       }
    175      
     173        nf.attach(*this);
     174      }
     175
    176176      /// \brief Detaches the observer into an AlterationNotifier.
    177177      ///
     
    181181        _notifier->detach(*this);
    182182      }
    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
    185185      /// attached into.
    186186      ///
     
    189189      ///
    190190      Notifier* notifier() const { return const_cast<Notifier*>(_notifier); }
    191      
     191
    192192      /// Gives back true when the observer is attached into a notifier.
    193193      bool attached() const { return _notifier != 0; }
     
    198198
    199199    protected:
    200      
     200
    201201      Notifier* _notifier;
    202202      typename std::list<ObserverBase*>::iterator _index;
     
    210210      virtual void add(const Item&) = 0;
    211211
    212       /// \brief The member function to notificate the observer about 
     212      /// \brief The member function to notificate the observer about
    213213      /// more item is added to the container.
    214214      ///
     
    223223      /// The erase() member function notificates the observer about an
    224224      /// item is erased from the container. It have to be overrided in
    225       /// the subclasses.       
     225      /// the subclasses.
    226226      virtual void erase(const Item&) = 0;
    227227
    228       /// \brief The member function to notificate the observer about 
     228      /// \brief The member function to notificate the observer about
    229229      /// more item is erased from the container.
    230230      ///
     
    248248      /// The clear() member function notificates the observer about all
    249249      /// items are erased from the container. It have to be overrided in
    250       /// the subclasses.     
     250      /// the subclasses.
    251251      virtual void clear() = 0;
    252252
    253253    };
    254        
     254
    255255  protected:
    256256
    257257    const Container* container;
    258258
    259     typedef std::list<ObserverBase*> Observers; 
     259    typedef std::list<ObserverBase*> Observers;
    260260    Observers _observers;
    261261
    262                
     262
    263263  public:
    264264
    265265    /// \brief Default constructor.
    266266    ///
    267     /// The default constructor of the AlterationNotifier. 
     267    /// The default constructor of the AlterationNotifier.
    268268    /// It creates an empty notifier.
    269     AlterationNotifier() 
     269    AlterationNotifier()
    270270      : container(0) {}
    271271
     
    273273    ///
    274274    /// Constructor with the observed container parameter.
    275     AlterationNotifier(const Container& _container) 
     275    AlterationNotifier(const Container& _container)
    276276      : container(&_container) {}
    277277
    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.
    281281    /// It creates only an empty notifier because the copiable
    282282    /// notifier's observers have to be registered still into that notifier.
    283     AlterationNotifier(const AlterationNotifier& _notifier) 
     283    AlterationNotifier(const AlterationNotifier& _notifier)
    284284      : container(_notifier.container) {}
    285285
    286286    /// \brief Destructor.
    287     ///         
     287    ///
    288288    /// Destructor of the AlterationNotifier.
    289289    ///
     
    291291      typename Observers::iterator it;
    292292      for (it = _observers.begin(); it != _observers.end(); ++it) {
    293         (*it)->_notifier = 0;
     293        (*it)->_notifier = 0;
    294294      }
    295295    }
     
    339339      return container->maxId(Item());
    340340    }
    341                
     341
    342342  protected:
    343343
     
    345345      observer._index = _observers.insert(_observers.begin(), &observer);
    346346      observer._notifier = this;
    347     } 
     347    }
    348348
    349349    void detach(ObserverBase& observer) {
     
    354354
    355355  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    ///
    363363    void add(const Item& item) {
    364364      typename Observers::reverse_iterator it;
     
    374374        throw;
    375375      }
    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    ///
    384384    void add(const std::vector<Item>& items) {
    385385      typename Observers::reverse_iterator it;
     
    395395        throw;
    396396      }
    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    ///
    405405    void erase(const Item& item) throw() {
    406406      typename Observers::iterator it = _observers.begin();
     
    417417    }
    418418
    419     /// \brief Notifies all the registed observers about more item erased 
     419    /// \brief Notifies all the registed observers about more item erased
    420420    /// 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    ///
    425425    void erase(const std::vector<Item>& items) {
    426426      typename Observers::iterator it = _observers.begin();
     
    437437    }
    438438
    439     /// \brief Notifies all the registed observers about the container is 
     439    /// \brief Notifies all the registed observers about the container is
    440440    /// built.
    441     ///         
     441    ///
    442442    /// Notifies all the registed observers about the container is built
    443443    /// from an empty container.
     
    457457    }
    458458
    459     /// \brief Notifies all the registed observers about all items are 
     459    /// \brief Notifies all the registed observers about all items are
    460460    /// erased.
    461461    ///
Note: See TracChangeset for help on using the changeset viewer.