Chris@16
|
1 // Boost.Geometry Index
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
|
Chris@16
|
4 //
|
Chris@16
|
5 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 #ifndef BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
|
Chris@16
|
10 #define BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/mpl/assert.hpp>
|
Chris@16
|
13
|
Chris@16
|
14 namespace boost { namespace geometry { namespace index {
|
Chris@16
|
15
|
Chris@16
|
16 namespace detail {
|
Chris@16
|
17
|
Chris@16
|
18 template <typename Geometry, typename GeometryTag>
|
Chris@16
|
19 struct is_indexable_impl { static const bool value = false; };
|
Chris@16
|
20
|
Chris@16
|
21 template <typename Point>
|
Chris@16
|
22 struct is_indexable_impl<Point, geometry::point_tag> { static const bool value = true; };
|
Chris@16
|
23
|
Chris@16
|
24 template <typename Box>
|
Chris@16
|
25 struct is_indexable_impl<Box, geometry::box_tag> { static const bool value = true; };
|
Chris@16
|
26
|
Chris@16
|
27 template <typename Indexable>
|
Chris@16
|
28 struct is_indexable
|
Chris@16
|
29 {
|
Chris@16
|
30 static const bool value =
|
Chris@16
|
31 is_indexable_impl<Indexable, typename geometry::traits::tag<Indexable>::type>::value;
|
Chris@16
|
32 };
|
Chris@16
|
33
|
Chris@16
|
34 } // namespace detail
|
Chris@16
|
35
|
Chris@16
|
36 /*!
|
Chris@16
|
37 \brief The function object extracting Indexable from Value.
|
Chris@16
|
38
|
Chris@16
|
39 It translates Value object to Indexable object. The default version handles Values which are Indexables.
|
Chris@16
|
40 This template is also specialized for std::pair<Indexable, T2> and boost::tuple<Indexable, ...>.
|
Chris@16
|
41
|
Chris@16
|
42 \tparam Value The Value type which may be translated directly to the Indexable.
|
Chris@16
|
43 */
|
Chris@16
|
44 template <typename Value>
|
Chris@16
|
45 struct indexable
|
Chris@16
|
46 {
|
Chris@16
|
47 BOOST_MPL_ASSERT_MSG(
|
Chris@16
|
48 (detail::is_indexable<Value>::value),
|
Chris@16
|
49 NOT_VALID_INDEXABLE_TYPE,
|
Chris@16
|
50 (Value)
|
Chris@16
|
51 );
|
Chris@16
|
52 /*! \brief The type of result returned by function object. */
|
Chris@16
|
53 typedef Value const& result_type;
|
Chris@16
|
54
|
Chris@16
|
55 /*!
|
Chris@16
|
56 \brief Return indexable extracted from the value.
|
Chris@16
|
57
|
Chris@16
|
58 \param v The value.
|
Chris@16
|
59 \return The indexable.
|
Chris@16
|
60 */
|
Chris@16
|
61 result_type operator()(Value const& v) const
|
Chris@16
|
62 {
|
Chris@16
|
63 return v;
|
Chris@16
|
64 }
|
Chris@16
|
65 };
|
Chris@16
|
66
|
Chris@16
|
67 /*!
|
Chris@16
|
68 \brief The function object extracting Indexable from Value.
|
Chris@16
|
69
|
Chris@16
|
70 This specialization translates from std::pair<Indexable, T2>.
|
Chris@16
|
71
|
Chris@16
|
72 \tparam Indexable The Indexable type.
|
Chris@16
|
73 \tparam T2 The second type.
|
Chris@16
|
74 */
|
Chris@16
|
75 template <typename Indexable, typename T2>
|
Chris@16
|
76 struct indexable< std::pair<Indexable, T2> >
|
Chris@16
|
77 {
|
Chris@16
|
78 BOOST_MPL_ASSERT_MSG(
|
Chris@16
|
79 (detail::is_indexable<Indexable>::value),
|
Chris@16
|
80 NOT_VALID_INDEXABLE_TYPE,
|
Chris@16
|
81 (Indexable)
|
Chris@16
|
82 );
|
Chris@16
|
83
|
Chris@16
|
84 /*! \brief The type of result returned by function object. */
|
Chris@16
|
85 typedef Indexable const& result_type;
|
Chris@16
|
86
|
Chris@16
|
87 /*!
|
Chris@16
|
88 \brief Return indexable extracted from the value.
|
Chris@16
|
89
|
Chris@16
|
90 \param v The value.
|
Chris@16
|
91 \return The indexable.
|
Chris@16
|
92 */
|
Chris@16
|
93 result_type operator()(std::pair<Indexable, T2> const& v) const
|
Chris@16
|
94 {
|
Chris@16
|
95 return v.first;
|
Chris@16
|
96 }
|
Chris@16
|
97 };
|
Chris@16
|
98
|
Chris@16
|
99 /*!
|
Chris@16
|
100 \brief The function object extracting Indexable from Value.
|
Chris@16
|
101
|
Chris@16
|
102 This specialization translates from boost::tuple<Indexable, ...>.
|
Chris@16
|
103
|
Chris@16
|
104 \tparam Indexable The Indexable type.
|
Chris@16
|
105 */
|
Chris@16
|
106 template <typename Indexable, typename T1, typename T2, typename T3, typename T4,
|
Chris@16
|
107 typename T5, typename T6, typename T7, typename T8, typename T9>
|
Chris@16
|
108 struct indexable< boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
|
Chris@16
|
109 {
|
Chris@16
|
110 typedef boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
|
Chris@16
|
111
|
Chris@16
|
112 BOOST_MPL_ASSERT_MSG(
|
Chris@16
|
113 (detail::is_indexable<Indexable>::value),
|
Chris@16
|
114 NOT_VALID_INDEXABLE_TYPE,
|
Chris@16
|
115 (Indexable)
|
Chris@16
|
116 );
|
Chris@16
|
117
|
Chris@16
|
118 /*! \brief The type of result returned by function object. */
|
Chris@16
|
119 typedef Indexable const& result_type;
|
Chris@16
|
120
|
Chris@16
|
121 /*!
|
Chris@16
|
122 \brief Return indexable extracted from the value.
|
Chris@16
|
123
|
Chris@16
|
124 \param v The value.
|
Chris@16
|
125 \return The indexable.
|
Chris@16
|
126 */
|
Chris@16
|
127 result_type operator()(value_type const& v) const
|
Chris@16
|
128 {
|
Chris@16
|
129 return boost::get<0>(v);
|
Chris@16
|
130 }
|
Chris@16
|
131 };
|
Chris@16
|
132
|
Chris@16
|
133 }}} // namespace boost::geometry::index
|
Chris@16
|
134
|
Chris@16
|
135 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
136
|
Chris@16
|
137 #include <tuple>
|
Chris@16
|
138
|
Chris@16
|
139 namespace boost { namespace geometry { namespace index {
|
Chris@16
|
140
|
Chris@16
|
141 /*!
|
Chris@16
|
142 \brief The function object extracting Indexable from Value.
|
Chris@16
|
143
|
Chris@16
|
144 This specialization translates from std::tuple<Indexable, Args...>.
|
Chris@16
|
145 It's defined if the compiler supports tuples and variadic templates.
|
Chris@16
|
146
|
Chris@16
|
147 \tparam Indexable The Indexable type.
|
Chris@16
|
148 */
|
Chris@16
|
149 template <typename Indexable, typename ...Args>
|
Chris@16
|
150 struct indexable< std::tuple<Indexable, Args...> >
|
Chris@16
|
151 {
|
Chris@16
|
152 typedef std::tuple<Indexable, Args...> value_type;
|
Chris@16
|
153
|
Chris@16
|
154 BOOST_MPL_ASSERT_MSG(
|
Chris@16
|
155 (detail::is_indexable<Indexable>::value),
|
Chris@16
|
156 NOT_VALID_INDEXABLE_TYPE,
|
Chris@16
|
157 (Indexable)
|
Chris@16
|
158 );
|
Chris@16
|
159
|
Chris@16
|
160 /*! \brief The type of result returned by function object. */
|
Chris@16
|
161 typedef Indexable const& result_type;
|
Chris@16
|
162
|
Chris@16
|
163 /*!
|
Chris@16
|
164 \brief Return indexable extracted from the value.
|
Chris@16
|
165
|
Chris@16
|
166 \param v The value.
|
Chris@16
|
167 \return The indexable.
|
Chris@16
|
168 */
|
Chris@16
|
169 result_type operator()(value_type const& v) const
|
Chris@16
|
170 {
|
Chris@16
|
171 return std::get<0>(v);
|
Chris@16
|
172 }
|
Chris@16
|
173 };
|
Chris@16
|
174
|
Chris@16
|
175 }}} // namespace boost::geometry::index
|
Chris@16
|
176
|
Chris@16
|
177 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
178
|
Chris@16
|
179 #endif // BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
|