summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-06-28 13:59:55 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-06-29 15:38:11 -0700
commit25ac89e018a27fc689f742429c78ba492682b0a0 (patch)
treec3434d5b652502f2fd3b64e2efdaeb2b7319f36b /include/mbgl
parent6dfe56510caa87b3e0fdbb8256d13ec955764d53 (diff)
downloadqtlocation-mapboxgl-25ac89e018a27fc689f742429c78ba492682b0a0.tar.gz
[core] Remove stops-based *Function constructors
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/style/conversion/function.hpp57
-rw-r--r--include/mbgl/style/function/camera_function.hpp36
-rw-r--r--include/mbgl/style/function/composite_function.hpp61
-rw-r--r--include/mbgl/style/function/convert.hpp39
-rw-r--r--include/mbgl/style/function/source_function.hpp43
5 files changed, 81 insertions, 155 deletions
diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp
index e230884944..932925c53c 100644
--- a/include/mbgl/style/conversion/function.hpp
+++ b/include/mbgl/style/conversion/function.hpp
@@ -3,9 +3,18 @@
#include <mbgl/style/function/camera_function.hpp>
#include <mbgl/style/function/source_function.hpp>
#include <mbgl/style/function/composite_function.hpp>
+#include <mbgl/style/function/convert.hpp>
+#include <mbgl/style/function/categorical_stops.hpp>
+#include <mbgl/style/function/exponential_stops.hpp>
+#include <mbgl/style/function/interval_stops.hpp>
+#include <mbgl/style/function/identity_stops.hpp>
+#include <mbgl/style/function/composite_exponential_stops.hpp>
+#include <mbgl/style/function/composite_interval_stops.hpp>
+#include <mbgl/style/function/composite_categorical_stops.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/util/ignore.hpp>
+#include <mbgl/util/variant.hpp>
namespace mbgl {
namespace style {
@@ -193,12 +202,22 @@ struct Converter<CameraFunction<T>> {
return {};
}
- auto stops = StopsConverter<T, typename CameraFunction<T>::Stops>()(value, error);
+ using Stops = std::conditional_t<
+ util::Interpolatable<T>::value,
+ variant<
+ ExponentialStops<T>,
+ IntervalStops<T>>,
+ variant<
+ IntervalStops<T>>>;
+
+ auto stops = StopsConverter<T, Stops>()(value, error);
if (!stops) {
return {};
}
- return CameraFunction<T>(*stops);
+ return CameraFunction<T>((*stops).match([&] (const auto& s) {
+ return expression::Convert::toExpression(s);
+ }), false);
}
};
@@ -238,7 +257,19 @@ struct Converter<SourceFunction<T>> {
return {};
}
- auto stops = StopsConverter<T, typename SourceFunction<T>::Stops>()(value, error);
+ using Stops = std::conditional_t<
+ util::Interpolatable<T>::value,
+ variant<
+ ExponentialStops<T>,
+ IntervalStops<T>,
+ CategoricalStops<T>,
+ IdentityStops<T>>,
+ variant<
+ IntervalStops<T>,
+ CategoricalStops<T>,
+ IdentityStops<T>>>;
+
+ auto stops = StopsConverter<T, Stops>()(value, error);
if (!stops) {
return {};
}
@@ -248,7 +279,9 @@ struct Converter<SourceFunction<T>> {
return {};
}
- return SourceFunction<T>(*propertyString, *stops, *defaultValue);
+ return SourceFunction<T>((*stops).match([&] (const auto& s) {
+ return expression::Convert::toExpression(*propertyString, s);
+ }), *defaultValue);
}
};
@@ -374,7 +407,17 @@ struct Converter<CompositeFunction<T>> {
return {};
}
- auto stops = StopsConverter<T, typename CompositeFunction<T>::Stops>()(value, error);
+ using Stops = std::conditional_t<
+ util::Interpolatable<T>::value,
+ variant<
+ CompositeExponentialStops<T>,
+ CompositeIntervalStops<T>,
+ CompositeCategoricalStops<T>>,
+ variant<
+ CompositeIntervalStops<T>,
+ CompositeCategoricalStops<T>>>;
+
+ auto stops = StopsConverter<T, Stops>()(value, error);
if (!stops) {
return {};
}
@@ -384,7 +427,9 @@ struct Converter<CompositeFunction<T>> {
return {};
}
- return CompositeFunction<T>(*propertyString, *stops, *defaultValue);
+ return CompositeFunction<T>((*stops).match([&] (const auto& s) {
+ return expression::Convert::toExpression(*propertyString, s);
+ }), *defaultValue);
}
};
diff --git a/include/mbgl/style/function/camera_function.hpp b/include/mbgl/style/function/camera_function.hpp
index 479deb20df..65b7991849 100644
--- a/include/mbgl/style/function/camera_function.hpp
+++ b/include/mbgl/style/function/camera_function.hpp
@@ -1,16 +1,12 @@
#pragma once
#include <mbgl/style/expression/expression.hpp>
+#include <mbgl/style/expression/value.hpp>
+#include <mbgl/style/expression/is_constant.hpp>
#include <mbgl/style/expression/interpolate.hpp>
#include <mbgl/style/expression/step.hpp>
#include <mbgl/style/expression/find_zoom_curve.hpp>
-#include <mbgl/style/expression/value.hpp>
-#include <mbgl/style/expression/is_constant.hpp>
-#include <mbgl/style/function/convert.hpp>
-#include <mbgl/style/function/exponential_stops.hpp>
-#include <mbgl/style/function/interval_stops.hpp>
-#include <mbgl/util/interpolate.hpp>
-#include <mbgl/util/variant.hpp>
+#include <mbgl/util/range.hpp>
namespace mbgl {
namespace style {
@@ -18,31 +14,15 @@ namespace style {
template <class T>
class CameraFunction {
public:
- using Stops = std::conditional_t<
- util::Interpolatable<T>::value,
- variant<
- ExponentialStops<T>,
- IntervalStops<T>>,
- variant<
- IntervalStops<T>>>;
-
- CameraFunction(std::unique_ptr<expression::Expression> expression_)
- : isExpression(true),
+ // The second parameter should be used only for conversions from legacy functions.
+ CameraFunction(std::unique_ptr<expression::Expression> expression_, bool isExpression_ = true)
+ : isExpression(isExpression_),
expression(std::move(expression_)),
- zoomCurve(expression::findZoomCurveChecked(expression.get()))
- {
+ zoomCurve(expression::findZoomCurveChecked(expression.get())) {
assert(!expression::isZoomConstant(*expression));
assert(expression::isFeatureConstant(*expression));
}
- CameraFunction(const Stops& stops)
- : isExpression(false),
- expression(stops.match([&] (const auto& s) {
- return expression::Convert::toExpression(s);
- })),
- zoomCurve(expression::findZoomCurveChecked(expression.get()))
- {}
-
T evaluate(float zoom) const {
const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(zoom, nullptr));
if (result) {
@@ -82,7 +62,7 @@ public:
const expression::Expression& getExpression() const { return *expression; }
private:
- std::shared_ptr<expression::Expression> expression;
+ std::shared_ptr<const expression::Expression> expression;
const variant<const expression::Interpolate*, const expression::Step*> zoomCurve;
};
diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp
index f99fc973ed..3b63bd005d 100644
--- a/include/mbgl/style/function/composite_function.hpp
+++ b/include/mbgl/style/function/composite_function.hpp
@@ -1,74 +1,29 @@
#pragma once
#include <mbgl/style/expression/expression.hpp>
+#include <mbgl/style/expression/value.hpp>
+#include <mbgl/style/expression/is_constant.hpp>
#include <mbgl/style/expression/interpolate.hpp>
#include <mbgl/style/expression/step.hpp>
#include <mbgl/style/expression/find_zoom_curve.hpp>
-#include <mbgl/style/expression/value.hpp>
-#include <mbgl/style/expression/is_constant.hpp>
-#include <mbgl/style/function/convert.hpp>
-#include <mbgl/style/function/composite_exponential_stops.hpp>
-#include <mbgl/style/function/composite_interval_stops.hpp>
-#include <mbgl/style/function/composite_categorical_stops.hpp>
-#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/range.hpp>
-#include <mbgl/util/variant.hpp>
-
-#include <string>
-#include <tuple>
namespace mbgl {
-
-class GeometryTileFeature;
-
namespace style {
-// A CompositeFunction consists of an outer zoom function whose stop range values are
-// "inner" source functions. It provides the GL Native implementation of
-// "zoom-and-property" functions from the style spec.
-
template <class T>
class CompositeFunction {
public:
- using InnerStops = std::conditional_t<
- util::Interpolatable<T>::value,
- variant<
- ExponentialStops<T>,
- IntervalStops<T>,
- CategoricalStops<T>>,
- variant<
- IntervalStops<T>,
- CategoricalStops<T>>>;
-
- using Stops = std::conditional_t<
- util::Interpolatable<T>::value,
- variant<
- CompositeExponentialStops<T>,
- CompositeIntervalStops<T>,
- CompositeCategoricalStops<T>>,
- variant<
- CompositeIntervalStops<T>,
- CompositeCategoricalStops<T>>>;
-
+ // The second parameter should be used only for conversions from legacy functions.
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()))
- {
+ : isExpression(defaultValue_),
+ expression(std::move(expression_)),
+ defaultValue(std::move(defaultValue_)),
+ zoomCurve(expression::findZoomCurveChecked(expression.get())) {
assert(!expression::isZoomConstant(*expression));
assert(!expression::isFeatureConstant(*expression));
}
- CompositeFunction(const std::string& property, const Stops& stops, optional<T> defaultValue_ = {})
- : isExpression(false),
- defaultValue(std::move(defaultValue_)),
- expression(stops.match([&] (const auto& s) {
- return expression::Convert::toExpression(property, s);
- })),
- zoomCurve(expression::findZoomCurveChecked(expression.get()))
- {}
-
// Return the range obtained by evaluating the function at each of the zoom levels in zoomRange
template <class Feature>
Range<T> evaluate(const Range<float>& zoomRange, const Feature& feature, T finalDefaultValue) {
@@ -118,8 +73,8 @@ public:
bool isExpression;
private:
+ std::shared_ptr<const expression::Expression> expression;
optional<T> defaultValue;
- std::shared_ptr<expression::Expression> expression;
const variant<const expression::Interpolate*, const expression::Step*> zoomCurve;
};
diff --git a/include/mbgl/style/function/convert.hpp b/include/mbgl/style/function/convert.hpp
index e5a5808e1d..a0dae992fa 100644
--- a/include/mbgl/style/function/convert.hpp
+++ b/include/mbgl/style/function/convert.hpp
@@ -306,40 +306,15 @@ struct Convert {
return std::move(*zoomCurve);
}
-
- static std::unique_ptr<Expression> fromIdentityFunction(type::Type type, const std::string& property)
+ template <typename T>
+ static std::unique_ptr<Expression> toExpression(const std::string& property,
+ const IdentityStops<T>&)
{
- std::unique_ptr<Expression> input = type.match(
- [&] (const type::StringType&) {
- return makeGet(type::String, property);
- },
- [&] (const type::NumberType&) {
- return makeGet(type::Number, property);
- },
- [&] (const type::BooleanType&) {
- return makeGet(type::Boolean, property);
- },
- [&] (const type::ColorType&) {
- std::vector<std::unique_ptr<Expression>> args;
- args.push_back(makeGet(type::String, property));
- return std::make_unique<Coercion>(type::Color, std::move(args));
- },
- [&] (const type::Array& arr) {
- std::vector<std::unique_ptr<Expression>> getArgs;
- getArgs.push_back(makeLiteral(property));
- ParsingContext ctx;
- ParseResult get = createCompoundExpression("get", std::move(getArgs), ctx);
- assert(get);
- assert(ctx.getErrors().size() == 0);
- return std::make_unique<ArrayAssertion>(arr, std::move(*get));
- },
- [&] (const auto&) -> std::unique_ptr<Expression> {
- return makeLiteral(Null);
- }
- );
-
- return input;
+ return fromIdentityFunction(property, expression::valueTypeToExpressionType<T>());
}
+
+private:
+ static std::unique_ptr<Expression> fromIdentityFunction(const std::string& property, type::Type type);
};
} // namespace expression
diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp
index bc4e3b9c7d..a83e73a5d0 100644
--- a/include/mbgl/style/function/source_function.hpp
+++ b/include/mbgl/style/function/source_function.hpp
@@ -1,15 +1,8 @@
#pragma once
+#include <mbgl/style/expression/expression.hpp>
+#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/expression/is_constant.hpp>
-#include <mbgl/style/function/convert.hpp>
-#include <mbgl/style/function/exponential_stops.hpp>
-#include <mbgl/style/function/interval_stops.hpp>
-#include <mbgl/style/function/categorical_stops.hpp>
-#include <mbgl/style/function/identity_stops.hpp>
-#include <mbgl/util/interpolate.hpp>
-#include <mbgl/util/variant.hpp>
-
-#include <string>
namespace mbgl {
namespace style {
@@ -17,37 +10,15 @@ namespace style {
template <class T>
class SourceFunction {
public:
- using Stops = std::conditional_t<
- util::Interpolatable<T>::value,
- variant<
- ExponentialStops<T>,
- IntervalStops<T>,
- CategoricalStops<T>,
- IdentityStops<T>>,
- variant<
- IntervalStops<T>,
- CategoricalStops<T>,
- IdentityStops<T>>>;
-
+ // The second parameter should be used only for conversions from legacy functions.
SourceFunction(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = {})
- : isExpression(true),
- defaultValue(std::move(defaultValue_)),
- expression(std::move(expression_))
- {
+ : isExpression(defaultValue_),
+ expression(std::move(expression_)),
+ defaultValue(std::move(defaultValue_)) {
assert(expression::isZoomConstant(*expression));
assert(!expression::isFeatureConstant(*expression));
}
- SourceFunction(const std::string& property, const Stops& stops, optional<T> defaultValue_ = {})
- : isExpression(false),
- defaultValue(std::move(defaultValue_)),
- expression(stops.match([&] (const IdentityStops<T>&) {
- return expression::Convert::fromIdentityFunction(expression::valueTypeToExpressionType<T>(), property);
- }, [&] (const auto& s) {
- return expression::Convert::toExpression(property, s);
- }))
- {}
-
template <class Feature>
T evaluate(const Feature& feature, T finalDefaultValue) const {
const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(&feature));
@@ -73,8 +44,8 @@ public:
const expression::Expression& getExpression() const { return *expression; }
private:
+ std::shared_ptr<const expression::Expression> expression;
optional<T> defaultValue;
- std::shared_ptr<expression::Expression> expression;
};
} // namespace style