clear.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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_ALGORITHMS_CLEAR_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
  12. #include <boost/geometry/algorithms/not_implemented.hpp>
  13. #include <boost/geometry/core/access.hpp>
  14. #include <boost/geometry/core/exterior_ring.hpp>
  15. #include <boost/geometry/core/interior_rings.hpp>
  16. #include <boost/geometry/core/mutable_range.hpp>
  17. #include <boost/geometry/core/tag_cast.hpp>
  18. #include <boost/geometry/geometries/concepts/check.hpp>
  19. #include <boost/type_traits/remove_const.hpp>
  20. #include <boost/variant/apply_visitor.hpp>
  21. #include <boost/variant/static_visitor.hpp>
  22. #include <boost/variant/variant_fwd.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_DETAIL
  26. namespace detail { namespace clear
  27. {
  28. template <typename Geometry>
  29. struct collection_clear
  30. {
  31. static inline void apply(Geometry& geometry)
  32. {
  33. traits::clear<Geometry>::apply(geometry);
  34. }
  35. };
  36. template <typename Polygon>
  37. struct polygon_clear
  38. {
  39. static inline void apply(Polygon& polygon)
  40. {
  41. traits::clear
  42. <
  43. typename boost::remove_reference
  44. <
  45. typename traits::interior_mutable_type<Polygon>::type
  46. >::type
  47. >::apply(interior_rings(polygon));
  48. traits::clear
  49. <
  50. typename boost::remove_reference
  51. <
  52. typename traits::ring_mutable_type<Polygon>::type
  53. >::type
  54. >::apply(exterior_ring(polygon));
  55. }
  56. };
  57. template <typename Geometry>
  58. struct no_action
  59. {
  60. static inline void apply(Geometry& )
  61. {
  62. }
  63. };
  64. }} // namespace detail::clear
  65. #endif // DOXYGEN_NO_DETAIL
  66. #ifndef DOXYGEN_NO_DISPATCH
  67. namespace dispatch
  68. {
  69. template
  70. <
  71. typename Geometry,
  72. typename Tag = typename tag_cast<typename tag<Geometry>::type, multi_tag>::type
  73. >
  74. struct clear: not_implemented<Tag>
  75. {};
  76. // Point/box/segment do not have clear. So specialize to do nothing.
  77. template <typename Geometry>
  78. struct clear<Geometry, point_tag>
  79. : detail::clear::no_action<Geometry>
  80. {};
  81. template <typename Geometry>
  82. struct clear<Geometry, box_tag>
  83. : detail::clear::no_action<Geometry>
  84. {};
  85. template <typename Geometry>
  86. struct clear<Geometry, segment_tag>
  87. : detail::clear::no_action<Geometry>
  88. {};
  89. template <typename Geometry>
  90. struct clear<Geometry, linestring_tag>
  91. : detail::clear::collection_clear<Geometry>
  92. {};
  93. template <typename Geometry>
  94. struct clear<Geometry, ring_tag>
  95. : detail::clear::collection_clear<Geometry>
  96. {};
  97. // Polygon can (indirectly) use std for clear
  98. template <typename Polygon>
  99. struct clear<Polygon, polygon_tag>
  100. : detail::clear::polygon_clear<Polygon>
  101. {};
  102. template <typename Geometry>
  103. struct devarianted_clear
  104. {
  105. static inline void apply(Geometry& geometry)
  106. {
  107. clear<Geometry>::apply(geometry);
  108. }
  109. };
  110. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  111. struct devarianted_clear<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  112. {
  113. struct visitor: static_visitor<void>
  114. {
  115. template <typename Geometry>
  116. inline void operator()(Geometry& geometry) const
  117. {
  118. clear<Geometry>::apply(geometry);
  119. }
  120. };
  121. static inline void apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry)
  122. {
  123. apply_visitor(visitor(), geometry);
  124. }
  125. };
  126. } // namespace dispatch
  127. #endif // DOXYGEN_NO_DISPATCH
  128. /*!
  129. \brief Clears a linestring, ring or polygon (exterior+interiors) or multi*
  130. \details Generic function to clear a geometry. All points will be removed from the collection or collections
  131. making up the geometry. In most cases this is equivalent to the .clear() method of a std::vector<...>. In
  132. the case of a polygon, this clear functionality is automatically called for the exterior ring, and for the
  133. interior ring collection. In the case of a point, boxes and segments, nothing will happen.
  134. \ingroup clear
  135. \tparam Geometry \tparam_geometry
  136. \param geometry \param_geometry which will be cleared
  137. \note points and boxes cannot be cleared, instead they can be set to zero by "assign_zero"
  138. \qbk{[include reference/algorithms/clear.qbk]}
  139. */
  140. template <typename Geometry>
  141. inline void clear(Geometry& geometry)
  142. {
  143. concept::check<Geometry>();
  144. dispatch::devarianted_clear<Geometry>::apply(geometry);
  145. }
  146. }} // namespace boost::geometry
  147. #endif // BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP