blob: 81a4951bf53e2e4547ade67584e44dcbd9fd0c19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#pragma once
#include <mbgl/style/expression/step.hpp>
#include <mbgl/style/expression/compound_expression.hpp>
#include <mbgl/style/expression/let.hpp>
#include <mbgl/style/expression/coalesce.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
namespace expression {
template <typename T>
optional<variant<Interpolate<T>*, Step*>> findZoomCurve(expression::Expression* e) {
if (auto curve = dynamic_cast<Interpolate<T>*>(e)) {
auto z = dynamic_cast<CompoundExpressionBase*>(curve->getInput().get());
if (z && z->getName() == "zoom") {
return {curve};
} else {
return optional<variant<Interpolate<T>*, Step*>>();
}
} else if (auto step = dynamic_cast<Step*>(e)) {
auto z = dynamic_cast<CompoundExpressionBase*>(step->getInput().get());
if (z && z->getName() == "zoom") {
return {step};
} else {
return optional<variant<Interpolate<T>*, Step*>>();
}
} else if (auto let = dynamic_cast<Let*>(e)) {
return findZoomCurve<T>(let->getResult());
} else if (auto coalesce = dynamic_cast<Coalesce*>(e)) {
std::size_t length = coalesce->getLength();
for (std::size_t i = 0; i < length; i++) {
optional<variant<Interpolate<T>*, Step*>> childInterpolate = findZoomCurve<T>(coalesce->getChild(i));
if (!childInterpolate) {
continue;
} else {
return childInterpolate;
}
}
}
return optional<variant<Interpolate<T>*, Step*>>();
}
} // namespace expression
} // namespace style
} // namespace mbgl
|