Ticket #3155: bgl.diff

File bgl.diff, 12.0 KB (added by tkeitt@…, 13 years ago)

svn diff

  • iteration_macros.hpp

     
    1010#ifndef BOOST_GRAPH_ITERATION_MACROS_HPP
    1111#define BOOST_GRAPH_ITERATION_MACROS_HPP
    1212
     13#include <utility>
     14
    1315#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)
    1617
    1718/*
    1819  BGL_FORALL_VERTICES_T(v, g, graph_t)  // This is on line 9
    1920  expands to the following, but all on the same line
    2021
    2122  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)
    2425    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)
    2728
    2829  The purpose of having two for-loops is just to provide a place to
    2930  declare both the iterator and value variables. There is really only
    3031  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  usually would be, oh well. The reason for the BGL_RANGE_9 = BGL_RANGE_9
    3233  in the outer for-loop is in case the user puts a break statement
    3334  in the inner for-loop.
    3435
     
    3738  Use the _T versions when the graph type is a template parameter or
    3839  dependent on a template parameter. Otherwise use the non _T versions.
    3940 
     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 
    4056 */
    4157
    4258
    4359#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__)) \
     60for (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) \
    4764  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)
    5067
    5168#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__)) \
     69for (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) \
    5573  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)
    5876
    5977#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__)) \
     78for (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) \
    6382  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)
    6685
    6786#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__)) \
     87for (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) \
    7191  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)
    7494
    7595#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__)) \
     96for (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) \
    80100for (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)
    83103
    84104#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__)) \
     105for (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) \
    89109for (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)
    92112
    93113#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__)) \
     114for (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) \
    98118for (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)
    101121
    102122#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__)) \
     123for (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) \
    107127for (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)
    110130
    111131#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__)) \
     132for (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) \
    116136for (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)
    119139
    120140#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__)) \
     141for (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) \
    125145for (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)
    128148
    129149#endif // BOOST_GRAPH_ITERATION_MACROS_HPP