[946] | 1 | // -*- c++ -*- |
---|
| 2 | |
---|
| 3 | #ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H |
---|
| 4 | #define LEMON_ERASABLE_GRAPH_EXTENDER_H |
---|
| 5 | |
---|
| 6 | #include <lemon/invalid.h> |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | namespace lemon { |
---|
| 10 | |
---|
| 11 | template <typename _Base> |
---|
| 12 | class ErasableGraphExtender : public _Base { |
---|
| 13 | public: |
---|
| 14 | |
---|
| 15 | typedef ErasableGraphExtender Graph; |
---|
| 16 | typedef _Base Parent; |
---|
| 17 | |
---|
| 18 | typedef typename Parent::Node Node; |
---|
| 19 | typedef typename Parent::Edge Edge; |
---|
| 20 | |
---|
| 21 | void erase(const Node& node) { |
---|
| 22 | Edge edge; |
---|
| 23 | Parent::firstOut(edge, node); |
---|
| 24 | while (edge != INVALID ) { |
---|
| 25 | erase(edge); |
---|
| 26 | Parent::firstOut(edge, node); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | Parent::firstIn(edge, node); |
---|
| 30 | while (edge != INVALID ) { |
---|
| 31 | erase(edge); |
---|
| 32 | Parent::firstIn(edge, node); |
---|
| 33 | } |
---|
| 34 | |
---|
[1039] | 35 | Parent::getNotifier(Node()).erase(node); |
---|
[946] | 36 | Parent::erase(node); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | void erase(const Edge& edge) { |
---|
[1039] | 40 | Parent::getNotifier(Edge()).erase(edge); |
---|
[946] | 41 | Parent::erase(edge); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | }; |
---|
| 45 | |
---|
[1022] | 46 | template <typename _Base> |
---|
| 47 | class ErasableUndirGraphExtender : public _Base { |
---|
| 48 | public: |
---|
| 49 | |
---|
| 50 | typedef ErasableUndirGraphExtender Graph; |
---|
| 51 | typedef _Base Parent; |
---|
| 52 | |
---|
| 53 | typedef typename Parent::Node Node; |
---|
| 54 | typedef typename Parent::UndirEdge UndirEdge; |
---|
| 55 | typedef typename Parent::Edge Edge; |
---|
| 56 | |
---|
| 57 | void erase(const Node& node) { |
---|
| 58 | Edge edge; |
---|
| 59 | Parent::firstOut(edge, node); |
---|
| 60 | while (edge != INVALID ) { |
---|
| 61 | erase(edge); |
---|
| 62 | Parent::firstOut(edge, node); |
---|
| 63 | } |
---|
| 64 | |
---|
[1039] | 65 | Parent::getNotifier(Node()).erase(node); |
---|
[1022] | 66 | Parent::erase(node); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | void erase(const UndirEdge& uedge) { |
---|
[1039] | 70 | Parent::getNotifier(Edge()).erase(Edge(uedge,true)); |
---|
| 71 | Parent::getNotifier(Edge()).erase(Edge(uedge,false)); |
---|
| 72 | Parent::getNotifier(UndirEdge()).erase(uedge); |
---|
[1022] | 73 | Parent::erase(uedge); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | }; |
---|
| 77 | |
---|
[946] | 78 | } |
---|
| 79 | |
---|
| 80 | #endif |
---|