src/hugo/for_each_macros.h
author marci
Thu, 20 May 2004 17:21:55 +0000
changeset 652 4dfa1f79bf3e
parent 639 a11a4377a816
child 654 8fd893331298
permissions -rw-r--r--
misc
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@638
    22
  /// FOR_EACH_GLOB(n, g) {
marci@638
    23
  /// ...
marci@638
    24
  /// }
marci@638
    25
  /// Graph::EdgeIt e;
marci@638
    26
  /// FOR_EACH_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@409
    31
#define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
marci@636
    32
marci@638
    33
  /// This macro provides a comfortable interface for iterating with HUGO 
marci@638
    34
  /// iterators.
marci@638
    35
  /// \code
marci@638
    36
  /// Graph g;
marci@639
    37
  /// ...
marci@638
    38
  /// Graph::Node v;
marci@638
    39
  /// Graph::OutEdgeIt e;
marci@638
    40
  /// FOR_EACH_INC_GLOB(e, g, v) {
marci@638
    41
  /// ...
marci@638
    42
  /// }
marci@638
    43
  /// typedef BipartiteGraph<Graph> BGraph;
marci@638
    44
  /// BGraph h;
marci@639
    45
  /// ...
marci@638
    46
  /// BGraph::ClassNodeIt n;
marci@638
    47
  /// FOR_EACH_INC_GLOB(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
marci@638
    48
  /// ...
marci@638
    49
  /// }
marci@638
    50
  /// \endcode
marci@638
    51
  /// Note that iterated variables \c e and \c n are global ones. 
marci@409
    52
#define FOR_EACH_INC_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
marci@638
    53
  
marci@636
    54
/// \deprecated
marci@638
    55
//#define FOR_EACH_EDGE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
marci@636
    56
/// \deprecated
marci@638
    57
//#define FOR_EACH_NODE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
marci@636
    58
/// \deprecated
marci@638
    59
//#define FOR_EACH_INEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
marci@636
    60
/// \deprecated
marci@638
    61
//#define FOR_EACH_OUTEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
marci@330
    62
marci@330
    63
//   template<typename It, typename Graph> 
marci@330
    64
//   It loopFirst(const Graph& g) const {
marci@330
    65
//     It e; g.first(e); return e; 
marci@330
    66
//   }
marci@330
    67
marci@330
    68
//   template<typename It, typename Graph> 
marci@330
    69
//   It loopFirst(const Graph& g, const Node& v) const {
marci@330
    70
//     It e; g.first(e, v); return e; 
marci@330
    71
//   }
marci@330
    72
marci@330
    73
//   template<typename Graph> 
marci@330
    74
//   typename Graph::NodeIt loopFirstNode(const Graph& g) const {
marci@330
    75
//     typename Graph::NodeIt e; g.first(e); return e; 
marci@330
    76
//   }
marci@330
    77
//   template<typename Graph> 
marci@330
    78
//   typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
marci@330
    79
//     typename Graph::EdgeIt e; g.first(e); return e; 
marci@330
    80
//   }
marci@330
    81
//   template<typename Graph> 
marci@330
    82
//   typename Graph::OutEdgeIt 
marci@330
    83
//   loopFirstOutEdge(const Graph& g, const Node& n) const {
marci@330
    84
//     typename Graph::OutEdgeIt e; g.first(e, n); return e; 
marci@330
    85
//   }
marci@330
    86
//   template<typename Graph> 
marci@330
    87
//   typename Graph::InEdgeIt 
marci@330
    88
//   loopFirstIn Edge(const Graph& g, const Node& n) const {
marci@330
    89
//     typename Graph::InEdgeIt e; g.first(e, n); return e; 
marci@330
    90
//   }
marci@330
    91
marci@330
    92
//FIXME ezt hogy a gorcsbe birja levezetni. Csak ugy leveszi a const-ot??
marci@330
    93
  template<typename It, typename Graph> 
marci@333
    94
  It loopFirst(const It&, const Graph& g) {
marci@333
    95
    It e; g.first(e); return e; 
marci@330
    96
  }
marci@330
    97
marci@330
    98
  template<typename It, typename Graph, typename Node> 
marci@333
    99
  It loopFirst(const It&, const Graph& g, const Node& v) {
marci@333
   100
    It e; g.first(e, v); return e; 
marci@330
   101
  }
marci@330
   102
marci@330
   103
//   template<typename Graph> 
marci@330
   104
//   typename Graph::NodeIt loopFirstNode(const Graph& g) const {
marci@330
   105
//     typename Graph::NodeIt e; g.first(e); return e; 
marci@330
   106
//   }
marci@330
   107
//   template<typename Graph> 
marci@330
   108
//   typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
marci@330
   109
//     typename Graph::EdgeIt e; g.first(e); return e; 
marci@330
   110
//   }
marci@330
   111
//   template<typename Graph> 
marci@330
   112
//   typename Graph::OutEdgeIt 
marci@330
   113
//   loopFirstOutEdge(const Graph& g, const Node& n) const {
marci@330
   114
//     typename Graph::OutEdgeIt e; g.first(e, n); return e; 
marci@330
   115
//   }
marci@330
   116
//   template<typename Graph> 
marci@330
   117
//   typename Graph::InEdgeIt 
marci@330
   118
//   loopFirstIn Edge(const Graph& g, const Node& n) const {
marci@330
   119
//     typename Graph::InEdgeIt e; g.first(e, n); return e; 
marci@330
   120
//   }
marci@330
   121
marci@638
   122
  /// This macro provides a comfortable interface for iterating with HUGO 
marci@638
   123
  /// iterators.
marci@638
   124
  /// \code
marci@638
   125
  /// Graph g;
marci@639
   126
  /// ...
marci@638
   127
  /// FOR_EACH_LOC(Graph::NodeIt, n, g) {
marci@638
   128
  /// ...
marci@638
   129
  /// }
marci@638
   130
  /// FOR_EACH_LOC(Graph::EdgeIt, e, g) {
marci@638
   131
  /// ...
marci@638
   132
  /// }
marci@638
   133
  /// \endcode
marci@638
   134
  /// Note that the iterated variables \c n and \c e are local ones. 
marci@333
   135
#define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
marci@638
   136
  
marci@638
   137
  /// This macro provides a comfortable interface for iterating with HUGO 
marci@638
   138
  /// iterators.
marci@638
   139
  /// \code
marci@638
   140
  /// Graph g;
marci@639
   141
  /// ...
marci@638
   142
  /// Graph::Node v;
marci@638
   143
  /// FOR_EACH_INC_LOC(Graph::OutEdgeIt, e, g, v) {
marci@638
   144
  /// ...
marci@638
   145
  /// }
marci@638
   146
  /// typedef BipartiteGraph<Graph> BGraph;
marci@638
   147
  /// BGraph h;
marci@639
   148
  /// ...
marci@638
   149
  /// FOR_EACH_INC_LOC(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
marci@638
   150
  /// ...
marci@638
   151
  /// }
marci@638
   152
  /// \endcode
marci@638
   153
  /// Note that the iterated variables \c e and \c n are local ones. 
marci@333
   154
#define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
marci@638
   155
  
marci@333
   156
// #define FOR_EACH_EDGE_LOC(e, g) ezt nem tom hogy kell for((g).first((e)); (g).valid((e)); (g).next((e)))
marci@330
   157
// #define FOR_EACH_NODE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
marci@330
   158
// #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
marci@330
   159
// #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
marci@330
   160
marci@330
   161
marci@330
   162
} //namespace hugo
marci@330
   163
marci@644
   164
#endif //HUGO_FOR_EACH_MACROS_H