for_each_coordinate.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2020.
  6. // Modifications copyright (c) 2020, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_UTIL_FOR_EACH_COORDINATE_HPP
  14. #define BOOST_GEOMETRY_UTIL_FOR_EACH_COORDINATE_HPP
  15. #include <boost/concept/requires.hpp>
  16. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DETAIL
  20. namespace detail
  21. {
  22. template
  23. <
  24. typename Point,
  25. int Dimension = 0,
  26. int DimensionCount = dimension<Point>::value
  27. >
  28. struct coordinates_scanner
  29. {
  30. template <typename Op>
  31. static inline Op apply(Point& point, Op operation)
  32. {
  33. operation.template apply<Point, Dimension>(point);
  34. return coordinates_scanner
  35. <
  36. Point,
  37. Dimension + 1
  38. >::apply(point, operation);
  39. }
  40. };
  41. template <typename Point, int DimensionCount>
  42. struct coordinates_scanner<Point, DimensionCount, DimensionCount>
  43. {
  44. template <typename Op>
  45. static inline Op apply(Point& , Op operation)
  46. {
  47. return operation;
  48. }
  49. };
  50. } // namespace detail
  51. #endif // DOXYGEN_NO_DETAIL
  52. template <typename Point, typename Op>
  53. inline void for_each_coordinate(Point& point, Op operation)
  54. {
  55. BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
  56. detail::coordinates_scanner<Point>::apply(point, operation);
  57. }
  58. template <typename Point, typename Op>
  59. inline Op for_each_coordinate(Point const& point, Op operation)
  60. {
  61. BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point>) );
  62. return detail::coordinates_scanner<Point const>::apply(point, operation);
  63. }
  64. }} // namespace boost::geometry
  65. #endif // BOOST_GEOMETRY_UTIL_FOR_EACH_COORDINATE_HPP