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