#pragma once #include #include #include #include #include #include #include #include namespace mbgl { namespace style { namespace conversion { template <> struct Converter { template optional operator()(const V& value, Error& error) const { optional converted = toBool(value); if (!converted) { error = { "value must be a boolean" }; return {}; } return *converted; } }; template <> struct Converter { template optional operator()(const V& value, Error& error) const { optional converted = toNumber(value); if (!converted) { error = { "value must be a number" }; return {}; } return *converted; } }; template <> struct Converter { template optional operator()(const V& value, Error& error) const { optional converted = toString(value); if (!converted) { error = { "value must be a string" }; return {}; } return *converted; } }; template struct Converter::value>> { template optional operator()(const V& value, Error& error) const { optional string = toString(value); if (!string) { error = { "value must be a string" }; return {}; } const auto result = Enum::toEnum(*string); if (!result) { error = { "value must be a valid enumeration value" }; return {}; } return *result; } }; template <> struct Converter { template optional operator()(const V& value, Error& error) const { optional string = toString(value); if (!string) { error = { "value must be a string" }; return {}; } optional color = Color::parse(*string); if (!color) { error = { "value must be a valid color" }; return {}; } return *color; } }; template struct Converter> { template optional> operator()(const V& value, Error& error) const { if (!isArray(value) || arrayLength(value) != N) { error = { "value must be an array of " + util::toString(N) + " numbers" }; return {}; } std::array result; for (size_t i = 0; i < N; i++) { optional n = toNumber(arrayMember(value, i)); if (!n) { error = { "value must be an array of " + util::toString(N) + " numbers" }; return {}; } result[i] = *n; } return result; } }; template <> struct Converter> { template optional> operator()(const V& value, Error& error) const { if (!isArray(value)) { error = { "value must be an array" }; return {}; } std::vector result; result.reserve(arrayLength(value)); for (std::size_t i = 0; i < arrayLength(value); ++i) { optional number = toNumber(arrayMember(value, i)); if (!number) { error = { "value must be an array of numbers" }; return {}; } result.push_back(*number); } return result; } }; template <> struct Converter> { template optional> operator()(const V& value, Error& error) const { if (!isArray(value)) { error = { "value must be an array" }; return {}; } std::vector result; result.reserve(arrayLength(value)); for (std::size_t i = 0; i < arrayLength(value); ++i) { optional string = toString(arrayMember(value, i)); if (!string) { error = { "value must be an array of strings" }; return {}; } result.push_back(*string); } return result; } }; } // namespace conversion } // namespace style } // namespace mbgl