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