1 // Boost.Geometry Index 2 // 3 // R-tree nodes based on Boost.Variant, storing static-size containers 4 // 5 // Copyright (c) 2011-2014 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 11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_STATIC_HPP 12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_STATIC_HPP 13 14 namespace boost { namespace geometry { namespace index { 15 16 namespace detail { namespace rtree { 17 18 // nodes default types 19 20 template <typename Value, typename Parameters, typename Box, typename Allocators> 21 struct variant_internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag> 22 { 23 typedef detail::varray< 24 rtree::ptr_pair<Box, typename Allocators::node_pointer>, 25 Parameters::max_elements + 1 26 > elements_type; 27 28 template <typename Alloc> variant_internal_nodeboost::geometry::index::detail::rtree::variant_internal_node29 inline variant_internal_node(Alloc const&) {} 30 31 elements_type elements; 32 }; 33 34 template <typename Value, typename Parameters, typename Box, typename Allocators> 35 struct variant_leaf<Value, Parameters, Box, Allocators, node_variant_static_tag> 36 { 37 typedef detail::varray< 38 Value, 39 Parameters::max_elements + 1 40 > elements_type; 41 42 template <typename Alloc> variant_leafboost::geometry::index::detail::rtree::variant_leaf43 inline variant_leaf(Alloc const&) {} 44 45 elements_type elements; 46 }; 47 48 // nodes traits 49 50 template <typename Value, typename Parameters, typename Box, typename Allocators> 51 struct node<Value, Parameters, Box, Allocators, node_variant_static_tag> 52 { 53 typedef boost::variant< 54 variant_leaf<Value, Parameters, Box, Allocators, node_variant_static_tag>, 55 variant_internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag> 56 > type; 57 }; 58 59 template <typename Value, typename Parameters, typename Box, typename Allocators> 60 struct internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag> 61 { 62 typedef variant_internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag> type; 63 }; 64 65 template <typename Value, typename Parameters, typename Box, typename Allocators> 66 struct leaf<Value, Parameters, Box, Allocators, node_variant_static_tag> 67 { 68 typedef variant_leaf<Value, Parameters, Box, Allocators, node_variant_static_tag> type; 69 }; 70 71 // visitor traits 72 73 template <typename Value, typename Parameters, typename Box, typename Allocators, bool IsVisitableConst> 74 struct visitor<Value, Parameters, Box, Allocators, node_variant_static_tag, IsVisitableConst> 75 { 76 typedef static_visitor<> type; 77 }; 78 79 // allocators 80 81 template <typename Allocator, typename Value, typename Parameters, typename Box> 82 class allocators<Allocator, Value, Parameters, Box, node_variant_static_tag> 83 : public Allocator::template rebind< 84 typename node< 85 Value, Parameters, Box, 86 allocators<Allocator, Value, Parameters, Box, node_variant_static_tag>, 87 node_variant_static_tag 88 >::type 89 >::other 90 { 91 typedef typename Allocator::template rebind< 92 Value 93 >::other value_allocator_type; 94 95 public: 96 typedef Allocator allocator_type; 97 98 typedef Value value_type; 99 typedef value_type & reference; 100 typedef const value_type & const_reference; 101 typedef typename value_allocator_type::size_type size_type; 102 typedef typename value_allocator_type::difference_type difference_type; 103 typedef typename value_allocator_type::pointer pointer; 104 typedef typename value_allocator_type::const_pointer const_pointer; 105 106 typedef typename Allocator::template rebind< 107 typename node<Value, Parameters, Box, allocators, node_variant_static_tag>::type 108 >::other::pointer node_pointer; 109 110 typedef typename Allocator::template rebind< 111 typename node<Value, Parameters, Box, allocators, node_variant_static_tag>::type 112 >::other node_allocator_type; 113 allocators()114 inline allocators() 115 : node_allocator_type() 116 {} 117 118 template <typename Alloc> allocators(Alloc const & alloc)119 inline explicit allocators(Alloc const& alloc) 120 : node_allocator_type(alloc) 121 {} 122 allocators(BOOST_FWD_REF (allocators)a)123 inline allocators(BOOST_FWD_REF(allocators) a) 124 : node_allocator_type(boost::move(a.node_allocator())) 125 {} 126 operator =(BOOST_FWD_REF (allocators)a)127 inline allocators & operator=(BOOST_FWD_REF(allocators) a) 128 { 129 node_allocator() = boost::move(a.node_allocator()); 130 return *this; 131 } 132 133 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES operator =(allocators const & a)134 inline allocators & operator=(allocators const& a) 135 { 136 node_allocator() = a.node_allocator(); 137 return *this; 138 } 139 #endif 140 swap(allocators & a)141 void swap(allocators & a) 142 { 143 boost::swap(node_allocator(), a.node_allocator()); 144 } 145 operator ==(allocators const & a) const146 bool operator==(allocators const& a) const { return node_allocator() == a.node_allocator(); } 147 template <typename Alloc> operator ==(Alloc const & a) const148 bool operator==(Alloc const& a) const { return node_allocator() == node_allocator_type(a); } 149 allocator() const150 Allocator allocator() const { return Allocator(node_allocator()); } 151 node_allocator()152 node_allocator_type & node_allocator() { return *this; } node_allocator() const153 node_allocator_type const& node_allocator() const { return *this; } 154 }; 155 156 }} // namespace detail::rtree 157 158 }}} // namespace boost::geometry::index 159 160 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_STATIC_HPP 161