From 80bfe0ae0167ca887ddcae7bb1d4e77146197894 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sun, 30 Sep 2012 12:54:25 +0000 Subject: [PATCH] code related to nodes visitation moved to XXX_visitor.hpp [SVN r80782] --- .../index/rtree/node/dynamic_visitor.hpp | 24 +++++ .../extensions/index/rtree/node/node.hpp | 4 +- .../index/rtree/node/node_d_mem_dynamic.hpp | 22 ----- .../index/rtree/node/node_s_mem_dynamic.hpp | 87 +++++-------------- .../index/rtree/node/node_s_mem_static.hpp | 29 ++++--- .../index/rtree/node/static_visitor.hpp | 76 ++++++++++++++++ 6 files changed, 139 insertions(+), 103 deletions(-) create mode 100644 include/boost/geometry/extensions/index/rtree/node/static_visitor.hpp diff --git a/include/boost/geometry/extensions/index/rtree/node/dynamic_visitor.hpp b/include/boost/geometry/extensions/index/rtree/node/dynamic_visitor.hpp index 0514bc907..7058057e4 100644 --- a/include/boost/geometry/extensions/index/rtree/node/dynamic_visitor.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/dynamic_visitor.hpp @@ -63,6 +63,30 @@ struct dynamic_visitor virtual void operator()(leaf &) = 0; }; +// nodes conversion + +template +inline Derived & get(dynamic_node & n) +{ + assert(dynamic_cast(&n)); + return static_cast(n); +} + +template +inline Derived * get(dynamic_node * n) +{ + assert(dynamic_cast(n)); + return static_cast(n); +} + +// apply visitor + +template +inline void apply_visitor(Visitor &v, Visitable & n) +{ + n.apply_visitor(v); +} + }} // namespace detail::rtree }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/extensions/index/rtree/node/node.hpp b/include/boost/geometry/extensions/index/rtree/node/node.hpp index bc4071d07..d3ce1aca3 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node.hpp @@ -14,9 +14,9 @@ #include #include -#include - #include + +#include #include #include diff --git a/include/boost/geometry/extensions/index/rtree/node/node_d_mem_dynamic.hpp b/include/boost/geometry/extensions/index/rtree/node/node_d_mem_dynamic.hpp index 54790364c..4f530a555 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_d_mem_dynamic.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_d_mem_dynamic.hpp @@ -77,22 +77,6 @@ struct leaf typedef dynamic_leaf type; }; -// nodes conversion - -template -inline Derived & get(dynamic_node & n) -{ - assert(dynamic_cast(&n)); - return static_cast(n); -} - -template -inline Derived * get(dynamic_node * n) -{ - assert(dynamic_cast(n)); - return static_cast(n); -} - // visitor traits template @@ -101,12 +85,6 @@ struct visitor type; }; -template -inline void apply_visitor(Visitor &v, Visitable & n) -{ - n.apply_visitor(v); -} - // element's indexable type template diff --git a/include/boost/geometry/extensions/index/rtree/node/node_s_mem_dynamic.hpp b/include/boost/geometry/extensions/index/rtree/node/node_s_mem_dynamic.hpp index 7ba08aabc..4b492c072 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_s_mem_dynamic.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_s_mem_dynamic.hpp @@ -12,7 +12,8 @@ #define BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_NODE_DEFAULT_VARIANT_HPP #include -#include + +#include namespace boost { namespace geometry { namespace index { @@ -21,7 +22,7 @@ namespace detail { namespace rtree { // nodes default types template -struct internal_node_variant +struct static_internal_node { typedef std::vector< std::pair< @@ -31,7 +32,7 @@ struct internal_node_variant typename Allocators::internal_node_elements_allocator_type > elements_type; - inline internal_node_variant(typename Allocators::internal_node_elements_allocator_type & al) + inline static_internal_node(typename Allocators::internal_node_elements_allocator_type & al) : elements(al) {} @@ -39,14 +40,14 @@ struct internal_node_variant }; template -struct leaf_variant +struct static_leaf { typedef std::vector< Value, typename Allocators::leaf_elements_allocator_type > elements_type; - inline leaf_variant(typename Allocators::leaf_elements_allocator_type & al) + inline static_leaf(typename Allocators::leaf_elements_allocator_type & al) : elements(al) {} @@ -59,47 +60,23 @@ template { typedef boost::variant< - leaf_variant, - internal_node_variant + static_leaf, + static_internal_node > type; }; template struct internal_node { - typedef internal_node_variant type; + typedef static_internal_node type; }; template struct leaf { - typedef leaf_variant type; + typedef static_leaf type; }; -// nodes conversion - -template -inline V & get( - boost::variant< - leaf_variant, - internal_node_variant - > &v -) -{ - return boost::get(v); -} - -template -inline V * get( - boost::variant< - leaf_variant, - internal_node_variant - > *v -) -{ - return boost::get(v); -} - // visitor traits template @@ -108,26 +85,6 @@ struct visitor type; }; -template -inline void apply_visitor(Visitor & v, - boost::variant< - leaf_variant, - internal_node_variant - > & n) -{ - boost::apply_visitor(v, n); -} - -template -inline void apply_visitor(Visitor & v, - boost::variant< - leaf_variant, - internal_node_variant - > const& n) -{ - boost::apply_visitor(v, n); -} - // element's indexable type template @@ -135,8 +92,8 @@ struct element_indexable_type< std::pair< Box, boost::variant< - leaf_variant, - internal_node_variant + static_leaf, + static_internal_node > * >, Translator @@ -152,8 +109,8 @@ inline Box const& element_indexable(std::pair< Box, boost::variant< - leaf_variant, - internal_node_variant + static_leaf, + static_internal_node > * > const& el, Translator const&) @@ -239,14 +196,14 @@ struct destroy_node_variant template struct create_node< Allocators, - internal_node_variant + static_internal_node > { static inline typename node::type * apply(Allocators & allocators) { return create_node_variant< - internal_node_variant + static_internal_node >::template apply< typename node::type >(allocators.node_allocator, allocators.internal_node_elements_allocator); @@ -256,14 +213,14 @@ struct create_node< template struct create_node< Allocators, - leaf_variant + static_leaf > { static inline typename node::type * apply(Allocators & allocators) { return create_node_variant< - leaf_variant + static_leaf >::template apply< typename node::type >(allocators.node_allocator, allocators.leaf_elements_allocator); @@ -275,13 +232,13 @@ struct create_node< template struct destroy_node< Allocators, - internal_node_variant + static_internal_node > { static inline void apply(Allocators & allocators, typename node::type * n) { destroy_node_variant< - internal_node_variant + static_internal_node >::apply(allocators.node_allocator, n); } }; @@ -289,13 +246,13 @@ struct destroy_node< template struct destroy_node< Allocators, - leaf_variant + static_leaf > { static inline void apply(Allocators & allocators, typename node::type * n) { destroy_node_variant< - leaf_variant + static_leaf >::apply(allocators.node_allocator, n); } }; diff --git a/include/boost/geometry/extensions/index/rtree/node/node_s_mem_static.hpp b/include/boost/geometry/extensions/index/rtree/node/node_s_mem_static.hpp index 78e63b62e..89730b59c 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_s_mem_static.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_s_mem_static.hpp @@ -11,8 +11,9 @@ #ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_NODE_DEFAULT_STATIC_VARIANT_HPP #define BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_NODE_DEFAULT_STATIC_VARIANT_HPP -#include -#include +#include + +#include namespace boost { namespace geometry { namespace index { @@ -21,7 +22,7 @@ namespace detail { namespace rtree { // nodes default types template -struct internal_node_variant +struct static_internal_node { typedef index::pushable_array< std::pair< @@ -32,18 +33,18 @@ struct internal_node_variant elements_type; template - inline internal_node_variant(Dummy) {} + inline static_internal_node(Dummy) {} elements_type elements; }; template -struct leaf_variant +struct static_leaf { typedef index::pushable_array elements_type; template - inline leaf_variant(Dummy) {} + inline static_leaf(Dummy) {} elements_type elements; }; @@ -54,21 +55,21 @@ template { typedef boost::variant< - leaf_variant, - internal_node_variant + static_leaf, + static_internal_node > type; }; template struct internal_node { - typedef internal_node_variant type; + typedef static_internal_node type; }; template struct leaf { - typedef leaf_variant type; + typedef static_leaf type; }; // visitor traits @@ -113,14 +114,14 @@ struct allocators template struct create_node< Allocators, - internal_node_variant + static_internal_node > { static inline typename node::type * apply(Allocators & allocators) { return create_node_variant< - internal_node_variant + static_internal_node >::template apply< typename node::type >(allocators.node_allocator, allocators.node_allocator); @@ -130,14 +131,14 @@ struct create_node< template struct create_node< Allocators, - leaf_variant + static_leaf > { static inline typename node::type * apply(Allocators & allocators) { return create_node_variant< - leaf_variant + static_leaf >::template apply< typename node::type >(allocators.node_allocator, allocators.node_allocator); diff --git a/include/boost/geometry/extensions/index/rtree/node/static_visitor.hpp b/include/boost/geometry/extensions/index/rtree/node/static_visitor.hpp new file mode 100644 index 000000000..70524f036 --- /dev/null +++ b/include/boost/geometry/extensions/index/rtree/node/static_visitor.hpp @@ -0,0 +1,76 @@ +// Boost.Geometry Index +// +// R-tree nodes static visitor related code +// +// Copyright (c) 2011-2012 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_EXTENSIONS_INDEX_RTREE_NODE_STATIC_VISITOR_HPP +#define BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_STATIC_VISITOR_HPP + +#include + +namespace boost { namespace geometry { namespace index { + +namespace detail { namespace rtree { + +// nodes variants forward declarations + +template +struct static_internal_node; + +template +struct static_leaf; + +// nodes conversion + +template +inline V & get( + boost::variant< + static_leaf, + static_internal_node + > & v) +{ + return boost::get(v); +} + +template +inline V * get( + boost::variant< + static_leaf, + static_internal_node + > *v) +{ + return boost::get(v); +} + +// apply visitor + +template +inline void apply_visitor(Visitor & v, + boost::variant< + static_leaf, + static_internal_node + > & n) +{ + boost::apply_visitor(v, n); +} + +template +inline void apply_visitor(Visitor & v, + boost::variant< + static_leaf, + static_internal_node + > const& n) +{ + boost::apply_visitor(v, n); +} + +}} // namespace detail::rtree + +}}} // namespace boost::geometry::index + +#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_STATIC_VISITOR_HPP