1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2013-2020.
6 // Modifications copyright (c) 2013-2020, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SINGLE_GEOMETRY_HPP
14 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SINGLE_GEOMETRY_HPP
16 #include <type_traits>
18 #include <boost/geometry/core/assert.hpp>
19 #include <boost/geometry/core/tag.hpp>
20 #include <boost/geometry/util/range.hpp>
22 namespace boost { namespace geometry {
24 #ifndef DOXYGEN_NO_DISPATCH
25 namespace detail_dispatch {
27 // Returns single geometry by Id
28 // for single geometries returns the geometry itself
32 bool IsMulti = std::is_base_of
35 typename geometry::tag<Geometry>::type
38 struct single_geometry
40 typedef Geometry & return_type;
42 template <typename Id>
43 static inline return_type apply(Geometry & g, Id const& ) { return g; }
46 // for multi geometries returns one of the stored single geometries
47 template <typename Geometry>
48 struct single_geometry<Geometry, true>
50 typedef typename boost::range_reference<Geometry>::type return_type;
52 template <typename Id>
53 static inline return_type apply(Geometry & g, Id const& id)
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));
61 } // namespace detail_dispatch
62 #endif // DOXYGEN_NO_DISPATCH
64 #ifndef DOXYGEN_NO_DETAIL
67 template <typename Geometry>
68 struct single_geometry_return_type
70 typedef typename detail_dispatch::single_geometry<Geometry>::return_type type;
73 template <typename Geometry, typename Id>
75 typename single_geometry_return_type<Geometry>::type
76 single_geometry(Geometry & geometry, Id const& id)
78 return detail_dispatch::single_geometry<Geometry>::apply(geometry, id);
81 template <typename Geometry, typename Id>
83 typename single_geometry_return_type<Geometry const>::type
84 single_geometry(Geometry const& geometry, Id const& id)
86 return detail_dispatch::single_geometry<Geometry const>::apply(geometry, id);
90 #endif // DOXYGEN_NO_DETAIL
92 }} // namespace boost::geometry
94 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SINGLE_GEOMETRY_HPP