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
11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_STATIC_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_STATIC_HPP
13
14 namespace boost { namespace geometry { namespace index {
15
16 namespace detail { namespace rtree {
17
18 template <typename Value, typename Parameters, typename Box, typename Allocators>
19 struct weak_internal_node<Value, Parameters, Box, Allocators, node_weak_static_tag>
20 : public weak_node<Value, Parameters, Box, Allocators, node_weak_static_tag>
21 {
22 typedef detail::varray<
23 rtree::ptr_pair<Box, typename Allocators::node_pointer>,
24 Parameters::max_elements + 1
25 > elements_type;
26
27 template <typename Alloc>
28 inline weak_internal_node(Alloc const&) {}
29
30 elements_type elements;
31 };
32
33 template <typename Value, typename Parameters, typename Box, typename Allocators>
RTP_check(const char * buf,const size_t len,int * is_rtp,FILE * log)34 struct weak_leaf<Value, Parameters, Box, Allocators, node_weak_static_tag>
35 : public weak_node<Value, Parameters, Box, Allocators, node_weak_static_tag>
36 {
37 typedef detail::varray<
38 Value,
39 Parameters::max_elements + 1
40 > elements_type;
41
42 template <typename Alloc>
43 inline weak_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_weak_static_tag>
52 {
53 typedef weak_node<Value, Parameters, Box, Allocators, node_weak_static_tag> type;
54 };
55
56 template <typename Value, typename Parameters, typename Box, typename Allocators>
57 struct internal_node<Value, Parameters, Box, Allocators, node_weak_static_tag>
58 {
59 typedef weak_internal_node<Value, Parameters, Box, Allocators, node_weak_static_tag> type;
60 };
61
62 template <typename Value, typename Parameters, typename Box, typename Allocators>
63 struct leaf<Value, Parameters, Box, Allocators, node_weak_static_tag>
64 {
65 typedef weak_leaf<Value, Parameters, Box, Allocators, node_weak_static_tag> type;
66 };
67
68 template <typename Value, typename Parameters, typename Box, typename Allocators, bool IsVisitableConst>
69 struct visitor<Value, Parameters, Box, Allocators, node_weak_static_tag, IsVisitableConst>
70 {
71 typedef weak_visitor<Value, Parameters, Box, Allocators, node_weak_static_tag, IsVisitableConst> type;
72 };
73
74 // allocators
75
76 template <typename Allocator, typename Value, typename Parameters, typename Box>
77 class allocators<Allocator, Value, Parameters, Box, node_weak_static_tag>
78 : public detail::rtree::internal_node_alloc<Allocator, Value, Parameters, Box, node_weak_static_tag>::type
79 , public detail::rtree::leaf_alloc<Allocator, Value, Parameters, Box, node_weak_static_tag>::type
80 {
81 typedef detail::rtree::internal_node_alloc
82 <
83 Allocator, Value, Parameters, Box, node_weak_static_tag
84 > internal_node_alloc;
85
86 typedef detail::rtree::leaf_alloc
87 <
88 Allocator, Value, Parameters, Box, node_weak_static_tag
89 > leaf_alloc;
90
91 typedef detail::rtree::node_alloc
92 <
93 Allocator, Value, Parameters, Box, node_weak_static_tag
94 > node_alloc;
95
96 public:
97 typedef typename internal_node_alloc::type internal_node_allocator_type;
RTP_verify(const char * buf,const size_t len,FILE * log)98 typedef typename leaf_alloc::type leaf_allocator_type;
99 typedef typename node_alloc::traits::pointer node_pointer;
100
101 private:
102 typedef typename boost::container::allocator_traits
103 <
104 leaf_allocator_type
105 >::template rebind_alloc<Value> value_allocator_type;
106 typedef boost::container::allocator_traits<value_allocator_type> value_allocator_traits;
107
108 public:
109 typedef Allocator allocator_type;
110
111 typedef Value value_type;
112 typedef typename value_allocator_traits::reference reference;
113 typedef typename value_allocator_traits::const_reference const_reference;
114 typedef typename value_allocator_traits::size_type size_type;
115 typedef typename value_allocator_traits::difference_type difference_type;
116 typedef typename value_allocator_traits::pointer pointer;
117 typedef typename value_allocator_traits::const_pointer const_pointer;
118
119 inline allocators()
120 : internal_node_allocator_type()
121 , leaf_allocator_type()
122 {}
123
124 template <typename Alloc>
125 inline explicit allocators(Alloc const& alloc)
126 : internal_node_allocator_type(alloc)
127 , leaf_allocator_type(alloc)
128 {}
129
130 inline allocators(BOOST_FWD_REF(allocators) a)
131 : internal_node_allocator_type(boost::move(a.internal_node_allocator()))
132 , leaf_allocator_type(boost::move(a.leaf_allocator()))
133 {}
134
135 inline allocators & operator=(BOOST_FWD_REF(allocators) a)
136 {
137 internal_node_allocator() = ::boost::move(a.internal_node_allocator());
138 leaf_allocator() = ::boost::move(a.leaf_allocator());
139 return *this;
140 }
141
142 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
RTP_hdrlen(const char * buf,const size_t len,size_t * hdrlen,FILE * log)143 inline allocators & operator=(allocators const& a)
144 {
145 internal_node_allocator() = a.internal_node_allocator();
146 leaf_allocator() = a.leaf_allocator();
147 return *this;
148 }
149 #endif
150
151 void swap(allocators & a)
152 {
153 boost::swap(internal_node_allocator(), a.internal_node_allocator());
154 boost::swap(leaf_allocator(), a.leaf_allocator());
155 }
156
157 bool operator==(allocators const& a) const { return leaf_allocator() == a.leaf_allocator(); }
158 template <typename Alloc>
159 bool operator==(Alloc const& a) const { return leaf_allocator() == leaf_allocator_type(a); }
160
161 Allocator allocator() const { return Allocator(leaf_allocator()); }
162
163 internal_node_allocator_type & internal_node_allocator() { return *this; }
164 internal_node_allocator_type const& internal_node_allocator() const { return *this; }
165 leaf_allocator_type & leaf_allocator() { return *this; }
166 leaf_allocator_type const& leaf_allocator() const{ return *this; }
167 };
168
169 }} // namespace detail::rtree
170
171 }}} // namespace boost::geometry::index
172
173 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_STATIC_HPP
174