1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
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
14#ifndef BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
15#define BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
16
17
18#include <boost/type_traits/remove_const.hpp>
19
20#include <boost/variant/apply_visitor.hpp>
21#include <boost/variant/static_visitor.hpp>
22#include <boost/variant/variant_fwd.hpp>
23
24#include <boost/geometry/algorithms/not_implemented.hpp>
25#include <boost/geometry/core/access.hpp>
26#include <boost/geometry/core/exterior_ring.hpp>
27#include <boost/geometry/core/interior_rings.hpp>
28#include <boost/geometry/core/mutable_range.hpp>
29#include <boost/geometry/core/tag_cast.hpp>
30#include <boost/geometry/core/tags.hpp>
31#include <boost/geometry/geometries/concepts/check.hpp>
32
33
34namespace boost { namespace geometry
35{
36
37#ifndef DOXYGEN_NO_DETAIL
38namespace detail { namespace clear
39{
40
41template <typename Geometry>
42struct collection_clear
43{
44 static inline void apply(Geometry& geometry)
45 {
46 traits::clear<Geometry>::apply(geometry);
47 }
48};
49
50template <typename Polygon>
51struct polygon_clear
52{
53 static inline void apply(Polygon& polygon)
54 {
55 traits::clear
56 <
57 typename boost::remove_reference
58 <
59 typename traits::interior_mutable_type<Polygon>::type
60 >::type
61 >::apply(interior_rings(polygon));
62 traits::clear
63 <
64 typename boost::remove_reference
65 <
66 typename traits::ring_mutable_type<Polygon>::type
67 >::type
68 >::apply(exterior_ring(polygon));
69 }
70};
71
72template <typename Geometry>
73struct no_action
74{
75 static inline void apply(Geometry& )
76 {
77 }
78};
79
80
81}} // namespace detail::clear
82#endif // DOXYGEN_NO_DETAIL
83
84#ifndef DOXYGEN_NO_DISPATCH
85namespace dispatch
86{
87
88template
89<
90 typename Geometry,
91 typename Tag = typename tag_cast<typename tag<Geometry>::type, multi_tag>::type
92>
93struct clear: not_implemented<Tag>
94{};
95
96// Point/box/segment do not have clear. So specialize to do nothing.
97template <typename Geometry>
98struct clear<Geometry, point_tag>
99 : detail::clear::no_action<Geometry>
100{};
101
102template <typename Geometry>
103struct clear<Geometry, box_tag>
104 : detail::clear::no_action<Geometry>
105{};
106
107template <typename Geometry>
108struct clear<Geometry, segment_tag>
109 : detail::clear::no_action<Geometry>
110{};
111
112template <typename Geometry>
113struct clear<Geometry, linestring_tag>
114 : detail::clear::collection_clear<Geometry>
115{};
116
117template <typename Geometry>
118struct clear<Geometry, ring_tag>
119 : detail::clear::collection_clear<Geometry>
120{};
121
122
123// Polygon can (indirectly) use std for clear
124template <typename Polygon>
125struct clear<Polygon, polygon_tag>
126 : detail::clear::polygon_clear<Polygon>
127{};
128
129
130template <typename Geometry>
131struct clear<Geometry, multi_tag>
132 : detail::clear::collection_clear<Geometry>
133{};
134
135
136} // namespace dispatch
137#endif // DOXYGEN_NO_DISPATCH
138
139
140namespace resolve_variant {
141
142template <typename Geometry>
143struct clear
144{
145 static inline void apply(Geometry& geometry)
146 {
147 dispatch::clear<Geometry>::apply(geometry);
148 }
149};
150
151template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
152struct clear<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
153{
154 struct visitor: static_visitor<void>
155 {
156 template <typename Geometry>
157 inline void operator()(Geometry& geometry) const
158 {
159 clear<Geometry>::apply(geometry);
160 }
161 };
162
163 static inline void apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry)
164 {
165 boost::apply_visitor(visitor(), geometry);
166 }
167};
168
169} // namespace resolve_variant
170
171
172/*!
173\brief Clears a linestring, ring or polygon (exterior+interiors) or multi*
174\details Generic function to clear a geometry. All points will be removed from the collection or collections
175 making up the geometry. In most cases this is equivalent to the .clear() method of a std::vector<...>. In
176 the case of a polygon, this clear functionality is automatically called for the exterior ring, and for the
177 interior ring collection. In the case of a point, boxes and segments, nothing will happen.
178\ingroup clear
179\tparam Geometry \tparam_geometry
180\param geometry \param_geometry which will be cleared
181\note points and boxes cannot be cleared, instead they can be set to zero by "assign_zero"
182
183\qbk{[include reference/algorithms/clear.qbk]}
184*/
185template <typename Geometry>
186inline void clear(Geometry& geometry)
187{
188 concept::check<Geometry>();
189
190 resolve_variant::clear<Geometry>::apply(geometry);
191}
192
193
194}} // namespace boost::geometry
195
196
197#endif // BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
198

source code of boost/boost/geometry/algorithms/clear.hpp