1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/marci/for_each_macros.h Thu Jul 22 14:09:21 2004 +0000
1.3 @@ -0,0 +1,175 @@
1.4 +// -*- c++ -*-
1.5 +#ifndef HUGO_FOR_EACH_MACROS_H
1.6 +#define HUGO_FOR_EACH_MACROS_H
1.7 +
1.8 +// /// \ingroup gwrappers
1.9 +/// \file
1.10 +/// \brief Iteration macros.
1.11 +///
1.12 +/// This file contains several macros which make easier writting
1.13 +/// for cycles in HUGO using HUGO iterators.
1.14 +///
1.15 +/// \author Marton Makai
1.16 +
1.17 +namespace hugo {
1.18 +
1.19 + /// This macro provides a comfortable interface for iterating with HUGO
1.20 + /// iterators.
1.21 + /// \code
1.22 + /// Graph g;
1.23 + /// ...
1.24 + /// Graph::NodeIt n;
1.25 + /// h_for_glob(n, g) {
1.26 + /// ...
1.27 + /// }
1.28 + /// Graph::EdgeIt e;
1.29 + /// h_for_glob(e, g) {
1.30 + /// ...
1.31 + /// }
1.32 + /// \endcode
1.33 + /// Note that the iterated variables \c n and \c e are global ones.
1.34 +#define h_for_glob(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
1.35 +
1.36 +/// \deprecated
1.37 +#define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
1.38 +
1.39 + /// This macro provides a comfortable interface for iterating with HUGO
1.40 + /// iterators.
1.41 + /// \code
1.42 + /// Graph g;
1.43 + /// ...
1.44 + /// Graph::Node v;
1.45 + /// Graph::OutEdgeIt e;
1.46 + /// h_for_inc_glob(e, g, v) {
1.47 + /// ...
1.48 + /// }
1.49 + /// typedef BipartiteGraph<Graph> BGraph;
1.50 + /// BGraph h;
1.51 + /// ...
1.52 + /// BGraph::ClassNodeIt n;
1.53 + /// h_for_inc_glob(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
1.54 + /// ...
1.55 + /// }
1.56 + /// \endcode
1.57 + /// Note that iterated variables \c e and \c n are global ones.
1.58 +#define h_for_inc_glob(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
1.59 +
1.60 +/// \deprecated
1.61 +#define FOR_EACH_INC_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
1.62 +
1.63 +/// \deprecated
1.64 +//#define FOR_EACH_EDGE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
1.65 +/// \deprecated
1.66 +//#define FOR_EACH_NODE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
1.67 +/// \deprecated
1.68 +//#define FOR_EACH_INEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
1.69 +/// \deprecated
1.70 +//#define FOR_EACH_OUTEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
1.71 +
1.72 +// template<typename It, typename Graph>
1.73 +// It loopFirst(const Graph& g) const {
1.74 +// It e; g.first(e); return e;
1.75 +// }
1.76 +
1.77 +// template<typename It, typename Graph>
1.78 +// It loopFirst(const Graph& g, const Node& v) const {
1.79 +// It e; g.first(e, v); return e;
1.80 +// }
1.81 +
1.82 +// template<typename Graph>
1.83 +// typename Graph::NodeIt loopFirstNode(const Graph& g) const {
1.84 +// typename Graph::NodeIt e; g.first(e); return e;
1.85 +// }
1.86 +// template<typename Graph>
1.87 +// typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
1.88 +// typename Graph::EdgeIt e; g.first(e); return e;
1.89 +// }
1.90 +// template<typename Graph>
1.91 +// typename Graph::OutEdgeIt
1.92 +// loopFirstOutEdge(const Graph& g, const Node& n) const {
1.93 +// typename Graph::OutEdgeIt e; g.first(e, n); return e;
1.94 +// }
1.95 +// template<typename Graph>
1.96 +// typename Graph::InEdgeIt
1.97 +// loopFirstIn Edge(const Graph& g, const Node& n) const {
1.98 +// typename Graph::InEdgeIt e; g.first(e, n); return e;
1.99 +// }
1.100 +
1.101 +//FIXME ezt hogy a gorcsbe birja levezetni. Csak ugy leveszi a const-ot??
1.102 + template<typename It, typename Graph>
1.103 + It loopFirst(const It&, const Graph& g) {
1.104 + It e; g.first(e); return e;
1.105 + }
1.106 +
1.107 + template<typename It, typename Graph, typename Node>
1.108 + It loopFirst(const It&, const Graph& g, const Node& v) {
1.109 + It e; g.first(e, v); return e;
1.110 + }
1.111 +
1.112 +// template<typename Graph>
1.113 +// typename Graph::NodeIt loopFirstNode(const Graph& g) const {
1.114 +// typename Graph::NodeIt e; g.first(e); return e;
1.115 +// }
1.116 +// template<typename Graph>
1.117 +// typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
1.118 +// typename Graph::EdgeIt e; g.first(e); return e;
1.119 +// }
1.120 +// template<typename Graph>
1.121 +// typename Graph::OutEdgeIt
1.122 +// loopFirstOutEdge(const Graph& g, const Node& n) const {
1.123 +// typename Graph::OutEdgeIt e; g.first(e, n); return e;
1.124 +// }
1.125 +// template<typename Graph>
1.126 +// typename Graph::InEdgeIt
1.127 +// loopFirstIn Edge(const Graph& g, const Node& n) const {
1.128 +// typename Graph::InEdgeIt e; g.first(e, n); return e;
1.129 +// }
1.130 +
1.131 + /// This macro provides a comfortable interface for iterating with HUGO
1.132 + /// iterators.
1.133 + /// \code
1.134 + /// Graph g;
1.135 + /// ...
1.136 + /// h_for(Graph::NodeIt, n, g) {
1.137 + /// ...
1.138 + /// }
1.139 + /// h_for(Graph::EdgeIt, e, g) {
1.140 + /// ...
1.141 + /// }
1.142 + /// \endcode
1.143 + /// Note that the iterated variables \c n and \c e are local ones.
1.144 +#define h_for(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
1.145 +
1.146 +/// \deprecated
1.147 +#define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
1.148 +
1.149 + /// This macro provides a comfortable interface for iterating with HUGO
1.150 + /// iterators.
1.151 + /// \code
1.152 + /// Graph g;
1.153 + /// ...
1.154 + /// Graph::Node v;
1.155 + /// h_for_inc(Graph::OutEdgeIt, e, g, v) {
1.156 + /// ...
1.157 + /// }
1.158 + /// typedef BipartiteGraph<Graph> BGraph;
1.159 + /// BGraph h;
1.160 + /// ...
1.161 + /// h_for_inc(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
1.162 + /// ...
1.163 + /// }
1.164 + /// \endcode
1.165 + /// Note that the iterated variables \c e and \c n are local ones.
1.166 +#define h_for_inc(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
1.167 +
1.168 +/// \deprecated
1.169 +#define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
1.170 +
1.171 +// #define FOR_EACH_EDGE_LOC(e, g) ezt nem tom hogy kell for((g).first((e)); (g).valid((e)); (g).next((e)))
1.172 +// #define FOR_EACH_NODE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
1.173 +// #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
1.174 +// #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
1.175 +
1.176 +} //namespace hugo
1.177 +
1.178 +#endif //HUGO_FOR_EACH_MACROS_H