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