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