#pragma once #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) != 2) { error = { "value must be an array of two numbers" }; return {}; } optional first = toNumber(arrayMember(value, 0)); optional second = toNumber(arrayMember(value, 1)); if (!first || !second) { error = { "value must be an array of two numbers" }; return {}; } return std::array {{ *first, *second }}; } }; template <> struct Converter> { template optional> operator()(const V& value, Error& error) const { if (!isArray(value) || arrayLength(value) != 4) { error = { "value must be an array of four numbers" }; return {}; } optional first = toNumber(arrayMember(value, 0)); optional second = toNumber(arrayMember(value, 1)); optional third = toNumber(arrayMember(value, 2)); optional fourth = toNumber(arrayMember(value, 3)); if (!first || !second) { error = { "value must be an array of four numbers" }; return {}; } return std::array {{ *first, *second, *third, *fourth }}; } }; 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