From 65080e2a9570d504bf676fd31fd6f0d9879ad6c7 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 23 Jul 2018 10:58:27 +0100 Subject: [PATCH] add support for BOOST_VERSION < 106700 --- include/mapnik/expression_grammar_x3.hpp | 9 +++- .../mapnik/expression_grammar_x3_config.hpp | 4 +- include/mapnik/expression_grammar_x3_def.hpp | 16 ++++-- .../json/extract_bounding_boxes_x3_config.hpp | 27 +++++++--- include/mapnik/json/json_grammar_config.hpp | 22 +++++--- include/mapnik/svg/svg_grammar_config_x3.hpp | 12 ++++- .../mapnik/svg/svg_path_grammar_x3_def.hpp | 52 ++++++++++++++----- .../svg/svg_transform_grammar_x3_def.hpp | 26 +++++++--- src/expression.cpp | 8 ++- src/json/extract_bounding_boxes_x3.cpp | 9 +++- src/json/parse_feature.cpp | 8 ++- src/parse_transform.cpp | 8 +++ src/svg/svg_path_parser.cpp | 7 ++- src/svg/svg_points_parser.cpp | 7 ++- src/svg/svg_transform_parser.cpp | 9 +++- .../mapnik-index/process_geojson_file_x3.cpp | 5 ++ 16 files changed, 182 insertions(+), 47 deletions(-) diff --git a/include/mapnik/expression_grammar_x3.hpp b/include/mapnik/expression_grammar_x3.hpp index 34de5c1dd..ffc487645 100644 --- a/include/mapnik/expression_grammar_x3.hpp +++ b/include/mapnik/expression_grammar_x3.hpp @@ -24,7 +24,7 @@ #define MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP #include - +#include #pragma GCC diagnostic push #include #include @@ -32,6 +32,13 @@ namespace mapnik { namespace grammar { +#if BOOST_VERSION >= 106700 +using transcoder_type = mapnik::transcoder; +#else +using transcoder_type = std::reference_wrapper; +#endif + + namespace x3 = boost::spirit::x3; struct transcoder_tag; struct expression_class; // top-most ID diff --git a/include/mapnik/expression_grammar_x3_config.hpp b/include/mapnik/expression_grammar_x3_config.hpp index 3de3e27c4..f8738f320 100644 --- a/include/mapnik/expression_grammar_x3_config.hpp +++ b/include/mapnik/expression_grammar_x3_config.hpp @@ -24,7 +24,6 @@ #define MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP #include -#include #include 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::type; - // define combined context using context_type = x3::context; }} diff --git a/include/mapnik/expression_grammar_x3_def.hpp b/include/mapnik/expression_grammar_x3_def.hpp index e3944ff2b..70dc2411d 100644 --- a/include/mapnik/expression_grammar_x3_def.hpp +++ b/include/mapnik/expression_grammar_x3_def.hpp @@ -70,6 +70,16 @@ namespace mapnik { namespace grammar { auto const& escaped_unicode = json::grammar::escaped_unicode; } + template + inline mapnik::transcoder const& extract_transcoder(Context const& ctx) + { +#if BOOST_VERSION >= 106700 + return x3::get(ctx); +#else + return x3::get(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(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(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(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); diff --git a/include/mapnik/json/extract_bounding_boxes_x3_config.hpp b/include/mapnik/json/extract_bounding_boxes_x3_config.hpp index eb7eb4193..40455423d 100644 --- a/include/mapnik/json/extract_bounding_boxes_x3_config.hpp +++ b/include/mapnik/json/extract_bounding_boxes_x3_config.hpp @@ -67,13 +67,24 @@ struct extract_positions using box_type = mapnik::box2d; using boxes_type = std::vector>>; -using callback_type = extract_positions; + using box_type_f = mapnik::box2d; using boxes_type_f = std::vector>>; -using callback_type_f = extract_positions; +#if BOOST_VERSION >= 106700 +using size_type = std::size_t; +using keys_map_type = keys_map; +using callback_type = extract_positions; +using callback_type_f = extract_positions; +#else +using size_type = std::reference_wrapper const; +using keys_map_type = std::reference_wrapper const; +using callback_type = std::reference_wrapper> const; +using callback_type_f = std::reference_wrapper> 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::type; using extract_bounding_boxes_context_type = - x3::context>; using extract_bounding_boxes_reverse_context_type = - x3::context>>; using extract_bounding_boxes_context_type_f = - x3::context>; using extract_bounding_boxes_reverse_context_type_f = - x3::context>>; }}} diff --git a/include/mapnik/json/json_grammar_config.hpp b/include/mapnik/json/json_grammar_config.hpp index ebd2977ff..82a21ff20 100644 --- a/include/mapnik/json/json_grammar_config.hpp +++ b/include/mapnik/json/json_grammar_config.hpp @@ -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::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 const; +using transcoder_type = std::reference_wrapper const; +using feature_impl_type = std::reference_wrapper const; +#endif + using context_type = x3::context; using feature_context_type = x3::context>; // our spirit x3 grammars needs this one with changed order of feature_impl and transcoder (??) using feature_context_const_type = x3::context>; }}} diff --git a/include/mapnik/svg/svg_grammar_config_x3.hpp b/include/mapnik/svg/svg_grammar_config_x3.hpp index c60595572..391b34420 100644 --- a/include/mapnik/svg/svg_grammar_config_x3.hpp +++ b/include/mapnik/svg/svg_grammar_config_x3.hpp @@ -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 const; +using relative_type = std::reference_wrapper const; +#endif + using phrase_parse_context_type = x3::phrase_parse_context::type; -using svg_parse_context_type = x3::context>; inline double deg2rad(double deg) {return (M_PI * deg) / 180.0;} diff --git a/include/mapnik/svg/svg_path_grammar_x3_def.hpp b/include/mapnik/svg/svg_path_grammar_x3_def.hpp index dab035bdc..250f7e1b0 100644 --- a/include/mapnik/svg/svg_path_grammar_x3_def.hpp +++ b/include/mapnik/svg/svg_path_grammar_x3_def.hpp @@ -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; +#if BOOST_VERSION >= 106700 + +template +svg_converter_type & extract_path(Context const& ctx) +{ + return x3::get(ctx); +} + +template +bool & extract_relative(Context const& ctx) +{ + return x3::get(ctx); +} + +#else +template +svg_converter_type & extract_path(Context const& ctx) +{ + return x3::get(ctx).get(); +} +template +bool & extract_relative(Context const& ctx) +{ + return x3::get(ctx).get(); +} +#endif + auto const move_to = [] (auto const& ctx) { - x3::get(ctx).move_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get(ctx)); + extract_path(ctx).move_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get(ctx)); }; auto const line_to = [] (auto const & ctx) { - x3::get(ctx).line_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get(ctx)); + extract_path(ctx).line_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get(ctx)); }; auto const hline_to = [] (auto const& ctx) { - x3::get(ctx).hline_to(_attr(ctx), x3::get(ctx)); + extract_path(ctx).hline_to(_attr(ctx), x3::get(ctx)); }; auto const vline_to = [] (auto const& ctx) { - x3::get(ctx).vline_to(_attr(ctx), x3::get(ctx)); + extract_path(ctx).vline_to(_attr(ctx), x3::get(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(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(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(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(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(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(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(ctx).curve3(std::get<0>(attr),std::get<1>(attr), + extract_path(ctx).curve3(std::get<0>(attr),std::get<1>(attr), x3::get(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(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(ctx)); @@ -119,17 +147,17 @@ auto const arc_to = [] (auto & ctx) auto const close_path = [] (auto const& ctx) { - x3::get(ctx).close_subpath(); + extract_path(ctx).close_subpath(); }; auto const relative = [] (auto const& ctx) { - x3::get(ctx) = true; + extract_relative(ctx) = true; }; auto const absolute = [] (auto const& ctx) { - x3::get(ctx) = false; + extract_relative(ctx) = false; }; // exported rules diff --git a/include/mapnik/svg/svg_transform_grammar_x3_def.hpp b/include/mapnik/svg/svg_transform_grammar_x3_def.hpp index b3b7ebe47..d6ea30be2 100644 --- a/include/mapnik/svg/svg_transform_grammar_x3_def.hpp +++ b/include/mapnik/svg/svg_transform_grammar_x3_def.hpp @@ -44,9 +44,23 @@ using x3::lit; using x3::double_; using x3::no_case; +#if BOOST_VERSION >= 106700 +template +auto & extract_transform(Context const& ctx) +{ + return x3::get(ctx); +} +#else +template +auto & extract_transform(Context const& ctx) +{ + return x3::get(ctx).get(); +} +#endif + auto const matrix_action = [] (auto const& ctx) { - auto & tr = x3::get(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(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(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(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(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(ctx); + auto & tr = extract_transform(ctx); auto skew_y= _attr(ctx); tr = agg::trans_affine_skewing(0.0, deg2rad(skew_y)) * tr; }; diff --git a/src/expression.cpp b/src/expression.cpp index ad87eb5ec..9c7c6c710 100644 --- a/src/expression.cpp +++ b/src/expression.cpp @@ -35,11 +35,17 @@ expression_ptr parse_expression(std::string const& str) auto node = std::make_shared(); using boost::spirit::x3::ascii::space; mapnik::transcoder const tr("utf8"); +#if BOOST_VERSION >=106700 auto parser = boost::spirit::x3::with(tr) [ mapnik::expression_grammar() ]; - +#else + auto parser = boost::spirit::x3::with(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(); diff --git a/src/json/extract_bounding_boxes_x3.cpp b/src/json/extract_bounding_boxes_x3.cpp index af9367ebe..c1c073d27 100644 --- a/src/json/extract_bounding_boxes_x3.cpp +++ b/src/json/extract_bounding_boxes_x3.cpp @@ -185,12 +185,19 @@ void extract_bounding_boxes(Iterator& start, Iterator const& end, Boxes & boxes) extract_positions 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(bracket_counter) [x3::with(callback) [x3::with(keys) [mapnik::json::grammar::feature_collection] ]]; - +#else + auto feature_collection_impl = x3::with(std::ref(bracket_counter)) + [x3::with(std::ref(callback)) + [x3::with(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"); diff --git a/src/json/parse_feature.cpp b/src/json/parse_feature.cpp index 6530377b4..9155ee306 100644 --- a/src/json/parse_feature.cpp +++ b/src/json/parse_feature.cpp @@ -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(tr) [x3::with(feature) - [ mapnik::json::feature_grammar() ]]; + [ mapnik::json::feature_grammar() ]]; +#else + auto grammar = x3::with(std::ref(tr)) + [x3::with(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"); diff --git a/src/parse_transform.cpp b/src/parse_transform.cpp index 3d2e5e0e4..b4daa8458 100644 --- a/src/parse_transform.cpp +++ b/src/parse_transform.cpp @@ -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(tr) [ mapnik::transform_expression_grammar() ]; +#else + auto const parser = boost::spirit::x3::with(std::ref(tr)) + [ + mapnik::transform_expression_grammar() + ]; +#endif + bool status = false; try { diff --git a/src/svg/svg_path_parser.cpp b/src/svg/svg_path_parser.cpp index 390b80da6..29c9b27ae 100644 --- a/src/svg/svg_path_parser.cpp +++ b/src/svg/svg_path_parser.cpp @@ -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(p) [ x3::with(relative) [mapnik::svg::svg_path_grammar()]]; - +#else + auto const grammar = x3::with(std::ref(p)) + [ x3::with(std::ref(relative)) + [mapnik::svg::svg_path_grammar()]]; +#endif try { if (!x3::phrase_parse(first, last, grammar, space_type()) diff --git a/src/svg/svg_points_parser.cpp b/src/svg/svg_points_parser.cpp index 2fd68734c..5e21ce4c8 100644 --- a/src/svg/svg_points_parser.cpp +++ b/src/svg/svg_points_parser.cpp @@ -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(p) [ x3::with(relative) [mapnik::svg::svg_points_grammar()]]; - +#else + auto const grammar = x3::with(std::ref(p)) + [ x3::with(std::ref(relative)) + [mapnik::svg::svg_points_grammar()]]; +#endif try { if (!x3::phrase_parse(first, last, grammar, space_type()) diff --git a/src/svg/svg_transform_parser.cpp b/src/svg/svg_transform_parser.cpp index e1ecf5639..e7f8863f3 100644 --- a/src/svg/svg_transform_parser.cpp +++ b/src/svg/svg_transform_parser.cpp @@ -37,8 +37,15 @@ 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(tr) - [mapnik::svg::svg_transform_grammar()]; + [mapnik::svg::svg_transform_grammar()]; + +#else + auto const grammar = x3::with(std::ref(tr)) + [mapnik::svg::svg_transform_grammar()]; +#endif try { diff --git a/utils/mapnik-index/process_geojson_file_x3.cpp b/utils/mapnik-index/process_geojson_file_x3.cpp index 62f5ccdea..4f12adbdf 100644 --- a/utils/mapnik-index/process_geojson_file_x3.cpp +++ b/utils/mapnik-index/process_geojson_file_x3.cpp @@ -285,8 +285,13 @@ std::pair 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(keys) [ geojson_value ]; +#else + auto feature_grammar = x3::with(std::ref(keys)) + [ geojson_value ]; +#endif for (auto const& item : boxes) { if (item.first.valid())