diff -r ef2d00e46897 -r c2992fd74dad lemon/bits/alteration_notifier.h --- a/lemon/bits/alteration_notifier.h Wed Feb 22 12:45:59 2006 +0000 +++ b/lemon/bits/alteration_notifier.h Wed Feb 22 18:26:56 2006 +0000 @@ -265,8 +265,16 @@ /// void add(const Item& item) { typename Container::iterator it; - for (it = container.begin(); it != container.end(); ++it) { - (*it)->add(item); + try { + for (it = container.begin(); it != container.end(); ++it) { + (*it)->add(item); + } + } catch (...) { + typename Container::iterator jt; + for (jt = container.begin(); jt != it; ++it) { + (*it)->erase(item); + } + throw; } } @@ -278,8 +286,16 @@ /// void add(const std::vector& items) { typename Container::iterator it; - for (it = container.begin(); it != container.end(); ++it) { - (*it)->add(items); + try { + for (it = container.begin(); it != container.end(); ++it) { + (*it)->add(items); + } + } catch (...) { + typename Container::iterator jt; + for (jt = container.begin(); jt != it; ++it) { + (*it)->erase(items); + } + throw; } } @@ -316,8 +332,16 @@ /// from an empty container. void build() { typename Container::iterator it; - for (it = container.begin(); it != container.end(); ++it) { - (*it)->build(); + try { + for (it = container.begin(); it != container.end(); ++it) { + (*it)->build(); + } + } catch (...) { + typename Container::iterator jt; + for (jt = container.begin(); jt != it; ++it) { + (*it)->clear(); + } + throw; } } @@ -335,232 +359,6 @@ } }; - - /// \brief Class to extend a graph with the functionality of alteration - /// observing. - /// - /// AlterableGraphExtender extends the _Base graphs functionality with - /// the possibility of alteration observing. It defines two observer - /// registrys for the nodes and mapes. - /// - /// \todo Document what "alteration observing" is. And probably find a - /// better (shorter) name. - /// - /// \param _Base is the base class to extend. - /// - /// \pre _Base is conform to the BaseGraphComponent concept. - /// - /// \post AlterableGraphExtender<_Base> is conform to the - /// AlterableGraphComponent concept. - /// - /// \author Balazs Dezso - - template - class AlterableGraphExtender : public _Base { - public: - - typedef AlterableGraphExtender Graph; - typedef _Base Parent; - - typedef typename Parent::Node Node; - typedef typename Parent::Edge Edge; - - /// The edge observer registry. - typedef AlterationNotifier EdgeNotifier; - /// The node observer registry. - typedef AlterationNotifier NodeNotifier; - - - protected: - - mutable EdgeNotifier edge_notifier; - - mutable NodeNotifier node_notifier; - - public: - - /// \brief Gives back the edge alteration notifier. - /// - /// Gives back the edge alteration notifier. - EdgeNotifier& getNotifier(Edge) const { - return edge_notifier; - } - - /// \brief Gives back the node alteration notifier. - /// - /// Gives back the node alteration notifier. - NodeNotifier& getNotifier(Node) const { - return node_notifier; - } - - ~AlterableGraphExtender() { - node_notifier.clear(); - edge_notifier.clear(); - } - - }; - - - template - class AlterableEdgeSetExtender : public _Base { - public: - - typedef AlterableEdgeSetExtender Graph; - typedef _Base Parent; - - typedef typename Parent::Edge Edge; - - /// The edge observer registry. - typedef AlterationNotifier EdgeNotifier; - - protected: - - mutable EdgeNotifier edge_notifier; - - public: - - /// \brief Gives back the edge alteration notifier. - /// - /// Gives back the edge alteration notifier. - EdgeNotifier& getNotifier(Edge) const { - return edge_notifier; - } - - ~AlterableEdgeSetExtender() { - edge_notifier.clear(); - } - - }; - - /// \brief Class to extend an undirected graph with the functionality of - /// alteration observing. - /// - /// \todo Document. - /// - /// \sa AlterableGraphExtender - /// - /// \bug This should be done some other way. Possibilities: template - /// specialization (not very easy, if at all possible); some kind of - /// enable_if boost technique? - - template - class AlterableUGraphExtender - : public AlterableGraphExtender<_Base> { - public: - - typedef AlterableUGraphExtender Graph; - typedef AlterableGraphExtender<_Base> Parent; - - typedef typename Parent::UEdge UEdge; - - /// The edge observer registry. - typedef AlterationNotifier UEdgeNotifier; - - protected: - - mutable UEdgeNotifier u_edge_notifier; - - public: - - using Parent::getNotifier; - UEdgeNotifier& getNotifier(UEdge) const { - return u_edge_notifier; - } - - ~AlterableUGraphExtender() { - u_edge_notifier.clear(); - } - }; - - template - class AlterableUEdgeSetExtender - : public AlterableEdgeSetExtender<_Base> { - public: - - typedef AlterableUEdgeSetExtender Graph; - typedef AlterableEdgeSetExtender<_Base> Parent; - - typedef typename Parent::UEdge UEdge; - - typedef AlterationNotifier UEdgeNotifier; - - protected: - - mutable UEdgeNotifier u_edge_notifier; - - public: - - using Parent::getNotifier; - UEdgeNotifier& getNotifier(UEdge) const { - return u_edge_notifier; - } - - ~AlterableUEdgeSetExtender() { - u_edge_notifier.clear(); - } - }; - - - - template - class AlterableBpUGraphExtender : public _Base { - public: - - typedef _Base Parent; - typedef AlterableBpUGraphExtender Graph; - - typedef typename Parent::Node Node; - typedef typename Parent::BNode BNode; - typedef typename Parent::ANode ANode; - typedef typename Parent::Edge Edge; - typedef typename Parent::UEdge UEdge; - - - typedef AlterationNotifier NodeNotifier; - typedef AlterationNotifier BNodeNotifier; - typedef AlterationNotifier ANodeNotifier; - typedef AlterationNotifier EdgeNotifier; - typedef AlterationNotifier UEdgeNotifier; - - protected: - - mutable NodeNotifier nodeNotifier; - mutable BNodeNotifier bNodeNotifier; - mutable ANodeNotifier aNodeNotifier; - mutable EdgeNotifier edgeNotifier; - mutable UEdgeNotifier uEdgeNotifier; - - public: - - NodeNotifier& getNotifier(Node) const { - return nodeNotifier; - } - - BNodeNotifier& getNotifier(BNode) const { - return bNodeNotifier; - } - - ANodeNotifier& getNotifier(ANode) const { - return aNodeNotifier; - } - - EdgeNotifier& getNotifier(Edge) const { - return edgeNotifier; - } - - UEdgeNotifier& getNotifier(UEdge) const { - return uEdgeNotifier; - } - - ~AlterableBpUGraphExtender() { - nodeNotifier.clear(); - bNodeNotifier.clear(); - aNodeNotifier.clear(); - edgeNotifier.clear(); - uEdgeNotifier.clear(); - } - - }; /// @}