summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-06-27 14:01:37 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-06-27 16:13:33 -0700
commit5ecfed5b79b389bf46ea95aeb66c74ee32aae64e (patch)
tree640be249c890a5ee1554748c5820c0fc507a5b57
parent63517b1b6f43aa313e7dc7e9638dd8017b7dc20f (diff)
downloadqtlocation-mapboxgl-5ecfed5b79b389bf46ea95aeb66c74ee32aae64e.tar.gz
[core] Simplify parseInterpolate
* Merge type checking into match arms * No need to use interpolator->match(...)
-rw-r--r--src/mbgl/style/expression/interpolate.cpp52
1 files changed, 14 insertions, 38 deletions
diff --git a/src/mbgl/style/expression/interpolate.cpp b/src/mbgl/style/expression/interpolate.cpp
index daad8523f2..75f4ce828e 100644
--- a/src/mbgl/style/expression/interpolate.cpp
+++ b/src/mbgl/style/expression/interpolate.cpp
@@ -155,52 +155,28 @@ ParseResult parseInterpolate(const Convertible& value, ParsingContext& ctx) {
assert(outputType);
- if (
- *outputType != type::Number &&
- *outputType != type::Color &&
- !(
- outputType->is<type::Array>() &&
- outputType->get<type::Array>().itemType == type::Number &&
- outputType->get<type::Array>().N
- )
- )
- {
- ctx.error("Type " + toString(*outputType) + " is not interpolatable.");
- return ParseResult();
- }
-
return outputType->match(
[&](const type::NumberType&) -> ParseResult {
- return interpolator->match([&](const auto& interpolator_) {
- return ParseResult(std::make_unique<Interpolate<double>>(
- *outputType, interpolator_, std::move(*input), std::move(stops)
- ));
- });
+ return ParseResult(std::make_unique<Interpolate<double>>(
+ *outputType, *interpolator, std::move(*input), std::move(stops)
+ ));
},
[&](const type::ColorType&) -> ParseResult {
- return interpolator->match([&](const auto& interpolator_) {
- return ParseResult(std::make_unique<Interpolate<Color>>(
- *outputType, interpolator_, std::move(*input), std::move(stops)
- ));
- });
+ return ParseResult(std::make_unique<Interpolate<Color>>(
+ *outputType, *interpolator, std::move(*input), std::move(stops)
+ ));
},
[&](const type::Array& arrayType) -> ParseResult {
- return interpolator->match(
- [&](const auto& continuousInterpolator) {
- if (arrayType.itemType != type::Number || !arrayType.N) {
- assert(false); // interpolability already checked above.
- return ParseResult();
- }
- return ParseResult(std::make_unique<Interpolate<std::vector<Value>>>(
- *outputType, continuousInterpolator, std::move(*input), std::move(stops)
- ));
- }
- );
+ if (arrayType.itemType != type::Number || !arrayType.N) {
+ ctx.error("Type " + toString(*outputType) + " is not interpolatable.");
+ return ParseResult();
+ }
+ return ParseResult(std::make_unique<Interpolate<std::vector<Value>>>(
+ *outputType, *interpolator, std::move(*input), std::move(stops)
+ ));
},
[&](const auto&) {
- // unreachable: Null, Boolean, String, Object, Value output types
- // are not interpolatable, and interpolability was already checked above
- assert(false);
+ ctx.error("Type " + toString(*outputType) + " is not interpolatable.");
return ParseResult();
}
);