closeable_view.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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-2023.
  6. // Modifications copyright (c) 2020-2023 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_VIEWS_CLOSEABLE_VIEW_HPP
  15. #define BOOST_GEOMETRY_VIEWS_CLOSEABLE_VIEW_HPP
  16. #include <boost/geometry/core/closure.hpp>
  17. #include <boost/geometry/core/point_order.hpp>
  18. #include <boost/geometry/core/ring_type.hpp>
  19. #include <boost/geometry/core/tag.hpp>
  20. #include <boost/geometry/core/tags.hpp>
  21. #include <boost/geometry/iterators/closing_iterator.hpp>
  22. #include <boost/geometry/views/identity_view.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_DETAIL
  26. namespace detail
  27. {
  28. template <typename Range>
  29. struct closing_view
  30. {
  31. using iterator = closing_iterator<Range const>;
  32. using const_iterator = closing_iterator<Range const>;
  33. // Keep this explicit, important for nested views/ranges
  34. explicit inline closing_view(Range const& r)
  35. : m_begin(r)
  36. , m_end(r, true)
  37. {}
  38. inline const_iterator begin() const { return m_begin; }
  39. inline const_iterator end() const { return m_end; }
  40. private:
  41. const_iterator m_begin;
  42. const_iterator m_end;
  43. };
  44. template
  45. <
  46. typename Range,
  47. closure_selector Close = geometry::closure<Range>::value
  48. >
  49. struct closed_view
  50. : identity_view<Range>
  51. {
  52. explicit inline closed_view(Range const& r)
  53. : identity_view<Range const>(r)
  54. {}
  55. };
  56. template <typename Range>
  57. struct closed_view<Range, open>
  58. : closing_view<Range>
  59. {
  60. explicit inline closed_view(Range const& r)
  61. : closing_view<Range const>(r)
  62. {}
  63. };
  64. } // namespace detail
  65. #endif // DOXYGEN_NO_DETAIL
  66. /*!
  67. \brief View on a range, either closing it or leaving it as it is
  68. \details The closeable_view is used internally by the library to handle all rings,
  69. either closed or open, the same way. The default method is closed, all
  70. algorithms process rings as if they are closed. Therefore, if they are opened,
  71. a view is created which closes them.
  72. The closeable_view might be used by library users, but its main purpose is
  73. internally.
  74. \tparam Range Original range
  75. \tparam Close Specifies if it the range is closed, if so, nothing will happen.
  76. If it is open, it will iterate the first point after the last point.
  77. \ingroup views
  78. */
  79. template <typename Range, closure_selector Close>
  80. struct closeable_view {};
  81. #ifndef DOXYGEN_NO_SPECIALIZATIONS
  82. template <typename Range>
  83. struct closeable_view<Range, closed>
  84. {
  85. using type = identity_view<Range>;
  86. };
  87. template <typename Range>
  88. struct closeable_view<Range, open>
  89. {
  90. using type = detail::closing_view<Range>;
  91. };
  92. #endif // DOXYGEN_NO_SPECIALIZATIONS
  93. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  94. namespace traits
  95. {
  96. template <typename Range, closure_selector Close>
  97. struct tag<geometry::detail::closed_view<Range, Close> >
  98. : geometry::tag<Range>
  99. {};
  100. template <typename Range, closure_selector Close>
  101. struct point_order<geometry::detail::closed_view<Range, Close> >
  102. : geometry::point_order<Range>
  103. {};
  104. template <typename Range, closure_selector Close>
  105. struct closure<geometry::detail::closed_view<Range, Close> >
  106. {
  107. static const closure_selector value = closed;
  108. };
  109. } // namespace traits
  110. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  111. }} // namespace boost::geometry
  112. #endif // BOOST_GEOMETRY_VIEWS_CLOSEABLE_VIEW_HPP