translator.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Boost.Geometry Index
  2. //
  3. // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
  4. //
  5. // This file was modified by Oracle on 2019-2020.
  6. // Modifications copyright (c) 2019-2020 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. namespace boost { namespace geometry { namespace index {
  16. namespace detail {
  17. template <typename Strategy>
  18. struct translator_equals
  19. {
  20. template <typename EqualTo, typename Value>
  21. static inline bool apply(EqualTo const& equal_to,
  22. Value const& v1, Value const& v2,
  23. Strategy const& strategy)
  24. {
  25. return equal_to(v1, v2, strategy);
  26. }
  27. };
  28. template <>
  29. struct translator_equals<default_strategy>
  30. {
  31. template <typename EqualTo, typename Value>
  32. static inline bool apply(EqualTo const& equal_to,
  33. Value const& v1, Value const& v2,
  34. default_strategy const&)
  35. {
  36. return equal_to(v1, v2);
  37. }
  38. };
  39. template <typename IndexableGetter, typename EqualTo>
  40. struct translator
  41. : public IndexableGetter
  42. , public EqualTo
  43. {
  44. typedef typename IndexableGetter::result_type result_type;
  45. translator(IndexableGetter const& i, EqualTo const& e)
  46. : IndexableGetter(i), EqualTo(e)
  47. {}
  48. template <typename Value>
  49. result_type operator()(Value const& value) const
  50. {
  51. return IndexableGetter::operator()(value);
  52. }
  53. template <typename Value, typename Strategy>
  54. bool equals(Value const& v1, Value const& v2, Strategy const& strategy) const
  55. {
  56. return translator_equals
  57. <
  58. Strategy
  59. >::apply(static_cast<EqualTo const&>(*this), v1, v2, strategy);
  60. }
  61. };
  62. template <typename IndexableGetter>
  63. struct result_type
  64. {
  65. typedef typename IndexableGetter::result_type type;
  66. };
  67. template <typename IndexableGetter>
  68. struct indexable_type
  69. {
  70. typedef typename std::remove_const<
  71. typename std::remove_reference<
  72. typename result_type<IndexableGetter>::type
  73. >::type
  74. >::type type;
  75. };
  76. } // namespace detail
  77. }}} // namespace boost::geometry::index
  78. #endif // BOOST_GEOMETRY_INDEX_DETAIL_TRANSLATOR_HPP