rtree: indexable<>, equal_to<> and translator<> relocated:

translator<>, indexable_type<>, result_type<> moved to detail namespace.
indexable<> and equal_to<> are now defined in separate files.
detail::translator namespace removed.

[SVN r83288]
This commit is contained in:
Adam Wulkiewicz
2013-03-03 23:41:22 +00:00
parent 5e2db81daf
commit cfb4911630
8 changed files with 311 additions and 321 deletions

View File

@@ -15,44 +15,6 @@ namespace boost { namespace geometry { namespace index { namespace detail {
namespace dispatch {
// Distinguish between indexables and other geometries
template <typename Geometry, typename GeometryTag>
struct indexable_type
{
typedef void type;
};
template <typename Point>
struct indexable_type<Point, geometry::point_tag>
{
typedef Point type;
};
template <typename Box>
struct indexable_type<Box, geometry::box_tag>
{
typedef Box type;
};
} // namespace dispatch
namespace traits
{
template <typename Indexable>
struct indexable_type
{
typedef typename dispatch::indexable_type<
Indexable,
typename geometry::traits::tag<Indexable>::type
>::type type;
};
} // namespace traits
namespace dispatch {
template <typename Indexable, typename IndexableTag>
struct point_type
{

View File

@@ -96,7 +96,7 @@ struct visitor<Value, Parameters, Box, Allocators, node_d_mem_dynamic_tag, IsVis
template <typename Element, typename Translator>
struct element_indexable_type
{
typedef typename translator::indexable_type<Translator>::type type;
typedef typename indexable_type<Translator>::type type;
};
template <typename First, typename Pointer, typename Translator>
@@ -111,7 +111,7 @@ struct element_indexable_type<
// element's indexable getter
template <typename Element, typename Translator>
typename translator::result_type<Translator>::type
typename result_type<Translator>::type
element_indexable(Element const& el, Translator const& tr)
{
return tr(el);

View File

@@ -68,7 +68,7 @@ struct nearest_query_result_k
public:
typedef typename geometry::default_distance_result<
Point,
typename translator::indexable_type<Translator>::type
typename indexable_type<Translator>::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<Translator>::type,
typename indexable_type<Translator>::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<Translator>::type,
typename indexable_type<Translator>::type,
index::detail::value_tag
> value_distances_predicates_check;

View File

@@ -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 <typename IndexableGetter, typename EqualTo>
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 <typename Value>
result_type operator()(Value const& value) const
{
return IndexableGetter::operator()(value);
}
template <typename Value>
bool equals(Value const& v1, Value const& v2) const
{
return EqualTo::operator()(v1, v2);
}
};
template <typename IndexableGetter>
struct result_type
{
typedef typename IndexableGetter::result_type type;
};
template <typename IndexableGetter>
struct indexable_type
{
typedef typename boost::remove_const<
typename boost::remove_reference<
typename result_type<IndexableGetter>::type
>::type
>::type type;
};
} // namespace detail
}}} // namespace boost::geometry::index
#endif // BOOST_GEOMETRY_INDEX_DETAIL_TRANSLATOR_HPP

View File

@@ -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 <boost/geometry/algorithms/equals.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail {
template <typename Geometry, typename Tag>
struct equals
{
static bool apply(Geometry const& g1, Geometry const& g2)
{
return geometry::equals(g1, g2);
}
};
template <typename T>
struct equals<T, void>
{
static bool apply(T const& v1, T const& v2)
{
return v1 == v2;
}
};
template <typename Tuple, size_t I, size_t N>
struct tuple_equals
{
inline static bool apply(Tuple const& t1, Tuple const& t2)
{
typedef typename boost::tuples::element<I, Tuple>::type T;
return
equals<
T, typename geometry::traits::tag<T>::type
>::apply(boost::get<I>(t1), boost::get<I>(t2))
&&
tuple_equals<Tuple, I+1, N>::apply(t1, t2);
}
};
template <typename Tuple, size_t I>
struct tuple_equals<Tuple, I, I>
{
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<T1, T2> and boost::tuple<...>.
\tparam Value The type of objects which are compared by this function object.
*/
template <typename Value>
struct equal_to
{
typedef bool result_type;
bool operator()(Value const& l, Value const& r) const
{
return detail::equals<Value, typename geometry::traits::tag<Value>::type>::apply(l ,r);
}
};
/*!
\brief The function object comparing Values.
This specialization compares values of type std::pair<T1, T2>.
It compares pairs' first values, then second values.
\tparam T1 The first type.
\tparam T2 The second type.
*/
template <typename T1, typename T2>
struct equal_to< std::pair<T1, T2> >
{
typedef bool result_type;
bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r) const
{
typedef detail::equals<T1, typename geometry::traits::tag<T1>::type> equals1;
typedef detail::equals<T2, typename geometry::traits::tag<T2>::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<tuple<...>>::value).
*/
template <typename T0, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8, typename T9>
struct equal_to< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
{
typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> 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_type>::value
>::apply(l ,r);
}
};
}}} // namespace boost::geometry::index
#endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP

