check.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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/type_traits/is_const.hpp>
  15. #include <boost/variant/variant_fwd.hpp>
  16. #include <boost/geometry/core/tag.hpp>
  17. #include <boost/geometry/core/tags.hpp>
  18. #include <boost/geometry/geometries/concepts/box_concept.hpp>
  19. #include <boost/geometry/geometries/concepts/linestring_concept.hpp>
  20. #include <boost/geometry/geometries/concepts/multi_point_concept.hpp>
  21. #include <boost/geometry/geometries/concepts/multi_linestring_concept.hpp>
  22. #include <boost/geometry/geometries/concepts/multi_polygon_concept.hpp>
  23. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  24. #include <boost/geometry/geometries/concepts/polygon_concept.hpp>
  25. #include <boost/geometry/geometries/concepts/ring_concept.hpp>
  26. #include <boost/geometry/geometries/concepts/segment_concept.hpp>
  27. #include <boost/geometry/algorithms/not_implemented.hpp>
  28. namespace boost { namespace geometry
  29. {
  30. #ifndef DOXYGEN_NO_DETAIL
  31. namespace detail { namespace concept_check
  32. {
  33. template <typename Concept>
  34. class check
  35. {
  36. BOOST_CONCEPT_ASSERT((Concept ));
  37. };
  38. }} // namespace detail::concept_check
  39. #endif // DOXYGEN_NO_DETAIL
  40. #ifndef DOXYGEN_NO_DISPATCH
  41. namespace dispatch
  42. {
  43. template
  44. <
  45. typename Geometry,
  46. typename GeometryTag = typename geometry::tag<Geometry>::type,
  47. bool IsConst = boost::is_const<Geometry>::type::value
  48. >
  49. struct check : not_implemented<GeometryTag>
  50. {};
  51. template <typename Geometry>
  52. struct check<Geometry, point_tag, true>
  53. : detail::concept_check::check<concept::ConstPoint<Geometry> >
  54. {};
  55. template <typename Geometry>
  56. struct check<Geometry, point_tag, false>
  57. : detail::concept_check::check<concept::Point<Geometry> >
  58. {};
  59. template <typename Geometry>
  60. struct check<Geometry, linestring_tag, true>
  61. : detail::concept_check::check<concept::ConstLinestring<Geometry> >
  62. {};
  63. template <typename Geometry>
  64. struct check<Geometry, linestring_tag, false>
  65. : detail::concept_check::check<concept::Linestring<Geometry> >
  66. {};
  67. template <typename Geometry>
  68. struct check<Geometry, ring_tag, true>
  69. : detail::concept_check::check<concept::ConstRing<Geometry> >
  70. {};
  71. template <typename Geometry>
  72. struct check<Geometry, ring_tag, false>
  73. : detail::concept_check::check<concept::Ring<Geometry> >
  74. {};
  75. template <typename Geometry>
  76. struct check<Geometry, polygon_tag, true>
  77. : detail::concept_check::check<concept::ConstPolygon<Geometry> >
  78. {};
  79. template <typename Geometry>
  80. struct check<Geometry, polygon_tag, false>
  81. : detail::concept_check::check<concept::Polygon<Geometry> >
  82. {};
  83. template <typename Geometry>
  84. struct check<Geometry, box_tag, true>
  85. : detail::concept_check::check<concept::ConstBox<Geometry> >
  86. {};
  87. template <typename Geometry>
  88. struct check<Geometry, box_tag, false>
  89. : detail::concept_check::check<concept::Box<Geometry> >
  90. {};
  91. template <typename Geometry>
  92. struct check<Geometry, segment_tag, true>
  93. : detail::concept_check::check<concept::ConstSegment<Geometry> >
  94. {};
  95. template <typename Geometry>
  96. struct check<Geometry, segment_tag, false>
  97. : detail::concept_check::check<concept::Segment<Geometry> >
  98. {};
  99. template <typename Geometry>
  100. struct check<Geometry, multi_point_tag, true>
  101. : detail::concept_check::check<concept::ConstMultiPoint<Geometry> >
  102. {};
  103. template <typename Geometry>
  104. struct check<Geometry, multi_point_tag, false>
  105. : detail::concept_check::check<concept::MultiPoint<Geometry> >
  106. {};
  107. template <typename Geometry>
  108. struct check<Geometry, multi_linestring_tag, true>
  109. : detail::concept_check::check<concept::ConstMultiLinestring<Geometry> >
  110. {};
  111. template <typename Geometry>
  112. struct check<Geometry, multi_linestring_tag, false>
  113. : detail::concept_check::check<concept::MultiLinestring<Geometry> >
  114. {};
  115. template <typename Geometry>
  116. struct check<Geometry, multi_polygon_tag, true>
  117. : detail::concept_check::check<concept::ConstMultiPolygon<Geometry> >
  118. {};
  119. template <typename Geometry>
  120. struct check<Geometry, multi_polygon_tag, false>
  121. : detail::concept_check::check<concept::MultiPolygon<Geometry> >
  122. {};
  123. } // namespace dispatch
  124. #endif
  125. namespace concept
  126. {
  127. #ifndef DOXYGEN_NO_DETAIL
  128. namespace detail
  129. {
  130. template <typename Geometry>
  131. struct checker : dispatch::check<Geometry>
  132. {};
  133. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  134. struct checker<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  135. {};
  136. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  137. struct checker<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const>
  138. {};
  139. }
  140. #endif // DOXYGEN_NO_DETAIL
  141. /*!
  142. \brief Checks, in compile-time, the concept of any geometry
  143. \ingroup concepts
  144. */
  145. template <typename Geometry>
  146. inline void check()
  147. {
  148. detail::checker<Geometry> c;
  149. boost::ignore_unused_variable_warning(c);
  150. }
  151. /*!
  152. \brief Checks, in compile-time, the concept of two geometries, and if they
  153. have equal dimensions
  154. \ingroup concepts
  155. */
  156. template <typename Geometry1, typename Geometry2>
  157. inline void check_concepts_and_equal_dimensions()
  158. {
  159. check<Geometry1>();
  160. check<Geometry2>();
  161. assert_dimension_equal<Geometry1, Geometry2>();
  162. }
  163. } // namespace concept
  164. }} // namespace boost::geometry
  165. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_CHECK_HPP