]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 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_POLICIES_IS_VALID_FAILURE_TYPE_POLICY_HPP | |
11 | #define BOOST_GEOMETRY_POLICIES_IS_VALID_FAILURE_TYPE_POLICY_HPP | |
12 | ||
13 | #include <boost/geometry/algorithms/validity_failure_type.hpp> | |
14 | ||
15 | ||
16 | namespace boost { namespace geometry | |
17 | { | |
18 | ||
19 | ||
20 | // policy that simply keeps (and can return) the failure type | |
21 | template <bool AllowDuplicates = true, bool AllowSpikes = true> | |
22 | class failure_type_policy | |
23 | { | |
24 | private: | |
25 | static inline | |
26 | validity_failure_type transform_failure_type(validity_failure_type failure) | |
27 | { | |
28 | if (AllowDuplicates && failure == failure_duplicate_points) | |
29 | { | |
30 | return no_failure; | |
31 | } | |
32 | return failure; | |
33 | } | |
34 | ||
35 | static inline | |
36 | validity_failure_type transform_failure_type(validity_failure_type failure, | |
37 | bool is_linear) | |
38 | { | |
39 | if (is_linear && AllowSpikes && failure == failure_spikes) | |
40 | { | |
41 | return no_failure; | |
42 | } | |
43 | return transform_failure_type(failure); | |
44 | } | |
45 | ||
46 | public: | |
47 | failure_type_policy() | |
48 | : m_failure(no_failure) | |
49 | {} | |
50 | ||
51 | template <validity_failure_type Failure> | |
52 | inline bool apply() | |
53 | { | |
54 | m_failure = transform_failure_type(Failure); | |
55 | return m_failure == no_failure; | |
56 | } | |
57 | ||
58 | template <validity_failure_type Failure, typename Data> | |
59 | inline bool apply(Data const&) | |
60 | { | |
61 | return apply<Failure>(); | |
62 | } | |
63 | ||
64 | template <validity_failure_type Failure, typename Data1, typename Data2> | |
65 | inline bool apply(Data1 const& data1, Data2 const&) | |
66 | { | |
67 | m_failure = transform_failure_type(Failure, data1); | |
68 | return m_failure == no_failure; | |
69 | } | |
70 | ||
71 | validity_failure_type failure() const | |
72 | { | |
73 | return m_failure; | |
74 | } | |
75 | ||
76 | private: | |
77 | validity_failure_type m_failure; | |
78 | }; | |
79 | ||
80 | ||
81 | }} // namespace boost::geometry | |
82 | ||
83 | #endif // BOOST_GEOMETRY_POLICIES_IS_VALID_FAILURE_TYPE_POLICY_HPP |