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 ExtendableEdgeSetExtender : public _Base { |
---|
34 | public: |
---|
35 | |
---|
36 | typedef ExtendableEdgeSetExtender Graph; |
---|
37 | typedef _Base Parent; |
---|
38 | |
---|
39 | typedef typename Parent::Edge Edge; |
---|
40 | typedef typename Parent::Node Node; |
---|
41 | |
---|
42 | Edge addEdge(const Node& from, const Node& to) { |
---|
43 | Edge edge = Parent::addEdge(from, to); |
---|
44 | Parent::getNotifier(Edge()).add(edge); |
---|
45 | return edge; |
---|
46 | } |
---|
47 | |
---|
48 | }; |
---|
49 | |
---|
50 | template <typename _Base> |
---|
51 | class ExtendableUGraphExtender : public _Base { |
---|
52 | public: |
---|
53 | |
---|
54 | typedef ExtendableUGraphExtender Graph; |
---|
55 | typedef _Base Parent; |
---|
56 | |
---|
57 | typedef typename Parent::Node Node; |
---|
58 | typedef typename Parent::Edge Edge; |
---|
59 | typedef typename Parent::UEdge UEdge; |
---|
60 | |
---|
61 | Node addNode() { |
---|
62 | Node node = Parent::addNode(); |
---|
63 | Parent::getNotifier(Node()).add(node); |
---|
64 | return node; |
---|
65 | } |
---|
66 | |
---|
67 | UEdge addEdge(const Node& from, const Node& to) { |
---|
68 | UEdge uedge = Parent::addEdge(from, to); |
---|
69 | Parent::getNotifier(UEdge()).add(uedge); |
---|
70 | |
---|
71 | std::vector<Edge> edges; |
---|
72 | edges.push_back(Parent::direct(uedge, true)); |
---|
73 | edges.push_back(Parent::direct(uedge, false)); |
---|
74 | Parent::getNotifier(Edge()).add(edges); |
---|
75 | |
---|
76 | return uedge; |
---|
77 | } |
---|
78 | |
---|
79 | }; |
---|
80 | |
---|
81 | template <typename _Base> |
---|
82 | class ExtendableUEdgeSetExtender : public _Base { |
---|
83 | public: |
---|
84 | |
---|
85 | typedef ExtendableUEdgeSetExtender Graph; |
---|
86 | typedef _Base Parent; |
---|
87 | |
---|
88 | typedef typename Parent::Node Node; |
---|
89 | typedef typename Parent::Edge Edge; |
---|
90 | typedef typename Parent::UEdge UEdge; |
---|
91 | |
---|
92 | UEdge addEdge(const Node& from, const Node& to) { |
---|
93 | UEdge uedge = Parent::addEdge(from, to); |
---|
94 | Parent::getNotifier(UEdge()).add(uedge); |
---|
95 | |
---|
96 | std::vector<Edge> edges; |
---|
97 | edges.push_back(Parent::direct(uedge, true)); |
---|
98 | edges.push_back(Parent::direct(uedge, false)); |
---|
99 | Parent::getNotifier(Edge()).add(edges); |
---|
100 | |
---|
101 | return uedge; |
---|
102 | } |
---|
103 | |
---|
104 | }; |
---|
105 | |
---|
106 | |
---|
107 | template <typename _Base> |
---|
108 | class ExtendableUBipartiteGraphExtender : public _Base { |
---|
109 | public: |
---|
110 | |
---|
111 | typedef _Base Parent; |
---|
112 | typedef ExtendableUBipartiteGraphExtender Graph; |
---|
113 | |
---|
114 | typedef typename Parent::Node Node; |
---|
115 | typedef typename Parent::LowerNode LowerNode; |
---|
116 | typedef typename Parent::UpperNode UpperNode; |
---|
117 | typedef typename Parent::Edge Edge; |
---|
118 | typedef typename Parent::UEdge UEdge; |
---|
119 | |
---|
120 | Node addUpperNode() { |
---|
121 | Node node = Parent::addUpperNode(); |
---|
122 | Parent::getNotifier(UpperNode()).add(node); |
---|
123 | Parent::getNotifier(Node()).add(node); |
---|
124 | return node; |
---|
125 | } |
---|
126 | |
---|
127 | Node addLowerNode() { |
---|
128 | Node node = Parent::addLowerNode(); |
---|
129 | Parent::getNotifier(LowerNode()).add(node); |
---|
130 | Parent::getNotifier(Node()).add(node); |
---|
131 | return node; |
---|
132 | } |
---|
133 | |
---|
134 | UEdge addEdge(const Node& source, const Node& target) { |
---|
135 | UEdge uedge = Parent::addEdge(source, target); |
---|
136 | Parent::getNotifier(UEdge()).add(uedge); |
---|
137 | |
---|
138 | std::vector<Edge> edges; |
---|
139 | edges.push_back(Parent::direct(uedge, true)); |
---|
140 | edges.push_back(Parent::direct(uedge, false)); |
---|
141 | Parent::getNotifier(Edge()).add(edges); |
---|
142 | |
---|
143 | return uedge; |
---|
144 | } |
---|
145 | |
---|
146 | }; |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | #endif |
---|