#pragma once #include #include #include namespace mbgl { namespace style { template class PropertyValue { private: using Value = variant>; Value value; friend bool operator==(const PropertyValue& lhs, const PropertyValue& rhs) noexcept { return lhs.value == rhs.value; } friend bool operator!=(const PropertyValue& lhs, const PropertyValue& rhs) noexcept { return !(lhs == rhs); } public: PropertyValue() = default; PropertyValue(T constant) : value(std::forward(constant)) {} PropertyValue(PropertyExpression expression) noexcept : value(std::move(expression)) {} bool isUndefined() const noexcept { return value.template is(); } bool isConstant() const noexcept { return value.template is(); } bool isExpression() const noexcept { return value.template is>(); } bool isDataDriven() const noexcept { return value.match([](const Undefined&) { return false; }, [](const T&) { return false; }, [](const PropertyExpression& fn) { return !fn.isFeatureConstant(); }); } bool isZoomConstant() const noexcept { return value.match([](const Undefined&) { return true; }, [](const T&) { return true; }, [](const PropertyExpression& fn) { return fn.isZoomConstant(); }); } const T& asConstant() const noexcept { return value.template get(); } PropertyExpression& asExpression() noexcept { return value.template get>(); } const PropertyExpression& asExpression() const noexcept { return value.template get>(); } template auto match(Ts&&... ts) const { return value.match(std::forward(ts)...); } template auto evaluate(const Evaluator& evaluator, TimePoint = {}) const { return Value::visit(value, evaluator); } bool hasDataDrivenPropertyDifference(const PropertyValue& other) const noexcept { return *this != other && (isDataDriven() || other.isDataDriven()); } using Dependency = style::expression::Dependency; Dependency getDependencies() const noexcept { return value.match([](const Undefined&) { return Dependency::None; }, [](const T&) { return Dependency::None; }, [](const PropertyExpression& ex) { return ex.getDependencies(); }); } }; } // namespace style } // namespace mbgl