9
3

destroy.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_DELETE_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_DELETE_HPP
  12. namespace boost { namespace geometry { namespace index {
  13. namespace detail { namespace rtree { namespace visitors {
  14. template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
  15. class destroy
  16. : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, false>::type
  17. {
  18. public:
  19. typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
  20. typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
  21. typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
  22. typedef typename Allocators::node_pointer node_pointer;
  23. inline destroy(node_pointer root_node, Allocators & allocators)
  24. : m_current_node(root_node)
  25. , m_allocators(allocators)
  26. {}
  27. inline void operator()(internal_node & n)
  28. {
  29. BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get<internal_node>(*m_current_node), "invalid pointers");
  30. node_pointer node_to_destroy = m_current_node;
  31. typedef typename rtree::elements_type<internal_node>::type elements_type;
  32. elements_type & elements = rtree::elements(n);
  33. for (typename elements_type::iterator it = elements.begin();
  34. it != elements.end(); ++it)
  35. {
  36. m_current_node = it->second;
  37. rtree::apply_visitor(*this, *m_current_node);
  38. it->second = 0;
  39. }
  40. rtree::destroy_node<Allocators, internal_node>::apply(m_allocators, node_to_destroy);
  41. }
  42. inline void operator()(leaf & l)
  43. {
  44. boost::ignore_unused(l);
  45. BOOST_GEOMETRY_INDEX_ASSERT(&l == &rtree::get<leaf>(*m_current_node), "invalid pointers");
  46. rtree::destroy_node<Allocators, leaf>::apply(m_allocators, m_current_node);
  47. }
  48. private:
  49. node_pointer m_current_node;
  50. Allocators & m_allocators;
  51. };
  52. }}} // namespace detail::rtree::visitors
  53. }}} // namespace boost::geometry::index
  54. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_DELETE_HPP