1 // Boost.Geometry Index
2 //
3 // R-tree destroying visitor implementation
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_VISITORS_DELETE_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_DELETE_HPP
13 
14 namespace boost { namespace geometry { namespace index {
15 
16 namespace detail { namespace rtree { namespace visitors {
17 
18 template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
19 class destroy
20     : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, false>::type
21 {
22 public:
23     typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
24     typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
25     typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
26 
27     typedef typename Allocators::node_pointer node_pointer;
28 
destroy(node_pointer root_node,Allocators & allocators)29     inline destroy(node_pointer root_node, Allocators & allocators)
30         : m_current_node(root_node)
31         , m_allocators(allocators)
32     {}
33 
operator ()(internal_node & n)34     inline void operator()(internal_node & n)
35     {
36         BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get<internal_node>(*m_current_node), "invalid pointers");
37 
38         node_pointer node_to_destroy = m_current_node;
39 
40         typedef typename rtree::elements_type<internal_node>::type elements_type;
41         elements_type & elements = rtree::elements(n);
42 
43         for (typename elements_type::iterator it = elements.begin();
44              it != elements.end(); ++it)
45         {
46             m_current_node = it->second;
47             rtree::apply_visitor(*this, *m_current_node);
48             it->second = 0;
49         }
50 
51         rtree::destroy_node<Allocators, internal_node>::apply(m_allocators, node_to_destroy);
52     }
53 
operator ()(leaf & l)54     inline void operator()(leaf & l)
55     {
56         boost::ignore_unused(l);
57         BOOST_GEOMETRY_INDEX_ASSERT(&l == &rtree::get<leaf>(*m_current_node), "invalid pointers");
58 
59         rtree::destroy_node<Allocators, leaf>::apply(m_allocators, m_current_node);
60     }
61 
62 private:
63     node_pointer m_current_node;
64     Allocators & m_allocators;
65 };
66 
67 }}} // namespace detail::rtree::visitors
68 
69 }}} // namespace boost::geometry::index
70 
71 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_DELETE_HPP
72