diff options
author | Anand Thakker <github@anandthakker.net> | 2017-07-07 21:41:36 -0400 |
---|---|---|
committer | Anand Thakker <github@anandthakker.net> | 2017-07-07 21:41:36 -0400 |
commit | 8f7bfb80c401447758229a92d6b268783089f23c (patch) | |
tree | 308722097c3e5616b7b40a726d99c695a9fe6d0b | |
parent | a6d0cf83b1cba21e4b7b8420a69f6c2643bb7899 (diff) | |
download | qtlocation-mapboxgl-8f7bfb80c401447758229a92d6b268783089f23c.tar.gz |
Use templatized parse()
-rw-r--r-- | include/mbgl/style/expression/expression.hpp | 46 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse.hpp | 8 |
2 files changed, 7 insertions, 47 deletions
diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index 20fe5be8f8..e35a302f00 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -130,8 +130,8 @@ public: name(name_) {} - template <class V> - static variant<CompileError, Args> parseArgs(const V& value, const ParsingContext& ctx) { + template <class Expr, class V> + static ParseResult parse(const V& value, const ParsingContext& ctx) { assert(isArray(value)); auto length = arrayLength(value); Args args; @@ -144,7 +144,7 @@ public: return parsedArg.template get<CompileError>(); } } - return std::move(args); + return std::make_unique<Expr>(ctx.key(), std::move(args)); } protected: @@ -182,16 +182,6 @@ public: return evaluateBinaryOperator<float>(zoom, feature, error, args, {}, [](float memo, float next) { return memo + next; }); } - - template <class V> - static ParseResult parse(const V& value, const ParsingContext& ctx) { - auto args = LambdaExpression::parseArgs(value, ctx); - if (args.template is<LambdaExpression::Args>()) { - return std::make_unique<PlusExpression>(ctx.key(), std::move(args.template get<Args>())); - } else { - return args.template get<CompileError>(); - } - } }; class TimesExpression : public LambdaExpression { @@ -205,16 +195,6 @@ public: return evaluateBinaryOperator<float>(zoom, feature, error, args, {}, [](float memo, float next) { return memo * next; }); } - - template <class V> - static ParseResult parse(const V& value, const ParsingContext& ctx) { - auto args = LambdaExpression::parseArgs(value, ctx); - if (args.template is<LambdaExpression::Args>()) { - return std::make_unique<TimesExpression>(ctx.key(), std::move(args.template get<Args>())); - } else { - return args.template get<CompileError>(); - } - } }; class MinusExpression : public LambdaExpression { @@ -228,16 +208,6 @@ public: return evaluateBinaryOperator<float>(zoom, feature, error, args, {}, [](float memo, float next) { return memo - next; }); } - - template <class V> - static ParseResult parse(const V& value, const ParsingContext& ctx) { - auto args = LambdaExpression::parseArgs(value, ctx); - if (args.template is<LambdaExpression::Args>()) { - return std::make_unique<MinusExpression>(ctx.key(), std::move(args.template get<Args>())); - } else { - return args.template get<CompileError>(); - } - } }; class DivideExpression : public LambdaExpression { @@ -251,16 +221,6 @@ public: return evaluateBinaryOperator<float>(zoom, feature, error, args, {}, [](float memo, float next) { return memo / next; }); } - - template <class V> - static ParseResult parse(const V& value, const ParsingContext& ctx) { - auto args = LambdaExpression::parseArgs(value, ctx); - if (args.template is<LambdaExpression::Args>()) { - return std::make_unique<DivideExpression>(ctx.key(), std::move(args.template get<Args>())); - } else { - return args.template get<CompileError>(); - } - } }; diff --git a/include/mbgl/style/expression/parse.hpp b/include/mbgl/style/expression/parse.hpp index 4776706749..1f5802d4fb 100644 --- a/include/mbgl/style/expression/parse.hpp +++ b/include/mbgl/style/expression/parse.hpp @@ -55,10 +55,10 @@ ParseResult parseExpression(const V& value, const ParsingContext& context) return error; } - if (*op == "+") return PlusExpression::parse(value, context); - if (*op == "-") return MinusExpression::parse(value, context); - if (*op == "*") return TimesExpression::parse(value, context); - if (*op == "/") return DivideExpression::parse(value, context); + if (*op == "+") return LambdaExpression::parse<PlusExpression>(value, context); + if (*op == "-") return LambdaExpression::parse<MinusExpression>(value, context); + if (*op == "*") return LambdaExpression::parse<TimesExpression>(value, context); + if (*op == "/") return LambdaExpression::parse<DivideExpression>(value, context); return CompileError { |