closeable_view.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.
  6. // Modifications copyright (c) 2020 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/ring_type.hpp>
  17. #include <boost/geometry/core/tag.hpp>
  18. #include <boost/geometry/core/tags.hpp>
  19. #include <boost/geometry/iterators/closing_iterator.hpp>
  20. #include <boost/geometry/views/identity_view.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. // Silence warning C4512: assignment operator could not be generated
  24. #if defined(_MSC_VER)
  25. #pragma warning(push)
  26. #pragma warning(disable : 4512)
  27. #endif
  28. #ifndef DOXYGEN_NO_DETAIL
  29. namespace detail
  30. {
  31. template <typename Range>
  32. struct closing_view
  33. {
  34. // Keep this explicit, important for nested views/ranges
  35. explicit inline closing_view(Range& r)
  36. : m_range(r)
  37. {}
  38. typedef closing_iterator<Range> iterator;
  39. typedef closing_iterator<Range const> const_iterator;
  40. inline const_iterator begin() const { return const_iterator(m_range); }
  41. inline const_iterator end() const { return const_iterator(m_range, true); }
  42. inline iterator begin() { return iterator(m_range); }
  43. inline iterator end() { return iterator(m_range, true); }
  44. private :
  45. Range& m_range;
  46. };
  47. }
  48. #endif // DOXYGEN_NO_DETAIL
  49. /*!
  50. \brief View on a range, either closing it or leaving it as it is
  51. \details The closeable_view is used internally by the library to handle all rings,
  52. either closed or open, the same way. The default method is closed, all
  53. algorithms process rings as if they are closed. Therefore, if they are opened,
  54. a view is created which closes them.
  55. The closeable_view might be used by library users, but its main purpose is
  56. internally.
  57. \tparam Range Original range
  58. \tparam Close Specifies if it the range is closed, if so, nothing will happen.
  59. If it is open, it will iterate the first point after the last point.
  60. \ingroup views
  61. */
  62. template <typename Range, closure_selector Close>
  63. struct closeable_view {};
  64. #ifndef DOXYGEN_NO_SPECIALIZATIONS
  65. template <typename Range>
  66. struct closeable_view<Range, closed>
  67. {
  68. typedef identity_view<Range> type;
  69. };
  70. template <typename Range>
  71. struct closeable_view<Range, open>
  72. {
  73. typedef detail::closing_view<Range> type;
  74. };
  75. #endif // DOXYGEN_NO_SPECIALIZATIONS
  76. #if defined(_MSC_VER)
  77. #pragma warning(pop)
  78. #endif
  79. }} // namespace boost::geometry
  80. #endif // BOOST_GEOMETRY_VIEWS_CLOSEABLE_VIEW_HPP