diff --git a/include/boost/geometry/index/detail/indexable.hpp b/include/boost/geometry/index/detail/indexable.hpp index 6d04b90ad..f0791b170 100644 --- a/include/boost/geometry/index/detail/indexable.hpp +++ b/include/boost/geometry/index/detail/indexable.hpp @@ -15,44 +15,6 @@ namespace boost { namespace geometry { namespace index { namespace detail { namespace dispatch { -// Distinguish between indexables and other geometries - -template -struct indexable_type -{ - typedef void type; -}; - -template -struct indexable_type -{ - typedef Point type; -}; - -template -struct indexable_type -{ - typedef Box type; -}; - -} // namespace dispatch - -namespace traits -{ - -template -struct indexable_type -{ - typedef typename dispatch::indexable_type< - Indexable, - typename geometry::traits::tag::type - >::type type; -}; - -} // namespace traits - -namespace dispatch { - template struct point_type { diff --git a/include/boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp b/include/boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp index 5a39b3e87..7d7bc401e 100644 --- a/include/boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp @@ -96,7 +96,7 @@ struct visitor struct element_indexable_type { - typedef typename translator::indexable_type::type type; + typedef typename indexable_type::type type; }; template @@ -111,7 +111,7 @@ struct element_indexable_type< // element's indexable getter template -typename translator::result_type::type +typename result_type::type element_indexable(Element const& el, Translator const& tr) { return tr(el); diff --git a/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp b/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp index 0019a4d81..43a808f5d 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp @@ -68,7 +68,7 @@ struct nearest_query_result_k public: typedef typename geometry::default_distance_result< Point, - typename translator::indexable_type::type + typename indexable_type::type >::type distance_type; inline explicit nearest_query_result_k(size_t k, OutIt out_it) @@ -168,13 +168,13 @@ public: typedef index::detail::distances_calc< DistancesPredicates, - typename translator::indexable_type::type, + typename indexable_type::type, index::detail::value_tag > value_distances_calc; typedef typename value_distances_calc::result_type value_distances_type; typedef index::detail::distances_predicates_check< DistancesPredicates, - typename translator::indexable_type::type, + typename indexable_type::type, index::detail::value_tag > value_distances_predicates_check; diff --git a/include/boost/geometry/index/detail/translator.hpp b/include/boost/geometry/index/detail/translator.hpp new file mode 100644 index 000000000..f377c720a --- /dev/null +++ b/include/boost/geometry/index/detail/translator.hpp @@ -0,0 +1,60 @@ +// Boost.Geometry Index +// +// Copyright (c) 2011-2013 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_TRANSLATOR_HPP +#define BOOST_GEOMETRY_INDEX_DETAIL_TRANSLATOR_HPP + +namespace boost { namespace geometry { namespace index { + +namespace detail { + +template +struct translator + : public IndexableGetter + , public EqualTo +{ + typedef typename IndexableGetter::result_type result_type; + + translator(IndexableGetter const& i, EqualTo const& e) + : IndexableGetter(i), EqualTo(e) + {} + + template + result_type operator()(Value const& value) const + { + return IndexableGetter::operator()(value); + } + + template + bool equals(Value const& v1, Value const& v2) const + { + return EqualTo::operator()(v1, v2); + } +}; + +template +struct result_type +{ + typedef typename IndexableGetter::result_type type; +}; + +template +struct indexable_type +{ + typedef typename boost::remove_const< + typename boost::remove_reference< + typename result_type::type + >::type + >::type type; +}; + +} // namespace detail + +}}} // namespace boost::geometry::index + +#endif // BOOST_GEOMETRY_INDEX_DETAIL_TRANSLATOR_HPP diff --git a/include/boost/geometry/index/equal_to.hpp b/include/boost/geometry/index/equal_to.hpp new file mode 100644 index 000000000..cf29b5d94 --- /dev/null +++ b/include/boost/geometry/index/equal_to.hpp @@ -0,0 +1,126 @@ +// Boost.Geometry Index +// +// Copyright (c) 2011-2013 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_EQUAL_TO_HPP +#define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP + +#include + +namespace boost { namespace geometry { namespace index { + +namespace detail { + +template +struct equals +{ + static bool apply(Geometry const& g1, Geometry const& g2) + { + return geometry::equals(g1, g2); + } +}; + +template +struct equals +{ + static bool apply(T const& v1, T const& v2) + { + return v1 == v2; + } +}; + +template +struct tuple_equals +{ + inline static bool apply(Tuple const& t1, Tuple const& t2) + { + typedef typename boost::tuples::element::type T; + return + equals< + T, typename geometry::traits::tag::type + >::apply(boost::get(t1), boost::get(t2)) + && + tuple_equals::apply(t1, t2); + } +}; + +template +struct tuple_equals +{ + inline static bool apply(Tuple const&, Tuple const&) + { + return true; + } +}; + +} // namespace detail + +/*! +\brief The function object comparing Values. + +It compares Geometries using geometry::equals() function. Other types are compared using operator==. +The default version handles Values which are Indexables. +This template is also specialized for std::pair and boost::tuple<...>. + +\tparam Value The type of objects which are compared by this function object. +*/ +template +struct equal_to +{ + typedef bool result_type; + bool operator()(Value const& l, Value const& r) const + { + return detail::equals::type>::apply(l ,r); + } +}; + +/*! +\brief The function object comparing Values. + +This specialization compares values of type std::pair. +It compares pairs' first values, then second values. + +\tparam T1 The first type. +\tparam T2 The second type. +*/ +template +struct equal_to< std::pair > +{ + typedef bool result_type; + bool operator()(std::pair const& l, std::pair const& r) const + { + typedef detail::equals::type> equals1; + typedef detail::equals::type> equals2; + + return equals1::apply(l.first, r.first) && equals2::apply(l.second, r.second); + } +}; + +/*! +\brief The function object comparing Values. + +This specialization compares values of type boost::tuple<...>. +It compares values stored in tuple in range [0, length>::value). +*/ +template +struct equal_to< boost::tuple > +{ + typedef boost::tuple value_type; + + typedef bool result_type; + bool operator()(value_type const& l, value_type const& r) const + { + return detail::tuple_equals< + value_type, 0, boost::tuples::length::value + >::apply(l ,r); + } +}; + +}}} // namespace boost::geometry::index + +#endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP diff --git a/include/boost/geometry/index/indexable.hpp b/include/boost/geometry/index/indexable.hpp new file mode 100644 index 000000000..4f27459fe --- /dev/null +++ b/include/boost/geometry/index/indexable.hpp @@ -0,0 +1,112 @@ +// Boost.Geometry Index +// +// Copyright (c) 2011-2013 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_INDEXABLE_HPP +#define BOOST_GEOMETRY_INDEX_INDEXABLE_HPP + +#include + +namespace boost { namespace geometry { namespace index { + +namespace detail { + +template +struct is_indexable_impl { static const bool value = false; }; + +template +struct is_indexable_impl { static const bool value = true; }; + +template +struct is_indexable_impl { static const bool value = true; }; + +template +struct is_indexable +{ + static const bool value = + is_indexable_impl::type>::value; +}; + +} // namespace detail + +/*! +\brief The function object extracting Indexable from Value. + +It translates Value object to Indexable object. The default version handles Values which are Indexables. +This template is also specialized for std::pair and boost::tuple. + +\tparam Value The Value type which may be translated directly to the Indexable. +*/ +template +struct indexable +{ + BOOST_MPL_ASSERT_MSG( + (detail::is_indexable::value), + NOT_VALID_INDEXABLE_TYPE, + (Value) + ); + + typedef Value const& result_type; + result_type operator()(Value const& v) const + { + return v; + } +}; + +/*! +\brief The function object extracting Indexable from Value. + +This specialization translates from std::pair. + +\tparam Indexable The Indexable type. +\tparam T2 The second type. +*/ +template +struct indexable< std::pair > +{ + BOOST_MPL_ASSERT_MSG( + (detail::is_indexable::value), + NOT_VALID_INDEXABLE_TYPE, + (Indexable) + ); + + typedef Indexable const& result_type; + result_type operator()(std::pair const& v) const + { + return v.first; + } +}; + +/*! +\brief The function object extracting Indexable from Value. + +This specialization translates from boost::tuple. + +\tparam Indexable The Indexable type. +*/ +template +struct indexable< boost::tuple > +{ + typedef boost::tuple value_type; + + BOOST_MPL_ASSERT_MSG( + (detail::is_indexable::value), + NOT_VALID_INDEXABLE_TYPE, + (Indexable) + ); + + typedef Indexable const& result_type; + result_type operator()(value_type const& v) const + { + return boost::get<0>(v); + } +}; + +}}} // namespace boost::geometry::index + +#endif // BOOST_GEOMETRY_INDEX_INDEXABLE_HPP diff --git a/include/boost/geometry/index/rtree.hpp b/include/boost/geometry/index/rtree.hpp index 4118ca19e..1f8fd246a 100644 --- a/include/boost/geometry/index/rtree.hpp +++ b/include/boost/geometry/index/rtree.hpp @@ -25,7 +25,11 @@ #include -#include +#include +#include + +#include +#include #include #include @@ -122,8 +126,8 @@ public: // TODO: SHOULD THIS TYPE BE REMOVED? /*! \brief The Indexable type to which Value is translated. */ - typedef typename index::detail::translator::indexable_type< - detail::translator::translator + typedef typename index::detail::indexable_type< + detail::translator >::type indexable_type; /*! \brief The Box type used by the R-tree. */ @@ -132,7 +136,7 @@ public: #if !defined(BOOST_GEOMETRY_INDEX_DETAIL_ENABLE_DEBUG_INTERFACE) private: #endif - typedef detail::translator::translator translator_type; + typedef detail::translator translator_type; typedef bounds_type box_type; typedef typename detail::rtree::options_type::type options_type; diff --git a/include/boost/geometry/index/translator.hpp b/include/boost/geometry/index/translator.hpp deleted file mode 100644 index 611623057..000000000 --- a/include/boost/geometry/index/translator.hpp +++ /dev/null @@ -1,274 +0,0 @@ -// Boost.Geometry Index -// -// Copyright (c) 2011-2013 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_TRANSLATOR_TRANSLATOR_HPP -#define BOOST_GEOMETRY_INDEX_TRANSLATOR_TRANSLATOR_HPP - -// move index::translator::def<> to index::translator<> -// make all index::translator<> methods static -// remove translator::index -// move helpers to index::default::translator - -//#include -//#include - -#include - -#include -#include - -namespace boost { namespace geometry { namespace index { - -namespace detail { namespace translator { - -template -struct indexable_not_found_error -{ - static const bool value = false; -}; -template <> -struct indexable_not_found_error -{ - static const bool value = true; -}; - -template -struct equals -{ - static bool apply(Geometry const& g1, Geometry const& g2) - { - return geometry::equals(g1, g2); - } -}; - -template -struct equals -{ - static bool apply(T const& v1, T const& v2) - { - return v1 == v2; - } -}; - -template -struct compare_tuples -{ - inline static bool apply(Tuple const& t1, Tuple const& t2) - { - typedef typename boost::tuples::element::type T; - return detail::translator::equals< - T, - typename geometry::traits::tag::type - >::apply(boost::get(t1), boost::get(t2)) - && - compare_tuples::apply(t1, t2); - } -}; - -template -struct compare_tuples -{ - inline static bool apply(Tuple const&, Tuple const&) - { - return true; - } -}; - -}} // namespace detail::translator - -/*! -\brief The function object extracting Indexable from Value. - -It translates Value object to Indexable object. The default version handles Values which are Indexables. -This template is also specialized for std::pair and boost::tuple. - -\tparam Value The Value type which may be translated directly to the Indexable. -*/ -template -struct indexable -{ - BOOST_MPL_ASSERT_MSG( - (!detail::translator::indexable_not_found_error< - typename detail::traits::indexable_type::type - >::value), - NOT_VALID_INDEXABLE_TYPE, - (Value) - ); - - typedef Value const& result_type; - result_type operator()(Value const& v) const - { - return v; - } -}; - -/*! -\brief The function object extracting Indexable from Value. - -This specialization translates from std::pair. - -\tparam Indexable The Indexable type. -\tparam T2 The second type. -*/ -template -struct indexable< std::pair > -{ - BOOST_MPL_ASSERT_MSG( - (!detail::translator::indexable_not_found_error< - typename detail::traits::indexable_type::type - >::value), - NOT_VALID_INDEXABLE_TYPE, - (Indexable) - ); - - typedef Indexable const& result_type; - result_type operator()(std::pair const& v) const - { - return v.first; - } -}; - -/*! -\brief The function object extracting Indexable from Value. - -This specialization translates from boost::tuple. - -\tparam Indexable The Indexable type. -*/ -template -struct indexable< boost::tuple > -{ - typedef boost::tuple value_type; - - BOOST_MPL_ASSERT_MSG( - (!detail::translator::indexable_not_found_error< - typename detail::traits::indexable_type::type - >::value), - NOT_VALID_INDEXABLE_TYPE, - (Indexable) - ); - - typedef Indexable const& result_type; - result_type operator()(value_type const& v) const - { - return boost::get<0>(v); - } -}; - -// equal_to - -/*! -\brief The function object comparing Values. - -It compares Geometries using geometry::equals() function. Other types are compared using operator==. -The default version handles Values which are Indexables. -This template is also specialized for std::pair and boost::tuple<...>. - -\tparam Value The type of objects which are compared by this function object. -*/ -template -struct equal_to -{ - typedef bool result_type; - bool operator()(Value const& l, Value const& r) const - { - return detail::translator::equals::type>::apply(l ,r); - } -}; - -/*! -\brief The function object comparing Values. - -This specialization compares values of type std::pair. -It compares pairs' first values, then second values. - -\tparam T1 The first type. -\tparam T2 The second type. -*/ -template -struct equal_to< std::pair > -{ - typedef bool result_type; - bool operator()(std::pair const& l, std::pair const& r) const - { - typedef detail::translator::equals::type> equals1; - typedef detail::translator::equals::type> equals2; - - return equals1::apply(l.first, r.first) && equals2::apply(l.second, r.second); - } -}; - -/*! -\brief The function object comparing Values. - -This specialization compares values of type boost::tuple<...>. -It compares values stored in tuple in range [0, length>::value). -*/ -template -struct equal_to< boost::tuple > -{ - typedef boost::tuple value_type; - - typedef bool result_type; - bool operator()(value_type const& l, value_type const& r) const - { - return detail::translator::compare_tuples< - value_type, 0, boost::tuples::length::value - >::apply(l ,r); - } -}; - -namespace detail { namespace translator { - -template -struct translator - : public IndexableGetter - , public EqualTo -{ - typedef typename IndexableGetter::result_type result_type; - - translator(IndexableGetter const& i, EqualTo const& e) - : IndexableGetter(i), EqualTo(e) - {} - - template - result_type operator()(Value const& value) const - { - return IndexableGetter::operator()(value); - } - - template - bool equals(Value const& v1, Value const& v2) const - { - return EqualTo::operator()(v1, v2); - } -}; - -template -struct result_type -{ - typedef typename Translator::result_type type; -}; - -template -struct indexable_type -{ - typedef typename boost::remove_const< - typename boost::remove_reference< - typename result_type::type - >::type - >::type type; -}; - -}} // namespace detail::translator - -}}} // namespace boost::geometry::index - -#endif // BOOST_GEOMETRY_INDEX_TRANSLATOR_TRANSLATOR_HPP