/***************************************************************************** * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2015 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef MAPNIK_EXPRESSION_NODE_HPP #define MAPNIK_EXPRESSION_NODE_HPP // mapnik #include #include #include #include #include #include #include // stl #include namespace mapnik { using value_type = mapnik::value; template struct make_op; template <> struct make_op { using type = std::negate;}; template <> struct make_op { using type = std::plus;}; template <> struct make_op { using type = std::minus;}; template <> struct make_op { using type = std::multiplies;}; template <> struct make_op { using type = std::divides;}; template <> struct make_op { using type = std::modulus;}; template <> struct make_op { using type = std::less;}; template <> struct make_op { using type = std::less_equal;}; template <> struct make_op { using type = std::greater;}; template <> struct make_op { using type = std::greater_equal;}; template <> struct make_op { using type = std::equal_to;}; template <> struct make_op { using type = std::not_equal_to;}; template <> struct make_op { using type = std::logical_not;}; template <> struct make_op { using type = std::logical_and;}; template <> struct make_op { using type = std::logical_or;}; template struct unary_node { unary_node (expr_node const& a) : expr(a) {} static const char* type() { return Tag::str(); } expr_node expr; }; template struct binary_node { binary_node(expr_node const& a, expr_node const& b) : left(a), right(b) {} static const char* type() { return Tag::str(); } expr_node left,right; }; struct unary_function_call { using argument_type = expr_node; unary_function_call() = default; unary_function_call(unary_function_impl _fun, argument_type const& _arg) : fun(_fun), arg(_arg) {} unary_function_impl fun; argument_type arg; }; struct binary_function_call { using argument_type = expr_node; binary_function_call() = default; binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2) : fun(_fun), arg1(_arg1), arg2(_arg2) {} binary_function_impl fun; argument_type arg1; argument_type arg2; }; // pimpl struct _regex_match_impl; struct _regex_replace_impl; struct MAPNIK_DECL regex_match_node { regex_match_node(transcoder const& tr, expr_node const& a, std::string const& ustr); mapnik::value apply(mapnik::value const& v) const; std::string to_string() const; expr_node expr; // TODO - use unique_ptr once https://github.com/mapnik/mapnik/issues/2457 is fixed std::shared_ptr<_regex_match_impl> impl_; }; struct MAPNIK_DECL regex_replace_node { regex_replace_node(transcoder const& tr, expr_node const& a, std::string const& ustr, std::string const& f); mapnik::value apply(mapnik::value const& v) const; std::string to_string() const; expr_node expr; // TODO - use unique_ptr once https://github.com/mapnik/mapnik/issues/2457 is fixed std::shared_ptr<_regex_replace_impl> impl_; }; inline expr_node & operator- (expr_node& expr) { return expr = unary_node(expr); } inline expr_node & operator += ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator -= ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator *= ( expr_node &left , expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator /= ( expr_node &left , expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator %= ( expr_node &left , expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator < ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator <= ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator > ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator >= ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator == ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator != ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator ! (expr_node & expr) { return expr = unary_node(expr); } inline expr_node & operator && ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } inline expr_node & operator || ( expr_node &left, expr_node const& right) { return left = binary_node(left,right); } } #endif //MAPNIK_EXPRESSION_NODE_HPP