// Boost.Geometry Index // // R-tree nodes based on static conversion, storing dynamic-size containers // // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland. // // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_DYNAMIC_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_DYNAMIC_HPP namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { template struct weak_internal_node : public weak_node { typedef boost::container::vector < rtree::ptr_pair, typename Allocators::internal_node_allocator_type::template rebind < rtree::ptr_pair >::other > elements_type; template inline weak_internal_node(Al const& al) : elements(al) {} elements_type elements; }; template struct weak_leaf : public weak_node { typedef boost::container::vector < Value, typename Allocators::leaf_allocator_type::template rebind < Value >::other > elements_type; template inline weak_leaf(Al const& al) : elements(al) {} elements_type elements; }; // nodes traits template struct node { typedef weak_node type; }; template struct internal_node { typedef weak_internal_node type; }; template struct leaf { typedef weak_leaf type; }; // visitor traits template struct visitor { typedef weak_visitor type; }; // allocators template class allocators : public Allocator::template rebind< typename internal_node< Value, Parameters, Box, allocators, node_weak_dynamic_tag >::type >::other , public Allocator::template rebind< typename leaf< Value, Parameters, Box, allocators, node_weak_dynamic_tag >::type >::other { typedef typename Allocator::template rebind< Value >::other value_allocator_type; public: typedef Allocator allocator_type; typedef Value value_type; typedef typename value_allocator_type::reference reference; typedef typename value_allocator_type::const_reference const_reference; typedef typename value_allocator_type::size_type size_type; typedef typename value_allocator_type::difference_type difference_type; typedef typename value_allocator_type::pointer pointer; typedef typename value_allocator_type::const_pointer const_pointer; typedef typename Allocator::template rebind< typename node::type >::other::pointer node_pointer; typedef typename Allocator::template rebind< typename internal_node::type >::other internal_node_allocator_type; typedef typename Allocator::template rebind< typename leaf::type >::other leaf_allocator_type; inline allocators() : internal_node_allocator_type() , leaf_allocator_type() {} template inline explicit allocators(Alloc const& alloc) : internal_node_allocator_type(alloc) , leaf_allocator_type(alloc) {} inline allocators(BOOST_FWD_REF(allocators) a) : internal_node_allocator_type(boost::move(a.internal_node_allocator())) , leaf_allocator_type(boost::move(a.leaf_allocator())) {} inline allocators & operator=(BOOST_FWD_REF(allocators) a) { internal_node_allocator() = ::boost::move(a.internal_node_allocator()); leaf_allocator() = ::boost::move(a.leaf_allocator()); return *this; } #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES inline allocators & operator=(allocators const& a) { internal_node_allocator() = a.internal_node_allocator(); leaf_allocator() = a.leaf_allocator(); return *this; } #endif void swap(allocators & a) { boost::swap(internal_node_allocator(), a.internal_node_allocator()); boost::swap(leaf_allocator(), a.leaf_allocator()); } bool operator==(allocators const& a) const { return leaf_allocator() == a.leaf_allocator(); } template bool operator==(Alloc const& a) const { return leaf_allocator() == leaf_allocator_type(a); } Allocator allocator() const { return Allocator(leaf_allocator()); } internal_node_allocator_type & internal_node_allocator() { return *this; } internal_node_allocator_type const& internal_node_allocator() const { return *this; } leaf_allocator_type & leaf_allocator() { return *this; } leaf_allocator_type const& leaf_allocator() const { return *this; } }; // create_node_impl template struct create_weak_node { template static inline BaseNodePtr apply(AllocNode & alloc_node) { typedef boost::container::allocator_traits Al; typedef typename Al::pointer P; P p = Al::allocate(alloc_node, 1); if ( 0 == p ) throw_runtime_error("boost::geometry::index::rtree node creation failed"); auto_deallocator deallocator(alloc_node, p); Al::construct(alloc_node, boost::addressof(*p), alloc_node); deallocator.release(); return p; } }; // destroy_node_impl template struct destroy_weak_node { template static inline void apply(AllocNode & alloc_node, BaseNodePtr n) { typedef boost::container::allocator_traits Al; typedef typename Al::pointer P; P p(&static_cast(rtree::get(*n))); Al::destroy(alloc_node, boost::addressof(*p)); Al::deallocate(alloc_node, p, 1); } }; // create_node template struct create_node< Allocators, weak_internal_node > { static inline typename Allocators::node_pointer apply(Allocators & allocators) { return create_weak_node< typename Allocators::node_pointer, weak_internal_node >::apply(allocators.internal_node_allocator()); } }; template struct create_node< Allocators, weak_leaf > { static inline typename Allocators::node_pointer apply(Allocators & allocators) { return create_weak_node< typename Allocators::node_pointer, weak_leaf >::apply(allocators.leaf_allocator()); } }; // destroy_node template struct destroy_node< Allocators, weak_internal_node > { static inline void apply(Allocators & allocators, typename Allocators::node_pointer n) { destroy_weak_node< weak_internal_node >::apply(allocators.internal_node_allocator(), n); } }; template struct destroy_node< Allocators, weak_leaf > { static inline void apply(Allocators & allocators, typename Allocators::node_pointer n) { destroy_weak_node< weak_leaf >::apply(allocators.leaf_allocator(), n); } }; }} // namespace detail::rtree }}} // namespace boost::geometry::index #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_WEAK_DYNAMIC_HPP