|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82484 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-01-13 18:09:28
Author: bruno.lalande
Date: 2013-01-13 18:09:27 EST (Sun, 13 Jan 2013)
New Revision: 82484
URL: http://svn.boost.org/trac/boost/changeset/82484
Log:
Made the length algorithm variant-aware.
Text files modified:
trunk/boost/geometry/algorithms/length.hpp | 86 +++++++++++++++++++++++++++++++++++++--
trunk/libs/geometry/test/algorithms/test_length.hpp | 5 +
2 files changed, 84 insertions(+), 7 deletions(-)
Modified: trunk/boost/geometry/algorithms/length.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/length.hpp (original)
+++ trunk/boost/geometry/algorithms/length.hpp 2013-01-13 18:09:27 EST (Sun, 13 Jan 2013)
@@ -18,7 +18,14 @@
#include <boost/range.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/greater.hpp>
#include <boost/mpl/if.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/set.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/transform.hpp>
#include <boost/type_traits.hpp>
#include <boost/geometry/core/cs.hpp>
@@ -33,6 +40,10 @@
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/default_length_result.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
+
namespace boost { namespace geometry
{
@@ -136,6 +147,69 @@
{};
+template <typename Geometry>
+struct devarianted_length
+{
+ typedef typename default_length_result<Geometry>::type result_type;
+
+ template <typename Strategy>
+ static inline result_type apply(Geometry const& geometry,
+ Strategy const& strategy)
+ {
+ return length<Geometry>::apply(geometry, strategy);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct devarianted_length<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+ typedef typename mpl::fold<
+ typename mpl::transform<
+ typename variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
+ default_length_result<mpl::_>
+ >::type,
+ mpl::set0<>,
+ mpl::insert<mpl::_1, mpl::_2>
+ >::type possible_result_types;
+
+ typedef typename mpl::if_<
+ mpl::greater<
+ mpl::size<possible_result_types>,
+ mpl::int_<1>
+ >,
+ typename make_variant_over<possible_result_types>::type,
+ typename mpl::front<possible_result_types>::type
+ >::type result_type;
+
+ template <typename Strategy>
+ struct visitor
+ : static_visitor<result_type>
+ {
+ Strategy const& m_strategy;
+
+ visitor(Strategy const& strategy)
+ : m_strategy(strategy)
+ {}
+
+ template <typename Geometry>
+ inline typename devarianted_length<Geometry>::result_type
+ operator()(Geometry const& geometry) const
+ {
+ return devarianted_length<Geometry>::apply(geometry, m_strategy);
+ }
+ };
+
+ template <typename Strategy>
+ static inline result_type apply(
+ variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
+ Strategy const& strategy
+ )
+ {
+ return apply_visitor(visitor<Strategy>(strategy), geometry);
+ }
+};
+
+
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
@@ -152,8 +226,8 @@
\qbk{[length] [length_output]}
*/
template<typename Geometry>
-inline typename default_length_result<Geometry>::type length(
- Geometry const& geometry)
+inline typename dispatch::devarianted_length<Geometry>::result_type
+length(Geometry const& geometry)
{
concept::check<Geometry const>();
@@ -164,7 +238,7 @@
point_tag, typename point_type<Geometry>::type
>::type strategy_type;
- return dispatch::length<Geometry>::apply(geometry, strategy_type());
+ return dispatch::devarianted_length<Geometry>::apply(geometry, strategy_type());
}
@@ -183,14 +257,14 @@
\qbk{[length_with_strategy] [length_with_strategy_output]}
*/
template<typename Geometry, typename Strategy>
-inline typename default_length_result<Geometry>::type length(
- Geometry const& geometry, Strategy const& strategy)
+inline typename dispatch::devarianted_length<Geometry>::result_type
+length(Geometry const& geometry, Strategy const& strategy)
{
concept::check<Geometry const>();
// detail::throw_on_empty_input(geometry);
- return dispatch::length<Geometry>::apply(geometry, strategy);
+ return dispatch::devarianted_length<Geometry>::apply(geometry, strategy);
}
Modified: trunk/libs/geometry/test/algorithms/test_length.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_length.hpp (original)
+++ trunk/libs/geometry/test/algorithms/test_length.hpp 2013-01-13 18:09:27 EST (Sun, 13 Jan 2013)
@@ -14,12 +14,14 @@
#include <boost/geometry/algorithms/length.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/strategies/strategies.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <boost/variant/variant.hpp>
template <typename Geometry>
void test_length(Geometry const& geometry, long double expected_length)
{
- typename bg::default_length_result<Geometry>::type length = bg::length(geometry);
+ BOOST_AUTO(length, bg::length(geometry));
#ifdef GEOMETRY_TEST_DEBUG
std::ostringstream out;
@@ -42,6 +44,7 @@
Geometry geometry;
bg::read_wkt(wkt, geometry);
test_length(geometry, expected_length);
+ test_length(boost::variant<Geometry>(geometry), expected_length);
}
template <typename Geometry>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk