~ai.tron/armagetronad/0.4-winlibs-updated

« back to all changes in this revision

Viewing changes to boost/includes/boost/geometry/index/detail/rtree/node/node_s_mem_dynamic.hpp

  • Committer: Nik K.
  • Date: 2013-11-07 16:58:35 UTC
  • Revision ID: nik.karbaum@gmail.com-20131107165835-kq99jz23drfj4dkh
Forgot to add some files; here they are

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Boost.Geometry Index
 
2
//
 
3
// R-tree nodes based on Boost.Variant, storing std::vectors
 
4
//
 
5
// Copyright (c) 2011-2013 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_NODE_DEFAULT_VARIANT_HPP
 
12
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_VARIANT_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 static_internal_node
 
22
{
 
23
    typedef typename Allocators::node_allocator_type::template rebind<
 
24
        rtree::ptr_pair<Box, typename Allocators::node_pointer>
 
25
    >::other elements_allocator_type;
 
26
 
 
27
    typedef boost::container::vector<
 
28
        rtree::ptr_pair<Box, typename Allocators::node_pointer>,
 
29
        elements_allocator_type
 
30
    > elements_type;
 
31
 
 
32
    template <typename Al>
 
33
    inline static_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 static_leaf
 
42
{
 
43
    typedef typename Allocators::node_allocator_type::template rebind<
 
44
        Value
 
45
    >::other elements_allocator_type;
 
46
 
 
47
    typedef boost::container::vector<
 
48
        Value,
 
49
        elements_allocator_type
 
50
    > elements_type;
 
51
 
 
52
     template <typename Al>
 
53
    inline static_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_s_mem_dynamic_tag>
 
64
{
 
65
    typedef boost::variant<
 
66
        static_leaf<Value, Parameters, Box, Allocators, node_s_mem_dynamic_tag>,
 
67
        static_internal_node<Value, Parameters, Box, Allocators, node_s_mem_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_s_mem_dynamic_tag>
 
73
{
 
74
    typedef static_internal_node<Value, Parameters, Box, Allocators, node_s_mem_dynamic_tag> type;
 
75
};
 
76
 
 
77
template <typename Value, typename Parameters, typename Box, typename Allocators>
 
78
struct leaf<Value, Parameters, Box, Allocators, node_s_mem_dynamic_tag>
 
79
{
 
80
    typedef static_leaf<Value, Parameters, Box, Allocators, node_s_mem_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_s_mem_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_s_mem_dynamic_tag>
 
95
    : public Allocator::template rebind<
 
96
        typename node<Value, Parameters, Box, allocators<Allocator, Value, Parameters, Box, node_s_mem_dynamic_tag>, node_s_mem_dynamic_tag>::type
 
97
    >::other
 
98
{
 
99
    typedef typename Allocator::template rebind<
 
100
        Value
 
101
    >::other value_allocator_type;
 
102
 
 
103
public:
 
104
    typedef Allocator allocator_type;
 
105
 
 
106
    typedef Value value_type;
 
107
    typedef typename value_allocator_type::reference reference;
 
108
    typedef typename value_allocator_type::const_reference const_reference;
 
109
    typedef typename value_allocator_type::size_type size_type;
 
110
    typedef typename value_allocator_type::difference_type difference_type;
 
111
    typedef typename value_allocator_type::pointer pointer;
 
112
    typedef typename value_allocator_type::const_pointer const_pointer;
 
113
 
 
114
    typedef typename Allocator::template rebind<
 
115
        typename node<Value, Parameters, Box, allocators, node_s_mem_dynamic_tag>::type
 
116
    >::other::pointer node_pointer;
 
117
 
 
118
    typedef typename Allocator::template rebind<
 
119
        typename internal_node<Value, Parameters, Box, allocators, node_s_mem_dynamic_tag>::type
 
120
    >::other::pointer internal_node_pointer;
 
121
 
 
122
    typedef typename Allocator::template rebind<
 
123
        typename node<Value, Parameters, Box, allocators, node_s_mem_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_static_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
        auto_deallocator<AllocNode> deallocator(alloc_node, p);
 
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_static_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
    static_internal_node<Value, Parameters, Box, Allocators, Tag>
 
214
>
 
215
{
 
216
    static inline typename Allocators::node_pointer
 
217
    apply(Allocators & allocators)
 
218
    {
 
219
        return create_static_node<
 
220
            typename Allocators::node_pointer,
 
221
            static_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
    static_leaf<Value, Parameters, Box, Allocators, Tag>
 
230
>
 
231
{
 
232
    static inline typename Allocators::node_pointer
 
233
    apply(Allocators & allocators)
 
234
    {
 
235
        return create_static_node<
 
236
            typename Allocators::node_pointer,
 
237
            static_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
    static_internal_node<Value, Parameters, Box, Allocators, Tag>
 
248
>
 
249
{
 
250
    static inline void apply(Allocators & allocators, typename Allocators::node_pointer n)
 
251
    {
 
252
        destroy_static_node<
 
253
            static_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
    static_leaf<Value, Parameters, Box, Allocators, Tag>
 
262
>
 
263
{
 
264
    static inline void apply(Allocators & allocators, typename Allocators::node_pointer n)
 
265
    {
 
266
        destroy_static_node<
 
267
            static_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_NODE_DEFAULT_VARIANT_HPP