subtree_destroyer.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SUBTREE_DESTROYED_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SUBTREE_DESTROYED_HPP
  12. #include <boost/geometry/index/detail/rtree/visitors/destroy.hpp>
  13. namespace boost { namespace geometry { namespace index {
  14. namespace detail { namespace rtree {
  15. template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
  16. class subtree_destroyer
  17. {
  18. typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
  19. typedef typename Allocators::node_pointer pointer;
  20. subtree_destroyer(subtree_destroyer const&);
  21. subtree_destroyer & operator=(subtree_destroyer const&);
  22. public:
  23. subtree_destroyer(pointer ptr, Allocators & allocators)
  24. : m_ptr(ptr)
  25. , m_allocators(allocators)
  26. {}
  27. ~subtree_destroyer()
  28. {
  29. reset();
  30. }
  31. void reset(pointer ptr = 0)
  32. {
  33. if ( m_ptr && m_ptr != ptr )
  34. {
  35. detail::rtree::visitors::destroy<Value, Options, Translator, Box, Allocators> del_v(m_ptr, m_allocators);
  36. detail::rtree::apply_visitor(del_v, *m_ptr);
  37. }
  38. m_ptr = ptr;
  39. }
  40. void release()
  41. {
  42. m_ptr = 0;
  43. }
  44. pointer get() const
  45. {
  46. return m_ptr;
  47. }
  48. node & operator*() const
  49. {
  50. return *m_ptr;
  51. }
  52. pointer operator->() const
  53. {
  54. return m_ptr;
  55. }
  56. private:
  57. pointer m_ptr;
  58. Allocators & m_allocators;
  59. };
  60. }} // namespace detail::rtree
  61. }}} // namespace boost::geometry::index
  62. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SUBTREE_DESTROYED_HPP