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