copy.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Boost.Geometry Index
  2. //
  3. // R-tree deep copying visitor implementation
  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_VISITORS_COPY_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP
  16. #include <boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp>
  17. namespace boost { namespace geometry { namespace index {
  18. namespace detail { namespace rtree { namespace visitors {
  19. template <typename MembersHolder>
  20. class copy
  21. : public MembersHolder::visitor
  22. {
  23. typedef typename MembersHolder::allocators_type allocators_type;
  24. typedef typename MembersHolder::node node;
  25. typedef typename MembersHolder::internal_node internal_node;
  26. typedef typename MembersHolder::leaf leaf;
  27. typedef rtree::subtree_destroyer<MembersHolder> subtree_destroyer;
  28. typedef typename allocators_type::node_pointer node_pointer;
  29. public:
  30. explicit inline copy(allocators_type & allocators)
  31. : result(0)
  32. , m_allocators(allocators)
  33. {}
  34. inline void operator()(internal_node & n)
  35. {
  36. node_pointer raw_new_node = rtree::create_node<allocators_type, internal_node>::apply(m_allocators); // MAY THROW, STRONG (N: alloc)
  37. subtree_destroyer new_node(raw_new_node, m_allocators);
  38. typedef typename rtree::elements_type<internal_node>::type elements_type;
  39. elements_type & elements = rtree::elements(n);
  40. elements_type & elements_dst = rtree::elements(rtree::get<internal_node>(*new_node));
  41. for (typename elements_type::iterator it = elements.begin();
  42. it != elements.end(); ++it)
  43. {
  44. rtree::apply_visitor(*this, *it->second); // MAY THROW (V, E: alloc, copy, N: alloc)
  45. // for exception safety
  46. subtree_destroyer auto_result(result, m_allocators);
  47. elements_dst.push_back( rtree::make_ptr_pair(it->first, result) ); // MAY THROW, STRONG (E: alloc, copy)
  48. auto_result.release();
  49. }
  50. result = new_node.get();
  51. new_node.release();
  52. }
  53. inline void operator()(leaf & l)
  54. {
  55. node_pointer raw_new_node = rtree::create_node<allocators_type, leaf>::apply(m_allocators); // MAY THROW, STRONG (N: alloc)
  56. subtree_destroyer new_node(raw_new_node, m_allocators);
  57. typedef typename rtree::elements_type<leaf>::type elements_type;
  58. elements_type & elements = rtree::elements(l);
  59. elements_type & elements_dst = rtree::elements(rtree::get<leaf>(*new_node));
  60. for (typename elements_type::iterator it = elements.begin();
  61. it != elements.end(); ++it)
  62. {
  63. elements_dst.push_back(*it); // MAY THROW, STRONG (V: alloc, copy)
  64. }
  65. result = new_node.get();
  66. new_node.release();
  67. }
  68. node_pointer result;
  69. private:
  70. allocators_type & m_allocators;
  71. };
  72. }}} // namespace detail::rtree::visitors
  73. }}} // namespace boost::geometry::index
  74. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP