#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) const { using namespace mbgl::style::expression; if (isUndefined(value)) { return DataDrivenPropertyValue(); } 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, convertTokens); } else { optional constant = convert(value, error); if (!constant) { return {}; } return convertTokens ? maybeConvertTokens(*constant) : DataDrivenPropertyValue(*constant); } if (!expression) { return {}; } else if (!(*expression).isFeatureConstant() || !(*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 DataDrivenPropertyValue(*constant); } else { assert(false); error = { "expected a literal expression" }; return {}; } } template DataDrivenPropertyValue maybeConvertTokens(const S& t) const { return DataDrivenPropertyValue(t); }; DataDrivenPropertyValue maybeConvertTokens(const std::string& t) const { return hasTokens(t) ? DataDrivenPropertyValue(PropertyExpression(convertTokenStringToExpression(t))) : DataDrivenPropertyValue(t); } }; } // namespace conversion } // namespace style } // namespace mbgl