1 // Boost.Geometry Index
3 // R-tree deep copying visitor implementation
5 // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
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)
11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP
14 namespace boost { namespace geometry { namespace index {
16 namespace detail { namespace rtree { namespace visitors {
18 template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
20 : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, false>::type
23 typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
24 typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
25 typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
27 typedef rtree::subtree_destroyer<Value, Options, Translator, Box, Allocators> subtree_destroyer;
28 typedef typename Allocators::node_pointer node_pointer;
30 explicit inline copy(Allocators & allocators)
32 , m_allocators(allocators)
35 inline void operator()(internal_node & n)
37 node_pointer raw_new_node = rtree::create_node<Allocators, internal_node>::apply(m_allocators); // MAY THROW, STRONG (N: alloc)
38 subtree_destroyer new_node(raw_new_node, m_allocators);
40 typedef typename rtree::elements_type<internal_node>::type elements_type;
41 elements_type & elements = rtree::elements(n);
43 elements_type & elements_dst = rtree::elements(rtree::get<internal_node>(*new_node));
45 for (typename elements_type::iterator it = elements.begin();
46 it != elements.end(); ++it)
48 rtree::apply_visitor(*this, *it->second); // MAY THROW (V, E: alloc, copy, N: alloc)
50 // for exception safety
51 subtree_destroyer auto_result(result, m_allocators);
53 elements_dst.push_back( rtree::make_ptr_pair(it->first, result) ); // MAY THROW, STRONG (E: alloc, copy)
55 auto_result.release();
58 result = new_node.get();
62 inline void operator()(leaf & l)
64 node_pointer raw_new_node = rtree::create_node<Allocators, leaf>::apply(m_allocators); // MAY THROW, STRONG (N: alloc)
65 subtree_destroyer new_node(raw_new_node, m_allocators);
67 typedef typename rtree::elements_type<leaf>::type elements_type;
68 elements_type & elements = rtree::elements(l);
70 elements_type & elements_dst = rtree::elements(rtree::get<leaf>(*new_node));
72 for (typename elements_type::iterator it = elements.begin();
73 it != elements.end(); ++it)
75 elements_dst.push_back(*it); // MAY THROW, STRONG (V: alloc, copy)
78 result = new_node.get();
85 Allocators & m_allocators;
88 }}} // namespace detail::rtree::visitors
90 }}} // namespace boost::geometry::index
92 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP