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