destroy.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Boost.Geometry Index
  2. //
  3. // R-tree destroying visitor implementation
  4. //
  5. // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2019-2023.
  8. // Modifications copyright (c) 2019-2023 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  10. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  11. //
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_DELETE_HPP
  16. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_DELETE_HPP
  17. #include <boost/geometry/index/detail/rtree/node/concept.hpp>
  18. #include <boost/geometry/index/detail/rtree/node/node_elements.hpp>
  19. #include <boost/geometry/index/detail/rtree/node/weak_visitor.hpp>
  20. namespace boost { namespace geometry { namespace index {
  21. namespace detail { namespace rtree { namespace visitors {
  22. template <typename MembersHolder>
  23. class destroy
  24. : public MembersHolder::visitor
  25. {
  26. public:
  27. typedef typename MembersHolder::node node;
  28. typedef typename MembersHolder::internal_node internal_node;
  29. typedef typename MembersHolder::leaf leaf;
  30. typedef typename MembersHolder::allocators_type allocators_type;
  31. typedef typename MembersHolder::node_pointer node_pointer;
  32. inline destroy(node_pointer node, allocators_type & allocators)
  33. : m_current_node(node)
  34. , m_allocators(allocators)
  35. {}
  36. inline void operator()(internal_node & n)
  37. {
  38. BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get<internal_node>(*m_current_node), "invalid pointers");
  39. node_pointer node_to_destroy = m_current_node;
  40. typedef typename rtree::elements_type<internal_node>::type elements_type;
  41. elements_type & elements = rtree::elements(n);
  42. for (typename elements_type::iterator it = elements.begin();
  43. it != elements.end(); ++it)
  44. {
  45. m_current_node = it->second;
  46. rtree::apply_visitor(*this, *m_current_node);
  47. it->second = 0;
  48. }
  49. rtree::destroy_node<allocators_type, internal_node>::apply(m_allocators, node_to_destroy);
  50. }
  51. inline void operator()(leaf & l)
  52. {
  53. boost::ignore_unused(l);
  54. BOOST_GEOMETRY_INDEX_ASSERT(&l == &rtree::get<leaf>(*m_current_node), "invalid pointers");
  55. rtree::destroy_node<allocators_type, leaf>::apply(m_allocators, m_current_node);
  56. }
  57. static inline void apply(node_pointer node, allocators_type & allocators)
  58. {
  59. destroy v(node, allocators);
  60. rtree::apply_visitor(v, *node);
  61. }
  62. private:
  63. node_pointer m_current_node;
  64. allocators_type & m_allocators;
  65. };
  66. }}} // namespace detail::rtree::visitors
  67. }}} // namespace boost::geometry::index
  68. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_DELETE_HPP