check.hpp 4.6 KB

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