Chris@16
|
1 // Boost.Geometry Index
|
Chris@16
|
2 //
|
Chris@101
|
3 // Copyright (c) 2011-2014 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@101
|
14 namespace boost { namespace geometry { namespace index { namespace detail {
|
Chris@16
|
15
|
Chris@16
|
16 template <typename Geometry, typename GeometryTag>
|
Chris@16
|
17 struct is_indexable_impl { static const bool value = false; };
|
Chris@16
|
18
|
Chris@16
|
19 template <typename Point>
|
Chris@16
|
20 struct is_indexable_impl<Point, geometry::point_tag> { static const bool value = true; };
|
Chris@16
|
21
|
Chris@16
|
22 template <typename Box>
|
Chris@16
|
23 struct is_indexable_impl<Box, geometry::box_tag> { static const bool value = true; };
|
Chris@16
|
24
|
Chris@101
|
25 template <typename Segment>
|
Chris@101
|
26 struct is_indexable_impl<Segment, geometry::segment_tag> { static const bool value = true; };
|
Chris@101
|
27
|
Chris@16
|
28 template <typename Indexable>
|
Chris@16
|
29 struct is_indexable
|
Chris@16
|
30 {
|
Chris@16
|
31 static const bool value =
|
Chris@101
|
32 is_indexable_impl
|
Chris@101
|
33 <
|
Chris@101
|
34 Indexable,
|
Chris@101
|
35 typename geometry::tag<Indexable>::type
|
Chris@101
|
36 >::value;
|
Chris@16
|
37 };
|
Chris@16
|
38
|
Chris@16
|
39 /*!
|
Chris@16
|
40 \brief The function object extracting Indexable from Value.
|
Chris@16
|
41
|
Chris@16
|
42 It translates Value object to Indexable object. The default version handles Values which are Indexables.
|
Chris@101
|
43 This template is also specialized for std::pair<Indexable, T2>, boost::tuple<Indexable, ...>
|
Chris@101
|
44 and std::tuple<Indexable, ...>.
|
Chris@16
|
45
|
Chris@16
|
46 \tparam Value The Value type which may be translated directly to the Indexable.
|
Chris@101
|
47 \tparam IsIndexable If true, the const reference to Value is returned.
|
Chris@16
|
48 */
|
Chris@101
|
49 template <typename Value, bool IsIndexable = is_indexable<Value>::value>
|
Chris@16
|
50 struct indexable
|
Chris@16
|
51 {
|
Chris@16
|
52 BOOST_MPL_ASSERT_MSG(
|
Chris@16
|
53 (detail::is_indexable<Value>::value),
|
Chris@16
|
54 NOT_VALID_INDEXABLE_TYPE,
|
Chris@16
|
55 (Value)
|
Chris@16
|
56 );
|
Chris@101
|
57
|
Chris@16
|
58 /*! \brief The type of result returned by function object. */
|
Chris@16
|
59 typedef Value const& result_type;
|
Chris@16
|
60
|
Chris@16
|
61 /*!
|
Chris@16
|
62 \brief Return indexable extracted from the value.
|
Chris@16
|
63
|
Chris@16
|
64 \param v The value.
|
Chris@16
|
65 \return The indexable.
|
Chris@16
|
66 */
|
Chris@101
|
67 inline result_type operator()(Value const& v) const
|
Chris@16
|
68 {
|
Chris@16
|
69 return v;
|
Chris@16
|
70 }
|
Chris@16
|
71 };
|
Chris@16
|
72
|
Chris@16
|
73 /*!
|
Chris@16
|
74 \brief The function object extracting Indexable from Value.
|
Chris@16
|
75
|
Chris@16
|
76 This specialization translates from std::pair<Indexable, T2>.
|
Chris@16
|
77
|
Chris@16
|
78 \tparam Indexable The Indexable type.
|
Chris@16
|
79 \tparam T2 The second type.
|
Chris@16
|
80 */
|
Chris@16
|
81 template <typename Indexable, typename T2>
|
Chris@101
|
82 struct indexable<std::pair<Indexable, T2>, false>
|
Chris@16
|
83 {
|
Chris@16
|
84 BOOST_MPL_ASSERT_MSG(
|
Chris@16
|
85 (detail::is_indexable<Indexable>::value),
|
Chris@16
|
86 NOT_VALID_INDEXABLE_TYPE,
|
Chris@16
|
87 (Indexable)
|
Chris@16
|
88 );
|
Chris@16
|
89
|
Chris@16
|
90 /*! \brief The type of result returned by function object. */
|
Chris@16
|
91 typedef Indexable const& result_type;
|
Chris@16
|
92
|
Chris@16
|
93 /*!
|
Chris@16
|
94 \brief Return indexable extracted from the value.
|
Chris@16
|
95
|
Chris@16
|
96 \param v The value.
|
Chris@16
|
97 \return The indexable.
|
Chris@16
|
98 */
|
Chris@101
|
99 inline result_type operator()(std::pair<Indexable, T2> const& v) const
|
Chris@16
|
100 {
|
Chris@16
|
101 return v.first;
|
Chris@16
|
102 }
|
Chris@16
|
103 };
|
Chris@16
|
104
|
Chris@16
|
105 /*!
|
Chris@16
|
106 \brief The function object extracting Indexable from Value.
|
Chris@16
|
107
|
Chris@16
|
108 This specialization translates from boost::tuple<Indexable, ...>.
|
Chris@16
|
109
|
Chris@16
|
110 \tparam Indexable The Indexable type.
|
Chris@16
|
111 */
|
Chris@16
|
112 template <typename Indexable, typename T1, typename T2, typename T3, typename T4,
|
Chris@16
|
113 typename T5, typename T6, typename T7, typename T8, typename T9>
|
Chris@101
|
114 struct indexable<boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
|
Chris@16
|
115 {
|
Chris@16
|
116 typedef boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
|
Chris@16
|
117
|
Chris@16
|
118 BOOST_MPL_ASSERT_MSG(
|
Chris@16
|
119 (detail::is_indexable<Indexable>::value),
|
Chris@16
|
120 NOT_VALID_INDEXABLE_TYPE,
|
Chris@16
|
121 (Indexable)
|
Chris@16
|
122 );
|
Chris@16
|
123
|
Chris@16
|
124 /*! \brief The type of result returned by function object. */
|
Chris@16
|
125 typedef Indexable const& result_type;
|
Chris@16
|
126
|
Chris@16
|
127 /*!
|
Chris@16
|
128 \brief Return indexable extracted from the value.
|
Chris@16
|
129
|
Chris@16
|
130 \param v The value.
|
Chris@16
|
131 \return The indexable.
|
Chris@16
|
132 */
|
Chris@101
|
133 inline result_type operator()(value_type const& v) const
|
Chris@16
|
134 {
|
Chris@16
|
135 return boost::get<0>(v);
|
Chris@16
|
136 }
|
Chris@16
|
137 };
|
Chris@16
|
138
|
Chris@101
|
139 }}}} // namespace boost::geometry::index::detail
|
Chris@16
|
140
|
Chris@16
|
141 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
142
|
Chris@16
|
143 #include <tuple>
|
Chris@16
|
144
|
Chris@101
|
145 namespace boost { namespace geometry { namespace index { namespace detail {
|
Chris@16
|
146
|
Chris@16
|
147 /*!
|
Chris@16
|
148 \brief The function object extracting Indexable from Value.
|
Chris@16
|
149
|
Chris@16
|
150 This specialization translates from std::tuple<Indexable, Args...>.
|
Chris@16
|
151 It's defined if the compiler supports tuples and variadic templates.
|
Chris@16
|
152
|
Chris@16
|
153 \tparam Indexable The Indexable type.
|
Chris@16
|
154 */
|
Chris@16
|
155 template <typename Indexable, typename ...Args>
|
Chris@101
|
156 struct indexable<std::tuple<Indexable, Args...>, false>
|
Chris@16
|
157 {
|
Chris@16
|
158 typedef std::tuple<Indexable, Args...> value_type;
|
Chris@16
|
159
|
Chris@16
|
160 BOOST_MPL_ASSERT_MSG(
|
Chris@16
|
161 (detail::is_indexable<Indexable>::value),
|
Chris@16
|
162 NOT_VALID_INDEXABLE_TYPE,
|
Chris@16
|
163 (Indexable)
|
Chris@16
|
164 );
|
Chris@16
|
165
|
Chris@16
|
166 /*! \brief The type of result returned by function object. */
|
Chris@16
|
167 typedef Indexable const& result_type;
|
Chris@16
|
168
|
Chris@16
|
169 /*!
|
Chris@16
|
170 \brief Return indexable extracted from the value.
|
Chris@16
|
171
|
Chris@16
|
172 \param v The value.
|
Chris@16
|
173 \return The indexable.
|
Chris@16
|
174 */
|
Chris@16
|
175 result_type operator()(value_type const& v) const
|
Chris@16
|
176 {
|
Chris@16
|
177 return std::get<0>(v);
|
Chris@16
|
178 }
|
Chris@16
|
179 };
|
Chris@16
|
180
|
Chris@101
|
181 }}}} // namespace boost::geometry::index::detail
|
Chris@16
|
182
|
Chris@16
|
183 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
184
|
Chris@101
|
185 namespace boost { namespace geometry { namespace index {
|
Chris@101
|
186
|
Chris@101
|
187 /*!
|
Chris@101
|
188 \brief The function object extracting Indexable from Value.
|
Chris@101
|
189
|
Chris@101
|
190 It translates Value object to Indexable object. By default, it can handle Values which are Indexables,
|
Chris@101
|
191 std::pair<Indexable, T2>, boost::tuple<Indexable, ...> and std::tuple<Indexable, ...> if STD tuples
|
Chris@101
|
192 and variadic templates are supported.
|
Chris@101
|
193
|
Chris@101
|
194 \tparam Value The Value type which may be translated directly to the Indexable.
|
Chris@101
|
195 */
|
Chris@101
|
196 template <typename Value>
|
Chris@101
|
197 struct indexable
|
Chris@101
|
198 : detail::indexable<Value>
|
Chris@101
|
199 {
|
Chris@101
|
200 /*! \brief The type of result returned by function object. It should be const Indexable reference. */
|
Chris@101
|
201 typedef typename detail::indexable<Value>::result_type result_type;
|
Chris@101
|
202
|
Chris@101
|
203 /*!
|
Chris@101
|
204 \brief Return indexable extracted from the value.
|
Chris@101
|
205
|
Chris@101
|
206 \param v The value.
|
Chris@101
|
207 \return The indexable.
|
Chris@101
|
208 */
|
Chris@101
|
209 inline result_type operator()(Value const& v) const
|
Chris@101
|
210 {
|
Chris@101
|
211 return detail::indexable<Value>::operator()(v);
|
Chris@101
|
212 }
|
Chris@101
|
213 };
|
Chris@101
|
214
|
Chris@101
|
215 }}} // namespace boost::geometry::index
|
Chris@101
|
216
|
Chris@16
|
217 #endif // BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
|