convert_point_to_point.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_ALGORITHMS_DETAIL_CONVERT_POINT_TO_POINT_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CONVERT_POINT_TO_POINT_HPP
  12. // Note: extracted from "convert.hpp" to avoid circular references convert/append
  13. #include <cstddef>
  14. #include <boost/numeric/conversion/cast.hpp>
  15. #include <boost/geometry/core/access.hpp>
  16. #include <boost/geometry/core/coordinate_dimension.hpp>
  17. #include <boost/geometry/core/coordinate_type.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. #ifndef DOXYGEN_NO_DETAIL
  21. namespace detail { namespace conversion
  22. {
  23. template <typename Source, typename Destination, std::size_t Dimension, std::size_t DimensionCount>
  24. struct point_to_point
  25. {
  26. static inline void apply(Source const& source, Destination& destination)
  27. {
  28. typedef typename coordinate_type<Destination>::type coordinate_type;
  29. set<Dimension>(destination, boost::numeric_cast<coordinate_type>(get<Dimension>(source)));
  30. point_to_point<Source, Destination, Dimension + 1, DimensionCount>::apply(source, destination);
  31. }
  32. };
  33. template <typename Source, typename Destination, std::size_t DimensionCount>
  34. struct point_to_point<Source, Destination, DimensionCount, DimensionCount>
  35. {
  36. static inline void apply(Source const& , Destination& )
  37. {}
  38. };
  39. template <typename Source, typename Destination>
  40. inline void convert_point_to_point(Source const& source, Destination& destination)
  41. {
  42. point_to_point<Source, Destination, 0, dimension<Destination>::value>::apply(source, destination);
  43. }
  44. }} // namespace detail::conversion
  45. #endif // DOXYGEN_NO_DETAIL
  46. }} // namespace boost::geometry
  47. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CONVERT_POINT_TO_POINT_HPP