1.1 --- a/src/lemon/graph_wrapper.h Mon Nov 15 16:09:07 2004 +0000
1.2 +++ b/src/lemon/graph_wrapper.h Mon Nov 15 16:39:55 2004 +0000
1.3 @@ -211,6 +211,30 @@
1.4 GraphWrapper(Graph& _graph) { setGraph(_graph); }
1.5 };
1.6
1.7 + template <typename _Graph>
1.8 + class RevGraphWrapperBase : public GraphWrapperBase<_Graph> {
1.9 + public:
1.10 + typedef _Graph Graph;
1.11 + typedef GraphWrapperBase<_Graph> Parent;
1.12 + protected:
1.13 + RevGraphWrapperBase() : Parent() { }
1.14 + public:
1.15 + typedef typename Parent::Node Node;
1.16 + typedef typename Parent::Edge Edge;
1.17 +
1.18 + using Parent::first;
1.19 + void firstIn(Edge& i, const Node& n) const { Parent::firstOut(i, n); }
1.20 + void firstOut(Edge& i, const Node& n ) const { Parent::firstIn(i, n); }
1.21 +
1.22 + using Parent::next;
1.23 + void nextIn(Edge& i) const { Parent::nextOut(i); }
1.24 + void nextOut(Edge& i) const { Parent::nextIn(i); }
1.25 +
1.26 + Node source(const Edge& e) const { return Parent::target(e); }
1.27 + Node target(const Edge& e) const { return Parent::source(e); }
1.28 + };
1.29 +
1.30 +
1.31 /// A graph wrapper which reverses the orientation of the edges.
1.32
1.33 ///\warning Graph wrappers are in even more experimental state than the other
1.34 @@ -234,71 +258,83 @@
1.35 /// RevGraphWrapper<ListGraph> gw(g);
1.36 /// \endcode
1.37 ///\author Marton Makai
1.38 - template<typename Graph>
1.39 - class RevGraphWrapper : public GraphWrapper<Graph> {
1.40 + template<typename _Graph>
1.41 + class RevGraphWrapper :
1.42 + public IterableGraphExtender<RevGraphWrapperBase<_Graph> > {
1.43 public:
1.44 - typedef GraphWrapper<Graph> Parent;
1.45 + typedef _Graph Graph;
1.46 + typedef IterableGraphExtender<
1.47 + RevGraphWrapperBase<_Graph> > Parent;
1.48 protected:
1.49 - RevGraphWrapper() : GraphWrapper<Graph>() { }
1.50 + RevGraphWrapper() { }
1.51 public:
1.52 - RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }
1.53 - RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { }
1.54 + RevGraphWrapper(_Graph& _graph) { setGraph(_graph); }
1.55 + };
1.56 +// template<typename Graph>
1.57 +// class RevGraphWrapper : public GraphWrapper<Graph> {
1.58 +// public:
1.59 +// typedef GraphWrapper<Graph> Parent;
1.60 +// protected:
1.61 +// RevGraphWrapper() : GraphWrapper<Graph>() { }
1.62 +// public:
1.63 +// RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }
1.64 +// RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { }
1.65
1.66 - typedef typename GraphWrapper<Graph>::Node Node;
1.67 - typedef typename GraphWrapper<Graph>::Edge Edge;
1.68 - //remark: OutEdgeIt and InEdgeIt cannot be typedef-ed to each other
1.69 - //because this does not work is some of them are not defined in the
1.70 - //original graph. The problem with this is that typedef-ed stuff
1.71 - //are instantiated in c++.
1.72 - class OutEdgeIt : public Edge {
1.73 - const RevGraphWrapper<Graph>* gw;
1.74 - friend class GraphWrapper<Graph>;
1.75 - public:
1.76 - OutEdgeIt() { }
1.77 - OutEdgeIt(Invalid i) : Edge(i) { }
1.78 - OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) :
1.79 - Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
1.80 - OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) :
1.81 - Edge(e), gw(&_gw) { }
1.82 - OutEdgeIt& operator++() {
1.83 - *(static_cast<Edge*>(this))=
1.84 - ++(typename Graph::InEdgeIt(*(gw->graph), *this));
1.85 - return *this;
1.86 - }
1.87 - };
1.88 - class InEdgeIt : public Edge {
1.89 - const RevGraphWrapper<Graph>* gw;
1.90 - friend class GraphWrapper<Graph>;
1.91 - public:
1.92 - InEdgeIt() { }
1.93 - InEdgeIt(Invalid i) : Edge(i) { }
1.94 - InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) :
1.95 - Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
1.96 - InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) :
1.97 - Edge(e), gw(&_gw) { }
1.98 - InEdgeIt& operator++() {
1.99 - *(static_cast<Edge*>(this))=
1.100 - ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
1.101 - return *this;
1.102 - }
1.103 - };
1.104 +// typedef typename GraphWrapper<Graph>::Node Node;
1.105 +// typedef typename GraphWrapper<Graph>::Edge Edge;
1.106 +// //remark: OutEdgeIt and InEdgeIt cannot be typedef-ed to each other
1.107 +// //because this does not work is some of them are not defined in the
1.108 +// //original graph. The problem with this is that typedef-ed stuff
1.109 +// //are instantiated in c++.
1.110 +// class OutEdgeIt : public Edge {
1.111 +// const RevGraphWrapper<Graph>* gw;
1.112 +// friend class GraphWrapper<Graph>;
1.113 +// public:
1.114 +// OutEdgeIt() { }
1.115 +// OutEdgeIt(Invalid i) : Edge(i) { }
1.116 +// OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) :
1.117 +// Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
1.118 +// OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) :
1.119 +// Edge(e), gw(&_gw) { }
1.120 +// OutEdgeIt& operator++() {
1.121 +// *(static_cast<Edge*>(this))=
1.122 +// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
1.123 +// return *this;
1.124 +// }
1.125 +// };
1.126 +// class InEdgeIt : public Edge {
1.127 +// const RevGraphWrapper<Graph>* gw;
1.128 +// friend class GraphWrapper<Graph>;
1.129 +// public:
1.130 +// InEdgeIt() { }
1.131 +// InEdgeIt(Invalid i) : Edge(i) { }
1.132 +// InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) :
1.133 +// Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
1.134 +// InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) :
1.135 +// Edge(e), gw(&_gw) { }
1.136 +// InEdgeIt& operator++() {
1.137 +// *(static_cast<Edge*>(this))=
1.138 +// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
1.139 +// return *this;
1.140 +// }
1.141 +// };
1.142
1.143 - using GraphWrapper<Graph>::first;
1.144 - OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
1.145 - i=OutEdgeIt(*this, p); return i;
1.146 - }
1.147 - InEdgeIt& first(InEdgeIt& i, const Node& p) const {
1.148 - i=InEdgeIt(*this, p); return i;
1.149 - }
1.150 +// using GraphWrapper<Graph>::first;
1.151 +// OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
1.152 +// i=OutEdgeIt(*this, p); return i;
1.153 +// }
1.154 +// InEdgeIt& first(InEdgeIt& i, const Node& p) const {
1.155 +// i=InEdgeIt(*this, p); return i;
1.156 +// }
1.157
1.158 - Node source(const Edge& e) const {
1.159 - return GraphWrapper<Graph>::target(e); }
1.160 - Node target(const Edge& e) const {
1.161 - return GraphWrapper<Graph>::source(e); }
1.162 +// Node source(const Edge& e) const {
1.163 +// return GraphWrapper<Graph>::target(e); }
1.164 +// Node target(const Edge& e) const {
1.165 +// return GraphWrapper<Graph>::source(e); }
1.166
1.167 - // KEEP_MAPS(Parent, RevGraphWrapper);
1.168 +// // KEEP_MAPS(Parent, RevGraphWrapper);
1.169
1.170 - };
1.171 +// };
1.172
1.173
1.174 template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
2.1 --- a/src/test/graph_wrapper_test.cc Mon Nov 15 16:09:07 2004 +0000
2.2 +++ b/src/test/graph_wrapper_test.cc Mon Nov 15 16:39:55 2004 +0000
2.3 @@ -44,7 +44,7 @@
2.4 {
2.5 checkConcept<StaticGraph, GraphWrapper<StaticGraph> >();
2.6
2.7 -// function_requires<StaticGraphConcept<RevGraphWrapper<Graph> > >();
2.8 + checkConcept<StaticGraph, RevGraphWrapper<StaticGraph> >();
2.9
2.10 checkConcept<StaticGraph, SubGraphWrapper<StaticGraph,
2.11 StaticGraph::NodeMap<bool> , StaticGraph::EdgeMap<bool> > >();