check.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  3. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_CHECK_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_CHECK_HPP
  12. #include <boost/concept_check.hpp>
  13. #include <boost/concept/requires.hpp>
  14. #include <boost/core/ignore_unused.hpp>
  15. #include <boost/type_traits/is_const.hpp>
  16. #include <boost/variant/variant_fwd.hpp>
  17. #include <boost/geometry/core/tag.hpp>
  18. #include <boost/geometry/core/tags.hpp>
  19. #include <boost/geometry/geometries/concepts/box_concept.hpp>
  20. #include <boost/geometry/geometries/concepts/linestring_concept.hpp>
  21. #include <boost/geometry/geometries/concepts/multi_point_concept.hpp>
  22. #include <boost/geometry/geometries/concepts/multi_linestring_concept.hpp>
  23. #include <boost/geometry/geometries/concepts/multi_polygon_concept.hpp>
  24. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  25. #include <boost/geometry/geometries/concepts/polygon_concept.hpp>
  26. #include <boost/geometry/geometries/concepts/ring_concept.hpp>
  27. #include <boost/geometry/geometries/concepts/segment_concept.hpp>
  28. #include <boost/geometry/algorithms/not_implemented.hpp>
  29. namespace boost { namespace geometry
  30. {
  31. #ifndef DOXYGEN_NO_DETAIL
  32. namespace detail { namespace concept_check
  33. {
  34. template <typename Concept>
  35. class check
  36. {
  37. BOOST_CONCEPT_ASSERT((Concept ));
  38. };
  39. }} // namespace detail::concept_check
  40. #endif // DOXYGEN_NO_DETAIL
  41. #ifndef DOXYGEN_NO_DISPATCH
  42. namespace dispatch
  43. {
  44. template
  45. <
  46. typename Geometry,
  47. typename GeometryTag = typename geometry::tag<Geometry>::type,
  48. bool IsConst = boost::is_const<Geometry>::type::value
  49. >
  50. struct check : not_implemented<GeometryTag>
  51. {};
  52. template <typename Geometry>
  53. struct check<Geometry, point_tag, true>
  54. : detail::concept_check::check<concepts::ConstPoint<Geometry> >
  55. {};
  56. template <typename Geometry>
  57. struct check<Geometry, point_tag, false>
  58. : detail::concept_check::check<concepts::Point<Geometry> >
  59. {};
  60. template <typename Geometry>
  61. struct check<Geometry, linestring_tag, true>
  62. : detail::concept_check::check<concepts::ConstLinestring<Geometry> >
  63. {};
  64. template <typename Geometry>
  65. struct check<Geometry, linestring_tag, false>
  66. : detail::concept_check::check<concepts::Linestring<Geometry> >
  67. {};
  68. template <typename Geometry>
  69. struct check<Geometry, ring_tag, true>
  70. : detail::concept_check::check<concepts::ConstRing<Geometry> >
  71. {};
  72. template <typename Geometry>
  73. struct check<Geometry, ring_tag, false>
  74. : detail::concept_check::check<concepts::Ring<Geometry> >
  75. {};
  76. template <typename Geometry>
  77. struct check<Geometry, polygon_tag, true>
  78. : detail::concept_check::check<concepts::ConstPolygon<Geometry> >
  79. {};
  80. template <typename Geometry>
  81. struct check<Geometry, polygon_tag, false>
  82. : detail::concept_check::check<concepts::Polygon<Geometry> >
  83. {};
  84. template <typename Geometry>
  85. struct check<Geometry, box_tag, true>
  86. : detail::concept_check::check<concepts::ConstBox<Geometry> >
  87. {};
  88. template <typename Geometry>
  89. struct check<Geometry, box_tag, false>
  90. : detail::concept_check::check<concepts::Box<Geometry> >
  91. {};
  92. template <typename Geometry>
  93. struct check<Geometry, segment_tag, true>
  94. : detail::concept_check::check<concepts::ConstSegment<Geometry> >
  95. {};
  96. template <typename Geometry>
  97. struct check<Geometry, segment_tag, false>
  98. : detail::concept_check::check<concepts::Segment<Geometry> >
  99. {};
  100. template <typename Geometry>
  101. struct check<Geometry, multi_point_tag, true>
  102. : detail::concept_check::check<concepts::ConstMultiPoint<Geometry> >
  103. {};
  104. template <typename Geometry>
  105. struct check<Geometry, multi_point_tag, false>
  106. : detail::concept_check::check<concepts::MultiPoint<Geometry> >
  107. {};
  108. template <typename Geometry>
  109. struct check<Geometry, multi_linestring_tag, true>
  110. : detail::concept_check::check<concepts::ConstMultiLinestring<Geometry> >
  111. {};
  112. template <typename Geometry>
  113. struct check<Geometry, multi_linestring_tag, false>
  114. : detail::concept_check::check<concepts::MultiLinestring<Geometry> >
  115. {};
  116. template <typename Geometry>
  117. struct check<Geometry, multi_polygon_tag, true>
  118. : detail::concept_check::check<concepts::ConstMultiPolygon<Geometry> >
  119. {};
  120. template <typename Geometry>
  121. struct check<Geometry, multi_polygon_tag, false>
  122. : detail::concept_check::check<concepts::MultiPolygon<Geometry> >
  123. {};
  124. } // namespace dispatch
  125. #endif
  126. namespace concepts
  127. {
  128. #ifndef DOXYGEN_NO_DETAIL
  129. namespace detail
  130. {
  131. template <typename Geometry>
  132. struct checker : dispatch::check<Geometry>
  133. {};
  134. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  135. struct checker<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  136. {};
  137. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  138. struct checker<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const>
  139. {};
  140. }
  141. #endif // DOXYGEN_NO_DETAIL
  142. /*!
  143. \brief Checks, in compile-time, the concept of any geometry
  144. \ingroup concepts
  145. */
  146. template <typename Geometry>
  147. inline void check()
  148. {
  149. detail::checker<Geometry> c;
  150. boost::ignore_unused(c);
  151. }
  152. /*!
  153. \brief Checks, in compile-time, the concept of two geometries, and if they
  154. have equal dimensions
  155. \ingroup concepts
  156. */
  157. template <typename Geometry1, typename Geometry2>
  158. inline void check_concepts_and_equal_dimensions()
  159. {
  160. check<Geometry1>();
  161. check<Geometry2>();
  162. assert_dimension_equal<Geometry1, Geometry2>();
  163. }
  164. } // namespace concepts
  165. }} // namespace boost::geometry
  166. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_CHECK_HPP