1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_AS_RANGE_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_AS_RANGE_HPP
16
17
18 #include <boost/type_traits.hpp>
19
20 #include <boost/geometry/core/exterior_ring.hpp>
21 #include <boost/geometry/core/tag.hpp>
22 #include <boost/geometry/core/tags.hpp>
23
24 #include <boost/geometry/util/add_const_if_c.hpp>
25
26
27 namespace boost { namespace geometry
28 {
29
30
31 #ifndef DOXYGEN_NO_DISPATCH
32 namespace dispatch
33 {
34
35
36 template <typename GeometryTag, typename Geometry, typename Range, bool IsConst>
37 struct as_range
38 {
getboost::geometry::dispatch::as_range39 static inline typename add_const_if_c<IsConst, Range>::type& get(
40 typename add_const_if_c<IsConst, Geometry>::type& input)
41 {
42 return input;
43 }
44 };
45
46
47 template <typename Geometry, typename Range, bool IsConst>
48 struct as_range<polygon_tag, Geometry, Range, IsConst>
49 {
getboost::geometry::dispatch::as_range50 static inline typename add_const_if_c<IsConst, Range>::type& get(
51 typename add_const_if_c<IsConst, Geometry>::type& input)
52 {
53 return exterior_ring(input);
54 }
55 };
56
57
58 } // namespace dispatch
59 #endif // DOXYGEN_NO_DISPATCH
60
61 // Will probably be replaced by the more generic "view_as", therefore in detail
62 namespace detail
63 {
64
65 /*!
66 \brief Function getting either the range (ring, linestring) itself
67 or the outer ring (polygon)
68 \details Utility to handle polygon's outer ring as a range
69 \ingroup utility
70 */
71 template <typename Range, typename Geometry>
as_range(Geometry & input)72 inline Range& as_range(Geometry& input)
73 {
74 return dispatch::as_range
75 <
76 typename tag<Geometry>::type,
77 Geometry,
78 Range,
79 false
80 >::get(input);
81 }
82
83
84 /*!
85 \brief Function getting either the range (ring, linestring) itself
86 or the outer ring (polygon), const version
87 \details Utility to handle polygon's outer ring as a range
88 \ingroup utility
89 */
90 template <typename Range, typename Geometry>
as_range(Geometry const & input)91 inline Range const& as_range(Geometry const& input)
92 {
93 return dispatch::as_range
94 <
95 typename tag<Geometry>::type,
96 Geometry,
97 Range,
98 true
99 >::get(input);
100 }
101
102 }
103
104 }} // namespace boost::geometry
105
106
107 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_AS_RANGE_HPP
108