box_concept.hpp 3.5 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/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. #include <boost/geometry/geometries/concepts/concept_type.hpp>
  19. namespace boost { namespace geometry { namespace concepts
  20. {
  21. template <typename Geometry>
  22. class Box
  23. {
  24. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  25. typedef typename point_type<Geometry>::type point_type;
  26. template
  27. <
  28. std::size_t Index,
  29. std::size_t Dimension,
  30. std::size_t DimensionCount
  31. >
  32. struct dimension_checker
  33. {
  34. static void apply()
  35. {
  36. Geometry* b = 0;
  37. geometry::set<Index, Dimension>(*b, geometry::get<Index, Dimension>(*b));
  38. dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
  39. }
  40. };
  41. template <std::size_t Index, std::size_t DimensionCount>
  42. struct dimension_checker<Index, DimensionCount, DimensionCount>
  43. {
  44. static void apply() {}
  45. };
  46. public :
  47. BOOST_CONCEPT_USAGE(Box)
  48. {
  49. static const std::size_t n = dimension<Geometry>::type::value;
  50. dimension_checker<min_corner, 0, n>::apply();
  51. dimension_checker<max_corner, 0, n>::apply();
  52. }
  53. #endif
  54. };
  55. /*!
  56. \brief Box concept (const version)
  57. \ingroup const_concepts
  58. \details The ConstBox concept apply the same as the Box concept,
  59. but does not apply write access.
  60. */
  61. template <typename Geometry>
  62. class ConstBox
  63. {
  64. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  65. typedef typename point_type<Geometry>::type point_type;
  66. typedef typename coordinate_type<Geometry>::type coordinate_type;
  67. template
  68. <
  69. std::size_t Index,
  70. std::size_t Dimension,
  71. std::size_t DimensionCount
  72. >
  73. struct dimension_checker
  74. {
  75. static void apply()
  76. {
  77. const Geometry* b = 0;
  78. coordinate_type coord(geometry::get<Index, Dimension>(*b));
  79. boost::ignore_unused(coord);
  80. dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
  81. }
  82. };
  83. template <std::size_t Index, std::size_t DimensionCount>
  84. struct dimension_checker<Index, DimensionCount, DimensionCount>
  85. {
  86. static void apply() {}
  87. };
  88. public :
  89. BOOST_CONCEPT_USAGE(ConstBox)
  90. {
  91. static const std::size_t n = dimension<Geometry>::type::value;
  92. dimension_checker<min_corner, 0, n>::apply();
  93. dimension_checker<max_corner, 0, n>::apply();
  94. }
  95. #endif
  96. };
  97. template <typename Geometry>
  98. struct concept_type<Geometry, box_tag>
  99. {
  100. using type = Box<Geometry>;
  101. };
  102. template <typename Geometry>
  103. struct concept_type<Geometry const, box_tag>
  104. {
  105. using type = ConstBox<Geometry>;
  106. };
  107. }}} // namespace boost::geometry::concepts
  108. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_BOX_CONCEPT_HPP