From 3422472c7d103990583557976f553309f1673f10 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Fri, 8 Nov 2024 09:53:43 +0000 Subject: [PATCH] Add `int()`,'float()` and `str()` implicit conversions ref #4477. --- include/mapnik/expression_grammar_x3_def.hpp | 19 +++++++++++-------- include/mapnik/function_call.hpp | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/mapnik/expression_grammar_x3_def.hpp b/include/mapnik/expression_grammar_x3_def.hpp index 690224b8f..7fb82a982 100644 --- a/include/mapnik/expression_grammar_x3_def.hpp +++ b/include/mapnik/expression_grammar_x3_def.hpp @@ -209,14 +209,17 @@ struct unary_function_types_ : x3::symbols { unary_function_types_() { - add("sin", sin_impl()) // - ("cos", cos_impl()) // - ("tan", tan_impl()) // - ("atan", atan_impl()) // - ("exp", exp_impl()) // - ("log", log_impl()) // - ("abs", abs_impl()) // - ("length", length_impl()) // + add("sin", sin_impl()) // + ("cos", cos_impl()) // + ("tan", tan_impl()) // + ("atan", atan_impl()) // + ("exp", exp_impl()) // + ("log", log_impl()) // + ("abs", abs_impl()) // + ("length", length_impl()) // + ("int", int_impl()) // + ("float", float_impl()) // + ("str", str_impl()) // ; } } const unary_func_types; diff --git a/include/mapnik/function_call.hpp b/include/mapnik/function_call.hpp index 62e8a401d..91399e376 100644 --- a/include/mapnik/function_call.hpp +++ b/include/mapnik/function_call.hpp @@ -89,6 +89,25 @@ struct length_impl value_type operator()(value_type const& val) const { return val.to_unicode().length(); } }; +// str +struct str_impl +{ + value_type operator()(value_type const& val) const { return val.to_unicode(); } +}; + +// int +struct int_impl +{ + value_type operator()(value_type const& val) const { return val.to_int(); } +}; + +// float +struct float_impl +{ + value_type operator()(value_type const& val) const { return val.to_double(); } +}; + + // min inline value_type min_impl(value_type const& arg1, value_type const& arg2) {