File indexing completed on 2025-01-18 09:35:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
0014 #define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
0015
0016 #include <boost/geometry/algorithms/detail/equals/interface.hpp>
0017 #include <boost/geometry/index/indexable.hpp>
0018
0019 #include <tuple>
0020
0021 namespace boost { namespace geometry { namespace index { namespace detail
0022 {
0023
0024 template <typename Geometry,
0025 typename Tag = typename geometry::tag<Geometry>::type>
0026 struct equals
0027 {
0028 template <typename Strategy>
0029 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const&)
0030 {
0031 return geometry::equals(g1, g2);
0032 }
0033 };
0034
0035 template <typename Geometry>
0036 struct equals<Geometry, point_tag>
0037 {
0038 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
0039 {
0040 return geometry::equals(g1, g2);
0041 }
0042
0043 template <typename Strategy>
0044 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
0045 {
0046 return geometry::equals(g1, g2, s);
0047 }
0048 };
0049
0050 template <typename Geometry>
0051 struct equals<Geometry, box_tag>
0052 {
0053 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
0054 {
0055 return geometry::equals(g1, g2);
0056 }
0057
0058 template <typename Strategy>
0059 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
0060 {
0061 return geometry::equals(g1, g2, s);
0062 }
0063 };
0064
0065 template <typename Geometry>
0066 struct equals<Geometry, segment_tag>
0067 {
0068 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
0069 {
0070 return geometry::equals(g1, g2);
0071 }
0072
0073 template <typename Strategy>
0074 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
0075 {
0076 return geometry::equals(g1, g2, s);
0077 }
0078 };
0079
0080
0081 template <typename Geometry, typename Tag>
0082 struct equals<Geometry *, Tag>
0083 {
0084 template <typename Strategy>
0085 inline static bool apply(const Geometry * g1, const Geometry * g2, Strategy const&)
0086 {
0087 return g1 == g2;
0088 }
0089 };
0090
0091 template <typename T>
0092 struct equals<T, void>
0093 {
0094 template <typename Strategy>
0095 inline static bool apply(T const& v1, T const& v2, Strategy const&)
0096 {
0097 return v1 == v2;
0098 }
0099 };
0100
0101 template <typename T>
0102 struct equals<T *, void>
0103 {
0104 template <typename Strategy>
0105 inline static bool apply(const T * v1, const T * v2, Strategy const&)
0106 {
0107 return v1 == v2;
0108 }
0109 };
0110
0111 template <typename Tuple, size_t I, size_t N>
0112 struct tuple_equals
0113 {
0114 template <typename Strategy>
0115 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
0116 {
0117 typedef typename boost::tuples::element<I, Tuple>::type T;
0118
0119 return equals<T>::apply(boost::get<I>(t1), boost::get<I>(t2), strategy)
0120 && tuple_equals<Tuple, I + 1, N>::apply(t1, t2, strategy);
0121 }
0122 };
0123
0124 template <typename Tuple, size_t I>
0125 struct tuple_equals<Tuple, I, I>
0126 {
0127 template <typename Strategy>
0128 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
0129 {
0130 return true;
0131 }
0132 };
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150 template <typename Value,
0151 bool IsIndexable = is_indexable<Value>::value>
0152 struct equal_to
0153 {
0154
0155 typedef bool result_type;
0156
0157
0158
0159
0160
0161
0162
0163
0164 template <typename Strategy>
0165 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
0166 {
0167 return detail::equals<Value>::apply(l, r, strategy);
0168 }
0169 };
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 template <typename T1, typename T2>
0181 struct equal_to<std::pair<T1, T2>, false>
0182 {
0183
0184 typedef bool result_type;
0185
0186
0187
0188
0189
0190
0191
0192
0193 template <typename Strategy>
0194 inline bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r,
0195 Strategy const& strategy) const
0196 {
0197 return detail::equals<T1>::apply(l.first, r.first, strategy)
0198 && detail::equals<T2>::apply(l.second, r.second, strategy);
0199 }
0200 };
0201
0202
0203
0204
0205
0206
0207
0208 template <typename T0, typename T1, typename T2, typename T3, typename T4,
0209 typename T5, typename T6, typename T7, typename T8, typename T9>
0210 struct equal_to<boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
0211 {
0212 typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
0213
0214
0215 typedef bool result_type;
0216
0217
0218
0219
0220
0221
0222
0223
0224 template <typename Strategy>
0225 inline bool operator()(value_type const& l, value_type const& r,
0226 Strategy const& strategy) const
0227 {
0228 return detail::tuple_equals<
0229 value_type, 0, boost::tuples::length<value_type>::value
0230 >::apply(l, r, strategy);
0231 }
0232 };
0233
0234 }}}}
0235
0236 namespace boost { namespace geometry { namespace index { namespace detail {
0237
0238 template <typename Tuple, size_t I, size_t N>
0239 struct std_tuple_equals
0240 {
0241 template <typename Strategy>
0242 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
0243 {
0244 typedef typename std::tuple_element<I, Tuple>::type T;
0245
0246 return equals<T>::apply(std::get<I>(t1), std::get<I>(t2), strategy)
0247 && std_tuple_equals<Tuple, I + 1, N>::apply(t1, t2, strategy);
0248 }
0249 };
0250
0251 template <typename Tuple, size_t I>
0252 struct std_tuple_equals<Tuple, I, I>
0253 {
0254 template <typename Strategy>
0255 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
0256 {
0257 return true;
0258 }
0259 };
0260
0261
0262
0263
0264
0265
0266
0267
0268 template <typename ...Args>
0269 struct equal_to<std::tuple<Args...>, false>
0270 {
0271 typedef std::tuple<Args...> value_type;
0272
0273
0274 typedef bool result_type;
0275
0276
0277
0278
0279
0280
0281
0282
0283 template <typename Strategy>
0284 bool operator()(value_type const& l, value_type const& r, Strategy const& strategy) const
0285 {
0286 return detail::std_tuple_equals<
0287 value_type, 0, std::tuple_size<value_type>::value
0288 >::apply(l, r, strategy);
0289 }
0290 };
0291
0292 }}}}
0293
0294
0295 namespace boost { namespace geometry { namespace index {
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307 template <typename Value>
0308 struct equal_to
0309 : detail::equal_to<Value>
0310 {
0311
0312 typedef typename detail::equal_to<Value>::result_type result_type;
0313
0314
0315
0316
0317
0318
0319
0320
0321 inline bool operator()(Value const& l, Value const& r) const
0322 {
0323 return detail::equal_to<Value>::operator()(l, r, default_strategy());
0324 }
0325
0326 template <typename Strategy>
0327 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
0328 {
0329 return detail::equal_to<Value>::operator()(l, r, strategy);
0330 }
0331 };
0332
0333 }}}
0334
0335 #endif