|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82378 - in trunk: boost/geometry/algorithms libs/geometry/test/multi/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-01-06 17:27:38
Author: bruno.lalande
Date: 2013-01-06 17:27:38 EST (Sun, 06 Jan 2013)
New Revision: 82378
URL: http://svn.boost.org/trac/boost/changeset/82378
Log:
Made num_points variant-aware.
Text files modified:
trunk/boost/geometry/algorithms/num_points.hpp | 28 +++++++++++++++++++++++++++-
trunk/libs/geometry/test/multi/algorithms/multi_num_points.cpp | 16 +++++++++++++---
2 files changed, 40 insertions(+), 4 deletions(-)
Modified: trunk/boost/geometry/algorithms/num_points.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/num_points.hpp (original)
+++ trunk/boost/geometry/algorithms/num_points.hpp 2013-01-06 17:27:38 EST (Sun, 06 Jan 2013)
@@ -24,10 +24,12 @@
#include <boost/geometry/core/interior_rings.hpp>
#include <boost/geometry/core/ring_type.hpp>
#include <boost/geometry/core/tag_cast.hpp>
-
#include <boost/geometry/algorithms/disjoint.hpp>
#include <boost/geometry/algorithms/not_implemented.hpp>
#include <boost/geometry/geometries/concepts/check.hpp>
+#include <boost/geometry/geometries/variant.hpp>
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
namespace boost { namespace geometry
@@ -107,6 +109,30 @@
struct num_points: not_implemented<Tag>
{};
+template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Unused>
+struct num_points<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Unused>
+{
+ struct visitor: boost::static_visitor<std::size_t>
+ {
+ bool m_add_for_open;
+
+ visitor(bool add_for_open): m_add_for_open(add_for_open) {}
+
+ template <typename Geometry>
+ typename std::size_t operator()(Geometry const& geometry) const
+ {
+ return dispatch::num_points<Geometry>::apply(geometry, m_add_for_open);
+ }
+ };
+
+ template <typename Variant>
+ static inline std::size_t
+ apply(Variant const& variant_geometry, bool add_for_open)
+ {
+ return boost::apply_visitor(visitor(add_for_open), variant_geometry);
+ }
+};
+
template <typename Geometry>
struct num_points<Geometry, point_tag>
: detail::num_points::other_count<1>
Modified: trunk/libs/geometry/test/multi/algorithms/multi_num_points.cpp
==============================================================================
--- trunk/libs/geometry/test/multi/algorithms/multi_num_points.cpp (original)
+++ trunk/libs/geometry/test/multi/algorithms/multi_num_points.cpp 2013-01-06 17:27:38 EST (Sun, 06 Jan 2013)
@@ -19,11 +19,12 @@
#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, int expected)
+void check_geometry(Geometry const& geometry, std::string const& wkt, int expected)
{
- Geometry geometry;
- bg::read_wkt(wkt, geometry);
int detected = bg::num_points(geometry);
BOOST_CHECK_MESSAGE(detected == expected,
"num_points: " << wkt
@@ -31,6 +32,15 @@
<< " detected: " << detected);
}
+template <typename Geometry>
+void test_geometry(std::string const& wkt, int expected)
+{
+ Geometry geometry;
+ bg::read_wkt(wkt, geometry);
+ check_geometry(geometry, wkt, expected);
+ check_geometry(boost::variant<Geometry>(geometry), wkt, expected);
+}
+
template <typename Point>
void test_all()
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