summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnand Thakker <github@anandthakker.net>2017-08-12 22:44:27 -0400
committerAnand Thakker <github@anandthakker.net>2017-08-12 22:44:27 -0400
commit598c7a18d342bc05149b58d53819fd0b28881938 (patch)
treeb03a0917052ae3fe6103d3360749203166c17e0f
parent2746c28328376ebd9eb821908b6738ae6ec7e523 (diff)
downloadqtlocation-mapboxgl-upstream/expressions-dependency-problem.tar.gz
wip - attempt to hook up expression parsingupstream/expressions-dependency-problem
-rw-r--r--include/mbgl/style/conversion/data_driven_property_value.hpp14
-rw-r--r--include/mbgl/style/conversion/expression.hpp19
-rw-r--r--include/mbgl/style/function/camera_function.hpp7
-rw-r--r--include/mbgl/style/function/composite_function.hpp12
-rw-r--r--include/mbgl/style/function/convert.hpp1
-rw-r--r--include/mbgl/style/function/source_function.hpp7
6 files changed, 55 insertions, 5 deletions
diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp
index 79b15dcfb0..ed8478a108 100644
--- a/include/mbgl/style/conversion/data_driven_property_value.hpp
+++ b/include/mbgl/style/conversion/data_driven_property_value.hpp
@@ -4,6 +4,8 @@
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion/function.hpp>
+#include <mbgl/style/conversion/expression.hpp>
+#include <mbgl/style/expression/value.hpp>
namespace mbgl {
namespace style {
@@ -21,6 +23,18 @@ struct Converter<DataDrivenPropertyValue<T>> {
return {};
}
return DataDrivenPropertyValue<T>(*constant);
+ } else if (objectMember(value, "expression")) {
+ optional<std::unique_ptr<Expression>> expression = convert<std::unique_ptr<Expression>>(*objectMember(value, "expression"), error, valueTypeToExpressionType<T>());
+ if (!expression) {
+ return {};
+ }
+ if ((*expression)->isFeatureConstant()) {
+ return DataDrivenPropertyValue<T>(CameraFunction<T>(std::move(*expression)));
+ } else if ((*expression)->isZoomConstant()) {
+ return DataDrivenPropertyValue<T>(SourceFunction<T>(std::move(*expression)));
+ } else {
+ return DataDrivenPropertyValue<T>(CompositeFunction<T>(std::move(*expression)));
+ }
} else if (!objectMember(value, "property")) {
optional<CameraFunction<T>> function = convert<CameraFunction<T>>(value, error);
if (!function) {
diff --git a/include/mbgl/style/conversion/expression.hpp b/include/mbgl/style/conversion/expression.hpp
index bce7c91396..601916250d 100644
--- a/include/mbgl/style/conversion/expression.hpp
+++ b/include/mbgl/style/conversion/expression.hpp
@@ -2,6 +2,7 @@
#include <memory>
#include <mbgl/style/expression/parse.hpp>
+#include <mbgl/style/expression/type.hpp>
#include <mbgl/style/conversion.hpp>
namespace mbgl {
@@ -12,12 +13,20 @@ using namespace mbgl::style::expression;
template<> struct Converter<std::unique_ptr<Expression>> {
template <class V>
- optional<std::unique_ptr<Expression>> operator()(const V& value, Error& error) const {
- auto parsed = parseExpression(value, ParsingContext());
- if (parsed.template is<std::unique_ptr<Expression>>()) {
- return std::move(parsed.template get<std::unique_ptr<Expression>>());
+ optional<std::unique_ptr<Expression>> operator()(const V& value, Error& error, type::Type expected) const {
+ std::vector<ParsingError> errors;
+ auto parsed = parseExpression(value, ParsingContext(errors, expected));
+ if (parsed) {
+ return std::move(*parsed);
}
- error = { parsed.template get<CompileError>().message };
+ std::string combinedError;
+ for (const ParsingError& parsingError : errors) {
+ if (combinedError.size() > 0) {
+ combinedError += "\n";
+ }
+ combinedError += parsingError.key + ": " + parsingError.message;
+ }
+ error = { combinedError };
return {};
};
};
diff --git a/include/mbgl/style/function/camera_function.hpp b/include/mbgl/style/function/camera_function.hpp
index 5a0f5ffe4a..55fd5cd7cc 100644
--- a/include/mbgl/style/function/camera_function.hpp
+++ b/include/mbgl/style/function/camera_function.hpp
@@ -19,6 +19,13 @@ public:
IntervalStops<T>>,
variant<
IntervalStops<T>>>;
+
+ CameraFunction(std::unique_ptr<expression::Expression> expression_)
+ : expression(std::move(expression_))
+ {
+ assert(!expression->isZoomConstant());
+ assert(expression->isFeatureConstant());
+ }
CameraFunction(Stops stops_)
: stops(std::move(stops_)),
diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp
index f7cbab1b21..7d77d5e552 100644
--- a/include/mbgl/style/function/composite_function.hpp
+++ b/include/mbgl/style/function/composite_function.hpp
@@ -50,6 +50,18 @@ public:
using Interpolator = expression::ExponentialInterpolator<T>;
using Curve = expression::Curve<Interpolator>;
+ CompositeFunction(std::unique_ptr<expression::Expression> expression_)
+ : expression(std::move(expression_)),
+ interpolator([&]() -> Interpolator {
+ optional<Curve*> zoomCurve = findZoomCurve(expression.get());
+ assert(zoomCurve);
+ return (*zoomCurve)->getInterpolator();
+ }())
+ {
+ assert(!expression->isZoomConstant());
+ assert(!expression->isFeatureConstant());
+ }
+
CompositeFunction(std::string property_, Stops stops_, optional<T> defaultValue_ = {})
: property(std::move(property_)),
stops(std::move(stops_)),
diff --git a/include/mbgl/style/function/convert.hpp b/include/mbgl/style/function/convert.hpp
index 67624625d4..ca021eadf6 100644
--- a/include/mbgl/style/function/convert.hpp
+++ b/include/mbgl/style/function/convert.hpp
@@ -1,5 +1,6 @@
#pragma once
+
#include <mbgl/util/enum.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/expression/array_assertion.hpp>
diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp
index 0ae8357d7b..d65d03857a 100644
--- a/include/mbgl/style/function/source_function.hpp
+++ b/include/mbgl/style/function/source_function.hpp
@@ -29,6 +29,13 @@ public:
CategoricalStops<T>,
IdentityStops<T>>>;
+ SourceFunction(std::unique_ptr<expression::Expression> expression_)
+ : expression(std::move(expression_))
+ {
+ assert(expression->isZoomConstant());
+ assert(!expression->isFeatureConstant());
+ }
+
SourceFunction(std::string property_, Stops stops_, optional<T> defaultValue_ = {})
: property(std::move(property_)),
stops(std::move(stops_)),