summaryrefslogtreecommitdiff
path: root/include/mbgl/style/color_ramp_property_value.hpp
blob: 03d74fae0c6a769d3c24b2e7b1211f9b600db468 (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
#pragma once

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

namespace mbgl {
namespace style {

/*
 * Special-case implementation of (a subset of) the PropertyValue<T> interface
 * used for building the HeatmapColor paint property traits class.
 */
class ColorRampPropertyValue {
private:
    std::shared_ptr<expression::Expression> value;

    friend bool operator==(const ColorRampPropertyValue& lhs, const ColorRampPropertyValue& rhs) {
        return (lhs.isUndefined() && rhs.isUndefined()) || (lhs.value && rhs.value && *(lhs.value) == *(rhs.value));
    }

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

public:
    ColorRampPropertyValue() : value(nullptr) {}
    ColorRampPropertyValue(std::shared_ptr<expression::Expression> value_) : value(std::move(value_)) {}

    bool isUndefined() const { return value.get() == nullptr; }

    // noop, needed for batch evaluation of paint property values to compile
    template <typename Evaluator>
    Color evaluate(const Evaluator&, TimePoint = {}) const { return {}; }

    Color evaluate(double rampEvaluationParameter) const {
        const auto result = value->evaluate(expression::EvaluationContext({}, nullptr, {rampEvaluationParameter}));
        return *expression::fromExpressionValue<Color>(*result);
    }

    bool isDataDriven()     const { return false; }
    bool hasDataDrivenPropertyDifference(const ColorRampPropertyValue&) const { return false; }
    
    const expression::Expression& getExpression() const { return *value; }
};


} // namespace style
} // namespace mbgl