lemon/bits/alteration_notifier.h
changeset 1979 c2992fd74dad
parent 1956 a055123339d5
child 1989 d276e88aa48a
     1.1 --- a/lemon/bits/alteration_notifier.h	Wed Feb 22 12:45:59 2006 +0000
     1.2 +++ b/lemon/bits/alteration_notifier.h	Wed Feb 22 18:26:56 2006 +0000
     1.3 @@ -265,8 +265,16 @@
     1.4      /// 
     1.5      void add(const Item& item) {
     1.6        typename Container::iterator it;
     1.7 -      for (it = container.begin(); it != container.end(); ++it) {
     1.8 -	(*it)->add(item);
     1.9 +      try {
    1.10 +        for (it = container.begin(); it != container.end(); ++it) {
    1.11 +          (*it)->add(item);
    1.12 +        }
    1.13 +      } catch (...) {
    1.14 +        typename Container::iterator jt;
    1.15 +        for (jt = container.begin(); jt != it; ++it) {
    1.16 +          (*it)->erase(item);
    1.17 +        }
    1.18 +        throw;
    1.19        }
    1.20      }	
    1.21  
    1.22 @@ -278,8 +286,16 @@
    1.23      /// 
    1.24      void add(const std::vector<Item>& items) {
    1.25        typename Container::iterator it;
    1.26 -      for (it = container.begin(); it != container.end(); ++it) {
    1.27 -	(*it)->add(items);
    1.28 +      try {
    1.29 +        for (it = container.begin(); it != container.end(); ++it) {
    1.30 +          (*it)->add(items);
    1.31 +        }
    1.32 +      } catch (...) {
    1.33 +        typename Container::iterator jt;
    1.34 +        for (jt = container.begin(); jt != it; ++it) {
    1.35 +          (*it)->erase(items);
    1.36 +        }
    1.37 +        throw;
    1.38        }
    1.39      }	
    1.40  
    1.41 @@ -316,8 +332,16 @@
    1.42      /// from an empty container.
    1.43      void build() {
    1.44        typename Container::iterator it;
    1.45 -      for (it = container.begin(); it != container.end(); ++it) {
    1.46 -	(*it)->build();
    1.47 +      try {
    1.48 +        for (it = container.begin(); it != container.end(); ++it) {
    1.49 +          (*it)->build();
    1.50 +        }
    1.51 +      } catch (...) {
    1.52 +        typename Container::iterator jt;
    1.53 +        for (jt = container.begin(); jt != it; ++it) {
    1.54 +          (*it)->clear();
    1.55 +        }
    1.56 +        throw;
    1.57        }
    1.58      }
    1.59  
    1.60 @@ -335,232 +359,6 @@
    1.61      }
    1.62    };
    1.63  
    1.64 -
    1.65 -  /// \brief Class to extend a graph with the functionality of alteration
    1.66 -  /// observing.
    1.67 -  ///
    1.68 -  /// AlterableGraphExtender extends the _Base graphs functionality with
    1.69 -  /// the possibility of alteration observing. It defines two observer
    1.70 -  /// registrys for the nodes and mapes.
    1.71 -  /// 
    1.72 -  /// \todo Document what "alteration observing" is. And probably find a
    1.73 -  /// better (shorter) name.
    1.74 -  ///
    1.75 -  /// \param _Base is the base class to extend.
    1.76 -  ///
    1.77 -  /// \pre _Base is conform to the BaseGraphComponent concept.
    1.78 -  ///
    1.79 -  /// \post AlterableGraphExtender<_Base> is conform to the
    1.80 -  /// AlterableGraphComponent concept.
    1.81 -  ///
    1.82 -  /// \author Balazs Dezso
    1.83 -
    1.84 -  template <typename _Base> 
    1.85 -  class AlterableGraphExtender : public _Base {
    1.86 -  public:
    1.87 -
    1.88 -    typedef AlterableGraphExtender Graph;
    1.89 -    typedef _Base Parent;
    1.90 -
    1.91 -    typedef typename Parent::Node Node;
    1.92 -    typedef typename Parent::Edge Edge;
    1.93 -
    1.94 -    /// The edge observer registry.
    1.95 -    typedef AlterationNotifier<Edge> EdgeNotifier;
    1.96 -    /// The node observer registry.
    1.97 -    typedef AlterationNotifier<Node> NodeNotifier;
    1.98 -
    1.99 -
   1.100 -  protected:
   1.101 -
   1.102 -    mutable EdgeNotifier edge_notifier;
   1.103 -
   1.104 -    mutable NodeNotifier node_notifier;
   1.105 -
   1.106 -  public:
   1.107 -
   1.108 -    /// \brief Gives back the edge alteration notifier.
   1.109 -    ///
   1.110 -    /// Gives back the edge alteration notifier.
   1.111 -    EdgeNotifier& getNotifier(Edge) const {
   1.112 -      return edge_notifier;
   1.113 -    }
   1.114 -
   1.115 -    /// \brief Gives back the node alteration notifier.
   1.116 -    ///
   1.117 -    /// Gives back the node alteration notifier.
   1.118 -    NodeNotifier& getNotifier(Node) const {
   1.119 -      return node_notifier;
   1.120 -    }
   1.121 -
   1.122 -    ~AlterableGraphExtender() {
   1.123 -      node_notifier.clear();
   1.124 -      edge_notifier.clear();
   1.125 -    }
   1.126 -    
   1.127 -  };
   1.128 -
   1.129 -
   1.130 -  template <typename _Base> 
   1.131 -  class AlterableEdgeSetExtender : public _Base {
   1.132 -  public:
   1.133 -
   1.134 -    typedef AlterableEdgeSetExtender Graph;
   1.135 -    typedef _Base Parent;
   1.136 -
   1.137 -    typedef typename Parent::Edge Edge;
   1.138 -
   1.139 -    /// The edge observer registry.
   1.140 -    typedef AlterationNotifier<Edge> EdgeNotifier;
   1.141 -
   1.142 -  protected:
   1.143 -
   1.144 -    mutable EdgeNotifier edge_notifier;
   1.145 -
   1.146 -  public:
   1.147 -
   1.148 -    /// \brief Gives back the edge alteration notifier.
   1.149 -    ///
   1.150 -    /// Gives back the edge alteration notifier.
   1.151 -    EdgeNotifier& getNotifier(Edge) const {
   1.152 -      return edge_notifier;
   1.153 -    }
   1.154 -
   1.155 -    ~AlterableEdgeSetExtender() {
   1.156 -      edge_notifier.clear();
   1.157 -    }
   1.158 -    
   1.159 -  };
   1.160 -
   1.161 -  /// \brief Class to extend an undirected graph with the functionality of
   1.162 -  /// alteration observing.
   1.163 -  ///
   1.164 -  /// \todo Document.
   1.165 -  ///
   1.166 -  /// \sa AlterableGraphExtender
   1.167 -  ///
   1.168 -  /// \bug This should be done some other way. Possibilities: template
   1.169 -  /// specialization (not very easy, if at all possible); some kind of
   1.170 -  /// enable_if boost technique?
   1.171 -
   1.172 -  template <typename _Base> 
   1.173 -  class AlterableUGraphExtender
   1.174 -    : public AlterableGraphExtender<_Base> {
   1.175 -  public:
   1.176 -
   1.177 -    typedef AlterableUGraphExtender Graph;
   1.178 -    typedef AlterableGraphExtender<_Base> Parent;
   1.179 -
   1.180 -    typedef typename Parent::UEdge UEdge;
   1.181 -
   1.182 -    /// The edge observer registry.
   1.183 -    typedef AlterationNotifier<UEdge> UEdgeNotifier;
   1.184 -
   1.185 -  protected:
   1.186 -
   1.187 -    mutable UEdgeNotifier u_edge_notifier;
   1.188 -
   1.189 -  public:
   1.190 -
   1.191 -    using Parent::getNotifier;
   1.192 -    UEdgeNotifier& getNotifier(UEdge) const {
   1.193 -      return u_edge_notifier;
   1.194 -    }
   1.195 -
   1.196 -    ~AlterableUGraphExtender() {
   1.197 -      u_edge_notifier.clear();
   1.198 -    }
   1.199 -  };
   1.200 -
   1.201 -  template <typename _Base> 
   1.202 -  class AlterableUEdgeSetExtender
   1.203 -    : public AlterableEdgeSetExtender<_Base> {
   1.204 -  public:
   1.205 -
   1.206 -    typedef AlterableUEdgeSetExtender Graph;
   1.207 -    typedef AlterableEdgeSetExtender<_Base> Parent;
   1.208 -
   1.209 -    typedef typename Parent::UEdge UEdge;
   1.210 -
   1.211 -    typedef AlterationNotifier<UEdge> UEdgeNotifier;
   1.212 -
   1.213 -  protected:
   1.214 -
   1.215 -    mutable UEdgeNotifier u_edge_notifier;
   1.216 -
   1.217 -  public:
   1.218 -
   1.219 -    using Parent::getNotifier;
   1.220 -    UEdgeNotifier& getNotifier(UEdge) const {
   1.221 -      return u_edge_notifier;
   1.222 -    }
   1.223 -
   1.224 -    ~AlterableUEdgeSetExtender() {
   1.225 -      u_edge_notifier.clear();
   1.226 -    }
   1.227 -  };
   1.228 -
   1.229 -
   1.230 -
   1.231 -  template <typename _Base>
   1.232 -  class AlterableBpUGraphExtender : public _Base {
   1.233 -  public:
   1.234 -
   1.235 -    typedef _Base Parent;
   1.236 -    typedef AlterableBpUGraphExtender Graph;
   1.237 -  
   1.238 -    typedef typename Parent::Node Node;
   1.239 -    typedef typename Parent::BNode BNode;
   1.240 -    typedef typename Parent::ANode ANode;
   1.241 -    typedef typename Parent::Edge Edge;
   1.242 -    typedef typename Parent::UEdge UEdge;
   1.243 -  
   1.244 -  
   1.245 -    typedef AlterationNotifier<Node> NodeNotifier;
   1.246 -    typedef AlterationNotifier<BNode> BNodeNotifier;
   1.247 -    typedef AlterationNotifier<ANode> ANodeNotifier;
   1.248 -    typedef AlterationNotifier<Edge> EdgeNotifier;
   1.249 -    typedef AlterationNotifier<UEdge> UEdgeNotifier;
   1.250 -
   1.251 -  protected:
   1.252 -
   1.253 -    mutable NodeNotifier nodeNotifier;
   1.254 -    mutable BNodeNotifier bNodeNotifier;
   1.255 -    mutable ANodeNotifier aNodeNotifier;
   1.256 -    mutable EdgeNotifier edgeNotifier;
   1.257 -    mutable UEdgeNotifier uEdgeNotifier;
   1.258 -
   1.259 -  public:
   1.260 -
   1.261 -    NodeNotifier& getNotifier(Node) const {
   1.262 -      return nodeNotifier;
   1.263 -    }
   1.264 -
   1.265 -    BNodeNotifier& getNotifier(BNode) const {
   1.266 -      return bNodeNotifier;
   1.267 -    }
   1.268 -
   1.269 -    ANodeNotifier& getNotifier(ANode) const {
   1.270 -      return aNodeNotifier;
   1.271 -    }
   1.272 -
   1.273 -    EdgeNotifier& getNotifier(Edge) const {
   1.274 -      return edgeNotifier;
   1.275 -    }
   1.276 -
   1.277 -    UEdgeNotifier& getNotifier(UEdge) const {
   1.278 -      return uEdgeNotifier;
   1.279 -    }
   1.280 -
   1.281 -    ~AlterableBpUGraphExtender() {
   1.282 -      nodeNotifier.clear();
   1.283 -      bNodeNotifier.clear();
   1.284 -      aNodeNotifier.clear();
   1.285 -      edgeNotifier.clear();
   1.286 -      uEdgeNotifier.clear();
   1.287 -    }
   1.288 -
   1.289 -  };
   1.290    
   1.291  /// @}
   1.292