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