#pragma once #include #include #include namespace mbgl { namespace style { namespace conversion { template struct Converter> { template Result> operator()(const V& value) const { if (!isObject(value)) { return Error { "function must be an object" }; } auto stopsValue = objectMember(value, "stops"); if (!stopsValue) { return Error { "function value must specify stops" }; } if (!isArray(*stopsValue)) { return Error { "function stops must be an array" }; } std::vector> stops; for (std::size_t i = 0; i < arrayLength(*stopsValue); ++i) { const auto& stopValue = arrayMember(*stopsValue, i); if (!isArray(stopValue)) { return Error { "function stop must be an array" }; } if (arrayLength(stopValue) != 2) { return Error { "function stop must have two elements" }; } optional z = toNumber(arrayMember(stopValue, 0)); if (!z) { return Error { "function stop zoom level must be a number" }; } Result v = convert(arrayMember(stopValue, 1)); if (!v) { return v.error(); } stops.emplace_back(*z, *v); } auto baseValue = objectMember(value, "base"); if (!baseValue) { return Function(stops, 1.0f); } optional base = toNumber(*baseValue); if (!base) { return Error { "function base must be a number"}; } return Function(stops, *base); } }; } // namespace conversion } // namespace style } // namespace mbgl