1 #pragma once 2 3 #include <mbgl/style/expression/expression.hpp> 4 #include <mbgl/style/conversion.hpp> 5 6 #include <memory> 7 #include <vector> 8 9 namespace mbgl { 10 namespace style { 11 namespace expression { 12 13 /** 14 * Special form for error-coalescing coercion expressions "to-number", 15 * "to-color". Since these coercions can fail at runtime, they accept multiple 16 * arguments, only evaluating one at a time until one succeeds. 17 */ 18 class Coercion : public Expression { 19 public: 20 Coercion(type::Type type_, std::vector<std::unique_ptr<Expression>> inputs_); 21 22 static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 23 24 EvaluationResult evaluate(const EvaluationContext& params) const override; 25 void eachChild(const std::function<void(const Expression&)>& visit) const override; 26 27 bool operator==(const Expression& e) const override; 28 29 std::vector<optional<Value>> possibleOutputs() const override; 30 31 std::string getOperator() const override; 32 private: 33 EvaluationResult (*coerceSingleValue) (const Value& v); 34 std::vector<std::unique_ptr<Expression>> inputs; 35 }; 36 37 } // namespace expression 38 } // namespace style 39 } // namespace mbgl 40 41