lemon/bits/edge_set_extender.h
changeset 709 0747f332c478
parent 559 c5fd2d996909
child 685 a27356ceb5bd
child 882 ece1f8a3052d
equal deleted inserted replaced
2:003580a06207 3:dbd790b96225
    32   // \ingroup digraphbits
    32   // \ingroup digraphbits
    33   //
    33   //
    34   // \brief Extender for the ArcSets
    34   // \brief Extender for the ArcSets
    35   template <typename Base>
    35   template <typename Base>
    36   class ArcSetExtender : public Base {
    36   class ArcSetExtender : public Base {
       
    37     typedef Base Parent;
       
    38 
    37   public:
    39   public:
    38 
    40 
    39     typedef Base Parent;
       
    40     typedef ArcSetExtender Digraph;
    41     typedef ArcSetExtender Digraph;
    41 
    42 
    42     // Base extensions
    43     // Base extensions
    43 
    44 
    44     typedef typename Parent::Node Node;
    45     typedef typename Parent::Node Node;
   216     // Mappable extension
   217     // Mappable extension
   217     
   218     
   218     template <typename _Value>
   219     template <typename _Value>
   219     class ArcMap 
   220     class ArcMap 
   220       : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
   221       : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
   221     public:
       
   222       typedef ArcSetExtender Digraph;
       
   223       typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
   222       typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
   224 
   223 
       
   224     public:
   225       explicit ArcMap(const Digraph& _g) 
   225       explicit ArcMap(const Digraph& _g) 
   226 	: Parent(_g) {}
   226 	: Parent(_g) {}
   227       ArcMap(const Digraph& _g, const _Value& _v) 
   227       ArcMap(const Digraph& _g, const _Value& _v) 
   228 	: Parent(_g, _v) {}
   228 	: Parent(_g, _v) {}
   229 
   229 
   272   // \ingroup digraphbits
   272   // \ingroup digraphbits
   273   //
   273   //
   274   // \brief Extender for the EdgeSets
   274   // \brief Extender for the EdgeSets
   275   template <typename Base>
   275   template <typename Base>
   276   class EdgeSetExtender : public Base {
   276   class EdgeSetExtender : public Base {
       
   277     typedef Base Parent;
   277 
   278 
   278   public:
   279   public:
   279 
   280 
   280     typedef Base Parent;
   281     typedef EdgeSetExtender Graph;
   281     typedef EdgeSetExtender Digraph;
       
   282 
   282 
   283     typedef typename Parent::Node Node;
   283     typedef typename Parent::Node Node;
   284     typedef typename Parent::Arc Arc;
   284     typedef typename Parent::Arc Arc;
   285     typedef typename Parent::Edge Edge;
   285     typedef typename Parent::Edge Edge;
   286 
       
   287 
   286 
   288     int maxId(Node) const {
   287     int maxId(Node) const {
   289       return Parent::maxNodeId();
   288       return Parent::maxNodeId();
   290     }
   289     }
   291 
   290 
   348       return edge_notifier;
   347       return edge_notifier;
   349     }
   348     }
   350 
   349 
   351 
   350 
   352     class NodeIt : public Node { 
   351     class NodeIt : public Node { 
   353       const Digraph* digraph;
   352       const Graph* graph;
   354     public:
   353     public:
   355 
   354 
   356       NodeIt() {}
   355       NodeIt() {}
   357 
   356 
   358       NodeIt(Invalid i) : Node(i) { }
   357       NodeIt(Invalid i) : Node(i) { }
   359 
   358 
   360       explicit NodeIt(const Digraph& _graph) : digraph(&_graph) {
   359       explicit NodeIt(const Graph& _graph) : graph(&_graph) {
   361 	_graph.first(static_cast<Node&>(*this));
   360 	_graph.first(static_cast<Node&>(*this));
   362       }
   361       }
   363 
   362 
   364       NodeIt(const Digraph& _graph, const Node& node) 
   363       NodeIt(const Graph& _graph, const Node& node) 
   365 	: Node(node), digraph(&_graph) {}
   364 	: Node(node), graph(&_graph) {}
   366 
   365 
   367       NodeIt& operator++() { 
   366       NodeIt& operator++() { 
   368 	digraph->next(*this);
   367 	graph->next(*this);
   369 	return *this; 
   368 	return *this; 
   370       }
   369       }
   371 
   370 
   372     };
   371     };
   373 
   372 
   374 
   373 
   375     class ArcIt : public Arc { 
   374     class ArcIt : public Arc { 
   376       const Digraph* digraph;
   375       const Graph* graph;
   377     public:
   376     public:
   378 
   377 
   379       ArcIt() { }
   378       ArcIt() { }
   380 
   379 
   381       ArcIt(Invalid i) : Arc(i) { }
   380       ArcIt(Invalid i) : Arc(i) { }
   382 
   381 
   383       explicit ArcIt(const Digraph& _graph) : digraph(&_graph) {
   382       explicit ArcIt(const Graph& _graph) : graph(&_graph) {
   384 	_graph.first(static_cast<Arc&>(*this));
   383 	_graph.first(static_cast<Arc&>(*this));
   385       }
   384       }
   386 
   385 
   387       ArcIt(const Digraph& _graph, const Arc& e) : 
   386       ArcIt(const Graph& _graph, const Arc& e) : 
   388 	Arc(e), digraph(&_graph) { }
   387 	Arc(e), graph(&_graph) { }
   389 
   388 
   390       ArcIt& operator++() { 
   389       ArcIt& operator++() { 
   391 	digraph->next(*this);
   390 	graph->next(*this);
   392 	return *this; 
   391 	return *this; 
   393       }
   392       }
   394 
   393 
   395     };
   394     };
   396 
   395 
   397 
   396 
   398     class OutArcIt : public Arc { 
   397     class OutArcIt : public Arc { 
   399       const Digraph* digraph;
   398       const Graph* graph;
   400     public:
   399     public:
   401 
   400 
   402       OutArcIt() { }
   401       OutArcIt() { }
   403 
   402 
   404       OutArcIt(Invalid i) : Arc(i) { }
   403       OutArcIt(Invalid i) : Arc(i) { }
   405 
   404 
   406       OutArcIt(const Digraph& _graph, const Node& node) 
   405       OutArcIt(const Graph& _graph, const Node& node) 
   407 	: digraph(&_graph) {
   406 	: graph(&_graph) {
   408 	_graph.firstOut(*this, node);
   407 	_graph.firstOut(*this, node);
   409       }
   408       }
   410 
   409 
   411       OutArcIt(const Digraph& _graph, const Arc& arc) 
   410       OutArcIt(const Graph& _graph, const Arc& arc) 
   412 	: Arc(arc), digraph(&_graph) {}
   411 	: Arc(arc), graph(&_graph) {}
   413 
   412 
   414       OutArcIt& operator++() { 
   413       OutArcIt& operator++() { 
   415 	digraph->nextOut(*this);
   414 	graph->nextOut(*this);
   416 	return *this; 
   415 	return *this; 
   417       }
   416       }
   418 
   417 
   419     };
   418     };
   420 
   419 
   421 
   420 
   422     class InArcIt : public Arc { 
   421     class InArcIt : public Arc { 
   423       const Digraph* digraph;
   422       const Graph* graph;
   424     public:
   423     public:
   425 
   424 
   426       InArcIt() { }
   425       InArcIt() { }
   427 
   426 
   428       InArcIt(Invalid i) : Arc(i) { }
   427       InArcIt(Invalid i) : Arc(i) { }
   429 
   428 
   430       InArcIt(const Digraph& _graph, const Node& node) 
   429       InArcIt(const Graph& _graph, const Node& node) 
   431 	: digraph(&_graph) {
   430 	: graph(&_graph) {
   432 	_graph.firstIn(*this, node);
   431 	_graph.firstIn(*this, node);
   433       }
   432       }
   434 
   433 
   435       InArcIt(const Digraph& _graph, const Arc& arc) : 
   434       InArcIt(const Graph& _graph, const Arc& arc) : 
   436 	Arc(arc), digraph(&_graph) {}
   435 	Arc(arc), graph(&_graph) {}
   437 
   436 
   438       InArcIt& operator++() { 
   437       InArcIt& operator++() { 
   439 	digraph->nextIn(*this);
   438 	graph->nextIn(*this);
   440 	return *this; 
   439 	return *this; 
   441       }
   440       }
   442 
   441 
   443     };
   442     };
   444 
   443 
   445 
   444 
   446     class EdgeIt : public Parent::Edge { 
   445     class EdgeIt : public Parent::Edge { 
   447       const Digraph* digraph;
   446       const Graph* graph;
   448     public:
   447     public:
   449 
   448 
   450       EdgeIt() { }
   449       EdgeIt() { }
   451 
   450 
   452       EdgeIt(Invalid i) : Edge(i) { }
   451       EdgeIt(Invalid i) : Edge(i) { }
   453 
   452 
   454       explicit EdgeIt(const Digraph& _graph) : digraph(&_graph) {
   453       explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
   455 	_graph.first(static_cast<Edge&>(*this));
   454 	_graph.first(static_cast<Edge&>(*this));
   456       }
   455       }
   457 
   456 
   458       EdgeIt(const Digraph& _graph, const Edge& e) : 
   457       EdgeIt(const Graph& _graph, const Edge& e) : 
   459 	Edge(e), digraph(&_graph) { }
   458 	Edge(e), graph(&_graph) { }
   460 
   459 
   461       EdgeIt& operator++() { 
   460       EdgeIt& operator++() { 
   462 	digraph->next(*this);
   461 	graph->next(*this);
   463 	return *this; 
   462 	return *this; 
   464       }
   463       }
   465 
   464 
   466     };
   465     };
   467 
   466 
   468     class IncEdgeIt : public Parent::Edge {
   467     class IncEdgeIt : public Parent::Edge {
   469       friend class EdgeSetExtender;
   468       friend class EdgeSetExtender;
   470       const Digraph* digraph;
   469       const Graph* graph;
   471       bool direction;
   470       bool direction;
   472     public:
   471     public:
   473 
   472 
   474       IncEdgeIt() { }
   473       IncEdgeIt() { }
   475 
   474 
   476       IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
   475       IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
   477 
   476 
   478       IncEdgeIt(const Digraph& _graph, const Node &n) : digraph(&_graph) {
   477       IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
   479 	_graph.firstInc(*this, direction, n);
   478 	_graph.firstInc(*this, direction, n);
   480       }
   479       }
   481 
   480 
   482       IncEdgeIt(const Digraph& _graph, const Edge &ue, const Node &n)
   481       IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n)
   483 	: digraph(&_graph), Edge(ue) {
   482 	: graph(&_graph), Edge(ue) {
   484 	direction = (_graph.source(ue) == n);
   483 	direction = (_graph.source(ue) == n);
   485       }
   484       }
   486 
   485 
   487       IncEdgeIt& operator++() {
   486       IncEdgeIt& operator++() {
   488 	digraph->nextInc(*this, direction);
   487 	graph->nextInc(*this, direction);
   489 	return *this; 
   488 	return *this; 
   490       }
   489       }
   491     };
   490     };
   492 
   491 
   493     // \brief Base node of the iterator
   492     // \brief Base node of the iterator
   532     }
   531     }
   533 
   532 
   534 
   533 
   535     template <typename _Value>
   534     template <typename _Value>
   536     class ArcMap 
   535     class ArcMap 
   537       : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
   536       : public MapExtender<DefaultMap<Graph, Arc, _Value> > {
   538     public:
   537       typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
   539       typedef EdgeSetExtender Digraph;
   538 
   540       typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
   539     public:
   541 
   540       ArcMap(const Graph& _g) 
   542       ArcMap(const Digraph& _g) 
       
   543 	: Parent(_g) {}
   541 	: Parent(_g) {}
   544       ArcMap(const Digraph& _g, const _Value& _v) 
   542       ArcMap(const Graph& _g, const _Value& _v) 
   545 	: Parent(_g, _v) {}
   543 	: Parent(_g, _v) {}
   546 
   544 
   547       ArcMap& operator=(const ArcMap& cmap) {
   545       ArcMap& operator=(const ArcMap& cmap) {
   548 	return operator=<ArcMap>(cmap);
   546 	return operator=<ArcMap>(cmap);
   549       }
   547       }
   557     };
   555     };
   558 
   556 
   559 
   557 
   560     template <typename _Value>
   558     template <typename _Value>
   561     class EdgeMap 
   559     class EdgeMap 
   562       : public MapExtender<DefaultMap<Digraph, Edge, _Value> > {
   560       : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
   563     public:
   561       typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
   564       typedef EdgeSetExtender Digraph;
   562 
   565       typedef MapExtender<DefaultMap<Digraph, Edge, _Value> > Parent;
   563     public:
   566 
   564       EdgeMap(const Graph& _g) 
   567       EdgeMap(const Digraph& _g) 
       
   568 	: Parent(_g) {}
   565 	: Parent(_g) {}
   569 
   566 
   570       EdgeMap(const Digraph& _g, const _Value& _v) 
   567       EdgeMap(const Graph& _g, const _Value& _v) 
   571 	: Parent(_g, _v) {}
   568 	: Parent(_g, _v) {}
   572 
   569 
   573       EdgeMap& operator=(const EdgeMap& cmap) {
   570       EdgeMap& operator=(const EdgeMap& cmap) {
   574 	return operator=<EdgeMap>(cmap);
   571 	return operator=<EdgeMap>(cmap);
   575       }
   572       }