point_concept.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. //
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2008-2014 Barend Gehrels, Amsterdam, the Netherlands.
  5. // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2014-2021.
  7. // Modifications copyright (c) 2014-2021, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP
  16. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP
  17. #include <cstddef>
  18. #include <boost/concept_check.hpp>
  19. #include <boost/core/ignore_unused.hpp>
  20. #include <boost/geometry/core/access.hpp>
  21. #include <boost/geometry/core/coordinate_dimension.hpp>
  22. #include <boost/geometry/core/coordinate_system.hpp>
  23. #include <boost/geometry/geometries/concepts/concept_type.hpp>
  24. namespace boost { namespace geometry { namespace concepts
  25. {
  26. template <typename Geometry>
  27. class Point
  28. {
  29. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  30. typedef typename coordinate_type<Geometry>::type ctype;
  31. typedef typename coordinate_system<Geometry>::type csystem;
  32. // The following enum is used to fully instantiate the coordinate
  33. // system class; this is needed in order to check the units passed
  34. // to it for non-Cartesian coordinate systems.
  35. enum { cs_check = sizeof(csystem) };
  36. enum { ccount = dimension<Geometry>::value };
  37. template <typename P, std::size_t Dimension, std::size_t DimensionCount>
  38. struct dimension_checker
  39. {
  40. static void apply()
  41. {
  42. P* p = 0;
  43. geometry::set<Dimension>(*p, geometry::get<Dimension>(*p));
  44. dimension_checker<P, Dimension+1, DimensionCount>::apply();
  45. }
  46. };
  47. template <typename P, std::size_t DimensionCount>
  48. struct dimension_checker<P, DimensionCount, DimensionCount>
  49. {
  50. static void apply() {}
  51. };
  52. public:
  53. /// BCCL macro to apply the Point concept
  54. BOOST_CONCEPT_USAGE(Point)
  55. {
  56. dimension_checker<Geometry, 0, ccount>::apply();
  57. }
  58. #endif
  59. };
  60. /*!
  61. \brief point concept (const version).
  62. \ingroup const_concepts
  63. \details The ConstPoint concept apply the same as the Point concept,
  64. but does not apply write access.
  65. */
  66. template <typename Geometry>
  67. class ConstPoint
  68. {
  69. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  70. typedef typename coordinate_type<Geometry>::type ctype;
  71. typedef typename coordinate_system<Geometry>::type csystem;
  72. // The following enum is used to fully instantiate the coordinate
  73. // system class; this is needed in order to check the units passed
  74. // to it for non-Cartesian coordinate systems.
  75. enum { cs_check = sizeof(csystem) };
  76. enum { ccount = dimension<Geometry>::value };
  77. template <typename P, std::size_t Dimension, std::size_t DimensionCount>
  78. struct dimension_checker
  79. {
  80. static void apply()
  81. {
  82. const P* p = 0;
  83. ctype coord(geometry::get<Dimension>(*p));
  84. boost::ignore_unused(p, coord);
  85. dimension_checker<P, Dimension+1, DimensionCount>::apply();
  86. }
  87. };
  88. template <typename P, std::size_t DimensionCount>
  89. struct dimension_checker<P, DimensionCount, DimensionCount>
  90. {
  91. static void apply() {}
  92. };
  93. public:
  94. /// BCCL macro to apply the ConstPoint concept
  95. BOOST_CONCEPT_USAGE(ConstPoint)
  96. {
  97. dimension_checker<Geometry, 0, ccount>::apply();
  98. }
  99. #endif
  100. };
  101. template <typename Geometry>
  102. struct concept_type<Geometry, point_tag>
  103. {
  104. using type = Point<Geometry>;
  105. };
  106. template <typename Geometry>
  107. struct concept_type<Geometry const, point_tag>
  108. {
  109. using type = ConstPoint<Geometry>;
  110. };
  111. }}} // namespace boost::geometry::concepts
  112. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP