2 #ifndef FOR_EACH_MACROS_H
3 #define FOR_EACH_MACROS_H
5 // /// \ingroup gwrappers
7 /// \brief Iteraton macros.
9 /// This file contains several macros which make easier writting
10 /// for cycles in HUGO, using HUGO iterators.
12 /// \author Marton Makai
16 /// The iteration with HUGO iterators i.e. for cycles can be
17 /// written very comfortable with this macro.
21 /// FOR_EACH_GLOB(n, g) {
25 /// FOR_EACH_GLOB(e, g) {
28 /// In the above cycle, the iterator variable \c n and \c e are global ones.
30 #define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
32 /// The iteration with HUGO iterators i.e. for cycles can be
33 /// written very comfortable with this macro.
37 /// Graph::OutEdgeIt e;
38 /// FOR_EACH_INC_GLOB(e, g, v) {
41 /// typedef BipartiteGraph<Graph> BGraph;
43 /// BGraph::ClassNodeIt n;
44 /// FOR_EACH_INC_GLOB(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
47 /// In the above cycle, the iterator variable \c e and \c n are global ones.
49 #define FOR_EACH_INC_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
52 #define FOR_EACH_EDGE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
54 #define FOR_EACH_NODE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
56 #define FOR_EACH_INEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
58 #define FOR_EACH_OUTEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
60 // template<typename It, typename Graph>
61 // It loopFirst(const Graph& g) const {
62 // It e; g.first(e); return e;
65 // template<typename It, typename Graph>
66 // It loopFirst(const Graph& g, const Node& v) const {
67 // It e; g.first(e, v); return e;
70 // template<typename Graph>
71 // typename Graph::NodeIt loopFirstNode(const Graph& g) const {
72 // typename Graph::NodeIt e; g.first(e); return e;
74 // template<typename Graph>
75 // typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
76 // typename Graph::EdgeIt e; g.first(e); return e;
78 // template<typename Graph>
79 // typename Graph::OutEdgeIt
80 // loopFirstOutEdge(const Graph& g, const Node& n) const {
81 // typename Graph::OutEdgeIt e; g.first(e, n); return e;
83 // template<typename Graph>
84 // typename Graph::InEdgeIt
85 // loopFirstIn Edge(const Graph& g, const Node& n) const {
86 // typename Graph::InEdgeIt e; g.first(e, n); return e;
89 //FIXME ezt hogy a gorcsbe birja levezetni. Csak ugy leveszi a const-ot??
90 template<typename It, typename Graph>
91 It loopFirst(const It&, const Graph& g) {
92 It e; g.first(e); return e;
95 template<typename It, typename Graph, typename Node>
96 It loopFirst(const It&, const Graph& g, const Node& v) {
97 It e; g.first(e, v); return e;
100 // template<typename Graph>
101 // typename Graph::NodeIt loopFirstNode(const Graph& g) const {
102 // typename Graph::NodeIt e; g.first(e); return e;
104 // template<typename Graph>
105 // typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
106 // typename Graph::EdgeIt e; g.first(e); return e;
108 // template<typename Graph>
109 // typename Graph::OutEdgeIt
110 // loopFirstOutEdge(const Graph& g, const Node& n) const {
111 // typename Graph::OutEdgeIt e; g.first(e, n); return e;
113 // template<typename Graph>
114 // typename Graph::InEdgeIt
115 // loopFirstIn Edge(const Graph& g, const Node& n) const {
116 // typename Graph::InEdgeIt e; g.first(e, n); return e;
119 /// The iteration with HUGO iterators i.e. for cycles can be
120 /// written very comfortable with this macro.
123 /// FOR_EACH_LOC(Graph::NodeIt, n, g) {
126 /// FOR_EACH_LOC(Graph::EdgeIt, e, g) {
129 /// In the above cycle, the iterator variable \c n and \c e are local ones.
131 #define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
133 /// The iteration with HUGO iterators i.e. for cycles can be
134 /// written very comfortable with this macro.
138 /// FOR_EACH_INC_LOC(Graph::OutEdgeIt, e, g, v) {
141 /// typedef BipartiteGraph<Graph> BGraph;
143 /// FOR_EACH_INC_LOC(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
146 /// In the above cycle, the iterator variable \c e and \c n are local ones.
148 #define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
150 // #define FOR_EACH_EDGE_LOC(e, g) ezt nem tom hogy kell for((g).first((e)); (g).valid((e)); (g).next((e)))
151 // #define FOR_EACH_NODE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
152 // #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
153 // #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
158 #endif //FOR_EACH_MACROS_H