variant_static.hpp 5.1 KB

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