123 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : |
125 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : |
124 ParentMap1(gw), ParentMap2(gw) { } |
126 ParentMap1(gw), ParentMap2(gw) { } |
125 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, |
127 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, |
126 const _Value& value) : |
128 const _Value& value) : |
127 ParentMap1(gw, value), ParentMap2(gw, value) { } |
129 ParentMap1(gw, value), ParentMap2(gw, value) { } |
128 // NodeMap(const NodeMap& copy) |
|
129 // : ParentMap1(copy), |
|
130 // ParentMap2(copy) { } |
|
131 // template <typename TT> |
|
132 // NodeMap(const NodeMap<TT>& copy) |
|
133 // : ParentMap1(copy), |
|
134 // ParentMap2(copy) { } |
|
135 // NodeMap& operator=(const NodeMap& copy) { |
|
136 // ParentMap1::operator=(copy); |
|
137 // ParentMap2::operator=(copy); |
|
138 // return *this; |
|
139 // } |
|
140 // template <typename TT> |
|
141 // NodeMap& operator=(const NodeMap<TT>& copy) { |
|
142 // ParentMap1::operator=(copy); |
|
143 // ParentMap2::operator=(copy); |
|
144 // return *this; |
|
145 // } |
|
146 _Value operator[](const Node& n) const { |
130 _Value operator[](const Node& n) const { |
147 if (!n.backward) |
131 if (!n.backward) |
148 return ParentMap1::operator[](n); |
132 return ParentMap1::operator[](n); |
149 else |
133 else |
150 return ParentMap2::operator[](n); |
134 return ParentMap2::operator[](n); |
243 Parent::Parent1::setGraph(_graph1); |
230 Parent::Parent1::setGraph(_graph1); |
244 Parent::Parent2::setGraph(_graph2); |
231 Parent::Parent2::setGraph(_graph2); |
245 } |
232 } |
246 }; |
233 }; |
247 |
234 |
|
235 |
|
236 template <typename _Graph, typename _EdgeSetGraph> |
|
237 class NewEdgeSetGraphWrapperBase : public GraphWrapperBase<_Graph> { |
|
238 public: |
|
239 typedef GraphWrapperBase<_Graph> Parent; |
|
240 typedef _Graph Graph; |
|
241 typedef _EdgeSetGraph EdgeSetGraph; |
|
242 typedef typename _Graph::Node Node; |
|
243 typedef typename _EdgeSetGraph::Node ENode; |
|
244 protected: |
|
245 EdgeSetGraph* edge_set_graph; |
|
246 typename Graph::NodeMap<ENode>* e_node; |
|
247 typename EdgeSetGraph::NodeMap<Node>* n_node; |
|
248 void setEdgeSetGraph(EdgeSetGraph& _edge_set_graph) { |
|
249 edge_set_graph=&_edge_set_graph; |
|
250 } |
|
251 /// For each node of \c Graph, this gives a node of \c EdgeSetGraph . |
|
252 void setNodeMap(typename EdgeSetGraph::NodeMap<Node>& _n_node) { |
|
253 n_node=&_n_node; |
|
254 } |
|
255 /// For each node of \c EdgeSetGraph, this gives a node of \c Graph . |
|
256 void setENodeMap(typename Graph::NodeMap<ENode>& _e_node) { |
|
257 e_node=&_e_node; |
|
258 } |
|
259 public: |
|
260 class Edge : public EdgeSetGraph::Edge { |
|
261 typedef typename EdgeSetGraph::Edge Parent; |
|
262 public: |
|
263 Edge() { } |
|
264 Edge(const Parent& e) : Parent(e) { } |
|
265 Edge(Invalid i) : Parent(i) { } |
|
266 }; |
|
267 |
|
268 using Parent::first; |
|
269 void first(Edge &e) const { |
|
270 edge_set_graph->first(e); |
|
271 } |
|
272 void firstOut(Edge& e, const Node& n) const { |
|
273 // cout << e_node << endl; |
|
274 // cout << n_node << endl; |
|
275 edge_set_graph->firstOut(e, (*e_node)[n]); |
|
276 } |
|
277 void firstIn(Edge& e, const Node& n) const { |
|
278 edge_set_graph->firstIn(e, (*e_node)[n]); |
|
279 } |
|
280 |
|
281 using Parent::next; |
|
282 void next(Edge &e) const { |
|
283 edge_set_graph->next(e); |
|
284 } |
|
285 void nextOut(Edge& e) const { |
|
286 edge_set_graph->nextOut(e); |
|
287 } |
|
288 void nextIn(Edge& e) const { |
|
289 edge_set_graph->nextIn(e); |
|
290 } |
|
291 |
|
292 Node source(const Edge& e) const { |
|
293 return (*n_node)[edge_set_graph->source(e)]; |
|
294 } |
|
295 Node target(const Edge& e) const { |
|
296 return (*n_node)[edge_set_graph->target(e)]; |
|
297 } |
|
298 |
|
299 int edgeNum() const { return edge_set_graph->edgeNum(); } |
|
300 |
|
301 Edge addEdge(const Node& u, const Node& v) { |
|
302 return edge_set_graph->addEdge((*e_node)[u], (*e_node)[v]); |
|
303 } |
|
304 |
|
305 using Parent::erase; |
|
306 void erase(const Edge& i) const { edge_set_graph->erase(i); } |
|
307 |
|
308 void clear() const { Parent::clear(); edge_set_graph->clear(); } |
|
309 |
|
310 bool forward(const Edge& e) const { return edge_set_graph->forward(e); } |
|
311 bool backward(const Edge& e) const { return edge_set_graph->backward(e); } |
|
312 |
|
313 using Parent::id; |
|
314 int id(const Edge& e) const { return edge_set_graph->id(e); } |
|
315 |
|
316 Edge opposite(const Edge& e) const { return edge_set_graph->opposite(e); } |
|
317 |
|
318 template <typename _Value> |
|
319 class EdgeMap : public EdgeSetGraph::EdgeMap<_Value> { |
|
320 public: |
|
321 typedef typename EdgeSetGraph::EdgeMap<_Value> Parent; |
|
322 typedef _Value Value; |
|
323 typedef Edge Key; |
|
324 EdgeMap(const NewEdgeSetGraphWrapperBase& gw) : |
|
325 Parent(*(gw.edge_set_graph)) { } |
|
326 EdgeMap(const NewEdgeSetGraphWrapperBase& gw, const _Value& _value) : |
|
327 Parent(*(gw.edge_set_graph), _value) { } |
|
328 }; |
|
329 |
|
330 }; |
|
331 |
|
332 template <typename _Graph, typename _EdgeSetGraph> |
|
333 class NewEdgeSetGraphWrapper : |
|
334 public IterableGraphExtender< |
|
335 NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > { |
|
336 public: |
|
337 typedef _Graph Graph; |
|
338 typedef _EdgeSetGraph EdgeSetGraph; |
|
339 typedef IterableGraphExtender< |
|
340 NewEdgeSetGraphWrapper<_Graph, _EdgeSetGraph> > Parent; |
|
341 protected: |
|
342 NewEdgeSetGraphWrapper() { } |
|
343 public: |
|
344 NewEdgeSetGraphWrapper(_Graph& _graph, |
|
345 _EdgeSetGraph& _edge_set_graph, |
|
346 typename _Graph:: |
|
347 NodeMap<typename _EdgeSetGraph::Node>& _e_node, |
|
348 typename _EdgeSetGraph:: |
|
349 NodeMap<typename _Graph::Node>& _n_node) { |
|
350 setGraph(_graph); |
|
351 setEdgeSetGraph(_edge_set_graph); |
|
352 setNodeMap(_n_node); |
|
353 setENodeMap(_e_node); |
|
354 } |
|
355 }; |
|
356 |
248 } //namespace lemon |
357 } //namespace lemon |
249 |
358 |
250 #endif //LEMON_MERGE_NODE_GRAPH_WRAPPER_H |
359 #endif //LEMON_MERGE_NODE_GRAPH_WRAPPER_H |