File indexing completed on 2025-01-18 09:36:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_GEOMETRY_VIEWS_DETAIL_RANDOM_ACCESS_VIEW_HPP
0011 #define BOOST_GEOMETRY_VIEWS_DETAIL_RANDOM_ACCESS_VIEW_HPP
0012
0013 #include <vector>
0014
0015 #include <boost/range/begin.hpp>
0016 #include <boost/range/end.hpp>
0017 #include <boost/range/iterator.hpp>
0018 #include <boost/range/size.hpp>
0019
0020 #include <boost/geometry/algorithms/detail/visit.hpp>
0021 #include <boost/geometry/core/geometry_types.hpp>
0022 #include <boost/geometry/core/tag.hpp>
0023 #include <boost/geometry/core/tags.hpp>
0024 #include <boost/geometry/util/sequence.hpp>
0025 #include <boost/geometry/util/type_traits.hpp>
0026
0027 namespace boost { namespace geometry
0028 {
0029
0030 #ifndef DOXYGEN_NO_DETAIL
0031 namespace detail
0032 {
0033
0034
0035 template <typename Range>
0036 struct is_random_access_range
0037 : std::is_convertible
0038 <
0039 typename boost::iterator_traversal
0040 <
0041 typename boost::range_iterator<Range>::type
0042 >::type,
0043 boost::random_access_traversal_tag
0044 >
0045 {};
0046
0047 template <typename Geometry>
0048 struct is_geometry_collection_recursive
0049 : util::bool_constant
0050 <
0051 util::is_geometry_collection
0052 <
0053 typename util::sequence_find_if
0054 <
0055 typename traits::geometry_types<std::remove_const_t<Geometry>>::type,
0056 util::is_geometry_collection
0057 >::type
0058 >::value
0059 >
0060 {};
0061
0062 template
0063 <
0064 typename GeometryCollection,
0065 bool IsRandomAccess = is_random_access_range<GeometryCollection>::value,
0066 bool IsRecursive = is_geometry_collection_recursive<GeometryCollection>::value
0067 >
0068 class random_access_view
0069 : public std::vector<typename boost::range_iterator<GeometryCollection>::type>
0070 {
0071
0072
0073
0074
0075 using base_t = std::vector<typename boost::range_iterator<GeometryCollection>::type>;
0076
0077 public:
0078 random_access_view(GeometryCollection & geometry)
0079 {
0080 this->reserve(boost::size(geometry));
0081 detail::visit_breadth_first_impl<true>::apply([&](auto&&, auto iter)
0082 {
0083 this->push_back(iter);
0084 return true;
0085 }, geometry);
0086 }
0087 };
0088
0089 template <typename GeometryCollection>
0090 class random_access_view<GeometryCollection, true, false>
0091 {
0092 public:
0093 using iterator = typename boost::range_iterator<GeometryCollection>::type;
0094 using const_iterator = typename boost::range_const_iterator<GeometryCollection>::type;
0095
0096 random_access_view(GeometryCollection & geometry)
0097 : m_begin(boost::begin(geometry))
0098 , m_end(boost::end(geometry))
0099 {}
0100
0101 iterator begin() { return m_begin; }
0102 iterator end() { return m_end; }
0103 const_iterator begin() const { return m_begin; }
0104 const_iterator end() const { return m_end; }
0105
0106 private:
0107 iterator m_begin, m_end;
0108 };
0109
0110
0111 template <typename GeometryCollection>
0112 struct random_access_view_iter_visit
0113 {
0114 template <typename Function, typename Iterator>
0115 static void apply(Function && function, Iterator iterator)
0116 {
0117 geometry::traits::iter_visit
0118 <
0119 std::remove_const_t<GeometryCollection>
0120 >::apply(std::forward<Function>(function), *iterator);
0121 }
0122 };
0123
0124
0125 template <typename ...Ts>
0126 struct remove_geometry_collections_pack
0127 {
0128 using type = util::type_sequence<>;
0129 };
0130
0131 template <typename T, typename ...Ts>
0132 struct remove_geometry_collections_pack<T, Ts...>
0133 {
0134 using next_sequence = typename remove_geometry_collections_pack<Ts...>::type;
0135 using type = std::conditional_t
0136 <
0137 util::is_geometry_collection<T>::value,
0138 next_sequence,
0139 typename util::sequence_merge<util::type_sequence<T>, next_sequence>::type
0140 >;
0141 };
0142
0143 template <typename Types>
0144 struct remove_geometry_collections;
0145
0146 template <typename ...Ts>
0147 struct remove_geometry_collections<util::type_sequence<Ts...>>
0148 : remove_geometry_collections_pack<Ts...>
0149 {};
0150
0151
0152 }
0153 #endif
0154
0155
0156 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
0157 namespace traits
0158 {
0159
0160 template<typename GeometryCollection, bool IsRandomAccess, bool IsRecursive>
0161 struct tag<geometry::detail::random_access_view<GeometryCollection, IsRandomAccess, IsRecursive>>
0162 {
0163 using type = geometry_collection_tag;
0164 };
0165
0166
0167 template <typename GeometryCollection>
0168 struct iter_visit<geometry::detail::random_access_view<GeometryCollection, false, false>>
0169 : geometry::detail::random_access_view_iter_visit<GeometryCollection>
0170 {};
0171
0172 template <typename GeometryCollection>
0173 struct iter_visit<geometry::detail::random_access_view<GeometryCollection, true, true>>
0174 : geometry::detail::random_access_view_iter_visit<GeometryCollection>
0175 {};
0176
0177 template <typename GeometryCollection>
0178 struct iter_visit<geometry::detail::random_access_view<GeometryCollection, false, true>>
0179 : geometry::detail::random_access_view_iter_visit<GeometryCollection>
0180 {};
0181
0182 template <typename GeometryCollection>
0183 struct iter_visit<geometry::detail::random_access_view<GeometryCollection, true, false>>
0184 {
0185 template <typename Function, typename Iterator>
0186 static void apply(Function && function, Iterator iterator)
0187 {
0188 geometry::traits::iter_visit
0189 <
0190 std::remove_const_t<GeometryCollection>
0191 >::apply(std::forward<Function>(function), iterator);
0192 }
0193 };
0194
0195
0196 template <typename GeometryCollection, bool IsRandomAccess>
0197 struct geometry_types<geometry::detail::random_access_view<GeometryCollection, IsRandomAccess, false>>
0198 : traits::geometry_types
0199 <
0200 std::remove_const_t<GeometryCollection>
0201 >
0202 {};
0203
0204 template <typename GeometryCollection, bool IsRandomAccess>
0205 struct geometry_types<geometry::detail::random_access_view<GeometryCollection, IsRandomAccess, true>>
0206 : geometry::detail::remove_geometry_collections
0207 <
0208 typename traits::geometry_types
0209 <
0210 std::remove_const_t<GeometryCollection>
0211 >::type
0212 >
0213 {};
0214
0215 }
0216 #endif
0217
0218
0219 }}
0220
0221
0222 #endif