1 | // -*- c++ -*- |
---|

2 | |
---|

3 | #ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H |
---|

4 | #define LEMON_ERASABLE_GRAPH_EXTENDER_H |
---|

5 | |
---|

6 | #include <vector> |
---|

7 | |
---|

8 | #include <lemon/invalid.h> |
---|

9 | |
---|

10 | |
---|

11 | namespace lemon { |
---|

12 | |
---|

13 | template <typename _Base> |
---|

14 | class ErasableGraphExtender : public _Base { |
---|

15 | public: |
---|

16 | |
---|

17 | typedef ErasableGraphExtender Graph; |
---|

18 | typedef _Base Parent; |
---|

19 | |
---|

20 | typedef typename Parent::Node Node; |
---|

21 | typedef typename Parent::Edge Edge; |
---|

22 | |
---|

23 | void erase(const Node& node) { |
---|

24 | Edge edge; |
---|

25 | Parent::firstOut(edge, node); |
---|

26 | while (edge != INVALID ) { |
---|

27 | erase(edge); |
---|

28 | Parent::firstOut(edge, node); |
---|

29 | } |
---|

30 | |
---|

31 | Parent::firstIn(edge, node); |
---|

32 | while (edge != INVALID ) { |
---|

33 | erase(edge); |
---|

34 | Parent::firstIn(edge, node); |
---|

35 | } |
---|

36 | |
---|

37 | Parent::getNotifier(Node()).erase(node); |
---|

38 | Parent::erase(node); |
---|

39 | } |
---|

40 | |
---|

41 | void erase(const Edge& edge) { |
---|

42 | Parent::getNotifier(Edge()).erase(edge); |
---|

43 | Parent::erase(edge); |
---|

44 | } |
---|

45 | |
---|

46 | }; |
---|

47 | |
---|

48 | template <typename _Base> |
---|

49 | class ErasableUndirGraphExtender : public _Base { |
---|

50 | public: |
---|

51 | |
---|

52 | typedef ErasableUndirGraphExtender Graph; |
---|

53 | typedef _Base Parent; |
---|

54 | |
---|

55 | typedef typename Parent::Node Node; |
---|

56 | typedef typename Parent::UndirEdge UndirEdge; |
---|

57 | typedef typename Parent::Edge Edge; |
---|

58 | |
---|

59 | void erase(const Node& node) { |
---|

60 | Edge edge; |
---|

61 | Parent::firstOut(edge, node); |
---|

62 | while (edge != INVALID ) { |
---|

63 | erase(edge); |
---|

64 | Parent::firstOut(edge, node); |
---|

65 | } |
---|

66 | |
---|

67 | Parent::getNotifier(Node()).erase(node); |
---|

68 | Parent::erase(node); |
---|

69 | } |
---|

70 | |
---|

71 | void erase(const UndirEdge& uedge) { |
---|

72 | std::vector<Edge> edges; |
---|

73 | edges.push_back(Edge(uedge,true)); |
---|

74 | edges.push_back(Edge(uedge,false)); |
---|

75 | Parent::getNotifier(Edge()).erase(edges); |
---|

76 | Parent::getNotifier(UndirEdge()).erase(uedge); |
---|

77 | Parent::erase(uedge); |
---|

78 | } |
---|

79 | |
---|

80 | }; |
---|

81 | |
---|

82 | } |
---|

83 | |
---|

84 | #endif |
---|