#pragma once #include #include namespace mbgl { namespace style { namespace expression { template class FormatSectionOverride final : public Expression { public: FormatSectionOverride(type::Type type_, PossiblyEvaluatedPropertyValue defaultValue_, std::string propertyName_) : Expression(Kind::FormatSectionOverride, std::move(type_), defaultValue_.getDependencies() | Dependency::Override | Dependency::Feature), defaultValue(std::move(defaultValue_)), propertyName(std::move(propertyName_)) {} EvaluationResult evaluate(const EvaluationContext& context) const final { using Object = std::unordered_map; if (context.formattedSection && context.formattedSection->is()) { const auto& section = context.formattedSection->get(); if (section.find(propertyName) != section.end()) { return section.at(propertyName); } } return defaultValue.match( [&context](const style::PropertyExpression& e) { return e.getExpression().evaluate(context); }, [](const T& t) -> EvaluationResult { return t; }); } void eachChild(const std::function& fn) const final { defaultValue.match([&fn](const style::PropertyExpression& e) { fn(e.getExpression()); }, [](const T&) {}); } bool operator==(const Expression& e) const final { if (e.getKind() == Kind::FormatSectionOverride) { const auto* other = static_cast(&e); if (getType() != other->getType() || propertyName != other->propertyName) { return false; } // Check that default values or property expressions are equal. return defaultValue.match( [other](const style::PropertyExpression& thisExpr) { return other->defaultValue.match( [&thisExpr](const style::PropertyExpression& otherExpr) { return thisExpr == otherExpr; }, [](const T&) { return false; }); }, [other](const T& thisValue) { return other->defaultValue.match( [&thisValue](const T& otherValue) { return thisValue == otherValue; }, [](const style::PropertyExpression&) { return false; }); }); } return false; } bool operator==(const FormatSectionOverride& other) const { return *this == static_cast(other); } std::vector> possibleOutputs() const final { return {std::nullopt}; } std::string getOperator() const final { return "format-section-override"; } private: PossiblyEvaluatedPropertyValue defaultValue; std::string propertyName; }; } // namespace expression } // namespace style } // namespace mbgl