avoid spirit usage in function_call.hpp - refs #2439
This commit is contained in:
parent
8ff17378a4
commit
89f64f6b97
5 changed files with 124 additions and 122 deletions
|
@ -126,6 +126,17 @@ struct integer_parser
|
||||||
using type = qi::int_parser<T,10,1,-1>;
|
using type = qi::int_parser<T,10,1,-1>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct unary_function_types : qi::symbols<char, unary_function_impl>
|
||||||
|
{
|
||||||
|
unary_function_types();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct binary_function_types : qi::symbols<char, binary_function_impl>
|
||||||
|
{
|
||||||
|
binary_function_types();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
struct MAPNIK_DECL expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
|
struct MAPNIK_DECL expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <mapnik/expression_grammar.hpp>
|
#include <mapnik/expression_grammar.hpp>
|
||||||
#include <mapnik/unicode.hpp>
|
#include <mapnik/unicode.hpp>
|
||||||
#include <mapnik/value_types.hpp>
|
#include <mapnik/value_types.hpp>
|
||||||
|
#include <mapnik/function_call.hpp>
|
||||||
|
|
||||||
// boost
|
// boost
|
||||||
#include <boost/spirit/include/qi.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
|
@ -43,6 +44,28 @@ namespace mapnik {
|
||||||
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 <typename T0,typename T1>
|
template <typename T0,typename T1>
|
||||||
expr_node regex_match_impl::operator() (T0 & node, T1 const& pattern) const
|
expr_node regex_match_impl::operator() (T0 & node, T1 const& pattern) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <mapnik/value_types.hpp>
|
#include <mapnik/value_types.hpp>
|
||||||
#include <mapnik/value.hpp>
|
#include <mapnik/value.hpp>
|
||||||
#include <mapnik/attribute.hpp>
|
#include <mapnik/attribute.hpp>
|
||||||
|
#include <mapnik/function_call.hpp>
|
||||||
#include <mapnik/expression_node_types.hpp>
|
#include <mapnik/expression_node_types.hpp>
|
||||||
|
|
||||||
// boost
|
// boost
|
||||||
|
@ -123,9 +124,6 @@ struct regex_replace_node
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using unary_function_impl = std::function<value_type(value_type const&)>;
|
|
||||||
using binary_function_impl = std::function<value_type(value_type const&, value_type const&)>;
|
|
||||||
|
|
||||||
struct unary_function_call
|
struct unary_function_call
|
||||||
{
|
{
|
||||||
using argument_type = expr_node;
|
using argument_type = expr_node;
|
||||||
|
|
|
@ -24,28 +24,104 @@
|
||||||
#define MAPNIK_FUNCTION_CALL_HPP
|
#define MAPNIK_FUNCTION_CALL_HPP
|
||||||
|
|
||||||
#include <mapnik/value.hpp>
|
#include <mapnik/value.hpp>
|
||||||
#include <mapnik/expression_node.hpp>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/spirit/include/qi_symbols.hpp>
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
using value_type = mapnik::value;
|
using value_type = mapnik::value;
|
||||||
namespace qi = boost::spirit::qi;
|
|
||||||
|
|
||||||
struct unary_function_types : qi::symbols<char, unary_function_impl>
|
using unary_function_impl = std::function<value_type(value_type const&)>;
|
||||||
{
|
using binary_function_impl = std::function<value_type(value_type const&, value_type const&)>;
|
||||||
unary_function_types();
|
|
||||||
};
|
|
||||||
|
|
||||||
struct binary_function_types : qi::symbols<char, binary_function_impl>
|
|
||||||
{
|
|
||||||
binary_function_types();
|
|
||||||
};
|
|
||||||
|
|
||||||
char const* unary_function_name(unary_function_impl const& fun);
|
char const* unary_function_name(unary_function_impl const& fun);
|
||||||
char const* binary_function_name(binary_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
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif //MAPNIK_FUNCTION_CALL_HPP
|
#endif // MAPNIK_FUNCTION_CALL_HPP
|
||||||
|
|
|
@ -24,87 +24,6 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
|
|
||||||
// functions
|
|
||||||
// exp
|
|
||||||
//template <typename T>
|
|
||||||
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)
|
char const* unary_function_name(unary_function_impl const& fun)
|
||||||
{
|
{
|
||||||
if (fun.target<sin_impl>()) return "sin";
|
if (fun.target<sin_impl>()) return "sin";
|
||||||
|
@ -118,31 +37,6 @@ char const* unary_function_name(unary_function_impl const& fun)
|
||||||
}
|
}
|
||||||
|
|
||||||
// binary functions
|
// 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)
|
char const* binary_function_name(binary_function_impl const& fun)
|
||||||
{
|
{
|
||||||
value_type(*const* f_ptr)(value_type const&, value_type const&) =
|
value_type(*const* f_ptr)(value_type const&, value_type const&) =
|
||||||
|
|
Loading…
Reference in a new issue