weak_static.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Boost.Geometry Index
  2. //
  3. // R-tree nodes based on static conversion, storing static-size containers
  4. //
  5. // Copyright (c) 2011-2023 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2021.
  8. // Modifications copyright (c) 2021 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. //
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_STATIC_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_STATIC_HPP
  16. #include <utility>
  17. #include <boost/container/allocator_traits.hpp>
  18. #include <boost/core/invoke_swap.hpp>
  19. #include <boost/geometry/index/detail/rtree/node/weak_dynamic.hpp>
  20. #include <boost/geometry/index/detail/varray.hpp>
  21. namespace boost { namespace geometry { namespace index {
  22. namespace detail { namespace rtree {
  23. template <typename Value, typename Parameters, typename Box, typename Allocators>
  24. struct weak_internal_node<Value, Parameters, Box, Allocators, node_weak_static_tag>
  25. : public weak_node<Value, Parameters, Box, Allocators, node_weak_static_tag>
  26. {
  27. typedef detail::varray<
  28. rtree::ptr_pair<Box, typename Allocators::node_pointer>,
  29. Parameters::max_elements + 1
  30. > elements_type;
  31. template <typename Alloc>
  32. inline weak_internal_node(Alloc const&) {}
  33. elements_type elements;
  34. };
  35. template <typename Value, typename Parameters, typename Box, typename Allocators>
  36. struct weak_leaf<Value, Parameters, Box, Allocators, node_weak_static_tag>
  37. : public weak_node<Value, Parameters, Box, Allocators, node_weak_static_tag>
  38. {
  39. typedef detail::varray<
  40. Value,
  41. Parameters::max_elements + 1
  42. > elements_type;
  43. template <typename Alloc>
  44. inline weak_leaf(Alloc const&) {}
  45. elements_type elements;
  46. };
  47. // nodes traits
  48. template <typename Value, typename Parameters, typename Box, typename Allocators>
  49. struct node<Value, Parameters, Box, Allocators, node_weak_static_tag>
  50. {
  51. typedef weak_node<Value, Parameters, Box, Allocators, node_weak_static_tag> type;
  52. };
  53. template <typename Value, typename Parameters, typename Box, typename Allocators>
  54. struct internal_node<Value, Parameters, Box, Allocators, node_weak_static_tag>
  55. {
  56. typedef weak_internal_node<Value, Parameters, Box, Allocators, node_weak_static_tag> type;
  57. };
  58. template <typename Value, typename Parameters, typename Box, typename Allocators>
  59. struct leaf<Value, Parameters, Box, Allocators, node_weak_static_tag>
  60. {
  61. typedef weak_leaf<Value, Parameters, Box, Allocators, node_weak_static_tag> type;
  62. };
  63. template <typename Value, typename Parameters, typename Box, typename Allocators, bool IsVisitableConst>
  64. struct visitor<Value, Parameters, Box, Allocators, node_weak_static_tag, IsVisitableConst>
  65. {
  66. typedef weak_visitor<Value, Parameters, Box, Allocators, node_weak_static_tag, IsVisitableConst> type;
  67. };
  68. // allocators
  69. template <typename Allocator, typename Value, typename Parameters, typename Box>
  70. class allocators<Allocator, Value, Parameters, Box, node_weak_static_tag>
  71. : public detail::rtree::internal_node_alloc<Allocator, Value, Parameters, Box, node_weak_static_tag>::type
  72. , public detail::rtree::leaf_alloc<Allocator, Value, Parameters, Box, node_weak_static_tag>::type
  73. {
  74. typedef detail::rtree::internal_node_alloc
  75. <
  76. Allocator, Value, Parameters, Box, node_weak_static_tag
  77. > internal_node_alloc;
  78. typedef detail::rtree::leaf_alloc
  79. <
  80. Allocator, Value, Parameters, Box, node_weak_static_tag
  81. > leaf_alloc;
  82. typedef detail::rtree::node_alloc
  83. <
  84. Allocator, Value, Parameters, Box, node_weak_static_tag
  85. > node_alloc;
  86. public:
  87. typedef typename internal_node_alloc::type internal_node_allocator_type;
  88. typedef typename leaf_alloc::type leaf_allocator_type;
  89. typedef typename node_alloc::traits::pointer node_pointer;
  90. private:
  91. typedef typename boost::container::allocator_traits
  92. <
  93. leaf_allocator_type
  94. >::template rebind_alloc<Value> value_allocator_type;
  95. typedef boost::container::allocator_traits<value_allocator_type> value_allocator_traits;
  96. public:
  97. typedef Allocator allocator_type;
  98. typedef Value value_type;
  99. typedef typename value_allocator_traits::reference reference;
  100. typedef typename value_allocator_traits::const_reference const_reference;
  101. typedef typename value_allocator_traits::size_type size_type;
  102. typedef typename value_allocator_traits::difference_type difference_type;
  103. typedef typename value_allocator_traits::pointer pointer;
  104. typedef typename value_allocator_traits::const_pointer const_pointer;
  105. inline allocators()
  106. : internal_node_allocator_type()
  107. , leaf_allocator_type()
  108. {}
  109. template <typename Alloc>
  110. inline explicit allocators(Alloc const& alloc)
  111. : internal_node_allocator_type(alloc)
  112. , leaf_allocator_type(alloc)
  113. {}
  114. inline allocators(allocators&& a)
  115. : internal_node_allocator_type(std::move(a.internal_node_allocator()))
  116. , leaf_allocator_type(std::move(a.leaf_allocator()))
  117. {}
  118. inline allocators & operator=(allocators&& a)
  119. {
  120. internal_node_allocator() = std::move(a.internal_node_allocator());
  121. leaf_allocator() = std::move(a.leaf_allocator());
  122. return *this;
  123. }
  124. inline allocators & operator=(allocators const& a)
  125. {
  126. internal_node_allocator() = a.internal_node_allocator();
  127. leaf_allocator() = a.leaf_allocator();
  128. return *this;
  129. }
  130. void swap(allocators & a)
  131. {
  132. boost::core::invoke_swap(internal_node_allocator(), a.internal_node_allocator());
  133. boost::core::invoke_swap(leaf_allocator(), a.leaf_allocator());
  134. }
  135. bool operator==(allocators const& a) const { return leaf_allocator() == a.leaf_allocator(); }
  136. template <typename Alloc>
  137. bool operator==(Alloc const& a) const { return leaf_allocator() == leaf_allocator_type(a); }
  138. Allocator allocator() const { return Allocator(leaf_allocator()); }
  139. internal_node_allocator_type & internal_node_allocator() { return *this; }
  140. internal_node_allocator_type const& internal_node_allocator() const { return *this; }
  141. leaf_allocator_type & leaf_allocator() { return *this; }
  142. leaf_allocator_type const& leaf_allocator() const{ return *this; }
  143. };
  144. }} // namespace detail::rtree
  145. }}} // namespace boost::geometry::index
  146. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_STATIC_HPP