translator.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Boost.Geometry Index
  2. //
  3. // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
  4. //
  5. // This file was modified by Oracle on 2019-2021.
  6. // Modifications copyright (c) 2019-2021 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. //
  9. // Use, modification and distribution is subject to the Boost Software License,
  10. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_TRANSLATOR_HPP
  13. #define BOOST_GEOMETRY_INDEX_DETAIL_TRANSLATOR_HPP
  14. #include <type_traits>
  15. #include <boost/geometry/strategies/default_strategy.hpp>
  16. namespace boost { namespace geometry { namespace index {
  17. namespace detail {
  18. template <typename Strategy>
  19. struct translator_equals
  20. {
  21. template <typename EqualTo, typename Value>
  22. static inline bool apply(EqualTo const& equal_to,
  23. Value const& v1, Value const& v2,
  24. Strategy const& strategy)
  25. {
  26. return equal_to(v1, v2, strategy);
  27. }
  28. };
  29. template <>
  30. struct translator_equals<default_strategy>
  31. {
  32. template <typename EqualTo, typename Value>
  33. static inline bool apply(EqualTo const& equal_to,
  34. Value const& v1, Value const& v2,
  35. default_strategy const&)
  36. {
  37. return equal_to(v1, v2);
  38. }
  39. };
  40. template <typename IndexableGetter, typename EqualTo>
  41. struct translator
  42. : public IndexableGetter
  43. , public EqualTo
  44. {
  45. typedef typename IndexableGetter::result_type result_type;
  46. translator(IndexableGetter const& i, EqualTo const& e)
  47. : IndexableGetter(i), EqualTo(e)
  48. {}
  49. template <typename Value>
  50. result_type operator()(Value const& value) const
  51. {
  52. return IndexableGetter::operator()(value);
  53. }
  54. template <typename Value, typename Strategy>
  55. bool equals(Value const& v1, Value const& v2, Strategy const& strategy) const
  56. {
  57. return translator_equals
  58. <
  59. Strategy
  60. >::apply(static_cast<EqualTo const&>(*this), v1, v2, strategy);
  61. }
  62. };
  63. template <typename IndexableGetter>
  64. struct result_type
  65. {
  66. typedef typename IndexableGetter::result_type type;
  67. };
  68. template <typename IndexableGetter>
  69. struct indexable_type
  70. {
  71. typedef typename std::remove_const<
  72. typename std::remove_reference<
  73. typename result_type<IndexableGetter>::type
  74. >::type
  75. >::type type;
  76. };
  77. } // namespace detail
  78. }}} // namespace boost::geometry::index
  79. #endif // BOOST_GEOMETRY_INDEX_DETAIL_TRANSLATOR_HPP