#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 = { ctx.getCombinedErrors() }; return {}; } expression = PropertyExpression(std::move(*parsed)); } else if (isObject(value)) { expression = convertFunctionToExpression(value, error, false); } else { optional constant = convert(value, error); if (!constant) { return {}; } return { *constant }; } if (!expression) { return {}; } else if (!(*expression).isFeatureConstant()) { error = { "data expressions not supported" }; return {}; } 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 {}; } return PropertyValue(*constant); } else { assert(false); error = { "expected a literal expression" }; return {}; } } }; } // namespace conversion } // namespace style } // namespace mbgl