]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/algorithms/detail/is_valid/interface.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / algorithms / detail / is_valid / interface.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
9
10 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_INTERFACE_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_INTERFACE_HPP
12
13 #include <sstream>
14 #include <string>
15
16 #include <boost/variant/apply_visitor.hpp>
17 #include <boost/variant/static_visitor.hpp>
18 #include <boost/variant/variant_fwd.hpp>
19
20 #include <boost/geometry/geometries/concepts/check.hpp>
21
22 #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
23 #include <boost/geometry/policies/is_valid/default_policy.hpp>
24 #include <boost/geometry/policies/is_valid/failing_reason_policy.hpp>
25 #include <boost/geometry/policies/is_valid/failure_type_policy.hpp>
26
27
28 namespace boost { namespace geometry
29 {
30
31
32 namespace resolve_variant {
33
34 template <typename Geometry>
35 struct is_valid
36 {
37 template <typename VisitPolicy>
38 static inline bool apply(Geometry const& geometry, VisitPolicy& visitor)
39 {
40 concepts::check<Geometry const>();
41 return dispatch::is_valid<Geometry>::apply(geometry, visitor);
42 }
43 };
44
45 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
46 struct is_valid<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
47 {
48 template <typename VisitPolicy>
49 struct visitor : boost::static_visitor<bool>
50 {
51 visitor(VisitPolicy& policy) : m_policy(policy) {}
52
53 template <typename Geometry>
54 bool operator()(Geometry const& geometry) const
55 {
56 return is_valid<Geometry>::apply(geometry, m_policy);
57 }
58
59 VisitPolicy& m_policy;
60 };
61
62 template <typename VisitPolicy>
63 static inline bool
64 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
65 VisitPolicy& policy_visitor)
66 {
67 return boost::apply_visitor(visitor<VisitPolicy>(policy_visitor),
68 geometry);
69 }
70 };
71
72 } // namespace resolve_variant
73
74
75 // Undocumented for now
76 template <typename Geometry, typename VisitPolicy>
77 inline bool is_valid(Geometry const& geometry, VisitPolicy& visitor)
78 {
79 return resolve_variant::is_valid<Geometry>::apply(geometry, visitor);
80 }
81
82
83 /*!
84 \brief \brief_check{is valid (in the OGC sense)}
85 \ingroup is_valid
86 \tparam Geometry \tparam_geometry
87 \param geometry \param_geometry
88 \return \return_check{is valid (in the OGC sense);
89 furthermore, the following geometries are considered valid:
90 multi-geometries with no elements,
91 linear geometries containing spikes,
92 areal geometries with duplicate (consecutive) points}
93
94 \qbk{[include reference/algorithms/is_valid.qbk]}
95 */
96 template <typename Geometry>
97 inline bool is_valid(Geometry const& geometry)
98 {
99 is_valid_default_policy<> policy_visitor;
100 return geometry::is_valid(geometry, policy_visitor);
101 }
102
103
104 /*!
105 \brief \brief_check{is valid (in the OGC sense)}
106 \ingroup is_valid
107 \tparam Geometry \tparam_geometry
108 \param geometry \param_geometry
109 \param failure An enumeration value indicating that the geometry is
110 valid or not, and if not valid indicating the reason why
111 \return \return_check{is valid (in the OGC sense);
112 furthermore, the following geometries are considered valid:
113 multi-geometries with no elements,
114 linear geometries containing spikes,
115 areal geometries with duplicate (consecutive) points}
116
117 \qbk{distinguish,with failure value}
118 \qbk{[include reference/algorithms/is_valid_with_failure.qbk]}
119 */
120 template <typename Geometry>
121 inline bool is_valid(Geometry const& geometry, validity_failure_type& failure)
122 {
123 failure_type_policy<> policy_visitor;
124 bool result = geometry::is_valid(geometry, policy_visitor);
125 failure = policy_visitor.failure();
126 return result;
127 }
128
129
130 /*!
131 \brief \brief_check{is valid (in the OGC sense)}
132 \ingroup is_valid
133 \tparam Geometry \tparam_geometry
134 \param geometry \param_geometry
135 \param message A string containing a message stating if the geometry
136 is valid or not, and if not valid a reason why
137 \return \return_check{is valid (in the OGC sense);
138 furthermore, the following geometries are considered valid:
139 multi-geometries with no elements,
140 linear geometries containing spikes,
141 areal geometries with duplicate (consecutive) points}
142
143 \qbk{distinguish,with message}
144 \qbk{[include reference/algorithms/is_valid_with_message.qbk]}
145 */
146 template <typename Geometry>
147 inline bool is_valid(Geometry const& geometry, std::string& message)
148 {
149 std::ostringstream stream;
150 failing_reason_policy<> policy_visitor(stream);
151 bool result = geometry::is_valid(geometry, policy_visitor);
152 message = stream.str();
153 return result;
154 }
155
156
157 }} // namespace boost::geometry
158
159 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_INTERFACE_HPP