summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-06-27 16:57:23 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-06-29 15:38:11 -0700
commit542a4b4501794653b55fd1ffc60cb01348d8fc88 (patch)
tree9e451d4117427044d4155396992faf0495a544f7 /include
parent16a3f318a13448a46a4f59b0e8df6a7f0b73bc17 (diff)
downloadqtlocation-mapboxgl-542a4b4501794653b55fd1ffc60cb01348d8fc88.tar.gz
[core] Replace use of *Stops with expressions DSL
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/style/expression/compound_expression.hpp15
-rw-r--r--include/mbgl/style/expression/dsl.hpp63
-rw-r--r--include/mbgl/style/expression/literal.hpp4
-rw-r--r--include/mbgl/style/function/composite_function.hpp3
-rw-r--r--include/mbgl/style/function/source_function.hpp3
5 files changed, 68 insertions, 20 deletions
diff --git a/include/mbgl/style/expression/compound_expression.hpp b/include/mbgl/style/expression/compound_expression.hpp
index 431afb4d13..9d39194563 100644
--- a/include/mbgl/style/expression/compound_expression.hpp
+++ b/include/mbgl/style/expression/compound_expression.hpp
@@ -134,24 +134,9 @@ struct CompoundExpressionRegistry {
ParseResult parseCompoundExpression(const std::string name, const mbgl::style::conversion::Convertible& value, ParsingContext& ctx);
-ParseResult createCompoundExpression(const CompoundExpressionRegistry::Definition& definition,
- std::vector<std::unique_ptr<Expression>> args,
- ParsingContext& ctx);
-
ParseResult createCompoundExpression(const std::string& name,
std::vector<std::unique_ptr<Expression>> args,
ParsingContext& ctx);
-// Convenience method for use expressions that have 0, 1, or 2 args.
-ParseResult createCompoundExpression(const std::string& name, ParsingContext& ctx);
-
-ParseResult createCompoundExpression(const std::string& name,
- std::unique_ptr<Expression> arg1,
- ParsingContext& ctx);
-
-ParseResult createCompoundExpression(const std::string& name,
- std::unique_ptr<Expression> arg1,
- std::unique_ptr<Expression> arg2,
- ParsingContext& ctx);
} // namespace expression
} // namespace style
diff --git a/include/mbgl/style/expression/dsl.hpp b/include/mbgl/style/expression/dsl.hpp
new file mode 100644
index 0000000000..b4e1ed436e
--- /dev/null
+++ b/include/mbgl/style/expression/dsl.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <mbgl/style/expression/value.hpp>
+#include <mbgl/style/expression/expression.hpp>
+#include <mbgl/style/expression/interpolator.hpp>
+
+#include <memory>
+
+namespace mbgl {
+namespace style {
+namespace expression {
+namespace dsl {
+
+// This convenience API does little to no expression validation or type-checking, and is intended for
+// use only by test and other non-production code.
+
+std::unique_ptr<Expression> literal(const char* value);
+std::unique_ptr<Expression> literal(Value value);
+
+std::unique_ptr<Expression> number(std::unique_ptr<Expression>);
+std::unique_ptr<Expression> string(std::unique_ptr<Expression>);
+
+std::unique_ptr<Expression> toColor(const char* value);
+std::unique_ptr<Expression> toColor(std::unique_ptr<Expression>);
+
+std::unique_ptr<Expression> get(const char* value);
+std::unique_ptr<Expression> get(std::unique_ptr<Expression>);
+
+std::unique_ptr<Expression> id();
+std::unique_ptr<Expression> zoom();
+
+std::unique_ptr<Expression> eq(std::unique_ptr<Expression>,
+ std::unique_ptr<Expression>);
+std::unique_ptr<Expression> ne(std::unique_ptr<Expression>,
+ std::unique_ptr<Expression>);
+std::unique_ptr<Expression> gt(std::unique_ptr<Expression>,
+ std::unique_ptr<Expression>);
+std::unique_ptr<Expression> lt(std::unique_ptr<Expression>,
+ std::unique_ptr<Expression>);
+
+Interpolator linear();
+Interpolator exponential(double base);
+Interpolator cubicBezier(double x1, double y1, double x2, double y2);
+
+std::unique_ptr<Expression> interpolate(Interpolator interpolator,
+ std::unique_ptr<Expression> input,
+ double input1, std::unique_ptr<Expression> output1);
+
+std::unique_ptr<Expression> interpolate(Interpolator interpolator,
+ std::unique_ptr<Expression> input,
+ double input1, std::unique_ptr<Expression> output1,
+ double input2, std::unique_ptr<Expression> output2);
+
+std::unique_ptr<Expression> interpolate(Interpolator interpolator,
+ std::unique_ptr<Expression> input,
+ double input1, std::unique_ptr<Expression> output1,
+ double input2, std::unique_ptr<Expression> output2,
+ double input3, std::unique_ptr<Expression> output3);
+
+} // namespace dsl
+} // namespace expression
+} // namespace style
+} // namespace mbgl
diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp
index d3b3a20cce..44c095bf28 100644
--- a/include/mbgl/style/expression/literal.hpp
+++ b/include/mbgl/style/expression/literal.hpp
@@ -47,13 +47,11 @@ public:
mbgl::Value serialize() const override;
std::string getOperator() const override { return "literal"; }
+
private:
Value value;
};
-std::unique_ptr<Literal> createLiteral(const char* value);
-std::unique_ptr<Literal> createLiteral(Value value);
-
} // namespace expression
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp
index 93986f82f2..f99fc973ed 100644
--- a/include/mbgl/style/function/composite_function.hpp
+++ b/include/mbgl/style/function/composite_function.hpp
@@ -50,8 +50,9 @@ public:
CompositeIntervalStops<T>,
CompositeCategoricalStops<T>>>;
- CompositeFunction(std::unique_ptr<expression::Expression> expression_)
+ CompositeFunction(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = {})
: isExpression(true),
+ defaultValue(std::move(defaultValue_)),
expression(std::move(expression_)),
zoomCurve(expression::findZoomCurveChecked(expression.get()))
{
diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp
index 5b51d0bf81..bc4e3b9c7d 100644
--- a/include/mbgl/style/function/source_function.hpp
+++ b/include/mbgl/style/function/source_function.hpp
@@ -29,8 +29,9 @@ public:
CategoricalStops<T>,
IdentityStops<T>>>;
- SourceFunction(std::unique_ptr<expression::Expression> expression_)
+ SourceFunction(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = {})
: isExpression(true),
+ defaultValue(std::move(defaultValue_)),
expression(std::move(expression_))
{
assert(expression::isZoomConstant(*expression));