mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-09 23:24:02 +00:00
Made wkt write variant-aware.
[SVN r82481]
This commit is contained in:
parent
d575690df3
commit
2da1ca09d1
@ -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 @@ struct wkt<Polygon, polygon_tag>
|
||||
{};
|
||||
|
||||
|
||||
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 @@ public:
|
||||
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;
|
||||
}
|
||||
|
@ -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 @@ void test_wkt(std::string const& wkt, std::size_t n, double len = 0,
|
||||
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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user