COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/for_each_macros.h @ 691:014c2e4eb07b

Last change on this file since 691:014c2e4eb07b was 654:8fd893331298, checked in by marci, 21 years ago

The new for macros are: h_for, h_for_inc, h_for_glob, h_for_inc_glob.

File size: 5.5 KB
RevLine 
[330]1// -*- c++ -*-
[644]2#ifndef HUGO_FOR_EACH_MACROS_H
3#define HUGO_FOR_EACH_MACROS_H
[330]4
[636]5// /// \ingroup gwrappers
6/// \file
[638]7/// \brief Iteration macros.
[636]8///
9/// This file contains several macros which make easier writting
[638]10/// for cycles in HUGO using HUGO iterators.
[636]11///
12/// \author Marton Makai
13
[330]14namespace hugo {
15
[638]16  /// This macro provides a comfortable interface for iterating with HUGO
17  /// iterators.
18  /// \code
19  /// Graph g;
[639]20  /// ...
[638]21  /// Graph::NodeIt n;
[654]22  /// h_for_glob(n, g) {
[638]23  /// ...
24  /// }
25  /// Graph::EdgeIt e;
[654]26  /// h_for_glob(e, g) {
[638]27  /// ...
28  /// }
29  /// \endcode
30  /// Note that the iterated variables \c n and \c e are global ones.
[654]31#define h_for_glob(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
32
33/// \deprecated
[409]34#define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
[636]35
[638]36  /// This macro provides a comfortable interface for iterating with HUGO
37  /// iterators.
38  /// \code
39  /// Graph g;
[639]40  /// ...
[638]41  /// Graph::Node v;
42  /// Graph::OutEdgeIt e;
[654]43  /// h_for_inc_glob(e, g, v) {
[638]44  /// ...
45  /// }
46  /// typedef BipartiteGraph<Graph> BGraph;
47  /// BGraph h;
[639]48  /// ...
[638]49  /// BGraph::ClassNodeIt n;
[654]50  /// h_for_inc_glob(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
[638]51  /// ...
52  /// }
53  /// \endcode
54  /// Note that iterated variables \c e and \c n are global ones.
[654]55#define h_for_inc_glob(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
56
57/// \deprecated
[409]58#define FOR_EACH_INC_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
[638]59 
[636]60/// \deprecated
[638]61//#define FOR_EACH_EDGE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
[636]62/// \deprecated
[638]63//#define FOR_EACH_NODE_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
[636]64/// \deprecated
[638]65//#define FOR_EACH_INEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
[636]66/// \deprecated
[638]67//#define FOR_EACH_OUTEDGE_GLOB(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
[330]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>
[333]100  It loopFirst(const It&, const Graph& g) {
101    It e; g.first(e); return e;
[330]102  }
103
104  template<typename It, typename Graph, typename Node>
[333]105  It loopFirst(const It&, const Graph& g, const Node& v) {
106    It e; g.first(e, v); return e;
[330]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
[638]128  /// This macro provides a comfortable interface for iterating with HUGO
129  /// iterators.
130  /// \code
131  /// Graph g;
[639]132  /// ...
[654]133  /// h_for(Graph::NodeIt, n, g) {
[638]134  /// ...
135  /// }
[654]136  /// h_for(Graph::EdgeIt, e, g) {
[638]137  /// ...
138  /// }
139  /// \endcode
140  /// Note that the iterated variables \c n and \c e are local ones.
[654]141#define h_for(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
142 
143/// \deprecated
[333]144#define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
[654]145
[638]146  /// This macro provides a comfortable interface for iterating with HUGO
147  /// iterators.
148  /// \code
149  /// Graph g;
[639]150  /// ...
[638]151  /// Graph::Node v;
[654]152  /// h_for_inc(Graph::OutEdgeIt, e, g, v) {
[638]153  /// ...
154  /// }
155  /// typedef BipartiteGraph<Graph> BGraph;
156  /// BGraph h;
[639]157  /// ...
[654]158  /// h_for_inc(BGraph::ClassNodeIt, n, h, h.S_CLASS) {
[638]159  /// ...
160  /// }
161  /// \endcode
162  /// Note that the iterated variables \c e and \c n are local ones.
[654]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
[333]166#define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype e=loopFirst(Ittype(), (g), (v)); (g).valid(e); (g).next(e))
[638]167 
[333]168// #define FOR_EACH_EDGE_LOC(e, g) ezt nem tom hogy kell for((g).first((e)); (g).valid((e)); (g).next((e)))
[330]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
[644]175#endif //HUGO_FOR_EACH_MACROS_H
Note: See TracBrowser for help on using the repository browser.