src/lemon/iterable_graph_extender.h
changeset 991 e619a466ca5d
parent 946 c94ef40a22ce
child 1021 fd1d073b6557
equal deleted inserted replaced
0:8d7e97ede627 1:750aa2250a3a
     6 
     6 
     7 namespace lemon {
     7 namespace lemon {
     8   
     8   
     9   template <typename _Base>
     9   template <typename _Base>
    10   class IterableGraphExtender : public _Base {
    10   class IterableGraphExtender : public _Base {
       
    11   public:
    11 
    12 
    12     typedef _Base Parent;
    13     typedef _Base Parent;
    13     typedef IterableGraphExtender<_Base> Graph;
    14     typedef IterableGraphExtender<_Base> Graph;
    14 
       
    15   public:
       
    16 
    15 
    17     typedef typename Parent::Node Node;
    16     typedef typename Parent::Node Node;
    18     typedef typename Parent::Edge Edge;
    17     typedef typename Parent::Edge Edge;
    19 
    18 
    20 
    19 
    24 
    23 
    25       NodeIt() {}
    24       NodeIt() {}
    26 
    25 
    27       NodeIt(Invalid i) : Node(i) { }
    26       NodeIt(Invalid i) : Node(i) { }
    28 
    27 
    29       explicit NodeIt(const Graph& _graph) : Node(), graph(&_graph) {
    28       explicit NodeIt(const Graph& _graph) : graph(&_graph) {
    30 	_graph.first(*static_cast<Node*>(this));
    29 	_graph.first(*static_cast<Node*>(this));
    31       }
    30       }
    32 
    31 
    33       NodeIt(const Graph& _graph, const Node& node) 
    32       NodeIt(const Graph& _graph, const Node& node) 
    34 	: Node(node), graph(&_graph) {}
    33 	: Node(node), graph(&_graph) {}
    47 
    46 
    48       EdgeIt() { }
    47       EdgeIt() { }
    49 
    48 
    50       EdgeIt(Invalid i) : Edge(i) { }
    49       EdgeIt(Invalid i) : Edge(i) { }
    51 
    50 
    52       explicit EdgeIt(const Graph& _graph) : Edge(), graph(&_graph) {
    51       explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
    53 	_graph.first(*static_cast<Edge*>(this));
    52 	_graph.first(*static_cast<Edge*>(this));
    54       }
    53       }
    55 
    54 
    56       EdgeIt(const Graph& _graph, const Edge& e) : 
    55       EdgeIt(const Graph& _graph, const Edge& e) : 
    57 	Edge(e), graph(&_graph) { }
    56 	Edge(e), graph(&_graph) { }
    71       OutEdgeIt() { }
    70       OutEdgeIt() { }
    72 
    71 
    73       OutEdgeIt(Invalid i) : Edge(i) { }
    72       OutEdgeIt(Invalid i) : Edge(i) { }
    74 
    73 
    75       OutEdgeIt(const Graph& _graph, const Node& node) 
    74       OutEdgeIt(const Graph& _graph, const Node& node) 
    76 	: Edge(), graph(&_graph) {
    75 	: graph(&_graph) {
    77 	_graph.firstOut(*this, node);
    76 	_graph.firstOut(*this, node);
    78       }
    77       }
    79 
    78 
    80       OutEdgeIt(const Graph& _graph, const Edge& edge) 
    79       OutEdgeIt(const Graph& _graph, const Edge& edge) 
    81 	: Edge(edge), graph(&_graph) {}
    80 	: Edge(edge), graph(&_graph) {}
    95       InEdgeIt() { }
    94       InEdgeIt() { }
    96 
    95 
    97       InEdgeIt(Invalid i) : Edge(i) { }
    96       InEdgeIt(Invalid i) : Edge(i) { }
    98 
    97 
    99       InEdgeIt(const Graph& _graph, const Node& node) 
    98       InEdgeIt(const Graph& _graph, const Node& node) 
   100 	: Edge(), graph(&_graph) {
    99 	: graph(&_graph) {
   101 	_graph.firstIn(*this, node);
   100 	_graph.firstIn(*this, node);
   102       }
   101       }
   103 
   102 
   104       InEdgeIt(const Graph& _graph, const Edge& edge) : 
   103       InEdgeIt(const Graph& _graph, const Edge& edge) : 
   105 	Edge(edge), graph(&_graph) {}
   104 	Edge(edge), graph(&_graph) {}
   124     void first(OutEdgeIt &) const;
   123     void first(OutEdgeIt &) const;
   125     void first(InEdgeIt &) const;
   124     void first(InEdgeIt &) const;
   126 
   125 
   127   };
   126   };
   128   
   127   
       
   128   template <typename _Base>
       
   129   class IterableUndirGraphExtender : public IterableGraphExtender<_Base> {
       
   130   public:
       
   131 
       
   132     typedef IterableGraphExtender<_Base> Parent;
       
   133     typedef IterableUndirGraphExtender<_Base> Graph;
       
   134 
       
   135     typedef typename Parent::UndirEdge UndirEdge;
       
   136 
       
   137     class UndirEdgeIt : public UndirEdge { 
       
   138       const Graph* graph;
       
   139     public:
       
   140 
       
   141       UndirEdgeIt() { }
       
   142 
       
   143       UndirEdgeIt(Invalid i) : UndirEdge(i) { }
       
   144 
       
   145       explicit UndirEdgeIt(const Graph& _graph) : graph(&_graph) {
       
   146 	_graph.first(*static_cast<UndirEdge*>(this));
       
   147       }
       
   148 
       
   149       UndirEdgeIt(const Graph& _graph, const UndirEdge& e) : 
       
   150 	UndirEdge(e), graph(&_graph) { }
       
   151 
       
   152       UndirEdgeIt& operator++() { 
       
   153 	graph->next(*this);
       
   154 	return *this; 
       
   155       }
       
   156 
       
   157     };
       
   158 
       
   159 
       
   160   };
   129 }
   161 }
   130 
   162 
   131 #endif // LEMON_GRAPH_EXTENDER_H
   163 #endif // LEMON_GRAPH_EXTENDER_H