compare.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_STRATEGIES_COMPARE_HPP
  11. #define BOOST_GEOMETRY_STRATEGIES_COMPARE_HPP
  12. #include <cstddef>
  13. #include <functional>
  14. #include <boost/mpl/if.hpp>
  15. #include <boost/geometry/core/cs.hpp>
  16. #include <boost/geometry/core/coordinate_type.hpp>
  17. #include <boost/geometry/strategies/tags.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. /*!
  21. \brief Traits class binding a comparing strategy to a coordinate system
  22. \ingroup util
  23. \tparam Tag tag of coordinate system of point-type
  24. \tparam Direction direction to compare on: 1 for less (-> ascending order)
  25. and -1 for greater (-> descending order)
  26. \tparam Point point-type
  27. \tparam CoordinateSystem coordinate sytem of point
  28. \tparam Dimension: the dimension to compare on
  29. */
  30. template
  31. <
  32. typename Tag,
  33. int Direction,
  34. typename Point,
  35. typename CoordinateSystem,
  36. std::size_t Dimension
  37. >
  38. struct strategy_compare
  39. {
  40. typedef strategy::not_implemented type;
  41. };
  42. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  43. // For compare we add defaults specializations,
  44. // because they defaultly redirect to std::less / greater / equal_to
  45. template
  46. <
  47. typename Tag,
  48. typename Point,
  49. typename CoordinateSystem,
  50. std::size_t Dimension
  51. >
  52. struct strategy_compare<Tag, 1, Point, CoordinateSystem, Dimension>
  53. {
  54. typedef std::less<typename coordinate_type<Point>::type> type;
  55. };
  56. template
  57. <
  58. typename Tag,
  59. typename Point,
  60. typename CoordinateSystem,
  61. std::size_t Dimension
  62. >
  63. struct strategy_compare<Tag, -1, Point, CoordinateSystem, Dimension>
  64. {
  65. typedef std::greater<typename coordinate_type<Point>::type> type;
  66. };
  67. template
  68. <
  69. typename Tag,
  70. typename Point,
  71. typename CoordinateSystem,
  72. std::size_t Dimension
  73. >
  74. struct strategy_compare<Tag, 0, Point, CoordinateSystem, Dimension>
  75. {
  76. typedef std::equal_to<typename coordinate_type<Point>::type> type;
  77. };
  78. #endif
  79. namespace strategy { namespace compare
  80. {
  81. /*!
  82. \brief Default strategy, indicates the default strategy for comparisons
  83. \details The default strategy for comparisons defer in most cases
  84. to std::less (for ascending) and std::greater (for descending).
  85. However, if a spherical coordinate system is used, and comparison
  86. is done on longitude, it will take another strategy handling circular
  87. */
  88. struct default_strategy {};
  89. #ifndef DOXYGEN_NO_DETAIL
  90. namespace detail
  91. {
  92. template <typename Type>
  93. struct is_default : boost::false_type
  94. {};
  95. template <>
  96. struct is_default<default_strategy> : boost::true_type
  97. {};
  98. /*!
  99. \brief Meta-function to select strategy
  100. \details If "default_strategy" is specified, it will take the
  101. traits-registered class for the specified coordinate system.
  102. If another strategy is explicitly specified, it takes that one.
  103. */
  104. template
  105. <
  106. typename Strategy,
  107. int Direction,
  108. typename Point,
  109. std::size_t Dimension
  110. >
  111. struct select_strategy
  112. {
  113. typedef typename
  114. boost::mpl::if_
  115. <
  116. is_default<Strategy>,
  117. typename strategy_compare
  118. <
  119. typename cs_tag<Point>::type,
  120. Direction,
  121. Point,
  122. typename coordinate_system<Point>::type,
  123. Dimension
  124. >::type,
  125. Strategy
  126. >::type type;
  127. };
  128. } // namespace detail
  129. #endif // DOXYGEN_NO_DETAIL
  130. }} // namespace strategy::compare
  131. }} // namespace boost::geometry
  132. #endif // BOOST_GEOMETRY_STRATEGIES_COMPARE_HPP