Chris@102
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@102
|
2
|
Chris@102
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@102
|
4
|
Chris@102
|
5 // This file was modified by Oracle on 2013, 2014.
|
Chris@102
|
6 // Modifications copyright (c) 2013-2014, Oracle and/or its affiliates.
|
Chris@102
|
7
|
Chris@102
|
8 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@102
|
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
10 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
11
|
Chris@102
|
12 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
Chris@102
|
13
|
Chris@102
|
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SINGLE_GEOMETRY_HPP
|
Chris@102
|
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SINGLE_GEOMETRY_HPP
|
Chris@102
|
16
|
Chris@102
|
17 #include <boost/type_traits/is_base_of.hpp>
|
Chris@102
|
18 #include <boost/geometry/core/tag.hpp>
|
Chris@102
|
19 #include <boost/geometry/util/range.hpp>
|
Chris@102
|
20
|
Chris@102
|
21 namespace boost { namespace geometry {
|
Chris@102
|
22
|
Chris@102
|
23 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@102
|
24 namespace detail_dispatch {
|
Chris@102
|
25
|
Chris@102
|
26 // Returns single geometry by Id
|
Chris@102
|
27 // for single geometries returns the geometry itself
|
Chris@102
|
28 template <typename Geometry,
|
Chris@102
|
29 bool IsMulti = boost::is_base_of
|
Chris@102
|
30 <
|
Chris@102
|
31 multi_tag,
|
Chris@102
|
32 typename geometry::tag<Geometry>::type
|
Chris@102
|
33 >::value
|
Chris@102
|
34 >
|
Chris@102
|
35 struct single_geometry
|
Chris@102
|
36 {
|
Chris@102
|
37 typedef Geometry & return_type;
|
Chris@102
|
38
|
Chris@102
|
39 template <typename Id>
|
Chris@102
|
40 static inline return_type apply(Geometry & g, Id const& ) { return g; }
|
Chris@102
|
41 };
|
Chris@102
|
42
|
Chris@102
|
43 // for multi geometries returns one of the stored single geometries
|
Chris@102
|
44 template <typename Geometry>
|
Chris@102
|
45 struct single_geometry<Geometry, true>
|
Chris@102
|
46 {
|
Chris@102
|
47 typedef typename boost::mpl::if_c
|
Chris@102
|
48 <
|
Chris@102
|
49 boost::is_const<Geometry>::value,
|
Chris@102
|
50 typename boost::range_value<Geometry>::type const&,
|
Chris@102
|
51 typename boost::range_value<Geometry>::type
|
Chris@102
|
52 >::type return_type;
|
Chris@102
|
53
|
Chris@102
|
54 template <typename Id>
|
Chris@102
|
55 static inline return_type apply(Geometry & g, Id const& id)
|
Chris@102
|
56 {
|
Chris@102
|
57 BOOST_ASSERT(id.multi_index >= 0);
|
Chris@102
|
58 typedef typename boost::range_size<Geometry>::type size_type;
|
Chris@102
|
59 return range::at(g, static_cast<size_type>(id.multi_index));
|
Chris@102
|
60 }
|
Chris@102
|
61 };
|
Chris@102
|
62
|
Chris@102
|
63 } // namespace detail_dispatch
|
Chris@102
|
64 #endif // DOXYGEN_NO_DISPATCH
|
Chris@102
|
65
|
Chris@102
|
66 #ifndef DOXYGEN_NO_DETAIL
|
Chris@102
|
67 namespace detail {
|
Chris@102
|
68
|
Chris@102
|
69 template <typename Geometry>
|
Chris@102
|
70 struct single_geometry_return_type
|
Chris@102
|
71 {
|
Chris@102
|
72 typedef typename detail_dispatch::single_geometry<Geometry>::return_type type;
|
Chris@102
|
73 };
|
Chris@102
|
74
|
Chris@102
|
75 template <typename Geometry, typename Id>
|
Chris@102
|
76 inline
|
Chris@102
|
77 typename single_geometry_return_type<Geometry>::type
|
Chris@102
|
78 single_geometry(Geometry & geometry, Id const& id)
|
Chris@102
|
79 {
|
Chris@102
|
80 return detail_dispatch::single_geometry<Geometry>::apply(geometry, id);
|
Chris@102
|
81 }
|
Chris@102
|
82
|
Chris@102
|
83 template <typename Geometry, typename Id>
|
Chris@102
|
84 inline
|
Chris@102
|
85 typename single_geometry_return_type<Geometry const>::type
|
Chris@102
|
86 single_geometry(Geometry const& geometry, Id const& id)
|
Chris@102
|
87 {
|
Chris@102
|
88 return detail_dispatch::single_geometry<Geometry const>::apply(geometry, id);
|
Chris@102
|
89 }
|
Chris@102
|
90
|
Chris@102
|
91 } // namespace detail
|
Chris@102
|
92 #endif // DOXYGEN_NO_DETAIL
|
Chris@102
|
93
|
Chris@102
|
94 }} // namespace boost::geometry
|
Chris@102
|
95
|
Chris@102
|
96 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SINGLE_GEOMETRY_HPP
|