lemon/bits/alteration_notifier.h
changeset 209 765619b7cbb2
parent 157 2ccc1afc2c52
child 220 a5d8c039f218
     1.1 --- a/lemon/bits/alteration_notifier.h	Sun Jul 13 16:46:56 2008 +0100
     1.2 +++ b/lemon/bits/alteration_notifier.h	Sun Jul 13 19:51:02 2008 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4 -/* -*- C++ -*-
     1.5 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     1.6   *
     1.7 - * This file is a part of LEMON, a generic C++ optimization library
     1.8 + * This file is a part of LEMON, a generic C++ optimization library.
     1.9   *
    1.10   * Copyright (C) 2003-2008
    1.11   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.12 @@ -32,7 +32,7 @@
    1.13  
    1.14    /// \ingroup graphbits
    1.15    ///
    1.16 -  /// \brief Notifier class to notify observes about alterations in 
    1.17 +  /// \brief Notifier class to notify observes about alterations in
    1.18    /// a container.
    1.19    ///
    1.20    /// The simple graph's can be refered as two containers, one node container
    1.21 @@ -49,7 +49,7 @@
    1.22    /// an alteration in the graph, which cause only drawback on the
    1.23    /// alteration of the graph.
    1.24    ///
    1.25 -  /// This class provides an interface to the container. The \e first() and \e 
    1.26 +  /// This class provides an interface to the container. The \e first() and \e
    1.27    /// next() member functions make possible to iterate on the keys of the
    1.28    /// container. The \e id() function returns an integer id for each key.
    1.29    /// The \e maxId() function gives back an upper bound of the ids.
    1.30 @@ -60,7 +60,7 @@
    1.31    /// \e erase() signals that only one or few items added or erased to or
    1.32    /// from the graph. If all items are erased from the graph or from an empty
    1.33    /// graph a new graph is builded then it can be signaled with the
    1.34 -  /// clear() and build() members. Important rule that if we erase items 
    1.35 +  /// clear() and build() members. Important rule that if we erase items
    1.36    /// from graph we should first signal the alteration and after that erase
    1.37    /// them from the container, on the other way on item addition we should
    1.38    /// first extend the container and just after that signal the alteration.
    1.39 @@ -68,7 +68,7 @@
    1.40    /// The alteration can be observed with a class inherited from the
    1.41    /// \e ObserverBase nested class. The signals can be handled with
    1.42    /// overriding the virtual functions defined in the base class.  The
    1.43 -  /// observer base can be attached to the notifier with the 
    1.44 +  /// observer base can be attached to the notifier with the
    1.45    /// \e attach() member and can be detached with detach() function. The
    1.46    /// alteration handlers should not call any function which signals
    1.47    /// an other alteration in the same notifier and should not
    1.48 @@ -79,13 +79,13 @@
    1.49    /// observeres will not be notified and the fulfilled additions will
    1.50    /// be rolled back by calling the \e erase() or \e clear()
    1.51    /// functions. Thence the \e erase() and \e clear() should not throw
    1.52 -  /// exception. Actullay, it can be throw only 
    1.53 +  /// exception. Actullay, it can be throw only
    1.54    /// \ref AlterationObserver::ImmediateDetach ImmediateDetach
    1.55    /// exception which detach the observer from the notifier.
    1.56    ///
    1.57    /// There are some place when the alteration observing is not completly
    1.58    /// reliable. If we want to carry out the node degree in the graph
    1.59 -  /// as in the \ref InDegMap and we use the reverseEdge that cause 
    1.60 +  /// as in the \ref InDegMap and we use the reverseEdge that cause
    1.61    /// unreliable functionality. Because the alteration observing signals
    1.62    /// only erasing and adding but not the reversing it will stores bad
    1.63    /// degrees. The sub graph adaptors cannot signal the alterations because
    1.64 @@ -104,7 +104,7 @@
    1.65      typedef _Container Container;
    1.66      typedef _Item Item;
    1.67  
    1.68 -    /// \brief Exception which can be called from \e clear() and 
    1.69 +    /// \brief Exception which can be called from \e clear() and
    1.70      /// \e erase().
    1.71      ///
    1.72      /// From the \e clear() and \e erase() function only this
    1.73 @@ -127,7 +127,7 @@
    1.74      ///
    1.75      /// The build() and clear() members are to notify the observer
    1.76      /// about the container is built from an empty container or
    1.77 -    /// is cleared to an empty container. 
    1.78 +    /// is cleared to an empty container.
    1.79  
    1.80      class ObserverBase {
    1.81      protected:
    1.82 @@ -138,7 +138,7 @@
    1.83        /// \brief Default constructor.
    1.84        ///
    1.85        /// Default constructor for ObserverBase.
    1.86 -      /// 
    1.87 +      ///
    1.88        ObserverBase() : _notifier(0) {}
    1.89  
    1.90        /// \brief Constructor which attach the observer into notifier.
    1.91 @@ -151,13 +151,13 @@
    1.92        /// \brief Constructor which attach the obserever to the same notifier.
    1.93        ///
    1.94        /// Constructor which attach the obserever to the same notifier as
    1.95 -      /// the other observer is attached to. 
    1.96 +      /// the other observer is attached to.
    1.97        ObserverBase(const ObserverBase& copy) {
    1.98 -	if (copy.attached()) {
    1.99 +        if (copy.attached()) {
   1.100            attach(*copy.notifier());
   1.101 -	}
   1.102 +        }
   1.103        }
   1.104 -	
   1.105 +
   1.106        /// \brief Destructor
   1.107        virtual ~ObserverBase() {
   1.108          if (attached()) {
   1.109 @@ -170,9 +170,9 @@
   1.110        /// This member attaches the observer into an AlterationNotifier.
   1.111        ///
   1.112        void attach(AlterationNotifier& nf) {
   1.113 -	nf.attach(*this);
   1.114 +        nf.attach(*this);
   1.115        }
   1.116 -      
   1.117 +
   1.118        /// \brief Detaches the observer into an AlterationNotifier.
   1.119        ///
   1.120        /// This member detaches the observer from an AlterationNotifier.
   1.121 @@ -180,15 +180,15 @@
   1.122        void detach() {
   1.123          _notifier->detach(*this);
   1.124        }
   1.125 -      
   1.126 -      /// \brief Gives back a pointer to the notifier which the map 
   1.127 +
   1.128 +      /// \brief Gives back a pointer to the notifier which the map
   1.129        /// attached into.
   1.130        ///
   1.131        /// This function gives back a pointer to the notifier which the map
   1.132        /// attached into.
   1.133        ///
   1.134        Notifier* notifier() const { return const_cast<Notifier*>(_notifier); }
   1.135 -      
   1.136 +
   1.137        /// Gives back true when the observer is attached into a notifier.
   1.138        bool attached() const { return _notifier != 0; }
   1.139  
   1.140 @@ -197,7 +197,7 @@
   1.141        ObserverBase& operator=(const ObserverBase& copy);
   1.142  
   1.143      protected:
   1.144 -      
   1.145 +
   1.146        Notifier* _notifier;
   1.147        typename std::list<ObserverBase*>::iterator _index;
   1.148  
   1.149 @@ -209,7 +209,7 @@
   1.150        /// subclasses.
   1.151        virtual void add(const Item&) = 0;
   1.152  
   1.153 -      /// \brief The member function to notificate the observer about 
   1.154 +      /// \brief The member function to notificate the observer about
   1.155        /// more item is added to the container.
   1.156        ///
   1.157        /// The add() member function notificates the observer about more item
   1.158 @@ -222,10 +222,10 @@
   1.159        ///
   1.160        /// The erase() member function notificates the observer about an
   1.161        /// item is erased from the container. It have to be overrided in
   1.162 -      /// the subclasses.	
   1.163 +      /// the subclasses.
   1.164        virtual void erase(const Item&) = 0;
   1.165  
   1.166 -      /// \brief The member function to notificate the observer about 
   1.167 +      /// \brief The member function to notificate the observer about
   1.168        /// more item is erased from the container.
   1.169        ///
   1.170        /// The erase() member function notificates the observer about more item
   1.171 @@ -247,50 +247,50 @@
   1.172        ///
   1.173        /// The clear() member function notificates the observer about all
   1.174        /// items are erased from the container. It have to be overrided in
   1.175 -      /// the subclasses.      
   1.176 +      /// the subclasses.
   1.177        virtual void clear() = 0;
   1.178  
   1.179      };
   1.180 -	
   1.181 +
   1.182    protected:
   1.183  
   1.184      const Container* container;
   1.185  
   1.186 -    typedef std::list<ObserverBase*> Observers; 
   1.187 +    typedef std::list<ObserverBase*> Observers;
   1.188      Observers _observers;
   1.189  
   1.190 -		
   1.191 +
   1.192    public:
   1.193  
   1.194      /// \brief Default constructor.
   1.195      ///
   1.196 -    /// The default constructor of the AlterationNotifier. 
   1.197 +    /// The default constructor of the AlterationNotifier.
   1.198      /// It creates an empty notifier.
   1.199 -    AlterationNotifier() 
   1.200 +    AlterationNotifier()
   1.201        : container(0) {}
   1.202  
   1.203      /// \brief Constructor.
   1.204      ///
   1.205      /// Constructor with the observed container parameter.
   1.206 -    AlterationNotifier(const Container& _container) 
   1.207 +    AlterationNotifier(const Container& _container)
   1.208        : container(&_container) {}
   1.209  
   1.210 -    /// \brief Copy Constructor of the AlterationNotifier. 
   1.211 +    /// \brief Copy Constructor of the AlterationNotifier.
   1.212      ///
   1.213 -    /// Copy constructor of the AlterationNotifier. 
   1.214 +    /// Copy constructor of the AlterationNotifier.
   1.215      /// It creates only an empty notifier because the copiable
   1.216      /// notifier's observers have to be registered still into that notifier.
   1.217 -    AlterationNotifier(const AlterationNotifier& _notifier) 
   1.218 +    AlterationNotifier(const AlterationNotifier& _notifier)
   1.219        : container(_notifier.container) {}
   1.220  
   1.221      /// \brief Destructor.
   1.222 -    ///		
   1.223 +    ///
   1.224      /// Destructor of the AlterationNotifier.
   1.225      ///
   1.226      ~AlterationNotifier() {
   1.227        typename Observers::iterator it;
   1.228        for (it = _observers.begin(); it != _observers.end(); ++it) {
   1.229 -	(*it)->_notifier = 0;
   1.230 +        (*it)->_notifier = 0;
   1.231        }
   1.232      }
   1.233  
   1.234 @@ -338,13 +338,13 @@
   1.235      int maxId() const {
   1.236        return container->maxId(Item());
   1.237      }
   1.238 -		
   1.239 +
   1.240    protected:
   1.241  
   1.242      void attach(ObserverBase& observer) {
   1.243        observer._index = _observers.insert(_observers.begin(), &observer);
   1.244        observer._notifier = this;
   1.245 -    } 
   1.246 +    }
   1.247  
   1.248      void detach(ObserverBase& observer) {
   1.249        _observers.erase(observer._index);
   1.250 @@ -353,13 +353,13 @@
   1.251      }
   1.252  
   1.253    public:
   1.254 -	
   1.255 -    /// \brief Notifies all the registed observers about an item added to 
   1.256 +
   1.257 +    /// \brief Notifies all the registed observers about an item added to
   1.258      /// the container.
   1.259      ///
   1.260 -    /// It notifies all the registed observers about an item added to 
   1.261 +    /// It notifies all the registed observers about an item added to
   1.262      /// the container.
   1.263 -    /// 
   1.264 +    ///
   1.265      void add(const Item& item) {
   1.266        typename Observers::reverse_iterator it;
   1.267        try {
   1.268 @@ -373,14 +373,14 @@
   1.269          }
   1.270          throw;
   1.271        }
   1.272 -    }	
   1.273 +    }
   1.274  
   1.275 -    /// \brief Notifies all the registed observers about more item added to 
   1.276 +    /// \brief Notifies all the registed observers about more item added to
   1.277      /// the container.
   1.278      ///
   1.279 -    /// It notifies all the registed observers about more item added to 
   1.280 +    /// It notifies all the registed observers about more item added to
   1.281      /// the container.
   1.282 -    /// 
   1.283 +    ///
   1.284      void add(const std::vector<Item>& items) {
   1.285        typename Observers::reverse_iterator it;
   1.286        try {
   1.287 @@ -394,14 +394,14 @@
   1.288          }
   1.289          throw;
   1.290        }
   1.291 -    }	
   1.292 +    }
   1.293  
   1.294 -    /// \brief Notifies all the registed observers about an item erased from 
   1.295 +    /// \brief Notifies all the registed observers about an item erased from
   1.296      /// the container.
   1.297 -    ///	
   1.298 -    /// It notifies all the registed observers about an item erased from 
   1.299 +    ///
   1.300 +    /// It notifies all the registed observers about an item erased from
   1.301      /// the container.
   1.302 -    /// 
   1.303 +    ///
   1.304      void erase(const Item& item) throw() {
   1.305        typename Observers::iterator it = _observers.begin();
   1.306        while (it != _observers.end()) {
   1.307 @@ -416,12 +416,12 @@
   1.308        }
   1.309      }
   1.310  
   1.311 -    /// \brief Notifies all the registed observers about more item erased  
   1.312 +    /// \brief Notifies all the registed observers about more item erased
   1.313      /// from the container.
   1.314 -    ///	
   1.315 -    /// It notifies all the registed observers about more item erased from 
   1.316 +    ///
   1.317 +    /// It notifies all the registed observers about more item erased from
   1.318      /// the container.
   1.319 -    /// 
   1.320 +    ///
   1.321      void erase(const std::vector<Item>& items) {
   1.322        typename Observers::iterator it = _observers.begin();
   1.323        while (it != _observers.end()) {
   1.324 @@ -436,9 +436,9 @@
   1.325        }
   1.326      }
   1.327  
   1.328 -    /// \brief Notifies all the registed observers about the container is 
   1.329 +    /// \brief Notifies all the registed observers about the container is
   1.330      /// built.
   1.331 -    ///		
   1.332 +    ///
   1.333      /// Notifies all the registed observers about the container is built
   1.334      /// from an empty container.
   1.335      void build() {
   1.336 @@ -456,7 +456,7 @@
   1.337        }
   1.338      }
   1.339  
   1.340 -    /// \brief Notifies all the registed observers about all items are 
   1.341 +    /// \brief Notifies all the registed observers about all items are
   1.342      /// erased.
   1.343      ///
   1.344      /// Notifies all the registed observers about all items are erased