failure_type_policy.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2015, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_POLICIES_IS_VALID_FAILURE_TYPE_POLICY_HPP
  7. #define BOOST_GEOMETRY_POLICIES_IS_VALID_FAILURE_TYPE_POLICY_HPP
  8. #include <boost/geometry/algorithms/validity_failure_type.hpp>
  9. namespace boost { namespace geometry
  10. {
  11. // policy that simply keeps (and can return) the failure type
  12. template <bool AllowDuplicates = true, bool AllowSpikes = true>
  13. class failure_type_policy
  14. {
  15. private:
  16. static inline
  17. validity_failure_type transform_failure_type(validity_failure_type failure)
  18. {
  19. if (AllowDuplicates && failure == failure_duplicate_points)
  20. {
  21. return no_failure;
  22. }
  23. return failure;
  24. }
  25. static inline
  26. validity_failure_type transform_failure_type(validity_failure_type failure,
  27. bool is_linear)
  28. {
  29. if (is_linear && AllowSpikes && failure == failure_spikes)
  30. {
  31. return no_failure;
  32. }
  33. return transform_failure_type(failure);
  34. }
  35. public:
  36. failure_type_policy()
  37. : m_failure(no_failure)
  38. {}
  39. template <validity_failure_type Failure>
  40. inline bool apply()
  41. {
  42. m_failure = transform_failure_type(Failure);
  43. return m_failure == no_failure;
  44. }
  45. template <validity_failure_type Failure, typename Data>
  46. inline bool apply(Data const&)
  47. {
  48. return apply<Failure>();
  49. }
  50. template <validity_failure_type Failure, typename Data1, typename Data2>
  51. inline bool apply(Data1 const& data1, Data2 const&)
  52. {
  53. m_failure = transform_failure_type(Failure, data1);
  54. return m_failure == no_failure;
  55. }
  56. validity_failure_type failure() const
  57. {
  58. return m_failure;
  59. }
  60. private:
  61. validity_failure_type m_failure;
  62. };
  63. }} // namespace boost::geometry
  64. #endif // BOOST_GEOMETRY_POLICIES_IS_VALID_FAILURE_TYPE_POLICY_HPP