summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-01-05 12:40:54 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-01-10 15:31:12 -0800
commit76ed5079a547e9f98616a9401c8814d224cec9d8 (patch)
tree4bad1bcefd0744a0262d6973b825a977fa2cfe45 /include
parent158bd5e08cae5974a9c587677d7d8e63a36a5ff0 (diff)
downloadqtlocation-mapboxgl-76ed5079a547e9f98616a9401c8814d224cec9d8.tar.gz
[core, ios, macos, android] Add data-driven-styling support for `text-font`
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/style/expression/array_assertion.hpp4
-rw-r--r--include/mbgl/style/expression/assertion.hpp5
-rw-r--r--include/mbgl/style/expression/at.hpp4
-rw-r--r--include/mbgl/style/expression/boolean_operator.hpp5
-rw-r--r--include/mbgl/style/expression/case.hpp2
-rw-r--r--include/mbgl/style/expression/coalesce.hpp4
-rw-r--r--include/mbgl/style/expression/coercion.hpp5
-rw-r--r--include/mbgl/style/expression/compound_expression.hpp8
-rw-r--r--include/mbgl/style/expression/equals.hpp1
-rw-r--r--include/mbgl/style/expression/expression.hpp18
-rw-r--r--include/mbgl/style/expression/interpolate.hpp2
-rw-r--r--include/mbgl/style/expression/let.hpp6
-rw-r--r--include/mbgl/style/expression/literal.hpp6
-rw-r--r--include/mbgl/style/expression/match.hpp7
-rw-r--r--include/mbgl/style/expression/step.hpp2
-rw-r--r--include/mbgl/style/expression/value.hpp9
-rw-r--r--include/mbgl/style/function/camera_function.hpp7
-rw-r--r--include/mbgl/style/function/composite_function.hpp4
-rw-r--r--include/mbgl/style/function/convert.hpp4
-rw-r--r--include/mbgl/style/function/source_function.hpp4
-rw-r--r--include/mbgl/style/layers/symbol_layer.hpp6
-rw-r--r--include/mbgl/util/optional.hpp3
22 files changed, 94 insertions, 22 deletions
diff --git a/include/mbgl/style/expression/array_assertion.hpp b/include/mbgl/style/expression/array_assertion.hpp
index 2516eea024..7f36f8aac2 100644
--- a/include/mbgl/style/expression/array_assertion.hpp
+++ b/include/mbgl/style/expression/array_assertion.hpp
@@ -30,6 +30,10 @@ public:
return false;
}
+ std::vector<optional<Value>> possibleOutputs() const override {
+ return input->possibleOutputs();
+ }
+
private:
std::unique_ptr<Expression> input;
};
diff --git a/include/mbgl/style/expression/assertion.hpp b/include/mbgl/style/expression/assertion.hpp
index 504d49f4e5..43ea73f2ba 100644
--- a/include/mbgl/style/expression/assertion.hpp
+++ b/include/mbgl/style/expression/assertion.hpp
@@ -1,7 +1,9 @@
#pragma once
+
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
+
#include <memory>
#include <vector>
@@ -23,6 +25,8 @@ public:
bool operator==(const Expression& e) const override;
+ std::vector<optional<Value>> possibleOutputs() const override;
+
private:
std::vector<std::unique_ptr<Expression>> inputs;
};
@@ -30,4 +34,3 @@ private:
} // namespace expression
} // namespace style
} // namespace mbgl
-
diff --git a/include/mbgl/style/expression/at.hpp b/include/mbgl/style/expression/at.hpp
index e3eefa4fe8..27fccc761f 100644
--- a/include/mbgl/style/expression/at.hpp
+++ b/include/mbgl/style/expression/at.hpp
@@ -28,6 +28,10 @@ public:
return false;
}
+ std::vector<optional<Value>> possibleOutputs() const override {
+ return { nullopt };
+ }
+
private:
std::unique_ptr<Expression> index;
std::unique_ptr<Expression> input;
diff --git a/include/mbgl/style/expression/boolean_operator.hpp b/include/mbgl/style/expression/boolean_operator.hpp
index 01231d706b..115a096665 100644
--- a/include/mbgl/style/expression/boolean_operator.hpp
+++ b/include/mbgl/style/expression/boolean_operator.hpp
@@ -2,6 +2,7 @@
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/conversion.hpp>
+
#include <memory>
namespace mbgl {
@@ -20,6 +21,7 @@ public:
EvaluationResult evaluate(const EvaluationContext& params) const override;
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
+ std::vector<optional<Value>> possibleOutputs() const override;
private:
std::vector<std::unique_ptr<Expression>> inputs;
@@ -36,8 +38,8 @@ public:
EvaluationResult evaluate(const EvaluationContext& params) const override;
void eachChild(const std::function<void(const Expression&)>& visit) const override;
-
bool operator==(const Expression& e) const override;
+ std::vector<optional<Value>> possibleOutputs() const override;
private:
std::vector<std::unique_ptr<Expression>> inputs;
@@ -46,4 +48,3 @@ private:
} // namespace expression
} // namespace style
} // namespace mbgl
-
diff --git a/include/mbgl/style/expression/case.hpp b/include/mbgl/style/expression/case.hpp
index ece2fe0329..e61a55fc6d 100644
--- a/include/mbgl/style/expression/case.hpp
+++ b/include/mbgl/style/expression/case.hpp
@@ -26,6 +26,8 @@ public:
bool operator==(const Expression& e) const override;
+ std::vector<optional<Value>> possibleOutputs() const override;
+
private:
std::vector<Branch> branches;
std::unique_ptr<Expression> otherwise;
diff --git a/include/mbgl/style/expression/coalesce.hpp b/include/mbgl/style/expression/coalesce.hpp
index 4e6a9b3793..52d9498cbd 100644
--- a/include/mbgl/style/expression/coalesce.hpp
+++ b/include/mbgl/style/expression/coalesce.hpp
@@ -27,7 +27,9 @@ public:
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
-
+
+ std::vector<optional<Value>> possibleOutputs() const override;
+
std::size_t getLength() const {
return args.size();
}
diff --git a/include/mbgl/style/expression/coercion.hpp b/include/mbgl/style/expression/coercion.hpp
index 665bb7ce7c..40d2490186 100644
--- a/include/mbgl/style/expression/coercion.hpp
+++ b/include/mbgl/style/expression/coercion.hpp
@@ -1,6 +1,8 @@
#pragma once
+
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/conversion.hpp>
+
#include <memory>
#include <vector>
@@ -23,6 +25,9 @@ public:
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
+
+ std::vector<optional<Value>> possibleOutputs() const override;
+
private:
EvaluationResult (*coerceSingleValue) (const Value& v);
std::vector<std::unique_ptr<Expression>> inputs;
diff --git a/include/mbgl/style/expression/compound_expression.hpp b/include/mbgl/style/expression/compound_expression.hpp
index fc3edbfd4a..8b74027578 100644
--- a/include/mbgl/style/expression/compound_expression.hpp
+++ b/include/mbgl/style/expression/compound_expression.hpp
@@ -72,7 +72,11 @@ public:
[&](const std::vector<type::Type>& p) -> optional<std::size_t> { return p.size(); }
);
}
-
+
+ std::vector<optional<Value>> possibleOutputs() const override {
+ return { nullopt };
+ }
+
private:
std::string name;
variant<std::vector<type::Type>, VarargsType> params;
@@ -107,7 +111,7 @@ public:
}
return false;
}
-
+
private:
Signature signature;
typename Signature::Args args;
diff --git a/include/mbgl/style/expression/equals.hpp b/include/mbgl/style/expression/equals.hpp
index 3c0c024294..80550bd59d 100644
--- a/include/mbgl/style/expression/equals.hpp
+++ b/include/mbgl/style/expression/equals.hpp
@@ -19,6 +19,7 @@ public:
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression&) const override;
EvaluationResult evaluate(const EvaluationContext&) const override;
+ std::vector<optional<Value>> possibleOutputs() const override;
private:
std::unique_ptr<Expression> lhs;
diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp
index a22fc28724..cf9fa0cb21 100644
--- a/include/mbgl/style/expression/expression.hpp
+++ b/include/mbgl/style/expression/expression.hpp
@@ -1,8 +1,5 @@
#pragma once
-#include <array>
-#include <vector>
-#include <memory>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/color.hpp>
@@ -10,6 +7,10 @@
#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
+#include <array>
+#include <vector>
+#include <memory>
+
namespace mbgl {
class GeometryTileFeature;
@@ -38,7 +39,7 @@ public:
optional<double> heatmapDensity;
};
-template<typename T>
+template <typename T>
class Result : private variant<EvaluationError, T> {
public:
using variant<EvaluationError, T>::variant;
@@ -128,6 +129,13 @@ public:
EvaluationResult evaluate(optional<float> zoom, const Feature& feature, optional<double> heatmapDensity) const;
+ /**
+ * Statically analyze the expression, attempting to enumerate possible outputs. Returns
+ * an array of values plus the sentinel null optional value, used to indicate that the
+ * complete set of outputs is statically undecidable.
+ */
+ virtual std::vector<optional<Value>> possibleOutputs() const = 0;
+
protected:
template <typename T>
static bool childrenEqual(const T& lhs, const T& rhs) {
@@ -161,8 +169,6 @@ protected:
const std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression>>& rhs) {
return *(lhs.first) == *(rhs.first) && *(lhs.second) == *(rhs.second);
}
-
-
private:
type::Type type;
diff --git a/include/mbgl/style/expression/interpolate.hpp b/include/mbgl/style/expression/interpolate.hpp
index fd9ec25a2c..c82c04bbb0 100644
--- a/include/mbgl/style/expression/interpolate.hpp
+++ b/include/mbgl/style/expression/interpolate.hpp
@@ -89,6 +89,8 @@ public:
);
}
+ std::vector<optional<Value>> possibleOutputs() const override;
+
protected:
const Interpolator interpolator;
const std::unique_ptr<Expression> input;
diff --git a/include/mbgl/style/expression/let.hpp b/include/mbgl/style/expression/let.hpp
index aaa16ca0c2..6829ded9b8 100644
--- a/include/mbgl/style/expression/let.hpp
+++ b/include/mbgl/style/expression/let.hpp
@@ -33,6 +33,8 @@ public:
return false;
}
+ std::vector<optional<Value>> possibleOutputs() const override;
+
Expression* getResult() const {
return result.get();
}
@@ -61,7 +63,9 @@ public:
}
return false;
}
-
+
+ std::vector<optional<Value>> possibleOutputs() const override;
+
private:
std::string name;
std::shared_ptr<Expression> value;
diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp
index a0819c7e73..82983d78af 100644
--- a/include/mbgl/style/expression/literal.hpp
+++ b/include/mbgl/style/expression/literal.hpp
@@ -28,7 +28,11 @@ public:
}
return false;
}
-
+
+ std::vector<optional<Value>> possibleOutputs() const override {
+ return {{ value }};
+ }
+
private:
Value value;
};
diff --git a/include/mbgl/style/expression/match.hpp b/include/mbgl/style/expression/match.hpp
index e17fe96bfe..682d784b0f 100644
--- a/include/mbgl/style/expression/match.hpp
+++ b/include/mbgl/style/expression/match.hpp
@@ -25,14 +25,15 @@ public:
otherwise(std::move(otherwise_))
{}
+ EvaluationResult evaluate(const EvaluationContext& params) const override;
+
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
- EvaluationResult evaluate(const EvaluationContext& params) const override;
-
+ std::vector<optional<Value>> possibleOutputs() const override;
+
private:
-
std::unique_ptr<Expression> input;
Branches branches;
std::unique_ptr<Expression> otherwise;
diff --git a/include/mbgl/style/expression/step.hpp b/include/mbgl/style/expression/step.hpp
index e3c49bc609..4a0a724d7c 100644
--- a/include/mbgl/style/expression/step.hpp
+++ b/include/mbgl/style/expression/step.hpp
@@ -33,6 +33,8 @@ public:
bool operator==(const Expression& e) const override;
+ std::vector<optional<Value>> possibleOutputs() const override;
+
static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx);
private:
diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp
index 8baa9d2dba..be5be64752 100644
--- a/include/mbgl/style/expression/value.hpp
+++ b/include/mbgl/style/expression/value.hpp
@@ -148,6 +148,15 @@ struct ValueConverter<T, std::enable_if_t< std::is_enum<T>::value >> {
static optional<T> fromExpressionValue(const Value& value);
};
+template <typename T>
+std::vector<optional<T>> fromExpressionValues(const std::vector<optional<Value>>& values) {
+ std::vector<optional<T>> result;
+ for (const auto& value : values) {
+ result.push_back(value ? fromExpressionValue<T>(*value) : nullopt);
+ }
+ return result;
+}
+
} // namespace expression
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/function/camera_function.hpp b/include/mbgl/style/function/camera_function.hpp
index 25b38e3616..015abd3e62 100644
--- a/include/mbgl/style/function/camera_function.hpp
+++ b/include/mbgl/style/function/camera_function.hpp
@@ -12,7 +12,6 @@
#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/variant.hpp>
-
namespace mbgl {
namespace style {
@@ -66,7 +65,11 @@ public:
[&](auto z) { return z->getCoveringStops(lower, upper); }
);
}
-
+
+ std::vector<optional<T>> possibleOutputs() const {
+ return expression::fromExpressionValues<T>(expression->possibleOutputs());
+ }
+
friend bool operator==(const CameraFunction& lhs,
const CameraFunction& rhs) {
return *lhs.expression == *rhs.expression;
diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp
index b44bf8e6fe..24578f599c 100644
--- a/include/mbgl/style/function/composite_function.hpp
+++ b/include/mbgl/style/function/composite_function.hpp
@@ -102,6 +102,10 @@ public:
);
}
+ std::vector<optional<T>> possibleOutputs() const {
+ return expression::fromExpressionValues<T>(expression->possibleOutputs());
+ }
+
friend bool operator==(const CompositeFunction& lhs,
const CompositeFunction& rhs) {
return *lhs.expression == *rhs.expression;
diff --git a/include/mbgl/style/function/convert.hpp b/include/mbgl/style/function/convert.hpp
index 9f7b7ed1f8..8e544d3ad5 100644
--- a/include/mbgl/style/function/convert.hpp
+++ b/include/mbgl/style/function/convert.hpp
@@ -45,6 +45,10 @@ public:
return EvaluationError{message};
}
+ std::vector<optional<Value>> possibleOutputs() const override {
+ return {};
+ }
+
private:
std::string message;
};
diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp
index 02e4b604e2..bd7b109fd8 100644
--- a/include/mbgl/style/function/source_function.hpp
+++ b/include/mbgl/style/function/source_function.hpp
@@ -57,6 +57,10 @@ public:
return defaultValue ? *defaultValue : finalDefaultValue;
}
+ std::vector<optional<T>> possibleOutputs() const {
+ return expression::fromExpressionValues<T>(expression->possibleOutputs());
+ }
+
friend bool operator==(const SourceFunction& lhs,
const SourceFunction& rhs) {
return *lhs.expression == *rhs.expression;
diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp
index a72baa0b4e..f068e2d060 100644
--- a/include/mbgl/style/layers/symbol_layer.hpp
+++ b/include/mbgl/style/layers/symbol_layer.hpp
@@ -118,9 +118,9 @@ public:
DataDrivenPropertyValue<std::string> getTextField() const;
void setTextField(DataDrivenPropertyValue<std::string>);
- static PropertyValue<std::vector<std::string>> getDefaultTextFont();
- PropertyValue<std::vector<std::string>> getTextFont() const;
- void setTextFont(PropertyValue<std::vector<std::string>>);
+ static DataDrivenPropertyValue<std::vector<std::string>> getDefaultTextFont();
+ DataDrivenPropertyValue<std::vector<std::string>> getTextFont() const;
+ void setTextFont(DataDrivenPropertyValue<std::vector<std::string>>);
static DataDrivenPropertyValue<float> getDefaultTextSize();
DataDrivenPropertyValue<float> getTextSize() const;
diff --git a/include/mbgl/util/optional.hpp b/include/mbgl/util/optional.hpp
index a9374a1b53..abec02dca9 100644
--- a/include/mbgl/util/optional.hpp
+++ b/include/mbgl/util/optional.hpp
@@ -7,4 +7,7 @@ namespace mbgl {
template <typename T>
using optional = std::experimental::optional<T>;
+using nullopt_t = std::experimental::nullopt_t;
+constexpr nullopt_t nullopt = std::experimental::nullopt;
+
} // namespace mbgl