as_range.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_AS_RANGE_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_AS_RANGE_HPP
  12. #include <boost/geometry/core/exterior_ring.hpp>
  13. #include <boost/geometry/core/tag.hpp>
  14. #include <boost/geometry/core/tags.hpp>
  15. #include <boost/geometry/util/add_const_if_c.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. #ifndef DOXYGEN_NO_DISPATCH
  19. namespace dispatch
  20. {
  21. template <typename GeometryTag, typename Geometry, typename Range, bool IsConst>
  22. struct as_range
  23. {
  24. static inline typename add_const_if_c<IsConst, Range>::type& get(
  25. typename add_const_if_c<IsConst, Geometry>::type& input)
  26. {
  27. return input;
  28. }
  29. };
  30. template <typename Geometry, typename Range, bool IsConst>
  31. struct as_range<polygon_tag, Geometry, Range, IsConst>
  32. {
  33. static inline typename add_const_if_c<IsConst, Range>::type& get(
  34. typename add_const_if_c<IsConst, Geometry>::type& input)
  35. {
  36. return exterior_ring(input);
  37. }
  38. };
  39. } // namespace dispatch
  40. #endif // DOXYGEN_NO_DISPATCH
  41. // Will probably be replaced by the more generic "view_as", therefore in detail
  42. namespace detail
  43. {
  44. /*!
  45. \brief Function getting either the range (ring, linestring) itself
  46. or the outer ring (polygon)
  47. \details Utility to handle polygon's outer ring as a range
  48. \ingroup utility
  49. */
  50. template <typename Range, typename Geometry>
  51. inline Range& as_range(Geometry& input)
  52. {
  53. return dispatch::as_range
  54. <
  55. typename tag<Geometry>::type,
  56. Geometry,
  57. Range,
  58. false
  59. >::get(input);
  60. }
  61. /*!
  62. \brief Function getting either the range (ring, linestring) itself
  63. or the outer ring (polygon), const version
  64. \details Utility to handle polygon's outer ring as a range
  65. \ingroup utility
  66. */
  67. template <typename Range, typename Geometry>
  68. inline Range const& as_range(Geometry const& input)
  69. {
  70. return dispatch::as_range
  71. <
  72. typename tag<Geometry>::type,
  73. Geometry,
  74. Range,
  75. true
  76. >::get(input);
  77. }
  78. }
  79. }} // namespace boost::geometry
  80. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_AS_RANGE_HPP