summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layout_property.hpp
blob: f5045b47fcb527d75e50600eaee50b803792b0f5 (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
#pragma once

#include <mbgl/style/property_value.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/style/property_evaluator.hpp>
#include <mbgl/util/rapidjson.hpp>

#include <utility>

namespace mbgl {
namespace style {

template <typename T>
class LayoutProperty {
public:
    explicit LayoutProperty(T v)
        : value(std::move(v)),
          defaultValue(value) {}

    const PropertyValue<T>& get() const {
        return currentValue;
    }

    void set(const PropertyValue<T>& value_) {
        currentValue = value_;
    }

    void parse(const char * name, const JSValue& layout) {
        if (layout.HasMember(name)) {
            currentValue = parseProperty<T>(name, layout[name]);
        }
    }

    void calculate(const CalculationParameters& parameters) {
        if (currentValue) {
            PropertyEvaluator<T> evaluator(parameters, defaultValue);
            value = PropertyValue<T>::visit(currentValue, evaluator);
        }
    }

    // TODO: remove / privatize
    operator T() const { return value; }
    T value;

private:
    T defaultValue;
    PropertyValue<T> currentValue;
};

} // namespace style
} // namespace mbgl