diff -r 3b1ad8bc21da -r bd7ea1a718e2 src/work/marci/merge_node_graph_wrapper.h --- a/src/work/marci/merge_node_graph_wrapper.h Mon Nov 29 17:55:46 2004 +0000 +++ b/src/work/marci/merge_node_graph_wrapper.h Wed Dec 01 14:08:37 2004 +0000 @@ -360,7 +360,7 @@ Generic implementation for unrelated _Graph1::Edge and _Graph2::Edge. */ template - class MergeEdgeGraphWrapperBase : + class MergeEdgeGraphWrapperBaseBase : public MergeNodeGraphWrapperBase<_Graph1, _Graph2> { public: static void printEdge() { std::cout << "edge: generic" << std::endl; } @@ -374,15 +374,11 @@ typedef typename Parent1::Edge Graph1Edge; typedef typename Parent2::Edge Graph2Edge; protected: - MergeEdgeGraphWrapperBase() { } + MergeEdgeGraphWrapperBaseBase() { } public: - template class EdgeMap; - - typedef typename Parent::Node Node; class Edge : public Graph1Edge, public Graph2Edge { - friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>; - template friend class EdgeMap; + friend class MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2>; protected: bool backward; //true, iff backward public: @@ -409,134 +405,14 @@ using Parent::forward; using Parent::backward; - bool forward(const Edge& e) const { return !e.backward; } - bool backward(const Edge& e) const { return e.backward; } + using Parent::setForward; + using Parent::setBackward; + static bool forward(const Edge& e) { return !e.backward; } + static bool backward(const Edge& e) { return e.backward; } + static void setForward(Edge& e) { e.backward=false; } + static void setBackward(Edge& e) { e.backward=true; } + }; - 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 { - if (!backward(n)) { - Parent1::graph->firstIn(*static_cast(&i), n); - if (*static_cast(&i)==INVALID) - i=INVALID; - else - i.backward=false; - } else { - Parent2::graph->firstIn(*static_cast(&i), n); - i.backward=true; - } - } - void firstOut(Edge& i, const Node& n) const { - if (!backward(n)) { - Parent1::graph->firstOut(*static_cast(&i), n); - if (*static_cast(&i)==INVALID) - i=INVALID; - else - i.backward=false; - } else { - 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) i=INVALID; - } 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) i=INVALID; - } 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 { - protected: - typedef typename Parent::Graph1::template EdgeMap<_Value> ParentMap1; - typedef typename Parent::Graph2::template EdgeMap<_Value> ParentMap2; - ParentMap1 forward_map; - ParentMap2 backward_map; - public: - typedef _Value Value; - typedef Edge Key; - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw) : - forward_map(*(gw.Parent1::graph)), - backward_map(*(gw.Parent2::graph)) { } - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw, - const _Value& value) : - forward_map(*(gw.Parent1::graph), value), - backward_map(*(gw.Parent2::graph), value) { } - _Value operator[](const Edge& n) const { - if (!n.backward) - return forward_map[n]; - else - return backward_map[n]; - } - void set(const Edge& n, const _Value& value) { - if (!n.backward) - forward_map.set(n, value); - else - backward_map.set(n, value); - } -// using ParentMap1::operator[]; -// using ParentMap2::operator[]; - }; - - }; /*! A graph wrapper base class @@ -547,7 +423,7 @@ are the same. */ template - class MergeEdgeGraphWrapperBase< + class MergeEdgeGraphWrapperBaseBase< _Graph1, _Graph2, typename boost::enable_if< boost::is_same >::type> : public MergeNodeGraphWrapperBase<_Graph1, _Graph2> { @@ -563,15 +439,11 @@ typedef typename Parent1::Edge Graph1Edge; typedef typename Parent2::Edge Graph2Edge; protected: - MergeEdgeGraphWrapperBase() { } + MergeEdgeGraphWrapperBaseBase() { } public: - template class EdgeMap; - - typedef typename Parent::Node Node; class Edge : public Graph1Edge { - friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>; - template friend class EdgeMap; + friend class MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2>; protected: bool backward; //true, iff backward public: @@ -594,133 +466,12 @@ using Parent::forward; using Parent::backward; - bool forward(const Edge& e) const { return !e.backward; } - bool backward(const Edge& e) const { return e.backward; } - - 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 { - if (!backward(n)) { - Parent1::graph->firstIn(*static_cast(&i), n); - if (*static_cast(&i)==INVALID) - i=INVALID; - else - i.backward=false; - } else { - Parent2::graph->firstIn(*static_cast(&i), n); - i.backward=true; - } - } - void firstOut(Edge& i, const Node& n) const { - if (!backward(n)) { - Parent1::graph->firstOut(*static_cast(&i), n); - if (*static_cast(&i)==INVALID) - i=INVALID; - else - i.backward=false; - } else { - 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) i=INVALID; - } 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) i=INVALID; - } 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 { - protected: - typedef typename Parent::Graph1::template EdgeMap<_Value> ParentMap1; - typedef typename Parent::Graph2::template EdgeMap<_Value> ParentMap2; - ParentMap1 forward_map; - ParentMap2 backward_map; - public: - typedef _Value Value; - typedef Edge Key; - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw) : - forward_map(*(gw.Parent1::graph)), - backward_map(*(gw.Parent2::graph)) { } - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw, - const _Value& value) : - forward_map(*(gw.Parent1::graph), value), - backward_map(*(gw.Parent2::graph), value) { } - _Value operator[](const Edge& n) const { - if (!n.backward) - return forward_map[n]; - else - return backward_map[n]; - } - void set(const Edge& n, const _Value& value) { - if (!n.backward) - forward_map.set(n, value); - else - backward_map.set(n, value); - } -// using ParentMap1::operator[]; -// using ParentMap2::operator[]; - }; - + using Parent::setForward; + using Parent::setBackward; + static bool forward(const Edge& e) { return !e.backward; } + static bool backward(const Edge& e) { return e.backward; } + static void setForward(Edge& e) { e.backward=false; } + static void setBackward(Edge& e) { e.backward=true; } }; @@ -733,7 +484,7 @@ is derived from it. */ template - class MergeEdgeGraphWrapperBase< + class MergeEdgeGraphWrapperBaseBase< _Graph1, _Graph2, typename boost::enable_if< boost::is_base_and_derived >::type> : public MergeNodeGraphWrapperBase<_Graph1, _Graph2> { @@ -749,15 +500,11 @@ typedef typename Parent1::Edge Graph1Edge; typedef typename Parent2::Edge Graph2Edge; protected: - MergeEdgeGraphWrapperBase() { } + MergeEdgeGraphWrapperBaseBase() { } public: - template class EdgeMap; - - typedef typename Parent::Node Node; class Edge : public Graph2Edge { - friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>; - template friend class EdgeMap; + friend class MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2>; protected: bool backward; //true, iff backward public: @@ -786,133 +533,12 @@ using Parent::forward; using Parent::backward; - bool forward(const Edge& e) const { return !e.backward; } - bool backward(const Edge& e) const { return e.backward; } - - 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 { - if (!backward(n)) { - Parent1::graph->firstIn(*static_cast(&i), n); - if (*static_cast(&i)==INVALID) - i=INVALID; - else - i.backward=false; - } else { - Parent2::graph->firstIn(*static_cast(&i), n); - i.backward=true; - } - } - void firstOut(Edge& i, const Node& n) const { - if (!backward(n)) { - Parent1::graph->firstOut(*static_cast(&i), n); - if (*static_cast(&i)==INVALID) - i=INVALID; - else - i.backward=false; - } else { - 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) i=INVALID; - } 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) i=INVALID; - } 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 { - protected: - typedef typename Parent::Graph1::template EdgeMap<_Value> ParentMap1; - typedef typename Parent::Graph2::template EdgeMap<_Value> ParentMap2; - ParentMap1 forward_map; - ParentMap2 backward_map; - public: - typedef _Value Value; - typedef Edge Key; - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw) : - forward_map(*(gw.Parent1::graph)), - backward_map(*(gw.Parent2::graph)) { } - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw, - const _Value& value) : - forward_map(*(gw.Parent1::graph), value), - backward_map(*(gw.Parent2::graph), value) { } - _Value operator[](const Edge& n) const { - if (!n.backward) - return forward_map[n]; - else - return backward_map[n]; - } - void set(const Edge& n, const _Value& value) { - if (!n.backward) - forward_map.set(n, value); - else - backward_map.set(n, value); - } -// using ParentMap1::operator[]; -// using ParentMap2::operator[]; - }; - + using Parent::setForward; + using Parent::setBackward; + static bool forward(const Edge& e) { return !e.backward; } + static bool backward(const Edge& e) { return e.backward; } + static void setForward(Edge& e) { e.backward=false; } + static void setBackward(Edge& e) { e.backward=true; } }; @@ -924,7 +550,7 @@ when _Graph1::Edge is derived from _Graph2::Edge. */ template - class MergeEdgeGraphWrapperBase< + class MergeEdgeGraphWrapperBaseBase< _Graph1, _Graph2, typename boost::enable_if< boost::is_base_and_derived >::type> : public MergeNodeGraphWrapperBase<_Graph1, _Graph2> { @@ -932,7 +558,7 @@ static void printEdge() { std::cout << "edge: 1st is derived" << std::endl; } typedef _Graph1 Graph1; typedef _Graph2 Graph2; - typedef MergeNodeGraphWrapperBase<_Graph1, _Graph2> Parent; + typedef MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2> Parent; typedef typename Parent::Parent1 Parent1; typedef typename Parent::Parent2 Parent2; // typedef P1<_Graph1> Parent1; @@ -940,15 +566,11 @@ typedef typename Parent1::Edge Graph1Edge; typedef typename Parent2::Edge Graph2Edge; protected: - MergeEdgeGraphWrapperBase() { } + MergeEdgeGraphWrapperBaseBase() { } public: - template class EdgeMap; - - typedef typename Parent::Node Node; class Edge : public Graph1Edge { - friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>; - template friend class EdgeMap; + friend class MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2>; protected: bool backward; //true, iff backward public: @@ -977,57 +599,80 @@ using Parent::forward; using Parent::backward; - bool forward(const Edge& e) const { return !e.backward; } - bool backward(const Edge& e) const { return e.backward; } + using Parent::setForward; + using Parent::setBackward; + static bool forward(const Edge& e) { return !e.backward; } + static bool backward(const Edge& e) { return e.backward; } + static void setForward(Edge& e) { e.backward=false; } + static void setBackward(Edge& e) { e.backward=true; } + }; + + + template + class MergeEdgeGraphWrapperBase : + public MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2> { + public: + typedef MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2> Parent; + typedef _Graph1 Graph1; + typedef _Graph2 Graph2; + typedef typename Parent::Parent1 Parent1; + typedef typename Parent::Parent2 Parent2; + typedef typename Parent1::Node Graph1Node; + typedef typename Parent2::Node Graph2Node; + typedef typename Parent1::Edge Graph1Edge; + typedef typename Parent2::Edge Graph2Edge; + + typedef typename Parent::Node Node; + typedef typename Parent::Edge Edge; using Parent::first; void first(Edge& i) const { Parent1::graph->first(*static_cast(&i)); - i.backward=false; + this->setForward(i); if (*static_cast(&i)==INVALID) { Parent2::graph->first(*static_cast(&i)); - i.backward=true; + this->setBackward(i); } } void firstIn(Edge& i, const Node& n) const { - if (!backward(n)) { + if (forward(n)) { Parent1::graph->firstIn(*static_cast(&i), n); if (*static_cast(&i)==INVALID) i=INVALID; else - i.backward=false; + this->setForward(i); } else { Parent2::graph->firstIn(*static_cast(&i), n); - i.backward=true; + this->setBackward(i); } } void firstOut(Edge& i, const Node& n) const { - if (!backward(n)) { + if (forward(n)) { Parent1::graph->firstOut(*static_cast(&i), n); if (*static_cast(&i)==INVALID) i=INVALID; - else - i.backward=false; + else + this->setForward(i); } else { Parent2::graph->firstOut(*static_cast(&i), n); - i.backward=true; + this->setBackward(i); } } using Parent::next; void next(Edge& i) const { - if (!(i.backward)) { + if (forward(i)) { Parent1::graph->next(*static_cast(&i)); if (*static_cast(&i)==INVALID) { Parent2::graph->first(*static_cast(&i)); - i.backward=true; + this->setBackward(i); } } else { Parent2::graph->next(*static_cast(&i)); } } void nextIn(Edge& i) const { - if (!(i.backward)) { + if (forward(i)) { Parent1::graph->nextIn(*static_cast(&i)); if (*static_cast(&i)==INVALID) i=INVALID; } else { @@ -1035,7 +680,7 @@ } } void nextOut(Edge& i) const { - if (!(i.backward)) { + if (Parent::forward(i)) { Parent1::graph->nextOut(*static_cast(&i)); if (*static_cast(&i)==INVALID) i=INVALID; } else { @@ -1044,7 +689,7 @@ } Node source(const Edge& i) const { - if (!(i.backward)) { + if (forward(i)) { return Node(Parent1::graph->source(i), INVALID, false); } else { @@ -1054,7 +699,7 @@ } Node target(const Edge& i) const { - if (!(i.backward)) { + if (forward(i)) { return Node(Parent1::graph->target(i), INVALID, false); } else { @@ -1065,7 +710,7 @@ using Parent::id; int id(const Edge& n) const { - if (!n.backward) + if (forward(n)) return this->Parent1::graph->id(n); else return this->Parent2::graph->id(n); @@ -1089,13 +734,13 @@ forward_map(*(gw.Parent1::graph), value), backward_map(*(gw.Parent2::graph), value) { } _Value operator[](const Edge& n) const { - if (!n.backward) + if (Parent::forward(n)) return forward_map[n]; else return backward_map[n]; } void set(const Edge& n, const _Value& value) { - if (!n.backward) + if (Parent::forward(n)) forward_map.set(n, value); else backward_map.set(n, value); @@ -1107,11 +752,24 @@ }; + /*! A graph wrapper class - for merging the node-sets and edge-sets of - two node-disjoint graphs - into one graph. - */ + for merging two node-disjoint graphs + into one graph. + Different implementations are according to the relation of + _Graph1::Edge and _Graph2::Edge. + If _Graph1::Edge and _Graph2::Edge are unrelated, then + MergeEdgeGraphWrapper<_Graph1, _Graph2>::Edge + is derived from both. + If _Graph1::Edge and _Graph2::Edge are the same type, then + MergeEdgeGraphWrapper<_Graph1, _Graph2>::Edge + is derived from _Graph1::Edge. + If one of _Graph1::Edge and _Graph2::Edge + is derived from the other one, then + MergeEdgeGraphWrapper<_Graph1, _Graph2>::Edge + is derived from the derived type. + It does not satisfy + */ template class MergeEdgeGraphWrapper : public IterableGraphExtender > {