Mercurial > code
comparison cpp/json_util/json_util.hpp @ 651:728bdf008ec3
json_util: wording
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 23 Oct 2018 21:15:00 +0200 |
parents | ff73f2dd1c82 |
children | 6739771fba29 |
comparison
equal
deleted
inserted
replaced
650:ff73f2dd1c82 | 651:728bdf008ec3 |
---|---|
36 namespace json_util { | 36 namespace json_util { |
37 | 37 |
38 /** | 38 /** |
39 * \brief Describe how to convert a JSON value. | 39 * \brief Describe how to convert a JSON value. |
40 * | 40 * |
41 * This class must be specialized for every type you want to convert from JSON | 41 * This traits must be specialized for every type you want to convert from JSON |
42 * to its native type. | 42 * to its native type. |
43 * | 43 * |
44 * You only need to implement the get function with the following signature: | 44 * You only need to implement the get function with the following signature: |
45 * | 45 * |
46 * ```cpp | 46 * ```cpp |
48 * ``` | 48 * ``` |
49 * | 49 * |
50 * The implementation should not throw an exception but return a null optional | 50 * The implementation should not throw an exception but return a null optional |
51 * instead. | 51 * instead. |
52 * | 52 * |
53 * This class is already specialized for the given types: | 53 * This traits is already specialized for the given types: |
54 * | 54 * |
55 * - bool | 55 * - bool |
56 * - double | 56 * - double |
57 * - std::uint(8, 16, 32, 64)_t | 57 * - std::uint(8, 16, 32, 64)_t |
58 * - std::string | 58 * - std::string |
67 struct type_traits<bool> { | 67 struct type_traits<bool> { |
68 /** | 68 /** |
69 * Convert the JSON value to bool. | 69 * Convert the JSON value to bool. |
70 * | 70 * |
71 * \param value the value | 71 * \param value the value |
72 * \return the bool or none if not a boolean type | 72 * \return the bool or empty if not a boolean type |
73 */ | 73 */ |
74 static auto get(const nlohmann::json& value) noexcept -> std::optional<bool>; | 74 static auto get(const nlohmann::json& value) noexcept -> std::optional<bool>; |
75 }; | 75 }; |
76 | 76 |
77 /** | 77 /** |
81 struct type_traits<double> { | 81 struct type_traits<double> { |
82 /** | 82 /** |
83 * Convert the JSON value to bool. | 83 * Convert the JSON value to bool. |
84 * | 84 * |
85 * \param value the value | 85 * \param value the value |
86 * \return the double or none if not a double type | 86 * \return the double or empty if not a double type |
87 */ | 87 */ |
88 static auto get(const nlohmann::json& value) noexcept -> std::optional<double>; | 88 static auto get(const nlohmann::json& value) noexcept -> std::optional<double>; |
89 }; | 89 }; |
90 | 90 |
91 /** | 91 /** |
95 struct type_traits<std::string> { | 95 struct type_traits<std::string> { |
96 /** | 96 /** |
97 * Convert the JSON value to std::string. | 97 * Convert the JSON value to std::string. |
98 * | 98 * |
99 * \param value the value | 99 * \param value the value |
100 * \return the string or none if not a string type | 100 * \return the string or empty if not a string type |
101 */ | 101 */ |
102 static auto get(const nlohmann::json& value) -> std::optional<std::string>; | 102 static auto get(const nlohmann::json& value) -> std::optional<std::string>; |
103 }; | 103 }; |
104 | 104 |
105 /** | 105 /** |
109 struct type_traits<std::int8_t> { | 109 struct type_traits<std::int8_t> { |
110 /** | 110 /** |
111 * Convert the JSON value to std::int8_t. | 111 * Convert the JSON value to std::int8_t. |
112 * | 112 * |
113 * \param value the value | 113 * \param value the value |
114 * \return the value or none if value does not fit between the range | 114 * \return the value or empty if value does not fit between the range |
115 */ | 115 */ |
116 static auto get(const nlohmann::json& value) -> std::optional<std::int8_t>; | 116 static auto get(const nlohmann::json& value) -> std::optional<std::int8_t>; |
117 }; | 117 }; |
118 | 118 |
119 /** | 119 /** |
123 struct type_traits<std::int16_t> { | 123 struct type_traits<std::int16_t> { |
124 /** | 124 /** |
125 * Convert the JSON value to std::int16_t. | 125 * Convert the JSON value to std::int16_t. |
126 * | 126 * |
127 * \param value the value | 127 * \param value the value |
128 * \return the value or none if value does not fit between the range | 128 * \return the value or empty if value does not fit between the range |
129 */ | 129 */ |
130 static auto get(const nlohmann::json& value) -> std::optional<std::int16_t>; | 130 static auto get(const nlohmann::json& value) -> std::optional<std::int16_t>; |
131 }; | 131 }; |
132 | 132 |
133 /** | 133 /** |
137 struct type_traits<std::int32_t> { | 137 struct type_traits<std::int32_t> { |
138 /** | 138 /** |
139 * Convert the JSON value to std::int32_t. | 139 * Convert the JSON value to std::int32_t. |
140 * | 140 * |
141 * \param value the value | 141 * \param value the value |
142 * \return the value or none if value does not fit between the range | 142 * \return the value or empty if value does not fit between the range |
143 */ | 143 */ |
144 static auto get(const nlohmann::json& value) -> std::optional<std::int32_t>; | 144 static auto get(const nlohmann::json& value) -> std::optional<std::int32_t>; |
145 }; | 145 }; |
146 | 146 |
147 /** | 147 /** |
151 struct type_traits<std::int64_t> { | 151 struct type_traits<std::int64_t> { |
152 /** | 152 /** |
153 * Convert the JSON value to std::int64_t. | 153 * Convert the JSON value to std::int64_t. |
154 * | 154 * |
155 * \param value the value | 155 * \param value the value |
156 * \return the int or none if not a int type | 156 * \return the int or empty if not a int type |
157 */ | 157 */ |
158 static auto get(const nlohmann::json& value) noexcept -> std::optional<std::int64_t>; | 158 static auto get(const nlohmann::json& value) noexcept -> std::optional<std::int64_t>; |
159 }; | 159 }; |
160 | 160 |
161 /** | 161 /** |
165 struct type_traits<std::uint8_t> { | 165 struct type_traits<std::uint8_t> { |
166 /** | 166 /** |
167 * Convert the JSON value to std::uint8_t. | 167 * Convert the JSON value to std::uint8_t. |
168 * | 168 * |
169 * \param value the value | 169 * \param value the value |
170 * \return the value or none if value does not fit between the range | 170 * \return the value or empty if value does not fit between the range |
171 */ | 171 */ |
172 static auto get(const nlohmann::json& value) -> std::optional<std::uint8_t>; | 172 static auto get(const nlohmann::json& value) -> std::optional<std::uint8_t>; |
173 }; | 173 }; |
174 | 174 |
175 /** | 175 /** |
179 struct type_traits<std::uint16_t> { | 179 struct type_traits<std::uint16_t> { |
180 /** | 180 /** |
181 * Convert the JSON value to std::uint16_t. | 181 * Convert the JSON value to std::uint16_t. |
182 * | 182 * |
183 * \param value the value | 183 * \param value the value |
184 * \return the value or none if value does not fit between the range | 184 * \return the value or empty if value does not fit between the range |
185 */ | 185 */ |
186 static auto get(const nlohmann::json& value) -> std::optional<std::uint16_t>; | 186 static auto get(const nlohmann::json& value) -> std::optional<std::uint16_t>; |
187 }; | 187 }; |
188 | 188 |
189 /** | 189 /** |
193 struct type_traits<std::uint32_t> { | 193 struct type_traits<std::uint32_t> { |
194 /** | 194 /** |
195 * Convert the JSON value to std::uint32_t. | 195 * Convert the JSON value to std::uint32_t. |
196 * | 196 * |
197 * \param value the value | 197 * \param value the value |
198 * \return the value or none if value does not fit between the range | 198 * \return the value or empty if value does not fit between the range |
199 */ | 199 */ |
200 static auto get(const nlohmann::json& value) -> std::optional<std::uint32_t>; | 200 static auto get(const nlohmann::json& value) -> std::optional<std::uint32_t>; |
201 }; | 201 }; |
202 | 202 |
203 /** | 203 /** |
207 struct type_traits<std::uint64_t> { | 207 struct type_traits<std::uint64_t> { |
208 /** | 208 /** |
209 * Convert the JSON value to std::uint64_t. | 209 * Convert the JSON value to std::uint64_t. |
210 * | 210 * |
211 * \param value the value | 211 * \param value the value |
212 * \return the int or none if not a int type | 212 * \return the int or empty if not a int type |
213 */ | 213 */ |
214 static auto get(const nlohmann::json& value) noexcept -> std::optional<std::uint64_t>; | 214 static auto get(const nlohmann::json& value) noexcept -> std::optional<std::uint64_t>; |
215 }; | 215 }; |
216 | 216 |
217 /** | 217 /** |