#pragma once #include #include #include #include #include #include #include #include #include namespace mbgl { namespace style { namespace conversion { template struct Converter> { optional> operator()(const Convertible& value, Error& error, bool convertTokens = false) const { using namespace mbgl::style::expression; // Only icon-image and text-field support tokens, and they are both data-driven. assert(!convertTokens); (void)convertTokens; if (isUndefined(value)) { return PropertyValue(); } optional> expression; if (isExpression(value)) { ParsingContext ctx(valueTypeToExpressionType()); ParseResult parsed = ctx.parseLayerPropertyExpression(value); if (!parsed) { error.message = ctx.getCombinedErrors(); return nullopt; } expression = PropertyExpression(std::move(*parsed)); } else if (isObject(value)) { expression = convertFunctionToExpression(value, error, false); } else { optional constant = convert(value, error); if (!constant) { return nullopt; } return { *constant }; } if (!expression) { return nullopt; } else if (!(*expression).isFeatureConstant()) { error.message = "data expressions not supported"; return nullopt; } else if (!(*expression).isZoomConstant()) { return { std::move(*expression) }; } else if ((*expression).getExpression().getKind() == Kind::Literal) { optional constant = fromExpressionValue( static_cast((*expression).getExpression()).getValue()); if (!constant) { return nullopt; } return PropertyValue(*constant); } else { assert(false); error.message = "expected a literal expression"; return nullopt; } } }; } // namespace conversion } // namespace style } // namespace mbgl