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_EQUAL_TO_HPP
|
Chris@16
|
10 #define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/geometry/algorithms/equals.hpp>
|
Chris@101
|
13 #include <boost/geometry/index/indexable.hpp>
|
Chris@16
|
14
|
Chris@101
|
15 namespace boost { namespace geometry { namespace index { namespace detail {
|
Chris@16
|
16
|
Chris@101
|
17 template <typename Geometry,
|
Chris@101
|
18 typename Tag = typename geometry::tag<Geometry>::type>
|
Chris@101
|
19 struct equals
|
Chris@101
|
20 {
|
Chris@101
|
21 inline static bool apply(Geometry const& g1, Geometry const& g2)
|
Chris@101
|
22 {
|
Chris@101
|
23 return geometry::equals(g1, g2);
|
Chris@101
|
24 }
|
Chris@101
|
25 };
|
Chris@16
|
26
|
Chris@16
|
27 template <typename Geometry, typename Tag>
|
Chris@101
|
28 struct equals<Geometry *, Tag>
|
Chris@16
|
29 {
|
Chris@101
|
30 inline static bool apply(const Geometry * g1, const Geometry * g2)
|
Chris@16
|
31 {
|
Chris@101
|
32 return g1 == g2;
|
Chris@16
|
33 }
|
Chris@16
|
34 };
|
Chris@16
|
35
|
Chris@16
|
36 template <typename T>
|
Chris@16
|
37 struct equals<T, void>
|
Chris@16
|
38 {
|
Chris@101
|
39 inline static bool apply(T const& v1, T const& v2)
|
Chris@16
|
40 {
|
Chris@16
|
41 return v1 == v2;
|
Chris@16
|
42 }
|
Chris@16
|
43 };
|
Chris@16
|
44
|
Chris@16
|
45 template <typename Tuple, size_t I, size_t N>
|
Chris@16
|
46 struct tuple_equals
|
Chris@16
|
47 {
|
Chris@16
|
48 inline static bool apply(Tuple const& t1, Tuple const& t2)
|
Chris@16
|
49 {
|
Chris@16
|
50 typedef typename boost::tuples::element<I, Tuple>::type T;
|
Chris@101
|
51
|
Chris@101
|
52 return equals<T>::apply(boost::get<I>(t1), boost::get<I>(t2))
|
Chris@101
|
53 && tuple_equals<Tuple, I+1, N>::apply(t1, t2);
|
Chris@16
|
54 }
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 template <typename Tuple, size_t I>
|
Chris@16
|
58 struct tuple_equals<Tuple, I, I>
|
Chris@16
|
59 {
|
Chris@16
|
60 inline static bool apply(Tuple const&, Tuple const&)
|
Chris@16
|
61 {
|
Chris@16
|
62 return true;
|
Chris@16
|
63 }
|
Chris@16
|
64 };
|
Chris@16
|
65
|
Chris@101
|
66 // TODO: Consider this: Since equal_to<> is using geometry::equals() it's possible that
|
Chris@101
|
67 // two compared Indexables are not exactly the same! They will be spatially equal
|
Chris@101
|
68 // but not strictly equal. Consider 2 Segments with reversed order of points.
|
Chris@101
|
69 // Therefore it's possible that during the Value removal different value will be
|
Chris@101
|
70 // removed than the one that was passed.
|
Chris@16
|
71
|
Chris@16
|
72 /*!
|
Chris@16
|
73 \brief The function object comparing Values.
|
Chris@16
|
74
|
Chris@16
|
75 It compares Geometries using geometry::equals() function. Other types are compared using operator==.
|
Chris@16
|
76 The default version handles Values which are Indexables.
|
Chris@16
|
77 This template is also specialized for std::pair<T1, T2> and boost::tuple<...>.
|
Chris@16
|
78
|
Chris@16
|
79 \tparam Value The type of objects which are compared by this function object.
|
Chris@101
|
80 \tparam IsIndexable If true, Values are compared using boost::geometry::equals() functions.
|
Chris@16
|
81 */
|
Chris@101
|
82 template <typename Value,
|
Chris@101
|
83 bool IsIndexable = is_indexable<Value>::value>
|
Chris@16
|
84 struct equal_to
|
Chris@16
|
85 {
|
Chris@16
|
86 /*! \brief The type of result returned by function object. */
|
Chris@16
|
87 typedef bool result_type;
|
Chris@16
|
88
|
Chris@16
|
89 /*!
|
Chris@16
|
90 \brief Compare values. If Value is a Geometry geometry::equals() function is used.
|
Chris@16
|
91
|
Chris@16
|
92 \param l First value.
|
Chris@16
|
93 \param r Second value.
|
Chris@16
|
94 \return true if values are equal.
|
Chris@16
|
95 */
|
Chris@101
|
96 inline bool operator()(Value const& l, Value const& r) const
|
Chris@16
|
97 {
|
Chris@101
|
98 return detail::equals<Value>::apply(l ,r);
|
Chris@16
|
99 }
|
Chris@16
|
100 };
|
Chris@16
|
101
|
Chris@16
|
102 /*!
|
Chris@16
|
103 \brief The function object comparing Values.
|
Chris@16
|
104
|
Chris@16
|
105 This specialization compares values of type std::pair<T1, T2>.
|
Chris@16
|
106 It compares pairs' first values, then second values.
|
Chris@16
|
107
|
Chris@16
|
108 \tparam T1 The first type.
|
Chris@16
|
109 \tparam T2 The second type.
|
Chris@16
|
110 */
|
Chris@16
|
111 template <typename T1, typename T2>
|
Chris@101
|
112 struct equal_to<std::pair<T1, T2>, false>
|
Chris@16
|
113 {
|
Chris@16
|
114 /*! \brief The type of result returned by function object. */
|
Chris@16
|
115 typedef bool result_type;
|
Chris@16
|
116
|
Chris@16
|
117 /*!
|
Chris@16
|
118 \brief Compare values. If pair<> Value member is a Geometry geometry::equals() function is used.
|
Chris@16
|
119
|
Chris@16
|
120 \param l First value.
|
Chris@16
|
121 \param r Second value.
|
Chris@16
|
122 \return true if values are equal.
|
Chris@16
|
123 */
|
Chris@101
|
124 inline bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r) const
|
Chris@16
|
125 {
|
Chris@101
|
126 return detail::equals<T1>::apply(l.first, r.first)
|
Chris@101
|
127 && detail::equals<T2>::apply(l.second, r.second);
|
Chris@16
|
128 }
|
Chris@16
|
129 };
|
Chris@16
|
130
|
Chris@16
|
131 /*!
|
Chris@16
|
132 \brief The function object comparing Values.
|
Chris@16
|
133
|
Chris@16
|
134 This specialization compares values of type boost::tuple<...>.
|
Chris@16
|
135 It compares all members of the tuple from the first one to the last one.
|
Chris@16
|
136 */
|
Chris@16
|
137 template <typename T0, typename T1, typename T2, typename T3, typename T4,
|
Chris@16
|
138 typename T5, typename T6, typename T7, typename T8, typename T9>
|
Chris@101
|
139 struct equal_to<boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
|
Chris@16
|
140 {
|
Chris@16
|
141 typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
|
Chris@16
|
142
|
Chris@16
|
143 /*! \brief The type of result returned by function object. */
|
Chris@16
|
144 typedef bool result_type;
|
Chris@16
|
145
|
Chris@16
|
146 /*!
|
Chris@16
|
147 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
|
Chris@16
|
148
|
Chris@16
|
149 \param l First value.
|
Chris@16
|
150 \param r Second value.
|
Chris@16
|
151 \return true if values are equal.
|
Chris@16
|
152 */
|
Chris@101
|
153 inline bool operator()(value_type const& l, value_type const& r) const
|
Chris@16
|
154 {
|
Chris@16
|
155 return detail::tuple_equals<
|
Chris@16
|
156 value_type, 0, boost::tuples::length<value_type>::value
|
Chris@16
|
157 >::apply(l ,r);
|
Chris@16
|
158 }
|
Chris@16
|
159 };
|
Chris@16
|
160
|
Chris@101
|
161 }}}} // namespace boost::geometry::index::detail
|
Chris@16
|
162
|
Chris@16
|
163 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
164
|
Chris@16
|
165 #include <tuple>
|
Chris@16
|
166
|
Chris@101
|
167 namespace boost { namespace geometry { namespace index { namespace detail {
|
Chris@16
|
168
|
Chris@16
|
169 template <typename Tuple, size_t I, size_t N>
|
Chris@16
|
170 struct std_tuple_equals
|
Chris@16
|
171 {
|
Chris@16
|
172 inline static bool apply(Tuple const& t1, Tuple const& t2)
|
Chris@16
|
173 {
|
Chris@16
|
174 typedef typename std::tuple_element<I, Tuple>::type T;
|
Chris@101
|
175
|
Chris@101
|
176 return equals<T>::apply(std::get<I>(t1), std::get<I>(t2))
|
Chris@101
|
177 && std_tuple_equals<Tuple, I+1, N>::apply(t1, t2);
|
Chris@16
|
178 }
|
Chris@16
|
179 };
|
Chris@16
|
180
|
Chris@16
|
181 template <typename Tuple, size_t I>
|
Chris@16
|
182 struct std_tuple_equals<Tuple, I, I>
|
Chris@16
|
183 {
|
Chris@16
|
184 inline static bool apply(Tuple const&, Tuple const&)
|
Chris@16
|
185 {
|
Chris@16
|
186 return true;
|
Chris@16
|
187 }
|
Chris@16
|
188 };
|
Chris@16
|
189
|
Chris@16
|
190 /*!
|
Chris@16
|
191 \brief The function object comparing Values.
|
Chris@16
|
192
|
Chris@16
|
193 This specialization compares values of type std::tuple<Args...>.
|
Chris@16
|
194 It's defined if the compiler supports tuples and variadic templates.
|
Chris@16
|
195 It compares all members of the tuple from the first one to the last one.
|
Chris@16
|
196 */
|
Chris@16
|
197 template <typename ...Args>
|
Chris@101
|
198 struct equal_to<std::tuple<Args...>, false>
|
Chris@16
|
199 {
|
Chris@16
|
200 typedef std::tuple<Args...> value_type;
|
Chris@16
|
201
|
Chris@16
|
202 /*! \brief The type of result returned by function object. */
|
Chris@16
|
203 typedef bool result_type;
|
Chris@16
|
204
|
Chris@16
|
205 /*!
|
Chris@16
|
206 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
|
Chris@16
|
207
|
Chris@16
|
208 \param l First value.
|
Chris@16
|
209 \param r Second value.
|
Chris@16
|
210 \return true if values are equal.
|
Chris@16
|
211 */
|
Chris@16
|
212 bool operator()(value_type const& l, value_type const& r) const
|
Chris@16
|
213 {
|
Chris@16
|
214 return detail::std_tuple_equals<
|
Chris@16
|
215 value_type, 0, std::tuple_size<value_type>::value
|
Chris@16
|
216 >::apply(l ,r);
|
Chris@16
|
217 }
|
Chris@16
|
218 };
|
Chris@16
|
219
|
Chris@101
|
220 }}}} // namespace boost::geometry::index::detail
|
Chris@16
|
221
|
Chris@16
|
222 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
223
|
Chris@101
|
224 namespace boost { namespace geometry { namespace index {
|
Chris@101
|
225
|
Chris@101
|
226 /*!
|
Chris@101
|
227 \brief The function object comparing Values.
|
Chris@101
|
228
|
Chris@101
|
229 The default version handles Values which are Indexables, std::pair<T1, T2>, boost::tuple<...>
|
Chris@101
|
230 and std::tuple<...> if STD tuples and variadic templates are supported.
|
Chris@101
|
231 All members are compared from left to right, Geometries using boost::geometry::equals() function,
|
Chris@101
|
232 other types using operator==.
|
Chris@101
|
233
|
Chris@101
|
234 \tparam Value The type of objects which are compared by this function object.
|
Chris@101
|
235 */
|
Chris@101
|
236 template <typename Value>
|
Chris@101
|
237 struct equal_to
|
Chris@101
|
238 : detail::equal_to<Value>
|
Chris@101
|
239 {
|
Chris@101
|
240 /*! \brief The type of result returned by function object. */
|
Chris@101
|
241 typedef typename detail::equal_to<Value>::result_type result_type;
|
Chris@101
|
242
|
Chris@101
|
243 /*!
|
Chris@101
|
244 \brief Compare Values.
|
Chris@101
|
245
|
Chris@101
|
246 \param l First value.
|
Chris@101
|
247 \param r Second value.
|
Chris@101
|
248 \return true if Values are equal.
|
Chris@101
|
249 */
|
Chris@101
|
250 inline bool operator()(Value const& l, Value const& r) const
|
Chris@101
|
251 {
|
Chris@101
|
252 return detail::equal_to<Value>::operator()(l ,r);
|
Chris@101
|
253 }
|
Chris@101
|
254 };
|
Chris@101
|
255
|
Chris@101
|
256 }}} // namespace boost::geometry::index
|
Chris@101
|
257
|
Chris@16
|
258 #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
|