add support for BOOST_VERSION < 106700

This commit is contained in:
Artem Pavlenko 2018-07-23 10:58:27 +01:00
parent 5fe0dda890
commit 65080e2a95
16 changed files with 182 additions and 47 deletions

View file

@ -24,7 +24,7 @@
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP
#include <mapnik/expression_node.hpp>
#include <mapnik/unicode.hpp>
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/spirit/home/x3.hpp>
@ -32,6 +32,13 @@
namespace mapnik { namespace grammar {
#if BOOST_VERSION >= 106700
using transcoder_type = mapnik::transcoder;
#else
using transcoder_type = std::reference_wrapper<mapnik::transcoder const>;
#endif
namespace x3 = boost::spirit::x3;
struct transcoder_tag;
struct expression_class; // top-most ID

View file

@ -24,7 +24,6 @@
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP
#include <mapnik/expression_grammar_x3.hpp>
#include <mapnik/unicode.hpp>
#include <string>
namespace mapnik { namespace grammar {
@ -32,10 +31,9 @@ namespace mapnik { namespace grammar {
namespace x3 = boost::spirit::x3;
using iterator_type = std::string::const_iterator;
using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;
// define combined context
using context_type = x3::context<transcoder_tag,
mapnik::transcoder const,
transcoder_type const,
phrase_context_type>;
}}

View file

@ -70,6 +70,16 @@ namespace mapnik { namespace grammar {
auto const& escaped_unicode = json::grammar::escaped_unicode;
}
template <typename Context>
inline mapnik::transcoder const& extract_transcoder(Context const& ctx)
{
#if BOOST_VERSION >= 106700
return x3::get<transcoder_tag>(ctx);
#else
return x3::get<transcoder_tag>(ctx).get();
#endif
}
auto append = [](auto const& ctx)
{
_val(ctx) += _attr(ctx);
@ -130,7 +140,7 @@ namespace mapnik { namespace grammar {
auto do_unicode = [] (auto const& ctx)
{
auto const& tr = x3::get<transcoder_tag>(ctx);
auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
};
@ -188,13 +198,13 @@ namespace mapnik { namespace grammar {
// regex
auto do_regex_match = [] (auto const& ctx)
{
auto const& tr = x3::get<transcoder_tag>(ctx);
auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)) , std::move(_attr(ctx))));
};
auto do_regex_replace = [] (auto const& ctx)
{
auto const& tr = x3::get<transcoder_tag>(ctx);
auto const& tr = extract_transcoder(ctx);
auto const& pair = _attr(ctx);
auto const& pattern = std::get<0>(pair);
auto const& format = std::get<1>(pair);

View file

@ -67,13 +67,24 @@ struct extract_positions
using box_type = mapnik::box2d<double>;
using boxes_type = std::vector<std::pair<box_type, std::pair<std::uint64_t, std::uint64_t>>>;
using callback_type = extract_positions<grammar::iterator_type, boxes_type>;
using box_type_f = mapnik::box2d<float>;
using boxes_type_f = std::vector<std::pair<box_type_f, std::pair<std::uint64_t, std::uint64_t>>>;
using callback_type_f = extract_positions<grammar::iterator_type, boxes_type_f>;
#if BOOST_VERSION >= 106700
using size_type = std::size_t;
using keys_map_type = keys_map;
using callback_type = extract_positions<grammar::iterator_type, boxes_type>;
using callback_type_f = extract_positions<grammar::iterator_type, boxes_type_f>;
#else
using size_type = std::reference_wrapper<std::size_t> const;
using keys_map_type = std::reference_wrapper<keys_map> const;
using callback_type = std::reference_wrapper<extract_positions<grammar::iterator_type, boxes_type>> const;
using callback_type_f = std::reference_wrapper<extract_positions<grammar::iterator_type, boxes_type_f>> const;
#endif
namespace grammar {
struct bracket_tag;
@ -85,26 +96,26 @@ using space_type = x3::standard::space_type;
using phrase_parse_context_type = x3::phrase_parse_context<space_type>::type;
using extract_bounding_boxes_context_type =
x3::context<bracket_tag, std::size_t,
x3::context<bracket_tag, size_type,
x3::context<feature_callback_tag, callback_type,
context_type>>;
using extract_bounding_boxes_reverse_context_type =
x3::context<keys_tag, keys_map,
x3::context<keys_tag, keys_map_type,
x3::context<feature_callback_tag, callback_type,
x3::context<bracket_tag, std::size_t,
x3::context<bracket_tag, size_type,
phrase_parse_context_type>>>;
using extract_bounding_boxes_context_type_f =
x3::context<bracket_tag, std::size_t,
x3::context<bracket_tag, size_type,
x3::context<feature_callback_tag, callback_type_f,
context_type>>;
using extract_bounding_boxes_reverse_context_type_f =
x3::context<keys_tag, keys_map,
x3::context<keys_tag, keys_map_type,
x3::context<feature_callback_tag, callback_type_f,
x3::context<bracket_tag, std::size_t,
x3::context<bracket_tag, size_type,
phrase_parse_context_type>>>;
}}}

View file

@ -90,23 +90,33 @@ struct feature_tag;
namespace x3 = boost::spirit::x3;
using space_type = x3::standard::space_type;
using iterator_type = char const*;
using phrase_parse_context_type = x3::phrase_parse_context<space_type>::type;
#if BOOST_VERSION >= 106700
using keys_map_type = keys_map;
using transcoder_type = mapnik::transcoder const;
using feature_impl_type = mapnik::feature_impl;
#else
using keys_map_type = std::reference_wrapper<keys_map> const;
using transcoder_type = std::reference_wrapper<mapnik::transcoder const> const;
using feature_impl_type = std::reference_wrapper<mapnik::feature_impl> const;
#endif
using context_type = x3::context<keys_tag,
keys_map,
keys_map_type,
phrase_parse_context_type>;
using feature_context_type = x3::context<transcoder_tag,
mapnik::transcoder const,
transcoder_type,
x3::context<feature_tag,
mapnik::feature_impl,
feature_impl_type,
phrase_parse_context_type>>;
// our spirit x3 grammars needs this one with changed order of feature_impl and transcoder (??)
using feature_context_const_type = x3::context<feature_tag,
mapnik::feature_impl,
feature_impl_type,
x3::context<transcoder_tag,
mapnik::transcoder const,
transcoder_type,
phrase_parse_context_type>>;
}}}

View file

@ -39,9 +39,17 @@ namespace x3 = boost::spirit::x3;
using space_type = x3::standard::space_type;
using iterator_type = char const*;
#if BOOST_VERSION >= 106700
using svg_converter_wrapper_type = svg_converter_type;
using relative_type = bool;
#else
using svg_converter_wrapper_type = std::reference_wrapper<svg_converter_type> const;
using relative_type = std::reference_wrapper<bool> const;
#endif
using phrase_parse_context_type = x3::phrase_parse_context<space_type>::type;
using svg_parse_context_type = x3::context<relative_tag, bool,
x3::context<svg_path_tag, svg_converter_type,
using svg_parse_context_type = x3::context<relative_tag, relative_type,
x3::context<svg_path_tag, svg_converter_wrapper_type,
phrase_parse_context_type>>;
inline double deg2rad(double deg) {return (M_PI * deg) / 180.0;}

View file

@ -34,6 +34,7 @@
namespace mapnik { namespace svg { namespace grammar {
namespace x3 = boost::spirit::x3;
using x3::lit;
@ -43,24 +44,51 @@ using x3::no_case;
using coord_type = std::tuple<double,double>;
#if BOOST_VERSION >= 106700
template <typename Context>
svg_converter_type & extract_path(Context const& ctx)
{
return x3::get<svg_path_tag>(ctx);
}
template <typename Context>
bool & extract_relative(Context const& ctx)
{
return x3::get<relative_tag>(ctx);
}
#else
template <typename Context>
svg_converter_type & extract_path(Context const& ctx)
{
return x3::get<svg_path_tag>(ctx).get();
}
template <typename Context>
bool & extract_relative(Context const& ctx)
{
return x3::get<relative_tag>(ctx).get();
}
#endif
auto const move_to = [] (auto const& ctx)
{
x3::get<svg_path_tag>(ctx).move_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get<relative_tag>(ctx));
extract_path(ctx).move_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get<relative_tag>(ctx));
};
auto const line_to = [] (auto const & ctx)
{
x3::get<svg_path_tag>(ctx).line_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get<relative_tag>(ctx));
extract_path(ctx).line_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get<relative_tag>(ctx));
};
auto const hline_to = [] (auto const& ctx)
{
x3::get<svg_path_tag>(ctx).hline_to(_attr(ctx), x3::get<relative_tag>(ctx));
extract_path(ctx).hline_to(_attr(ctx), x3::get<relative_tag>(ctx));
};
auto const vline_to = [] (auto const& ctx)
{
x3::get<svg_path_tag>(ctx).vline_to(_attr(ctx), x3::get<relative_tag>(ctx));
extract_path(ctx).vline_to(_attr(ctx), x3::get<relative_tag>(ctx));
};
auto const curve4 = [] (auto const& ctx)
@ -69,7 +97,7 @@ auto const curve4 = [] (auto const& ctx)
auto const& p0 = boost::fusion::at_c<0>(attr);
auto const& p1 = boost::fusion::at_c<1>(attr);
auto const& p2 = boost::fusion::at_c<2>(attr);
x3::get<svg_path_tag>(ctx).curve4(std::get<0>(p0),std::get<1>(p0),
extract_path(ctx).curve4(std::get<0>(p0),std::get<1>(p0),
std::get<0>(p1),std::get<1>(p1),
std::get<0>(p2),std::get<1>(p2),
x3::get<relative_tag>(ctx));
@ -80,7 +108,7 @@ auto const curve4_smooth = [] (auto const& ctx)
auto const& attr = _attr(ctx);
auto const& p0 = boost::fusion::at_c<0>(attr);
auto const& p1 = boost::fusion::at_c<1>(attr);
x3::get<svg_path_tag>(ctx).curve4(std::get<0>(p0),std::get<1>(p0),
extract_path(ctx).curve4(std::get<0>(p0),std::get<1>(p0),
std::get<0>(p1),std::get<1>(p1),
x3::get<relative_tag>(ctx));
};
@ -90,7 +118,7 @@ auto const curve3 = [] (auto const& ctx)
auto const& attr = _attr(ctx);
auto const& p0 = boost::fusion::at_c<0>(attr);
auto const& p1 = boost::fusion::at_c<1>(attr);
x3::get<svg_path_tag>(ctx).curve3(std::get<0>(p0),std::get<1>(p0),
extract_path(ctx).curve3(std::get<0>(p0),std::get<1>(p0),
std::get<0>(p1),std::get<1>(p1),
x3::get<relative_tag>(ctx));
};
@ -98,7 +126,7 @@ auto const curve3 = [] (auto const& ctx)
auto const curve3_smooth = [] (auto const& ctx)
{
auto const& attr = _attr(ctx);
x3::get<svg_path_tag>(ctx).curve3(std::get<0>(attr),std::get<1>(attr),
extract_path(ctx).curve3(std::get<0>(attr),std::get<1>(attr),
x3::get<relative_tag>(ctx));
};
@ -111,7 +139,7 @@ auto const arc_to = [] (auto & ctx)
int large_arc_flag = boost::fusion::at_c<2>(attr);
int sweep_flag = boost::fusion::at_c<3>(attr);
auto const& v = boost::fusion::at_c<4>(attr);
x3::get<svg_path_tag>(ctx).arc_to(std::get<0>(p),std::get<1>(p),
extract_path(ctx).arc_to(std::get<0>(p),std::get<1>(p),
deg2rad(angle), large_arc_flag, sweep_flag,
std::get<0>(v),std::get<1>(v),
x3::get<relative_tag>(ctx));
@ -119,17 +147,17 @@ auto const arc_to = [] (auto & ctx)
auto const close_path = [] (auto const& ctx)
{
x3::get<svg_path_tag>(ctx).close_subpath();
extract_path(ctx).close_subpath();
};
auto const relative = [] (auto const& ctx)
{
x3::get<relative_tag>(ctx) = true;
extract_relative(ctx) = true;
};
auto const absolute = [] (auto const& ctx)
{
x3::get<relative_tag>(ctx) = false;
extract_relative(ctx) = false;
};
// exported rules

View file

@ -44,9 +44,23 @@ using x3::lit;
using x3::double_;
using x3::no_case;
#if BOOST_VERSION >= 106700
template <typename Context>
auto & extract_transform(Context const& ctx)
{
return x3::get<svg_transform_tag>(ctx);
}
#else
template <typename Context>
auto & extract_transform(Context const& ctx)
{
return x3::get<svg_transform_tag>(ctx).get();
}
#endif
auto const matrix_action = [] (auto const& ctx)
{
auto & tr = x3::get<svg_transform_tag>(ctx);
auto & tr = extract_transform(ctx);
auto const& attr = _attr(ctx);
auto a = boost::fusion::at_c<0>(attr);
auto b = boost::fusion::at_c<1>(attr);
@ -59,7 +73,7 @@ auto const matrix_action = [] (auto const& ctx)
auto const rotate_action = [] (auto const& ctx)
{
auto & tr = x3::get<svg_transform_tag>(ctx);
auto & tr = extract_transform(ctx);
auto const& attr = _attr(ctx);
auto a = boost::fusion::at_c<0>(attr);
auto cx = boost::fusion::at_c<1>(attr) ? *boost::fusion::at_c<1>(attr) : 0.0;
@ -79,7 +93,7 @@ auto const rotate_action = [] (auto const& ctx)
auto const translate_action = [] (auto const& ctx)
{
auto & tr = x3::get<svg_transform_tag>(ctx);
auto & tr = extract_transform(ctx);
auto const& attr = _attr(ctx);
auto tx = boost::fusion::at_c<0>(attr);
auto ty = boost::fusion::at_c<1>(attr);
@ -89,7 +103,7 @@ auto const translate_action = [] (auto const& ctx)
auto const scale_action = [] (auto const& ctx)
{
auto & tr = x3::get<svg_transform_tag>(ctx);
auto & tr = extract_transform(ctx);
auto const& attr = _attr(ctx);
auto sx = boost::fusion::at_c<0>(attr);
auto sy = boost::fusion::at_c<1>(attr);
@ -99,14 +113,14 @@ auto const scale_action = [] (auto const& ctx)
auto const skewX_action = [] (auto const& ctx)
{
auto & tr = x3::get<svg_transform_tag>(ctx);
auto & tr = extract_transform(ctx);
auto skew_x = _attr(ctx);
tr = agg::trans_affine_skewing(deg2rad(skew_x), 0.0) * tr;
};
auto const skewY_action = [] (auto const& ctx)
{
auto & tr = x3::get<svg_transform_tag>(ctx);
auto & tr = extract_transform(ctx);
auto skew_y= _attr(ctx);
tr = agg::trans_affine_skewing(0.0, deg2rad(skew_y)) * tr;
};

View file

@ -35,11 +35,17 @@ expression_ptr parse_expression(std::string const& str)
auto node = std::make_shared<expr_node>();
using boost::spirit::x3::ascii::space;
mapnik::transcoder const tr("utf8");
#if BOOST_VERSION >=106700
auto parser = boost::spirit::x3::with<mapnik::grammar::transcoder_tag>(tr)
[
mapnik::expression_grammar()
];
#else
auto parser = boost::spirit::x3::with<mapnik::grammar::transcoder_tag>(std::ref(tr))
[
mapnik::expression_grammar()
];
#endif
bool r = false;
std::string::const_iterator itr = str.begin();
std::string::const_iterator const end = str.end();

View file

@ -185,12 +185,19 @@ void extract_bounding_boxes(Iterator& start, Iterator const& end, Boxes & boxes)
extract_positions<iterator_type, Boxes> callback(start, boxes);
auto keys = mapnik::json::get_keys();
std::size_t bracket_counter = 0;
#if BOOST_VERSION >= 106700
auto feature_collection_impl = x3::with<mapnik::json::grammar::bracket_tag>(bracket_counter)
[x3::with<mapnik::json::grammar::feature_callback_tag>(callback)
[x3::with<mapnik::json::grammar::keys_tag>(keys)
[mapnik::json::grammar::feature_collection]
]];
#else
auto feature_collection_impl = x3::with<mapnik::json::grammar::bracket_tag>(std::ref(bracket_counter))
[x3::with<mapnik::json::grammar::feature_callback_tag>(std::ref(callback))
[x3::with<mapnik::json::grammar::keys_tag>(std::ref(keys))
[mapnik::json::grammar::feature_collection]
]];
#endif
if (!x3::phrase_parse(start, end, feature_collection_impl, space_type()))
{
throw std::runtime_error("Can't extract bounding boxes");

View file

@ -31,9 +31,15 @@ void parse_feature(Iterator start, Iterator end, feature_impl& feature, mapnik::
{
namespace x3 = boost::spirit::x3;
using space_type = mapnik::json::grammar::space_type;
#if BOOST_VERSION >= 106700
auto grammar = x3::with<mapnik::json::grammar::transcoder_tag>(tr)
[x3::with<mapnik::json::grammar::feature_tag>(feature)
[ mapnik::json::feature_grammar() ]];
#else
auto grammar = x3::with<mapnik::json::grammar::transcoder_tag>(std::ref(tr))
[x3::with<mapnik::json::grammar::feature_tag>(std::ref(feature))
[ mapnik::json::feature_grammar() ]];
#endif
if (!x3::phrase_parse(start, end, grammar, space_type()))
{
throw std::runtime_error("Can't parser GeoJSON Feature");

View file

@ -37,10 +37,18 @@ transform_list_ptr parse_transform(std::string const& str, std::string const& en
std::string::const_iterator itr = str.begin();
std::string::const_iterator end = str.end();
mapnik::transcoder const tr(encoding);
#if BOOST_VERSION >= 106700
auto const parser = boost::spirit::x3::with<mapnik::grammar::transcoder_tag>(tr)
[
mapnik::transform_expression_grammar()
];
#else
auto const parser = boost::spirit::x3::with<mapnik::grammar::transcoder_tag>(std::ref(tr))
[
mapnik::transform_expression_grammar()
];
#endif
bool status = false;
try
{

View file

@ -40,10 +40,15 @@ bool parse_path(const char* wkt, PathType& p)
iterator_type last = wkt + std::strlen(wkt);
bool relative = false;
using space_type = mapnik::svg::grammar::space_type;
#if BOOST_VERSION >= 106700
auto const grammar = x3::with<mapnik::svg::grammar::svg_path_tag>(p)
[ x3::with<mapnik::svg::grammar::relative_tag>(relative)
[mapnik::svg::svg_path_grammar()]];
#else
auto const grammar = x3::with<mapnik::svg::grammar::svg_path_tag>(std::ref(p))
[ x3::with<mapnik::svg::grammar::relative_tag>(std::ref(relative))
[mapnik::svg::svg_path_grammar()]];
#endif
try
{
if (!x3::phrase_parse(first, last, grammar, space_type())

View file

@ -40,10 +40,15 @@ bool parse_points(const char* wkt, PathType& p)
iterator_type last = wkt + std::strlen(wkt);
bool relative = false;
#if BOOST_VERSION >= 106700
auto const grammar = x3::with<mapnik::svg::grammar::svg_path_tag>(p)
[ x3::with<mapnik::svg::grammar::relative_tag>(relative)
[mapnik::svg::svg_points_grammar()]];
#else
auto const grammar = x3::with<mapnik::svg::grammar::svg_path_tag>(std::ref(p))
[ x3::with<mapnik::svg::grammar::relative_tag>(std::ref(relative))
[mapnik::svg::svg_points_grammar()]];
#endif
try
{
if (!x3::phrase_parse(first, last, grammar, space_type())

View file

@ -37,9 +37,16 @@ bool parse_svg_transform(const char* wkt, Transform& tr)
iterator_type first = wkt;
iterator_type last = wkt + std::strlen(wkt);
using space_type = mapnik::svg::grammar::space_type;
#if BOOST_VERSION >= 106700
auto const grammar = x3::with<mapnik::svg::grammar::svg_transform_tag>(tr)
[mapnik::svg::svg_transform_grammar()];
#else
auto const grammar = x3::with<mapnik::svg::grammar::svg_transform_tag>(std::ref(tr))
[mapnik::svg::svg_transform_grammar()];
#endif
try
{
if (!x3::phrase_parse(first, last, grammar, space_type())

View file

@ -285,8 +285,13 @@ std::pair<bool,typename T::value_type::first_type> process_geojson_file_x3(T & b
using namespace boost::spirit;
using space_type = mapnik::json::grammar::space_type;
auto keys = mapnik::json::get_keys();
#if BOOST_VERSION >= 106700
auto feature_grammar = x3::with<mapnik::json::grammar::keys_tag>(keys)
[ geojson_value ];
#else
auto feature_grammar = x3::with<mapnik::json::grammar::keys_tag>(std::ref(keys))
[ geojson_value ];
#endif
for (auto const& item : boxes)
{
if (item.first.valid())