1 | // -*- c++ -*- |
---|
2 | |
---|
3 | #ifndef LEMON_EXTENDABLE_GRAPH_EXTENDER_H |
---|
4 | #define LEMON_EXTENDABLE_GRAPH_EXTENDER_H |
---|
5 | |
---|
6 | namespace lemon { |
---|
7 | |
---|
8 | template <typename _Base> |
---|
9 | class ExtendableGraphExtender : public _Base { |
---|
10 | public: |
---|
11 | |
---|
12 | typedef ExtendableGraphExtender Graph; |
---|
13 | typedef _Base Parent; |
---|
14 | |
---|
15 | typedef typename Parent::Node Node; |
---|
16 | typedef typename Parent::Edge Edge; |
---|
17 | |
---|
18 | Node addNode() { |
---|
19 | Node node = Parent::addNode(); |
---|
20 | Parent::getNotifier(Node()).add(node); |
---|
21 | return node; |
---|
22 | } |
---|
23 | |
---|
24 | Edge addEdge(const Node& from, const Node& to) { |
---|
25 | Edge edge = Parent::addEdge(from, to); |
---|
26 | Parent::getNotifier(Edge()).add(edge); |
---|
27 | return edge; |
---|
28 | } |
---|
29 | |
---|
30 | }; |
---|
31 | |
---|
32 | template <typename _Base> |
---|
33 | class ExtendableUndirGraphExtender : public _Base { |
---|
34 | public: |
---|
35 | |
---|
36 | typedef ExtendableUndirGraphExtender Graph; |
---|
37 | typedef _Base Parent; |
---|
38 | |
---|
39 | typedef typename Parent::Node Node; |
---|
40 | typedef typename Parent::Edge Edge; |
---|
41 | typedef typename Parent::UndirEdge UndirEdge; |
---|
42 | |
---|
43 | Node addNode() { |
---|
44 | Node node = Parent::addNode(); |
---|
45 | Parent::getNotifier(Node()).add(node); |
---|
46 | return node; |
---|
47 | } |
---|
48 | |
---|
49 | UndirEdge addEdge(const Node& from, const Node& to) { |
---|
50 | UndirEdge uedge = Parent::addEdge(from, to); |
---|
51 | Parent::getNotifier(UndirEdge()).add(uedge); |
---|
52 | |
---|
53 | std::vector<Edge> edges; |
---|
54 | edges.push_back(Parent::direct(uedge, true)); |
---|
55 | edges.push_back(Parent::direct(uedge, false)); |
---|
56 | Parent::getNotifier(Edge()).add(edges); |
---|
57 | |
---|
58 | return uedge; |
---|
59 | } |
---|
60 | |
---|
61 | }; |
---|
62 | |
---|
63 | |
---|
64 | template <typename _Base> |
---|
65 | class ExtendableUndirBipartiteGraphExtender : public _Base { |
---|
66 | public: |
---|
67 | |
---|
68 | typedef _Base Parent; |
---|
69 | typedef ExtendableUndirBipartiteGraphExtender Graph; |
---|
70 | |
---|
71 | typedef typename Parent::Node Node; |
---|
72 | typedef typename Parent::LowerNode LowerNode; |
---|
73 | typedef typename Parent::UpperNode UpperNode; |
---|
74 | typedef typename Parent::Edge Edge; |
---|
75 | typedef typename Parent::UndirEdge UndirEdge; |
---|
76 | |
---|
77 | Node addUpperNode() { |
---|
78 | Node node = Parent::addUpperNode(); |
---|
79 | Parent::getNotifier(UpperNode()).add(node); |
---|
80 | Parent::getNotifier(Node()).add(node); |
---|
81 | return node; |
---|
82 | } |
---|
83 | |
---|
84 | Node addLowerNode() { |
---|
85 | Node node = Parent::addLowerNode(); |
---|
86 | Parent::getNotifier(LowerNode()).add(node); |
---|
87 | Parent::getNotifier(Node()).add(node); |
---|
88 | return node; |
---|
89 | } |
---|
90 | |
---|
91 | UndirEdge addEdge(const Node& source, const Node& target) { |
---|
92 | UndirEdge undiredge = Parent::addEdge(source, target); |
---|
93 | Parent::getNotifier(UndirEdge()).add(undiredge); |
---|
94 | |
---|
95 | std::vector<Edge> edges; |
---|
96 | edges.push_back(Parent::direct(undiredge, true)); |
---|
97 | edges.push_back(Parent::direct(undiredge, false)); |
---|
98 | Parent::getNotifier(Edge()).add(edges); |
---|
99 | |
---|
100 | return undiredge; |
---|
101 | } |
---|
102 | |
---|
103 | }; |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | #endif |
---|