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