| 1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
| 2 | |
| 3 | // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. |
| 4 | // Copyright (c) 2008-2015 Bruno Lalande, Paris, France. |
| 5 | // Copyright (c) 2009-2015 Mateusz Loskot, London, UK. |
| 6 | |
| 7 | // This file was modified by Oracle on 2015-2021. |
| 8 | // Modifications copyright (c) 2015-2021, Oracle and/or its affiliates. |
| 9 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle |
| 10 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
| 11 | |
| 12 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library |
| 13 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. |
| 14 | |
| 15 | // Use, modification and distribution is subject to the Boost Software License, |
| 16 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 17 | // http://www.boost.org/LICENSE_1_0.txt) |
| 18 | |
| 19 | |
| 20 | #ifndef BOOST_GEOMETRY_CORE_RING_TYPE_HPP |
| 21 | #define BOOST_GEOMETRY_CORE_RING_TYPE_HPP |
| 22 | |
| 23 | #include <type_traits> |
| 24 | |
| 25 | #include <boost/range/value_type.hpp> |
| 26 | |
| 27 | #include <boost/geometry/core/static_assert.hpp> |
| 28 | #include <boost/geometry/core/tag.hpp> |
| 29 | #include <boost/geometry/core/tags.hpp> |
| 30 | |
| 31 | |
| 32 | namespace boost { namespace geometry |
| 33 | { |
| 34 | |
| 35 | namespace traits |
| 36 | { |
| 37 | |
| 38 | |
| 39 | /*! |
| 40 | \brief Traits class to indicate ring-type of a polygon's exterior ring/interior rings |
| 41 | \ingroup traits |
| 42 | \par Geometries: |
| 43 | - polygon |
| 44 | \par Specializations should provide: |
| 45 | - typedef XXX type ( e.g. ring<P> ) |
| 46 | \tparam Geometry geometry |
| 47 | */ |
| 48 | template <typename Geometry> |
| 49 | struct ring_const_type |
| 50 | { |
| 51 | BOOST_GEOMETRY_STATIC_ASSERT_FALSE( |
| 52 | "Not implemented for this Geometry type." , |
| 53 | Geometry); |
| 54 | }; |
| 55 | |
| 56 | template <typename Geometry> |
| 57 | struct ring_mutable_type |
| 58 | { |
| 59 | BOOST_GEOMETRY_STATIC_ASSERT_FALSE( |
| 60 | "Not implemented for this Geometry type." , |
| 61 | Geometry); |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | } // namespace traits |
| 66 | |
| 67 | |
| 68 | #ifndef DOXYGEN_NO_DISPATCH |
| 69 | namespace core_dispatch |
| 70 | { |
| 71 | |
| 72 | template <typename GeometryTag, typename Geometry> |
| 73 | struct ring_return_type |
| 74 | {}; |
| 75 | |
| 76 | |
| 77 | template <typename LineString> |
| 78 | struct ring_return_type<linestring_tag, LineString> |
| 79 | { |
| 80 | typedef LineString& type; |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | template <typename Ring> |
| 85 | struct ring_return_type<ring_tag, Ring> |
| 86 | { |
| 87 | typedef Ring& type; |
| 88 | }; |
| 89 | |
| 90 | |
| 91 | template <typename Polygon> |
| 92 | struct ring_return_type<polygon_tag, Polygon> |
| 93 | { |
| 94 | typedef typename std::remove_const<Polygon>::type nc_polygon_type; |
| 95 | |
| 96 | typedef std::conditional_t |
| 97 | < |
| 98 | std::is_const<Polygon>::value, |
| 99 | typename traits::ring_const_type<nc_polygon_type>::type, |
| 100 | typename traits::ring_mutable_type<nc_polygon_type>::type |
| 101 | > type; |
| 102 | }; |
| 103 | |
| 104 | |
| 105 | template <typename MultiLinestring> |
| 106 | struct ring_return_type<multi_linestring_tag, MultiLinestring> |
| 107 | { |
| 108 | typedef typename ring_return_type |
| 109 | < |
| 110 | linestring_tag, |
| 111 | std::conditional_t |
| 112 | < |
| 113 | std::is_const<MultiLinestring>::value, |
| 114 | typename boost::range_value<MultiLinestring>::type const, |
| 115 | typename boost::range_value<MultiLinestring>::type |
| 116 | > |
| 117 | >::type type; |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | template <typename MultiPolygon> |
| 122 | struct ring_return_type<multi_polygon_tag, MultiPolygon> |
| 123 | { |
| 124 | typedef typename ring_return_type |
| 125 | < |
| 126 | polygon_tag, |
| 127 | std::conditional_t |
| 128 | < |
| 129 | std::is_const<MultiPolygon>::value, |
| 130 | typename boost::range_value<MultiPolygon>::type const, |
| 131 | typename boost::range_value<MultiPolygon>::type |
| 132 | > |
| 133 | >::type type; |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | template <typename GeometryTag, typename Geometry> |
| 138 | struct ring_type |
| 139 | {}; |
| 140 | |
| 141 | |
| 142 | template <typename Linestring> |
| 143 | struct ring_type<linestring_tag, Linestring> |
| 144 | { |
| 145 | typedef Linestring type; |
| 146 | }; |
| 147 | |
| 148 | |
| 149 | template <typename Ring> |
| 150 | struct ring_type<ring_tag, Ring> |
| 151 | { |
| 152 | typedef Ring type; |
| 153 | }; |
| 154 | |
| 155 | |
| 156 | template <typename Polygon> |
| 157 | struct ring_type<polygon_tag, Polygon> |
| 158 | { |
| 159 | typedef typename std::remove_reference |
| 160 | < |
| 161 | typename ring_return_type<polygon_tag, Polygon>::type |
| 162 | >::type type; |
| 163 | }; |
| 164 | |
| 165 | |
| 166 | template <typename MultiLinestring> |
| 167 | struct ring_type<multi_linestring_tag, MultiLinestring> |
| 168 | { |
| 169 | typedef typename std::remove_reference |
| 170 | < |
| 171 | typename ring_return_type<multi_linestring_tag, MultiLinestring>::type |
| 172 | >::type type; |
| 173 | }; |
| 174 | |
| 175 | |
| 176 | template <typename MultiPolygon> |
| 177 | struct ring_type<multi_polygon_tag, MultiPolygon> |
| 178 | { |
| 179 | typedef typename std::remove_reference |
| 180 | < |
| 181 | typename ring_return_type<multi_polygon_tag, MultiPolygon>::type |
| 182 | >::type type; |
| 183 | }; |
| 184 | |
| 185 | |
| 186 | } // namespace core_dispatch |
| 187 | #endif |
| 188 | |
| 189 | |
| 190 | /*! |
| 191 | \brief \brief_meta{type, ring_type, \meta_geometry_type} |
| 192 | \details A polygon contains one exterior ring |
| 193 | and zero or more interior rings (holes). |
| 194 | This metafunction retrieves the type of the rings. |
| 195 | Exterior ring and each of the interior rings all have the same ring_type. |
| 196 | \tparam Geometry A type fullfilling the Ring, Polygon or MultiPolygon concept. |
| 197 | \ingroup core |
| 198 | |
| 199 | \qbk{[include reference/core/ring_type.qbk]} |
| 200 | */ |
| 201 | template <typename Geometry> |
| 202 | struct ring_type |
| 203 | { |
| 204 | typedef typename core_dispatch::ring_type |
| 205 | < |
| 206 | typename tag<Geometry>::type, |
| 207 | Geometry |
| 208 | >::type type; |
| 209 | }; |
| 210 | |
| 211 | |
| 212 | template <typename Geometry> |
| 213 | struct ring_return_type |
| 214 | { |
| 215 | typedef typename core_dispatch::ring_return_type |
| 216 | < |
| 217 | typename tag<Geometry>::type, |
| 218 | Geometry |
| 219 | >::type type; |
| 220 | }; |
| 221 | |
| 222 | |
| 223 | }} // namespace boost::geometry |
| 224 | |
| 225 | |
| 226 | #endif // BOOST_GEOMETRY_CORE_RING_TYPE_HPP |
| 227 | |