source: NonGTP/Boost/boost/graph/iteration_macros.hpp @ 857

Revision 857, 6.7 KB checked in by igarcia, 19 years ago (diff)
Line 
1//=======================================================================
2// Copyright 2001 Indiana University
3// Author: Jeremy G. Siek
4//
5// Distributed under the Boost Software License, Version 1.0. (See
6// accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//=======================================================================
9
10#ifndef BOOST_GRAPH_ITERATION_MACROS_HPP
11#define BOOST_GRAPH_ITERATION_MACROS_HPP
12
13#define BGL_CAT(x,y) x ## y
14#define BGL_FIRST(linenum) BGL_CAT(bgl_first_,linenum)
15#define BGL_LAST(linenum) BGL_CAT(bgl_last_,linenum)
16
17/*
18  BGL_FORALL_VERTICES_T(v, g, graph_t)  // This is on line 9
19  expands to the following, but all on the same line
20
21  for (typename boost::graph_traits<graph_t>::vertex_iterator
22           bgl_first_9 = vertices(g).first, bgl_last_9 = vertices(g).second;
23       bgl_first_9 != bgl_last_9; bgl_first_9 = bgl_last_9)
24    for (typename boost::graph_traits<graph_t>::vertex_descriptor v;
25         bgl_first_9 != bgl_last ? (v = *bgl_first_9, true) : false;
26         ++bgl_first_9)
27
28  The purpose of having two for-loops is just to provide a place to
29  declare both the iterator and value variables. There is really only
30  one loop. The stopping condition gets executed two more times than it
31  usually would be, oh well. The reason for the bgl_first_9 = bgl_last_9
32  in the outer for-loop is in case the user puts a break statement
33  in the inner for-loop.
34
35  The other macros work in a similar fashion.
36
37  Use the _T versions when the graph type is a template parameter or
38  dependent on a template parameter. Otherwise use the non _T versions.
39 
40 */
41
42
43#define BGL_FORALL_VERTICES_T(VNAME, GNAME, GraphType) \
44for (typename boost::graph_traits<GraphType>::vertex_iterator \
45  BGL_FIRST(__LINE__) = vertices(GNAME).first, BGL_LAST(__LINE__) = vertices(GNAME).second; \
46  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
47  for (typename boost::graph_traits<GraphType>::vertex_descriptor VNAME; \
48    BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true):false; \
49     ++BGL_FIRST(__LINE__))
50
51#define BGL_FORALL_VERTICES(VNAME, GNAME, GraphType) \
52for (boost::graph_traits<GraphType>::vertex_iterator \
53  BGL_FIRST(__LINE__) = vertices(GNAME).first, BGL_LAST(__LINE__) = vertices(GNAME).second; \
54  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
55  for (boost::graph_traits<GraphType>::vertex_descriptor VNAME; \
56    BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true):false; \
57     ++BGL_FIRST(__LINE__))
58
59#define BGL_FORALL_EDGES_T(ENAME, GNAME, GraphType) \
60for (typename boost::graph_traits<GraphType>::edge_iterator \
61  BGL_FIRST(__LINE__) = edges(GNAME).first, BGL_LAST(__LINE__) = edges(GNAME).second; \
62  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
63  for (typename boost::graph_traits<GraphType>::edge_descriptor ENAME; \
64    BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true):false; \
65     ++BGL_FIRST(__LINE__))
66
67#define BGL_FORALL_EDGES(ENAME, GNAME, GraphType) \
68for (boost::graph_traits<GraphType>::edge_iterator \
69  BGL_FIRST(__LINE__) = edges(GNAME).first, BGL_LAST(__LINE__) = edges(GNAME).second; \
70  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
71  for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \
72     BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true):false; \
73     ++BGL_FIRST(__LINE__))
74
75#define BGL_FORALL_ADJ_T(UNAME, VNAME, GNAME, GraphType) \
76for (typename boost::graph_traits<GraphType>::adjacency_iterator \
77  BGL_FIRST(__LINE__) = adjacent_vertices(UNAME, GNAME).first,\
78  BGL_LAST(__LINE__) = adjacent_vertices(UNAME, GNAME).second; \
79  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
80for (typename boost::graph_traits<GraphType>::vertex_descriptor VNAME; \
81  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true) : false; \
82   ++BGL_FIRST(__LINE__))
83
84#define BGL_FORALL_ADJ(UNAME, VNAME, GNAME, GraphType) \
85for (boost::graph_traits<GraphType>::adjacency_iterator \
86  BGL_FIRST(__LINE__) = adjacent_vertices(UNAME, GNAME).first,\
87  BGL_LAST(__LINE__) = adjacent_vertices(UNAME, GNAME).second; \
88  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
89for (boost::graph_traits<GraphType>::vertex_descriptor VNAME; \
90  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true) : false; \
91   ++BGL_FIRST(__LINE__))
92
93#define BGL_FORALL_OUTEDGES_T(UNAME, ENAME, GNAME, GraphType) \
94for (typename boost::graph_traits<GraphType>::out_edge_iterator \
95  BGL_FIRST(__LINE__) = out_edges(UNAME, GNAME).first,\
96  BGL_LAST(__LINE__) = out_edges(UNAME, GNAME).second; \
97  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
98for (typename boost::graph_traits<GraphType>::edge_descriptor ENAME; \
99  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \
100   ++BGL_FIRST(__LINE__))
101
102#define BGL_FORALL_OUTEDGES(UNAME, ENAME, GNAME, GraphType) \
103for (boost::graph_traits<GraphType>::out_edge_iterator \
104  BGL_FIRST(__LINE__) = out_edges(UNAME, GNAME).first,\
105  BGL_LAST(__LINE__) = out_edges(UNAME, GNAME).second; \
106  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
107for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \
108  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \
109   ++BGL_FIRST(__LINE__))
110
111#define BGL_FORALL_INEDGES_T(UNAME, ENAME, GNAME, GraphType) \
112for (typename boost::graph_traits<GraphType>::in_edge_iterator \
113  BGL_FIRST(__LINE__) = in_edges(UNAME, GNAME).first,\
114  BGL_LAST(__LINE__) = in_edges(UNAME, GNAME).second; \
115  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
116for (typename boost::graph_traits<GraphType>::edge_descriptor ENAME; \
117  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \
118   ++BGL_FIRST(__LINE__))
119
120#define BGL_FORALL_INEDGES(UNAME, ENAME, GNAME, GraphType) \
121for (boost::graph_traits<GraphType>::in_edge_iterator \
122  BGL_FIRST(__LINE__) = in_edges(UNAME, GNAME).first,\
123  BGL_LAST(__LINE__) = in_edges(UNAME, GNAME).second; \
124  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
125for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \
126  BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \
127   ++BGL_FIRST(__LINE__))
128
129#endif // BOOST_GRAPH_ITERATION_MACROS_HPP
Note: See TracBrowser for help on using the repository browser.