Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82472 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-01-12 18:06:18


Author: bruno.lalande
Date: 2013-01-12 18:06:18 EST (Sat, 12 Jan 2013)
New Revision: 82472
URL: http://svn.boost.org/trac/boost/changeset/82472

Log:
Made the convert algorithm variant-aware.
Text files modified:
   trunk/boost/geometry/algorithms/convert.hpp | 46 +++++++++++++++++++++++++++++++++++++--
   trunk/libs/geometry/test/algorithms/test_convert.hpp | 17 +++++++++-----
   2 files changed, 54 insertions(+), 9 deletions(-)

Modified: trunk/boost/geometry/algorithms/convert.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/convert.hpp (original)
+++ trunk/boost/geometry/algorithms/convert.hpp 2013-01-12 18:06:18 EST (Sat, 12 Jan 2013)
@@ -40,6 +40,10 @@
 #include <boost/geometry/core/point_order.hpp>
 #include <boost/geometry/geometries/concepts/check.hpp>
 
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
+
 
 namespace boost { namespace geometry
 {
@@ -377,6 +381,44 @@
 };
 
 
+template <typename Geometry1, typename Geometry2>
+struct devarianted_convert
+{
+ static inline void apply(Geometry1 const& geometry1, Geometry2& geometry2)
+ {
+ concept::check_concepts_and_equal_dimensions<Geometry1 const, Geometry2>();
+ convert<Geometry1, Geometry2>::apply(geometry1, geometry2);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
+struct devarianted_convert<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
+{
+ struct visitor: static_visitor<void>
+ {
+ Geometry2& m_geometry2;
+
+ visitor(Geometry2& geometry2)
+ : m_geometry2(geometry2)
+ {}
+
+ template <typename Geometry1>
+ inline void operator()(Geometry1 const& geometry1) const
+ {
+ devarianted_convert<Geometry1, Geometry2>::apply(geometry1, m_geometry2);
+ }
+ };
+
+ static inline void apply(
+ boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
+ Geometry2& geometry2
+ )
+ {
+ apply_visitor(visitor(geometry2), geometry1);
+ }
+};
+
+
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH
 
@@ -399,9 +441,7 @@
 template <typename Geometry1, typename Geometry2>
 inline void convert(Geometry1 const& geometry1, Geometry2& geometry2)
 {
- concept::check_concepts_and_equal_dimensions<Geometry1 const, Geometry2>();
-
- dispatch::convert<Geometry1, Geometry2>::apply(geometry1, geometry2);
+ dispatch::devarianted_convert<Geometry1, Geometry2>::apply(geometry1, geometry2);
 }
 
 

Modified: trunk/libs/geometry/test/algorithms/test_convert.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_convert.hpp (original)
+++ trunk/libs/geometry/test/algorithms/test_convert.hpp 2013-01-12 18:06:18 EST (Sat, 12 Jan 2013)
@@ -21,6 +21,7 @@
 #include <boost/geometry/geometries/adapted/c_array.hpp>
 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
 
+#include <boost/variant/variant.hpp>
 
 #include <geometry_test_common.hpp>
 
@@ -31,20 +32,24 @@
 
 
 
-template <typename Geometry1, typename Geometry2>
-void test_mixed(std::string const& wkt, std::string const& expected)
+template <typename Geometry2, typename Geometry1>
+void check_mixed(Geometry1 const& geometry1, std::string const& expected)
 {
- Geometry1 geometry1;
- bg::read_wkt(wkt, geometry1);
-
     Geometry2 geometry2;
     bg::convert(geometry1, geometry2);
 
     std::ostringstream out;
     out << bg::wkt(geometry2);
     BOOST_CHECK_EQUAL(out.str(), expected);
+}
 
- // std::cout << bg::area(geometry1) << " " << bg::area(geometry2) << std::endl;
+template <typename Geometry1, typename Geometry2>
+void test_mixed(std::string const& wkt, std::string const& expected)
+{
+ Geometry1 geometry1;
+ bg::read_wkt(wkt, geometry1);
+ check_mixed<Geometry2>(geometry1, expected);
+ check_mixed<Geometry2>(boost::variant<Geometry1>(geometry1), expected);
 }
 
 template <typename Geometry1, typename Geometry2>


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