#pragma once #include #include #include #include #include #include #include namespace mbgl { namespace style { namespace conversion { template <> struct Converter { template Result operator()(const V& value) const { optional converted = toBool(value); if (!converted) { return Error { "value must be a boolean" }; } return *converted; } }; template <> struct Converter { template Result operator()(const V& value) const { optional converted = toNumber(value); if (!converted) { return Error { "value must be a number" }; } return *converted; } }; template <> struct Converter { template Result operator()(const V& value) const { optional converted = toString(value); if (!converted) { return Error { "value must be a string" }; } return *converted; } }; template struct Converter::value>> { template Result operator()(const V& value) const { optional string = toString(value); if (!string) { return Error { "value must be a string" }; } const auto result = Enum::toEnum(*string); if (!result) { return Error { "value must be a valid enumeration value" }; } return *result; } }; template <> struct Converter { template Result operator()(const V& value) const { optional string = toString(value); if (!string) { return Error { "value must be a string" }; } optional color = Color::parse(*string); if (!color) { return Error { "value must be a valid color" }; } return *color; } }; template <> struct Converter> { template Result> operator()(const V& value) const { if (!isArray(value) || arrayLength(value) != 2) { return Error { "value must be an array of two numbers" }; } optional first = toNumber(arrayMember(value, 0)); optional second = toNumber(arrayMember(value, 1)); if (!first || !second) { return Error { "value must be an array of two numbers" }; } return std::array {{ *first, *second }}; } }; template <> struct Converter> { template Result> operator()(const V& value) const { if (!isArray(value) || arrayLength(value) != 4) { return Error { "value must be an array of four numbers" }; } 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) { return Error { "value must be an array of four numbers" }; } return std::array {{ *first, *second, *third, *fourth }}; } }; template <> struct Converter> { template Result> operator()(const V& value) const { if (!isArray(value)) { return Error { "value must be an array" }; } 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) { return Error { "value must be an array of numbers" }; } result.push_back(*number); } return result; } }; template <> struct Converter> { template Result> operator()(const V& value) const { if (!isArray(value)) { return Error { "value must be an array" }; } 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) { return Error { "value must be an array of strings" }; } result.push_back(*string); } return result; } }; } // namespace conversion } // namespace style } // namespace mbgl