coordinate_dimension.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_CORE_COORDINATE_DIMENSION_HPP
  11. #define BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP
  12. #include <cstddef>
  13. #include <boost/mpl/assert.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include <boost/geometry/core/point_type.hpp>
  16. #include <boost/geometry/util/bare_type.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace traits
  20. {
  21. /*!
  22. \brief Traits class indicating the number of dimensions of a point
  23. \par Geometries:
  24. - point
  25. \par Specializations should provide:
  26. - value (should be derived from boost::mpl::int_<D>
  27. \ingroup traits
  28. */
  29. template <typename Point, typename Enable = void>
  30. struct dimension
  31. {
  32. BOOST_MPL_ASSERT_MSG
  33. (
  34. false, NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE, (types<Point>)
  35. );
  36. };
  37. } // namespace traits
  38. #ifndef DOXYGEN_NO_DISPATCH
  39. namespace core_dispatch
  40. {
  41. // Base class derive from its own specialization of point-tag
  42. template <typename T, typename G>
  43. struct dimension : dimension<point_tag, typename point_type<T, G>::type> {};
  44. template <typename P>
  45. struct dimension<point_tag, P>
  46. : traits::dimension<typename geometry::util::bare_type<P>::type>
  47. {
  48. BOOST_MPL_ASSERT_MSG(
  49. (traits::dimension<typename geometry::util::bare_type<P>::type>::value > 0),
  50. INVALID_DIMENSION_VALUE,
  51. (traits::dimension<typename geometry::util::bare_type<P>::type>)
  52. );
  53. };
  54. } // namespace core_dispatch
  55. #endif
  56. /*!
  57. \brief \brief_meta{value, number of coordinates (the number of axes of any geometry), \meta_point_type}
  58. \tparam Geometry \tparam_geometry
  59. \ingroup core
  60. \qbk{[include reference/core/coordinate_dimension.qbk]}
  61. */
  62. template <typename Geometry>
  63. struct dimension
  64. : core_dispatch::dimension
  65. <
  66. typename tag<Geometry>::type,
  67. typename geometry::util::bare_type<Geometry>::type
  68. >
  69. {};
  70. /*!
  71. \brief assert_dimension, enables compile-time checking if coordinate dimensions are as expected
  72. \ingroup utility
  73. */
  74. template <typename Geometry, int Dimensions>
  75. inline void assert_dimension()
  76. {
  77. BOOST_STATIC_ASSERT(( static_cast<int>(dimension<Geometry>::value) == Dimensions ));
  78. }
  79. /*!
  80. \brief assert_dimension, enables compile-time checking if coordinate dimensions are as expected
  81. \ingroup utility
  82. */
  83. template <typename Geometry, int Dimensions>
  84. inline void assert_dimension_less_equal()
  85. {
  86. BOOST_STATIC_ASSERT(( static_cast<int>(dimension<Geometry>::type::value) <= Dimensions ));
  87. }
  88. template <typename Geometry, int Dimensions>
  89. inline void assert_dimension_greater_equal()
  90. {
  91. BOOST_STATIC_ASSERT(( static_cast<int>(dimension<Geometry>::type::value) >= Dimensions ));
  92. }
  93. /*!
  94. \brief assert_dimension_equal, enables compile-time checking if coordinate dimensions of two geometries are equal
  95. \ingroup utility
  96. */
  97. template <typename G1, typename G2>
  98. inline void assert_dimension_equal()
  99. {
  100. BOOST_STATIC_ASSERT(( static_cast<size_t>(dimension<G1>::type::value) == static_cast<size_t>(dimension<G2>::type::value) ));
  101. }
  102. }} // namespace boost::geometry
  103. #endif // BOOST_GEOMETRY_CORE_COORDINATE_DIMENSION_HPP