interface.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2017, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_INTERFACE_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_INTERFACE_HPP
  9. #include <boost/variant/apply_visitor.hpp>
  10. #include <boost/variant/static_visitor.hpp>
  11. #include <boost/variant/variant_fwd.hpp>
  12. #include <boost/geometry/geometries/concepts/check.hpp>
  13. #include <boost/geometry/algorithms/dispatch/is_simple.hpp>
  14. #include <boost/geometry/core/cs.hpp>
  15. #include <boost/geometry/strategies/default_strategy.hpp>
  16. #include <boost/geometry/strategies/intersection.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace resolve_strategy
  20. {
  21. struct is_simple
  22. {
  23. template <typename Geometry, typename Strategy>
  24. static inline bool apply(Geometry const& geometry,
  25. Strategy const& strategy)
  26. {
  27. return dispatch::is_simple<Geometry>::apply(geometry, strategy);
  28. }
  29. template <typename Geometry>
  30. static inline bool apply(Geometry const& geometry,
  31. default_strategy)
  32. {
  33. // NOTE: Currently the strategy is only used for Linear geometries
  34. typedef typename strategy::intersection::services::default_strategy
  35. <
  36. typename cs_tag<Geometry>::type
  37. >::type strategy_type;
  38. return dispatch::is_simple<Geometry>::apply(geometry, strategy_type());
  39. }
  40. };
  41. } // namespace resolve_strategy
  42. namespace resolve_variant
  43. {
  44. template <typename Geometry>
  45. struct is_simple
  46. {
  47. template <typename Strategy>
  48. static inline bool apply(Geometry const& geometry, Strategy const& strategy)
  49. {
  50. concepts::check<Geometry const>();
  51. return resolve_strategy::is_simple::apply(geometry, strategy);
  52. }
  53. };
  54. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  55. struct is_simple<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  56. {
  57. template <typename Strategy>
  58. struct visitor : boost::static_visitor<bool>
  59. {
  60. Strategy const& m_strategy;
  61. visitor(Strategy const& strategy)
  62. : m_strategy(strategy)
  63. {}
  64. template <typename Geometry>
  65. bool operator()(Geometry const& geometry) const
  66. {
  67. return is_simple<Geometry>::apply(geometry, m_strategy);
  68. }
  69. };
  70. template <typename Strategy>
  71. static inline bool
  72. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
  73. Strategy const& strategy)
  74. {
  75. return boost::apply_visitor(visitor<Strategy>(strategy), geometry);
  76. }
  77. };
  78. } // namespace resolve_variant
  79. /*!
  80. \brief \brief_check{is simple}
  81. \ingroup is_simple
  82. \tparam Geometry \tparam_geometry
  83. \tparam Strategy \tparam_strategy{Is_simple}
  84. \param geometry \param_geometry
  85. \param strategy \param_strategy{is_simple}
  86. \return \return_check{is simple}
  87. \qbk{distinguish,with strategy}
  88. \qbk{[include reference/algorithms/is_simple.qbk]}
  89. */
  90. template <typename Geometry, typename Strategy>
  91. inline bool is_simple(Geometry const& geometry, Strategy const& strategy)
  92. {
  93. return resolve_variant::is_simple<Geometry>::apply(geometry, strategy);
  94. }
  95. /*!
  96. \brief \brief_check{is simple}
  97. \ingroup is_simple
  98. \tparam Geometry \tparam_geometry
  99. \param geometry \param_geometry
  100. \return \return_check{is simple}
  101. \qbk{[include reference/algorithms/is_simple.qbk]}
  102. */
  103. template <typename Geometry>
  104. inline bool is_simple(Geometry const& geometry)
  105. {
  106. return resolve_variant::is_simple<Geometry>::apply(geometry, default_strategy());
  107. }
  108. }} // namespace boost::geometry
  109. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_INTERFACE_HPP