9
3

copy.hpp 3.6 KB

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