summaryrefslogtreecommitdiff
path: root/include/mbgl/style/data_driven_property_value.hpp
blob: 5d7c596363b48d4195d8c19e392205ebc2a66798 (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
#pragma once

#include <mbgl/util/variant.hpp>
#include <mbgl/style/undefined.hpp>
#include <mbgl/style/function/camera_function.hpp>
#include <mbgl/style/function/source_function.hpp>
#include <mbgl/style/function/composite_function.hpp>

namespace mbgl {
namespace style {

template <class T>
class DataDrivenPropertyValue {
private:
    using Value = variant<
        Undefined,
        T,
        CameraFunction<T>,
        SourceFunction<T>,
        CompositeFunction<T>>;

    Value value;

    friend bool operator==(const DataDrivenPropertyValue& lhs,
                           const DataDrivenPropertyValue& rhs) {
        return lhs.value == rhs.value;
    }

    friend bool operator!=(const DataDrivenPropertyValue& lhs,
                           const DataDrivenPropertyValue& rhs) {
        return !(lhs == rhs);
    }

public:
    DataDrivenPropertyValue() = default;
    DataDrivenPropertyValue(                  T  v) : value(std::move(v)) {}
    DataDrivenPropertyValue(   CameraFunction<T> v) : value(std::move(v)) {}
    DataDrivenPropertyValue(   SourceFunction<T> v) : value(std::move(v)) {}
    DataDrivenPropertyValue(CompositeFunction<T> v) : value(std::move(v)) {}

    bool isUndefined() const {
        return value.template is<Undefined>();
    }

    bool isDataDriven() const {
        return value.template is<SourceFunction<T>>() || value.template is<CompositeFunction<T>>();
    }
    
    bool isZoomConstant() const {
        return !value.template is<CameraFunction<T>>() && !value.template is<CompositeFunction<T>>();
    }

    template <class... Ts>
    auto match(Ts&&... ts) const {
        return value.match(std::forward<Ts>(ts)...);
    }

    template <typename Evaluator>
    auto evaluate(const Evaluator& evaluator, TimePoint = {}) const {
        return Value::visit(value, evaluator);
    }

    bool hasDataDrivenPropertyDifference(const DataDrivenPropertyValue<T>& other) const {
        return *this != other && (isDataDriven() || other.isDataDriven());
    }
};

} // namespace style
} // namespace mbgl