Changeset 1002:ea3ecb3c9846 in lemon-0.x
- Timestamp:
- 11/17/04 20:37:54 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1392
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/marci/merge_node_graph_wrapper.h
r921 r1002 26 26 namespace lemon { 27 27 28 template <typename Graph1, typename Graph2, typename Enable=void> 29 class MergeNodeGraphWrapper : 30 public GraphWrapper<Graph1>, public GraphWrapper<Graph2> { 31 typedef GraphWrapper<Graph1> Parent1; 32 typedef GraphWrapper<Graph2> Parent2; 33 typedef typename GraphWrapper<Graph1>::Node Graph1Node; 34 typedef typename GraphWrapper<Graph2>::Node Graph2Node; 28 template <typename _Graph1, typename _Graph2, typename Enable=void> 29 class MergeNodeGraphWrapperBase : 30 public GraphWrapperBase<_Graph1>, public GraphWrapperBase<_Graph2> { 35 31 public: 36 class Node; 37 class NodeIt; 38 friend class Node; 39 friend class NodeIt; 40 template<typename Value> class NodeMap; 41 42 MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) : 43 Parent1(_graph1), Parent2(_graph2) { } 32 typedef _Graph1 Graph1; 33 typedef _Graph2 Graph2; 34 typedef GraphWrapperBase<_Graph1> Parent1; 35 typedef GraphWrapperBase<_Graph2> Parent2; 36 typedef typename Parent1::Node Graph1Node; 37 typedef typename Parent2::Node Graph2Node; 38 protected: 39 MergeNodeGraphWrapperBase() { } 40 public: 41 template <typename _Value> class NodeMap; 44 42 45 43 class Node : public Graph1Node, public Graph2Node { 46 friend class MergeNodeGraphWrapper <Graph1,Graph2>;47 template <typename Value> friend class NodeMap;44 friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>; 45 template <typename Value> friend class NodeMap; 48 46 protected: 49 47 bool backward; //true, iff backward … … 73 71 }; 74 72 75 class NodeIt : public Node { 76 friend class MergeNodeGraphWrapper<Graph1, Graph2>; 77 protected: 78 const MergeNodeGraphWrapper<Graph1, Graph2>* gw; 79 public: 80 NodeIt() { } 81 NodeIt(Invalid i) : Node(i) { } 82 NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw) : 83 Node(typename Graph1::NodeIt(*_gw.Parent1::graph), 84 typename Graph2::Node(), 85 false), gw(&_gw) { 86 if (*static_cast<Graph1Node*>(this)==INVALID) { 87 // *static_cast<Node*>(this)= 88 // Node(Graph1Node(INVALID), 89 // typename Graph2::NodeIt(*_gw.Parent2::graph), 90 // true); 91 *static_cast<Graph2Node*>(this)= 92 typename Graph2::NodeIt(*_gw.Parent2::graph); 93 backward=true; 73 //typedef void Edge; 74 class Edge { }; 75 76 void first(Node& i) const { 77 Parent1::graph->first(*static_cast<Graph1Node*>(&i)); 78 i.backward=false; 79 if (*static_cast<Graph1Node*>(&i)==INVALID) { 80 Parent2::graph->first(*static_cast<Graph2Node*>(&i)); 81 i.backward=true; 82 } 83 } 84 void next(Node& i) const { 85 if (!(i.backward)) { 86 Parent1::graph->next(*static_cast<Graph1Node*>(&i)); 87 if (*static_cast<Graph1Node*>(&i)==INVALID) { 88 Parent2::graph->first(*static_cast<Graph2Node*>(&i)); 89 i.backward=true; 94 90 } 91 } else { 92 Parent2::graph->next(*static_cast<Graph2Node*>(&i)); 95 93 } 96 NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw, 97 const Node& n) : 98 Node(n), gw(&_gw) { } 99 NodeIt& operator++() { 100 if (!this->backward) { 101 *(static_cast<Graph1Node*>(this))= 102 ++(typename Graph1::NodeIt(*gw->Parent1::graph, *this)); 103 if (*static_cast<Graph1Node*>(this)==INVALID) { 104 // *static_cast<Node*>(this)= 105 // Node(typename Graph1::Node(INVALID), 106 // typename Graph2::NodeIt(*gw->Parent2::graph), true); 107 *static_cast<Graph2Node*>(this)= 108 typename Graph2::NodeIt(*gw->Parent2::graph); 109 backward=true; 110 } 111 } else { 112 *(static_cast<Graph2Node*>(this))= 113 ++(typename Graph2::NodeIt(*gw->Parent2::graph, *this)); 114 } 115 return *this; 116 } 117 }; 94 } 118 95 119 96 int id(const Node& n) const { … … 124 101 } 125 102 126 template <typename Value>127 class NodeMap : public Parent1::template NodeMap< Value>,128 public Parent2::template NodeMap< Value> {129 typedef typename Parent1::template NodeMap< Value> ParentMap1;130 typedef typename Parent2::template NodeMap< Value> ParentMap2;103 template <typename _Value> 104 class NodeMap : public Parent1::template NodeMap<_Value>, 105 public Parent2::template NodeMap<_Value> { 106 typedef typename Parent1::template NodeMap<_Value> ParentMap1; 107 typedef typename Parent2::template NodeMap<_Value> ParentMap2; 131 108 public: 132 NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw) :133 ParentMap1(gw), 134 ParentMap2(gw) { } 135 NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw, 136 const Value& value) 137 : ParentMap1(gw, value),138 139 NodeMap(const NodeMap& copy)140 : ParentMap1(copy),141 ParentMap2(copy) { }142 template <typename TT>143 NodeMap(const NodeMap<TT>& copy)144 : ParentMap1(copy),145 ParentMap2(copy) { }146 NodeMap& operator=(const NodeMap& copy) {147 ParentMap1::operator=(copy);148 ParentMap2::operator=(copy);149 return *this;150 }151 template <typename TT>152 NodeMap& operator=(const NodeMap<TT>& copy) {153 ParentMap1::operator=(copy);154 ParentMap2::operator=(copy);155 return *this;156 }157 Value operator[](const Node& n) const {109 typedef _Value Value; 110 typedef Node Key; 111 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : 112 ParentMap1(gw), ParentMap2(gw) { } 113 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, 114 const _Value& value) : 115 ParentMap1(gw, value), ParentMap2(gw, value) { } 116 // NodeMap(const NodeMap& copy) 117 // : ParentMap1(copy), 118 // ParentMap2(copy) { } 119 // template <typename TT> 120 // NodeMap(const NodeMap<TT>& copy) 121 // : ParentMap1(copy), 122 // ParentMap2(copy) { } 123 // NodeMap& operator=(const NodeMap& copy) { 124 // ParentMap1::operator=(copy); 125 // ParentMap2::operator=(copy); 126 // return *this; 127 // } 128 // template <typename TT> 129 // NodeMap& operator=(const NodeMap<TT>& copy) { 130 // ParentMap1::operator=(copy); 131 // ParentMap2::operator=(copy); 132 // return *this; 133 // } 134 _Value operator[](const Node& n) const { 158 135 if (!n.backward) 159 136 return ParentMap1::operator[](n); … … 161 138 return ParentMap2::operator[](n); 162 139 } 163 void set(const Node& n, const Value& value) {140 void set(const Node& n, const _Value& value) { 164 141 if (!n.backward) 165 142 ParentMap1::set(n, value); … … 170 147 using ParentMap2::operator[]; 171 148 }; 172 149 150 }; 151 152 153 template <typename _Graph1, typename _Graph2, typename Enable=void> 154 class MergeNodeGraphWrapper : public 155 IterableGraphExtender<MergeNodeGraphWrapperBase<_Graph1, _Graph2, Enable> > { 156 public: 157 typedef _Graph1 Graph1; 158 typedef _Graph2 Graph2; 159 typedef IterableGraphExtender< 160 MergeNodeGraphWrapperBase<_Graph1, _Graph2, Enable> > Parent; 161 protected: 162 MergeNodeGraphWrapper() { } 163 public: 164 MergeNodeGraphWrapper(_Graph1& _graph1, _Graph2& _graph2) { 165 Parent::Parent1::setGraph(_graph1); 166 Parent::Parent2::setGraph(_graph2); 167 } 173 168 }; 174 169
Note: See TracChangeset
for help on using the changeset viewer.