box2d<T> - update to use boost::spirit::x3

This commit is contained in:
artemp 2016-08-19 18:33:16 +01:00
parent 85a75af9c6
commit 45dd2754db
2 changed files with 27 additions and 18 deletions

View file

@ -51,11 +51,11 @@ template <typename T> class MAPNIK_DECL box2d
public:
using value_type = T;
using box2d_type = box2d<value_type>;
private:
T minx_;
T miny_;
T maxx_;
T maxy_;
private:
friend inline void swap(box2d_type & lhs, box2d_type & rhs)
{
using std::swap;

View file

@ -33,24 +33,30 @@
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/fusion/include/adapt_adt.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/support_adapt_adt_attributes.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/home/x3.hpp>
#pragma GCC diagnostic pop
// agg
#include "agg_trans_affine.h"
BOOST_FUSION_ADAPT_TPL_ADT(
BOOST_FUSION_ADAPT_TPL_STRUCT(
(T),
(mapnik::box2d)(T),
(T, T, obj.minx(), obj.set_minx(mapnik::safe_cast<T>(val)))
(T, T, obj.miny(), obj.set_miny(mapnik::safe_cast<T>(val)))
(T, T, obj.maxx(), obj.set_maxx(mapnik::safe_cast<T>(val)))
(T, T, obj.maxy(), obj.set_maxy(mapnik::safe_cast<T>(val))))
(T, minx_),
(T, miny_),
(T, maxx_),
(T, maxy_))
namespace mapnik {
namespace detail {
auto minx = [](auto& ctx) { _val(ctx) = _attr(ctx); };
auto miny = [](auto& ctx) { _val(ctx) = _attr(ctx); };
auto maxx = [](auto& ctx) { _val(ctx) = _attr(ctx); };
auto maxy = [](auto& ctx) { _val(ctx) = _attr(ctx); };
}
namespace mapnik
{
template <typename T>
box2d<T>::box2d()
:minx_( std::numeric_limits<T>::max()),
@ -61,13 +67,13 @@ box2d<T>::box2d()
template <typename T>
box2d<T>::box2d(T minx,T miny,T maxx,T maxy)
{
init(minx,miny,maxx,maxy);
init(minx, miny, maxx, maxy);
}
template <typename T>
box2d<T>::box2d(coord<T,2> const& c0, coord<T,2> const& c1)
{
init(c0.x,c0.y,c1.x,c1.y);
init(c0.x, c0.y, c1.x, c1.y);
}
template <typename T>
@ -350,12 +356,15 @@ void box2d<T>::pad(T padding)
template <typename T>
bool box2d<T>::from_string(std::string const& str)
{
boost::spirit::qi::lit_type lit;
boost::spirit::qi::double_type double_;
boost::spirit::ascii::space_type space;
bool r = boost::spirit::qi::phrase_parse(str.begin(),
using boost::spirit::x3::lit;
boost::spirit::x3::double_type double_;
boost::spirit::x3::ascii::space_type space;
bool r = boost::spirit::x3::phrase_parse(str.begin(),
str.end(),
double_ >> -lit(',') >> double_ >> -lit(',') >> double_ >> -lit(',') >> double_,
double_[detail::minx] >> -lit(',') >>
double_[detail::miny] >> -lit(',') >>
double_[detail::maxx] >> -lit(',') >>
double_[detail::maxy],
space,
*this);
return r;