Do not append -Wall -W to CXXFLAGS when it is set on the commandline.
2 #ifndef LEMON_ITERABLE_GRAPH_EXTENDER_H
3 #define LEMON_ITERABLE_GRAPH_EXTENDER_H
5 #include <lemon/invalid.h>
6 #include <lemon/utility.h>
10 template <typename _Base>
11 class IterableGraphExtender : public _Base {
14 /// Indicates that the graph is undirected.
18 ///\bug Should it be here?
19 typedef False UndirTag;
22 typedef IterableGraphExtender<_Base> Graph;
24 typedef typename Parent::Node Node;
25 typedef typename Parent::Edge Edge;
28 class NodeIt : public Node {
34 NodeIt(Invalid i) : Node(i) { }
36 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
37 _graph.first(*static_cast<Node*>(this));
40 NodeIt(const Graph& _graph, const Node& node)
41 : Node(node), graph(&_graph) {}
43 NodeIt& operator++() {
51 class EdgeIt : public Edge {
57 EdgeIt(Invalid i) : Edge(i) { }
59 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
60 _graph.first(*static_cast<Edge*>(this));
63 EdgeIt(const Graph& _graph, const Edge& e) :
64 Edge(e), graph(&_graph) { }
66 EdgeIt& operator++() {
74 class OutEdgeIt : public Edge {
80 OutEdgeIt(Invalid i) : Edge(i) { }
82 OutEdgeIt(const Graph& _graph, const Node& node)
84 _graph.firstOut(*this, node);
87 OutEdgeIt(const Graph& _graph, const Edge& edge)
88 : Edge(edge), graph(&_graph) {}
90 OutEdgeIt& operator++() {
91 graph->nextOut(*this);
98 class InEdgeIt : public Edge {
104 InEdgeIt(Invalid i) : Edge(i) { }
106 InEdgeIt(const Graph& _graph, const Node& node)
108 _graph.firstIn(*this, node);
111 InEdgeIt(const Graph& _graph, const Edge& edge) :
112 Edge(edge), graph(&_graph) {}
114 InEdgeIt& operator++() {
115 graph->nextIn(*this);
121 /// \brief Base node of the iterator
123 /// Returns the base node (ie. the source in this case) of the iterator
124 Node baseNode(const OutEdgeIt &e) const {
125 return Parent::source((Edge)e);
127 /// \brief Running node of the iterator
129 /// Returns the running node (ie. the target in this case) of the
131 Node runningNode(const OutEdgeIt &e) const {
132 return Parent::target((Edge)e);
135 /// \brief Base node of the iterator
137 /// Returns the base node (ie. the target in this case) of the iterator
138 Node baseNode(const InEdgeIt &e) const {
139 return Parent::target((Edge)e);
141 /// \brief Running node of the iterator
143 /// Returns the running node (ie. the source in this case) of the
145 Node runningNode(const InEdgeIt &e) const {
146 return Parent::source((Edge)e);
151 /// \brief The opposite node on the given edge.
153 /// Gives back the opposite on the given edge.
154 Node oppositeNode(const Node& n, const Edge& e) const {
155 if (Parent::source(e) == n) {
156 return Parent::target(e);
158 return Parent::source(e);
164 // void first(NodeIt &) const;
165 // void first(EdgeIt &) const;
166 // void first(OutEdgeIt &) const;
167 // void first(InEdgeIt &) const;
176 template <typename _Base>
177 class IterableUndirGraphExtender : public IterableGraphExtender<_Base> {
180 /// Indicates that the graph is undirected.
182 ///\todo Better name?
184 ///\bug Should it be here?
185 ///\bug Should be tested in the concept checker whether it is defined
187 typedef True UndirTag;
189 typedef IterableGraphExtender<_Base> Parent;
190 typedef IterableUndirGraphExtender<_Base> Graph;
191 typedef typename Parent::Node Node;
192 typedef typename Parent::Edge Edge;
193 typedef typename Parent::UndirEdge UndirEdge;
195 class UndirEdgeIt : public Parent::UndirEdge {
201 UndirEdgeIt(Invalid i) : UndirEdge(i) { }
203 explicit UndirEdgeIt(const Graph& _graph) : graph(&_graph) {
204 _graph.first(*static_cast<UndirEdge*>(this));
207 UndirEdgeIt(const Graph& _graph, const UndirEdge& e) :
208 UndirEdge(e), graph(&_graph) { }
210 UndirEdgeIt& operator++() {
217 class IncEdgeIt : public Parent::UndirEdge {
220 friend class IterableUndirGraphExtender;
225 IncEdgeIt(Invalid i) : UndirEdge(i), direction(false) { }
227 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
228 _graph.firstInc(*this, direction, n);
231 IncEdgeIt(const Graph& _graph, const UndirEdge &ue, const Node &n)
232 : graph(&_graph), UndirEdge(ue) {
233 direction = (_graph.source(ue) == n);
236 IncEdgeIt& operator++() {
237 graph->nextInc(*this, direction);
242 using Parent::baseNode;
243 using Parent::runningNode;
245 /// Base node of the iterator
247 /// Returns the base node of the iterator
248 Node baseNode(const IncEdgeIt &e) const {
249 return e.direction ? source(e) : target(e);
251 /// Running node of the iterator
253 /// Returns the running node of the iterator
254 Node runningNode(const IncEdgeIt &e) const {
255 return e.direction ? target(e) : source(e);
258 /// \brief The opposite node on the given undirected edge.
260 /// Gives back the opposite on the given undirected edge.
261 Node oppositeNode(const Node& n, const UndirEdge& e) const {
262 if (Parent::source(e) == n) {
263 return Parent::target(e);
265 return Parent::source(e);
272 template <typename _Base>
273 class IterableUndirBipartiteGraphExtender : public _Base {
275 typedef _Base Parent;
276 typedef IterableUndirBipartiteGraphExtender Graph;
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;
284 class NodeIt : public Node {
290 NodeIt(Invalid i) : Node(INVALID) { }
292 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
293 graph->first(static_cast<Node&>(*this));
296 NodeIt(const Graph& _graph, const Node& node)
297 : Node(node), graph(&_graph) { }
299 NodeIt& operator++() {
306 class UpperNodeIt : public Node {
307 friend class IterableUndirBipartiteGraphExtender;
313 UpperNodeIt(Invalid i) : Node(INVALID) { }
315 explicit UpperNodeIt(const Graph& _graph) : graph(&_graph) {
316 graph->firstUpper(static_cast<Node&>(*this));
319 UpperNodeIt(const Graph& _graph, const Node& node)
320 : Node(node), graph(&_graph) {}
322 UpperNodeIt& operator++() {
323 graph->nextUpper(*this);
328 class LowerNodeIt : public Node {
329 friend class IterableUndirBipartiteGraphExtender;
335 LowerNodeIt(Invalid i) : Node(INVALID) { }
337 explicit LowerNodeIt(const Graph& _graph) : graph(&_graph) {
338 graph->firstLower(static_cast<Node&>(*this));
341 LowerNodeIt(const Graph& _graph, const Node& node)
342 : Node(node), graph(&_graph) {}
344 LowerNodeIt& operator++() {
345 graph->nextLower(*this);
350 class EdgeIt : public Edge {
351 friend class IterableUndirBipartiteGraphExtender;
357 EdgeIt(Invalid i) : Edge(INVALID) { }
359 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
360 graph->first(static_cast<Edge&>(*this));
363 EdgeIt(const Graph& _graph, const Edge& edge)
364 : Edge(edge), graph(&_graph) { }
366 EdgeIt& operator++() {
373 class UndirEdgeIt : public UndirEdge {
374 friend class IterableUndirBipartiteGraphExtender;
380 UndirEdgeIt(Invalid i) : UndirEdge(INVALID) { }
382 explicit UndirEdgeIt(const Graph& _graph) : graph(&_graph) {
383 graph->first(static_cast<UndirEdge&>(*this));
386 UndirEdgeIt(const Graph& _graph, const UndirEdge& edge)
387 : UndirEdge(edge), graph(&_graph) { }
389 UndirEdgeIt& operator++() {
395 class OutEdgeIt : public Edge {
396 friend class IterableUndirBipartiteGraphExtender;
402 OutEdgeIt(Invalid i) : Edge(i) { }
404 OutEdgeIt(const Graph& _graph, const Node& node)
406 graph->firstOut(*this, node);
409 OutEdgeIt(const Graph& _graph, const Edge& edge)
410 : Edge(edge), graph(&_graph) {}
412 OutEdgeIt& operator++() {
413 graph->nextOut(*this);
420 class InEdgeIt : public Edge {
421 friend class IterableUndirBipartiteGraphExtender;
427 InEdgeIt(Invalid i) : Edge(i) { }
429 InEdgeIt(const Graph& _graph, const Node& node)
431 graph->firstIn(*this, node);
434 InEdgeIt(const Graph& _graph, const Edge& edge) :
435 Edge(edge), graph(&_graph) {}
437 InEdgeIt& operator++() {
438 graph->nextIn(*this);
444 /// \brief Base node of the iterator
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);
450 /// \brief Running node of the iterator
452 /// Returns the running node (ie. the target in this case) of the
454 Node runningNode(const OutEdgeIt &e) const {
455 return Parent::target((Edge&)e);
458 /// \brief Base node of the iterator
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);
464 /// \brief Running node of the iterator
466 /// Returns the running node (ie. the source in this case) of the
468 Node runningNode(const InEdgeIt &e) const {
469 return Parent::source((Edge&)e);
472 class IncEdgeIt : public Parent::UndirEdge {
473 friend class IterableUndirBipartiteGraphExtender;
480 IncEdgeIt(Invalid i) : UndirEdge(i), direction(true) { }
482 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
483 graph->firstInc(*this, direction, n);
486 IncEdgeIt(const Graph& _graph, const UndirEdge &ue, const Node &n)
487 : graph(&_graph), UndirEdge(ue) {
488 direction = (graph->source(ue) == n);
491 IncEdgeIt& operator++() {
492 graph->nextInc(*this, direction);
498 /// Base node of the iterator
500 /// Returns the base node of the iterator
501 Node baseNode(const IncEdgeIt &e) const {
502 return e.direction ? source(e) : target(e);
505 /// Running node of the iterator
507 /// Returns the running node of the iterator
508 Node runningNode(const IncEdgeIt &e) const {
509 return e.direction ? target(e) : source(e);
516 #endif // LEMON_GRAPH_EXTENDER_H