closeable_view.hpp 2.9 KB

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