From 9b9e0f5b64f1e01d85009a17eaee1674fb8eff56 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 4 Mar 2016 10:25:03 +0100 Subject: [PATCH] update old boost::phoenix syntax --- include/mapnik/css_color_grammar.hpp | 21 +- include/mapnik/svg/svg_path_commands.hpp | 64 +--- include/mapnik/svg/svg_path_grammar.hpp | 2 +- include/mapnik/svg/svg_transform_grammar.hpp | 337 +++++++++---------- test/data-visual | 2 +- 5 files changed, 164 insertions(+), 262 deletions(-) diff --git a/include/mapnik/css_color_grammar.hpp b/include/mapnik/css_color_grammar.hpp index bababa3d4..9dff6a2a0 100644 --- a/include/mapnik/css_color_grammar.hpp +++ b/include/mapnik/css_color_grammar.hpp @@ -49,12 +49,7 @@ using ascii_space_type = boost::spirit::ascii::space_type; struct percent_conv_impl { - template - struct result - { - using type = unsigned; - }; - + using result_type = unsigned; unsigned operator() (double val) const { return safe_cast(std::lround((255.0 * val)/100.0)); @@ -63,12 +58,7 @@ struct percent_conv_impl struct alpha_conv_impl { - template - struct result - { - using type = unsigned; - }; - + using result_type = unsigned; unsigned operator() (double val) const { return safe_cast(std::lround((255.0 * val))); @@ -77,12 +67,7 @@ struct alpha_conv_impl struct hsl_conv_impl { - template - struct result - { - using type = void; - }; - + using result_type = void; template void operator() (T0 & c, T1 h, T2 s, T3 l) const { diff --git a/include/mapnik/svg/svg_path_commands.hpp b/include/mapnik/svg/svg_path_commands.hpp index cf69e13a5..0e75d5b22 100644 --- a/include/mapnik/svg/svg_path_commands.hpp +++ b/include/mapnik/svg/svg_path_commands.hpp @@ -47,13 +47,7 @@ inline double deg2rad(double deg) template struct move_to { - - template - struct result - { - using type = void; - }; - + using result_type = void; explicit move_to(PathType & path) : path_(path) {} @@ -69,12 +63,7 @@ struct move_to template struct hline_to { - template - struct result - { - using type = void; - }; - + using result_type = void; explicit hline_to(PathType & path) : path_(path) {} @@ -91,12 +80,7 @@ struct hline_to template struct vline_to { - template - struct result - { - using type = void; - }; - + using result_type = void; explicit vline_to(PathType & path) : path_(path) {} @@ -112,12 +96,7 @@ struct vline_to template struct line_to { - template - struct result - { - using type = void; - }; - + using result_type = void; explicit line_to(PathType & path) : path_(path) {} @@ -134,12 +113,7 @@ struct line_to template struct curve4 { - template - struct result - { - using type = void; - }; - + using result_type = void; explicit curve4(PathType & path) : path_(path) {} @@ -159,12 +133,7 @@ struct curve4 template struct curve4_smooth { - template - struct result - { - using type = void; - }; - + using result_type = void; explicit curve4_smooth(PathType & path) : path_(path) {} @@ -181,12 +150,7 @@ struct curve4_smooth template struct curve3 { - template - struct result - { - using type = void; - }; - + using result_type = void; explicit curve3(PathType & path) : path_(path) {} @@ -204,12 +168,7 @@ struct curve3 template struct curve3_smooth { - template - struct result - { - using type = void; - }; - + using result_type = void; explicit curve3_smooth(PathType & path) : path_(path) {} @@ -226,12 +185,7 @@ struct curve3_smooth template struct arc_to { - template - struct result - { - using type = void; - }; - + using result_type = void; explicit arc_to(PathType & path) : path_(path) {} diff --git a/include/mapnik/svg/svg_path_grammar.hpp b/include/mapnik/svg/svg_path_grammar.hpp index 93d27f10b..ac8a84bee 100644 --- a/include/mapnik/svg/svg_path_grammar.hpp +++ b/include/mapnik/svg/svg_path_grammar.hpp @@ -132,7 +132,7 @@ namespace mapnik { namespace svg { function > close_; }; - }} +}} #endif // MAPNIK_SVG_PATH_GRAMMAR_HPP diff --git a/include/mapnik/svg/svg_transform_grammar.hpp b/include/mapnik/svg/svg_transform_grammar.hpp index 1465f3a2a..e7cd37853 100644 --- a/include/mapnik/svg/svg_transform_grammar.hpp +++ b/include/mapnik/svg/svg_transform_grammar.hpp @@ -40,226 +40,189 @@ namespace mapnik { namespace svg { - using namespace boost::spirit; - using namespace boost::fusion; - using namespace boost::phoenix; +using namespace boost::spirit; +using namespace boost::fusion; +using namespace boost::phoenix; - inline double deg2rad(double d) +inline double deg2rad(double d) +{ + return M_PI * d / 180.0; +} + +template +struct process_matrix +{ + using result_type = void; + explicit process_matrix( TransformType & tr) + :tr_(tr) {} + + void operator () (double a, double b, double c, double d, double e, double f) const { - return M_PI * d / 180.0; + tr_ = agg::trans_affine(a,b,c,d,e,f) * tr_; } - template - struct process_matrix + TransformType & tr_; +}; + +template +struct process_rotate +{ + using result_type = void; + explicit process_rotate( TransformType & tr) + :tr_(tr) {} + + template + void operator () (T0 a, T1 cx, T2 cy) const { - template - struct result + if (cx == 0.0 && cy == 0.0) { - using type = void; - }; - - explicit process_matrix( TransformType & tr) - :tr_(tr) {} - - void operator () (double a, double b, double c, double d, double e, double f) const - { - tr_ = agg::trans_affine(a,b,c,d,e,f) * tr_; + tr_ = agg::trans_affine_rotation(deg2rad(a)) * tr_; } + else + { + agg::trans_affine t = agg::trans_affine_translation(-cx,-cy); + t *= agg::trans_affine_rotation(deg2rad(a)); + t *= agg::trans_affine_translation(cx, cy); + tr_ = t * tr_; + } + } - TransformType & tr_; - }; + TransformType & tr_; +}; - template - struct process_rotate +template +struct process_translate +{ + using result_type = void; + explicit process_translate( TransformType & tr) + :tr_(tr) {} + + template + void operator () (T0 tx, T1 ty) const { - template - struct result - { - using type = void; - }; + if (ty) tr_ = agg::trans_affine_translation(tx,*ty) * tr_; + else tr_ = agg::trans_affine_translation(tx,0.0) * tr_; + } - explicit process_rotate( TransformType & tr) - :tr_(tr) {} + TransformType & tr_; +}; - template - void operator () (T0 a, T1 cx, T2 cy) const - { - if (cx == 0.0 && cy == 0.0) - { - tr_ = agg::trans_affine_rotation(deg2rad(a)) * tr_; - } - else - { - agg::trans_affine t = agg::trans_affine_translation(-cx,-cy); - t *= agg::trans_affine_rotation(deg2rad(a)); - t *= agg::trans_affine_translation(cx, cy); - tr_ = t * tr_; - } - } +template +struct process_scale +{ + using result_type = void; + explicit process_scale( TransformType & tr) + :tr_(tr) {} - TransformType & tr_; - }; - - template - struct process_translate + template + void operator () (T0 sx, T1 sy) const { - template - struct result - { - using type = void; - }; + if (sy) tr_ = agg::trans_affine_scaling(sx,*sy) * tr_; + else tr_ = agg::trans_affine_scaling(sx,sx) * tr_; + } - explicit process_translate( TransformType & tr) - :tr_(tr) {} + TransformType & tr_; +}; - template - void operator () (T0 tx, T1 ty) const - { - if (ty) tr_ = agg::trans_affine_translation(tx,*ty) * tr_; - else tr_ = agg::trans_affine_translation(tx,0.0) * tr_; - } - TransformType & tr_; - }; +template +struct process_skew +{ + using result_type = void; + explicit process_skew( TransformType & tr) + :tr_(tr) {} - template - struct process_scale + template + void operator () (T0 skew_x, T1 skew_y) const { - template - struct result - { - using type = void; - }; + tr_ = agg::trans_affine_skewing(deg2rad(skew_x),deg2rad(skew_y)) * tr_; + } - explicit process_scale( TransformType & tr) - :tr_(tr) {} + TransformType & tr_; +}; - template - void operator () (T0 sx, T1 sy) const - { - if (sy) tr_ = agg::trans_affine_scaling(sx,*sy) * tr_; - else tr_ = agg::trans_affine_scaling(sx,sx) * tr_; - } - - TransformType & tr_; - }; - - - template - struct process_skew +template +struct svg_transform_grammar : qi::grammar +{ + explicit svg_transform_grammar(TransformType & tr) + : svg_transform_grammar::base_type(start), + matrix_action(process_matrix(tr)), + rotate_action(process_rotate(tr)), + translate_action(process_translate(tr)), + scale_action(process_scale(tr)), + skew_action(process_skew(tr)) { - template - struct result - { - using type = void; - }; + qi::_1_type _1; + qi::_2_type _2; + qi::_3_type _3; + qi::_4_type _4; + qi::_5_type _5; + qi::_6_type _6; + qi::_a_type _a; + qi::_b_type _b; + qi::_c_type _c; + qi::lit_type lit; + qi::double_type double_; + qi::no_case_type no_case; - explicit process_skew( TransformType & tr) - :tr_(tr) {} + start = +transform_ ; - template - void operator () (T0 skew_x, T1 skew_y) const - { - tr_ = agg::trans_affine_skewing(deg2rad(skew_x),deg2rad(skew_y)) * tr_; - } + transform_ = matrix | rotate | translate | scale | rotate | skewX | skewY ; - TransformType & tr_; - }; + matrix = no_case[lit("matrix")] + >> lit('(') + >> ( + double_ >> -lit(',') + >> double_ >> -lit(',') + >> double_ >> -lit(',') + >> double_ >> -lit(',') + >> double_ >> -lit(',') + >> double_) [ matrix_action(_1,_2,_3,_4,_5,_6) ] + >> lit(')') + ; - // commented as this does not appear used and crashes clang when used with pch - /* - struct print_action - { - template - void operator()(T const& c, qi::unused_type, qi::unused_type) const - { - MAPNIK_LOG_DEBUG(svg) << typeid(c).name(); - } - }; - */ + translate = no_case[lit("translate")] + >> lit('(') + >> (double_ >> -lit(',') + >> -double_) [ translate_action(_1,_2) ] + >> lit(')'); - template - struct svg_transform_grammar : qi::grammar - { - explicit svg_transform_grammar(TransformType & tr) - : svg_transform_grammar::base_type(start), - matrix_action(process_matrix(tr)), - rotate_action(process_rotate(tr)), - translate_action(process_translate(tr)), - scale_action(process_scale(tr)), - skew_action(process_skew(tr)) - { - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::_5_type _5; - qi::_6_type _6; - qi::_a_type _a; - qi::_b_type _b; - qi::_c_type _c; - qi::lit_type lit; - qi::double_type double_; - qi::no_case_type no_case; + scale = no_case[lit("scale")] + >> lit('(') + >> (double_ >> -lit(',') + >> -double_ )[ scale_action(_1,_2)] + >> lit(')'); - start = +transform_ ; + rotate = no_case[lit("rotate")] + >> lit('(') + >> double_[_a = _1] >> -lit(',') + >> -(double_ [_b = _1] >> -lit(',') >> double_[_c = _1]) + >> lit(')') [ rotate_action(_a,_b,_c)]; - transform_ = matrix | rotate | translate | scale | rotate | skewX | skewY ; + skewX = no_case[lit("skewX")] >> lit('(') >> double_ [ skew_action(_1, 0.0)] >> lit(')'); - matrix = no_case[lit("matrix")] - >> lit('(') - >> ( - double_ >> -lit(',') - >> double_ >> -lit(',') - >> double_ >> -lit(',') - >> double_ >> -lit(',') - >> double_ >> -lit(',') - >> double_) [ matrix_action(_1,_2,_3,_4,_5,_6) ] - >> lit(')') - ; + skewY = no_case[lit("skewY")] >> lit('(') >> double_ [ skew_action(0.0, _1)] >> lit(')'); - translate = no_case[lit("translate")] - >> lit('(') - >> (double_ >> -lit(',') - >> -double_) [ translate_action(_1,_2) ] - >> lit(')'); + } - scale = no_case[lit("scale")] - >> lit('(') - >> (double_ >> -lit(',') - >> -double_ )[ scale_action(_1,_2)] - >> lit(')'); + // rules + qi::rule start; + qi::rule transform_; + qi::rule matrix; + qi::rule translate; + qi::rule scale; + qi::rule, SkipType> rotate; + qi::rule skewX; + qi::rule skewY; - rotate = no_case[lit("rotate")] - >> lit('(') - >> double_[_a = _1] >> -lit(',') - >> -(double_ [_b = _1] >> -lit(',') >> double_[_c = _1]) - >> lit(')') [ rotate_action(_a,_b,_c)]; + // actions + function > matrix_action; + function > rotate_action; + function > translate_action; + function > scale_action; + function > skew_action; +}; - skewX = no_case[lit("skewX")] >> lit('(') >> double_ [ skew_action(_1, 0.0)] >> lit(')'); - - skewY = no_case[lit("skewY")] >> lit('(') >> double_ [ skew_action(0.0, _1)] >> lit(')'); - - } - - // rules - qi::rule start; - qi::rule transform_; - qi::rule matrix; - qi::rule translate; - qi::rule scale; - qi::rule, SkipType> rotate; - qi::rule skewX; - qi::rule skewY; - - // actions - function > matrix_action; - function > rotate_action; - function > translate_action; - function > scale_action; - function > skew_action; - }; - - }} +}} #endif // MAPNIK_SVG_TRANSFORM_GRAMMAR_HPP diff --git a/test/data-visual b/test/data-visual index 93e70a5ae..cc17060aa 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 93e70a5ae91b2bd4b8fc3912a7e6e4b017021b2b +Subproject commit cc17060aaeb459fd5ed3f8c50ef66bfd461585ab