Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:43:19

0001 // Boost.Geometry Index
0002 //
0003 // Copyright (c) 2011-2016 Adam Wulkiewicz, Lodz, Poland.
0004 //
0005 // This file was modified by Oracle on 2019-2020.
0006 // Modifications copyright (c) 2019-2020 Oracle and/or its affiliates.
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0008 //
0009 // Use, modification and distribution is subject to the Boost Software License,
0010 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
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 = geometry::tag_t<Geometry>>
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 // TODO: Consider this: Since equal_to<> is using geometry::equals() it's possible that
0135 //       two compared Indexables are not exactly the same! They will be spatially equal
0136 //       but not strictly equal. Consider 2 Segments with reversed order of points.
0137 //       Therefore it's possible that during the Value removal different value will be
0138 //       removed than the one that was passed.
0139 
0140 /*!
0141 \brief The function object comparing Values.
0142 
0143 It compares Geometries using geometry::equals() function. Other types are compared using operator==.
0144 The default version handles Values which are Indexables.
0145 This template is also specialized for std::pair<T1, T2> and boost::tuple<...>.
0146 
0147 \tparam Value       The type of objects which are compared by this function object.
0148 \tparam IsIndexable If true, Values are compared using boost::geometry::equals() functions.
0149 */
0150 template <typename Value,
0151           bool IsIndexable = is_indexable<Value>::value>
0152 struct equal_to
0153 {
0154     /*! \brief The type of result returned by function object. */
0155     typedef bool result_type;
0156 
0157     /*!
0158     \brief Compare values. If Value is a Geometry geometry::equals() function is used.
0159 
0160     \param l First value.
0161     \param r Second value.
0162     \param strategy Strategy to be used.
0163     \return true if values are equal.
0164     */
0165     template <typename Strategy>
0166     inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
0167     {
0168         return detail::equals<Value>::apply(l, r, strategy);
0169     }
0170 };
0171 
0172 /*!
0173 \brief The function object comparing Values.
0174 
0175 This specialization compares values of type std::pair<T1, T2>.
0176 It compares pairs' first values, then second values.
0177 
0178 \tparam T1       The first type.
0179 \tparam T2       The second type.
0180 */
0181 template <typename T1, typename T2>
0182 struct equal_to<std::pair<T1, T2>, false>
0183 {
0184     /*! \brief The type of result returned by function object. */
0185     typedef bool result_type;
0186 
0187     /*!
0188     \brief Compare values. If pair<> Value member is a Geometry geometry::equals() function is used.
0189 
0190     \param l First value.
0191     \param r Second value.
0192     \param strategy Strategy to be used.
0193     \return true if values are equal.
0194     */
0195     template <typename Strategy>
0196     inline bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r,
0197                            Strategy const& strategy) const
0198     {
0199         return detail::equals<T1>::apply(l.first, r.first, strategy)
0200             && detail::equals<T2>::apply(l.second, r.second, strategy);
0201     }
0202 };
0203 
0204 /*!
0205 \brief The function object comparing Values.
0206 
0207 This specialization compares values of type boost::tuple<...>.
0208 It compares all members of the tuple from the first one to the last one.
0209 */
0210 template <typename T0, typename T1, typename T2, typename T3, typename T4,
0211           typename T5, typename T6, typename T7, typename T8, typename T9>
0212 struct equal_to<boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
0213 {
0214     typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
0215 
0216     /*! \brief The type of result returned by function object. */
0217     typedef bool result_type;
0218 
0219     /*!
0220     \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
0221 
0222     \param l First value.
0223     \param r Second value.
0224     \param strategy Strategy to be used.
0225     \return true if values are equal.
0226     */
0227     template <typename Strategy>
0228     inline bool operator()(value_type const& l, value_type const& r,
0229                            Strategy const& strategy) const
0230     {
0231         return detail::tuple_equals<
0232             value_type, 0, boost::tuples::length<value_type>::value
0233         >::apply(l, r, strategy);
0234     }
0235 };
0236 
0237 }}}} // namespace boost::geometry::index::detail
0238 
0239 namespace boost { namespace geometry { namespace index { namespace detail {
0240 
0241 template <typename Tuple, size_t I, size_t N>
0242 struct std_tuple_equals
0243 {
0244     template <typename Strategy>
0245     inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
0246     {
0247         typedef typename std::tuple_element<I, Tuple>::type T;
0248 
0249         return equals<T>::apply(std::get<I>(t1), std::get<I>(t2), strategy)
0250             && std_tuple_equals<Tuple, I + 1, N>::apply(t1, t2, strategy);
0251     }
0252 };
0253 
0254 template <typename Tuple, size_t I>
0255 struct std_tuple_equals<Tuple, I, I>
0256 {
0257     template <typename Strategy>
0258     inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
0259     {
0260         return true;
0261     }
0262 };
0263 
0264 /*!
0265 \brief The function object comparing Values.
0266 
0267 This specialization compares values of type std::tuple<Args...>.
0268 It's defined if the compiler supports tuples and variadic templates.
0269 It compares all members of the tuple from the first one to the last one.
0270 */
0271 template <typename ...Args>
0272 struct equal_to<std::tuple<Args...>, false>
0273 {
0274     typedef std::tuple<Args...> value_type;
0275 
0276     /*! \brief The type of result returned by function object. */
0277     typedef bool result_type;
0278 
0279     /*!
0280     \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
0281 
0282     \param l First value.
0283     \param r Second value.
0284     \param strategy Strategy to be used.
0285     \return true if values are equal.
0286     */
0287     template <typename Strategy>
0288     bool operator()(value_type const& l, value_type const& r, Strategy const& strategy) const
0289     {
0290         return detail::std_tuple_equals<
0291             value_type, 0, std::tuple_size<value_type>::value
0292         >::apply(l, r, strategy);
0293     }
0294 };
0295 
0296 }}}} // namespace boost::geometry::index::detail
0297 
0298 
0299 namespace boost { namespace geometry { namespace index {
0300 
0301 /*!
0302 \brief The function object comparing Values.
0303 
0304 The default version handles Values which are Indexables, std::pair<T1, T2>, boost::tuple<...>
0305 and std::tuple<...> if STD tuples and variadic templates are supported.
0306 All members are compared from left to right, Geometries using boost::geometry::equals() function,
0307 other types using operator==.
0308 
0309 \tparam Value       The type of objects which are compared by this function object.
0310 */
0311 template <typename Value>
0312 struct equal_to
0313     : detail::equal_to<Value>
0314 {
0315     /*! \brief The type of result returned by function object. */
0316     typedef typename detail::equal_to<Value>::result_type result_type;
0317 
0318     /*!
0319     \brief Compare Values.
0320 
0321     \param l First value.
0322     \param r Second value.
0323     \return true if Values are equal.
0324     */
0325     inline bool operator()(Value const& l, Value const& r) const
0326     {
0327         return detail::equal_to<Value>::operator()(l, r, default_strategy());
0328     }
0329 
0330     template <typename Strategy>
0331     inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
0332     {
0333         return detail::equal_to<Value>::operator()(l, r, strategy);
0334     }
0335 };
0336 
0337 }}} // namespace boost::geometry::index
0338 
0339 #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP