]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/index/detail/rtree/node/variant_dynamic.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / index / detail / rtree / node / variant_dynamic.hpp
1 // Boost.Geometry Index
2 //
3 // R-tree nodes based on Boost.Variant, storing dynamic-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_DYNAMIC_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_DYNAMIC_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, typename Tag>
21 struct variant_internal_node
22 {
23 typedef boost::container::vector
24 <
25 rtree::ptr_pair<Box, typename Allocators::node_pointer>,
26 typename Allocators::node_allocator_type::template rebind
27 <
28 rtree::ptr_pair<Box, typename Allocators::node_pointer>
29 >::other
30 > elements_type;
31
32 template <typename Al>
33 inline variant_internal_node(Al const& al)
34 : elements(al)
35 {}
36
37 elements_type elements;
38 };
39
40 template <typename Value, typename Parameters, typename Box, typename Allocators, typename Tag>
41 struct variant_leaf
42 {
43 typedef boost::container::vector
44 <
45 Value,
46 typename Allocators::node_allocator_type::template rebind
47 <
48 Value
49 >::other
50 > elements_type;
51
52 template <typename Al>
53 inline variant_leaf(Al const& al)
54 : elements(al)
55 {}
56
57 elements_type elements;
58 };
59
60 // nodes traits
61
62 template <typename Value, typename Parameters, typename Box, typename Allocators>
63 struct node<Value, Parameters, Box, Allocators, node_variant_dynamic_tag>
64 {
65 typedef boost::variant<
66 variant_leaf<Value, Parameters, Box, Allocators, node_variant_dynamic_tag>,
67 variant_internal_node<Value, Parameters, Box, Allocators, node_variant_dynamic_tag>
68 > type;
69 };
70
71 template <typename Value, typename Parameters, typename Box, typename Allocators>
72 struct internal_node<Value, Parameters, Box, Allocators, node_variant_dynamic_tag>
73 {
74 typedef variant_internal_node<Value, Parameters, Box, Allocators, node_variant_dynamic_tag> type;
75 };
76
77 template <typename Value, typename Parameters, typename Box, typename Allocators>
78 struct leaf<Value, Parameters, Box, Allocators, node_variant_dynamic_tag>
79 {
80 typedef variant_leaf<Value, Parameters, Box, Allocators, node_variant_dynamic_tag> type;
81 };
82
83 // visitor traits
84
85 template <typename Value, typename Parameters, typename Box, typename Allocators, bool IsVisitableConst>
86 struct visitor<Value, Parameters, Box, Allocators, node_variant_dynamic_tag, IsVisitableConst>
87 {
88 typedef static_visitor<> type;
89 };
90
91 // allocators
92
93 template <typename Allocator, typename Value, typename Parameters, typename Box>
94 class allocators<Allocator, Value, Parameters, Box, node_variant_dynamic_tag>
95 : public Allocator::template rebind<
96 typename node<
97 Value, Parameters, Box,
98 allocators<Allocator, Value, Parameters, Box, node_variant_dynamic_tag>,
99 node_variant_dynamic_tag
100 >::type
101 >::other
102 {
103 typedef typename Allocator::template rebind<
104 Value
105 >::other value_allocator_type;
106
107 public:
108 typedef Allocator allocator_type;
109
110 typedef Value value_type;
111 typedef typename value_allocator_type::reference reference;
112 typedef typename value_allocator_type::const_reference const_reference;
113 typedef typename value_allocator_type::size_type size_type;
114 typedef typename value_allocator_type::difference_type difference_type;
115 typedef typename value_allocator_type::pointer pointer;
116 typedef typename value_allocator_type::const_pointer const_pointer;
117
118 typedef typename Allocator::template rebind<
119 typename node<Value, Parameters, Box, allocators, node_variant_dynamic_tag>::type
120 >::other::pointer node_pointer;
121
122 typedef typename Allocator::template rebind<
123 typename node<Value, Parameters, Box, allocators, node_variant_dynamic_tag>::type
124 >::other node_allocator_type;
125
126 inline allocators()
127 : node_allocator_type()
128 {}
129
130 template <typename Alloc>
131 inline explicit allocators(Alloc const& alloc)
132 : node_allocator_type(alloc)
133 {}
134
135 inline allocators(BOOST_FWD_REF(allocators) a)
136 : node_allocator_type(boost::move(a.node_allocator()))
137 {}
138
139 inline allocators & operator=(BOOST_FWD_REF(allocators) a)
140 {
141 node_allocator() = boost::move(a.node_allocator());
142 return *this;
143 }
144
145 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
146 inline allocators & operator=(allocators const& a)
147 {
148 node_allocator() = a.node_allocator();
149 return *this;
150 }
151 #endif
152
153 void swap(allocators & a)
154 {
155 boost::swap(node_allocator(), a.node_allocator());
156 }
157
158 bool operator==(allocators const& a) const { return node_allocator() == a.node_allocator(); }
159 template <typename Alloc>
160 bool operator==(Alloc const& a) const { return node_allocator() == node_allocator_type(a); }
161
162 Allocator allocator() const { return Allocator(node_allocator()); }
163
164 node_allocator_type & node_allocator() { return *this; }
165 node_allocator_type const& node_allocator() const { return *this; }
166 };
167
168 // create_node_variant
169
170 template <typename VariantPtr, typename Node>
171 struct create_variant_node
172 {
173 template <typename AllocNode>
174 static inline VariantPtr apply(AllocNode & alloc_node)
175 {
176 typedef boost::container::allocator_traits<AllocNode> Al;
177 typedef typename Al::pointer P;
178
179 P p = Al::allocate(alloc_node, 1);
180
181 if ( 0 == p )
182 throw_runtime_error("boost::geometry::index::rtree node creation failed");
183
184 scoped_deallocator<AllocNode> deallocator(p, alloc_node);
185
186 Al::construct(alloc_node, boost::addressof(*p), Node(alloc_node)); // implicit cast to Variant
187
188 deallocator.release();
189 return p;
190 }
191 };
192
193 // destroy_node_variant
194
195 template <typename Node>
196 struct destroy_variant_node
197 {
198 template <typename AllocNode, typename VariantPtr>
199 static inline void apply(AllocNode & alloc_node, VariantPtr n)
200 {
201 typedef boost::container::allocator_traits<AllocNode> Al;
202
203 Al::destroy(alloc_node, boost::addressof(*n));
204 Al::deallocate(alloc_node, n, 1);
205 }
206 };
207
208 // create_node
209
210 template <typename Allocators, typename Value, typename Parameters, typename Box, typename Tag>
211 struct create_node<
212 Allocators,
213 variant_internal_node<Value, Parameters, Box, Allocators, Tag>
214 >
215 {
216 static inline typename Allocators::node_pointer
217 apply(Allocators & allocators)
218 {
219 return create_variant_node<
220 typename Allocators::node_pointer,
221 variant_internal_node<Value, Parameters, Box, Allocators, Tag>
222 >::apply(allocators.node_allocator());
223 }
224 };
225
226 template <typename Allocators, typename Value, typename Parameters, typename Box, typename Tag>
227 struct create_node<
228 Allocators,
229 variant_leaf<Value, Parameters, Box, Allocators, Tag>
230 >
231 {
232 static inline typename Allocators::node_pointer
233 apply(Allocators & allocators)
234 {
235 return create_variant_node<
236 typename Allocators::node_pointer,
237 variant_leaf<Value, Parameters, Box, Allocators, Tag>
238 >::apply(allocators.node_allocator());
239 }
240 };
241
242 // destroy_node
243
244 template <typename Allocators, typename Value, typename Parameters, typename Box, typename Tag>
245 struct destroy_node<
246 Allocators,
247 variant_internal_node<Value, Parameters, Box, Allocators, Tag>
248 >
249 {
250 static inline void apply(Allocators & allocators, typename Allocators::node_pointer n)
251 {
252 destroy_variant_node<
253 variant_internal_node<Value, Parameters, Box, Allocators, Tag>
254 >::apply(allocators.node_allocator(), n);
255 }
256 };
257
258 template <typename Allocators, typename Value, typename Parameters, typename Box, typename Tag>
259 struct destroy_node<
260 Allocators,
261 variant_leaf<Value, Parameters, Box, Allocators, Tag>
262 >
263 {
264 static inline void apply(Allocators & allocators, typename Allocators::node_pointer n)
265 {
266 destroy_variant_node<
267 variant_leaf<Value, Parameters, Box, Allocators, Tag>
268 >::apply(allocators.node_allocator(), n);
269 }
270 };
271
272 }} // namespace detail::rtree
273
274 }}} // namespace boost::geometry::index
275
276 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_DYNAMIC_HPP