reversible_view.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. // This file was modified by Oracle on 2020-2021.
  6. // Modifications copyright (c) 2020-2021 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_VIEWS_REVERSIBLE_VIEW_HPP
  14. #define BOOST_GEOMETRY_VIEWS_REVERSIBLE_VIEW_HPP
  15. #include <boost/version.hpp>
  16. #include <boost/range/adaptor/reversed.hpp>
  17. #include <boost/geometry/core/closure.hpp>
  18. #include <boost/geometry/core/point_order.hpp>
  19. #include <boost/geometry/core/ring_type.hpp>
  20. #include <boost/geometry/core/tag.hpp>
  21. #include <boost/geometry/core/tags.hpp>
  22. #include <boost/geometry/util/order_as_direction.hpp>
  23. #include <boost/geometry/views/identity_view.hpp>
  24. namespace boost { namespace geometry
  25. {
  26. #ifndef DOXYGEN_NO_DETAIL
  27. namespace detail
  28. {
  29. template
  30. <
  31. typename Range,
  32. order_selector Order = geometry::point_order<Range>::value
  33. >
  34. struct clockwise_view
  35. : identity_view<Range>
  36. {
  37. explicit inline clockwise_view(Range& r)
  38. : identity_view<Range>(r)
  39. {}
  40. };
  41. template <typename Range>
  42. struct clockwise_view<Range, counterclockwise>
  43. : boost::reversed_range<Range>
  44. {
  45. explicit inline clockwise_view(Range& r)
  46. : boost::reversed_range<Range>(r)
  47. {}
  48. };
  49. } // namespace detail
  50. #endif // DOXYGEN_NO_DETAIL
  51. /*!
  52. \brief View on a range, reversing direction if necessary
  53. \tparam Range original range
  54. \tparam Direction direction of iteration
  55. \ingroup views
  56. */
  57. template <typename Range, iterate_direction Direction>
  58. struct reversible_view {};
  59. #ifndef DOXYGEN_NO_SPECIALIZATIONS
  60. template <typename Range>
  61. struct reversible_view<Range, iterate_forward>
  62. {
  63. using type = identity_view<Range>;
  64. };
  65. template <typename Range>
  66. struct reversible_view<Range, iterate_reverse>
  67. {
  68. using type = boost::reversed_range<Range>;
  69. };
  70. #endif // DOXYGEN_NO_SPECIALIZATIONS
  71. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  72. namespace traits
  73. {
  74. template <typename Range, order_selector Order>
  75. struct tag<detail::clockwise_view<Range, Order> >
  76. : geometry::tag<Range>
  77. {};
  78. template <typename Range, order_selector Order>
  79. struct point_order<detail::clockwise_view<Range, Order> >
  80. {
  81. static const order_selector value = clockwise;
  82. };
  83. template <typename Range, order_selector Order>
  84. struct closure<detail::clockwise_view<Range, Order> >
  85. : geometry::closure<Range>
  86. {};
  87. } // namespace traits
  88. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  89. }} // namespace boost::geometry
  90. #endif // BOOST_GEOMETRY_VIEWS_REVERSIBLE_VIEW_HPP