blob: 10c7ef4bde6c8c09c61c06d1b49ba739ba70ed8e (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include <mbgl/style/expression/boolean_operator.hpp>
namespace mbgl {
namespace style {
namespace expression {
EvaluationResult Any::evaluate(const EvaluationParameters& params) const {
for (auto it = inputs.begin(); it != inputs.end(); it++) {
const EvaluationResult result = (*it)->evaluate(params);
if (!result) return result;
if (result->get<bool>()) return EvaluationResult(true);
}
return EvaluationResult(false);
}
void Any::eachChild(const std::function<void(const Expression*)>& visit) const {
for (const std::unique_ptr<Expression>& input : inputs) {
visit(input.get());
}
}
EvaluationResult All::evaluate(const EvaluationParameters& params) const {
for (auto it = inputs.begin(); it != inputs.end(); it++) {
const EvaluationResult result = (*it)->evaluate(params);
if (!result) return result;
if (!result->get<bool>()) return EvaluationResult(false);
}
return EvaluationResult(true);
}
void All::eachChild(const std::function<void(const Expression*)>& visit) const {
for (const std::unique_ptr<Expression>& input : inputs) {
visit(input.get());
}
}
using namespace mbgl::style::conversion;
template <class T>
ParseResult parseBooleanOp(const Convertible& value, ParsingContext ctx) {
assert(isArray(value));
auto length = arrayLength(value);
std::vector<std::unique_ptr<Expression>> parsedInputs;
parsedInputs.reserve(length - 1);
for (std::size_t i = 1; i < length; i++) {
auto parsed = ctx.concat(i, {type::Boolean}).parse(arrayMember(value, i));
if (!parsed) {
return parsed;
}
parsedInputs.push_back(std::move(*parsed));
}
return ParseResult(std::make_unique<T>(std::move(parsedInputs)));
}
ParseResult Any::parse(const Convertible& value, ParsingContext ctx) {
return parseBooleanOp<Any>(value, ctx);
}
ParseResult All::parse(const Convertible& value, ParsingContext ctx) {
return parseBooleanOp<All>(value, ctx);
}
} // namespace expression
} // namespace style
} // namespace mbgl
|