lemon/bits/iterable_graph_extender.h
changeset 1827 dc660ed95b31
parent 1704 467d7927a901
child 1909 2d806130e700
equal deleted inserted replaced
4:c80879d4331e 5:94d8f7d5e86b
   265 	return Parent::source(e);
   265 	return Parent::source(e);
   266       }
   266       }
   267     }
   267     }
   268 
   268 
   269   };
   269   };
       
   270 
       
   271 
       
   272   template <typename _Base>
       
   273   class IterableUndirBipartiteGraphExtender : public _Base {
       
   274   public:
       
   275     typedef _Base Parent;
       
   276     typedef IterableUndirBipartiteGraphExtender Graph;
       
   277    
       
   278     typedef typename Parent::Node Node;
       
   279     typedef typename Parent::UpperNode UpperNode;
       
   280     typedef typename Parent::LowerNode LowerNode;
       
   281     typedef typename Parent::Edge Edge;
       
   282     typedef typename Parent::UndirEdge UndirEdge;
       
   283   
       
   284     class NodeIt : public Node { 
       
   285       const Graph* graph;
       
   286     public:
       
   287     
       
   288       NodeIt() { }
       
   289     
       
   290       NodeIt(Invalid i) : Node(INVALID) { }
       
   291     
       
   292       explicit NodeIt(const Graph& _graph) : graph(&_graph) {
       
   293 	graph->first(static_cast<Node&>(*this));
       
   294       }
       
   295 
       
   296       NodeIt(const Graph& _graph, const Node& node) 
       
   297 	: Node(node), graph(&_graph) { }
       
   298     
       
   299       NodeIt& operator++() { 
       
   300 	graph->next(*this);
       
   301 	return *this; 
       
   302       }
       
   303 
       
   304     };
       
   305 
       
   306     class UpperNodeIt : public Node { 
       
   307       friend class IterableUndirBipartiteGraphExtender;
       
   308       const Graph* graph;
       
   309     public:
       
   310     
       
   311       UpperNodeIt() { }
       
   312     
       
   313       UpperNodeIt(Invalid i) : Node(INVALID) { }
       
   314     
       
   315       explicit UpperNodeIt(const Graph& _graph) : graph(&_graph) {
       
   316 	graph->firstUpper(static_cast<Node&>(*this));
       
   317       }
       
   318 
       
   319       UpperNodeIt(const Graph& _graph, const Node& node) 
       
   320 	: Node(node), graph(&_graph) {}
       
   321     
       
   322       UpperNodeIt& operator++() { 
       
   323 	graph->nextUpper(*this);
       
   324 	return *this; 
       
   325       }
       
   326     };
       
   327 
       
   328     class LowerNodeIt : public Node { 
       
   329       friend class IterableUndirBipartiteGraphExtender;
       
   330       const Graph* graph;
       
   331     public:
       
   332     
       
   333       LowerNodeIt() { }
       
   334     
       
   335       LowerNodeIt(Invalid i) : Node(INVALID) { }
       
   336     
       
   337       explicit LowerNodeIt(const Graph& _graph) : graph(&_graph) {
       
   338 	graph->firstLower(static_cast<Node&>(*this));
       
   339       }
       
   340 
       
   341       LowerNodeIt(const Graph& _graph, const Node& node) 
       
   342 	: Node(node), graph(&_graph) {}
       
   343     
       
   344       LowerNodeIt& operator++() { 
       
   345 	graph->nextLower(*this);
       
   346 	return *this; 
       
   347       }
       
   348     };
       
   349 
       
   350     class EdgeIt : public Edge { 
       
   351       friend class IterableUndirBipartiteGraphExtender;
       
   352       const Graph* graph;
       
   353     public:
       
   354     
       
   355       EdgeIt() { }
       
   356     
       
   357       EdgeIt(Invalid i) : Edge(INVALID) { }
       
   358     
       
   359       explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
       
   360 	graph->first(static_cast<Edge&>(*this));
       
   361       }
       
   362 
       
   363       EdgeIt(const Graph& _graph, const Edge& edge) 
       
   364 	: Edge(edge), graph(&_graph) { }
       
   365     
       
   366       EdgeIt& operator++() { 
       
   367 	graph->next(*this);
       
   368 	return *this; 
       
   369       }
       
   370 
       
   371     };
       
   372 
       
   373     class UndirEdgeIt : public UndirEdge { 
       
   374       friend class IterableUndirBipartiteGraphExtender;
       
   375       const Graph* graph;
       
   376     public:
       
   377     
       
   378       UndirEdgeIt() { }
       
   379     
       
   380       UndirEdgeIt(Invalid i) : UndirEdge(INVALID) { }
       
   381     
       
   382       explicit UndirEdgeIt(const Graph& _graph) : graph(&_graph) {
       
   383 	graph->first(static_cast<UndirEdge&>(*this));
       
   384       }
       
   385 
       
   386       UndirEdgeIt(const Graph& _graph, const UndirEdge& edge) 
       
   387 	: UndirEdge(edge), graph(&_graph) { }
       
   388     
       
   389       UndirEdgeIt& operator++() { 
       
   390 	graph->next(*this);
       
   391 	return *this; 
       
   392       }
       
   393     };
       
   394 
       
   395     class OutEdgeIt : public Edge { 
       
   396       friend class IterableUndirBipartiteGraphExtender;
       
   397       const Graph* graph;
       
   398     public:
       
   399     
       
   400       OutEdgeIt() { }
       
   401     
       
   402       OutEdgeIt(Invalid i) : Edge(i) { }
       
   403     
       
   404       OutEdgeIt(const Graph& _graph, const Node& node) 
       
   405 	: graph(&_graph) {
       
   406 	graph->firstOut(*this, node);
       
   407       }
       
   408     
       
   409       OutEdgeIt(const Graph& _graph, const Edge& edge) 
       
   410 	: Edge(edge), graph(&_graph) {}
       
   411     
       
   412       OutEdgeIt& operator++() { 
       
   413 	graph->nextOut(*this);
       
   414 	return *this; 
       
   415       }
       
   416 
       
   417     };
       
   418 
       
   419 
       
   420     class InEdgeIt : public Edge { 
       
   421       friend class IterableUndirBipartiteGraphExtender;
       
   422       const Graph* graph;
       
   423     public:
       
   424     
       
   425       InEdgeIt() { }
       
   426     
       
   427       InEdgeIt(Invalid i) : Edge(i) { }
       
   428     
       
   429       InEdgeIt(const Graph& _graph, const Node& node) 
       
   430 	: graph(&_graph) {
       
   431 	graph->firstIn(*this, node);
       
   432       }
       
   433     
       
   434       InEdgeIt(const Graph& _graph, const Edge& edge) : 
       
   435 	Edge(edge), graph(&_graph) {}
       
   436     
       
   437       InEdgeIt& operator++() { 
       
   438 	graph->nextIn(*this);
       
   439 	return *this; 
       
   440       }
       
   441 
       
   442     };
       
   443   
       
   444     /// \brief Base node of the iterator
       
   445     ///
       
   446     /// Returns the base node (ie. the source in this case) of the iterator
       
   447     Node baseNode(const OutEdgeIt &e) const {
       
   448       return Parent::source((Edge&)e);
       
   449     }
       
   450     /// \brief Running node of the iterator
       
   451     ///
       
   452     /// Returns the running node (ie. the target in this case) of the
       
   453     /// iterator
       
   454     Node runningNode(const OutEdgeIt &e) const {
       
   455       return Parent::target((Edge&)e);
       
   456     }
       
   457   
       
   458     /// \brief Base node of the iterator
       
   459     ///
       
   460     /// Returns the base node (ie. the target in this case) of the iterator
       
   461     Node baseNode(const InEdgeIt &e) const {
       
   462       return Parent::target((Edge&)e);
       
   463     }
       
   464     /// \brief Running node of the iterator
       
   465     ///
       
   466     /// Returns the running node (ie. the source in this case) of the
       
   467     /// iterator
       
   468     Node runningNode(const InEdgeIt &e) const {
       
   469       return Parent::source((Edge&)e);
       
   470     }
       
   471   
       
   472     class IncEdgeIt : public Parent::UndirEdge { 
       
   473       friend class IterableUndirBipartiteGraphExtender;
       
   474       const Graph* graph;
       
   475       bool direction;
       
   476     public:
       
   477     
       
   478       IncEdgeIt() { }
       
   479     
       
   480       IncEdgeIt(Invalid i) : UndirEdge(i), direction(true) { }
       
   481     
       
   482       IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
       
   483 	graph->firstInc(*this, direction, n);
       
   484       }
       
   485 
       
   486       IncEdgeIt(const Graph& _graph, const UndirEdge &ue, const Node &n)
       
   487 	: graph(&_graph), UndirEdge(ue) {
       
   488 	direction = (graph->source(ue) == n);
       
   489       }
       
   490 
       
   491       IncEdgeIt& operator++() {
       
   492 	graph->nextInc(*this, direction);
       
   493 	return *this; 
       
   494       }
       
   495     };
       
   496   
       
   497 
       
   498     /// Base node of the iterator
       
   499     ///
       
   500     /// Returns the base node of the iterator
       
   501     Node baseNode(const IncEdgeIt &e) const {
       
   502       return e.direction ? source(e) : target(e);
       
   503     }
       
   504 
       
   505     /// Running node of the iterator
       
   506     ///
       
   507     /// Returns the running node of the iterator
       
   508     Node runningNode(const IncEdgeIt &e) const {
       
   509       return e.direction ? target(e) : source(e);
       
   510     }
       
   511   
       
   512   };
       
   513 
   270 }
   514 }
   271 
   515 
   272 #endif // LEMON_GRAPH_EXTENDER_H
   516 #endif // LEMON_GRAPH_EXTENDER_H