as_range.hpp 2.7 KB

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