diff -r afe5cf34aa50 -r ea3ecb3c9846 src/work/marci/merge_node_graph_wrapper.h --- a/src/work/marci/merge_node_graph_wrapper.h Wed Nov 17 17:13:15 2004 +0000 +++ b/src/work/marci/merge_node_graph_wrapper.h Wed Nov 17 19:37:54 2004 +0000 @@ -25,26 +25,24 @@ namespace lemon { - template - class MergeNodeGraphWrapper : - public GraphWrapper, public GraphWrapper { - typedef GraphWrapper Parent1; - typedef GraphWrapper Parent2; - typedef typename GraphWrapper::Node Graph1Node; - typedef typename GraphWrapper::Node Graph2Node; + template + class MergeNodeGraphWrapperBase : + public GraphWrapperBase<_Graph1>, public GraphWrapperBase<_Graph2> { public: - class Node; - class NodeIt; - friend class Node; - friend class NodeIt; - template class NodeMap; - - MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) : - Parent1(_graph1), Parent2(_graph2) { } + typedef _Graph1 Graph1; + typedef _Graph2 Graph2; + typedef GraphWrapperBase<_Graph1> Parent1; + typedef GraphWrapperBase<_Graph2> Parent2; + typedef typename Parent1::Node Graph1Node; + typedef typename Parent2::Node Graph2Node; + protected: + MergeNodeGraphWrapperBase() { } + public: + template class NodeMap; class Node : public Graph1Node, public Graph2Node { - friend class MergeNodeGraphWrapper; - template friend class NodeMap; + friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>; + template friend class NodeMap; protected: bool backward; //true, iff backward public: @@ -72,49 +70,28 @@ } }; - class NodeIt : public Node { - friend class MergeNodeGraphWrapper; - protected: - const MergeNodeGraphWrapper* gw; - public: - NodeIt() { } - NodeIt(Invalid i) : Node(i) { } - NodeIt(const MergeNodeGraphWrapper& _gw) : - Node(typename Graph1::NodeIt(*_gw.Parent1::graph), - typename Graph2::Node(), - false), gw(&_gw) { - if (*static_cast(this)==INVALID) { -// *static_cast(this)= -// Node(Graph1Node(INVALID), -// typename Graph2::NodeIt(*_gw.Parent2::graph), -// true); - *static_cast(this)= - typename Graph2::NodeIt(*_gw.Parent2::graph); - backward=true; + //typedef void Edge; + class Edge { }; + + void first(Node& i) const { + Parent1::graph->first(*static_cast(&i)); + i.backward=false; + if (*static_cast(&i)==INVALID) { + Parent2::graph->first(*static_cast(&i)); + i.backward=true; + } + } + void next(Node& i) const { + if (!(i.backward)) { + Parent1::graph->next(*static_cast(&i)); + if (*static_cast(&i)==INVALID) { + Parent2::graph->first(*static_cast(&i)); + i.backward=true; } + } else { + Parent2::graph->next(*static_cast(&i)); } - NodeIt(const MergeNodeGraphWrapper& _gw, - const Node& n) : - Node(n), gw(&_gw) { } - NodeIt& operator++() { - if (!this->backward) { - *(static_cast(this))= - ++(typename Graph1::NodeIt(*gw->Parent1::graph, *this)); - if (*static_cast(this)==INVALID) { -// *static_cast(this)= -// Node(typename Graph1::Node(INVALID), -// typename Graph2::NodeIt(*gw->Parent2::graph), true); - *static_cast(this)= - typename Graph2::NodeIt(*gw->Parent2::graph); - backward=true; - } - } else { - *(static_cast(this))= - ++(typename Graph2::NodeIt(*gw->Parent2::graph, *this)); - } - return *this; - } - }; + } int id(const Node& n) const { if (!n.backward) @@ -123,44 +100,44 @@ return this->Parent2::graph->id(n); } - template - class NodeMap : public Parent1::template NodeMap, - public Parent2::template NodeMap { - typedef typename Parent1::template NodeMap ParentMap1; - typedef typename Parent2::template NodeMap ParentMap2; + template + class NodeMap : public Parent1::template NodeMap<_Value>, + public Parent2::template NodeMap<_Value> { + typedef typename Parent1::template NodeMap<_Value> ParentMap1; + typedef typename Parent2::template NodeMap<_Value> ParentMap2; public: - NodeMap(const MergeNodeGraphWrapper& gw) : - ParentMap1(gw), - ParentMap2(gw) { } - NodeMap(const MergeNodeGraphWrapper& gw, - const Value& value) - : ParentMap1(gw, value), - ParentMap2(gw, value) { } - NodeMap(const NodeMap& copy) - : ParentMap1(copy), - ParentMap2(copy) { } - template - NodeMap(const NodeMap& copy) - : ParentMap1(copy), - ParentMap2(copy) { } - NodeMap& operator=(const NodeMap& copy) { - ParentMap1::operator=(copy); - ParentMap2::operator=(copy); - return *this; - } - template - NodeMap& operator=(const NodeMap& copy) { - ParentMap1::operator=(copy); - ParentMap2::operator=(copy); - return *this; - } - Value operator[](const Node& n) const { + typedef _Value Value; + typedef Node Key; + NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : + ParentMap1(gw), ParentMap2(gw) { } + NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, + const _Value& value) : + ParentMap1(gw, value), ParentMap2(gw, value) { } +// NodeMap(const NodeMap& copy) +// : ParentMap1(copy), +// ParentMap2(copy) { } +// template +// NodeMap(const NodeMap& copy) +// : ParentMap1(copy), +// ParentMap2(copy) { } +// NodeMap& operator=(const NodeMap& copy) { +// ParentMap1::operator=(copy); +// ParentMap2::operator=(copy); +// return *this; +// } +// template +// NodeMap& operator=(const NodeMap& copy) { +// ParentMap1::operator=(copy); +// ParentMap2::operator=(copy); +// return *this; +// } + _Value operator[](const Node& n) const { if (!n.backward) return ParentMap1::operator[](n); else return ParentMap2::operator[](n); } - void set(const Node& n, const Value& value) { + void set(const Node& n, const _Value& value) { if (!n.backward) ParentMap1::set(n, value); else @@ -169,7 +146,25 @@ using ParentMap1::operator[]; using ParentMap2::operator[]; }; - + + }; + + + template + class MergeNodeGraphWrapper : public + IterableGraphExtender > { + public: + typedef _Graph1 Graph1; + typedef _Graph2 Graph2; + typedef IterableGraphExtender< + MergeNodeGraphWrapperBase<_Graph1, _Graph2, Enable> > Parent; + protected: + MergeNodeGraphWrapper() { } + public: + MergeNodeGraphWrapper(_Graph1& _graph1, _Graph2& _graph2) { + Parent::Parent1::setGraph(_graph1); + Parent::Parent2::setGraph(_graph2); + } }; } //namespace lemon