coordinate_dimension.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. // This file was modified by Oracle on 2020.
  6. // Modifications copyright (c) 2020, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP
  14. #define BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP
  15. #include <cstddef>
  16. #include <boost/geometry/core/point_type.hpp>
  17. #include <boost/geometry/core/static_assert.hpp>
  18. #include <boost/geometry/util/type_traits_std.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. namespace traits
  22. {
  23. /*!
  24. \brief Traits class indicating the number of dimensions of a point
  25. \par Geometries:
  26. - point
  27. \par Specializations should provide:
  28. - value (e.g. derived from std::integral_constant<std::size_t, D>)
  29. \ingroup traits
  30. */
  31. template <typename Point, typename Enable = void>
  32. struct dimension
  33. {
  34. BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
  35. "Not implemented for this Point type.",
  36. Point);
  37. };
  38. } // namespace traits
  39. #ifndef DOXYGEN_NO_DISPATCH
  40. namespace core_dispatch
  41. {
  42. // Base class derive from its own specialization of point-tag
  43. template <typename T, typename G>
  44. struct dimension
  45. : dimension<point_tag, typename point_type<T, G>::type>::type
  46. {};
  47. template <typename P>
  48. struct dimension<point_tag, P>
  49. : std::integral_constant
  50. <
  51. std::size_t,
  52. traits::dimension<util::remove_cptrref_t<P>>::value
  53. >
  54. {
  55. BOOST_GEOMETRY_STATIC_ASSERT(
  56. (traits::dimension<util::remove_cptrref_t<P>>::value > 0),
  57. "Dimension has to be greater than 0.",
  58. traits::dimension<util::remove_cptrref_t<P>>
  59. );
  60. };
  61. } // namespace core_dispatch
  62. #endif
  63. /*!
  64. \brief \brief_meta{value, number of coordinates (the number of axes of any geometry), \meta_point_type}
  65. \tparam Geometry \tparam_geometry
  66. \ingroup core
  67. \qbk{[include reference/core/coordinate_dimension.qbk]}
  68. */
  69. template <typename Geometry>
  70. struct dimension
  71. : core_dispatch::dimension
  72. <
  73. typename tag<Geometry>::type,
  74. typename util::remove_cptrref<Geometry>::type
  75. >
  76. {};
  77. /*!
  78. \brief assert_dimension, enables compile-time checking if coordinate dimensions are as expected
  79. \ingroup utility
  80. */
  81. template <typename Geometry, std::size_t Dimensions>
  82. constexpr inline void assert_dimension()
  83. {
  84. BOOST_STATIC_ASSERT(( dimension<Geometry>::value == Dimensions ));
  85. }
  86. /*!
  87. \brief assert_dimension, enables compile-time checking if coordinate dimensions are as expected
  88. \ingroup utility
  89. */
  90. template <typename Geometry, std::size_t Dimensions>
  91. constexpr inline void assert_dimension_less_equal()
  92. {
  93. BOOST_STATIC_ASSERT(( dimension<Geometry>::value <= Dimensions ));
  94. }
  95. template <typename Geometry, std::size_t Dimensions>
  96. constexpr inline void assert_dimension_greater_equal()
  97. {
  98. BOOST_STATIC_ASSERT(( dimension<Geometry>::value >= Dimensions ));
  99. }
  100. /*!
  101. \brief assert_dimension_equal, enables compile-time checking if coordinate dimensions of two geometries are equal
  102. \ingroup utility
  103. */
  104. template <typename G1, typename G2>
  105. constexpr inline void assert_dimension_equal()
  106. {
  107. BOOST_STATIC_ASSERT(( dimension<G1>::value == dimension<G2>::value ));
  108. }
  109. }} // namespace boost::geometry
  110. #endif // BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP