lemon/bits/iterable_graph_extender.h
changeset 1820 22099ef840d7
parent 1704 467d7927a901
child 1909 2d806130e700
     1.1 --- a/lemon/bits/iterable_graph_extender.h	Mon Nov 21 12:07:05 2005 +0000
     1.2 +++ b/lemon/bits/iterable_graph_extender.h	Mon Nov 21 17:48:00 2005 +0000
     1.3 @@ -267,6 +267,250 @@
     1.4      }
     1.5  
     1.6    };
     1.7 +
     1.8 +
     1.9 +  template <typename _Base>
    1.10 +  class IterableUndirBipartiteGraphExtender : public _Base {
    1.11 +  public:
    1.12 +    typedef _Base Parent;
    1.13 +    typedef IterableUndirBipartiteGraphExtender Graph;
    1.14 +   
    1.15 +    typedef typename Parent::Node Node;
    1.16 +    typedef typename Parent::UpperNode UpperNode;
    1.17 +    typedef typename Parent::LowerNode LowerNode;
    1.18 +    typedef typename Parent::Edge Edge;
    1.19 +    typedef typename Parent::UndirEdge UndirEdge;
    1.20 +  
    1.21 +    class NodeIt : public Node { 
    1.22 +      const Graph* graph;
    1.23 +    public:
    1.24 +    
    1.25 +      NodeIt() { }
    1.26 +    
    1.27 +      NodeIt(Invalid i) : Node(INVALID) { }
    1.28 +    
    1.29 +      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
    1.30 +	graph->first(static_cast<Node&>(*this));
    1.31 +      }
    1.32 +
    1.33 +      NodeIt(const Graph& _graph, const Node& node) 
    1.34 +	: Node(node), graph(&_graph) { }
    1.35 +    
    1.36 +      NodeIt& operator++() { 
    1.37 +	graph->next(*this);
    1.38 +	return *this; 
    1.39 +      }
    1.40 +
    1.41 +    };
    1.42 +
    1.43 +    class UpperNodeIt : public Node { 
    1.44 +      friend class IterableUndirBipartiteGraphExtender;
    1.45 +      const Graph* graph;
    1.46 +    public:
    1.47 +    
    1.48 +      UpperNodeIt() { }
    1.49 +    
    1.50 +      UpperNodeIt(Invalid i) : Node(INVALID) { }
    1.51 +    
    1.52 +      explicit UpperNodeIt(const Graph& _graph) : graph(&_graph) {
    1.53 +	graph->firstUpper(static_cast<Node&>(*this));
    1.54 +      }
    1.55 +
    1.56 +      UpperNodeIt(const Graph& _graph, const Node& node) 
    1.57 +	: Node(node), graph(&_graph) {}
    1.58 +    
    1.59 +      UpperNodeIt& operator++() { 
    1.60 +	graph->nextUpper(*this);
    1.61 +	return *this; 
    1.62 +      }
    1.63 +    };
    1.64 +
    1.65 +    class LowerNodeIt : public Node { 
    1.66 +      friend class IterableUndirBipartiteGraphExtender;
    1.67 +      const Graph* graph;
    1.68 +    public:
    1.69 +    
    1.70 +      LowerNodeIt() { }
    1.71 +    
    1.72 +      LowerNodeIt(Invalid i) : Node(INVALID) { }
    1.73 +    
    1.74 +      explicit LowerNodeIt(const Graph& _graph) : graph(&_graph) {
    1.75 +	graph->firstLower(static_cast<Node&>(*this));
    1.76 +      }
    1.77 +
    1.78 +      LowerNodeIt(const Graph& _graph, const Node& node) 
    1.79 +	: Node(node), graph(&_graph) {}
    1.80 +    
    1.81 +      LowerNodeIt& operator++() { 
    1.82 +	graph->nextLower(*this);
    1.83 +	return *this; 
    1.84 +      }
    1.85 +    };
    1.86 +
    1.87 +    class EdgeIt : public Edge { 
    1.88 +      friend class IterableUndirBipartiteGraphExtender;
    1.89 +      const Graph* graph;
    1.90 +    public:
    1.91 +    
    1.92 +      EdgeIt() { }
    1.93 +    
    1.94 +      EdgeIt(Invalid i) : Edge(INVALID) { }
    1.95 +    
    1.96 +      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
    1.97 +	graph->first(static_cast<Edge&>(*this));
    1.98 +      }
    1.99 +
   1.100 +      EdgeIt(const Graph& _graph, const Edge& edge) 
   1.101 +	: Edge(edge), graph(&_graph) { }
   1.102 +    
   1.103 +      EdgeIt& operator++() { 
   1.104 +	graph->next(*this);
   1.105 +	return *this; 
   1.106 +      }
   1.107 +
   1.108 +    };
   1.109 +
   1.110 +    class UndirEdgeIt : public UndirEdge { 
   1.111 +      friend class IterableUndirBipartiteGraphExtender;
   1.112 +      const Graph* graph;
   1.113 +    public:
   1.114 +    
   1.115 +      UndirEdgeIt() { }
   1.116 +    
   1.117 +      UndirEdgeIt(Invalid i) : UndirEdge(INVALID) { }
   1.118 +    
   1.119 +      explicit UndirEdgeIt(const Graph& _graph) : graph(&_graph) {
   1.120 +	graph->first(static_cast<UndirEdge&>(*this));
   1.121 +      }
   1.122 +
   1.123 +      UndirEdgeIt(const Graph& _graph, const UndirEdge& edge) 
   1.124 +	: UndirEdge(edge), graph(&_graph) { }
   1.125 +    
   1.126 +      UndirEdgeIt& operator++() { 
   1.127 +	graph->next(*this);
   1.128 +	return *this; 
   1.129 +      }
   1.130 +    };
   1.131 +
   1.132 +    class OutEdgeIt : public Edge { 
   1.133 +      friend class IterableUndirBipartiteGraphExtender;
   1.134 +      const Graph* graph;
   1.135 +    public:
   1.136 +    
   1.137 +      OutEdgeIt() { }
   1.138 +    
   1.139 +      OutEdgeIt(Invalid i) : Edge(i) { }
   1.140 +    
   1.141 +      OutEdgeIt(const Graph& _graph, const Node& node) 
   1.142 +	: graph(&_graph) {
   1.143 +	graph->firstOut(*this, node);
   1.144 +      }
   1.145 +    
   1.146 +      OutEdgeIt(const Graph& _graph, const Edge& edge) 
   1.147 +	: Edge(edge), graph(&_graph) {}
   1.148 +    
   1.149 +      OutEdgeIt& operator++() { 
   1.150 +	graph->nextOut(*this);
   1.151 +	return *this; 
   1.152 +      }
   1.153 +
   1.154 +    };
   1.155 +
   1.156 +
   1.157 +    class InEdgeIt : public Edge { 
   1.158 +      friend class IterableUndirBipartiteGraphExtender;
   1.159 +      const Graph* graph;
   1.160 +    public:
   1.161 +    
   1.162 +      InEdgeIt() { }
   1.163 +    
   1.164 +      InEdgeIt(Invalid i) : Edge(i) { }
   1.165 +    
   1.166 +      InEdgeIt(const Graph& _graph, const Node& node) 
   1.167 +	: graph(&_graph) {
   1.168 +	graph->firstIn(*this, node);
   1.169 +      }
   1.170 +    
   1.171 +      InEdgeIt(const Graph& _graph, const Edge& edge) : 
   1.172 +	Edge(edge), graph(&_graph) {}
   1.173 +    
   1.174 +      InEdgeIt& operator++() { 
   1.175 +	graph->nextIn(*this);
   1.176 +	return *this; 
   1.177 +      }
   1.178 +
   1.179 +    };
   1.180 +  
   1.181 +    /// \brief Base node of the iterator
   1.182 +    ///
   1.183 +    /// Returns the base node (ie. the source in this case) of the iterator
   1.184 +    Node baseNode(const OutEdgeIt &e) const {
   1.185 +      return Parent::source((Edge&)e);
   1.186 +    }
   1.187 +    /// \brief Running node of the iterator
   1.188 +    ///
   1.189 +    /// Returns the running node (ie. the target in this case) of the
   1.190 +    /// iterator
   1.191 +    Node runningNode(const OutEdgeIt &e) const {
   1.192 +      return Parent::target((Edge&)e);
   1.193 +    }
   1.194 +  
   1.195 +    /// \brief Base node of the iterator
   1.196 +    ///
   1.197 +    /// Returns the base node (ie. the target in this case) of the iterator
   1.198 +    Node baseNode(const InEdgeIt &e) const {
   1.199 +      return Parent::target((Edge&)e);
   1.200 +    }
   1.201 +    /// \brief Running node of the iterator
   1.202 +    ///
   1.203 +    /// Returns the running node (ie. the source in this case) of the
   1.204 +    /// iterator
   1.205 +    Node runningNode(const InEdgeIt &e) const {
   1.206 +      return Parent::source((Edge&)e);
   1.207 +    }
   1.208 +  
   1.209 +    class IncEdgeIt : public Parent::UndirEdge { 
   1.210 +      friend class IterableUndirBipartiteGraphExtender;
   1.211 +      const Graph* graph;
   1.212 +      bool direction;
   1.213 +    public:
   1.214 +    
   1.215 +      IncEdgeIt() { }
   1.216 +    
   1.217 +      IncEdgeIt(Invalid i) : UndirEdge(i), direction(true) { }
   1.218 +    
   1.219 +      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
   1.220 +	graph->firstInc(*this, direction, n);
   1.221 +      }
   1.222 +
   1.223 +      IncEdgeIt(const Graph& _graph, const UndirEdge &ue, const Node &n)
   1.224 +	: graph(&_graph), UndirEdge(ue) {
   1.225 +	direction = (graph->source(ue) == n);
   1.226 +      }
   1.227 +
   1.228 +      IncEdgeIt& operator++() {
   1.229 +	graph->nextInc(*this, direction);
   1.230 +	return *this; 
   1.231 +      }
   1.232 +    };
   1.233 +  
   1.234 +
   1.235 +    /// Base node of the iterator
   1.236 +    ///
   1.237 +    /// Returns the base node of the iterator
   1.238 +    Node baseNode(const IncEdgeIt &e) const {
   1.239 +      return e.direction ? source(e) : target(e);
   1.240 +    }
   1.241 +
   1.242 +    /// Running node of the iterator
   1.243 +    ///
   1.244 +    /// Returns the running node of the iterator
   1.245 +    Node runningNode(const IncEdgeIt &e) const {
   1.246 +      return e.direction ? target(e) : source(e);
   1.247 +    }
   1.248 +  
   1.249 +  };
   1.250 +
   1.251  }
   1.252  
   1.253  #endif // LEMON_GRAPH_EXTENDER_H