1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/lemon/iterable_graph_extender.h Wed Oct 27 22:38:50 2004 +0000
1.3 @@ -0,0 +1,131 @@
1.4 +// -*- c++ -*-
1.5 +#ifndef LEMON_ITERABLE_GRAPH_EXTENDER_H
1.6 +#define LEMON_ITERABLE_GRAPH_EXTENDER_H
1.7 +
1.8 +#include <lemon/invalid.h>
1.9 +
1.10 +namespace lemon {
1.11 +
1.12 + template <typename _Base>
1.13 + class IterableGraphExtender : public _Base {
1.14 +
1.15 + typedef _Base Parent;
1.16 + typedef IterableGraphExtender<_Base> Graph;
1.17 +
1.18 + public:
1.19 +
1.20 + typedef typename Parent::Node Node;
1.21 + typedef typename Parent::Edge Edge;
1.22 +
1.23 +
1.24 + class NodeIt : public Node {
1.25 + const Graph* graph;
1.26 + public:
1.27 +
1.28 + NodeIt() {}
1.29 +
1.30 + NodeIt(Invalid i) : Node(i) { }
1.31 +
1.32 + explicit NodeIt(const Graph& _graph) : Node(), graph(&_graph) {
1.33 + _graph.first(*static_cast<Node*>(this));
1.34 + }
1.35 +
1.36 + NodeIt(const Graph& _graph, const Node& node)
1.37 + : Node(node), graph(&_graph) {}
1.38 +
1.39 + NodeIt& operator++() {
1.40 + graph->next(*this);
1.41 + return *this;
1.42 + }
1.43 +
1.44 + };
1.45 +
1.46 +
1.47 + class EdgeIt : public Edge {
1.48 + const Graph* graph;
1.49 + public:
1.50 +
1.51 + EdgeIt() { }
1.52 +
1.53 + EdgeIt(Invalid i) : Edge(i) { }
1.54 +
1.55 + explicit EdgeIt(const Graph& _graph) : Edge(), graph(&_graph) {
1.56 + _graph.first(*static_cast<Edge*>(this));
1.57 + }
1.58 +
1.59 + EdgeIt(const Graph& _graph, const Edge& e) :
1.60 + Edge(e), graph(&_graph) { }
1.61 +
1.62 + EdgeIt& operator++() {
1.63 + graph->next(*this);
1.64 + return *this;
1.65 + }
1.66 +
1.67 + };
1.68 +
1.69 +
1.70 + class OutEdgeIt : public Edge {
1.71 + const Graph* graph;
1.72 + public:
1.73 +
1.74 + OutEdgeIt() { }
1.75 +
1.76 + OutEdgeIt(Invalid i) : Edge(i) { }
1.77 +
1.78 + OutEdgeIt(const Graph& _graph, const Node& node)
1.79 + : Edge(), graph(&_graph) {
1.80 + _graph.firstOut(*this, node);
1.81 + }
1.82 +
1.83 + OutEdgeIt(const Graph& _graph, const Edge& edge)
1.84 + : Edge(edge), graph(&_graph) {}
1.85 +
1.86 + OutEdgeIt& operator++() {
1.87 + graph->nextOut(*this);
1.88 + return *this;
1.89 + }
1.90 +
1.91 + };
1.92 +
1.93 +
1.94 + class InEdgeIt : public Edge {
1.95 + const Graph* graph;
1.96 + public:
1.97 +
1.98 + InEdgeIt() { }
1.99 +
1.100 + InEdgeIt(Invalid i) : Edge(i) { }
1.101 +
1.102 + InEdgeIt(const Graph& _graph, const Node& node)
1.103 + : Edge(), graph(&_graph) {
1.104 + _graph.firstIn(*this, node);
1.105 + }
1.106 +
1.107 + InEdgeIt(const Graph& _graph, const Edge& edge) :
1.108 + Edge(edge), graph(&_graph) {}
1.109 +
1.110 + InEdgeIt& operator++() {
1.111 + graph->nextIn(*this);
1.112 + return *this;
1.113 + }
1.114 +
1.115 + };
1.116 +
1.117 + using Parent::first;
1.118 +
1.119 + private:
1.120 +
1.121 + /// \todo When (and if) we change the iterators concept to use operator*,
1.122 + /// then the following shadowed methods will become superfluous.
1.123 + /// But for now these are important safety measures.
1.124 +
1.125 + void first(NodeIt &) const;
1.126 + void first(EdgeIt &) const;
1.127 + void first(OutEdgeIt &) const;
1.128 + void first(InEdgeIt &) const;
1.129 +
1.130 + };
1.131 +
1.132 +}
1.133 +
1.134 +#endif // LEMON_GRAPH_EXTENDER_H