Bug fixes.
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);
113 /// Base node of the iterator
115 /// Returns the base node (ie. the source in this case) of the iterator
117 /// \todo Document in the concept!
118 Node baseNode(const OutEdgeIt &e) const {
121 /// Running node of the iterator
123 /// Returns the running node (ie. the target in this case) of the
126 /// \todo Document in the concept!
127 Node runningNode(const OutEdgeIt &e) const {
131 /// Base node of the iterator
133 /// Returns the base node (ie. the target in this case) of the iterator
135 /// \todo Document in the concept!
136 Node baseNode(const InEdgeIt &e) const {
139 /// Running node of the iterator
141 /// Returns the running node (ie. the source in this case) of the
144 /// \todo Document in the concept!
145 Node runningNode(const InEdgeIt &e) const {
153 // /// \todo When (and if) we change the iterators concept to use operator*,
154 // /// then the following shadowed methods will become superfluous.
155 // /// But for now these are important safety measures.
157 // void first(NodeIt &) const;
158 // void first(EdgeIt &) const;
159 // void first(OutEdgeIt &) const;
160 // void first(InEdgeIt &) const;
169 template <typename _Base>
170 class IterableUndirGraphExtender : public IterableGraphExtender<_Base> {
173 typedef IterableGraphExtender<_Base> Parent;
174 typedef IterableUndirGraphExtender<_Base> Graph;
175 typedef typename Parent::Node Node;
177 typedef typename Parent::UndirEdge UndirEdge;
179 class UndirEdgeIt : public Parent::UndirEdge {
185 UndirEdgeIt(Invalid i) : UndirEdge(i) { }
187 explicit UndirEdgeIt(const Graph& _graph) : graph(&_graph) {
188 _graph.first(*static_cast<UndirEdge*>(this));
191 UndirEdgeIt(const Graph& _graph, const UndirEdge& e) :
192 UndirEdge(e), graph(&_graph) { }
194 UndirEdgeIt& operator++() {
201 class IncEdgeIt : public Parent::UndirEdge {
204 friend class IterableUndirGraphExtender;
205 template <typename G>
206 friend class UndirGraphExtender;
211 IncEdgeIt(Invalid i) : UndirEdge(i), forward(false) { }
213 IncEdgeIt(const Graph& _graph, const Node &n)
216 _graph._dirFirstOut(*this, n);
219 IncEdgeIt(const Graph& _graph, const UndirEdge &ue, const Node &n)
220 : graph(&_graph), UndirEdge(ue)
222 forward = (_graph.source(ue) == n);
225 IncEdgeIt& operator++() {
226 graph->_dirNextOut(*this);
231 using Parent::baseNode;
232 using Parent::runningNode;
234 /// Base node of the iterator
236 /// Returns the base node of the iterator
237 Node baseNode(const IncEdgeIt &e) const {
238 return _dirSource(e);
240 /// Running node of the iterator
242 /// Returns the running node of the iterator
243 Node runningNode(const IncEdgeIt &e) const {
244 return _dirTarget(e);
250 #endif // LEMON_GRAPH_EXTENDER_H