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, 2014.
6 // Modifications copyright (c) 2013-2014, Oracle and/or its affiliates.
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)
12 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SINGLE_GEOMETRY_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SINGLE_GEOMETRY_HPP
17 #include <boost/mpl/if.hpp>
18 #include <boost/type_traits/is_base_of.hpp>
20 #include <boost/geometry/core/assert.hpp>
21 #include <boost/geometry/core/tag.hpp>
22 #include <boost/geometry/util/range.hpp>
24 namespace boost { namespace geometry {
26 #ifndef DOXYGEN_NO_DISPATCH
27 namespace detail_dispatch {
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
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