Changeset 970:09f9abe22df2 in lemon0.x for src/lemon/graph_wrapper.h
 Timestamp:
 11/08/04 17:33:53 (17 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1357
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/lemon/graph_wrapper.h
r933 r970 109 109 /// 110 110 ///\author Marton Makai 111 template<typename Graph> 112 class GraphWrapper { 111 template<typename _Graph> 112 class GraphWrapperBase { 113 public: 114 typedef _Graph Graph; 115 /// \todo Is it needed? 116 typedef Graph BaseGraph; 117 typedef Graph ParentGraph; 118 113 119 protected: 114 120 Graph* graph; 115 GraphWrapper () : graph(0) { }121 GraphWrapperBase() : graph(0) { } 116 122 void setGraph(Graph& _graph) { graph=&_graph; } 117 123 118 124 public: 119 typedef Graph BaseGraph; 120 typedef Graph ParentGraph; 121 122 GraphWrapper(Graph& _graph) : graph(&_graph) { } 123 GraphWrapper(const GraphWrapper<Graph>& gw) : graph(gw.graph) { } 125 GraphWrapperBase(Graph& _graph) : graph(&_graph) { } 126 GraphWrapperBase(const GraphWrapperBase<_Graph>& gw) : graph(gw.graph) { } 124 127 125 128 typedef typename Graph::Node Node; 126 class NodeIt : public Node {127 const GraphWrapper<Graph>* gw;128 friend class GraphWrapper<Graph>;129 public:130 NodeIt() { }131 NodeIt(Invalid i) : Node(i) { }132 NodeIt(const GraphWrapper<Graph>& _gw) :133 Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) { }134 NodeIt(const GraphWrapper<Graph>& _gw, const Node& n) :135 Node(n), gw(&_gw) { }136 NodeIt& operator++() {137 *(static_cast<Node*>(this))=138 ++(typename Graph::NodeIt(*(gw>graph), *this));139 return *this;140 }141 };142 129 typedef typename Graph::Edge Edge; 143 class OutEdgeIt : public Edge {144 const GraphWrapper<Graph>* gw;145 friend class GraphWrapper<Graph>;146 public:147 OutEdgeIt() { }148 OutEdgeIt(Invalid i) : Edge(i) { }149 OutEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) :150 Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }151 OutEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) :152 Edge(e), gw(&_gw) { }153 OutEdgeIt& operator++() {154 *(static_cast<Edge*>(this))=155 ++(typename Graph::OutEdgeIt(*(gw>graph), *this));156 return *this;157 }158 };159 class InEdgeIt : public Edge {160 const GraphWrapper<Graph>* gw;161 friend class GraphWrapper<Graph>;162 public:163 InEdgeIt() { }164 InEdgeIt(Invalid i) : Edge(i) { }165 InEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) :166 Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }167 InEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) :168 Edge(e), gw(&_gw) { }169 InEdgeIt& operator++() {170 *(static_cast<Edge*>(this))=171 ++(typename Graph::InEdgeIt(*(gw>graph), *this));172 return *this;173 }174 };175 class EdgeIt : public Edge {176 const GraphWrapper<Graph>* gw;177 friend class GraphWrapper<Graph>;178 public:179 EdgeIt() { }180 EdgeIt(Invalid i) : Edge(i) { }181 EdgeIt(const GraphWrapper<Graph>& _gw) :182 Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { }183 EdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) :184 Edge(e), gw(&_gw) { }185 EdgeIt& operator++() {186 *(static_cast<Edge*>(this))=187 ++(typename Graph::EdgeIt(*(gw>graph), *this));188 return *this;189 }190 };191 130 192 NodeIt& first(NodeIt& i) const { 193 i=NodeIt(*this); return i; 194 } 195 OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 196 i=OutEdgeIt(*this, p); return i; 197 } 198 InEdgeIt& first(InEdgeIt& i, const Node& p) const { 199 i=InEdgeIt(*this, p); return i; 200 } 201 EdgeIt& first(EdgeIt& i) const { 202 i=EdgeIt(*this); return i; 203 } 204 205 Node tail(const Edge& e) const { 206 return Node(graph>tail(static_cast<typename Graph::Edge>(e))); } 207 Node head(const Edge& e) const { 208 return Node(graph>head(static_cast<typename Graph::Edge>(e))); } 131 void first(Node& i) const { graph>first(i); } 132 void first(Edge& i) const { graph>first(i); } 133 void firstIn(Edge& i, const Node& n) const { graph>firstIn(i, n); } 134 void firstOut(Edge& i, const Node& n ) const { graph>firstOut(i, n); } 135 // NodeIt& first(NodeIt& i) const { 136 // i=NodeIt(*this); return i; 137 // } 138 // OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 139 // i=OutEdgeIt(*this, p); return i; 140 // } 141 // InEdgeIt& first(InEdgeIt& i, const Node& p) const { 142 // i=InEdgeIt(*this, p); return i; 143 // } 144 // EdgeIt& first(EdgeIt& i) const { 145 // i=EdgeIt(*this); return i; 146 // } 147 148 void next(Node& i) const { graph>next(i); } 149 void next(Edge& i) const { graph>next(i); } 150 void nextIn(Edge& i) const { graph>nextIn(i); } 151 void nextOut(Edge& i) const { graph>nextOut(i); } 152 153 Node tail(const Edge& e) const { return graph>tail(e); } 154 Node head(const Edge& e) const { return graph>head(e); } 155 // Node tail(const Edge& e) const { 156 // return Node(graph>tail(static_cast<typename Graph::Edge>(e))); } 157 // Node head(const Edge& e) const { 158 // return Node(graph>head(static_cast<typename Graph::Edge>(e))); } 209 159 210 160 int nodeNum() const { return graph>nodeNum(); } … … 228 178 Edge opposite(const Edge& e) const { return Edge(graph>opposite(e)); } 229 179 230 231 IMPORT_NODE_MAP(Graph, *(gw.graph), GraphWrapper, gw); 232 IMPORT_EDGE_MAP(Graph, *(gw.graph), GraphWrapper, gw); 233 180 template <typename _Value> 181 class NodeMap : public _Graph::template NodeMap<_Value> { 182 public: 183 typedef typename _Graph::template NodeMap<_Value> Parent; 184 NodeMap(const GraphWrapperBase<_Graph>& gw) : Parent(*gw.graph) { } 185 NodeMap(const GraphWrapperBase<_Graph>& gw, const _Value& value) 186 : Parent(*gw.graph, value) { } 187 }; 188 189 template <typename _Value> 190 class EdgeMap : public _Graph::template EdgeMap<_Value> { 191 public: 192 typedef typename _Graph::template EdgeMap<_Value> Parent; 193 EdgeMap(const GraphWrapperBase<_Graph>& gw) : Parent(*gw.graph) { } 194 EdgeMap(const GraphWrapperBase<_Graph>& gw, const _Value& value) 195 : Parent(*gw.graph, value) { } 196 }; 234 197 235 198 }; 236 199 237 200 template <typename _Graph> 201 class GraphWrapper : 202 public IterableGraphExtender<GraphWrapperBase<_Graph> > { 203 public: 204 typedef _Graph Graph; 205 typedef IterableGraphExtender<GraphWrapperBase<_Graph> > Parent; 206 protected: 207 GraphWrapper() : Parent() { } 208 209 public: 210 GraphWrapper(Graph& _graph) { setGraph(_graph); } 211 }; 238 212 239 213 /// A graph wrapper which reverses the orientation of the edges. … … 1104 1078 }; 1105 1079 1106 using GraphWrapper<Graph>::first;1107 OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {1108 i=OutEdgeIt(*this, p); return i;1109 }1110 InEdgeIt& first(InEdgeIt& i, const Node& p) const {1111 i=InEdgeIt(*this, p); return i;1112 }1113 EdgeIt& first(EdgeIt& i) const {1114 i=EdgeIt(*this); return i;1115 }1080 // using GraphWrapper<Graph>::first; 1081 // OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 1082 // i=OutEdgeIt(*this, p); return i; 1083 // } 1084 // InEdgeIt& first(InEdgeIt& i, const Node& p) const { 1085 // i=InEdgeIt(*this, p); return i; 1086 // } 1087 // EdgeIt& first(EdgeIt& i) const { 1088 // i=EdgeIt(*this); return i; 1089 // } 1116 1090 1117 1091 … … 1435 1409 }; 1436 1410 1437 using GraphWrapper<Graph>::first;1438 OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {1439 i=OutEdgeIt(*this, p); return i;1440 }1411 // using GraphWrapper<Graph>::first; 1412 // OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 1413 // i=OutEdgeIt(*this, p); return i; 1414 // } 1441 1415 void erase(const Edge& e) const { 1442 1416 Node n=tail(e);
Note: See TracChangeset
for help on using the changeset viewer.