box_concept.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_BOX_CONCEPT_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_BOX_CONCEPT_HPP
  12. #include <cstddef>
  13. #include <boost/concept_check.hpp>
  14. #include <boost/core/ignore_unused.hpp>
  15. #include <boost/geometry/core/access.hpp>
  16. #include <boost/geometry/core/coordinate_dimension.hpp>
  17. #include <boost/geometry/core/point_type.hpp>
  18. namespace boost { namespace geometry { namespace concepts
  19. {
  20. /*!
  21. \brief Box concept
  22. \ingroup concepts
  23. \par Formal definition:
  24. The box concept is defined as following:
  25. - there must be a specialization of traits::tag defining box_tag as type
  26. - there must be a specialization of traits::point_type to define the
  27. underlying point type (even if it does not consist of points, it should define
  28. this type, to indicate the points it can work with)
  29. - there must be a specialization of traits::indexed_access, per index
  30. (min_corner, max_corner) and per dimension, with two functions:
  31. - get to get a coordinate value
  32. - set to set a coordinate value (this one is not checked for ConstBox)
  33. */
  34. template <typename Geometry>
  35. class Box
  36. {
  37. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  38. typedef typename point_type<Geometry>::type point_type;
  39. template
  40. <
  41. std::size_t Index,
  42. std::size_t Dimension,
  43. std::size_t DimensionCount
  44. >
  45. struct dimension_checker
  46. {
  47. static void apply()
  48. {
  49. Geometry* b = 0;
  50. geometry::set<Index, Dimension>(*b, geometry::get<Index, Dimension>(*b));
  51. dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
  52. }
  53. };
  54. template <std::size_t Index, std::size_t DimensionCount>
  55. struct dimension_checker<Index, DimensionCount, DimensionCount>
  56. {
  57. static void apply() {}
  58. };
  59. public :
  60. BOOST_CONCEPT_USAGE(Box)
  61. {
  62. static const std::size_t n = dimension<Geometry>::type::value;
  63. dimension_checker<min_corner, 0, n>::apply();
  64. dimension_checker<max_corner, 0, n>::apply();
  65. }
  66. #endif
  67. };
  68. /*!
  69. \brief Box concept (const version)
  70. \ingroup const_concepts
  71. \details The ConstBox concept apply the same as the Box concept,
  72. but does not apply write access.
  73. */
  74. template <typename Geometry>
  75. class ConstBox
  76. {
  77. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  78. typedef typename point_type<Geometry>::type point_type;
  79. typedef typename coordinate_type<Geometry>::type coordinate_type;
  80. template
  81. <
  82. std::size_t Index,
  83. std::size_t Dimension,
  84. std::size_t DimensionCount
  85. >
  86. struct dimension_checker
  87. {
  88. static void apply()
  89. {
  90. const Geometry* b = 0;
  91. coordinate_type coord(geometry::get<Index, Dimension>(*b));
  92. boost::ignore_unused(coord);
  93. dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
  94. }
  95. };
  96. template <std::size_t Index, std::size_t DimensionCount>
  97. struct dimension_checker<Index, DimensionCount, DimensionCount>
  98. {
  99. static void apply() {}
  100. };
  101. public :
  102. BOOST_CONCEPT_USAGE(ConstBox)
  103. {
  104. static const std::size_t n = dimension<Geometry>::type::value;
  105. dimension_checker<min_corner, 0, n>::apply();
  106. dimension_checker<max_corner, 0, n>::apply();
  107. }
  108. #endif
  109. };
  110. }}} // namespace boost::geometry::concepts
  111. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_BOX_CONCEPT_HPP