1 |
|
---|
2 | // (C) Copyright François Faure, iMAGIS-GRAVIR / UJF, 2001. Permission
|
---|
3 | // to copy, use, modify, sell and distribute this software is granted
|
---|
4 | // provided this copyright notice appears in all copies. This software
|
---|
5 | // is provided "as is" without express or implied warranty, and with
|
---|
6 | // no claim as to its suitability for any purpose.
|
---|
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 François 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_iterator.hpp>
|
---|
22 | #include <boost/graph/properties.hpp>
|
---|
23 | #include <boost/pending/ct_if.hpp>
|
---|
24 | #include <boost/type_traits/same_traits.hpp>
|
---|
25 |
|
---|
26 | namespace boost {
|
---|
27 |
|
---|
28 | //======================================================================
|
---|
29 | // graph property iterator range
|
---|
30 |
|
---|
31 | template <class Graph, class PropertyTag>
|
---|
32 | class graph_property_iter_range {
|
---|
33 | typedef typename property_map<Graph, PropertyTag>::type map_type;
|
---|
34 | typedef typename property_map<Graph, PropertyTag>::const_type
|
---|
35 | const_map_type;
|
---|
36 | typedef typename property_kind<PropertyTag>::type Kind;
|
---|
37 | typedef typename ct_if<is_same<Kind, vertex_property_tag>::value,
|
---|
38 | typename graph_traits<Graph>::vertex_iterator,
|
---|
39 | typename graph_traits<Graph>::edge_iterator>::type iter;
|
---|
40 | public:
|
---|
41 | typedef typename property_map_iterator_generator<map_type, iter>::type
|
---|
42 | iterator;
|
---|
43 | typedef typename property_map_iterator_generator<const_map_type, iter>
|
---|
44 | ::type const_iterator;
|
---|
45 | typedef std::pair<iterator, iterator> type;
|
---|
46 | typedef std::pair<const_iterator, const_iterator> const_type;
|
---|
47 | };
|
---|
48 |
|
---|
49 | namespace detail {
|
---|
50 |
|
---|
51 | template<class Graph,class Tag>
|
---|
52 | typename graph_property_iter_range<Graph,Tag>::type
|
---|
53 | get_property_iter_range_kind(Graph& graph, const Tag& tag,
|
---|
54 | const vertex_property_tag& )
|
---|
55 | {
|
---|
56 | typedef typename graph_property_iter_range<Graph,Tag>::iterator iter;
|
---|
57 | return std::make_pair(iter(vertices(graph).first, get(tag, graph)),
|
---|
58 | iter(vertices(graph).second, get(tag, graph)));
|
---|
59 | }
|
---|
60 |
|
---|
61 | template<class Graph,class Tag>
|
---|
62 | typename graph_property_iter_range<Graph,Tag>::const_type
|
---|
63 | get_property_iter_range_kind(const Graph& graph, const Tag& tag,
|
---|
64 | const vertex_property_tag& )
|
---|
65 | {
|
---|
66 | typedef typename graph_property_iter_range<Graph,Tag>
|
---|
67 | ::const_iterator iter;
|
---|
68 | return std::make_pair(iter(vertices(graph).first, get(tag, graph)),
|
---|
69 | iter(vertices(graph).second, get(tag, graph)));
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | template<class Graph,class Tag>
|
---|
74 | typename graph_property_iter_range<Graph,Tag>::type
|
---|
75 | get_property_iter_range_kind(Graph& graph, const Tag& tag,
|
---|
76 | const edge_property_tag& )
|
---|
77 | {
|
---|
78 | typedef typename graph_property_iter_range<Graph,Tag>::iterator iter;
|
---|
79 | return std::make_pair(iter(edges(graph).first, get(tag, graph)),
|
---|
80 | iter(edges(graph).second, get(tag, graph)));
|
---|
81 | }
|
---|
82 |
|
---|
83 | template<class Graph,class Tag>
|
---|
84 | typename graph_property_iter_range<Graph,Tag>::const_type
|
---|
85 | get_property_iter_range_kind(const Graph& graph, const Tag& tag,
|
---|
86 | const edge_property_tag& )
|
---|
87 | {
|
---|
88 | typedef typename graph_property_iter_range<Graph,Tag>
|
---|
89 | ::const_iterator iter;
|
---|
90 | return std::make_pair(iter(edges(graph).first, get(tag, graph)),
|
---|
91 | iter(edges(graph).second, get(tag, graph)));
|
---|
92 | }
|
---|
93 |
|
---|
94 | } // namespace detail
|
---|
95 |
|
---|
96 | //======================================================================
|
---|
97 | // get an iterator range of properties
|
---|
98 |
|
---|
99 | template<class Graph, class Tag>
|
---|
100 | typename graph_property_iter_range<Graph, Tag>::type
|
---|
101 | get_property_iter_range(Graph& graph, const Tag& tag)
|
---|
102 | {
|
---|
103 | typedef typename property_kind<Tag>::type Kind;
|
---|
104 | return detail::get_property_iter_range_kind(graph, tag, Kind());
|
---|
105 | }
|
---|
106 |
|
---|
107 | template<class Graph, class Tag>
|
---|
108 | typename graph_property_iter_range<Graph, Tag>::const_type
|
---|
109 | get_property_iter_range(const Graph& graph, const Tag& tag)
|
---|
110 | {
|
---|
111 | typedef typename property_kind<Tag>::type Kind;
|
---|
112 | return detail::get_property_iter_range_kind(graph, tag, Kind());
|
---|
113 | }
|
---|
114 |
|
---|
115 | } // namespace boost
|
---|
116 |
|
---|
117 |
|
---|
118 | #endif // BOOST_GRAPH_PROPERTY_ITER_RANGE_HPP
|
---|