$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r86414 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-10-24 02:10:34
Author: bruno.lalande
Date: 2013-10-24 02:10:34 EDT (Thu, 24 Oct 2013)
New Revision: 86414
URL: http://svn.boost.org/trac/boost/changeset/86414
Log:
Made 'correct' variant-aware.
Added:
   trunk/libs/geometry/test/algorithms/test_correct.hpp   (contents, props changed)
Text files modified: 
   trunk/boost/geometry/algorithms/correct.hpp          |    41 +++++++++++++++++++++++++++--           
   trunk/libs/geometry/test/algorithms/correct.cpp      |    21 --------------                          
   trunk/libs/geometry/test/algorithms/test_correct.hpp |    55 ++++++++++++++++++++++++++++++++++++++++
   3 files changed, 94 insertions(+), 23 deletions(-)
Modified: trunk/boost/geometry/algorithms/correct.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/correct.hpp	Thu Oct 24 01:39:18 2013	(r86413)
+++ trunk/boost/geometry/algorithms/correct.hpp	2013-10-24 02:10:34 EDT (Thu, 24 Oct 2013)	(r86414)
@@ -22,6 +22,9 @@
 #include <boost/mpl/assert.hpp>
 #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/closure.hpp>
 #include <boost/geometry/core/cs.hpp>
@@ -242,6 +245,40 @@
 #endif // DOXYGEN_NO_DISPATCH
 
 
+namespace resolve_variant {
+
+template <typename Geometry>
+struct correct
+{
+    static inline void apply(Geometry& geometry)
+    {
+        concept::check<Geometry const>();
+        dispatch::correct<Geometry>::apply(geometry);
+    }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct correct<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+    struct visitor: boost::static_visitor<void>
+    {
+        template <typename Geometry>
+        void operator()(Geometry& geometry) const
+        {
+            correct<Geometry>::apply(geometry);
+        }
+    };
+
+    static inline void
+    apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry)
+    {
+        boost::apply_visitor(visitor(), geometry);
+    }
+};
+
+} // namespace resolve_variant
+
+
 /*!
 \brief Corrects a geometry
 \details Corrects a geometry: all rings which are wrongly oriented with respect
@@ -257,9 +294,7 @@
 template <typename Geometry>
 inline void correct(Geometry& geometry)
 {
-    concept::check<Geometry const>();
-
-    dispatch::correct<Geometry>::apply(geometry);
+    resolve_variant::correct<Geometry>::apply(geometry);
 }
 
 #if defined(_MSC_VER)
Modified: trunk/libs/geometry/test/algorithms/correct.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/correct.cpp	Thu Oct 24 01:39:18 2013	(r86413)
+++ trunk/libs/geometry/test/algorithms/correct.cpp	2013-10-24 02:10:34 EDT (Thu, 24 Oct 2013)	(r86414)
@@ -14,37 +14,18 @@
 
 #include <sstream>
 
-#include <geometry_test_common.hpp>
+#include <algorithms/test_correct.hpp>
 
-#include <boost/geometry/algorithms/correct.hpp>
 #include <boost/geometry/strategies/strategies.hpp>
 
 #include <boost/geometry/io/dsv/write.hpp>
 
-#include <boost/geometry/io/wkt/read.hpp>
-#include <boost/geometry/io/wkt/write.hpp>
-
 #include <boost/geometry/geometries/point_xy.hpp>
 #include <boost/geometry/geometries/box.hpp>
 #include <boost/geometry/geometries/ring.hpp>
 #include <boost/geometry/geometries/polygon.hpp>
 
 
-template <typename Geometry>
-void test_geometry(std::string const& wkt, std::string const& expected)
-{
-    Geometry geometry;
-
-    bg::read_wkt(wkt, geometry);
-    bg::correct(geometry);
-
-    std::ostringstream out;
-    out << bg::wkt(geometry);
-
-    BOOST_CHECK_EQUAL(out.str(), expected);
-}
-
-
 // Note: 3D/box test cannot be done using WKT because:
 // -> wkt-box does not exist
 // -> so it is converted to a ring
Added: trunk/libs/geometry/test/algorithms/test_correct.hpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/libs/geometry/test/algorithms/test_correct.hpp	2013-10-24 02:10:34 EDT (Thu, 24 Oct 2013)	(r86414)
@@ -0,0 +1,55 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+// Unit Test
+
+// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
+// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
+// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
+
+// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
+// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
+
+// 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_TEST_CORRECT_HPP
+#define BOOST_GEOMETRY_TEST_CORRECT_HPP
+
+
+// Test-functionality, shared between single and multi tests
+
+#include <sstream>
+
+#include <geometry_test_common.hpp>
+
+#include <boost/geometry/algorithms/correct.hpp>
+#include <boost/geometry/io/wkt/read.hpp>
+#include <boost/geometry/io/wkt/write.hpp>
+#include <boost/variant/variant.hpp>
+
+
+template <typename Geometry>
+void check_geometry(Geometry const& geometry, std::string const& expected)
+{
+    std::ostringstream out;
+    out << bg::wkt(geometry);
+
+    BOOST_CHECK_EQUAL(out.str(), expected);
+}
+
+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);
+
+    bg::correct(geometry);
+    check_geometry(geometry, expected);
+
+    bg::correct(v);
+    check_geometry(v, expected);
+}
+
+
+#endif