2 #ifndef LEMON_ITERABLE_GRAPH_EXTENDER_H
3 #define LEMON_ITERABLE_GRAPH_EXTENDER_H
5 #include <lemon/invalid.h>
9 template <typename _Base>
10 class IterableGraphExtender : public _Base {
14 typedef IterableGraphExtender<_Base> Graph;
16 typedef typename Parent::Node Node;
17 typedef typename Parent::Edge Edge;
20 class NodeIt : public Node {
26 NodeIt(Invalid i) : Node(i) { }
28 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
29 _graph.first(*static_cast<Node*>(this));
32 NodeIt(const Graph& _graph, const Node& node)
33 : Node(node), graph(&_graph) {}
35 NodeIt& operator++() {
43 class EdgeIt : public Edge {
49 EdgeIt(Invalid i) : Edge(i) { }
51 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
52 _graph.first(*static_cast<Edge*>(this));
55 EdgeIt(const Graph& _graph, const Edge& e) :
56 Edge(e), graph(&_graph) { }
58 EdgeIt& operator++() {
66 class OutEdgeIt : public Edge {
72 OutEdgeIt(Invalid i) : Edge(i) { }
74 OutEdgeIt(const Graph& _graph, const Node& node)
76 _graph.firstOut(*this, node);
79 OutEdgeIt(const Graph& _graph, const Edge& edge)
80 : Edge(edge), graph(&_graph) {}
82 OutEdgeIt& operator++() {
83 graph->nextOut(*this);
90 class InEdgeIt : public Edge {
96 InEdgeIt(Invalid i) : Edge(i) { }
98 InEdgeIt(const Graph& _graph, const Node& node)
100 _graph.firstIn(*this, node);
103 InEdgeIt(const Graph& _graph, const Edge& edge) :
104 Edge(edge), graph(&_graph) {}
106 InEdgeIt& operator++() {
107 graph->nextIn(*this);
117 /// \todo When (and if) we change the iterators concept to use operator*,
118 /// then the following shadowed methods will become superfluous.
119 /// But for now these are important safety measures.
121 void first(NodeIt &) const;
122 void first(EdgeIt &) const;
123 void first(OutEdgeIt &) const;
124 void first(InEdgeIt &) const;
128 template <typename _Base>
129 class IterableUndirGraphExtender : public IterableGraphExtender<_Base> {
132 typedef IterableGraphExtender<_Base> Parent;
133 typedef IterableUndirGraphExtender<_Base> Graph;
135 typedef typename Parent::UndirEdge UndirEdge;
137 class UndirEdgeIt : public UndirEdge {
143 UndirEdgeIt(Invalid i) : UndirEdge(i) { }
145 explicit UndirEdgeIt(const Graph& _graph) : graph(&_graph) {
146 _graph.first(*static_cast<UndirEdge*>(this));
149 UndirEdgeIt(const Graph& _graph, const UndirEdge& e) :
150 UndirEdge(e), graph(&_graph) { }
152 UndirEdgeIt& operator++() {
163 #endif // LEMON_GRAPH_EXTENDER_H