#pragma once #include #include namespace mbgl { namespace style { namespace expression { template class FormatSectionOverride final : public Expression { public: FormatSectionOverride(const type::Type& type_, PossiblyEvaluatedPropertyValue defaultValue_, std::string propertyName_) : Expression(Kind::FormatSectionOverride, type_), 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.evaluate(*context.feature, *context.zoom, 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; } std::vector> possibleOutputs() const final { return {nullopt}; } std::string getOperator() const final { return "format-section-override"; } private: PossiblyEvaluatedPropertyValue defaultValue; std::string propertyName; }; } // namespace expression } // namespace style } // namespace mbgl