COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/for_each_macros.h @ 639:a11a4377a816

Last change on this file since 639:a11a4377a816 was 639:a11a4377a816, checked in by marci, 21 years ago

misc

File size: 5.1 KB
RevLine 
[330]1// -*- c++ -*-
2#ifndef FOR_EACH_MACROS_H
3#define FOR_EACH_MACROS_H
4
[636]5// /// \ingroup gwrappers
6/// \file
[638]7/// \brief Iteration macros.
[636]8///
9/// This file contains several macros which make easier writting
[638]10/// for cycles in HUGO using HUGO iterators.
[636]11///
12/// \author Marton Makai
13
[330]14namespace hugo {
15
[638]16  /// This macro provides a comfortable interface for iterating with HUGO
17  /// iterators.
18  /// \code
19  /// Graph g;
[639]20  /// ...
[638]21  /// Graph::NodeIt n;
22  /// FOR_EACH_GLOB(n, g) {
23  /// ...
24  /// }
25  /// Graph::EdgeIt e;
26  /// FOR_EACH_GLOB(e, g) {
27  /// ...
28  /// }
29  /// \endcode
30  /// Note that the iterated variables \c n and \c e are global ones.
[409]31#define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
[636]32
[638]33  /// This macro provides a comfortable interface for iterating with HUGO
34  /// iterators.
35  /// \code
36  /// Graph g;
[639]37  /// ...
[638]38  /// Graph::Node v;
39  /// Graph::OutEdgeIt e;
40  /// FOR_EACH_INC_GLOB(e, g, v) {
41  /// ...
42  /// }
43  /// typedef BipartiteGraph<Graph> BGraph;
44  /// BGraph h;
[639]45  /// ...
[638]46  /// BGraph::ClassNodeIt n;
47  /// FOR_EACH_INC_GLOB(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
48  /// ...
49  /// }
50  /// \endcode
51  /// Note that iterated variables \c e and \c n are global ones.
[409]52#define FOR_EACH_INC_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
[638]53 
[636]54/// \deprecated
[638]55//#define FOR_EACH_EDGE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
[636]56/// \deprecated
[638]57//#define FOR_EACH_NODE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
[636]58/// \deprecated
[638]59//#define FOR_EACH_INEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
[636]60/// \deprecated
[638]61//#define FOR_EACH_OUTEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
[330]62
63//   template<typename It, typename Graph>
64//   It loopFirst(const Graph& g) const {
65//     It e; g.first(e); return e;
66//   }
67
68//   template<typename It, typename Graph>
69//   It loopFirst(const Graph& g, const Node& v) const {
70//     It e; g.first(e, v); return e;
71//   }
72
73//   template<typename Graph>
74//   typename Graph::NodeIt loopFirstNode(const Graph& g) const {
75//     typename Graph::NodeIt e; g.first(e); return e;
76//   }
77//   template<typename Graph>
78//   typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
79//     typename Graph::EdgeIt e; g.first(e); return e;
80//   }
81//   template<typename Graph>
82//   typename Graph::OutEdgeIt
83//   loopFirstOutEdge(const Graph& g, const Node& n) const {
84//     typename Graph::OutEdgeIt e; g.first(e, n); return e;
85//   }
86//   template<typename Graph>
87//   typename Graph::InEdgeIt
88//   loopFirstIn Edge(const Graph& g, const Node& n) const {
89//     typename Graph::InEdgeIt e; g.first(e, n); return e;
90//   }
91
92//FIXME ezt hogy a gorcsbe birja levezetni. Csak ugy leveszi a const-ot??
93  template<typename It, typename Graph>
[333]94  It loopFirst(const It&, const Graph& g) {
95    It e; g.first(e); return e;
[330]96  }
97
98  template<typename It, typename Graph, typename Node>
[333]99  It loopFirst(const It&, const Graph& g, const Node& v) {
100    It e; g.first(e, v); return e;
[330]101  }
102
103//   template<typename Graph>
104//   typename Graph::NodeIt loopFirstNode(const Graph& g) const {
105//     typename Graph::NodeIt e; g.first(e); return e;
106//   }
107//   template<typename Graph>
108//   typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
109//     typename Graph::EdgeIt e; g.first(e); return e;
110//   }
111//   template<typename Graph>
112//   typename Graph::OutEdgeIt
113//   loopFirstOutEdge(const Graph& g, const Node& n) const {
114//     typename Graph::OutEdgeIt e; g.first(e, n); return e;
115//   }
116//   template<typename Graph>
117//   typename Graph::InEdgeIt
118//   loopFirstIn Edge(const Graph& g, const Node& n) const {
119//     typename Graph::InEdgeIt e; g.first(e, n); return e;
120//   }
121
[638]122  /// This macro provides a comfortable interface for iterating with HUGO
123  /// iterators.
124  /// \code
125  /// Graph g;
[639]126  /// ...
[638]127  /// FOR_EACH_LOC(Graph::NodeIt, n, g) {
128  /// ...
129  /// }
130  /// FOR_EACH_LOC(Graph::EdgeIt, e, g) {
131  /// ...
132  /// }
133  /// \endcode
134  /// Note that the iterated variables \c n and \c e are local ones.
[333]135#define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
[638]136 
137  /// This macro provides a comfortable interface for iterating with HUGO
138  /// iterators.
139  /// \code
140  /// Graph g;
[639]141  /// ...
[638]142  /// Graph::Node v;
143  /// FOR_EACH_INC_LOC(Graph::OutEdgeIt, e, g, v) {
144  /// ...
145  /// }
146  /// typedef BipartiteGraph<Graph> BGraph;
147  /// BGraph h;
[639]148  /// ...
[638]149  /// FOR_EACH_INC_LOC(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
150  /// ...
151  /// }
152  /// \endcode
153  /// Note that the iterated variables \c e and \c n are local ones.
[333]154#define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
[638]155 
[333]156// #define FOR_EACH_EDGE_LOC(e, g) ezt nem tom hogy kell for((g).first((e)); (g).valid((e)); (g).next((e)))
[330]157// #define FOR_EACH_NODE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
158// #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
159// #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
160
161
162} //namespace hugo
163
164#endif //FOR_EACH_MACROS_H
Note: See TracBrowser for help on using the repository browser.