std_pair_as_segment.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  3. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  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_GEOMETRIES_ADAPTED_STD_PAIR_AS_SEGMENT_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_PAIR_AS_SEGMENT_HPP
  12. // Only possible if the std::pair is not used for iterator/pair
  13. // (maybe it is possible to avoid that by detecting in the other file
  14. // if an iterator was used in the pair)
  15. #ifdef BOOST_GEOMETRY_ADAPTED_STD_RANGE_TAG_DEFINED
  16. #error Include only one headerfile to register tag for adapted std:: containers or iterator pair
  17. #endif
  18. #define BOOST_GEOMETRY_ADAPTED_STD_RANGE_TAG_DEFINED
  19. #include <cstddef>
  20. #include <boost/geometry/core/access.hpp>
  21. #include <boost/geometry/core/tag.hpp>
  22. #include <boost/geometry/core/tags.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  26. namespace traits
  27. {
  28. template <typename Point>
  29. struct tag<std::pair<Point, Point> >
  30. {
  31. typedef segment_tag type;
  32. };
  33. template <typename Point>
  34. struct point_type<std::pair<Point, Point> >
  35. {
  36. typedef Point type;
  37. };
  38. template <typename Point, std::size_t Dimension>
  39. struct indexed_access<std::pair<Point, Point>, 0, Dimension>
  40. {
  41. typedef typename geometry::coordinate_type<Point>::type coordinate_type;
  42. static inline coordinate_type get(std::pair<Point, Point> const& s)
  43. {
  44. return geometry::get<Dimension>(s.first);
  45. }
  46. static inline void set(std::pair<Point, Point>& s, coordinate_type const& value)
  47. {
  48. geometry::set<Dimension>(s.first, value);
  49. }
  50. };
  51. template <typename Point, std::size_t Dimension>
  52. struct indexed_access<std::pair<Point, Point>, 1, Dimension>
  53. {
  54. typedef typename geometry::coordinate_type<Point>::type coordinate_type;
  55. static inline coordinate_type get(std::pair<Point, Point> const& s)
  56. {
  57. return geometry::get<Dimension>(s.second);
  58. }
  59. static inline void set(std::pair<Point, Point>& s, coordinate_type const& value)
  60. {
  61. geometry::set<Dimension>(s.second, value);
  62. }
  63. };
  64. } // namespace traits
  65. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  66. }} // namespace boost::geometry
  67. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_PAIR_AS_SEGMENT_HPP