for_each_coordinate.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // 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_UTIL_FOR_EACH_COORDINATE_HPP
  11. #define BOOST_GEOMETRY_UTIL_FOR_EACH_COORDINATE_HPP
  12. #include <boost/concept/requires.hpp>
  13. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  14. #include <boost/geometry/util/add_const_if_c.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. #ifndef DOXYGEN_NO_DETAIL
  18. namespace detail
  19. {
  20. template <typename Point, int Dimension, int DimensionCount, bool IsConst>
  21. struct coordinates_scanner
  22. {
  23. template <typename Op>
  24. static inline Op apply(typename add_const_if_c
  25. <
  26. IsConst,
  27. Point
  28. >::type& point, Op operation)
  29. {
  30. operation.template apply<Point, Dimension>(point);
  31. return coordinates_scanner
  32. <
  33. Point,
  34. Dimension+1,
  35. DimensionCount,
  36. IsConst
  37. >::apply(point, operation);
  38. }
  39. };
  40. template <typename Point, int DimensionCount, bool IsConst>
  41. struct coordinates_scanner<Point, DimensionCount, DimensionCount, IsConst>
  42. {
  43. template <typename Op>
  44. static inline Op apply(typename add_const_if_c
  45. <
  46. IsConst,
  47. Point
  48. >::type& , Op operation)
  49. {
  50. return operation;
  51. }
  52. };
  53. } // namespace detail
  54. #endif // DOXYGEN_NO_DETAIL
  55. template <typename Point, typename Op>
  56. inline void for_each_coordinate(Point& point, Op operation)
  57. {
  58. BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
  59. typedef typename detail::coordinates_scanner
  60. <
  61. Point, 0, dimension<Point>::type::value, false
  62. > scanner;
  63. scanner::apply(point, operation);
  64. }
  65. template <typename Point, typename Op>
  66. inline Op for_each_coordinate(Point const& point, Op operation)
  67. {
  68. BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point>) );
  69. typedef typename detail::coordinates_scanner
  70. <
  71. Point, 0, dimension<Point>::type::value, true
  72. > scanner;
  73. return scanner::apply(point, operation);
  74. }
  75. }} // namespace boost::geometry
  76. #endif // BOOST_GEOMETRY_UTIL_FOR_EACH_COORDINATE_HPP