Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:34

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 = 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 // 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     \return true if values are equal.
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 \brief The function object comparing Values.
0173 
0174 This specialization compares values of type std::pair<T1, T2>.
0175 It compares pairs' first values, then second values.
0176 
0177 \tparam T1       The first type.
0178 \tparam T2       The second type.
0179 */
0180 template <typename T1, typename T2>
0181 struct equal_to<std::pair<T1, T2>, false>
0182 {
0183     /*! \brief The type of result returned by function object. */
0184     typedef bool result_type;
0185 
0186     /*!
0187     \brief Compare values. If pair<> Value member is a Geometry geometry::equals() function is used.
0188 
0189     \param l First value.
0190     \param r Second value.
0191     \return true if values are equal.
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 \brief The function object comparing Values.
0204 
0205 This specialization compares values of type boost::tuple<...>.
0206 It compares all members of the tuple from the first one to the last one.
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     /*! \brief The type of result returned by function object. */
0215     typedef bool result_type;
0216 
0217     /*!
0218     \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
0219 
0220     \param l First value.
0221     \param r Second value.
0222     \return true if values are equal.
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 }}}} // namespace boost::geometry::index::detail
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 \brief The function object comparing Values.
0263 
0264 This specialization compares values of type std::tuple<Args...>.
0265 It's defined if the compiler supports tuples and variadic templates.
0266 It compares all members of the tuple from the first one to the last one.
0267 */
0268 template <typename ...Args>
0269 struct equal_to<std::tuple<Args...>, false>
0270 {
0271     typedef std::tuple<Args...> value_type;
0272 
0273     /*! \brief The type of result returned by function object. */
0274     typedef bool result_type;
0275 
0276     /*!
0277     \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
0278 
0279     \param l First value.
0280     \param r Second value.
0281     \return true if values are equal.
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 }}}} // namespace boost::geometry::index::detail
0293 
0294 
0295 namespace boost { namespace geometry { namespace index {
0296 
0297 /*!
0298 \brief The function object comparing Values.
0299 
0300 The default version handles Values which are Indexables, std::pair<T1, T2>, boost::tuple<...>
0301 and std::tuple<...> if STD tuples and variadic templates are supported.
0302 All members are compared from left to right, Geometries using boost::geometry::equals() function,
0303 other types using operator==.
0304 
0305 \tparam Value       The type of objects which are compared by this function object.
0306 */
0307 template <typename Value>
0308 struct equal_to
0309     : detail::equal_to<Value>
0310 {
0311     /*! \brief The type of result returned by function object. */
0312     typedef typename detail::equal_to<Value>::result_type result_type;
0313 
0314     /*!
0315     \brief Compare Values.
0316 
0317     \param l First value.
0318     \param r Second value.
0319     \return true if Values are equal.
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 }}} // namespace boost::geometry::index
0334 
0335 #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP