1 // Boost.Geometry Index
2 //
3 // R-tree subtree scoped destroyer
4 //
5 // Copyright (c) 2011-2015 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_SUBTREE_DESTROYED_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SUBTREE_DESTROYED_HPP
13 
14 #include <boost/geometry/index/detail/rtree/visitors/destroy.hpp>
15 
16 namespace boost { namespace geometry { namespace index {
17 
18 namespace detail { namespace rtree {
19 
20 template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
21 class subtree_destroyer
22 {
23     typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
24     typedef typename Allocators::node_pointer pointer;
25 
26     subtree_destroyer(subtree_destroyer const&);
27     subtree_destroyer & operator=(subtree_destroyer const&);
28 
29 public:
subtree_destroyer(pointer ptr,Allocators & allocators)30     subtree_destroyer(pointer ptr, Allocators & allocators)
31         : m_ptr(ptr)
32         , m_allocators(allocators)
33     {}
34 
~subtree_destroyer()35     ~subtree_destroyer()
36     {
37         reset();
38     }
39 
reset(pointer ptr=0)40     void reset(pointer ptr = 0)
41     {
42         if ( m_ptr && m_ptr != ptr )
43         {
44             detail::rtree::visitors::destroy<Value, Options, Translator, Box, Allocators> del_v(m_ptr, m_allocators);
45             detail::rtree::apply_visitor(del_v, *m_ptr);
46         }
47         m_ptr = ptr;
48     }
49 
release()50     void release()
51     {
52         m_ptr = 0;
53     }
54 
get() const55     pointer get() const
56     {
57         return m_ptr;
58     }
59 
operator *() const60     node & operator*() const
61     {
62         return *m_ptr;
63     }
64 
operator ->() const65     pointer operator->() const
66     {
67         return m_ptr;
68     }
69 
70 private:
71     pointer m_ptr;
72     Allocators & m_allocators;
73 };
74 
75 }} // namespace detail::rtree
76 
77 }}} // namespace boost::geometry::index
78 
79 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SUBTREE_DESTROYED_HPP
80