sl@0: //======================================================================= sl@0: // Copyright 2001 Indiana University sl@0: // Author: Jeremy G. Siek sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: //======================================================================= sl@0: sl@0: #ifndef BOOST_GRAPH_ITERATION_MACROS_HPP sl@0: #define BOOST_GRAPH_ITERATION_MACROS_HPP sl@0: sl@0: #define BGL_CAT(x,y) x ## y sl@0: #define BGL_FIRST(linenum) BGL_CAT(bgl_first_,linenum) sl@0: #define BGL_LAST(linenum) BGL_CAT(bgl_last_,linenum) sl@0: sl@0: /* sl@0: BGL_FORALL_VERTICES_T(v, g, graph_t) // This is on line 9 sl@0: expands to the following, but all on the same line sl@0: sl@0: for (typename boost::graph_traits::vertex_iterator sl@0: bgl_first_9 = vertices(g).first, bgl_last_9 = vertices(g).second; sl@0: bgl_first_9 != bgl_last_9; bgl_first_9 = bgl_last_9) sl@0: for (typename boost::graph_traits::vertex_descriptor v; sl@0: bgl_first_9 != bgl_last ? (v = *bgl_first_9, true) : false; sl@0: ++bgl_first_9) sl@0: sl@0: The purpose of having two for-loops is just to provide a place to sl@0: declare both the iterator and value variables. There is really only sl@0: one loop. The stopping condition gets executed two more times than it sl@0: usually would be, oh well. The reason for the bgl_first_9 = bgl_last_9 sl@0: in the outer for-loop is in case the user puts a break statement sl@0: in the inner for-loop. sl@0: sl@0: The other macros work in a similar fashion. sl@0: sl@0: Use the _T versions when the graph type is a template parameter or sl@0: dependent on a template parameter. Otherwise use the non _T versions. sl@0: sl@0: */ sl@0: sl@0: sl@0: #define BGL_FORALL_VERTICES_T(VNAME, GNAME, GraphType) \ sl@0: for (typename boost::graph_traits::vertex_iterator \ sl@0: BGL_FIRST(__LINE__) = vertices(GNAME).first, BGL_LAST(__LINE__) = vertices(GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (typename boost::graph_traits::vertex_descriptor VNAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true):false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_VERTICES(VNAME, GNAME, GraphType) \ sl@0: for (boost::graph_traits::vertex_iterator \ sl@0: BGL_FIRST(__LINE__) = vertices(GNAME).first, BGL_LAST(__LINE__) = vertices(GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (boost::graph_traits::vertex_descriptor VNAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true):false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_EDGES_T(ENAME, GNAME, GraphType) \ sl@0: for (typename boost::graph_traits::edge_iterator \ sl@0: BGL_FIRST(__LINE__) = edges(GNAME).first, BGL_LAST(__LINE__) = edges(GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (typename boost::graph_traits::edge_descriptor ENAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true):false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_EDGES(ENAME, GNAME, GraphType) \ sl@0: for (boost::graph_traits::edge_iterator \ sl@0: BGL_FIRST(__LINE__) = edges(GNAME).first, BGL_LAST(__LINE__) = edges(GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (boost::graph_traits::edge_descriptor ENAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true):false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_ADJ_T(UNAME, VNAME, GNAME, GraphType) \ sl@0: for (typename boost::graph_traits::adjacency_iterator \ sl@0: BGL_FIRST(__LINE__) = adjacent_vertices(UNAME, GNAME).first,\ sl@0: BGL_LAST(__LINE__) = adjacent_vertices(UNAME, GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (typename boost::graph_traits::vertex_descriptor VNAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true) : false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_ADJ(UNAME, VNAME, GNAME, GraphType) \ sl@0: for (boost::graph_traits::adjacency_iterator \ sl@0: BGL_FIRST(__LINE__) = adjacent_vertices(UNAME, GNAME).first,\ sl@0: BGL_LAST(__LINE__) = adjacent_vertices(UNAME, GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (boost::graph_traits::vertex_descriptor VNAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true) : false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_OUTEDGES_T(UNAME, ENAME, GNAME, GraphType) \ sl@0: for (typename boost::graph_traits::out_edge_iterator \ sl@0: BGL_FIRST(__LINE__) = out_edges(UNAME, GNAME).first,\ sl@0: BGL_LAST(__LINE__) = out_edges(UNAME, GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (typename boost::graph_traits::edge_descriptor ENAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_OUTEDGES(UNAME, ENAME, GNAME, GraphType) \ sl@0: for (boost::graph_traits::out_edge_iterator \ sl@0: BGL_FIRST(__LINE__) = out_edges(UNAME, GNAME).first,\ sl@0: BGL_LAST(__LINE__) = out_edges(UNAME, GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (boost::graph_traits::edge_descriptor ENAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_INEDGES_T(UNAME, ENAME, GNAME, GraphType) \ sl@0: for (typename boost::graph_traits::in_edge_iterator \ sl@0: BGL_FIRST(__LINE__) = in_edges(UNAME, GNAME).first,\ sl@0: BGL_LAST(__LINE__) = in_edges(UNAME, GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (typename boost::graph_traits::edge_descriptor ENAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #define BGL_FORALL_INEDGES(UNAME, ENAME, GNAME, GraphType) \ sl@0: for (boost::graph_traits::in_edge_iterator \ sl@0: BGL_FIRST(__LINE__) = in_edges(UNAME, GNAME).first,\ sl@0: BGL_LAST(__LINE__) = in_edges(UNAME, GNAME).second; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ sl@0: for (boost::graph_traits::edge_descriptor ENAME; \ sl@0: BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \ sl@0: ++BGL_FIRST(__LINE__)) sl@0: sl@0: #endif // BOOST_GRAPH_ITERATION_MACROS_HPP