1 // Boost.Geometry Index
3 // R-tree nodes based on Boost.Variant, storing static-size containers
5 // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
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)
11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_STATIC_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_STATIC_HPP
14 namespace boost { namespace geometry { namespace index {
16 namespace detail { namespace rtree {
18 // nodes default types
20 template <typename Value, typename Parameters, typename Box, typename Allocators>
21 struct variant_internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag>
23 typedef detail::varray<
24 rtree::ptr_pair<Box, typename Allocators::node_pointer>,
25 Parameters::max_elements + 1
28 template <typename Alloc>
29 inline variant_internal_node(Alloc const&) {}
31 elements_type elements;
34 template <typename Value, typename Parameters, typename Box, typename Allocators>
35 struct variant_leaf<Value, Parameters, Box, Allocators, node_variant_static_tag>
37 typedef detail::varray<
39 Parameters::max_elements + 1
42 template <typename Alloc>
43 inline variant_leaf(Alloc const&) {}
45 elements_type elements;
50 template <typename Value, typename Parameters, typename Box, typename Allocators>
51 struct node<Value, Parameters, Box, Allocators, node_variant_static_tag>
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>
59 template <typename Value, typename Parameters, typename Box, typename Allocators>
60 struct internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag>
62 typedef variant_internal_node<Value, Parameters, Box, Allocators, node_variant_static_tag> type;
65 template <typename Value, typename Parameters, typename Box, typename Allocators>
66 struct leaf<Value, Parameters, Box, Allocators, node_variant_static_tag>
68 typedef variant_leaf<Value, Parameters, Box, Allocators, node_variant_static_tag> type;
73 template <typename Value, typename Parameters, typename Box, typename Allocators, bool IsVisitableConst>
74 struct visitor<Value, Parameters, Box, Allocators, node_variant_static_tag, IsVisitableConst>
76 typedef static_visitor<> type;
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<
85 Value, Parameters, Box,
86 allocators<Allocator, Value, Parameters, Box, node_variant_static_tag>,
87 node_variant_static_tag
91 typedef typename Allocator::template rebind<
93 >::other value_allocator_type;
96 typedef Allocator allocator_type;
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;
106 typedef typename Allocator::template rebind<
107 typename node<Value, Parameters, Box, allocators, node_variant_static_tag>::type
108 >::other::pointer node_pointer;
110 typedef typename Allocator::template rebind<
111 typename node<Value, Parameters, Box, allocators, node_variant_static_tag>::type
112 >::other node_allocator_type;
115 : node_allocator_type()
118 template <typename Alloc>
119 inline explicit allocators(Alloc const& alloc)
120 : node_allocator_type(alloc)
123 inline allocators(BOOST_FWD_REF(allocators) a)
124 : node_allocator_type(boost::move(a.node_allocator()))
127 inline allocators & operator=(BOOST_FWD_REF(allocators) a)
129 node_allocator() = boost::move(a.node_allocator());
133 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
134 inline allocators & operator=(allocators const& a)
136 node_allocator() = a.node_allocator();
141 void swap(allocators & a)
143 boost::swap(node_allocator(), a.node_allocator());
146 bool operator==(allocators const& a) const { return node_allocator() == a.node_allocator(); }
147 template <typename Alloc>
148 bool operator==(Alloc const& a) const { return node_allocator() == node_allocator_type(a); }
150 Allocator allocator() const { return Allocator(node_allocator()); }
152 node_allocator_type & node_allocator() { return *this; }
153 node_allocator_type const& node_allocator() const { return *this; }
156 }} // namespace detail::rtree
158 }}} // namespace boost::geometry::index
160 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_STATIC_HPP