Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86678 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-11-13 09:53:37


Author: bruno.lalande
Date: 2013-11-13 09:53:37 EST (Wed, 13 Nov 2013)
New Revision: 86678
URL: http://svn.boost.org/trac/boost/changeset/86678

Log:
Made reverse algorithm variant-aware.

Text files modified:
   trunk/boost/geometry/algorithms/reverse.hpp | 41 +++++++++++++++++++++++++++++++++++++--
   trunk/libs/geometry/test/algorithms/test_reverse.hpp | 18 ++++++++++++----
   2 files changed, 51 insertions(+), 8 deletions(-)

Modified: trunk/boost/geometry/algorithms/reverse.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/reverse.hpp Wed Nov 13 08:30:10 2013 (r86677)
+++ trunk/boost/geometry/algorithms/reverse.hpp 2013-11-13 09:53:37 EST (Wed, 13 Nov 2013) (r86678)
@@ -18,6 +18,9 @@
 
 #include <boost/range.hpp>
 #include <boost/typeof/typeof.hpp>
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
 
 #include <boost/geometry/core/interior_rings.hpp>
 #include <boost/geometry/geometries/concepts/check.hpp>
@@ -100,6 +103,40 @@
 #endif
 
 
+namespace resolve_variant
+{
+
+template <typename Geometry>
+struct reverse
+{
+ static void apply(Geometry& geometry)
+ {
+ concept::check<Geometry>();
+ dispatch::reverse<Geometry>::apply(geometry);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct reverse<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+ struct visitor: boost::static_visitor<void>
+ {
+ template <typename Geometry>
+ void operator()(Geometry& geometry) const
+ {
+ reverse<Geometry>::apply(geometry);
+ }
+ };
+
+ static inline void apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry)
+ {
+ boost::apply_visitor(visitor(), geometry);
+ }
+};
+
+} // namespace resolve_variant
+
+
 /*!
 \brief Reverses the points within a geometry
 \details Generic function to reverse a geometry. It resembles the std::reverse
@@ -114,9 +151,7 @@
 template <typename Geometry>
 inline void reverse(Geometry& geometry)
 {
- concept::check<Geometry>();
-
- dispatch::reverse<Geometry>::apply(geometry);
+ resolve_variant::reverse<Geometry>::apply(geometry);
 }
 
 }} // namespace boost::geometry

Modified: trunk/libs/geometry/test/algorithms/test_reverse.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_reverse.hpp Wed Nov 13 08:30:10 2013 (r86677)
+++ trunk/libs/geometry/test/algorithms/test_reverse.hpp 2013-11-13 09:53:37 EST (Wed, 13 Nov 2013) (r86678)
@@ -13,16 +13,13 @@
 
 #include <geometry_test_common.hpp>
 #include <boost/geometry/algorithms/reverse.hpp>
-
 #include <boost/geometry/io/wkt/wkt.hpp>
+#include <boost/variant/variant.hpp>
 
 
 template <typename Geometry>
-void test_geometry(std::string const& wkt, std::string const& expected)
+void check_geometry(Geometry& geometry, std::string const& wkt, std::string const& expected)
 {
- Geometry geometry;
-
- bg::read_wkt(wkt, geometry);
     bg::reverse(geometry);
 
     std::ostringstream out;
@@ -34,5 +31,16 @@
         << " got " << out.str());
 }
 
+template <typename Geometry>
+void test_geometry(std::string const& wkt, std::string const& expected)
+{
+ Geometry geometry;
+ bg::read_wkt(wkt, geometry);
+ boost::variant<Geometry> v(geometry);
+
+ check_geometry(geometry, wkt, expected);
+ check_geometry(v, wkt, expected);
+}
+
 
 #endif


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