src/work/marci/for_each_macros.h
changeset 808 9cabbdd73375
child 921 818510fa3d99
equal deleted inserted replaced
-1:000000000000 4:b24f6eb44aba
       
     1 // -*- c++ -*-
       
     2 #ifndef HUGO_FOR_EACH_MACROS_H
       
     3 #define HUGO_FOR_EACH_MACROS_H
       
     4 
       
     5 // /// \ingroup gwrappers
       
     6 /// \file
       
     7 /// \brief Iteration 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 
       
    14 namespace hugo {
       
    15 
       
    16   /// This macro provides a comfortable interface for iterating with HUGO 
       
    17   /// iterators.
       
    18   /// \code
       
    19   /// Graph g;
       
    20   /// ...
       
    21   /// Graph::NodeIt n;
       
    22   /// h_for_glob(n, g) {
       
    23   /// ...
       
    24   /// }
       
    25   /// Graph::EdgeIt e;
       
    26   /// h_for_glob(e, g) {
       
    27   /// ...
       
    28   /// }
       
    29   /// \endcode
       
    30   /// Note that the iterated variables \c n and \c e are global ones. 
       
    31 #define h_for_glob(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
       
    32 
       
    33 /// \deprecated
       
    34 #define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
       
    35 
       
    36   /// This macro provides a comfortable interface for iterating with HUGO 
       
    37   /// iterators.
       
    38   /// \code
       
    39   /// Graph g;
       
    40   /// ...
       
    41   /// Graph::Node v;
       
    42   /// Graph::OutEdgeIt e;
       
    43   /// h_for_inc_glob(e, g, v) {
       
    44   /// ...
       
    45   /// }
       
    46   /// typedef BipartiteGraph<Graph> BGraph;
       
    47   /// BGraph h;
       
    48   /// ...
       
    49   /// BGraph::ClassNodeIt n;
       
    50   /// h_for_inc_glob(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
       
    51   /// ...
       
    52   /// }
       
    53   /// \endcode
       
    54   /// Note that iterated variables \c e and \c n are global ones. 
       
    55 #define h_for_inc_glob(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
       
    56 
       
    57 /// \deprecated
       
    58 #define FOR_EACH_INC_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
       
    59   
       
    60 /// \deprecated
       
    61 //#define FOR_EACH_EDGE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
       
    62 /// \deprecated
       
    63 //#define FOR_EACH_NODE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
       
    64 /// \deprecated
       
    65 //#define FOR_EACH_INEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
       
    66 /// \deprecated
       
    67 //#define FOR_EACH_OUTEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
       
    68 
       
    69 //   template<typename It, typename Graph> 
       
    70 //   It loopFirst(const Graph& g) const {
       
    71 //     It e; g.first(e); return e; 
       
    72 //   }
       
    73 
       
    74 //   template<typename It, typename Graph> 
       
    75 //   It loopFirst(const Graph& g, const Node& v) const {
       
    76 //     It e; g.first(e, v); return e; 
       
    77 //   }
       
    78 
       
    79 //   template<typename Graph> 
       
    80 //   typename Graph::NodeIt loopFirstNode(const Graph& g) const {
       
    81 //     typename Graph::NodeIt e; g.first(e); return e; 
       
    82 //   }
       
    83 //   template<typename Graph> 
       
    84 //   typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
       
    85 //     typename Graph::EdgeIt e; g.first(e); return e; 
       
    86 //   }
       
    87 //   template<typename Graph> 
       
    88 //   typename Graph::OutEdgeIt 
       
    89 //   loopFirstOutEdge(const Graph& g, const Node& n) const {
       
    90 //     typename Graph::OutEdgeIt e; g.first(e, n); return e; 
       
    91 //   }
       
    92 //   template<typename Graph> 
       
    93 //   typename Graph::InEdgeIt 
       
    94 //   loopFirstIn Edge(const Graph& g, const Node& n) const {
       
    95 //     typename Graph::InEdgeIt e; g.first(e, n); return e; 
       
    96 //   }
       
    97 
       
    98 //FIXME ezt hogy a gorcsbe birja levezetni. Csak ugy leveszi a const-ot??
       
    99   template<typename It, typename Graph> 
       
   100   It loopFirst(const It&, const Graph& g) {
       
   101     It e; g.first(e); return e; 
       
   102   }
       
   103 
       
   104   template<typename It, typename Graph, typename Node> 
       
   105   It loopFirst(const It&, const Graph& g, const Node& v) {
       
   106     It e; g.first(e, v); return e; 
       
   107   }
       
   108 
       
   109 //   template<typename Graph> 
       
   110 //   typename Graph::NodeIt loopFirstNode(const Graph& g) const {
       
   111 //     typename Graph::NodeIt e; g.first(e); return e; 
       
   112 //   }
       
   113 //   template<typename Graph> 
       
   114 //   typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
       
   115 //     typename Graph::EdgeIt e; g.first(e); return e; 
       
   116 //   }
       
   117 //   template<typename Graph> 
       
   118 //   typename Graph::OutEdgeIt 
       
   119 //   loopFirstOutEdge(const Graph& g, const Node& n) const {
       
   120 //     typename Graph::OutEdgeIt e; g.first(e, n); return e; 
       
   121 //   }
       
   122 //   template<typename Graph> 
       
   123 //   typename Graph::InEdgeIt 
       
   124 //   loopFirstIn Edge(const Graph& g, const Node& n) const {
       
   125 //     typename Graph::InEdgeIt e; g.first(e, n); return e; 
       
   126 //   }
       
   127 
       
   128   /// This macro provides a comfortable interface for iterating with HUGO 
       
   129   /// iterators.
       
   130   /// \code
       
   131   /// Graph g;
       
   132   /// ...
       
   133   /// h_for(Graph::NodeIt, n, g) {
       
   134   /// ...
       
   135   /// }
       
   136   /// h_for(Graph::EdgeIt, e, g) {
       
   137   /// ...
       
   138   /// }
       
   139   /// \endcode
       
   140   /// Note that the iterated variables \c n and \c e are local ones. 
       
   141 #define h_for(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
       
   142   
       
   143 /// \deprecated
       
   144 #define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
       
   145 
       
   146   /// This macro provides a comfortable interface for iterating with HUGO 
       
   147   /// iterators.
       
   148   /// \code
       
   149   /// Graph g;
       
   150   /// ...
       
   151   /// Graph::Node v;
       
   152   /// h_for_inc(Graph::OutEdgeIt, e, g, v) {
       
   153   /// ...
       
   154   /// }
       
   155   /// typedef BipartiteGraph<Graph> BGraph;
       
   156   /// BGraph h;
       
   157   /// ...
       
   158   /// h_for_inc(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
       
   159   /// ...
       
   160   /// }
       
   161   /// \endcode
       
   162   /// Note that the iterated variables \c e and \c n are local ones. 
       
   163 #define h_for_inc(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
       
   164   
       
   165 /// \deprecated
       
   166 #define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
       
   167   
       
   168 // #define FOR_EACH_EDGE_LOC(e, g) ezt nem tom hogy kell for((g).first((e)); (g).valid((e)); (g).next((e)))
       
   169 // #define FOR_EACH_NODE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
       
   170 // #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
       
   171 // #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
       
   172 
       
   173 } //namespace hugo
       
   174 
       
   175 #endif //HUGO_FOR_EACH_MACROS_H