marci@330: // -*- c++ -*- marci@330: #ifndef FOR_EACH_MACROS_H marci@330: #define FOR_EACH_MACROS_H marci@330: marci@636: // /// \ingroup gwrappers marci@636: /// \file marci@636: /// \brief Iteraton macros. marci@636: /// marci@636: /// This file contains several macros which make easier writting marci@636: /// for cycles in HUGO, using HUGO iterators. marci@636: /// marci@636: /// \author Marton Makai marci@636: marci@330: namespace hugo { marci@330: marci@636: /// The iteration with HUGO iterators i.e. for cycles can be marci@636: /// written very comfortable with this macro. marci@636: /// \code marci@636: /// Graph g; marci@636: /// Graph::NodeIt n; marci@636: /// FOR_EACH_GLOB(n, g) { marci@636: /// ... marci@636: /// } marci@636: /// Graph::EdgeIt e; marci@636: /// FOR_EACH_GLOB(e, g) { marci@636: /// ... marci@636: /// } marci@636: /// In the above cycle, the iterator variable \c n and \c e are global ones. marci@636: /// \endcode marci@409: #define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e))) marci@636: marci@636: /// The iteration with HUGO iterators i.e. for cycles can be marci@636: /// written very comfortable with this macro. marci@636: /// \code marci@636: /// Graph g; marci@636: /// Graph::Node v; marci@636: /// Graph::OutEdgeIt e; marci@636: /// FOR_EACH_INC_GLOB(e, g, v) { marci@636: /// ... marci@636: /// } marci@636: /// typedef BipartiteGraph BGraph; marci@636: /// BGraph h; marci@636: /// BGraph::ClassNodeIt n; marci@636: /// FOR_EACH_INC_GLOB(BGraph::ClassNodeIt, n, h, h.S_CLASS) { marci@636: /// ... marci@636: /// } marci@636: /// In the above cycle, the iterator variable \c e and \c n are global ones. marci@636: /// \endcode marci@409: #define FOR_EACH_INC_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e))) marci@330: marci@636: /// \deprecated marci@409: #define FOR_EACH_EDGE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e))) marci@636: /// \deprecated marci@409: #define FOR_EACH_NODE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e))) marci@636: /// \deprecated marci@409: #define FOR_EACH_INEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e))) marci@636: /// \deprecated marci@409: #define FOR_EACH_OUTEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e))) marci@330: marci@330: // template marci@330: // It loopFirst(const Graph& g) const { marci@330: // It e; g.first(e); return e; marci@330: // } marci@330: marci@330: // template marci@330: // It loopFirst(const Graph& g, const Node& v) const { marci@330: // It e; g.first(e, v); return e; marci@330: // } marci@330: marci@330: // template marci@330: // typename Graph::NodeIt loopFirstNode(const Graph& g) const { marci@330: // typename Graph::NodeIt e; g.first(e); return e; marci@330: // } marci@330: // template marci@330: // typename Graph::EdgeIt loopFirstEdge(const Graph& g) const { marci@330: // typename Graph::EdgeIt e; g.first(e); return e; marci@330: // } marci@330: // template marci@330: // typename Graph::OutEdgeIt marci@330: // loopFirstOutEdge(const Graph& g, const Node& n) const { marci@330: // typename Graph::OutEdgeIt e; g.first(e, n); return e; marci@330: // } marci@330: // template marci@330: // typename Graph::InEdgeIt marci@330: // loopFirstIn Edge(const Graph& g, const Node& n) const { marci@330: // typename Graph::InEdgeIt e; g.first(e, n); return e; marci@330: // } marci@330: marci@330: //FIXME ezt hogy a gorcsbe birja levezetni. Csak ugy leveszi a const-ot?? marci@330: template marci@333: It loopFirst(const It&, const Graph& g) { marci@333: It e; g.first(e); return e; marci@330: } marci@330: marci@330: template marci@333: It loopFirst(const It&, const Graph& g, const Node& v) { marci@333: It e; g.first(e, v); return e; marci@330: } marci@330: marci@330: // template marci@330: // typename Graph::NodeIt loopFirstNode(const Graph& g) const { marci@330: // typename Graph::NodeIt e; g.first(e); return e; marci@330: // } marci@330: // template marci@330: // typename Graph::EdgeIt loopFirstEdge(const Graph& g) const { marci@330: // typename Graph::EdgeIt e; g.first(e); return e; marci@330: // } marci@330: // template marci@330: // typename Graph::OutEdgeIt marci@330: // loopFirstOutEdge(const Graph& g, const Node& n) const { marci@330: // typename Graph::OutEdgeIt e; g.first(e, n); return e; marci@330: // } marci@330: // template marci@330: // typename Graph::InEdgeIt marci@330: // loopFirstIn Edge(const Graph& g, const Node& n) const { marci@330: // typename Graph::InEdgeIt e; g.first(e, n); return e; marci@330: // } marci@330: marci@636: /// The iteration with HUGO iterators i.e. for cycles can be marci@636: /// written very comfortable with this macro. marci@636: /// \code marci@636: /// Graph g; marci@636: /// FOR_EACH_LOC(Graph::NodeIt, n, g) { marci@636: /// ... marci@636: /// } marci@636: /// FOR_EACH_LOC(Graph::EdgeIt, e, g) { marci@636: /// ... marci@636: /// } marci@636: /// In the above cycle, the iterator variable \c n and \c e are local ones. marci@636: /// \endcode marci@333: #define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e)) marci@636: marci@636: /// The iteration with HUGO iterators i.e. for cycles can be marci@636: /// written very comfortable with this macro. marci@636: /// \code marci@636: /// Graph g; marci@636: /// Graph::Node v; marci@636: /// FOR_EACH_INC_LOC(Graph::OutEdgeIt, e, g, v) { marci@636: /// ... marci@636: /// } marci@636: /// typedef BipartiteGraph BGraph; marci@636: /// BGraph h; marci@636: /// FOR_EACH_INC_LOC(BGraph::ClassNodeIt, n, h, h.S_CLASS) { marci@636: /// ... marci@636: /// } marci@636: /// In the above cycle, the iterator variable \c e and \c n are local ones. marci@636: /// \endcode marci@333: #define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e)) marci@330: marci@333: // #define FOR_EACH_EDGE_LOC(e, g) ezt nem tom hogy kell for((g).first((e)); (g).valid((e)); (g).next((e))) marci@330: // #define FOR_EACH_NODE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e))) marci@330: // #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e))) marci@330: // #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e))) marci@330: marci@330: marci@330: } //namespace hugo marci@330: marci@330: #endif //FOR_EACH_MACROS_H