Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82481 - in trunk: boost/geometry/io/wkt libs/geometry/test/io/wkt
From: bruno.lalande_at_[hidden]
Date: 2013-01-13 12:25:15


Author: bruno.lalande
Date: 2013-01-13 12:25:15 EST (Sun, 13 Jan 2013)
New Revision: 82481
URL: http://svn.boost.org/trac/boost/changeset/82481

Log:
Made wkt write variant-aware.
Text files modified:
   trunk/boost/geometry/io/wkt/write.hpp | 46 +++++++++++++++++++++++++++++++++++++++
   trunk/libs/geometry/test/io/wkt/wkt.cpp | 16 ++++++++++---
   2 files changed, 57 insertions(+), 5 deletions(-)

Modified: trunk/boost/geometry/io/wkt/write.hpp
==============================================================================
--- trunk/boost/geometry/io/wkt/write.hpp (original)
+++ trunk/boost/geometry/io/wkt/write.hpp 2013-01-13 12:25:15 EST (Sun, 13 Jan 2013)
@@ -33,6 +33,10 @@
 
 #include <boost/geometry/io/wkt/detail/prefix.hpp>
 
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
+
 namespace boost { namespace geometry
 {
 
@@ -307,6 +311,46 @@
 {};
 
 
+template <typename Geometry>
+struct devarianted_wkt
+{
+ template <typename OutputStream>
+ static inline void apply(OutputStream& os, Geometry const& geometry)
+ {
+ wkt<Geometry>::apply(os, geometry);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct devarianted_wkt<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+ template <typename OutputStream>
+ struct visitor: static_visitor<void>
+ {
+ OutputStream& m_os;
+
+ visitor(OutputStream& os)
+ : m_os(os)
+ {}
+
+ template <typename Geometry>
+ inline void operator()(Geometry const& geometry) const
+ {
+ devarianted_wkt<Geometry>::apply(m_os, geometry);
+ }
+ };
+
+ template <typename OutputStream>
+ static inline void apply(
+ OutputStream& os,
+ variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry
+ )
+ {
+ apply_visitor(visitor<OutputStream>(os), geometry);
+ }
+};
+
+
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH
 
@@ -335,7 +379,7 @@
             std::basic_ostream<Char, Traits>& os,
             wkt_manipulator const& m)
     {
- dispatch::wkt<Geometry>::apply(os, m.m_geometry);
+ dispatch::devarianted_wkt<Geometry>::apply(os, m.m_geometry);
         os.flush();
         return os;
     }

Modified: trunk/libs/geometry/test/io/wkt/wkt.cpp
==============================================================================
--- trunk/libs/geometry/test/io/wkt/wkt.cpp (original)
+++ trunk/libs/geometry/test/io/wkt/wkt.cpp 2013-01-13 12:25:15 EST (Sun, 13 Jan 2013)
@@ -30,6 +30,16 @@
 #include <boost/geometry/core/topological_dimension.hpp>
 #include <boost/geometry/io/wkt/read.hpp>
 #include <boost/geometry/io/wkt/write.hpp>
+#include <boost/variant/variant.hpp>
+
+template <typename G>
+void check_wkt(G const& geometry, std::string const& expected)
+{
+ std::ostringstream out;
+ out << bg::wkt(geometry);
+ BOOST_CHECK_EQUAL(boost::to_upper_copy(out.str()),
+ boost::to_upper_copy(expected));
+}
 
 template <typename G>
 void test_wkt(std::string const& wkt, std::size_t n, double len = 0,
@@ -57,10 +67,8 @@
         BOOST_CHECK_CLOSE(double(bg::perimeter(geometry)), peri, 0.0001);
     }
 
- std::ostringstream out;
- out << bg::wkt(geometry);
- BOOST_CHECK_EQUAL(boost::to_upper_copy(out.str()),
- boost::to_upper_copy(wkt));
+ check_wkt(geometry, wkt);
+ check_wkt(boost::variant<G>(geometry), wkt);
 }
 
 template <typename G>


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