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