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