MergeNodeGraphWrapper with factory
authormarci
Wed, 17 Nov 2004 19:37:54 +0000
changeset 1002ea3ecb3c9846
parent 1001 afe5cf34aa50
child 1003 ac4f15d1191a
MergeNodeGraphWrapper with factory
src/work/marci/merge_node_graph_wrapper.h
     1.1 --- a/src/work/marci/merge_node_graph_wrapper.h	Wed Nov 17 17:13:15 2004 +0000
     1.2 +++ b/src/work/marci/merge_node_graph_wrapper.h	Wed Nov 17 19:37:54 2004 +0000
     1.3 @@ -25,26 +25,24 @@
     1.4  
     1.5  namespace lemon {
     1.6  
     1.7 -  template <typename Graph1, typename Graph2, typename Enable=void> 
     1.8 -  class MergeNodeGraphWrapper : 
     1.9 -    public GraphWrapper<Graph1>, public GraphWrapper<Graph2> {
    1.10 -    typedef GraphWrapper<Graph1> Parent1;
    1.11 -    typedef GraphWrapper<Graph2> Parent2;
    1.12 -    typedef typename GraphWrapper<Graph1>::Node Graph1Node;
    1.13 -    typedef typename GraphWrapper<Graph2>::Node Graph2Node;
    1.14 +  template <typename _Graph1, typename _Graph2, typename Enable=void>
    1.15 +  class MergeNodeGraphWrapperBase : 
    1.16 +    public GraphWrapperBase<_Graph1>, public GraphWrapperBase<_Graph2> {
    1.17    public:
    1.18 -    class Node;
    1.19 -    class NodeIt;
    1.20 -    friend class Node;
    1.21 -    friend class NodeIt;
    1.22 -    template<typename Value> class NodeMap;
    1.23 -
    1.24 -    MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) : 
    1.25 -      Parent1(_graph1), Parent2(_graph2) { }
    1.26 +    typedef _Graph1 Graph1;
    1.27 +    typedef _Graph2 Graph2;
    1.28 +    typedef GraphWrapperBase<_Graph1> Parent1;
    1.29 +    typedef GraphWrapperBase<_Graph2> Parent2;
    1.30 +    typedef typename Parent1::Node Graph1Node;
    1.31 +    typedef typename Parent2::Node Graph2Node;
    1.32 +  protected:
    1.33 +    MergeNodeGraphWrapperBase() { }
    1.34 +  public:
    1.35 +    template <typename _Value> class NodeMap;
    1.36  
    1.37      class Node : public Graph1Node, public Graph2Node {
    1.38 -      friend class MergeNodeGraphWrapper<Graph1, Graph2>;
    1.39 -      template<typename Value> friend class NodeMap;
    1.40 +      friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>;
    1.41 +      template <typename Value> friend class NodeMap;
    1.42      protected:
    1.43        bool backward; //true, iff backward
    1.44      public:
    1.45 @@ -72,49 +70,28 @@
    1.46        }
    1.47      };
    1.48  
    1.49 -    class NodeIt : public Node {
    1.50 -      friend class MergeNodeGraphWrapper<Graph1, Graph2>;
    1.51 -    protected:
    1.52 -      const MergeNodeGraphWrapper<Graph1, Graph2>* gw;
    1.53 -    public:
    1.54 -      NodeIt() { }
    1.55 -      NodeIt(Invalid i) : Node(i) { }
    1.56 -      NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw) : 
    1.57 -	Node(typename Graph1::NodeIt(*_gw.Parent1::graph), 
    1.58 -	     typename Graph2::Node(),
    1.59 -	     false), gw(&_gw) { 
    1.60 -	if (*static_cast<Graph1Node*>(this)==INVALID) {
    1.61 -// 	  *static_cast<Node*>(this)=
    1.62 -// 	    Node(Graph1Node(INVALID), 
    1.63 -// 		 typename Graph2::NodeIt(*_gw.Parent2::graph), 
    1.64 -// 		 true);
    1.65 -	  *static_cast<Graph2Node*>(this)=
    1.66 -	    typename Graph2::NodeIt(*_gw.Parent2::graph);
    1.67 -	  backward=true;
    1.68 +    //typedef void Edge;
    1.69 +    class Edge { };
    1.70 +    
    1.71 +    void first(Node& i) const {
    1.72 +      Parent1::graph->first(*static_cast<Graph1Node*>(&i));
    1.73 +      i.backward=false;
    1.74 +      if (*static_cast<Graph1Node*>(&i)==INVALID) {
    1.75 +	Parent2::graph->first(*static_cast<Graph2Node*>(&i));
    1.76 +	i.backward=true;
    1.77 +      }
    1.78 +    }
    1.79 +    void next(Node& i) const {
    1.80 +      if (!(i.backward)) {
    1.81 +	Parent1::graph->next(*static_cast<Graph1Node*>(&i));
    1.82 +	if (*static_cast<Graph1Node*>(&i)==INVALID) {
    1.83 +	  Parent2::graph->first(*static_cast<Graph2Node*>(&i));
    1.84 +	  i.backward=true;
    1.85  	}
    1.86 +      } else {
    1.87 +	Parent2::graph->next(*static_cast<Graph2Node*>(&i));
    1.88        }
    1.89 -      NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw, 
    1.90 -	     const Node& n) : 
    1.91 -	Node(n), gw(&_gw) { }
    1.92 -      NodeIt& operator++() { 
    1.93 -	if (!this->backward) {
    1.94 -	  *(static_cast<Graph1Node*>(this))=
    1.95 -	    ++(typename Graph1::NodeIt(*gw->Parent1::graph, *this));
    1.96 -	  if (*static_cast<Graph1Node*>(this)==INVALID) {
    1.97 -// 	    *static_cast<Node*>(this)=
    1.98 -// 	      Node(typename Graph1::Node(INVALID), 
    1.99 -// 		   typename Graph2::NodeIt(*gw->Parent2::graph), true);
   1.100 -	    *static_cast<Graph2Node*>(this)=
   1.101 -	      typename Graph2::NodeIt(*gw->Parent2::graph);
   1.102 -	    backward=true;
   1.103 -	  }
   1.104 -	} else {
   1.105 -	  *(static_cast<Graph2Node*>(this))=
   1.106 -	    ++(typename Graph2::NodeIt(*gw->Parent2::graph, *this));
   1.107 -	}
   1.108 -	return *this;
   1.109 -      }
   1.110 -    };
   1.111 +    }
   1.112  
   1.113      int id(const Node& n) const { 
   1.114        if (!n.backward) 
   1.115 @@ -123,44 +100,44 @@
   1.116  	return this->Parent2::graph->id(n);
   1.117      }
   1.118  
   1.119 -    template <typename Value> 
   1.120 -    class NodeMap : public Parent1::template NodeMap<Value>, 
   1.121 -		    public Parent2::template NodeMap<Value> { 
   1.122 -      typedef typename Parent1::template NodeMap<Value> ParentMap1;
   1.123 -      typedef typename Parent2::template NodeMap<Value> ParentMap2;
   1.124 +    template <typename _Value> 
   1.125 +    class NodeMap : public Parent1::template NodeMap<_Value>, 
   1.126 +		    public Parent2::template NodeMap<_Value> { 
   1.127 +      typedef typename Parent1::template NodeMap<_Value> ParentMap1;
   1.128 +      typedef typename Parent2::template NodeMap<_Value> ParentMap2;
   1.129      public:
   1.130 -      NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw) : 
   1.131 -	ParentMap1(gw), 
   1.132 -	ParentMap2(gw) { }
   1.133 -      NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw, 
   1.134 -	      const Value& value)
   1.135 -	: ParentMap1(gw, value), 
   1.136 -	  ParentMap2(gw, value) { }
   1.137 -      NodeMap(const NodeMap& copy)
   1.138 -	: ParentMap1(copy), 
   1.139 -	  ParentMap2(copy) { }
   1.140 -      template <typename TT>
   1.141 -      NodeMap(const NodeMap<TT>& copy)
   1.142 -	: ParentMap1(copy),
   1.143 -	  ParentMap2(copy) { }
   1.144 -      NodeMap& operator=(const NodeMap& copy) {
   1.145 -	ParentMap1::operator=(copy);
   1.146 -	ParentMap2::operator=(copy);
   1.147 -	return *this;
   1.148 -      }
   1.149 -      template <typename TT>
   1.150 -      NodeMap& operator=(const NodeMap<TT>& copy) {
   1.151 -	ParentMap1::operator=(copy);
   1.152 -	ParentMap2::operator=(copy);
   1.153 -	return *this;
   1.154 -      }
   1.155 -      Value operator[](const Node& n) const {
   1.156 +      typedef _Value Value;
   1.157 +      typedef Node Key;
   1.158 +      NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : 
   1.159 +	ParentMap1(gw), ParentMap2(gw) { }
   1.160 +      NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, 
   1.161 +	      const _Value& value) : 
   1.162 +	ParentMap1(gw, value), ParentMap2(gw, value) { }
   1.163 +//       NodeMap(const NodeMap& copy)
   1.164 +// 	: ParentMap1(copy), 
   1.165 +// 	  ParentMap2(copy) { }
   1.166 +//       template <typename TT>
   1.167 +//       NodeMap(const NodeMap<TT>& copy)
   1.168 +// 	: ParentMap1(copy),
   1.169 +// 	  ParentMap2(copy) { }
   1.170 +//       NodeMap& operator=(const NodeMap& copy) {
   1.171 +// 	ParentMap1::operator=(copy);
   1.172 +// 	ParentMap2::operator=(copy);
   1.173 +// 	return *this;
   1.174 +//       }
   1.175 +//       template <typename TT>
   1.176 +//       NodeMap& operator=(const NodeMap<TT>& copy) {
   1.177 +// 	ParentMap1::operator=(copy);
   1.178 +// 	ParentMap2::operator=(copy);
   1.179 +// 	return *this;
   1.180 +//       }
   1.181 +      _Value operator[](const Node& n) const {
   1.182  	if (!n.backward) 
   1.183  	  return ParentMap1::operator[](n);
   1.184  	else 
   1.185  	  return ParentMap2::operator[](n);
   1.186        }
   1.187 -      void set(const Node& n, const Value& value) {
   1.188 +      void set(const Node& n, const _Value& value) {
   1.189  	if (!n.backward) 
   1.190  	  ParentMap1::set(n, value);
   1.191  	else 
   1.192 @@ -169,7 +146,25 @@
   1.193        using ParentMap1::operator[];
   1.194        using ParentMap2::operator[];
   1.195      };
   1.196 -    
   1.197 +
   1.198 +  };
   1.199 +
   1.200 +
   1.201 +  template <typename _Graph1, typename _Graph2, typename Enable=void>
   1.202 +  class MergeNodeGraphWrapper : public 
   1.203 +  IterableGraphExtender<MergeNodeGraphWrapperBase<_Graph1, _Graph2, Enable> > {
   1.204 +  public:
   1.205 +    typedef _Graph1 Graph1;
   1.206 +    typedef _Graph2 Graph2;
   1.207 +    typedef IterableGraphExtender<
   1.208 +      MergeNodeGraphWrapperBase<_Graph1, _Graph2, Enable> > Parent;
   1.209 +  protected:
   1.210 +    MergeNodeGraphWrapper() { }
   1.211 +  public:
   1.212 +    MergeNodeGraphWrapper(_Graph1& _graph1, _Graph2& _graph2) { 
   1.213 +      Parent::Parent1::setGraph(_graph1);
   1.214 +      Parent::Parent2::setGraph(_graph2);
   1.215 +    }
   1.216    };
   1.217  
   1.218  } //namespace lemon