variant_static.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Boost.Geometry Index
  2. //
  3. // R-tree nodes based on Boost.Variant, 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_VARIANT_STATIC_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_STATIC_HPP
  16. #include <utility>
  17. #include <boost/container/allocator_traits.hpp>
  18. #include <boost/core/invoke_swap.hpp>
  19. #include <boost/variant/static_visitor.hpp>
  20. #include <boost/variant/variant.hpp>
  21. #include <boost/geometry/index/detail/rtree/node/variant_dynamic.hpp>
  22. #include <boost/geometry/index/detail/varray.hpp>
  23. namespace boost { namespace geometry { namespace index {
  24. namespace detail { namespace rtree {
  25. // nodes default types
  26. template <typename Value, typename Parameters, typename Box, typename Allocators>
  27. struct variant_internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag>
  28. {
  29. typedef detail::varray<
  30. rtree::ptr_pair<Box, typename Allocators::node_pointer>,
  31. Parameters::max_elements + 1
  32. > elements_type;
  33. template <typename Alloc>
  34. inline variant_internal_node(Alloc const&) {}
  35. elements_type elements;
  36. };
  37. template <typename Value, typename Parameters, typename Box, typename Allocators>
  38. struct variant_leaf<Value, Parameters, Box, Allocators, node_variant_static_tag>
  39. {
  40. typedef detail::varray<
  41. Value,
  42. Parameters::max_elements + 1
  43. > elements_type;
  44. template <typename Alloc>
  45. inline variant_leaf(Alloc const&) {}
  46. elements_type elements;
  47. };
  48. // nodes traits
  49. template <typename Value, typename Parameters, typename Box, typename Allocators>
  50. struct node<Value, Parameters, Box, Allocators, node_variant_static_tag>
  51. {
  52. typedef boost::variant<
  53. variant_leaf<Value, Parameters, Box, Allocators, node_variant_static_tag>,
  54. variant_internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag>
  55. > type;
  56. };
  57. template <typename Value, typename Parameters, typename Box, typename Allocators>
  58. struct internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag>
  59. {
  60. typedef variant_internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag> type;
  61. };
  62. template <typename Value, typename Parameters, typename Box, typename Allocators>
  63. struct leaf<Value, Parameters, Box, Allocators, node_variant_static_tag>
  64. {
  65. typedef variant_leaf<Value, Parameters, Box, Allocators, node_variant_static_tag> type;
  66. };
  67. // visitor traits
  68. template <typename Value, typename Parameters, typename Box, typename Allocators, bool IsVisitableConst>
  69. struct visitor<Value, Parameters, Box, Allocators, node_variant_static_tag, IsVisitableConst>
  70. {
  71. typedef static_visitor<> type;
  72. };
  73. // allocators
  74. template <typename Allocator, typename Value, typename Parameters, typename Box>
  75. class allocators<Allocator, Value, Parameters, Box, node_variant_static_tag>
  76. : public detail::rtree::node_alloc
  77. <
  78. Allocator, Value, Parameters, Box, node_variant_static_tag
  79. >::type
  80. {
  81. typedef detail::rtree::node_alloc
  82. <
  83. Allocator, Value, Parameters, Box, node_variant_static_tag
  84. > node_alloc;
  85. public:
  86. typedef typename node_alloc::type node_allocator_type;
  87. typedef typename node_alloc::traits::pointer node_pointer;
  88. private:
  89. typedef typename boost::container::allocator_traits
  90. <
  91. node_allocator_type
  92. >::template rebind_alloc<Value> value_allocator_type;
  93. typedef boost::container::allocator_traits<value_allocator_type> value_allocator_traits;
  94. public:
  95. typedef Allocator allocator_type;
  96. typedef Value value_type;
  97. typedef typename value_allocator_traits::reference reference;
  98. typedef typename value_allocator_traits::const_reference const_reference;
  99. typedef typename value_allocator_traits::size_type size_type;
  100. typedef typename value_allocator_traits::difference_type difference_type;
  101. typedef typename value_allocator_traits::pointer pointer;
  102. typedef typename value_allocator_traits::const_pointer const_pointer;
  103. inline allocators()
  104. : node_allocator_type()
  105. {}
  106. template <typename Alloc>
  107. inline explicit allocators(Alloc const& alloc)
  108. : node_allocator_type(alloc)
  109. {}
  110. inline allocators(allocators&& a)
  111. : node_allocator_type(std::move(a.node_allocator()))
  112. {}
  113. inline allocators & operator=(allocators&& a)
  114. {
  115. node_allocator() = std::move(a.node_allocator());
  116. return *this;
  117. }
  118. inline allocators & operator=(allocators const& a)
  119. {
  120. node_allocator() = a.node_allocator();
  121. return *this;
  122. }
  123. void swap(allocators & a)
  124. {
  125. boost::core::invoke_swap(node_allocator(), a.node_allocator());
  126. }
  127. bool operator==(allocators const& a) const { return node_allocator() == a.node_allocator(); }
  128. template <typename Alloc>
  129. bool operator==(Alloc const& a) const { return node_allocator() == node_allocator_type(a); }
  130. Allocator allocator() const { return Allocator(node_allocator()); }
  131. node_allocator_type & node_allocator() { return *this; }
  132. node_allocator_type const& node_allocator() const { return *this; }
  133. };
  134. }} // namespace detail::rtree
  135. }}} // namespace boost::geometry::index
  136. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_STATIC_HPP