Changeset 917:ffb8f0cbcb57 in lemon0.x
 Timestamp:
 09/28/04 19:00:18 (17 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1228
 Location:
 src/work/marci
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/marci/merge_node_graph_wrapper.h
r915 r917 1 1 /* * C++ * 2 * src/hugo/ graph_wrapper.h  Part of HUGOlib, a generic C++ optimization library2 * src/hugo/merge_node_graph_wrapper.h  Part of HUGOlib, a generic C++ optimization library 3 3 * 4 4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport … … 15 15 */ 16 16 17 #ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H 18 #define HUGO_MERGE_NODE_GRAPH_WRAPPER_H 19 17 20 #include <hugo/invalid.h> 18 21 #include <hugo/maps.h> … … 21 24 #include <iostream> 22 25 23 #ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H24 #define HUGO_MERGE_NODE_GRAPH_WRAPPER_H25 26 26 namespace hugo { 27 27 28 template <typename Graph1, typename Graph2 >28 template <typename Graph1, typename Graph2, typename Enable=void> 29 29 class MergeNodeGraphWrapper : 30 30 public GraphWrapper<Graph1>, public GraphWrapper<Graph2> { … … 38 38 friend class Node; 39 39 friend class NodeIt; 40 template<typename Value> class NodeMap; 40 41 41 42 MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) : … … 44 45 class Node : public Graph1Node, public Graph2Node { 45 46 friend class MergeNodeGraphWrapper<Graph1, Graph2>; 46 //template<typename T> friend class NodeMap;47 template<typename Value> friend class NodeMap; 47 48 protected: 48 49 bool backward; //true, iff backward … … 81 82 NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw) : 82 83 Node(typename Graph1::NodeIt(*_gw.Parent1::graph), 83 typename Graph2::Node It(),84 typename Graph2::Node(), 84 85 false), gw(&_gw) { 85 86 if (*static_cast<Graph1Node*>(this)==INVALID) { 86 *static_cast<Node*>(this)= 87 Node(Graph1Node(INVALID), 88 typename Graph2::NodeIt(*_gw.Parent2::graph), 89 true); 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; 90 94 } 91 95 } … … 98 102 ++(typename Graph1::NodeIt(*gw>Parent1::graph, *this)); 99 103 if (*static_cast<Graph1Node*>(this)==INVALID) { 100 *static_cast<Node*>(this)= 101 Node(typename Graph1::Node(INVALID), 102 typename Graph2::NodeIt(*gw>Parent2::graph), true); 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; 103 110 } 104 111 } else { … … 117 124 } 118 125 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; 131 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 ParentMap2(gw, value) { } 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 { 158 if (!n.backward) 159 return ParentMap1::operator[](n); 160 else 161 return ParentMap2::operator[](n); 162 } 163 void set(const Node& n, const Value& value) { 164 if (!n.backward) 165 ParentMap1::set(n, value); 166 else 167 ParentMap2::set(n, value); 168 } 169 using ParentMap1::operator[]; 170 using ParentMap2::operator[]; 171 }; 172 119 173 }; 120 174 
src/work/marci/merge_node_graph_wrapper_test.cc
r915 r917 11 11 12 12 int main() { 13 SmartGraph g; 14 ListGraph h; 15 typedef MergeNodeGraphWrapper<SmartGraph, ListGraph> GW; 13 typedef SmartGraph Graph1; 14 typedef ListGraph Graph2; 15 Graph1 g; 16 Graph2 h; 17 typedef MergeNodeGraphWrapper<Graph1, Graph2> GW; 16 18 GW gw(g, h); 17 g.addNode();18 g.addNode();19 g.addNode();20 h.addNode();21 h.addNode();19 Graph1::Node n1=g.addNode(); 20 Graph1::Node n2=g.addNode(); 21 Graph1::Node n3=g.addNode(); 22 Graph2::Node n4=h.addNode(); 23 Graph2::Node n5=h.addNode(); 22 24 //GW::NodeIt n(gw) 23 25 for (GW::NodeIt n(gw); n!=INVALID; ++n) { 24 26 cout << gw.id(n) << endl; 25 27 } 28 29 GW::NodeMap<int> nm(gw); 30 int i=0; 31 for (GW::NodeIt n(gw); n!=INVALID; ++n) { 32 ++i; 33 nm.set(n, i); 34 } 35 for (Graph1::NodeIt n(g); n!=INVALID; ++n) { 36 cout << nm[n] << endl; 37 } 38 for (Graph2::NodeIt n(h); n!=INVALID; ++n) { 39 cout << nm[n] << endl; 40 } 26 41 }
Note: See TracChangeset
for help on using the changeset viewer.