os/ossrv/ossrv_pub/boost_apis/boost/graph/graph_traits.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
//=======================================================================
sl@0
     2
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
sl@0
     3
// Authors: Andrew Lumsdaine, Lie-Quan Lee, 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_TRAITS_HPP
sl@0
    11
#define BOOST_GRAPH_TRAITS_HPP
sl@0
    12
sl@0
    13
#include <boost/config.hpp>
sl@0
    14
#include <iterator>
sl@0
    15
#include <boost/tuple/tuple.hpp>
sl@0
    16
#include <boost/mpl/if.hpp>
sl@0
    17
#include <boost/type_traits/is_same.hpp>
sl@0
    18
#include <boost/iterator/iterator_categories.hpp>
sl@0
    19
#include <boost/iterator/iterator_adaptor.hpp>
sl@0
    20
#include <boost/detail/workaround.hpp>
sl@0
    21
sl@0
    22
namespace boost {
sl@0
    23
sl@0
    24
  template <typename G>
sl@0
    25
  struct graph_traits {
sl@0
    26
    typedef typename G::vertex_descriptor      vertex_descriptor;
sl@0
    27
    typedef typename G::edge_descriptor        edge_descriptor;
sl@0
    28
    typedef typename G::adjacency_iterator     adjacency_iterator;
sl@0
    29
    typedef typename G::out_edge_iterator      out_edge_iterator;
sl@0
    30
    typedef typename G::in_edge_iterator       in_edge_iterator;
sl@0
    31
    typedef typename G::vertex_iterator        vertex_iterator;
sl@0
    32
    typedef typename G::edge_iterator          edge_iterator;
sl@0
    33
sl@0
    34
    typedef typename G::directed_category      directed_category;
sl@0
    35
    typedef typename G::edge_parallel_category edge_parallel_category;
sl@0
    36
    typedef typename G::traversal_category     traversal_category;
sl@0
    37
sl@0
    38
    typedef typename G::vertices_size_type     vertices_size_type;
sl@0
    39
    typedef typename G::edges_size_type        edges_size_type;
sl@0
    40
    typedef typename G::degree_size_type       degree_size_type;
sl@0
    41
sl@0
    42
    static inline vertex_descriptor null_vertex();
sl@0
    43
  };
sl@0
    44
sl@0
    45
  template <typename G>
sl@0
    46
  inline typename graph_traits<G>::vertex_descriptor
sl@0
    47
  graph_traits<G>::null_vertex()
sl@0
    48
  {
sl@0
    49
    return G::null_vertex();
sl@0
    50
  }
sl@0
    51
sl@0
    52
  // directed_category tags
sl@0
    53
  struct directed_tag { };
sl@0
    54
  struct undirected_tag { };
sl@0
    55
  struct bidirectional_tag : public directed_tag { };
sl@0
    56
sl@0
    57
  namespace detail {
sl@0
    58
    inline bool is_directed(directed_tag) { return true; }
sl@0
    59
    inline bool is_directed(undirected_tag) { return false; }
sl@0
    60
  }
sl@0
    61
sl@0
    62
  template <typename Graph>
sl@0
    63
  bool is_directed(const Graph&) { 
sl@0
    64
    typedef typename graph_traits<Graph>::directed_category Cat;
sl@0
    65
    return detail::is_directed(Cat());
sl@0
    66
  }
sl@0
    67
  template <typename Graph>
sl@0
    68
  bool is_undirected(const Graph& g) { 
sl@0
    69
    return ! is_directed(g);
sl@0
    70
  }
sl@0
    71
sl@0
    72
  // edge_parallel_category tags
sl@0
    73
  struct allow_parallel_edge_tag {};
sl@0
    74
  struct disallow_parallel_edge_tag {};
sl@0
    75
sl@0
    76
  namespace detail {
sl@0
    77
    inline bool allows_parallel(allow_parallel_edge_tag) { return true; }
sl@0
    78
    inline bool allows_parallel(disallow_parallel_edge_tag) { return false; }
sl@0
    79
  }
sl@0
    80
sl@0
    81
  template <typename Graph>
sl@0
    82
  bool allows_parallel_edges(const Graph&) { 
sl@0
    83
    typedef typename graph_traits<Graph>::edge_parallel_category Cat;
sl@0
    84
    return detail::allows_parallel(Cat());
sl@0
    85
  }
sl@0
    86
sl@0
    87
  // traversal_category tags
sl@0
    88
  struct incidence_graph_tag { };
sl@0
    89
  struct adjacency_graph_tag { };
sl@0
    90
  struct bidirectional_graph_tag : 
sl@0
    91
    public virtual incidence_graph_tag { };
sl@0
    92
  struct vertex_list_graph_tag { };
sl@0
    93
  struct edge_list_graph_tag { };
sl@0
    94
  struct adjacency_matrix_tag { };
sl@0
    95
sl@0
    96
  //?? not the right place ?? Lee
sl@0
    97
  typedef boost::forward_traversal_tag multi_pass_input_iterator_tag;
sl@0
    98
sl@0
    99
  template <typename G>
sl@0
   100
  struct edge_property_type {
sl@0
   101
    typedef typename G::edge_property_type type;
sl@0
   102
  };
sl@0
   103
  template <typename G>
sl@0
   104
  struct vertex_property_type {
sl@0
   105
    typedef typename G::vertex_property_type type;
sl@0
   106
  };
sl@0
   107
  template <typename G>
sl@0
   108
  struct graph_property_type {
sl@0
   109
    typedef typename G::graph_property_type type;
sl@0
   110
  };
sl@0
   111
sl@0
   112
  struct no_vertex_bundle {};
sl@0
   113
  struct no_edge_bundle {};
sl@0
   114
sl@0
   115
  template<typename G>
sl@0
   116
  struct vertex_bundle_type
sl@0
   117
  {
sl@0
   118
    typedef typename G::vertex_bundled type;
sl@0
   119
  };
sl@0
   120
sl@0
   121
  template<typename G>
sl@0
   122
  struct edge_bundle_type
sl@0
   123
  {
sl@0
   124
    typedef typename G::edge_bundled type;
sl@0
   125
  };
sl@0
   126
sl@0
   127
  namespace graph { namespace detail {
sl@0
   128
    template<typename Graph, typename Descriptor>
sl@0
   129
    class bundled_result
sl@0
   130
    {
sl@0
   131
      typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
sl@0
   132
      typedef typename mpl::if_c<(is_same<Descriptor, Vertex>::value),
sl@0
   133
                                 vertex_bundle_type<Graph>,
sl@0
   134
                                 edge_bundle_type<Graph> >::type bundler;
sl@0
   135
sl@0
   136
    public:
sl@0
   137
      typedef typename bundler::type type;
sl@0
   138
    };
sl@0
   139
  } } // end namespace graph::detail
sl@0
   140
} // namespace boost
sl@0
   141
