alpar@725: // -*- c++ -*-
alpar@921: #ifndef LEMON_FOR_EACH_MACROS_H
alpar@921: #define LEMON_FOR_EACH_MACROS_H
alpar@725: 
alpar@725: // /// \ingroup gwrappers
alpar@725: /// \file
alpar@725: /// \brief Iteration macros.
alpar@725: ///
alpar@725: /// This file contains several macros which make easier writting 
alpar@921: /// for cycles in LEMON using LEMON iterators.
alpar@725: ///
alpar@725: /// \author Marton Makai
alpar@725: 
alpar@921: namespace lemon {
alpar@725: 
alpar@921:   /// This macro provides a comfortable interface for iterating with LEMON 
alpar@725:   /// iterators.
alpar@725:   /// \code
alpar@725:   /// Graph g;
alpar@725:   /// ...
alpar@725:   /// Graph::NodeIt n;
alpar@725:   /// h_for_glob(n, g) {
alpar@725:   /// ...
alpar@725:   /// }
alpar@725:   /// Graph::EdgeIt e;
alpar@725:   /// h_for_glob(e, g) {
alpar@725:   /// ...
alpar@725:   /// }
alpar@725:   /// \endcode
alpar@725:   /// Note that the iterated variables \c n and \c e are global ones. 
alpar@725: #define h_for_glob(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
alpar@725: 
alpar@725: /// \deprecated
alpar@725: #define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
alpar@725: 
alpar@921:   /// This macro provides a comfortable interface for iterating with LEMON 
alpar@725:   /// iterators.
alpar@725:   /// \code
alpar@725:   /// Graph g;
alpar@725:   /// ...
alpar@725:   /// Graph::Node v;
alpar@725:   /// Graph::OutEdgeIt e;
alpar@725:   /// h_for_inc_glob(e, g, v) {
alpar@725:   /// ...
alpar@725:   /// }
alpar@725:   /// typedef BipartiteGraph<Graph> BGraph;
alpar@725:   /// BGraph h;
alpar@725:   /// ...
alpar@725:   /// BGraph::ClassNodeIt n;
alpar@725:   /// h_for_inc_glob(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
alpar@725:   /// ...
alpar@725:   /// }
alpar@725:   /// \endcode
alpar@725:   /// Note that iterated variables \c e and \c n are global ones. 
alpar@725: #define h_for_inc_glob(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
alpar@725: 
alpar@725: /// \deprecated
alpar@725: #define FOR_EACH_INC_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
alpar@725:   
alpar@725: /// \deprecated
alpar@725: //#define FOR_EACH_EDGE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
alpar@725: /// \deprecated
alpar@725: //#define FOR_EACH_NODE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
alpar@725: /// \deprecated
alpar@725: //#define FOR_EACH_INEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
alpar@725: /// \deprecated
alpar@725: //#define FOR_EACH_OUTEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
alpar@725: 
alpar@725: //   template<typename It, typename Graph> 
alpar@725: //   It loopFirst(const Graph& g) const {
alpar@725: //     It e; g.first(e); return e; 
alpar@725: //   }
alpar@725: 
alpar@725: //   template<typename It, typename Graph> 
alpar@725: //   It loopFirst(const Graph& g, const Node& v) const {
alpar@725: //     It e; g.first(e, v); return e; 
alpar@725: //   }
alpar@725: 
alpar@725: //   template<typename Graph> 
alpar@725: //   typename Graph::NodeIt loopFirstNode(const Graph& g) const {
alpar@725: //     typename Graph::NodeIt e; g.first(e); return e; 
alpar@725: //   }
alpar@725: //   template<typename Graph> 
alpar@725: //   typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
alpar@725: //     typename Graph::EdgeIt e; g.first(e); return e; 
alpar@725: //   }
alpar@725: //   template<typename Graph> 
alpar@725: //   typename Graph::OutEdgeIt 
alpar@725: //   loopFirstOutEdge(const Graph& g, const Node& n) const {
alpar@725: //     typename Graph::OutEdgeIt e; g.first(e, n); return e; 
alpar@725: //   }
alpar@725: //   template<typename Graph> 
alpar@725: //   typename Graph::InEdgeIt 
alpar@725: //   loopFirstIn Edge(const Graph& g, const Node& n) const {
alpar@725: //     typename Graph::InEdgeIt e; g.first(e, n); return e; 
alpar@725: //   }
alpar@725: 
alpar@725: //FIXME ezt hogy a gorcsbe birja levezetni. Csak ugy leveszi a const-ot??
alpar@725:   template<typename It, typename Graph> 
alpar@725:   It loopFirst(const It&, const Graph& g) {
alpar@725:     It e; g.first(e); return e; 
alpar@725:   }
alpar@725: 
alpar@725:   template<typename It, typename Graph, typename Node> 
alpar@725:   It loopFirst(const It&, const Graph& g, const Node& v) {
alpar@725:     It e; g.first(e, v); return e; 
alpar@725:   }
alpar@725: 
alpar@725: //   template<typename Graph> 
alpar@725: //   typename Graph::NodeIt loopFirstNode(const Graph& g) const {
alpar@725: //     typename Graph::NodeIt e; g.first(e); return e; 
alpar@725: //   }
alpar@725: //   template<typename Graph> 
alpar@725: //   typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
alpar@725: //     typename Graph::EdgeIt e; g.first(e); return e; 
alpar@725: //   }
alpar@725: //   template<typename Graph> 
alpar@725: //   typename Graph::OutEdgeIt 
alpar@725: //   loopFirstOutEdge(const Graph& g, const Node& n) const {
alpar@725: //     typename Graph::OutEdgeIt e; g.first(e, n); return e; 
alpar@725: //   }
alpar@725: //   template<typename Graph> 
alpar@725: //   typename Graph::InEdgeIt 
alpar@725: //   loopFirstIn Edge(const Graph& g, const Node& n) const {
alpar@725: //     typename Graph::InEdgeIt e; g.first(e, n); return e; 
alpar@725: //   }
alpar@725: 
alpar@921:   /// This macro provides a comfortable interface for iterating with LEMON 
alpar@725:   /// iterators.
alpar@725:   /// \code
alpar@725:   /// Graph g;
alpar@725:   /// ...
alpar@725:   /// h_for(Graph::NodeIt, n, g) {
alpar@725:   /// ...
alpar@725:   /// }
alpar@725:   /// h_for(Graph::EdgeIt, e, g) {
alpar@725:   /// ...
alpar@725:   /// }
alpar@725:   /// \endcode
alpar@725:   /// Note that the iterated variables \c n and \c e are local ones. 
alpar@725: #define h_for(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
alpar@725:   
alpar@725: /// \deprecated
alpar@725: #define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
alpar@725: 
alpar@921:   /// This macro provides a comfortable interface for iterating with LEMON 
alpar@725:   /// iterators.
alpar@725:   /// \code
alpar@725:   /// Graph g;
alpar@725:   /// ...
alpar@725:   /// Graph::Node v;
alpar@725:   /// h_for_inc(Graph::OutEdgeIt, e, g, v) {
alpar@725:   /// ...
alpar@725:   /// }
alpar@725:   /// typedef BipartiteGraph<Graph> BGraph;
alpar@725:   /// BGraph h;
alpar@725:   /// ...
alpar@725:   /// h_for_inc(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
alpar@725:   /// ...
alpar@725:   /// }
alpar@725:   /// \endcode
alpar@725:   /// Note that the iterated variables \c e and \c n are local ones. 
alpar@725: #define h_for_inc(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
alpar@725:   
alpar@725: /// \deprecated
alpar@725: #define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
alpar@725:   
alpar@725: // #define FOR_EACH_EDGE_LOC(e, g) ezt nem tom hogy kell for((g).first((e)); (g).valid((e)); (g).next((e)))
alpar@725: // #define FOR_EACH_NODE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
alpar@725: // #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
alpar@725: // #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
alpar@725: 
alpar@921: } //namespace lemon
alpar@725: 
alpar@921: #endif //LEMON_FOR_EACH_MACROS_H