box_concept.hpp 3.8 KB

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