1#pragma once
2
3#include <mbgl/style/conversion.hpp>
4#include <mbgl/util/color.hpp>
5#include <mbgl/util/enum.hpp>
6#include <mbgl/util/string.hpp>
7
8#include <array>
9#include <string>
10#include <vector>
11
12namespace mbgl {
13namespace style {
14namespace conversion {
15
16template <>
17struct Converter<bool> {
18 optional<bool> operator()(const Convertible& value, Error& error) const;
19};
20
21template <>
22struct Converter<float> {
23 optional<float> operator()(const Convertible& value, Error& error) const;
24};
25
26template <>
27struct Converter<std::string> {
28 optional<std::string> operator()(const Convertible& value, Error& error) const;
29};
30
31template <class T>
32struct Converter<T, typename std::enable_if_t<std::is_enum<T>::value>> {
33 optional<T> operator()(const Convertible& value, Error& error) const {
34 optional<std::string> string = toString(v: value);
35 if (!string) {
36 error = { .message: "value must be a string" };
37 return {};
38 }
39
40 const auto result = Enum<T>::toEnum(*string);
41 if (!result) {
42 error = { .message: "value must be a valid enumeration value" };
43 return {};
44 }
45
46 return *result;
47 }
48};
49
50template <>
51struct Converter<Color> {
52 optional<Color> operator()(const Convertible& value, Error& error) const;
53};
54
55template <size_t N>
56struct Converter<std::array<float, N>> {
57 optional<std::array<float, N>> operator()(const Convertible& value, Error& error) const {
58 if (!isArray(v: value) || arrayLength(v: value) != N) {
59 error = { .message: "value must be an array of " + util::toString(t: N) + " numbers" };
60 return {};
61 }
62
63 std::array<float, N> result;
64 for (size_t i = 0; i < N; i++) {
65 optional<float> n = toNumber(v: arrayMember(v: value, i));
66 if (!n) {
67 error = { .message: "value must be an array of " + util::toString(t: N) + " numbers" };
68 return {};
69 }
70 result[i] = *n;
71 }
72 return result;
73 }
74};
75
76template <>
77struct Converter<std::vector<float>> {
78 optional<std::vector<float>> operator()(const Convertible& value, Error& error) const;
79};
80
81template <>
82struct Converter<std::vector<std::string>> {
83 optional<std::vector<std::string>> operator()(const Convertible& value, Error& error) const;
84};
85
86} // namespace conversion
87} // namespace style
88} // namespace mbgl
89

source code of qtlocation/src/3rdparty/mapbox-gl-native/include/mbgl/style/conversion/constant.hpp