# HG changeset patch # User marci # Date 1100536795 0 # Node ID 665ffade9aca830b7dfb38b54d7c23663e767429 # Parent eea8ed12e4be7789e4b549b12696974057e62b62 RevGraphWrapper modified according to the factory diff -r eea8ed12e4be -r 665ffade9aca src/lemon/graph_wrapper.h --- a/src/lemon/graph_wrapper.h Mon Nov 15 16:09:07 2004 +0000 +++ b/src/lemon/graph_wrapper.h Mon Nov 15 16:39:55 2004 +0000 @@ -211,6 +211,30 @@ GraphWrapper(Graph& _graph) { setGraph(_graph); } }; + template + class RevGraphWrapperBase : public GraphWrapperBase<_Graph> { + public: + typedef _Graph Graph; + typedef GraphWrapperBase<_Graph> Parent; + protected: + RevGraphWrapperBase() : Parent() { } + public: + typedef typename Parent::Node Node; + typedef typename Parent::Edge Edge; + + using Parent::first; + void firstIn(Edge& i, const Node& n) const { Parent::firstOut(i, n); } + void firstOut(Edge& i, const Node& n ) const { Parent::firstIn(i, n); } + + using Parent::next; + void nextIn(Edge& i) const { Parent::nextOut(i); } + void nextOut(Edge& i) const { Parent::nextIn(i); } + + Node source(const Edge& e) const { return Parent::target(e); } + Node target(const Edge& e) const { return Parent::source(e); } + }; + + /// A graph wrapper which reverses the orientation of the edges. ///\warning Graph wrappers are in even more experimental state than the other @@ -234,71 +258,83 @@ /// RevGraphWrapper gw(g); /// \endcode ///\author Marton Makai - template - class RevGraphWrapper : public GraphWrapper { + template + class RevGraphWrapper : + public IterableGraphExtender > { public: - typedef GraphWrapper Parent; + typedef _Graph Graph; + typedef IterableGraphExtender< + RevGraphWrapperBase<_Graph> > Parent; protected: - RevGraphWrapper() : GraphWrapper() { } + RevGraphWrapper() { } public: - RevGraphWrapper(Graph& _graph) : GraphWrapper(_graph) { } - RevGraphWrapper(const RevGraphWrapper& gw) : Parent(gw) { } + RevGraphWrapper(_Graph& _graph) { setGraph(_graph); } + }; +// template +// class RevGraphWrapper : public GraphWrapper { +// public: +// typedef GraphWrapper Parent; +// protected: +// RevGraphWrapper() : GraphWrapper() { } +// public: +// RevGraphWrapper(Graph& _graph) : GraphWrapper(_graph) { } +// RevGraphWrapper(const RevGraphWrapper& gw) : Parent(gw) { } - typedef typename GraphWrapper::Node Node; - typedef typename GraphWrapper::Edge Edge; - //remark: OutEdgeIt and InEdgeIt cannot be typedef-ed to each other - //because this does not work is some of them are not defined in the - //original graph. The problem with this is that typedef-ed stuff - //are instantiated in c++. - class OutEdgeIt : public Edge { - const RevGraphWrapper* gw; - friend class GraphWrapper; - public: - OutEdgeIt() { } - OutEdgeIt(Invalid i) : Edge(i) { } - OutEdgeIt(const RevGraphWrapper& _gw, const Node& n) : - Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { } - OutEdgeIt(const RevGraphWrapper& _gw, const Edge& e) : - Edge(e), gw(&_gw) { } - OutEdgeIt& operator++() { - *(static_cast(this))= - ++(typename Graph::InEdgeIt(*(gw->graph), *this)); - return *this; - } - }; - class InEdgeIt : public Edge { - const RevGraphWrapper* gw; - friend class GraphWrapper; - public: - InEdgeIt() { } - InEdgeIt(Invalid i) : Edge(i) { } - InEdgeIt(const RevGraphWrapper& _gw, const Node& n) : - Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { } - InEdgeIt(const RevGraphWrapper& _gw, const Edge& e) : - Edge(e), gw(&_gw) { } - InEdgeIt& operator++() { - *(static_cast(this))= - ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); - return *this; - } - }; +// typedef typename GraphWrapper::Node Node; +// typedef typename GraphWrapper::Edge Edge; +// //remark: OutEdgeIt and InEdgeIt cannot be typedef-ed to each other +// //because this does not work is some of them are not defined in the +// //original graph. The problem with this is that typedef-ed stuff +// //are instantiated in c++. +// class OutEdgeIt : public Edge { +// const RevGraphWrapper* gw; +// friend class GraphWrapper; +// public: +// OutEdgeIt() { } +// OutEdgeIt(Invalid i) : Edge(i) { } +// OutEdgeIt(const RevGraphWrapper& _gw, const Node& n) : +// Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { } +// OutEdgeIt(const RevGraphWrapper& _gw, const Edge& e) : +// Edge(e), gw(&_gw) { } +// OutEdgeIt& operator++() { +// *(static_cast(this))= +// ++(typename Graph::InEdgeIt(*(gw->graph), *this)); +// return *this; +// } +// }; +// class InEdgeIt : public Edge { +// const RevGraphWrapper* gw; +// friend class GraphWrapper; +// public: +// InEdgeIt() { } +// InEdgeIt(Invalid i) : Edge(i) { } +// InEdgeIt(const RevGraphWrapper& _gw, const Node& n) : +// Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { } +// InEdgeIt(const RevGraphWrapper& _gw, const Edge& e) : +// Edge(e), gw(&_gw) { } +// InEdgeIt& operator++() { +// *(static_cast(this))= +// ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); +// return *this; +// } +// }; - using GraphWrapper::first; - OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { - i=OutEdgeIt(*this, p); return i; - } - InEdgeIt& first(InEdgeIt& i, const Node& p) const { - i=InEdgeIt(*this, p); return i; - } +// using GraphWrapper::first; +// OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { +// i=OutEdgeIt(*this, p); return i; +// } +// InEdgeIt& first(InEdgeIt& i, const Node& p) const { +// i=InEdgeIt(*this, p); return i; +// } - Node source(const Edge& e) const { - return GraphWrapper::target(e); } - Node target(const Edge& e) const { - return GraphWrapper::source(e); } +// Node source(const Edge& e) const { +// return GraphWrapper::target(e); } +// Node target(const Edge& e) const { +// return GraphWrapper::source(e); } - // KEEP_MAPS(Parent, RevGraphWrapper); +// // KEEP_MAPS(Parent, RevGraphWrapper); - }; +// }; template diff -r eea8ed12e4be -r 665ffade9aca src/test/graph_wrapper_test.cc --- a/src/test/graph_wrapper_test.cc Mon Nov 15 16:09:07 2004 +0000 +++ b/src/test/graph_wrapper_test.cc Mon Nov 15 16:39:55 2004 +0000 @@ -44,7 +44,7 @@ { checkConcept >(); -// function_requires > >(); + checkConcept >(); checkConcept , StaticGraph::EdgeMap > >();