summaryrefslogtreecommitdiff
path: root/include/mbgl/style/expression/in.hpp
blob: ab8e2e9ff2ae962e777894f24a7bafc0033c387a (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
#pragma once

#include <mbgl/style/conversion.hpp>
#include <mbgl/style/expression/expression.hpp>
#include <memory>

namespace mbgl {
namespace style {
namespace expression {

class In : public Expression {
public:
    In(std::unique_ptr<Expression> needle_, std::unique_ptr<Expression> haystack_)
        : Expression(Kind::In, type::Boolean), needle(std::move(needle_)), haystack(std::move(haystack_)) {}

    static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx);

    EvaluationResult evaluate(const EvaluationContext& params) const override;
    void eachChild(const std::function<void(const Expression&)>&) const override;

    bool operator==(const Expression& e) const override {
        if (e.getKind() == Kind::In) {
            auto rhs = static_cast<const In*>(&e);
            return *needle == *(rhs->needle) && *haystack == *(rhs->haystack);
        }
        return false;
    }

    std::vector<optional<Value>> possibleOutputs() const override { return {nullopt}; }

    std::string getOperator() const override { return "in"; }

private:
    std::unique_ptr<Expression> needle;
    std::unique_ptr<Expression> haystack;
    static bool isComparableType(type::Type type);
    static bool isComparableRuntimeValue(type::Type type);
    static bool isSearchableRuntimeValue(type::Type type);
};

} // namespace expression
} // namespace style
} // namespace mbgl