point_concept.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. //
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP
  12. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP
  13. #include <cstddef>
  14. #include <boost/concept_check.hpp>
  15. #include <boost/geometry/core/access.hpp>
  16. #include <boost/geometry/core/coordinate_dimension.hpp>
  17. #include <boost/geometry/core/coordinate_system.hpp>
  18. namespace boost { namespace geometry { namespace concept
  19. {
  20. /*!
  21. \brief Point concept.
  22. \ingroup concepts
  23. \par Formal definition:
  24. The point concept is defined as following:
  25. - there must be a specialization of traits::tag defining point_tag as type
  26. - there must be a specialization of traits::coordinate_type defining the type
  27. of its coordinates
  28. - there must be a specialization of traits::coordinate_system defining its
  29. coordinate system (cartesian, spherical, etc)
  30. - there must be a specialization of traits::dimension defining its number
  31. of dimensions (2, 3, ...) (derive it conveniently
  32. from boost::mpl::int_&lt;X&gt; for X-D)
  33. - there must be a specialization of traits::access, per dimension,
  34. with two functions:
  35. - \b get to get a coordinate value
  36. - \b set to set a coordinate value (this one is not checked for ConstPoint)
  37. \par Example:
  38. A legacy point, defining the necessary specializations to fulfil to the concept.
  39. Suppose that the following point is defined:
  40. \dontinclude doxygen_5.cpp
  41. \skip legacy_point1
  42. \until };
  43. It can then be adapted to the concept as following:
  44. \dontinclude doxygen_5.cpp
  45. \skip adapt legacy_point1
  46. \until }}
  47. Note that it is done like above to show the system. Users will normally use the registration macro.
  48. \par Example:
  49. A read-only legacy point, using a macro to fulfil to the ConstPoint concept.
  50. It cannot be modified by the library but can be used in all algorithms where
  51. points are not modified.
  52. The point looks like the following:
  53. \dontinclude doxygen_5.cpp
  54. \skip legacy_point2
  55. \until };
  56. It uses the macro as following:
  57. \dontinclude doxygen_5.cpp
  58. \skip adapt legacy_point2
  59. \until end adaptation
  60. */
  61. template <typename Geometry>
  62. class Point
  63. {
  64. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  65. typedef typename coordinate_type<Geometry>::type ctype;
  66. typedef typename coordinate_system<Geometry>::type csystem;
  67. enum { ccount = dimension<Geometry>::value };
  68. template <typename P, std::size_t Dimension, std::size_t DimensionCount>
  69. struct dimension_checker
  70. {
  71. static void apply()
  72. {
  73. P* p = 0;
  74. geometry::set<Dimension>(*p, geometry::get<Dimension>(*p));
  75. dimension_checker<P, Dimension+1, DimensionCount>::apply();
  76. }
  77. };
  78. template <typename P, std::size_t DimensionCount>
  79. struct dimension_checker<P, DimensionCount, DimensionCount>
  80. {
  81. static void apply() {}
  82. };
  83. public:
  84. /// BCCL macro to apply the Point concept
  85. BOOST_CONCEPT_USAGE(Point)
  86. {
  87. dimension_checker<Geometry, 0, ccount>::apply();
  88. }
  89. #endif
  90. };
  91. /*!
  92. \brief point concept (const version).
  93. \ingroup const_concepts
  94. \details The ConstPoint concept apply the same as the Point concept,
  95. but does not apply write access.
  96. */
  97. template <typename Geometry>
  98. class ConstPoint
  99. {
  100. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  101. typedef typename coordinate_type<Geometry>::type ctype;
  102. typedef typename coordinate_system<Geometry>::type csystem;
  103. enum { ccount = dimension<Geometry>::value };
  104. template <typename P, std::size_t Dimension, std::size_t DimensionCount>
  105. struct dimension_checker
  106. {
  107. static void apply()
  108. {
  109. const P* p = 0;
  110. ctype coord(geometry::get<Dimension>(*p));
  111. boost::ignore_unused_variable_warning(coord);
  112. dimension_checker<P, Dimension+1, DimensionCount>::apply();
  113. }
  114. };
  115. template <typename P, std::size_t DimensionCount>
  116. struct dimension_checker<P, DimensionCount, DimensionCount>
  117. {
  118. static void apply() {}
  119. };
  120. public:
  121. /// BCCL macro to apply the ConstPoint concept
  122. BOOST_CONCEPT_USAGE(ConstPoint)
  123. {
  124. dimension_checker<Geometry, 0, ccount>::apply();
  125. }
  126. #endif
  127. };
  128. }}} // namespace boost::geometry::concept
  129. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP