interface.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2020, 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/detail.hpp>
  17. #include <boost/geometry/strategies/relate/services.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. namespace resolve_strategy
  21. {
  22. template
  23. <
  24. typename Strategy,
  25. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  26. >
  27. struct is_simple
  28. {
  29. template <typename Geometry>
  30. static inline bool apply(Geometry const& geometry,
  31. Strategy const& strategy)
  32. {
  33. return dispatch::is_simple<Geometry>::apply(geometry, strategy);
  34. }
  35. };
  36. template <typename Strategy>
  37. struct is_simple<Strategy, false>
  38. {
  39. template <typename Geometry>
  40. static inline bool apply(Geometry const& geometry,
  41. Strategy const& strategy)
  42. {
  43. using strategies::relate::services::strategy_converter;
  44. return dispatch::is_simple
  45. <
  46. Geometry
  47. >::apply(geometry, strategy_converter<Strategy>::get(strategy));
  48. }
  49. };
  50. template <>
  51. struct is_simple<default_strategy, false>
  52. {
  53. template <typename Geometry>
  54. static inline bool apply(Geometry const& geometry,
  55. default_strategy)
  56. {
  57. // NOTE: Currently the strategy is only used for Linear geometries
  58. typedef typename strategies::relate::services::default_strategy
  59. <
  60. Geometry, Geometry
  61. >::type strategy_type;
  62. return dispatch::is_simple<Geometry>::apply(geometry, strategy_type());
  63. }
  64. };
  65. } // namespace resolve_strategy
  66. namespace resolve_variant
  67. {
  68. template <typename Geometry>
  69. struct is_simple
  70. {
  71. template <typename Strategy>
  72. static inline bool apply(Geometry const& geometry, Strategy const& strategy)
  73. {
  74. concepts::check<Geometry const>();
  75. return resolve_strategy::is_simple<Strategy>::apply(geometry, strategy);
  76. }
  77. };
  78. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  79. struct is_simple<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  80. {
  81. template <typename Strategy>
  82. struct visitor : boost::static_visitor<bool>
  83. {
  84. Strategy const& m_strategy;
  85. visitor(Strategy const& strategy)
  86. : m_strategy(strategy)
  87. {}
  88. template <typename Geometry>
  89. bool operator()(Geometry const& geometry) const
  90. {
  91. return is_simple<Geometry>::apply(geometry, m_strategy);
  92. }
  93. };
  94. template <typename Strategy>
  95. static inline bool
  96. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
  97. Strategy const& strategy)
  98. {
  99. return boost::apply_visitor(visitor<Strategy>(strategy), geometry);
  100. }
  101. };
  102. } // namespace resolve_variant
  103. /*!
  104. \brief \brief_check{is simple}
  105. \ingroup is_simple
  106. \tparam Geometry \tparam_geometry
  107. \tparam Strategy \tparam_strategy{Is_simple}
  108. \param geometry \param_geometry
  109. \param strategy \param_strategy{is_simple}
  110. \return \return_check{is simple}
  111. \qbk{distinguish,with strategy}
  112. \qbk{[include reference/algorithms/is_simple.qbk]}
  113. */
  114. template <typename Geometry, typename Strategy>
  115. inline bool is_simple(Geometry const& geometry, Strategy const& strategy)
  116. {
  117. return resolve_variant::is_simple<Geometry>::apply(geometry, strategy);
  118. }
  119. /*!
  120. \brief \brief_check{is simple}
  121. \ingroup is_simple
  122. \tparam Geometry \tparam_geometry
  123. \param geometry \param_geometry
  124. \return \return_check{is simple}
  125. \qbk{[include reference/algorithms/is_simple.qbk]}
  126. */
  127. template <typename Geometry>
  128. inline bool is_simple(Geometry const& geometry)
  129. {
  130. return resolve_variant::is_simple<Geometry>::apply(geometry, default_strategy());
  131. }
  132. }} // namespace boost::geometry
  133. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_INTERFACE_HPP