subtree_destroyer.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Boost.Geometry Index
  2. //
  3. // R-tree subtree scoped destroyer
  4. //
  5. // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2019.
  8. // Modifications copyright (c) 2019 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. //
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SUBTREE_DESTROYED_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SUBTREE_DESTROYED_HPP
  16. #include <boost/geometry/index/detail/rtree/visitors/destroy.hpp>
  17. namespace boost { namespace geometry { namespace index {
  18. namespace detail { namespace rtree {
  19. template <typename MembersHolder>
  20. class subtree_destroyer
  21. {
  22. typedef typename MembersHolder::node node;
  23. typedef typename MembersHolder::allocators_type allocators_type;
  24. typedef typename MembersHolder::node_pointer pointer;
  25. subtree_destroyer(subtree_destroyer const&);
  26. subtree_destroyer & operator=(subtree_destroyer const&);
  27. public:
  28. subtree_destroyer(pointer ptr, allocators_type & allocators)
  29. : m_ptr(ptr)
  30. , m_allocators(allocators)
  31. {}
  32. ~subtree_destroyer()
  33. {
  34. reset();
  35. }
  36. void reset(pointer ptr = 0)
  37. {
  38. if ( m_ptr && m_ptr != ptr )
  39. {
  40. detail::rtree::visitors::destroy<MembersHolder>::apply(m_ptr, m_allocators);
  41. }
  42. m_ptr = ptr;
  43. }
  44. void release()
  45. {
  46. m_ptr = 0;
  47. }
  48. pointer get() const
  49. {
  50. return m_ptr;
  51. }
  52. node & operator*() const
  53. {
  54. return *m_ptr;
  55. }
  56. pointer operator->() const
  57. {
  58. return m_ptr;
  59. }
  60. private:
  61. pointer m_ptr;
  62. allocators_type & m_allocators;
  63. };
  64. }} // namespace detail::rtree
  65. }}} // namespace boost::geometry::index
  66. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SUBTREE_DESTROYED_HPP