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