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