1
2 // (C) Copyright Francois Faure, iMAGIS-GRAVIR / UJF, 2001.
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Revision History:
9 // 03 May 2001 Jeremy Siek
10 // Generalized the property map iterator and moved that
11 // part to boost/property_map.hpp. Also modified to
12 // differentiate between const/mutable graphs and
13 // added a workaround to avoid partial specialization.
14
15 // 02 May 2001 Francois Faure
16 // Initial version.
17
18 #ifndef BOOST_GRAPH_PROPERTY_ITER_RANGE_HPP
19 #define BOOST_GRAPH_PROPERTY_ITER_RANGE_HPP
20
21 #include <boost/property_map/property_map_iterator.hpp>
22 #include <boost/graph/properties.hpp>
23 #include <boost/mpl/if.hpp>
24 #include <boost/type_traits/same_traits.hpp>
25
26 namespace boost
27 {
28
29 //======================================================================
30 // graph property iterator range
31
32 template < class Graph, class PropertyTag > class graph_property_iter_range
33 {
34 typedef typename property_map< Graph, PropertyTag >::type map_type;
35 typedef
36 typename property_map< Graph, PropertyTag >::const_type const_map_type;
37 typedef typename property_kind< PropertyTag >::type Kind;
38 typedef typename mpl::if_c< is_same< Kind, vertex_property_tag >::value,
39 typename graph_traits< Graph >::vertex_iterator,
40 typename graph_traits< Graph >::edge_iterator >::type iter;
41
42 public:
43 typedef typename property_map_iterator_generator< map_type, iter >::type
44 iterator;
45 typedef
46 typename property_map_iterator_generator< const_map_type, iter >::type
47 const_iterator;
48 typedef std::pair< iterator, iterator > type;
49 typedef std::pair< const_iterator, const_iterator > const_type;
50 };
51
52 namespace detail
53 {
54
55 template < class Graph, class Tag >
56 typename graph_property_iter_range< Graph, Tag >::type
get_property_iter_range_kind(Graph & graph,const Tag & tag,const vertex_property_tag &)57 get_property_iter_range_kind(
58 Graph& graph, const Tag& tag, const vertex_property_tag&)
59 {
60 typedef typename graph_property_iter_range< Graph, Tag >::iterator iter;
61 return std::make_pair(iter(vertices(graph).first, get(tag, graph)),
62 iter(vertices(graph).second, get(tag, graph)));
63 }
64
65 template < class Graph, class Tag >
66 typename graph_property_iter_range< Graph, Tag >::const_type
get_property_iter_range_kind(const Graph & graph,const Tag & tag,const vertex_property_tag &)67 get_property_iter_range_kind(
68 const Graph& graph, const Tag& tag, const vertex_property_tag&)
69 {
70 typedef typename graph_property_iter_range< Graph, Tag >::const_iterator
71 iter;
72 return std::make_pair(iter(vertices(graph).first, get(tag, graph)),
73 iter(vertices(graph).second, get(tag, graph)));
74 }
75
76 template < class Graph, class Tag >
77 typename graph_property_iter_range< Graph, Tag >::type
get_property_iter_range_kind(Graph & graph,const Tag & tag,const edge_property_tag &)78 get_property_iter_range_kind(
79 Graph& graph, const Tag& tag, const edge_property_tag&)
80 {
81 typedef typename graph_property_iter_range< Graph, Tag >::iterator iter;
82 return std::make_pair(iter(edges(graph).first, get(tag, graph)),
83 iter(edges(graph).second, get(tag, graph)));
84 }
85
86 template < class Graph, class Tag >
87 typename graph_property_iter_range< Graph, Tag >::const_type
get_property_iter_range_kind(const Graph & graph,const Tag & tag,const edge_property_tag &)88 get_property_iter_range_kind(
89 const Graph& graph, const Tag& tag, const edge_property_tag&)
90 {
91 typedef typename graph_property_iter_range< Graph, Tag >::const_iterator
92 iter;
93 return std::make_pair(iter(edges(graph).first, get(tag, graph)),
94 iter(edges(graph).second, get(tag, graph)));
95 }
96
97 } // namespace detail
98
99 //======================================================================
100 // get an iterator range of properties
101
102 template < class Graph, class Tag >
get_property_iter_range(Graph & graph,const Tag & tag)103 typename graph_property_iter_range< Graph, Tag >::type get_property_iter_range(
104 Graph& graph, const Tag& tag)
105 {
106 typedef typename property_kind< Tag >::type Kind;
107 return detail::get_property_iter_range_kind(graph, tag, Kind());
108 }
109
110 template < class Graph, class Tag >
111 typename graph_property_iter_range< Graph, Tag >::const_type
get_property_iter_range(const Graph & graph,const Tag & tag)112 get_property_iter_range(const Graph& graph, const Tag& tag)
113 {
114 typedef typename property_kind< Tag >::type Kind;
115 return detail::get_property_iter_range_kind(graph, tag, Kind());
116 }
117
118 } // namespace boost
119
120 #endif // BOOST_GRAPH_PROPERTY_ITER_RANGE_HPP
121