View File

@@ -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 <boost/mpl/assert.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail {
template <typename Geometry, typename GeometryTag>
struct is_indexable_impl { static const bool value = false; };
template <typename Point>
struct is_indexable_impl<Point, geometry::point_tag> { static const bool value = true; };
template <typename Box>
struct is_indexable_impl<Box, geometry::box_tag> { static const bool value = true; };
template <typename Indexable>
struct is_indexable
{
static const bool value =
is_indexable_impl<Indexable, typename geometry::traits::tag<Indexable>::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<Indexable, T2> and boost::tuple<Indexable, ...>.
\tparam Value The Value type which may be translated directly to the Indexable.
*/
template <typename Value>
struct indexable
{
BOOST_MPL_ASSERT_MSG(
(detail::is_indexable<Value>::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<Indexable, T2>.
\tparam Indexable The Indexable type.
\tparam T2 The second type.
*/
template <typename Indexable, typename T2>
struct indexable< std::pair<Indexable, T2> >
{
BOOST_MPL_ASSERT_MSG(
(detail::is_indexable<Indexable>::value),
NOT_VALID_INDEXABLE_TYPE,
(Indexable)
);
typedef Indexable const& result_type;
result_type operator()(std::pair<Indexable, T2> const& v) const
{
return v.first;
}
};
/*!
\brief The function object extracting Indexable from Value.
This specialization translates from boost::tuple<Indexable, ...>.
\tparam Indexable The Indexable type.
*/
template <typename Indexable, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8, typename T9>
struct indexable< boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
{
typedef boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
BOOST_MPL_ASSERT_MSG(
(detail::is_indexable<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

View File

@@ -25,7 +25,11 @@
#include <boost/geometry/index/detail/rtree/options.hpp>
#include <boost/geometry/index/translator.hpp>
#include <boost/geometry/index/indexable.hpp>
#include <boost/geometry/index/equal_to.hpp>
#include <boost/geometry/index/detail/indexable.hpp>
#include <boost/geometry/index/detail/translator.hpp>
#include <boost/geometry/index/predicates.hpp>
#include <boost/geometry/index/distance_predicates.hpp>
@@ -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<IndexableGetter, EqualTo>
typedef typename index::detail::indexable_type<
detail::translator<IndexableGetter, EqualTo>
>::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<IndexableGetter, EqualTo> translator_type;
typedef detail::translator<IndexableGetter, EqualTo> translator_type;
typedef bounds_type box_type;
typedef typename detail::rtree::options_type<Parameters>::type options_type;

View File

@@ -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 <boost/geometry/index/translator/def.hpp>
//#include <boost/geometry/index/translator/index.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/geometry/algorithms/equals.hpp>
#include <boost/geometry/index/detail/indexable.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail { namespace translator {
template <typename Geometry>
struct indexable_not_found_error
{
static const bool value = false;
};
template <>
struct indexable_not_found_error<void>
{
static const bool value = true;
};
template <typename Geometry, typename Tag>
struct equals
{
static bool apply(Geometry const& g1, Geometry const& g2)
{
return geometry::equals(g1, g2);
}
};
template <typename T>
struct equals<T, void>
{
static bool apply(T const& v1, T const& v2)
{
return v1 == v2;
}
};
template <typename Tuple, size_t I, size_t N>
struct compare_tuples
{
inline static bool apply(Tuple const& t1, Tuple const& t2)
{
typedef typename boost::tuples::element<I, Tuple>::type T;
return detail::translator::equals<
T,
typename geometry::traits::tag<T>::type
>::apply(boost::get<I>(t1), boost::get<I>(t2))
&&
compare_tuples<Tuple, I+1, N>::apply(t1, t2);
}
};
template <typename Tuple, size_t I>
struct compare_tuples<Tuple, I, I>
{
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<Indexable, T2> and boost::tuple<Indexable, ...>.
\tparam Value The Value type which may be translated directly to the Indexable.
*/
template <typename Value>
struct indexable
{
BOOST_MPL_ASSERT_MSG(
(!detail::translator::indexable_not_found_error<
typename detail::traits::indexable_type<Value>::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<Indexable, T2>.
\tparam Indexable The Indexable type.
\tparam T2 The second type.
*/
template <typename Indexable, typename T2>
struct indexable< std::pair<Indexable, T2> >
{
BOOST_MPL_ASSERT_MSG(
(!detail::translator::indexable_not_found_error<
typename detail::traits::indexable_type<Indexable>::type
>::value),
NOT_VALID_INDEXABLE_TYPE,
(Indexable)
);
typedef Indexable const& result_type;
result_type operator()(std::pair<Indexable, T2> const& v) const
{
return v.first;
}
};
/*!
\brief The function object extracting Indexable from Value.
This specialization translates from boost::tuple<Indexable, ...>.
\tparam Indexable The Indexable type.
*/
template <typename Indexable, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8, typename T9>
struct indexable< boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
{
typedef boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
BOOST_MPL_ASSERT_MSG(
(!detail::translator::indexable_not_found_error<
typename detail::traits::indexable_type<Indexable>::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<T1, T2> and boost::tuple<...>.
\tparam Value The type of objects which are compared by this function object.
*/
template <typename Value>
struct equal_to
{
typedef bool result_type;
bool operator()(Value const& l, Value const& r) const
{
return detail::translator::equals<Value, typename geometry::traits::tag<Value>::type>::apply(l ,r);
}
};
/*!
\brief The function object comparing Values.
This specialization compares values of type std::pair<T1, T2>.
It compares pairs' first values, then second values.
\tparam T1 The first type.
\tparam T2 The second type.
*/
template <typename T1, typename T2>
struct equal_to< std::pair<T1, T2> >
{
typedef bool result_type;
bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r) const
{
typedef detail::translator::equals<T1, typename geometry::traits::tag<T1>::type> equals1;
typedef detail::translator::equals<T2, typename geometry::traits::tag<T2>::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<tuple<...>>::value).
*/
template <typename T0, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8, typename T9>
struct equal_to< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
{
typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> 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_type>::value
>::apply(l ,r);
}
};
namespace detail { namespace translator {
template <typename IndexableGetter, typename EqualTo>
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 <typename Value>
result_type operator()(Value const& value) const
{
return IndexableGetter::operator()(value);
}
template <typename Value>
bool equals(Value const& v1, Value const& v2) const
{
return EqualTo::operator()(v1, v2);
}
};
template <typename Translator>
struct result_type
{
typedef typename Translator::result_type type;
};
template <typename Translator>
struct indexable_type
{
typedef typename boost::remove_const<
typename boost::remove_reference<
typename result_type<Translator>::type
>::type
>::type type;
};
}} // namespace detail::translator
}}} // namespace boost::geometry::index
#endif // BOOST_GEOMETRY_INDEX_TRANSLATOR_TRANSLATOR_HPP