weak_static.hpp 6.1 KB

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