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

#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/expression/parsing_context.hpp>

namespace mbgl {
namespace style {
namespace expression {

struct FormatExpressionSection {
    explicit FormatExpressionSection(std::unique_ptr<Expression> content_);

    void setTextSectionOptions(optional<std::unique_ptr<Expression>> fontScale_,
                               optional<std::unique_ptr<Expression>> textFont_,
                               optional<std::unique_ptr<Expression>> textColor_);

    // Content can be expression that evaluates to String or Image.
    std::shared_ptr<Expression> content;

    // Text related section options.
    optional<std::shared_ptr<Expression>> fontScale;
    optional<std::shared_ptr<Expression>> textFont;
    optional<std::shared_ptr<Expression>> textColor;
};
    
class FormatExpression final : public Expression {
public:
    explicit FormatExpression(std::vector<FormatExpressionSection> sections);
    
    EvaluationResult evaluate(const EvaluationContext&) const override;
    static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&);
    
    void eachChild(const std::function<void(const Expression&)>&) const override;
    
    bool operator==(const Expression& e) const override;
    
    std::vector<optional<Value>> possibleOutputs() const override {
        // Technically the combinatoric set of all children
        // Usually, this.text will be undefined anyway
        return { nullopt };
    }
    
    const std::vector<FormatExpressionSection>& getSections() const { return sections; }

    mbgl::Value serialize() const override;
    std::string getOperator() const override { return "format"; }
private:
    std::vector<FormatExpressionSection> sections;
};
    
} // namespace expression
} // namespace style
} // namespace mbgl