closeable_view.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_CLOSEABLE_VIEW_HPP
  14. #define BOOST_GEOMETRY_VIEWS_CLOSEABLE_VIEW_HPP
  15. #include <boost/geometry/core/closure.hpp>
  16. #include <boost/geometry/core/point_order.hpp>
  17. #include <boost/geometry/core/ring_type.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. #include <boost/geometry/iterators/closing_iterator.hpp>
  21. #include <boost/geometry/views/identity_view.hpp>
  22. namespace boost { namespace geometry
  23. {
  24. #ifndef DOXYGEN_NO_DETAIL
  25. namespace detail
  26. {
  27. template <typename Range>
  28. struct closing_view
  29. {
  30. using iterator = closing_iterator<Range const>;
  31. using const_iterator = closing_iterator<Range const>;
  32. // Keep this explicit, important for nested views/ranges
  33. explicit inline closing_view(Range const& r)
  34. : m_begin(r)
  35. , m_end(r, true)
  36. {}
  37. inline const_iterator begin() const { return m_begin; }
  38. inline const_iterator end() const { return m_end; }
  39. private:
  40. const_iterator m_begin;
  41. const_iterator m_end;
  42. };
  43. template
  44. <
  45. typename Range,
  46. closure_selector Close = geometry::closure<Range>::value
  47. >
  48. struct closed_view
  49. : identity_view<Range>
  50. {
  51. explicit inline closed_view(Range const& r)
  52. : identity_view<Range const>(r)
  53. {}
  54. };
  55. template <typename Range>
  56. struct closed_view<Range, open>
  57. : closing_view<Range>
  58. {
  59. explicit inline closed_view(Range const& r)
  60. : closing_view<Range const>(r)
  61. {}
  62. };
  63. } // namespace detail
  64. #endif // DOXYGEN_NO_DETAIL
  65. /*!
  66. \brief View on a range, either closing it or leaving it as it is
  67. \details The closeable_view is used internally by the library to handle all rings,
  68. either closed or open, the same way. The default method is closed, all
  69. algorithms process rings as if they are closed. Therefore, if they are opened,
  70. a view is created which closes them.
  71. The closeable_view might be used by library users, but its main purpose is
  72. internally.
  73. \tparam Range Original range
  74. \tparam Close Specifies if it the range is closed, if so, nothing will happen.
  75. If it is open, it will iterate the first point after the last point.
  76. \ingroup views
  77. */
  78. template <typename Range, closure_selector Close>
  79. struct closeable_view {};
  80. #ifndef DOXYGEN_NO_SPECIALIZATIONS
  81. template <typename Range>
  82. struct closeable_view<Range, closed>
  83. {
  84. using type = identity_view<Range>;
  85. };
  86. template <typename Range>
  87. struct closeable_view<Range, open>
  88. {
  89. using type = detail::closing_view<Range>;
  90. };
  91. #endif // DOXYGEN_NO_SPECIALIZATIONS
  92. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  93. namespace traits
  94. {
  95. template <typename Range, closure_selector Close>
  96. struct tag<detail::closed_view<Range, Close> >
  97. : geometry::tag<Range>
  98. {};
  99. template <typename Range, closure_selector Close>
  100. struct point_order<detail::closed_view<Range, Close> >
  101. : geometry::point_order<Range>
  102. {};
  103. template <typename Range, closure_selector Close>
  104. struct closure<detail::closed_view<Range, Close> >
  105. {
  106. static const closure_selector value = closed;
  107. };
  108. } // namespace traits
  109. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  110. }} // namespace boost::geometry
  111. #endif // BOOST_GEOMETRY_VIEWS_CLOSEABLE_VIEW_HPP