#pragma once #include #include #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) const { using namespace mbgl::style::expression; if (isUndefined(value)) { return DataDrivenPropertyValue(); } else if (isExpression(value)) { ParsingContext ctx(valueTypeToExpressionType()); ParseResult expression = ctx.parseLayerPropertyExpression(value); if (!expression) { error = { ctx.getCombinedErrors() }; return {}; } bool featureConstant = isFeatureConstant(**expression); bool zoomConstant = isZoomConstant(**expression); if (featureConstant && !zoomConstant) { return DataDrivenPropertyValue(CameraFunction(std::move(*expression))); } else if (!featureConstant && zoomConstant) { return DataDrivenPropertyValue(SourceFunction(std::move(*expression))); } else if (!featureConstant && !zoomConstant) { return DataDrivenPropertyValue(CompositeFunction(std::move(*expression))); } else { auto literal = dynamic_cast(expression->get()); assert(literal); optional constant = fromExpressionValue(literal->getValue()); if (!constant) { return {}; } return DataDrivenPropertyValue(*constant); } } else if (!isObject(value)) { optional constant = convert(value, error); if (!constant) { return {}; } return DataDrivenPropertyValue(*constant); } else if (!objectMember(value, "property")) { optional> function = convert>(value, error); if (!function) { return {}; } return DataDrivenPropertyValue(*function); } else { optional> composite = convert>(value, error); if (composite) { return DataDrivenPropertyValue(*composite); } optional> source = convert>(value, error); if (!source) { return {}; } return DataDrivenPropertyValue(*source); } } }; } // namespace conversion } // namespace style } // namespace mbgl