Ticket #3155: bgl.diff
File bgl.diff, 12.0 KB (added by , 13 years ago) |
---|
-
iteration_macros.hpp
10 10 #ifndef BOOST_GRAPH_ITERATION_MACROS_HPP 11 11 #define BOOST_GRAPH_ITERATION_MACROS_HPP 12 12 13 #include <utility> 14 13 15 #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 #define BGL_RANGE(linenum) BGL_CAT(bgl_range_,linenum) 16 17 17 18 /* 18 19 BGL_FORALL_VERTICES_T(v, g, graph_t) // This is on line 9 19 20 expands to the following, but all on the same line 20 21 21 22 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)23 BGL_FIRST_9 = vertices(g).first, BGL_LAST_9 = vertices(g).second; 24 BGL_FIRST_9 != BGL_LAST_9; BGL_FIRST_9 = BGL_LAST_9) 24 25 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)26 BGL_FIRST_9 != BGL_LAST_9 ? (v = *BGL_FIRST_9, true) : false; 27 ++BGL_FIRST_9) 27 28 28 29 The purpose of having two for-loops is just to provide a place to 29 30 declare both the iterator and value variables. There is really only 30 31 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_932 usually would be, oh well. The reason for the BGL_RANGE_9 = BGL_RANGE_9 32 33 in the outer for-loop is in case the user puts a break statement 33 34 in the inner for-loop. 34 35 … … 37 38 Use the _T versions when the graph type is a template parameter or 38 39 dependent on a template parameter. Otherwise use the non _T versions. 39 40 41 ----------------------- 42 6/9/09 THK 43 44 The above contains two calls to the vertices function. I modified these 45 macros to expand to 46 47 for (std::pair<typename boost::graph_traits<graph_t>::vertex_iterator, 48 typename boost::graph_traits<graph_t>::vertex_iterator> BGL_RANGE_9 = vertices(g); 49 BGL_RANGE_9.first != BGL_RANGE_9.second; 50 BGL_RANGE_9.first = BGL_RANGE_9.second) 51 for (typename boost::graph_traits<graph_t>::vertex_descriptor v; 52 BGL_RANGE_9.first != BGL_RANGE_9.second ? (v = *BGL_RANGE_9.first, true) : false; 53 ++BGL_RANGE_9.first) 54 55 40 56 */ 41 57 42 58 43 59 #define BGL_FORALL_VERTICES_T(VNAME, GNAME, GraphType) \ 44 for (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__)) \ 60 for (std::pair<typename boost::graph_traits<GraphType>::vertex_iterator, \ 61 typename boost::graph_traits<GraphType>::vertex_iterator> BGL_RANGE(__LINE__) = vertices(GNAME); \ 62 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 63 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 47 64 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__))65 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (VNAME = *BGL_RANGE(__LINE__).first, true):false; \ 66 ++BGL_RANGE(__LINE__).first) 50 67 51 68 #define BGL_FORALL_VERTICES(VNAME, GNAME, GraphType) \ 52 for (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__)) \ 69 for (std::pair<boost::graph_traits<GraphType>::vertex_iterator, \ 70 boost::graph_traits<GraphType>::vertex_iterator> BGL_RANGE(__LINE__) = vertices(GNAME); \ 71 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 72 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 55 73 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__))74 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (VNAME = *BGL_RANGE(__LINE__).first, true):false; \ 75 ++BGL_RANGE(__LINE__).first) 58 76 59 77 #define BGL_FORALL_EDGES_T(ENAME, GNAME, GraphType) \ 60 for (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__)) \ 78 for (std::pair<typename boost::graph_traits<GraphType>::edge_iterator, \ 79 typename boost::graph_traits<GraphType>::edge_iterator> BGL_RANGE(__LINE__) = edges(GNAME); \ 80 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 81 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 63 82 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__))83 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (ENAME = *BGL_RANGE(__LINE__).first, true):false; \ 84 ++BGL_RANGE(__LINE__).first) 66 85 67 86 #define BGL_FORALL_EDGES(ENAME, GNAME, GraphType) \ 68 for (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__)) \ 87 for (std::pair<boost::graph_traits<GraphType>::edge_iterator, \ 88 boost::graph_traits<GraphType>::edge_iterator> BGL_RANGE(__LINE__) = edges(GNAME); \ 89 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 90 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 71 91 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__))92 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (ENAME = *BGL_RANGE(__LINE__).first, true):false; \ 93 ++BGL_RANGE(__LINE__).first) 74 94 75 95 #define BGL_FORALL_ADJ_T(UNAME, VNAME, GNAME, GraphType) \ 76 for ( 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__)) \96 for (std::pair<typename boost::graph_traits<GraphType>::adjacency_iterator, \ 97 typename boost::graph_traits<GraphType>::adjacency_iterator> BGL_RANGE(__LINE__) = adjacent_vertices(UNAME, GNAME); \ 98 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 99 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 80 100 for (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__))101 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (VNAME = *BGL_RANGE(__LINE__).first, true) : false; \ 102 ++BGL_RANGE(__LINE__).first) 83 103 84 104 #define BGL_FORALL_ADJ(UNAME, VNAME, GNAME, GraphType) \ 85 for ( 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__)) \105 for (std::pair<boost::graph_traits<GraphType>::adjacency_iterator, \ 106 boost::graph_traits<GraphType>::adjacency_iterator> BGL_RANGE(__LINE__) = adjacent_vertices(UNAME, GNAME); \ 107 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 108 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 89 109 for (boost::graph_traits<GraphType>::vertex_descriptor VNAME; \ 90 BGL_ FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true) : false; \91 ++BGL_ FIRST(__LINE__))110 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (VNAME = *BGL_RANGE(__LINE__).first, true) : false; \ 111 ++BGL_RANGE(__LINE__).first) 92 112 93 113 #define BGL_FORALL_OUTEDGES_T(UNAME, ENAME, GNAME, GraphType) \ 94 for ( 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__)) \114 for (std::pair<typename boost::graph_traits<GraphType>::out_edge_iterator, \ 115 typename boost::graph_traits<GraphType>::out_edge_iterator> BGL_RANGE(__LINE__) = out_edges(UNAME, GNAME); \ 116 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 117 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 98 118 for (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__))119 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (ENAME = *BGL_RANGE(__LINE__).first, true) : false; \ 120 ++BGL_RANGE(__LINE__).first) 101 121 102 122 #define BGL_FORALL_OUTEDGES(UNAME, ENAME, GNAME, GraphType) \ 103 for ( 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__)) \123 for (std::pair<boost::graph_traits<GraphType>::out_edge_iterator, \ 124 boost::graph_traits<GraphType>::out_edge_iterator> BGL_RANGE(__LINE__) = out_edges(UNAME, GNAME); \ 125 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 126 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 107 127 for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \ 108 BGL_ FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \109 ++BGL_ FIRST(__LINE__))128 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (ENAME = *BGL_RANGE(__LINE__).first, true) : false; \ 129 ++BGL_RANGE(__LINE__).first) 110 130 111 131 #define BGL_FORALL_INEDGES_T(UNAME, ENAME, GNAME, GraphType) \ 112 for ( 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__)) \132 for (std::pair<typename boost::graph_traits<GraphType>::in_edge_iterator, \ 133 typename boost::graph_traits<GraphType>::in_edge_iterator> BGL_RANGE(__LINE__) = in_edges(UNAME, GNAME); \ 134 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 135 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 116 136 for (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__))137 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (ENAME = *BGL_RANGE(__LINE__).first, true) : false; \ 138 ++BGL_RANGE(__LINE__).first) 119 139 120 140 #define BGL_FORALL_INEDGES(UNAME, ENAME, GNAME, GraphType) \ 121 for ( 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__)) \141 for (std::pair<boost::graph_traits<GraphType>::in_edge_iterator, \ 142 boost::graph_traits<GraphType>::in_edge_iterator> BGL_RANGE(__LINE__) = in_edges(UNAME, GNAME); \ 143 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second; \ 144 BGL_RANGE(__LINE__).first = BGL_RANGE(__LINE__).second) \ 125 145 for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \ 126 BGL_ FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \127 ++BGL_ FIRST(__LINE__))146 BGL_RANGE(__LINE__).first != BGL_RANGE(__LINE__).second ? (ENAME = *BGL_RANGE(__LINE__).first, true) : false; \ 147 ++BGL_RANGE(__LINE__).first) 128 148 129 149 #endif // BOOST_GRAPH_ITERATION_MACROS_HPP