From 89f64f6b9748293e4c1e8af1292104dec059b5de Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 29 Sep 2014 13:12:38 -0700 Subject: [PATCH] avoid spirit usage in function_call.hpp - refs #2439 --- include/mapnik/expression_grammar.hpp | 11 +++ include/mapnik/expression_grammar_impl.hpp | 23 +++++ include/mapnik/expression_node.hpp | 4 +- include/mapnik/function_call.hpp | 102 +++++++++++++++++--- src/function_call.cpp | 106 --------------------- 5 files changed, 124 insertions(+), 122 deletions(-) diff --git a/include/mapnik/expression_grammar.hpp b/include/mapnik/expression_grammar.hpp index 6342fe23a..fd8663bb8 100644 --- a/include/mapnik/expression_grammar.hpp +++ b/include/mapnik/expression_grammar.hpp @@ -126,6 +126,17 @@ struct integer_parser using type = qi::int_parser; }; +struct unary_function_types : qi::symbols +{ + unary_function_types(); +}; + +struct binary_function_types : qi::symbols +{ + binary_function_types(); +}; + + #ifdef __GNUC__ template struct MAPNIK_DECL expression_grammar : qi::grammar diff --git a/include/mapnik/expression_grammar_impl.hpp b/include/mapnik/expression_grammar_impl.hpp index 2a79b4fc3..8edb01313 100644 --- a/include/mapnik/expression_grammar_impl.hpp +++ b/include/mapnik/expression_grammar_impl.hpp @@ -28,6 +28,7 @@ #include #include #include +#include // boost #include @@ -43,6 +44,28 @@ namespace mapnik { namespace mapnik { +unary_function_types::unary_function_types() +{ + add + ("sin", sin_impl()) + ("cos", cos_impl()) + ("tan", tan_impl()) + ("atan", atan_impl()) + ("exp", exp_impl()) + ("abs", abs_impl()) + ("length",length_impl()) + ; +} + +binary_function_types::binary_function_types() +{ + add + ("min", binary_function_impl(min_impl)) + ("max", binary_function_impl(max_impl)) + ("pow", binary_function_impl(pow_impl)) + ; +} + template expr_node regex_match_impl::operator() (T0 & node, T1 const& pattern) const { diff --git a/include/mapnik/expression_node.hpp b/include/mapnik/expression_node.hpp index ac3a8fe27..95e5fc1fc 100644 --- a/include/mapnik/expression_node.hpp +++ b/include/mapnik/expression_node.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include // boost @@ -123,9 +124,6 @@ struct regex_replace_node }; #endif -using unary_function_impl = std::function; -using binary_function_impl = std::function; - struct unary_function_call { using argument_type = expr_node; diff --git a/include/mapnik/function_call.hpp b/include/mapnik/function_call.hpp index 236ad0361..5453d92af 100644 --- a/include/mapnik/function_call.hpp +++ b/include/mapnik/function_call.hpp @@ -24,28 +24,104 @@ #define MAPNIK_FUNCTION_CALL_HPP #include -#include #include -#include +#include +#include namespace mapnik { using value_type = mapnik::value; -namespace qi = boost::spirit::qi; -struct unary_function_types : qi::symbols -{ - unary_function_types(); -}; - -struct binary_function_types : qi::symbols -{ - binary_function_types(); -}; +using unary_function_impl = std::function; +using binary_function_impl = std::function; char const* unary_function_name(unary_function_impl const& fun); char const* binary_function_name(binary_function_impl const& fun); +// functions +// exp +struct exp_impl +{ + //using type = T; + value_type operator() (value_type const& val) const + { + return std::exp(val.to_double()); + } + +}; + +// sin +struct sin_impl +{ + value_type operator() (value_type const& val) const + { + return std::sin(val.to_double()); + } +}; + +// cos +struct cos_impl +{ + value_type operator() (value_type const& val) const + { + return std::cos(val.to_double()); + } +}; + +// tan +struct tan_impl +{ + value_type operator() (value_type const& val) const + { + return std::tan(val.to_double()); + } +}; + +// atan +struct atan_impl +{ + value_type operator()(value_type const& val) const + { + return std::atan(val.to_double()); + } +}; + +// abs +struct abs_impl +{ + value_type operator() (value_type const& val) const + { + return std::fabs(val.to_double()); + } +}; + +// length +struct length_impl +{ + value_type operator() (value_type const& val) const + { + return val.to_unicode().length(); + } +}; + +// min +inline value_type min_impl(value_type const& arg1, value_type const& arg2) +{ + return std::min(arg1.to_double(), arg2.to_double()); +} + +// max +inline value_type max_impl(value_type const& arg1, value_type const& arg2) +{ + return std::max(arg1.to_double(), arg2.to_double()); +} + +// pow +inline value_type pow_impl(value_type const& arg1, value_type const& arg2) +{ + return std::pow(arg1.to_double(), arg2.to_double()); +} + } // namespace mapnik -#endif //MAPNIK_FUNCTION_CALL_HPP +#endif // MAPNIK_FUNCTION_CALL_HPP diff --git a/src/function_call.cpp b/src/function_call.cpp index 6febc0bfc..99b1435d7 100644 --- a/src/function_call.cpp +++ b/src/function_call.cpp @@ -24,87 +24,6 @@ namespace mapnik { - -// functions -// exp -//template -struct exp_impl -{ - //using type = T; - value_type operator() (value_type const& val) const - { - return std::exp(val.to_double()); - } - -}; - -// sin -struct sin_impl -{ - value_type operator() (value_type const& val) const - { - return std::sin(val.to_double()); - } -}; - -// cos -struct cos_impl -{ - value_type operator() (value_type const& val) const - { - return std::cos(val.to_double()); - } -}; - -// tan -struct tan_impl -{ - value_type operator() (value_type const& val) const - { - return std::tan(val.to_double()); - } -}; - -// atan -struct atan_impl -{ - value_type operator()(value_type const& val) const - { - return std::atan(val.to_double()); - } -}; - -// abs -struct abs_impl -{ - value_type operator() (value_type const& val) const - { - return std::fabs(val.to_double()); - } -}; - -// length -struct length_impl -{ - value_type operator() (value_type const& val) const - { - return val.to_unicode().length(); - } -}; - -unary_function_types::unary_function_types() -{ - add - ("sin", sin_impl()) - ("cos", cos_impl()) - ("tan", tan_impl()) - ("atan", atan_impl()) - ("exp", exp_impl()) - ("abs", abs_impl()) - ("length",length_impl()) - ; -} - char const* unary_function_name(unary_function_impl const& fun) { if (fun.target()) return "sin"; @@ -118,31 +37,6 @@ char const* unary_function_name(unary_function_impl const& fun) } // binary functions -// min -inline value_type min_impl(value_type const& arg1, value_type const& arg2) -{ - return std::min(arg1.to_double(), arg2.to_double()); -} -// max -inline value_type max_impl(value_type const& arg1, value_type const& arg2) -{ - return std::max(arg1.to_double(), arg2.to_double()); -} -// pow -inline value_type pow_impl(value_type const& arg1, value_type const& arg2) -{ - return std::pow(arg1.to_double(), arg2.to_double()); -} - -binary_function_types::binary_function_types() -{ - add - ("min", binary_function_impl(min_impl)) - ("max", binary_function_impl(max_impl)) - ("pow", binary_function_impl(pow_impl)) - ; -} - char const* binary_function_name(binary_function_impl const& fun) { value_type(*const* f_ptr)(value_type const&, value_type const&) =