summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnand Thakker <github@anandthakker.net>2017-10-24 23:10:23 -0400
committerAnand Thakker <github@anandthakker.net>2017-10-25 11:53:48 -0400
commitb4566512d1df0d14939b5ff9f1f5b7ff8abb0a3e (patch)
tree7ce5a23592c638c6d345465abef05a1ab7cc42d9
parent33ba5333c0895aafa837770985ba68edacb3db27 (diff)
downloadqtlocation-mapboxgl-b4566512d1df0d14939b5ff9f1f5b7ff8abb0a3e.tar.gz
Drop wrapper `{expression:}` object.
-rw-r--r--cmake/core-files.cmake2
-rw-r--r--include/mbgl/style/conversion/data_driven_property_value.hpp19
-rw-r--r--include/mbgl/style/expression/is_expression.hpp14
-rw-r--r--src/mbgl/style/expression/is_expression.cpp43
4 files changed, 70 insertions, 8 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake
index 206a1c8d25..cd66fccef3 100644
--- a/cmake/core-files.cmake
+++ b/cmake/core-files.cmake
@@ -406,6 +406,7 @@ set(MBGL_CORE_FILES
include/mbgl/style/expression/curve.hpp
include/mbgl/style/expression/expression.hpp
include/mbgl/style/expression/is_constant.hpp
+ include/mbgl/style/expression/is_expression.hpp
include/mbgl/style/expression/let.hpp
include/mbgl/style/expression/literal.hpp
include/mbgl/style/expression/match.hpp
@@ -423,6 +424,7 @@ set(MBGL_CORE_FILES
src/mbgl/style/expression/compound_expression.cpp
src/mbgl/style/expression/curve.cpp
src/mbgl/style/expression/is_constant.cpp
+ src/mbgl/style/expression/is_expression.cpp
src/mbgl/style/expression/let.cpp
src/mbgl/style/expression/literal.cpp
src/mbgl/style/expression/match.cpp
diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp
index aac09aa343..79ea34979e 100644
--- a/include/mbgl/style/conversion/data_driven_property_value.hpp
+++ b/include/mbgl/style/conversion/data_driven_property_value.hpp
@@ -1,10 +1,12 @@
#pragma once
+#include <unordered_set>
#include <mbgl/style/data_driven_property_value.hpp>
#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/is_expression.hpp>
#include <mbgl/style/expression/curve.hpp>
#include <mbgl/style/expression/is_constant.hpp>
@@ -14,18 +16,13 @@ namespace conversion {
template <class T>
struct Converter<DataDrivenPropertyValue<T>> {
+
optional<DataDrivenPropertyValue<T>> operator()(const Convertible& value, Error& error) const {
if (isUndefined(value)) {
return DataDrivenPropertyValue<T>();
- } else if (!isObject(value)) {
- optional<T> constant = convert<T>(value, error);
- if (!constant) {
- return {};
- }
- return DataDrivenPropertyValue<T>(*constant);
- } else if (objectMember(value, "expression")) {
+ } else if (expression::isExpression(value)) {
optional<std::unique_ptr<Expression>> expression = convert<std::unique_ptr<Expression>>(
- *objectMember(value, "expression"),
+ value,
error,
valueTypeToExpressionType<T>());
@@ -44,6 +41,12 @@ struct Converter<DataDrivenPropertyValue<T>> {
return DataDrivenPropertyValue<T>(CompositeFunction<T>(std::move(*expression)));
}
+ } else if (!isObject(value)) {
+ optional<T> constant = convert<T>(value, error);
+ if (!constant) {
+ return {};
+ }
+ return DataDrivenPropertyValue<T>(*constant);
} else if (!objectMember(value, "property")) {
optional<CameraFunction<T>> function = convert<CameraFunction<T>>(value, error);
if (!function) {
diff --git a/include/mbgl/style/expression/is_expression.hpp b/include/mbgl/style/expression/is_expression.hpp
new file mode 100644
index 0000000000..7cb2b03863
--- /dev/null
+++ b/include/mbgl/style/expression/is_expression.hpp
@@ -0,0 +1,14 @@
+#pragma once
+#include <unordered_set>
+#include <mbgl/style/expression/expression.hpp>
+#include <mbgl/style/expression/compound_expression.hpp>
+
+namespace mbgl {
+namespace style {
+namespace expression {
+
+bool isExpression(const conversion::Convertible& value);
+
+} // namespace expression
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/expression/is_expression.cpp b/src/mbgl/style/expression/is_expression.cpp
new file mode 100644
index 0000000000..1b70c7a096
--- /dev/null
+++ b/src/mbgl/style/expression/is_expression.cpp
@@ -0,0 +1,43 @@
+#include <mbgl/style/expression/is_expression.hpp>
+#include <mbgl/style/conversion.hpp>
+
+namespace mbgl {
+namespace style {
+namespace expression {
+
+bool isExpression(const conversion::Convertible& value) {
+ using namespace mbgl::style::conversion;
+
+ static std::unordered_set<std::string> specialForms = {
+ "literal",
+ "match",
+ "curve",
+ "coalesce",
+ "array",
+ "let",
+ "var",
+ "at",
+ "string",
+ "number",
+ "color",
+ "boolean",
+ "to-string",
+ "to-number",
+ "to-color",
+ "to-boolean",
+ "any",
+ "all"
+ };
+
+ if (!isArray(value) || arrayLength(value) == 0) return false;
+ optional<std::string> name = toString(arrayMember(value, 0));
+ if (!name) return false;
+
+ return (specialForms.find(*name) != specialForms.end()) ||
+ (CompoundExpressionRegistry::definitions.find(*name) != CompoundExpressionRegistry::definitions.end());
+}
+
+
+} // namespace expression
+} // namespace style
+} // namespace mbgl