sl@0
   142
// Since pair is in namespace std, Koenig lookup will find source and
sl@0
   143
// target if they are also defined in namespace std.  This is illegal,
sl@0
   144
// but the alternative is to put source and target in the global
sl@0
   145
// namespace which causes name conflicts with other libraries (like
sl@0
   146
// SUIF).
sl@0
   147
namespace std {
sl@0
   148
sl@0
   149
  /* Some helper functions for dealing with pairs as edges */
sl@0
   150
  template <class T, class G>
sl@0
   151
  T source(pair<T,T> p, const G&) { return p.first; }
sl@0
   152
sl@0
   153
  template <class T, class G>
sl@0
   154
  T target(pair<T,T> p, const G&) { return p.second; }
sl@0
   155
sl@0
   156
}
sl@0
   157
sl@0
   158
#if defined(__GNUC__) && defined(__SGI_STL_PORT)
sl@0
   159
// For some reason g++ with STLport does not see the above definition
sl@0
   160
// of source() and target() unless we bring them into the boost
sl@0
   161
// namespace.
sl@0
   162
namespace boost {
sl@0
   163
  using std::source;
sl@0
   164
  using std::target;
sl@0
   165
}
sl@0
   166
#endif
sl@0
   167
sl@0
   168
#endif // BOOST_GRAPH_TRAITS_HPP