Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82395 - in trunk: boost/geometry/algorithms libs/geometry/test/multi/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-01-07 19:05:37


Author: bruno.lalande
Date: 2013-01-07 19:05:36 EST (Mon, 07 Jan 2013)
New Revision: 82395
URL: http://svn.boost.org/trac/boost/changeset/82395

Log:
Made clear() variant-aware.
Added:
   trunk/libs/geometry/test/multi/algorithms/multi_clear.cpp (contents, props changed)
Text files modified:
   trunk/boost/geometry/algorithms/clear.hpp | 25 +++++++++++++++++++++++--
   1 files changed, 23 insertions(+), 2 deletions(-)

Modified: trunk/boost/geometry/algorithms/clear.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/clear.hpp (original)
+++ trunk/boost/geometry/algorithms/clear.hpp 2013-01-07 19:05:36 EST (Mon, 07 Jan 2013)
@@ -14,7 +14,6 @@
 #ifndef BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
 #define BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
 
-#include <boost/type_traits/remove_const.hpp>
 
 #include <boost/geometry/algorithms/not_implemented.hpp>
 #include <boost/geometry/core/access.hpp>
@@ -22,8 +21,11 @@
 #include <boost/geometry/core/interior_rings.hpp>
 #include <boost/geometry/core/mutable_range.hpp>
 #include <boost/geometry/core/tag_cast.hpp>
-
 #include <boost/geometry/geometries/concepts/check.hpp>
+#include <boost/type_traits/remove_const.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
 
 
 namespace boost { namespace geometry
@@ -72,6 +74,7 @@
     }
 };
 
+
 }} // namespace detail::clear
 #endif // DOXYGEN_NO_DETAIL
 
@@ -121,6 +124,17 @@
 {};
 
 
+struct variant_dispatcher: boost::static_visitor<void>
+{
+ template <typename Geometry>
+ void operator()(Geometry& geometry) const
+ {
+ concept::check<Geometry>();
+ clear<Geometry>::apply(geometry);
+ }
+};
+
+
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH
 
@@ -147,6 +161,13 @@
 }
 
 
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+inline void clear(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry)
+{
+ apply_visitor(dispatch::variant_dispatcher(), geometry);
+}
+
+
 }} // namespace boost::geometry
 
 

Added: trunk/libs/geometry/test/multi/algorithms/multi_clear.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/test/multi/algorithms/multi_clear.cpp 2013-01-07 19:05:36 EST (Mon, 07 Jan 2013)
@@ -0,0 +1,69 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright (c) 2011-2012 Barend Gehrels, 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)
+
+#include <geometry_test_common.hpp>
+
+#include <boost/geometry/algorithms/clear.hpp>
+#include <boost/geometry/algorithms/num_points.hpp>
+#include <boost/geometry/multi/algorithms/clear.hpp>
+#include <boost/geometry/multi/algorithms/num_points.hpp>
+
+#include <boost/geometry/io/wkt/wkt.hpp>
+#include <boost/geometry/multi/io/wkt/wkt.hpp>
+
+#include <boost/geometry/geometries/geometries.hpp>
+#include <boost/geometry/geometries/point_xy.hpp>
+#include <boost/geometry/multi/geometries/multi_point.hpp>
+#include <boost/geometry/multi/geometries/multi_linestring.hpp>
+#include <boost/geometry/multi/geometries/multi_polygon.hpp>
+
+#include <boost/variant/variant.hpp>
+
+
+template <typename Geometry>
+void test_geometry(std::string const& wkt, unsigned int expected)
+{
+ Geometry geometry;
+ bg::read_wkt(wkt, geometry);
+ boost::variant<Geometry> variant_geometry(geometry);
+
+ bg::clear(geometry);
+ BOOST_CHECK_EQUAL(bg::num_points(geometry), expected);
+
+ bg::clear(variant_geometry);
+ BOOST_CHECK_EQUAL(bg::num_points(variant_geometry), expected);
+}
+
+
+template <typename Point>
+void test_all()
+{
+ typedef bg::model::polygon<Point> poly;
+ typedef bg::model::linestring<Point> ls;
+ typedef bg::model::multi_point<Point> mpoint;
+ typedef bg::model::multi_linestring<ls> mls;
+ typedef bg::model::multi_polygon<poly> mpoly;
+
+ test_geometry<Point>("POINT(0 0)", 1);
+ test_geometry<ls>("LINESTRING(0 0,0 1)", 0);
+ test_geometry<poly>("POLYGON((0 0,0 1,1 0,0 0))", 0);
+ test_geometry<mpoint>("MULTIPOINT((0 0),(0 1),(1 0),(0 0))", 0);
+ test_geometry<mls>("MULTILINESTRING((0 0,0 1),(1 0,0 0))", 0);
+ test_geometry<mpoly>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((10 0,10 1,11 0,10 0)))", 0);
+}
+
+
+int test_main( int , char* [] )
+{
+ test_all<bg::model::d2::point_xy<double> >();
+
+#ifdef HAVE_TTMATH
+ test_all<bg::model::d2::point_xy<ttmath_big> >();
+#endif
+
+ return 0;
+}


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