123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_HPP
- #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_HPP
- #include <type_traits>
- #include <boost/container/vector.hpp>
- #include <boost/geometry/core/static_assert.hpp>
- #include <boost/geometry/index/detail/varray.hpp>
- #include <boost/geometry/index/detail/rtree/node/concept.hpp>
- #include <boost/geometry/index/detail/rtree/node/pairs.hpp>
- #include <boost/geometry/index/detail/rtree/node/node_elements.hpp>
- #include <boost/geometry/index/detail/rtree/node/scoped_deallocator.hpp>
- #include <boost/geometry/index/detail/rtree/node/variant_visitor.hpp>
- #include <boost/geometry/index/detail/rtree/node/variant_dynamic.hpp>
- #include <boost/geometry/index/detail/rtree/node/variant_static.hpp>
- #include <boost/geometry/algorithms/expand.hpp>
- #include <boost/geometry/index/detail/rtree/visitors/destroy.hpp>
- #include <boost/geometry/index/detail/rtree/visitors/is_leaf.hpp>
- #include <boost/geometry/index/detail/algorithms/bounds.hpp>
- #include <boost/geometry/index/detail/is_bounding_geometry.hpp>
- namespace boost { namespace geometry { namespace index {
- namespace detail { namespace rtree {
- template <typename Box, typename FwdIter, typename Translator, typename Strategy>
- inline Box elements_box(FwdIter first, FwdIter last, Translator const& tr,
- Strategy const& strategy)
- {
- Box result;
-
-
- geometry::assign_inverse(result);
-
-
-
- if ( first == last )
- return result;
- detail::bounds(element_indexable(*first, tr), result, strategy);
- ++first;
- for ( ; first != last ; ++first )
- detail::expand(result, element_indexable(*first, tr), strategy);
- return result;
- }
- template <typename Box, typename FwdIter, typename Translator, typename Strategy>
- inline Box values_box(FwdIter first, FwdIter last, Translator const& tr,
- Strategy const& strategy)
- {
- typedef typename std::iterator_traits<FwdIter>::value_type element_type;
- BOOST_GEOMETRY_STATIC_ASSERT((is_leaf_element<element_type>::value),
- "This function should be called only for elements of leaf nodes.",
- element_type);
- Box result = elements_box<Box>(first, last, tr, strategy);
- #ifdef BOOST_GEOMETRY_INDEX_EXPERIMENTAL_ENLARGE_BY_EPSILON
- if (BOOST_GEOMETRY_CONDITION((
- ! is_bounding_geometry
- <
- typename indexable_type<Translator>::type
- >::value)))
- {
- geometry::detail::expand_by_epsilon(result);
- }
- #endif
- return result;
- }
- template <typename MembersHolder>
- struct destroy_element
- {
- typedef typename MembersHolder::parameters_type parameters_type;
- typedef typename MembersHolder::allocators_type allocators_type;
- typedef typename MembersHolder::internal_node internal_node;
- typedef typename MembersHolder::leaf leaf;
- inline static void apply(typename internal_node::elements_type::value_type & element,
- allocators_type & allocators)
- {
- detail::rtree::visitors::destroy<MembersHolder>::apply(element.second, allocators);
- element.second = 0;
- }
- inline static void apply(typename leaf::elements_type::value_type &,
- allocators_type &)
- {}
- };
- template <typename MembersHolder>
- struct destroy_elements
- {
- typedef typename MembersHolder::value_type value_type;
- typedef typename MembersHolder::allocators_type allocators_type;
- template <typename Range>
- inline static void apply(Range & elements, allocators_type & allocators)
- {
- apply(boost::begin(elements), boost::end(elements), allocators);
- }
- template <typename It>
- inline static void apply(It first, It last, allocators_type & allocators)
- {
- typedef std::is_same
- <
- value_type, typename std::iterator_traits<It>::value_type
- > is_range_of_values;
- apply_dispatch(first, last, allocators, is_range_of_values());
- }
- private:
- template <typename It>
- inline static void apply_dispatch(It first, It last, allocators_type & allocators,
- std::false_type )
- {
- for ( ; first != last ; ++first )
- {
- detail::rtree::visitors::destroy<MembersHolder>::apply(first->second, allocators);
- first->second = 0;
- }
- }
- template <typename It>
- inline static void apply_dispatch(It , It , allocators_type & ,
- std::true_type )
- {}
- };
- template <typename Container, typename Iterator>
- void move_from_back(Container & container, Iterator it)
- {
- BOOST_GEOMETRY_INDEX_ASSERT(!container.empty(), "cannot copy from empty container");
- Iterator back_it = container.end();
- --back_it;
- if ( it != back_it )
- {
- *it = std::move(*back_it);
- }
- }
- }}
- }}}
- #endif
|