src/work/marci/merge_node_graph_wrapper.h
changeset 1008 3fef334f5f37
parent 1007 a7d5fe18d8f9
child 1009 8cb323dbae93
equal deleted inserted replaced
4:e69db6f916a6 5:676a7aa3bc13
    20 #include <lemon/invalid.h>
    20 #include <lemon/invalid.h>
    21 #include <lemon/maps.h>
    21 #include <lemon/maps.h>
    22 #include <lemon/map_defines.h>
    22 #include <lemon/map_defines.h>
    23 #include <lemon/graph_wrapper.h>
    23 #include <lemon/graph_wrapper.h>
    24 #include <iostream>
    24 #include <iostream>
       
    25 using std::cout;
       
    26 using std::endl;
    25 
    27 
    26 #include <boost/type_traits.hpp>
    28 #include <boost/type_traits.hpp>
    27 #include <boost/utility/enable_if.hpp>
    29 #include <boost/utility/enable_if.hpp>
    28 
    30 
    29 namespace lemon {
    31 namespace lemon {
   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);
   159       using ParentMap2::operator[];
   143       using ParentMap2::operator[];
   160     };
   144     };
   161 
   145 
   162   };
   146   };
   163 
   147 
       
   148   //not yet working
   164   template <typename _Graph1, typename _Graph2>
   149   template <typename _Graph1, typename _Graph2>
   165   class MergeNodeGraphWrapperBase<
   150   class MergeNodeGraphWrapperBase<
   166     _Graph1, _Graph2, typename boost::enable_if<
   151     _Graph1, _Graph2, typename boost::enable_if<
   167     boost::is_same<typename _Graph1::Node, typename _Graph2::Node> >::type> : 
   152     boost::is_same<typename _Graph1::Node, typename _Graph2::Node> >::type> : 
   168     public P1<_Graph1>, public P2<_Graph2> {
   153     public P1<_Graph1>, public P2<_Graph2> {
   181     class Edge { };
   166     class Edge { };
   182     void first() const;
   167     void first() const;
   183     void next() const;
   168     void next() const;
   184   };
   169   };
   185 
   170 
       
   171   //not yet working
   186   template <typename _Graph1, typename _Graph2>
   172   template <typename _Graph1, typename _Graph2>
   187   class MergeNodeGraphWrapperBase<
   173   class MergeNodeGraphWrapperBase<
   188     _Graph1, _Graph2, typename boost::enable_if<
   174     _Graph1, _Graph2, typename boost::enable_if<
   189     boost::is_base_and_derived<typename _Graph1::Node, typename _Graph2::Node> >::type> : 
   175     boost::is_base_and_derived<typename _Graph1::Node, typename _Graph2::Node> >::type> : 
   190     public P1<_Graph1>, public P2<_Graph2> {
   176     public P1<_Graph1>, public P2<_Graph2> {
   203     class Edge { };
   189     class Edge { };
   204     void first() const;
   190     void first() const;
   205     void next() const;
   191     void next() const;
   206   };
   192   };
   207 
   193 
       
   194   //not yet working
   208   template <typename _Graph1, typename _Graph2>
   195   template <typename _Graph1, typename _Graph2>
   209   class MergeNodeGraphWrapperBase<
   196   class MergeNodeGraphWrapperBase<
   210     _Graph1, _Graph2, typename boost::enable_if<
   197     _Graph1, _Graph2, typename boost::enable_if<
   211     boost::is_base_and_derived<typename _Graph2::Node, typename _Graph1::Node> >::type> : 
   198     boost::is_base_and_derived<typename _Graph2::Node, typename _Graph1::Node> >::type> : 
   212     public P1<_Graph1>, public P2<_Graph2> {
   199     public P1<_Graph1>, public P2<_Graph2> {
   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