diff -r 3fef334f5f37 -r 8cb323dbae93 src/work/marci/merge_node_graph_wrapper.h --- a/src/work/marci/merge_node_graph_wrapper.h Thu Nov 18 22:31:21 2004 +0000 +++ b/src/work/marci/merge_node_graph_wrapper.h Fri Nov 19 17:22:29 2004 +0000 @@ -38,11 +38,14 @@ class P2 : public GraphWrapperBase<_Graph2> { }; + /*! A base class for merging the node-set of two node-disjoint graphs + into the node-set of one graph. + */ template class MergeNodeGraphWrapperBase : public P1<_Graph1>, public P2<_Graph2> { public: - void print() const { std::cout << "generic" << std::endl; } + void printNode() const { std::cout << "generic" << std::endl; } typedef _Graph1 Graph1; typedef _Graph2 Graph2; typedef P1<_Graph1> Parent1; @@ -139,8 +142,8 @@ else ParentMap2::set(n, value); } - using ParentMap1::operator[]; - using ParentMap2::operator[]; +// using ParentMap1::operator[]; +// using ParentMap2::operator[]; }; }; @@ -152,7 +155,7 @@ boost::is_same >::type> : public P1<_Graph1>, public P2<_Graph2> { public : - void print() const { std::cout << "same" << std::endl; } + void printNode() const { std::cout << "same" << std::endl; } typedef _Graph1 Graph1; typedef _Graph2 Graph2; typedef P1<_Graph1> Parent1; @@ -175,7 +178,7 @@ boost::is_base_and_derived >::type> : public P1<_Graph1>, public P2<_Graph2> { public : - void print() const { std::cout << "2. nagyobb" << std::endl; } + void printNode() const { std::cout << "2. nagyobb" << std::endl; } typedef _Graph1 Graph1; typedef _Graph2 Graph2; typedef P1<_Graph1> Parent1; @@ -198,7 +201,7 @@ boost::is_base_and_derived >::type> : public P1<_Graph1>, public P2<_Graph2> { public : - void print() const { std::cout << "1. nagyobb" << std::endl; } + void printNode() const { std::cout << "1. nagyobb" << std::endl; } typedef _Graph1 Graph1; typedef _Graph2 Graph2; typedef P1<_Graph1> Parent1; @@ -215,14 +218,14 @@ }; - template + template class MergeNodeGraphWrapper : public - IterableGraphExtender > { + IterableGraphExtender > { public: typedef _Graph1 Graph1; typedef _Graph2 Graph2; typedef IterableGraphExtender< - MergeNodeGraphWrapperBase<_Graph1, _Graph2, Enable> > Parent; + MergeNodeGraphWrapperBase<_Graph1, _Graph2> > Parent; protected: MergeNodeGraphWrapper() { } public: @@ -232,6 +235,200 @@ } }; + + /*! A base class for merging the node-sets and edge-sets of + two node-disjoint graphs + into one graph. + */ + template + class MergeEdgeGraphWrapperBase : + public MergeNodeGraphWrapperBase<_Graph1, _Graph2> { + public: + void printEdge() const { std::cout << "generic" << std::endl; } + typedef _Graph1 Graph1; + typedef _Graph2 Graph2; + typedef MergeNodeGraphWrapperBase<_Graph1, _Graph2> Parent; + typedef typename Parent::Parent1 Parent1; + typedef typename Parent::Parent2 Parent2; +// typedef P1<_Graph1> Parent1; +// typedef P2<_Graph2> Parent2; + typedef typename Parent1::Edge Graph1Edge; + typedef typename Parent2::Edge Graph2Edge; + protected: + MergeEdgeGraphWrapperBase() { } + public: + template class EdgeMap; + + typedef typename Parent::Node Node; + + class Edge : public Graph1Edge, public Graph2Edge { + friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>; + template friend class EdgeMap; + protected: + bool backward; //true, iff backward + public: + Edge() { } + /// \todo =false is needed, or causes problems? + /// If \c _backward is false, then we get an edge corresponding to the + /// original one, otherwise its oppositely directed pair is obtained. + Edge(const Graph1Edge& n1, + const Graph2Edge& n2, bool _backward) : + Graph1Edge(n1), Graph2Edge(n2), backward(_backward) { } + Edge(Invalid i) : Graph1Edge(i), Graph2Edge(i), backward(true) { } + bool operator==(const Edge& v) const { + return (this->backward==v.backward && + static_cast(*this)== + static_cast(v) && + static_cast(*this)== + static_cast(v)); + } + bool operator!=(const Edge& v) const { + return (this->backward!=v.backward || + static_cast(*this)!= + static_cast(v) || + static_cast(*this)!= + static_cast(v)); + } + }; + + using Parent::first; + void first(Edge& 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 firstIn(Edge& i, const Node& n) const { + Parent1::graph->firstIn(*static_cast(&i), n); + i.backward=false; + if (*static_cast(&i)==INVALID) { + Parent2::graph->firstIn(*static_cast(&i), n); + i.backward=true; + } + } + void firstOut(Edge& i, const Node& n) const { + Parent1::graph->firstOut(*static_cast(&i), n); + i.backward=false; + if (*static_cast(&i)==INVALID) { + Parent2::graph->firstOut(*static_cast(&i), n); + i.backward=true; + } + } + + using Parent::next; + void next(Edge& 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)); + } + } + void nextIn(Edge& i) const { + if (!(i.backward)) { + Parent1::graph->nextIn(*static_cast(&i)); + if (*static_cast(&i)==INVALID) { + Parent2::graph->first(*static_cast(&i)); + i.backward=true; + } + } else { + Parent2::graph->nextIn(*static_cast(&i)); + } + } + void nextOut(Edge& i) const { + if (!(i.backward)) { + Parent1::graph->nextOut(*static_cast(&i)); + if (*static_cast(&i)==INVALID) { + Parent2::graph->first(*static_cast(&i)); + i.backward=true; + } + } else { + Parent2::graph->nextOut(*static_cast(&i)); + } + } + + Node source(const Edge& i) const { + if (!(i.backward)) { + return + Node(Parent1::graph->source(i), INVALID, false); + } else { + return + Node(INVALID, Parent2::graph->source(i), true); + } + } + + Node target(const Edge& i) const { + if (!(i.backward)) { + return + Node(Parent1::graph->target(i), INVALID, false); + } else { + return + Node(INVALID, Parent2::graph->target(i), true); + } + } + + using Parent::id; + int id(const Edge& n) const { + if (!n.backward) + return this->Parent1::graph->id(n); + else + return this->Parent2::graph->id(n); + } + + template + class EdgeMap : public Parent1::template EdgeMap<_Value>, + public Parent2::template EdgeMap<_Value> { + typedef typename Parent1::template EdgeMap<_Value> ParentMap1; + typedef typename Parent2::template EdgeMap<_Value> ParentMap2; + public: + typedef _Value Value; + typedef Edge Key; + EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw) : + ParentMap1(gw), ParentMap2(gw) { } + EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw, + const _Value& value) : + ParentMap1(gw, value), ParentMap2(gw, value) { } + _Value operator[](const Edge& n) const { + if (!n.backward) + return ParentMap1::operator[](n); + else + return ParentMap2::operator[](n); + } + void set(const Edge& n, const _Value& value) { + if (!n.backward) + ParentMap1::set(n, value); + else + ParentMap2::set(n, value); + } +// using ParentMap1::operator[]; +// using ParentMap2::operator[]; + }; + + }; + + + template + class MergeEdgeGraphWrapper : public + IterableGraphExtender > { + public: + typedef _Graph1 Graph1; + typedef _Graph2 Graph2; + typedef IterableGraphExtender< + MergeEdgeGraphWrapperBase<_Graph1, _Graph2> > Parent; + protected: + MergeEdgeGraphWrapper() { } + public: + MergeEdgeGraphWrapper(_Graph1& _graph1, _Graph2& _graph2) { + Parent::Parent1::setGraph(_graph1); + Parent::Parent2::setGraph(_graph2); + } + }; + template class NewEdgeSetGraphWrapperBase : public GraphWrapperBase<_Graph> {