JSON for Modern C++  3.9.1
json.hpp
1 /*
2  __ _____ _____ _____
3  __| | __| | | | JSON for Modern C++
4 | | |__ | | | | | | version 3.9.1
5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
6 
7 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
8 SPDX-License-Identifier: MIT
9 Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 SOFTWARE.
28 */
29 
30 #ifndef INCLUDE_NLOHMANN_JSON_HPP_
31 #define INCLUDE_NLOHMANN_JSON_HPP_
32 
33 #define NLOHMANN_JSON_VERSION_MAJOR 3
34 #define NLOHMANN_JSON_VERSION_MINOR 9
35 #define NLOHMANN_JSON_VERSION_PATCH 1
36 
37 #include <algorithm> // all_of, find, for_each
38 #include <cstddef> // nullptr_t, ptrdiff_t, size_t
39 #include <functional> // hash, less
40 #include <initializer_list> // initializer_list
41 #ifndef JSON_NO_IO
42  #include <iosfwd> // istream, ostream
43 #endif // JSON_NO_IO
44 #include <iterator> // random_access_iterator_tag
45 #include <memory> // unique_ptr
46 #include <numeric> // accumulate
47 #include <string> // string, stoi, to_string
48 #include <utility> // declval, forward, move, pair, swap
49 #include <vector> // vector
50 
51 // #include <nlohmann/adl_serializer.hpp>
52 
53 
54 #include <type_traits>
55 #include <utility>
56 
57 // #include <nlohmann/detail/conversions/from_json.hpp>
58 
59 
60 #include <algorithm> // transform
61 #include <array> // array
62 #include <forward_list> // forward_list
63 #include <iterator> // inserter, front_inserter, end
64 #include <map> // map
65 #include <string> // string
66 #include <tuple> // tuple, make_tuple
67 #include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible
68 #include <unordered_map> // unordered_map
69 #include <utility> // pair, declval
70 #include <valarray> // valarray
71 
72 // #include <nlohmann/detail/exceptions.hpp>
73 
74 
75 #include <exception> // exception
76 #include <stdexcept> // runtime_error
77 #include <string> // to_string
78 #include <vector> // vector
79 
80 // #include <nlohmann/detail/value_t.hpp>
81 
82 
83 #include <array> // array
84 #include <cstddef> // size_t
85 #include <cstdint> // uint8_t
86 #include <string> // string
87 
88 namespace nlohmann
89 {
90 namespace detail
91 {
93 // JSON type enumeration //
95 
120 enum class value_t : std::uint8_t
121 {
122  null,
123  object,
124  array,
125  string,
126  boolean,
127  number_integer,
128  number_unsigned,
129  number_float,
130  binary,
131  discarded
132 };
133 
147 inline bool operator<(const value_t lhs, const value_t rhs) noexcept
148 {
149  static constexpr std::array<std::uint8_t, 9> order = {{
150  0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,
151  1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */,
152  6 /* binary */
153  }
154  };
155 
156  const auto l_index = static_cast<std::size_t>(lhs);
157  const auto r_index = static_cast<std::size_t>(rhs);
158  return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
159 }
160 } // namespace detail
161 } // namespace nlohmann
162 
163 // #include <nlohmann/detail/string_escape.hpp>
164 
165 
166 #include <string>
167 // #include <nlohmann/detail/macro_scope.hpp>
168 
169 
170 #include <utility> // pair
171 // #include <nlohmann/thirdparty/hedley/hedley.hpp>
172 
173 
174 /* Hedley - https://nemequ.github.io/hedley
175  * Created by Evan Nemerson <evan@nemerson.com>
176  *
177  * To the extent possible under law, the author(s) have dedicated all
178  * copyright and related and neighboring rights to this software to
179  * the public domain worldwide. This software is distributed without
180  * any warranty.
181  *
182  * For details, see <http://creativecommons.org/publicdomain/zero/1.0/>.
183  * SPDX-License-Identifier: CC0-1.0
184  */
185 
186 #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
187 #if defined(JSON_HEDLEY_VERSION)
188  #undef JSON_HEDLEY_VERSION
189 #endif
190 #define JSON_HEDLEY_VERSION 15
191 
192 #if defined(JSON_HEDLEY_STRINGIFY_EX)
193  #undef JSON_HEDLEY_STRINGIFY_EX
194 #endif
195 #define JSON_HEDLEY_STRINGIFY_EX(x) #x
196 
197 #if defined(JSON_HEDLEY_STRINGIFY)
198  #undef JSON_HEDLEY_STRINGIFY
199 #endif
200 #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
201 
202 #if defined(JSON_HEDLEY_CONCAT_EX)
203  #undef JSON_HEDLEY_CONCAT_EX
204 #endif
205 #define JSON_HEDLEY_CONCAT_EX(a,b) a##b
206 
207 #if defined(JSON_HEDLEY_CONCAT)
208  #undef JSON_HEDLEY_CONCAT
209 #endif
210 #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
211 
212 #if defined(JSON_HEDLEY_CONCAT3_EX)
213  #undef JSON_HEDLEY_CONCAT3_EX
214 #endif
215 #define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
216 
217 #if defined(JSON_HEDLEY_CONCAT3)
218  #undef JSON_HEDLEY_CONCAT3
219 #endif
220 #define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
221 
222 #if defined(JSON_HEDLEY_VERSION_ENCODE)
223  #undef JSON_HEDLEY_VERSION_ENCODE
224 #endif
225 #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
226 
227 #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
228  #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
229 #endif
230 #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
231 
232 #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
233  #undef JSON_HEDLEY_VERSION_DECODE_MINOR
234 #endif
235 #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
236 
237 #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
238  #undef JSON_HEDLEY_VERSION_DECODE_REVISION
239 #endif
240 #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
241 
242 #if defined(JSON_HEDLEY_GNUC_VERSION)
243  #undef JSON_HEDLEY_GNUC_VERSION
244 #endif
245 #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
246  #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
247 #elif defined(__GNUC__)
248  #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
249 #endif
250 
251 #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
252  #undef JSON_HEDLEY_GNUC_VERSION_CHECK
253 #endif
254 #if defined(JSON_HEDLEY_GNUC_VERSION)
255  #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
256 #else
257  #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
258 #endif
259 
260 #if defined(JSON_HEDLEY_MSVC_VERSION)
261  #undef JSON_HEDLEY_MSVC_VERSION
262 #endif
263 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
264  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
265 #elif defined(_MSC_FULL_VER) && !defined(__ICL)
266  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
267 #elif defined(_MSC_VER) && !defined(__ICL)
268  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
269 #endif
270 
271 #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
272  #undef JSON_HEDLEY_MSVC_VERSION_CHECK
273 #endif
274 #if !defined(JSON_HEDLEY_MSVC_VERSION)
275  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
276 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
277  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
278 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
279  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
280 #else
281  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
282 #endif
283 
284 #if defined(JSON_HEDLEY_INTEL_VERSION)
285  #undef JSON_HEDLEY_INTEL_VERSION
286 #endif
287 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
288  #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
289 #elif defined(__INTEL_COMPILER) && !defined(__ICL)
290  #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
291 #endif
292 
293 #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
294  #undef JSON_HEDLEY_INTEL_VERSION_CHECK
295 #endif
296 #if defined(JSON_HEDLEY_INTEL_VERSION)
297  #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
298 #else
299  #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
300 #endif
301 
302 #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
303  #undef JSON_HEDLEY_INTEL_CL_VERSION
304 #endif
305 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
306  #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
307 #endif
308 
309 #if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
310  #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
311 #endif
312 #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
313  #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
314 #else
315  #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
316 #endif
317 
318 #if defined(JSON_HEDLEY_PGI_VERSION)
319  #undef JSON_HEDLEY_PGI_VERSION
320 #endif
321 #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
322  #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
323 #endif
324 
325 #if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
326  #undef JSON_HEDLEY_PGI_VERSION_CHECK
327 #endif
328 #if defined(JSON_HEDLEY_PGI_VERSION)
329  #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
330 #else
331  #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
332 #endif
333 
334 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
335  #undef JSON_HEDLEY_SUNPRO_VERSION
336 #endif
337 #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
338  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10)
339 #elif defined(__SUNPRO_C)
340  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
341 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
342  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10)
343 #elif defined(__SUNPRO_CC)
344  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
345 #endif
346 
347 #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
348  #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
349 #endif
350 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
351  #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
352 #else
353  #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
354 #endif
355 
356 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
357  #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
358 #endif
359 #if defined(__EMSCRIPTEN__)
360  #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
361 #endif
362 
363 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
364  #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
365 #endif
366 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
367  #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
368 #else
369  #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
370 #endif
371 
372 #if defined(JSON_HEDLEY_ARM_VERSION)
373  #undef JSON_HEDLEY_ARM_VERSION
374 #endif
375 #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
376  #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
377 #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
378  #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
379 #endif
380 
381 #if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
382  #undef JSON_HEDLEY_ARM_VERSION_CHECK
383 #endif
384 #if defined(JSON_HEDLEY_ARM_VERSION)
385  #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
386 #else
387  #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
388 #endif
389 
390 #if defined(JSON_HEDLEY_IBM_VERSION)
391  #undef JSON_HEDLEY_IBM_VERSION
392 #endif
393 #if defined(__ibmxl__)
394  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
395 #elif defined(__xlC__) && defined(__xlC_ver__)
396  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
397 #elif defined(__xlC__)
398  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
399 #endif
400 
401 #if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
402  #undef JSON_HEDLEY_IBM_VERSION_CHECK
403 #endif
404 #if defined(JSON_HEDLEY_IBM_VERSION)
405  #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
406 #else
407  #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
408 #endif
409 
410 #if defined(JSON_HEDLEY_TI_VERSION)
411  #undef JSON_HEDLEY_TI_VERSION
412 #endif
413 #if \
414  defined(__TI_COMPILER_VERSION__) && \
415  ( \
416  defined(__TMS470__) || defined(__TI_ARM__) || \
417  defined(__MSP430__) || \
418  defined(__TMS320C2000__) \
419  )
420 #if (__TI_COMPILER_VERSION__ >= 16000000)
421  #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
422 #endif
423 #endif
424 
425 #if defined(JSON_HEDLEY_TI_VERSION_CHECK)
426  #undef JSON_HEDLEY_TI_VERSION_CHECK
427 #endif
428 #if defined(JSON_HEDLEY_TI_VERSION)
429  #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
430 #else
431  #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
432 #endif
433 
434 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
435  #undef JSON_HEDLEY_TI_CL2000_VERSION
436 #endif
437 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
438  #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
439 #endif
440 
441 #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
442  #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
443 #endif
444 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
445  #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
446 #else
447  #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
448 #endif
449 
450 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
451  #undef JSON_HEDLEY_TI_CL430_VERSION
452 #endif
453 #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
454  #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
455 #endif
456 
457 #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
458  #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
459 #endif
460 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
461  #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
462 #else
463  #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
464 #endif
465 
466 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
467  #undef JSON_HEDLEY_TI_ARMCL_VERSION
468 #endif
469 #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
470  #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
471 #endif
472 
473 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
474  #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
475 #endif
476 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
477  #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
478 #else
479  #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
480 #endif
481 
482 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
483  #undef JSON_HEDLEY_TI_CL6X_VERSION
484 #endif
485 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
486  #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
487 #endif
488 
489 #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
490  #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
491 #endif
492 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
493  #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
494 #else
495  #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
496 #endif
497 
498 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
499  #undef JSON_HEDLEY_TI_CL7X_VERSION
500 #endif
501 #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
502  #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
503 #endif
504 
505 #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
506  #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
507 #endif
508 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
509  #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
510 #else
511  #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
512 #endif
513 
514 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
515  #undef JSON_HEDLEY_TI_CLPRU_VERSION
516 #endif
517 #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
518  #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
519 #endif
520 
521 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
522  #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
523 #endif
524 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
525  #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
526 #else
527  #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
528 #endif
529 
530 #if defined(JSON_HEDLEY_CRAY_VERSION)
531  #undef JSON_HEDLEY_CRAY_VERSION
532 #endif
533 #if defined(_CRAYC)
534  #if defined(_RELEASE_PATCHLEVEL)
535  #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
536  #else
537  #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
538  #endif
539 #endif
540 
541 #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
542  #undef JSON_HEDLEY_CRAY_VERSION_CHECK
543 #endif
544 #if defined(JSON_HEDLEY_CRAY_VERSION)
545  #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
546 #else
547  #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
548 #endif
549 
550 #if defined(JSON_HEDLEY_IAR_VERSION)
551  #undef JSON_HEDLEY_IAR_VERSION
552 #endif
553 #if defined(__IAR_SYSTEMS_ICC__)
554  #if __VER__ > 1000
555  #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
556  #else
557  #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
558  #endif
559 #endif
560 
561 #if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
562  #undef JSON_HEDLEY_IAR_VERSION_CHECK
563 #endif
564 #if defined(JSON_HEDLEY_IAR_VERSION)
565  #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
566 #else
567  #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
568 #endif
569 
570 #if defined(JSON_HEDLEY_TINYC_VERSION)
571  #undef JSON_HEDLEY_TINYC_VERSION
572 #endif
573 #if defined(__TINYC__)
574  #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
575 #endif
576 
577 #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
578  #undef JSON_HEDLEY_TINYC_VERSION_CHECK
579 #endif
580 #if defined(JSON_HEDLEY_TINYC_VERSION)
581  #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
582 #else
583  #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
584 #endif
585 
586 #if defined(JSON_HEDLEY_DMC_VERSION)
587  #undef JSON_HEDLEY_DMC_VERSION
588 #endif
589 #if defined(__DMC__)
590  #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
591 #endif
592 
593 #if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
594  #undef JSON_HEDLEY_DMC_VERSION_CHECK
595 #endif
596 #if defined(JSON_HEDLEY_DMC_VERSION)
597  #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
598 #else
599  #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
600 #endif
601 
602 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
603  #undef JSON_HEDLEY_COMPCERT_VERSION
604 #endif
605 #if defined(__COMPCERT_VERSION__)
606  #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
607 #endif
608 
609 #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
610  #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
611 #endif
612 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
613  #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
614 #else
615  #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
616 #endif
617 
618 #if defined(JSON_HEDLEY_PELLES_VERSION)
619  #undef JSON_HEDLEY_PELLES_VERSION
620 #endif
621 #if defined(__POCC__)
622  #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
623 #endif
624 
625 #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
626  #undef JSON_HEDLEY_PELLES_VERSION_CHECK
627 #endif
628 #if defined(JSON_HEDLEY_PELLES_VERSION)
629  #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
630 #else
631  #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
632 #endif
633 
634 #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
635  #undef JSON_HEDLEY_MCST_LCC_VERSION
636 #endif
637 #if defined(__LCC__) && defined(__LCC_MINOR__)
638  #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
639 #endif
640 
641 #if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
642  #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
643 #endif
644 #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
645  #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
646 #else
647  #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
648 #endif
649 
650 #if defined(JSON_HEDLEY_GCC_VERSION)
651  #undef JSON_HEDLEY_GCC_VERSION
652 #endif
653 #if \
654  defined(JSON_HEDLEY_GNUC_VERSION) && \
655  !defined(__clang__) && \
656  !defined(JSON_HEDLEY_INTEL_VERSION) && \
657  !defined(JSON_HEDLEY_PGI_VERSION) && \
658  !defined(JSON_HEDLEY_ARM_VERSION) && \
659  !defined(JSON_HEDLEY_CRAY_VERSION) && \
660  !defined(JSON_HEDLEY_TI_VERSION) && \
661  !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
662  !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
663  !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
664  !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
665  !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
666  !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
667  !defined(__COMPCERT__) && \
668  !defined(JSON_HEDLEY_MCST_LCC_VERSION)
669  #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
670 #endif
671 
672 #if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
673  #undef JSON_HEDLEY_GCC_VERSION_CHECK
674 #endif
675 #if defined(JSON_HEDLEY_GCC_VERSION)
676  #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
677 #else
678  #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
679 #endif
680 
681 #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
682  #undef JSON_HEDLEY_HAS_ATTRIBUTE
683 #endif
684 #if \
685  defined(__has_attribute) && \
686  ( \
687  (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
688  )
689 # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
690 #else
691 # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
692 #endif
693 
694 #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
695  #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
696 #endif
697 #if defined(__has_attribute)
698  #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
699 #else
700  #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
701 #endif
702 
703 #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
704  #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
705 #endif
706 #if defined(__has_attribute)
707  #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
708 #else
709  #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
710 #endif
711 
712 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
713  #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
714 #endif
715 #if \
716  defined(__has_cpp_attribute) && \
717  defined(__cplusplus) && \
718  (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
719  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
720 #else
721  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
722 #endif
723 
724 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
725  #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
726 #endif
727 #if !defined(__cplusplus) || !defined(__has_cpp_attribute)
728  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
729 #elif \
730  !defined(JSON_HEDLEY_PGI_VERSION) && \
731  !defined(JSON_HEDLEY_IAR_VERSION) && \
732  (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
733  (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
734  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
735 #else
736  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
737 #endif
738 
739 #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
740  #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
741 #endif
742 #if defined(__has_cpp_attribute) && defined(__cplusplus)
743  #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
744 #else
745  #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
746 #endif
747 
748 #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
749  #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
750 #endif
751 #if defined(__has_cpp_attribute) && defined(__cplusplus)
752  #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
753 #else
754  #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
755 #endif
756 
757 #if defined(JSON_HEDLEY_HAS_BUILTIN)
758  #undef JSON_HEDLEY_HAS_BUILTIN
759 #endif
760 #if defined(__has_builtin)
761  #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
762 #else
763  #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
764 #endif
765 
766 #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
767  #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
768 #endif
769 #if defined(__has_builtin)
770  #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
771 #else
772  #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
773 #endif
774 
775 #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
776  #undef JSON_HEDLEY_GCC_HAS_BUILTIN
777 #endif
778 #if defined(__has_builtin)
779  #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
780 #else
781  #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
782 #endif
783 
784 #if defined(JSON_HEDLEY_HAS_FEATURE)
785  #undef JSON_HEDLEY_HAS_FEATURE
786 #endif
787 #if defined(__has_feature)
788  #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
789 #else
790  #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
791 #endif
792 
793 #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
794  #undef JSON_HEDLEY_GNUC_HAS_FEATURE
795 #endif
796 #if defined(__has_feature)
797  #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
798 #else
799  #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
800 #endif
801 
802 #if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
803  #undef JSON_HEDLEY_GCC_HAS_FEATURE
804 #endif
805 #if defined(__has_feature)
806  #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
807 #else
808  #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
809 #endif
810 
811 #if defined(JSON_HEDLEY_HAS_EXTENSION)
812  #undef JSON_HEDLEY_HAS_EXTENSION
813 #endif
814 #if defined(__has_extension)
815  #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
816 #else
817  #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
818 #endif
819 
820 #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
821  #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
822 #endif
823 #if defined(__has_extension)
824  #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
825 #else
826  #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
827 #endif
828 
829 #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
830  #undef JSON_HEDLEY_GCC_HAS_EXTENSION
831 #endif
832 #if defined(__has_extension)
833  #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
834 #else
835  #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
836 #endif
837 
838 #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
839  #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
840 #endif
841 #if defined(__has_declspec_attribute)
842  #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
843 #else
844  #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
845 #endif
846 
847 #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
848  #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
849 #endif
850 #if defined(__has_declspec_attribute)
851  #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
852 #else
853  #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
854 #endif
855 
856 #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
857  #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
858 #endif
859 #if defined(__has_declspec_attribute)
860  #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
861 #else
862  #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
863 #endif
864 
865 #if defined(JSON_HEDLEY_HAS_WARNING)
866  #undef JSON_HEDLEY_HAS_WARNING
867 #endif
868 #if defined(__has_warning)
869  #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
870 #else
871  #define JSON_HEDLEY_HAS_WARNING(warning) (0)
872 #endif
873 
874 #if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
875  #undef JSON_HEDLEY_GNUC_HAS_WARNING
876 #endif
877 #if defined(__has_warning)
878  #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
879 #else
880  #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
881 #endif
882 
883 #if defined(JSON_HEDLEY_GCC_HAS_WARNING)
884  #undef JSON_HEDLEY_GCC_HAS_WARNING
885 #endif
886 #if defined(__has_warning)
887  #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
888 #else
889  #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
890 #endif
891 
892 #if \
893  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
894  defined(__clang__) || \
895  JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
896  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
897  JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
898  JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
899  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
900  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
901  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
902  JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
903  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
904  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
905  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
906  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
907  JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
908  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
909  JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
910  (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
911  #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
912 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
913  #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
914 #else
915  #define JSON_HEDLEY_PRAGMA(value)
916 #endif
917 
918 #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
919  #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
920 #endif
921 #if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
922  #undef JSON_HEDLEY_DIAGNOSTIC_POP
923 #endif
924 #if defined(__clang__)
925  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
926  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
927 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
928  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
929  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
930 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
931  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
932  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
933 #elif \
934  JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
935  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
936  #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
937  #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
938 #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
939  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
940  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
941 #elif \
942  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
943  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
944  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
945  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
946  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
947  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
948  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
949  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
950 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
951  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
952  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
953 #else
954  #define JSON_HEDLEY_DIAGNOSTIC_PUSH
955  #define JSON_HEDLEY_DIAGNOSTIC_POP
956 #endif
957 
958 /* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for
959  HEDLEY INTERNAL USE ONLY. API subject to change without notice. */
960 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
961  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
962 #endif
963 #if defined(__cplusplus)
964 # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
965 # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
966 # if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
967 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
968  JSON_HEDLEY_DIAGNOSTIC_PUSH \
969  _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
970  _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
971  _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
972  xpr \
973  JSON_HEDLEY_DIAGNOSTIC_POP
974 # else
975 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
976  JSON_HEDLEY_DIAGNOSTIC_PUSH \
977  _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
978  _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
979  xpr \
980  JSON_HEDLEY_DIAGNOSTIC_POP
981 # endif
982 # else
983 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
984  JSON_HEDLEY_DIAGNOSTIC_PUSH \
985  _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
986  xpr \
987  JSON_HEDLEY_DIAGNOSTIC_POP
988 # endif
989 # endif
990 #endif
991 #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
992  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
993 #endif
994 
995 #if defined(JSON_HEDLEY_CONST_CAST)
996  #undef JSON_HEDLEY_CONST_CAST
997 #endif
998 #if defined(__cplusplus)
999 # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1000 #elif \
1001  JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1002  JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1003  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1004 # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1005  JSON_HEDLEY_DIAGNOSTIC_PUSH \
1006  JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1007  ((T) (expr)); \
1008  JSON_HEDLEY_DIAGNOSTIC_POP \
1009  }))
1010 #else
1011 # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1012 #endif
1013 
1014 #if defined(JSON_HEDLEY_REINTERPRET_CAST)
1015  #undef JSON_HEDLEY_REINTERPRET_CAST
1016 #endif
1017 #if defined(__cplusplus)
1018  #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1019 #else
1020  #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1021 #endif
1022 
1023 #if defined(JSON_HEDLEY_STATIC_CAST)
1024  #undef JSON_HEDLEY_STATIC_CAST
1025 #endif
1026 #if defined(__cplusplus)
1027  #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1028 #else
1029  #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1030 #endif
1031 
1032 #if defined(JSON_HEDLEY_CPP_CAST)
1033  #undef JSON_HEDLEY_CPP_CAST
1034 #endif
1035 #if defined(__cplusplus)
1036 # if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1037 # define JSON_HEDLEY_CPP_CAST(T, expr) \
1038  JSON_HEDLEY_DIAGNOSTIC_PUSH \
1039  _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1040  ((T) (expr)) \
1041  JSON_HEDLEY_DIAGNOSTIC_POP
1042 # elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1043 # define JSON_HEDLEY_CPP_CAST(T, expr) \
1044  JSON_HEDLEY_DIAGNOSTIC_PUSH \
1045  _Pragma("diag_suppress=Pe137") \
1046  JSON_HEDLEY_DIAGNOSTIC_POP
1047 # else
1048 # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1049 # endif
1050 #else
1051 # define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1052 #endif
1053 
1054 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1055  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1056 #endif
1057 #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1058  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1059 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1060  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1061 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1062  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1063 #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1064  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1065 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1066  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1067 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1068  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1069 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1070  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1071 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1072  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1073 #elif \
1074  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1075  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1076  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1077  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1078  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1079  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1080  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1081  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1082  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1083  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1084  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1085  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1086 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1087  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1088 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1089  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1090 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1091  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1092 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1093  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1094 #else
1095  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1096 #endif
1097 
1098 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1099  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1100 #endif
1101 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1102  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1103 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1104  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1105 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1106  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1107 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1108  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1109 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1110  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1111 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1112  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1113 #elif \
1114  JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1115  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1116  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1117  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1118  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1119 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1120  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1121 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1122  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1123 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1124  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1125 #else
1126  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1127 #endif
1128 
1129 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1130  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1131 #endif
1132 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1133  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1134 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1135  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1136 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1137  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1138 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1139  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1140 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1141  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1142 #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1143  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1144 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1145  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1146 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1147  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1148 #elif \
1149  JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1150  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1151  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1152  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1153 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1154  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1155 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1156  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1157 #else
1158  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1159 #endif
1160 
1161 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1162  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1163 #endif
1164 #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1165  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1166 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1167  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1168 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1169  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1170 #else
1171  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1172 #endif
1173 
1174 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1175  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1176 #endif
1177 #if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1178  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1179 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1180  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1181 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1182  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1183 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1184  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1185 #else
1186  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1187 #endif
1188 
1189 #if defined(JSON_HEDLEY_DEPRECATED)
1190  #undef JSON_HEDLEY_DEPRECATED
1191 #endif
1192 #if defined(JSON_HEDLEY_DEPRECATED_FOR)
1193  #undef JSON_HEDLEY_DEPRECATED_FOR
1194 #endif
1195 #if \
1196  JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1197  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1198  #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1199  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1200 #elif \
1201  (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1202  JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1203  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1204  JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1205  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1206  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1207  JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1208  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1209  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1210  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1211  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1212  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1213  #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1214  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1215 #elif defined(__cplusplus) && (__cplusplus >= 201402L)
1216  #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1217  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1218 #elif \
1219  JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1220  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1221  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1222  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1223  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1224  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1225  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1226  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1227  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1228  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1229  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1230  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1231  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1232  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1233  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1234  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1235  #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1236  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1237 #elif \
1238  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1239  JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1240  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1241  #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1242  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1243 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1244  #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1245  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1246 #else
1247  #define JSON_HEDLEY_DEPRECATED(since)
1248  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1249 #endif
1250 
1251 #if defined(JSON_HEDLEY_UNAVAILABLE)
1252  #undef JSON_HEDLEY_UNAVAILABLE
1253 #endif
1254 #if \
1255  JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1256  JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1257  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1258  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1259  #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1260 #else
1261  #define JSON_HEDLEY_UNAVAILABLE(available_since)
1262 #endif
1263 
1264 #if defined()
1265  #undef
1266 #endif
1267 #if defined(_MSG)
1268  #undef _MSG
1269 #endif
1270 #if \
1271  JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1272  JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1273  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1274  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1275  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1276  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1277  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1278  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1279  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1280  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1281  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1282  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1283  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1284  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1285  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1286  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1287  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1288  #define __attribute__((__warn_unused_result__))
1289  #define _MSG(msg) __attribute__((__warn_unused_result__))
1290 #elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1291  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1292  #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1293 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1294  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1295  #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1296 #elif defined(_Check_return_) /* SAL */
1297  #define _Check_return_
1298  #define _MSG(msg) _Check_return_
1299 #else
1300  #define
1301  #define _MSG(msg)
1302 #endif
1303 
1304 #if defined(JSON_HEDLEY_SENTINEL)
1305  #undef JSON_HEDLEY_SENTINEL
1306 #endif
1307 #if \
1308  JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1309  JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1310  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1311  JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1312  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1313  #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1314 #else
1315  #define JSON_HEDLEY_SENTINEL(position)
1316 #endif
1317 
1318 #if defined(JSON_HEDLEY_NO_RETURN)
1319  #undef JSON_HEDLEY_NO_RETURN
1320 #endif
1321 #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1322  #define JSON_HEDLEY_NO_RETURN __noreturn
1323 #elif \
1324  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1325  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1326  #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1327 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1328  #define JSON_HEDLEY_NO_RETURN _Noreturn
1329 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1330  #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1331 #elif \
1332  JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1333  JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1334  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1335  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1336  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1337  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1338  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1339  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1340  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1341  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1342  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1343  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1344  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1345  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1346  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1347  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1348  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1349  #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1350 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1351  #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1352 #elif \
1353  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1354  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1355  #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1356 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1357  #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1358 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1359  #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1360 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1361  #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1362 #else
1363  #define JSON_HEDLEY_NO_RETURN
1364 #endif
1365 
1366 #if defined(JSON_HEDLEY_NO_ESCAPE)
1367  #undef JSON_HEDLEY_NO_ESCAPE
1368 #endif
1369 #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1370  #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1371 #else
1372  #define JSON_HEDLEY_NO_ESCAPE
1373 #endif
1374 
1375 #if defined(JSON_HEDLEY_UNREACHABLE)
1376  #undef JSON_HEDLEY_UNREACHABLE
1377 #endif
1378 #if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1379  #undef JSON_HEDLEY_UNREACHABLE_RETURN
1380 #endif
1381 #if defined(JSON_HEDLEY_ASSUME)
1382  #undef JSON_HEDLEY_ASSUME
1383 #endif
1384 #if \
1385  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1386  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1387  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1388  #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1389 #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1390  #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1391 #elif \
1392  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1393  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1394  #if defined(__cplusplus)
1395  #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1396  #else
1397  #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1398  #endif
1399 #endif
1400 #if \
1401  (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1402  JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1403  JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1404  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1405  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1406  JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1407  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1408  #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1409 #elif defined(JSON_HEDLEY_ASSUME)
1410  #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1411 #endif
1412 #if !defined(JSON_HEDLEY_ASSUME)
1413  #if defined(JSON_HEDLEY_UNREACHABLE)
1414  #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1415  #else
1416  #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1417  #endif
1418 #endif
1419 #if defined(JSON_HEDLEY_UNREACHABLE)
1420  #if \
1421  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1422  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1423  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1424  #else
1425  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1426  #endif
1427 #else
1428  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1429 #endif
1430 #if !defined(JSON_HEDLEY_UNREACHABLE)
1431  #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1432 #endif
1433 
1434 JSON_HEDLEY_DIAGNOSTIC_PUSH
1435 #if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1436  #pragma clang diagnostic ignored "-Wpedantic"
1437 #endif
1438 #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1439  #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1440 #endif
1441 #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1442  #if defined(__clang__)
1443  #pragma clang diagnostic ignored "-Wvariadic-macros"
1444  #elif defined(JSON_HEDLEY_GCC_VERSION)
1445  #pragma GCC diagnostic ignored "-Wvariadic-macros"
1446  #endif
1447 #endif
1448 #if defined(JSON_HEDLEY_NON_NULL)
1449  #undef JSON_HEDLEY_NON_NULL
1450 #endif
1451 #if \
1452  JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1453  JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1454  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1455  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1456  #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1457 #else
1458  #define JSON_HEDLEY_NON_NULL(...)
1459 #endif
1460 JSON_HEDLEY_DIAGNOSTIC_POP
1461 
1462 #if defined(JSON_HEDLEY_PRINTF_FORMAT)
1463  #undef JSON_HEDLEY_PRINTF_FORMAT
1464 #endif
1465 #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1466  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1467 #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1468  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1469 #elif \
1470  JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1471  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1472  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1473  JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1474  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1475  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1476  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1477  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1478  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1479  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1480  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1481  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1482  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1483  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1484  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1485  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1486  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1487  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1488 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1489  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1490 #else
1491  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1492 #endif
1493 
1494 #if defined(JSON_HEDLEY_CONSTEXPR)
1495  #undef JSON_HEDLEY_CONSTEXPR
1496 #endif
1497 #if defined(__cplusplus)
1498  #if __cplusplus >= 201103L
1499  #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1500  #endif
1501 #endif
1502 #if !defined(JSON_HEDLEY_CONSTEXPR)
1503  #define JSON_HEDLEY_CONSTEXPR
1504 #endif
1505 
1506 #if defined(JSON_HEDLEY_PREDICT)
1507  #undef JSON_HEDLEY_PREDICT
1508 #endif
1509 #if defined(JSON_HEDLEY_LIKELY)
1510  #undef JSON_HEDLEY_LIKELY
1511 #endif
1512 #if defined(JSON_HEDLEY_UNLIKELY)
1513  #undef JSON_HEDLEY_UNLIKELY
1514 #endif
1515 #if defined(JSON_HEDLEY_UNPREDICTABLE)
1516  #undef JSON_HEDLEY_UNPREDICTABLE
1517 #endif
1518 #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1519  #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1520 #endif
1521 #if \
1522  (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1523  JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1524  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1525 # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1526 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1527 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1528 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1529 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1530 #elif \
1531  (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1532  JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1533  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1534  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1535  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1536  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1537  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1538  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1539  JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1540  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1541  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1542  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1543  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1544  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1545  JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1546  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1547 # define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1548  (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1549 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1550  (__extension__ ({ \
1551  double hedley_probability_ = (probability); \
1552  ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1553  }))
1554 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1555  (__extension__ ({ \
1556  double hedley_probability_ = (probability); \
1557  ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1558  }))
1559 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1560 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1561 #else
1562 # define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1563 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1564 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1565 # define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1566 # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1567 #endif
1568 #if !defined(JSON_HEDLEY_UNPREDICTABLE)
1569  #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1570 #endif
1571 
1572 #if defined(JSON_HEDLEY_MALLOC)
1573  #undef JSON_HEDLEY_MALLOC
1574 #endif
1575 #if \
1576  JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1577  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1578  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1579  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1580  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1581  JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1582  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1583  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1584  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1585  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1586  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1587  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1588  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1589  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1590  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1591  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1592  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1593  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1594  #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1595 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1596  #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1597 #elif \
1598  JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1599  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1600  #define JSON_HEDLEY_MALLOC __declspec(restrict)
1601 #else
1602  #define JSON_HEDLEY_MALLOC
1603 #endif
1604 
1605 #if defined(JSON_HEDLEY_PURE)
1606  #undef JSON_HEDLEY_PURE
1607 #endif
1608 #if \
1609  JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1610  JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1611  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1612  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1613  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1614  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1615  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1616  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1617  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1618  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1619  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1620  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1621  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1622  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1623  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1624  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1625  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1626  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1627  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1628 # define JSON_HEDLEY_PURE __attribute__((__pure__))
1629 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1630 # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1631 #elif defined(__cplusplus) && \
1632  ( \
1633  JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1634  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1635  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1636  )
1637 # define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1638 #else
1639 # define JSON_HEDLEY_PURE
1640 #endif
1641 
1642 #if defined(JSON_HEDLEY_CONST)
1643  #undef JSON_HEDLEY_CONST
1644 #endif
1645 #if \
1646  JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1647  JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1648  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1649  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1650  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1651  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1652  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1653  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1654  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1655  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1656  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1657  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1658  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1659  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1660  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1661  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1662  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1663  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1664  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1665  #define JSON_HEDLEY_CONST __attribute__((__const__))
1666 #elif \
1667  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1668  #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1669 #else
1670  #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1671 #endif
1672 
1673 #if defined(JSON_HEDLEY_RESTRICT)
1674  #undef JSON_HEDLEY_RESTRICT
1675 #endif
1676 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1677  #define JSON_HEDLEY_RESTRICT restrict
1678 #elif \
1679  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1680  JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1681  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1682  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1683  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1684  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1685  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1686  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1687  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1688  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1689  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1690  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1691  JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1692  defined(__clang__) || \
1693  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1694  #define JSON_HEDLEY_RESTRICT __restrict
1695 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1696  #define JSON_HEDLEY_RESTRICT _Restrict
1697 #else
1698  #define JSON_HEDLEY_RESTRICT
1699 #endif
1700 
1701 #if defined(JSON_HEDLEY_INLINE)
1702  #undef JSON_HEDLEY_INLINE
1703 #endif
1704 #if \
1705  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1706  (defined(__cplusplus) && (__cplusplus >= 199711L))
1707  #define JSON_HEDLEY_INLINE inline
1708 #elif \
1709  defined(JSON_HEDLEY_GCC_VERSION) || \
1710  JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1711  #define JSON_HEDLEY_INLINE __inline__
1712 #elif \
1713  JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1714  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1715  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1716  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1717  JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1718  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1719  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1720  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1721  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1722  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1723  #define JSON_HEDLEY_INLINE __inline
1724 #else
1725  #define JSON_HEDLEY_INLINE
1726 #endif
1727 
1728 #if defined(JSON_HEDLEY_ALWAYS_INLINE)
1729  #undef JSON_HEDLEY_ALWAYS_INLINE
1730 #endif
1731 #if \
1732  JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1733  JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1734  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1735  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1736  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1737  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1738  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1739  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1740  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1741  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1742  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1743  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1744  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1745  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1746  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1747  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1748  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1749  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1750  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1751 # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1752 #elif \
1753  JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1754  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1755 # define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1756 #elif defined(__cplusplus) && \
1757  ( \
1758  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1759  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1760  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1761  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1762  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1763  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1764  )
1765 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1766 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1767 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1768 #else
1769 # define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1770 #endif
1771 
1772 #if defined(JSON_HEDLEY_NEVER_INLINE)
1773  #undef JSON_HEDLEY_NEVER_INLINE
1774 #endif
1775 #if \
1776  JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1777  JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1778  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1779  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1780  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1781  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1782  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1783  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1784  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1785  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1786  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1787  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1788  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1789  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1790  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1791  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1792  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1793  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1794  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1795  #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1796 #elif \
1797  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1798  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1799  #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1800 #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1801  #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1802 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1803  #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1804 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1805  #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1806 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1807  #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1808 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1809  #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1810 #else
1811  #define JSON_HEDLEY_NEVER_INLINE
1812 #endif
1813 
1814 #if defined(JSON_HEDLEY_PRIVATE)
1815  #undef JSON_HEDLEY_PRIVATE
1816 #endif
1817 #if defined(JSON_HEDLEY_PUBLIC)
1818  #undef JSON_HEDLEY_PUBLIC
1819 #endif
1820 #if defined(JSON_HEDLEY_IMPORT)
1821  #undef JSON_HEDLEY_IMPORT
1822 #endif
1823 #if defined(_WIN32) || defined(__CYGWIN__)
1824 # define JSON_HEDLEY_PRIVATE
1825 # define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1826 # define JSON_HEDLEY_IMPORT __declspec(dllimport)
1827 #else
1828 # if \
1829  JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1830  JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1831  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1832  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1833  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1834  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1835  ( \
1836  defined(__TI_EABI__) && \
1837  ( \
1838  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1839  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1840  ) \
1841  ) || \
1842  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1843 # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1844 # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1845 # else
1846 # define JSON_HEDLEY_PRIVATE
1847 # define JSON_HEDLEY_PUBLIC
1848 # endif
1849 # define JSON_HEDLEY_IMPORT extern
1850 #endif
1851 
1852 #if defined(JSON_HEDLEY_NO_THROW)
1853  #undef JSON_HEDLEY_NO_THROW
1854 #endif
1855 #if \
1856  JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1857  JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1858  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1859  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1860  #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1861 #elif \
1862  JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1863  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1864  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1865  #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1866 #else
1867  #define JSON_HEDLEY_NO_THROW
1868 #endif
1869 
1870 #if defined(JSON_HEDLEY_FALL_THROUGH)
1871  #undef JSON_HEDLEY_FALL_THROUGH
1872 #endif
1873 #if \
1874  JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
1875  JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
1876  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1877  #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1878 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1879  #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1880 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1881  #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1882 #elif defined(__fallthrough) /* SAL */
1883  #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1884 #else
1885  #define JSON_HEDLEY_FALL_THROUGH
1886 #endif
1887 
1888 #if defined()
1889  #undef
1890 #endif
1891 #if \
1892  JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1893  JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1894  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1895  #define __attribute__((__returns_nonnull__))
1896 #elif defined(_Ret_notnull_) /* SAL */
1897  #define _Ret_notnull_
1898 #else
1899  #define
1900 #endif
1901 
1902 #if defined(JSON_HEDLEY_ARRAY_PARAM)
1903  #undef JSON_HEDLEY_ARRAY_PARAM
1904 #endif
1905 #if \
1906  defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1907  !defined(__STDC_NO_VLA__) && \
1908  !defined(__cplusplus) && \
1909  !defined(JSON_HEDLEY_PGI_VERSION) && \
1910  !defined(JSON_HEDLEY_TINYC_VERSION)
1911  #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1912 #else
1913  #define JSON_HEDLEY_ARRAY_PARAM(name)
1914 #endif
1915 
1916 #if defined(JSON_HEDLEY_IS_CONSTANT)
1917  #undef JSON_HEDLEY_IS_CONSTANT
1918 #endif
1919 #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1920  #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1921 #endif
1922 /* JSON_HEDLEY_IS_CONSTEXPR_ is for
1923  HEDLEY INTERNAL USE ONLY. API subject to change without notice. */
1924 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1925  #undef JSON_HEDLEY_IS_CONSTEXPR_
1926 #endif
1927 #if \
1928  JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1929  JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1930  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1931  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1932  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1933  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1934  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1935  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1936  JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1937  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1938  #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1939 #endif
1940 #if !defined(__cplusplus)
1941 # if \
1942  JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1943  JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1944  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1945  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1946  JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1947  JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1948  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1949 #if defined(__INTPTR_TYPE__)
1950  #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1951 #else
1952  #include <stdint.h>
1953  #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1954 #endif
1955 # elif \
1956  ( \
1957  defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
1958  !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
1959  !defined(JSON_HEDLEY_PGI_VERSION) && \
1960  !defined(JSON_HEDLEY_IAR_VERSION)) || \
1961  (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1962  JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1963  JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1964  JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1965  JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1966 #if defined(__INTPTR_TYPE__)
1967  #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1968 #else
1969  #include <stdint.h>
1970  #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1971 #endif
1972 # elif \
1973  defined(JSON_HEDLEY_GCC_VERSION) || \
1974  defined(JSON_HEDLEY_INTEL_VERSION) || \
1975  defined(JSON_HEDLEY_TINYC_VERSION) || \
1976  defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
1977  JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
1978  defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
1979  defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
1980  defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
1981  defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
1982  defined(__clang__)
1983 # define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1984  sizeof(void) != \
1985  sizeof(*( \
1986  1 ? \
1987  ((void*) ((expr) * 0L) ) : \
1988 ((struct { char v[sizeof(void) * 2]; } *) 1) \
1989  ) \
1990  ) \
1991  )
1992 # endif
1993 #endif
1994 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1995  #if !defined(JSON_HEDLEY_IS_CONSTANT)
1996  #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1997  #endif
1998  #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
1999 #else
2000  #if !defined(JSON_HEDLEY_IS_CONSTANT)
2001  #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2002  #endif
2003  #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2004 #endif
2005 
2006 #if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2007  #undef JSON_HEDLEY_BEGIN_C_DECLS
2008 #endif
2009 #if defined(JSON_HEDLEY_END_C_DECLS)
2010  #undef JSON_HEDLEY_END_C_DECLS
2011 #endif
2012 #if defined(JSON_HEDLEY_C_DECL)
2013  #undef JSON_HEDLEY_C_DECL
2014 #endif
2015 #if defined(__cplusplus)
2016  #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2017  #define JSON_HEDLEY_END_C_DECLS }
2018  #define JSON_HEDLEY_C_DECL extern "C"
2019 #else
2020  #define JSON_HEDLEY_BEGIN_C_DECLS
2021  #define JSON_HEDLEY_END_C_DECLS
2022  #define JSON_HEDLEY_C_DECL
2023 #endif
2024 
2025 #if defined(JSON_HEDLEY_STATIC_ASSERT)
2026  #undef JSON_HEDLEY_STATIC_ASSERT
2027 #endif
2028 #if \
2029  !defined(__cplusplus) && ( \
2030  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2031  (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2032  JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2033  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2034  defined(_Static_assert) \
2035  )
2036 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2037 #elif \
2038  (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2039  JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2040  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2041 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2042 #else
2043 # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2044 #endif
2045 
2046 #if defined(JSON_HEDLEY_NULL)
2047  #undef JSON_HEDLEY_NULL
2048 #endif
2049 #if defined(__cplusplus)
2050  #if __cplusplus >= 201103L
2051  #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2052  #elif defined(NULL)
2053  #define JSON_HEDLEY_NULL NULL
2054  #else
2055  #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2056  #endif
2057 #elif defined(NULL)
2058  #define JSON_HEDLEY_NULL NULL
2059 #else
2060  #define JSON_HEDLEY_NULL ((void*) 0)
2061 #endif
2062 
2063 #if defined(JSON_HEDLEY_MESSAGE)
2064  #undef JSON_HEDLEY_MESSAGE
2065 #endif
2066 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2067 # define JSON_HEDLEY_MESSAGE(msg) \
2068  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2069  JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2070  JSON_HEDLEY_PRAGMA(message msg) \
2071  JSON_HEDLEY_DIAGNOSTIC_POP
2072 #elif \
2073  JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2074  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2075 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2076 #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2077 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2078 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2079 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2080 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2081 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2082 #else
2083 # define JSON_HEDLEY_MESSAGE(msg)
2084 #endif
2085 
2086 #if defined(JSON_HEDLEY_WARNING)
2087  #undef JSON_HEDLEY_WARNING
2088 #endif
2089 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2090 # define JSON_HEDLEY_WARNING(msg) \
2091  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2092  JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2093  JSON_HEDLEY_PRAGMA(clang warning msg) \
2094  JSON_HEDLEY_DIAGNOSTIC_POP
2095 #elif \
2096  JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2097  JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2098  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2099 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2100 #elif \
2101  JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2102  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2103 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2104 #else
2105 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2106 #endif
2107 
2108 #if defined(JSON_HEDLEY_REQUIRE)
2109  #undef JSON_HEDLEY_REQUIRE
2110 #endif
2111 #if defined(JSON_HEDLEY_REQUIRE_MSG)
2112  #undef JSON_HEDLEY_REQUIRE_MSG
2113 #endif
2114 #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2115 # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2116 # define JSON_HEDLEY_REQUIRE(expr) \
2117  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2118  _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2119  __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2120  JSON_HEDLEY_DIAGNOSTIC_POP
2121 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2122  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2123  _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2124  __attribute__((diagnose_if(!(expr), msg, "error"))) \
2125  JSON_HEDLEY_DIAGNOSTIC_POP
2126 # else
2127 # define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2128 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2129 # endif
2130 #else
2131 # define JSON_HEDLEY_REQUIRE(expr)
2132 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2133 #endif
2134 
2135 #if defined(JSON_HEDLEY_FLAGS)
2136  #undef JSON_HEDLEY_FLAGS
2137 #endif
2138 #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2139  #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2140 #else
2141  #define JSON_HEDLEY_FLAGS
2142 #endif
2143 
2144 #if defined(JSON_HEDLEY_FLAGS_CAST)
2145  #undef JSON_HEDLEY_FLAGS_CAST
2146 #endif
2147 #if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2148 # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2149  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2150  _Pragma("warning(disable:188)") \
2151  ((T) (expr)); \
2152  JSON_HEDLEY_DIAGNOSTIC_POP \
2153  }))
2154 #else
2155 # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2156 #endif
2157 
2158 #if defined(JSON_HEDLEY_EMPTY_BASES)
2159  #undef JSON_HEDLEY_EMPTY_BASES
2160 #endif
2161 #if \
2162  (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2163  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2164  #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2165 #else
2166  #define JSON_HEDLEY_EMPTY_BASES
2167 #endif
2168 
2169 /* Remaining macros are deprecated. */
2170 
2171 #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2172  #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2173 #endif
2174 #if defined(__clang__)
2175  #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2176 #else
2177  #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2178 #endif
2179 
2180 #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2181  #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2182 #endif
2183 #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2184 
2185 #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2186  #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2187 #endif
2188 #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2189 
2190 #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2191  #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2192 #endif
2193 #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2194 
2195 #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2196  #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2197 #endif
2198 #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2199 
2200 #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2201  #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2202 #endif
2203 #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2204 
2205 #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2206  #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2207 #endif
2208 #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2209 
2210 #if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2211  #undef JSON_HEDLEY_CLANG_HAS_WARNING
2212 #endif
2213 #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2214 
2215 #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */
2216 
2217 
2218 // This file contains all internal macro definitions
2219 // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
2220 
2221 // exclude unsupported compilers
2222 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2223  #if defined(__clang__)
2224  #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2225  #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2226  #endif
2227  #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2228  #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2229  #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2230  #endif
2231  #endif
2232 #endif
2233 
2234 // C++ language standard detection
2235 // if the user manually specified the used c++ version this is skipped
2236 #if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
2237  #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2238  #define JSON_HAS_CPP_20
2239  #define JSON_HAS_CPP_17
2240  #define JSON_HAS_CPP_14
2241  #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
2242  #define JSON_HAS_CPP_17
2243  #define JSON_HAS_CPP_14
2244  #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2245  #define JSON_HAS_CPP_14
2246  #endif
2247  // the cpp 11 flag is always specified because it is the minimal required version
2248  #define JSON_HAS_CPP_11
2249 #endif
2250 
2251 // disable documentation warnings on clang
2252 #if defined(__clang__)
2253  #pragma GCC diagnostic push
2254  #pragma GCC diagnostic ignored "-Wdocumentation"
2255 #endif
2256 
2257 // allow to disable exceptions
2258 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2259  #define JSON_THROW(exception) throw exception
2260  #define JSON_TRY try
2261  #define JSON_CATCH(exception) catch(exception)
2262  #define JSON_INTERNAL_CATCH(exception) catch(exception)
2263 #else
2264  #include <cstdlib>
2265  #define JSON_THROW(exception) std::abort()
2266  #define JSON_TRY if(true)
2267  #define JSON_CATCH(exception) if(false)
2268  #define JSON_INTERNAL_CATCH(exception) if(false)
2269 #endif
2270 
2271 // override exception macros
2272 #if defined(JSON_THROW_USER)
2273  #undef JSON_THROW
2274  #define JSON_THROW JSON_THROW_USER
2275 #endif
2276 #if defined(JSON_TRY_USER)
2277  #undef JSON_TRY
2278  #define JSON_TRY JSON_TRY_USER
2279 #endif
2280 #if defined(JSON_CATCH_USER)
2281  #undef JSON_CATCH
2282  #define JSON_CATCH JSON_CATCH_USER
2283  #undef JSON_INTERNAL_CATCH
2284  #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2285 #endif
2286 #if defined(JSON_INTERNAL_CATCH_USER)
2287  #undef JSON_INTERNAL_CATCH
2288  #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2289 #endif
2290 
2291 // allow to override assert
2292 #if !defined(JSON_ASSERT)
2293  #include <cassert> // assert
2294  #define JSON_ASSERT(x) assert(x)
2295 #endif
2296 
2297 // allow to access some private functions (needed by the test suite)
2298 #if defined(JSON_TESTS_PRIVATE)
2299  #define JSON_PRIVATE_UNLESS_TESTED public
2300 #else
2301  #define JSON_PRIVATE_UNLESS_TESTED private
2302 #endif
2303 
2309 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2310  template<typename BasicJsonType> \
2311  inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2312  { \
2313  static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2314  static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2315  auto it = std::find_if(std::begin(m), std::end(m), \
2316  [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2317  { \
2318  return ej_pair.first == e; \
2319  }); \
2320  j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2321  } \
2322  template<typename BasicJsonType> \
2323  inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2324  { \
2325  static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2326  static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2327  auto it = std::find_if(std::begin(m), std::end(m), \
2328  [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2329  { \
2330  return ej_pair.second == j; \
2331  }); \
2332  e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2333  }
2334 
2335 // Ugly macros to avoid uglier copy-paste when specializing basic_json. They
2336 // may be removed in the future once the class is split.
2337 
2338 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2339  template<template<typename, typename, typename...> class ObjectType, \
2340  template<typename, typename...> class ArrayType, \
2341  class StringType, class BooleanType, class NumberIntegerType, \
2342  class NumberUnsignedType, class NumberFloatType, \
2343  template<typename> class AllocatorType, \
2344  template<typename, typename = void> class JSONSerializer, \
2345  class BinaryType>
2346 
2347 #define NLOHMANN_BASIC_JSON_TPL \
2348  basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2349  NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2350  AllocatorType, JSONSerializer, BinaryType>
2351 
2352 // Macros to simplify conversion from/to types
2353 
2354 #define NLOHMANN_JSON_EXPAND( x ) x
2355 #define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME
2356 #define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2357  NLOHMANN_JSON_PASTE64, \
2358  NLOHMANN_JSON_PASTE63, \
2359  NLOHMANN_JSON_PASTE62, \
2360  NLOHMANN_JSON_PASTE61, \
2361  NLOHMANN_JSON_PASTE60, \
2362  NLOHMANN_JSON_PASTE59, \
2363  NLOHMANN_JSON_PASTE58, \
2364  NLOHMANN_JSON_PASTE57, \
2365  NLOHMANN_JSON_PASTE56, \
2366  NLOHMANN_JSON_PASTE55, \
2367  NLOHMANN_JSON_PASTE54, \
2368  NLOHMANN_JSON_PASTE53, \
2369  NLOHMANN_JSON_PASTE52, \
2370  NLOHMANN_JSON_PASTE51, \
2371  NLOHMANN_JSON_PASTE50, \
2372  NLOHMANN_JSON_PASTE49, \
2373  NLOHMANN_JSON_PASTE48, \
2374  NLOHMANN_JSON_PASTE47, \
2375  NLOHMANN_JSON_PASTE46, \
2376  NLOHMANN_JSON_PASTE45, \
2377  NLOHMANN_JSON_PASTE44, \
2378  NLOHMANN_JSON_PASTE43, \
2379  NLOHMANN_JSON_PASTE42, \
2380  NLOHMANN_JSON_PASTE41, \
2381  NLOHMANN_JSON_PASTE40, \
2382  NLOHMANN_JSON_PASTE39, \
2383  NLOHMANN_JSON_PASTE38, \
2384  NLOHMANN_JSON_PASTE37, \
2385  NLOHMANN_JSON_PASTE36, \
2386  NLOHMANN_JSON_PASTE35, \
2387  NLOHMANN_JSON_PASTE34, \
2388  NLOHMANN_JSON_PASTE33, \
2389  NLOHMANN_JSON_PASTE32, \
2390  NLOHMANN_JSON_PASTE31, \
2391  NLOHMANN_JSON_PASTE30, \
2392  NLOHMANN_JSON_PASTE29, \
2393  NLOHMANN_JSON_PASTE28, \
2394  NLOHMANN_JSON_PASTE27, \
2395  NLOHMANN_JSON_PASTE26, \
2396  NLOHMANN_JSON_PASTE25, \
2397  NLOHMANN_JSON_PASTE24, \
2398  NLOHMANN_JSON_PASTE23, \
2399  NLOHMANN_JSON_PASTE22, \
2400  NLOHMANN_JSON_PASTE21, \
2401  NLOHMANN_JSON_PASTE20, \
2402  NLOHMANN_JSON_PASTE19, \
2403  NLOHMANN_JSON_PASTE18, \
2404  NLOHMANN_JSON_PASTE17, \
2405  NLOHMANN_JSON_PASTE16, \
2406  NLOHMANN_JSON_PASTE15, \
2407  NLOHMANN_JSON_PASTE14, \
2408  NLOHMANN_JSON_PASTE13, \
2409  NLOHMANN_JSON_PASTE12, \
2410  NLOHMANN_JSON_PASTE11, \
2411  NLOHMANN_JSON_PASTE10, \
2412  NLOHMANN_JSON_PASTE9, \
2413  NLOHMANN_JSON_PASTE8, \
2414  NLOHMANN_JSON_PASTE7, \
2415  NLOHMANN_JSON_PASTE6, \
2416  NLOHMANN_JSON_PASTE5, \
2417  NLOHMANN_JSON_PASTE4, \
2418  NLOHMANN_JSON_PASTE3, \
2419  NLOHMANN_JSON_PASTE2, \
2420  NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2421 #define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2422 #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2423 #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2424 #define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2425 #define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2426 #define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6)
2427 #define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
2428 #define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8)
2429 #define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9)
2430 #define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)
2431 #define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)
2432 #define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
2433 #define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
2434 #define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
2435 #define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)
2436 #define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)
2437 #define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
2438 #define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
2439 #define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
2440 #define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)
2441 #define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)
2442 #define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)
2443 #define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23)
2444 #define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24)
2445 #define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25)
2446 #define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26)
2447 #define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27)
2448 #define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28)
2449 #define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29)
2450 #define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30)
2451 #define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31)
2452 #define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32)
2453 #define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33)
2454 #define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34)
2455 #define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35)
2456 #define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36)
2457 #define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37)
2458 #define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38)
2459 #define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39)
2460 #define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40)
2461 #define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)
2462 #define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42)
2463 #define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43)
2464 #define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44)
2465 #define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45)
2466 #define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46)
2467 #define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47)
2468 #define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48)
2469 #define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49)
2470 #define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50)
2471 #define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51)
2472 #define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52)
2473 #define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53)
2474 #define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54)
2475 #define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55)
2476 #define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56)
2477 #define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57)
2478 #define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58)
2479 #define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59)
2480 #define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60)
2481 #define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61)
2482 #define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62)
2483 #define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)
2484 
2485 #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2486 #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2487 
2493 #define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2494  friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2495  friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2496 
2502 #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2503  inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2504  inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2505 
2506 #ifndef JSON_USE_IMPLICIT_CONVERSIONS
2507  #define JSON_USE_IMPLICIT_CONVERSIONS 1
2508 #endif
2509 
2510 #if JSON_USE_IMPLICIT_CONVERSIONS
2511  #define JSON_EXPLICIT
2512 #else
2513  #define JSON_EXPLICIT explicit
2514 #endif
2515 
2516 
2517 namespace nlohmann
2518 {
2519 namespace detail
2520 {
2521 
2535 inline void replace_substring(std::string& s, const std::string& f,
2536  const std::string& t)
2537 {
2538  JSON_ASSERT(!f.empty());
2539  for (auto pos = s.find(f); // find first occurrence of f
2540  pos != std::string::npos; // make sure f was found
2541  s.replace(pos, f.size(), t), // replace with t, and
2542  pos = s.find(f, pos + t.size())) // find next occurrence of f
2543  {}
2544 }
2545 
2553 inline std::string escape(std::string s)
2554 {
2555  replace_substring(s, "~", "~0");
2556  replace_substring(s, "/", "~1");
2557  return s;
2558 }
2559 
2567 static void unescape(std::string& s)
2568 {
2569  replace_substring(s, "~1", "/");
2570  replace_substring(s, "~0", "~");
2571 }
2572 
2573 } // namespace detail
2574 } // namespace nlohmann
2575 
2576 // #include <nlohmann/detail/input/position_t.hpp>
2577 
2578 
2579 #include <cstddef> // size_t
2580 
2581 namespace nlohmann
2582 {
2583 namespace detail
2584 {
2586 struct position_t
2587 {
2589  std::size_t chars_read_total = 0;
2591  std::size_t chars_read_current_line = 0;
2593  std::size_t lines_read = 0;
2594 
2596  constexpr operator size_t() const
2597  {
2598  return chars_read_total;
2599  }
2600 };
2601 
2602 } // namespace detail
2603 } // namespace nlohmann
2604 
2605 // #include <nlohmann/detail/macro_scope.hpp>
2606 
2607 
2608 namespace nlohmann
2609 {
2610 namespace detail
2611 {
2613 // exceptions //
2615 
2644 class exception : public std::exception
2645 {
2646  public:
2648  const char* what() const noexcept override
2649  {
2650  return m.what();
2651  }
2652 
2654  const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
2655 
2656  protected:
2657  JSON_HEDLEY_NON_NULL(3)
2658  exception(int id_, const char* what_arg) : id(id_), m(what_arg) {}
2659 
2660  static std::string name(const std::string& ename, int id_)
2661  {
2662  return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
2663  }
2664 
2665  template<typename BasicJsonType>
2666  static std::string diagnostics(const BasicJsonType& leaf_element)
2667  {
2668 #if JSON_DIAGNOSTICS
2669  std::vector<std::string> tokens;
2670  for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent)
2671  {
2672  switch (current->m_parent->type())
2673  {
2674  case value_t::array:
2675  {
2676  for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
2677  {
2678  if (&current->m_parent->m_value.array->operator[](i) == current)
2679  {
2680  tokens.emplace_back(std::to_string(i));
2681  break;
2682  }
2683  }
2684  break;
2685  }
2686 
2687  case value_t::object:
2688  {
2689  for (const auto& element : *current->m_parent->m_value.object)
2690  {
2691  if (&element.second == current)
2692  {
2693  tokens.emplace_back(element.first.c_str());
2694  break;
2695  }
2696  }
2697  break;
2698  }
2699 
2700  default: // LCOV_EXCL_LINE
2701  break; // LCOV_EXCL_LINE
2702  }
2703  }
2704 
2705  if (tokens.empty())
2706  {
2707  return "";
2708  }
2709 
2710  return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
2711  [](const std::string & a, const std::string & b)
2712  {
2713  return a + "/" + detail::escape(b);
2714  }) + ") ";
2715 #else
2716  static_cast<void>(leaf_element);
2717  return "";
2718 #endif
2719  }
2720 
2721  private:
2723  std::runtime_error m;
2724 };
2725 
2771 class parse_error : public exception
2772 {
2773  public:
2783  template<typename BasicJsonType>
2784  static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context)
2785  {
2786  std::string w = exception::name("parse_error", id_) + "parse error" +
2787  position_string(pos) + ": " + exception::diagnostics(context) + what_arg;
2788  return parse_error(id_, pos.chars_read_total, w.c_str());
2789  }
2790 
2791  template<typename BasicJsonType>
2792  static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context)
2793  {
2794  std::string w = exception::name("parse_error", id_) + "parse error" +
2795  (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
2796  ": " + exception::diagnostics(context) + what_arg;
2797  return parse_error(id_, byte_, w.c_str());
2798  }
2799 
2809  const std::size_t byte;
2810 
2811  private:
2812  parse_error(int id_, std::size_t byte_, const char* what_arg)
2813  : exception(id_, what_arg), byte(byte_) {}
2814 
2815  static std::string position_string(const position_t& pos)
2816  {
2817  return " at line " + std::to_string(pos.lines_read + 1) +
2818  ", column " + std::to_string(pos.chars_read_current_line);
2819  }
2820 };
2821 
2859 class invalid_iterator : public exception
2860 {
2861  public:
2862  template<typename BasicJsonType>
2863  static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context)
2864  {
2865  std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
2866  return invalid_iterator(id_, w.c_str());
2867  }
2868 
2869  private:
2870  JSON_HEDLEY_NON_NULL(3)
2871  invalid_iterator(int id_, const char* what_arg)
2872  : exception(id_, what_arg) {}
2873 };
2874 
2914 class type_error : public exception
2915 {
2916  public:
2917  template<typename BasicJsonType>
2918  static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
2919  {
2920  std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg;
2921  return type_error(id_, w.c_str());
2922  }
2923 
2924  private:
2925  JSON_HEDLEY_NON_NULL(3)
2926  type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
2927 };
2928 
2962 class out_of_range : public exception
2963 {
2964  public:
2965  template<typename BasicJsonType>
2966  static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context)
2967  {
2968  std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg;
2969  return out_of_range(id_, w.c_str());
2970  }
2971 
2972  private:
2973  JSON_HEDLEY_NON_NULL(3)
2974  out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}
2975 };
2976 
3001 class other_error : public exception
3002 {
3003  public:
3004  template<typename BasicJsonType>
3005  static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
3006  {
3007  std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg;
3008  return other_error(id_, w.c_str());
3009  }
3010 
3011  private:
3012  JSON_HEDLEY_NON_NULL(3)
3013  other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
3014 };
3015 } // namespace detail
3016 } // namespace nlohmann
3017 
3018 // #include <nlohmann/detail/macro_scope.hpp>
3019 
3020 // #include <nlohmann/detail/meta/cpp_future.hpp>
3021 
3022 
3023 #include <cstddef> // size_t
3024 #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
3025 #include <utility> // index_sequence, make_index_sequence, index_sequence_for
3026 
3027 // #include <nlohmann/detail/macro_scope.hpp>
3028 
3029 
3030 namespace nlohmann
3031 {
3032 namespace detail
3033 {
3034 
3035 template<typename T>
3036 using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3037 
3038 #ifdef JSON_HAS_CPP_14
3039 
3040 // the following utilities are natively available in C++14
3041 using std::enable_if_t;
3042 using std::index_sequence;
3043 using std::make_index_sequence;
3044 using std::index_sequence_for;
3045 
3046 #else
3047 
3048 // alias templates to reduce boilerplate
3049 template<bool B, typename T = void>
3050 using enable_if_t = typename std::enable_if<B, T>::type;
3051 
3052 // The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h
3053 // which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0.
3054 
3056 
3057 // integer_sequence
3058 //
3059 // Class template representing a compile-time integer sequence. An instantiation
3060 // of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its
3061 // type through its template arguments (which is a common need when
3062 // working with C++11 variadic templates). `absl::integer_sequence` is designed
3063 // to be a drop-in replacement for C++14's `std::integer_sequence`.
3064 //
3065 // Example:
3066 //
3067 // template< class T, T... Ints >
3068 // void user_function(integer_sequence<T, Ints...>);
3069 //
3070 // int main()
3071 // {
3072 // // user_function's `T` will be deduced to `int` and `Ints...`
3073 // // will be deduced to `0, 1, 2, 3, 4`.
3074 // user_function(make_integer_sequence<int, 5>());
3075 // }
3076 template <typename T, T... Ints>
3077 struct integer_sequence
3078 {
3079  using value_type = T;
3080  static constexpr std::size_t size() noexcept
3081  {
3082  return sizeof...(Ints);
3083  }
3084 };
3085 
3086 // index_sequence
3087 //
3088 // A helper template for an `integer_sequence` of `size_t`,
3089 // `absl::index_sequence` is designed to be a drop-in replacement for C++14's
3090 // `std::index_sequence`.
3091 template <size_t... Ints>
3092 using index_sequence = integer_sequence<size_t, Ints...>;
3093 
3094 namespace utility_internal
3095 {
3096 
3097 template <typename Seq, size_t SeqSize, size_t Rem>
3098 struct Extend;
3099 
3100 // Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency.
3101 template <typename T, T... Ints, size_t SeqSize>
3102 struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
3103 {
3104  using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
3105 };
3106 
3107 template <typename T, T... Ints, size_t SeqSize>
3108 struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
3109 {
3110  using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
3111 };
3112 
3113 // Recursion helper for 'make_integer_sequence<T, N>'.
3114 // 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'.
3115 template <typename T, size_t N>
3116 struct Gen
3117 {
3118  using type =
3119  typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3120 };
3121 
3122 template <typename T>
3123 struct Gen<T, 0>
3124 {
3125  using type = integer_sequence<T>;
3126 };
3127 
3128 } // namespace utility_internal
3129 
3130 // Compile-time sequences of integers
3131 
3132 // make_integer_sequence
3133 //
3134 // This template alias is equivalent to
3135 // `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in
3136 // replacement for C++14's `std::make_integer_sequence`.
3137 template <typename T, T N>
3138 using make_integer_sequence = typename utility_internal::Gen<T, N>::type;
3139 
3140 // make_index_sequence
3141 //
3142 // This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,
3143 // and is designed to be a drop-in replacement for C++14's
3144 // `std::make_index_sequence`.
3145 template <size_t N>
3146 using make_index_sequence = make_integer_sequence<size_t, N>;
3147 
3148 // index_sequence_for
3149 //
3150 // Converts a typename pack into an index sequence of the same length, and
3151 // is designed to be a drop-in replacement for C++14's
3152 // `std::index_sequence_for()`
3153 template <typename... Ts>
3154 using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
3155 
3157 
3158 #endif
3159 
3160 // dispatch utility (taken from ranges-v3)
3161 template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
3162 template<> struct priority_tag<0> {};
3163 
3164 // taken from ranges-v3
3165 template<typename T>
3166 struct static_const
3167 {
3168  static constexpr T value{};
3169 };
3170 
3171 template<typename T>
3172 constexpr T static_const<T>::value;
3173 
3174 } // namespace detail
3175 } // namespace nlohmann
3176 
3177 // #include <nlohmann/detail/meta/identity_tag.hpp>
3178 
3179 
3180 namespace nlohmann
3181 {
3182 namespace detail
3183 {
3184 // dispatching helper struct
3185 template <class T> struct identity_tag {};
3186 } // namespace detail
3187 } // namespace nlohmann
3188 
3189 // #include <nlohmann/detail/meta/type_traits.hpp>
3190 
3191 
3192 #include <limits> // numeric_limits
3193 #include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
3194 #include <utility> // declval
3195 #include <tuple> // tuple
3196 
3197 // #include <nlohmann/detail/iterators/iterator_traits.hpp>
3198 
3199 
3200 #include <iterator> // random_access_iterator_tag
3201 
3202 // #include <nlohmann/detail/meta/void_t.hpp>
3203 
3204 
3205 namespace nlohmann
3206 {
3207 namespace detail
3208 {
3209 template<typename ...Ts> struct make_void
3210 {
3211  using type = void;
3212 };
3213 template<typename ...Ts> using void_t = typename make_void<Ts...>::type;
3214 } // namespace detail
3215 } // namespace nlohmann
3216 
3217 // #include <nlohmann/detail/meta/cpp_future.hpp>
3218 
3219 
3220 namespace nlohmann
3221 {
3222 namespace detail
3223 {
3224 template<typename It, typename = void>
3225 struct iterator_types {};
3226 
3227 template<typename It>
3228 struct iterator_types <
3229  It,
3230  void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3231  typename It::reference, typename It::iterator_category >>
3232 {
3233  using difference_type = typename It::difference_type;
3234  using value_type = typename It::value_type;
3235  using pointer = typename It::pointer;
3236  using reference = typename It::reference;
3237  using iterator_category = typename It::iterator_category;
3238 };
3239 
3240 // This is required as some compilers implement std::iterator_traits in a way that
3241 // doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341.
3242 template<typename T, typename = void>
3243 struct iterator_traits
3244 {
3245 };
3246 
3247 template<typename T>
3248 struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
3249  : iterator_types<T>
3250 {
3251 };
3252 
3253 template<typename T>
3254 struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
3255 {
3256  using iterator_category = std::random_access_iterator_tag;
3257  using value_type = T;
3258  using difference_type = ptrdiff_t;
3259  using pointer = T*;
3260  using reference = T&;
3261 };
3262 } // namespace detail
3263 } // namespace nlohmann
3264 
3265 // #include <nlohmann/detail/macro_scope.hpp>
3266 
3267 // #include <nlohmann/detail/meta/cpp_future.hpp>
3268 
3269 // #include <nlohmann/detail/meta/detected.hpp>
3270 
3271 
3272 #include <type_traits>
3273 
3274 // #include <nlohmann/detail/meta/void_t.hpp>
3275 
3276 
3277 // https://en.cppreference.com/w/cpp/experimental/is_detected
3278 namespace nlohmann
3279 {
3280 namespace detail
3281 {
3282 struct nonesuch
3283 {
3284  nonesuch() = delete;
3285  ~nonesuch() = delete;
3286  nonesuch(nonesuch const&) = delete;
3287  nonesuch(nonesuch const&&) = delete;
3288  void operator=(nonesuch const&) = delete;
3289  void operator=(nonesuch&&) = delete;
3290 };
3291 
3292 template<class Default,
3293  class AlwaysVoid,
3294  template<class...> class Op,
3295  class... Args>
3296 struct detector
3297 {
3298  using value_t = std::false_type;
3299  using type = Default;
3300 };
3301 
3302 template<class Default, template<class...> class Op, class... Args>
3303 struct detector<Default, void_t<Op<Args...>>, Op, Args...>
3304 {
3305  using value_t = std::true_type;
3306  using type = Op<Args...>;
3307 };
3308 
3309 template<template<class...> class Op, class... Args>
3310 using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
3311 
3312 template<template<class...> class Op, class... Args>
3313 using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
3314 
3315 template<class Default, template<class...> class Op, class... Args>
3316 using detected_or = detector<Default, void, Op, Args...>;
3317 
3318 template<class Default, template<class...> class Op, class... Args>
3319 using detected_or_t = typename detected_or<Default, Op, Args...>::type;
3320 
3321 template<class Expected, template<class...> class Op, class... Args>
3322 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
3323 
3324 template<class To, template<class...> class Op, class... Args>
3325 using is_detected_convertible =
3326  std::is_convertible<detected_t<Op, Args...>, To>;
3327 } // namespace detail
3328 } // namespace nlohmann
3329 
3330 // #include <nlohmann/json_fwd.hpp>
3331 #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3332 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3333 
3334 #include <cstdint> // int64_t, uint64_t
3335 #include <map> // map
3336 #include <memory> // allocator
3337 #include <string> // string
3338 #include <vector> // vector
3339 
3345 namespace nlohmann
3346 {
3354 template<typename T = void, typename SFINAE = void>
3355 struct adl_serializer;
3356 
3357 template<template<typename U, typename V, typename... Args> class ObjectType =
3358  std::map,
3359  template<typename U, typename... Args> class ArrayType = std::vector,
3360  class StringType = std::string, class BooleanType = bool,
3361  class NumberIntegerType = std::int64_t,
3362  class NumberUnsignedType = std::uint64_t,
3363  class NumberFloatType = double,
3364  template<typename U> class AllocatorType = std::allocator,
3365  template<typename T, typename SFINAE = void> class JSONSerializer =
3366  adl_serializer,
3367  class BinaryType = std::vector<std::uint8_t>>
3368 class basic_json;
3369 
3381 template<typename BasicJsonType>
3382 class json_pointer;
3383 
3393 
3394 template<class Key, class T, class IgnoredLess, class Allocator>
3395 struct ordered_map;
3396 
3405 
3406 } // namespace nlohmann
3407 
3408 #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
3409 
3410 
3411 namespace nlohmann
3412 {
3421 namespace detail
3422 {
3424 // helpers //
3426 
3427 // Note to maintainers:
3428 //
3429 // Every trait in this file expects a non CV-qualified type.
3430 // The only exceptions are in the 'aliases for detected' section
3431 // (i.e. those of the form: decltype(T::member_function(std::declval<T>())))
3432 //
3433 // In this case, T has to be properly CV-qualified to constraint the function arguments
3434 // (e.g. to_json(BasicJsonType&, const T&))
3435 
3436 template<typename> struct is_basic_json : std::false_type {};
3437 
3438 NLOHMANN_BASIC_JSON_TPL_DECLARATION
3439 struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
3440 
3442 // json_ref helpers //
3444 
3445 template<typename>
3446 class json_ref;
3447 
3448 template<typename>
3449 struct is_json_ref : std::false_type {};
3450 
3451 template<typename T>
3452 struct is_json_ref<json_ref<T>> : std::true_type {};
3453 
3455 // aliases for detected //
3457 
3458 template<typename T>
3459 using mapped_type_t = typename T::mapped_type;
3460 
3461 template<typename T>
3462 using key_type_t = typename T::key_type;
3463 
3464 template<typename T>
3465 using value_type_t = typename T::value_type;
3466 
3467 template<typename T>
3468 using difference_type_t = typename T::difference_type;
3469 
3470 template<typename T>
3471 using pointer_t = typename T::pointer;
3472 
3473 template<typename T>
3474 using reference_t = typename T::reference;
3475 
3476 template<typename T>
3477 using iterator_category_t = typename T::iterator_category;
3478 
3479 template<typename T>
3480 using iterator_t = typename T::iterator;
3481 
3482 template<typename T, typename... Args>
3483 using to_json_function = decltype(T::to_json(std::declval<Args>()...));
3484 
3485 template<typename T, typename... Args>
3486 using from_json_function = decltype(T::from_json(std::declval<Args>()...));
3487 
3488 template<typename T, typename U>
3489 using get_template_function = decltype(std::declval<T>().template get<U>());
3490 
3491 // trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
3492 template<typename BasicJsonType, typename T, typename = void>
3493 struct has_from_json : std::false_type {};
3494 
3495 // trait checking if j.get<T> is valid
3496 // use this trait instead of std::is_constructible or std::is_convertible,
3497 // both rely on, or make use of implicit conversions, and thus fail when T
3498 // has several constructors/operator= (see https://github.com/nlohmann/json/issues/958)
3499 template <typename BasicJsonType, typename T>
3500 struct is_getable
3501 {
3502  static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3503 };
3504 
3505 template<typename BasicJsonType, typename T>
3506 struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3507 {
3508  using serializer = typename BasicJsonType::template json_serializer<T, void>;
3509 
3510  static constexpr bool value =
3511  is_detected_exact<void, from_json_function, serializer,
3512  const BasicJsonType&, T&>::value;
3513 };
3514 
3515 // This trait checks if JSONSerializer<T>::from_json(json const&) exists
3516 // this overload is used for non-default-constructible user-defined-types
3517 template<typename BasicJsonType, typename T, typename = void>
3518 struct has_non_default_from_json : std::false_type {};
3519 
3520 template<typename BasicJsonType, typename T>
3521 struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3522 {
3523  using serializer = typename BasicJsonType::template json_serializer<T, void>;
3524 
3525  static constexpr bool value =
3526  is_detected_exact<T, from_json_function, serializer,
3527  const BasicJsonType&>::value;
3528 };
3529 
3530 // This trait checks if BasicJsonType::json_serializer<T>::to_json exists
3531 // Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion.
3532 template<typename BasicJsonType, typename T, typename = void>
3533 struct has_to_json : std::false_type {};
3534 
3535 template<typename BasicJsonType, typename T>
3536 struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3537 {
3538  using serializer = typename BasicJsonType::template json_serializer<T, void>;
3539 
3540  static constexpr bool value =
3541  is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3542  T>::value;
3543 };
3544 
3545 
3547 // is_ functions //
3549 
3550 // https://en.cppreference.com/w/cpp/types/conjunction
3551 template<class...> struct conjunction : std::true_type { };
3552 template<class B1> struct conjunction<B1> : B1 { };
3553 template<class B1, class... Bn>
3554 struct conjunction<B1, Bn...>
3555 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3556 
3557 // Reimplementation of is_constructible and is_default_constructible, due to them being broken for
3558 // std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).
3559 // This causes compile errors in e.g. clang 3.5 or gcc 4.9.
3560 template <typename T>
3561 struct is_default_constructible : std::is_default_constructible<T> {};
3562 
3563 template <typename T1, typename T2>
3564 struct is_default_constructible<std::pair<T1, T2>>
3565  : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3566 
3567 template <typename T1, typename T2>
3568 struct is_default_constructible<const std::pair<T1, T2>>
3569  : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3570 
3571 template <typename... Ts>
3572 struct is_default_constructible<std::tuple<Ts...>>
3573  : conjunction<is_default_constructible<Ts>...> {};
3574 
3575 template <typename... Ts>
3576 struct is_default_constructible<const std::tuple<Ts...>>
3577  : conjunction<is_default_constructible<Ts>...> {};
3578 
3579 
3580 template <typename T, typename... Args>
3581 struct is_constructible : std::is_constructible<T, Args...> {};
3582 
3583 template <typename T1, typename T2>
3584 struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
3585 
3586 template <typename T1, typename T2>
3587 struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
3588 
3589 template <typename... Ts>
3590 struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
3591 
3592 template <typename... Ts>
3593 struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
3594 
3595 
3596 template<typename T, typename = void>
3597 struct is_iterator_traits : std::false_type {};
3598 
3599 template<typename T>
3600 struct is_iterator_traits<iterator_traits<T>>
3601 {
3602  private:
3603  using traits = iterator_traits<T>;
3604 
3605  public:
3606  static constexpr auto value =
3607  is_detected<value_type_t, traits>::value &&
3608  is_detected<difference_type_t, traits>::value &&
3609  is_detected<pointer_t, traits>::value &&
3610  is_detected<iterator_category_t, traits>::value &&
3611  is_detected<reference_t, traits>::value;
3612 };
3613 
3614 // The following implementation of is_complete_type is taken from
3615 // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/
3616 // and is written by Xiang Fan who agreed to using it in this library.
3617 
3618 template<typename T, typename = void>
3619 struct is_complete_type : std::false_type {};
3620 
3621 template<typename T>
3622 struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3623 
3624 template<typename BasicJsonType, typename CompatibleObjectType,
3625  typename = void>
3626 struct is_compatible_object_type_impl : std::false_type {};
3627 
3628 template<typename BasicJsonType, typename CompatibleObjectType>
3629 struct is_compatible_object_type_impl <
3630  BasicJsonType, CompatibleObjectType,
3631  enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3632  is_detected<key_type_t, CompatibleObjectType>::value >>
3633 {
3634  using object_t = typename BasicJsonType::object_t;
3635 
3636  // macOS's is_constructible does not play well with nonesuch...
3637  static constexpr bool value =
3638  is_constructible<typename object_t::key_type,
3639  typename CompatibleObjectType::key_type>::value &&
3640  is_constructible<typename object_t::mapped_type,
3641  typename CompatibleObjectType::mapped_type>::value;
3642 };
3643 
3644 template<typename BasicJsonType, typename CompatibleObjectType>
3645 struct is_compatible_object_type
3646  : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
3647 
3648 template<typename BasicJsonType, typename ConstructibleObjectType,
3649  typename = void>
3650 struct is_constructible_object_type_impl : std::false_type {};
3651 
3652 template<typename BasicJsonType, typename ConstructibleObjectType>
3653 struct is_constructible_object_type_impl <
3654  BasicJsonType, ConstructibleObjectType,
3655  enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3656  is_detected<key_type_t, ConstructibleObjectType>::value >>
3657 {
3658  using object_t = typename BasicJsonType::object_t;
3659 
3660  static constexpr bool value =
3661  (is_default_constructible<ConstructibleObjectType>::value &&
3662  (std::is_move_assignable<ConstructibleObjectType>::value ||
3663  std::is_copy_assignable<ConstructibleObjectType>::value) &&
3664  (is_constructible<typename ConstructibleObjectType::key_type,
3665  typename object_t::key_type>::value &&
3666  std::is_same <
3667  typename object_t::mapped_type,
3668  typename ConstructibleObjectType::mapped_type >::value)) ||
3669  (has_from_json<BasicJsonType,
3670  typename ConstructibleObjectType::mapped_type>::value ||
3671  has_non_default_from_json <
3672  BasicJsonType,
3673  typename ConstructibleObjectType::mapped_type >::value);
3674 };
3675 
3676 template<typename BasicJsonType, typename ConstructibleObjectType>
3677 struct is_constructible_object_type
3678  : is_constructible_object_type_impl<BasicJsonType,
3679  ConstructibleObjectType> {};
3680 
3681 template<typename BasicJsonType, typename CompatibleStringType,
3682  typename = void>
3683 struct is_compatible_string_type_impl : std::false_type {};
3684 
3685 template<typename BasicJsonType, typename CompatibleStringType>
3686 struct is_compatible_string_type_impl <
3687  BasicJsonType, CompatibleStringType,
3688  enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3689  value_type_t, CompatibleStringType>::value >>
3690 {
3691  static constexpr auto value =
3692  is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
3693 };
3694 
3695 template<typename BasicJsonType, typename ConstructibleStringType>
3696 struct is_compatible_string_type
3697  : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3698 
3699 template<typename BasicJsonType, typename ConstructibleStringType,
3700  typename = void>
3701 struct is_constructible_string_type_impl : std::false_type {};
3702 
3703 template<typename BasicJsonType, typename ConstructibleStringType>
3704 struct is_constructible_string_type_impl <
3705  BasicJsonType, ConstructibleStringType,
3706  enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3707  value_type_t, ConstructibleStringType>::value >>
3708 {
3709  static constexpr auto value =
3710  is_constructible<ConstructibleStringType,
3711  typename BasicJsonType::string_t>::value;
3712 };
3713 
3714 template<typename BasicJsonType, typename ConstructibleStringType>
3715 struct is_constructible_string_type
3716  : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3717 
3718 template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
3719 struct is_compatible_array_type_impl : std::false_type {};
3720 
3721 template<typename BasicJsonType, typename CompatibleArrayType>
3722 struct is_compatible_array_type_impl <
3723  BasicJsonType, CompatibleArrayType,
3724  enable_if_t < is_detected<value_type_t, CompatibleArrayType>::value&&
3725  is_detected<iterator_t, CompatibleArrayType>::value&&
3726 // This is needed because json_reverse_iterator has a ::iterator type...
3727 // Therefore it is detected as a CompatibleArrayType.
3728 // The real fix would be to have an Iterable concept.
3729  !is_iterator_traits <
3730  iterator_traits<CompatibleArrayType >>::value >>
3731 {
3732  static constexpr bool value =
3733  is_constructible<BasicJsonType,
3734  typename CompatibleArrayType::value_type>::value;
3735 };
3736 
3737 template<typename BasicJsonType, typename CompatibleArrayType>
3738 struct is_compatible_array_type
3739  : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
3740 
3741 template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>
3742 struct is_constructible_array_type_impl : std::false_type {};
3743 
3744 template<typename BasicJsonType, typename ConstructibleArrayType>
3745 struct is_constructible_array_type_impl <
3746  BasicJsonType, ConstructibleArrayType,
3747  enable_if_t<std::is_same<ConstructibleArrayType,
3748  typename BasicJsonType::value_type>::value >>
3749  : std::true_type {};
3750 
3751 template<typename BasicJsonType, typename ConstructibleArrayType>
3752 struct is_constructible_array_type_impl <
3753  BasicJsonType, ConstructibleArrayType,
3754  enable_if_t < !std::is_same<ConstructibleArrayType,
3755  typename BasicJsonType::value_type>::value&&
3756  is_default_constructible<ConstructibleArrayType>::value&&
3757 (std::is_move_assignable<ConstructibleArrayType>::value ||
3758  std::is_copy_assignable<ConstructibleArrayType>::value)&&
3759 is_detected<value_type_t, ConstructibleArrayType>::value&&
3760 is_detected<iterator_t, ConstructibleArrayType>::value&&
3761 is_complete_type <
3762 detected_t<value_type_t, ConstructibleArrayType >>::value >>
3763 {
3764  static constexpr bool value =
3765  // This is needed because json_reverse_iterator has a ::iterator type,
3766  // furthermore, std::back_insert_iterator (and other iterators) have a
3767  // base class `iterator`... Therefore it is detected as a
3768  // ConstructibleArrayType. The real fix would be to have an Iterable
3769  // concept.
3770  !is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value &&
3771 
3772  (std::is_same<typename ConstructibleArrayType::value_type,
3773  typename BasicJsonType::array_t::value_type>::value ||
3774  has_from_json<BasicJsonType,
3775  typename ConstructibleArrayType::value_type>::value ||
3776  has_non_default_from_json <
3777  BasicJsonType, typename ConstructibleArrayType::value_type >::value);
3778 };
3779 
3780 template<typename BasicJsonType, typename ConstructibleArrayType>
3781 struct is_constructible_array_type
3782  : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
3783 
3784 template<typename RealIntegerType, typename CompatibleNumberIntegerType,
3785  typename = void>
3786 struct is_compatible_integer_type_impl : std::false_type {};
3787 
3788 template<typename RealIntegerType, typename CompatibleNumberIntegerType>
3789 struct is_compatible_integer_type_impl <
3790  RealIntegerType, CompatibleNumberIntegerType,
3791  enable_if_t < std::is_integral<RealIntegerType>::value&&
3792  std::is_integral<CompatibleNumberIntegerType>::value&&
3793  !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3794 {
3795  // is there an assert somewhere on overflows?
3796  using RealLimits = std::numeric_limits<RealIntegerType>;
3797  using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3798 
3799  static constexpr auto value =
3800  is_constructible<RealIntegerType,
3801  CompatibleNumberIntegerType>::value &&
3802  CompatibleLimits::is_integer &&
3803  RealLimits::is_signed == CompatibleLimits::is_signed;
3804 };
3805 
3806 template<typename RealIntegerType, typename CompatibleNumberIntegerType>
3807 struct is_compatible_integer_type
3808  : is_compatible_integer_type_impl<RealIntegerType,
3809  CompatibleNumberIntegerType> {};
3810 
3811 template<typename BasicJsonType, typename CompatibleType, typename = void>
3812 struct is_compatible_type_impl: std::false_type {};
3813 
3814 template<typename BasicJsonType, typename CompatibleType>
3815 struct is_compatible_type_impl <
3816  BasicJsonType, CompatibleType,
3817  enable_if_t<is_complete_type<CompatibleType>::value >>
3818 {
3819  static constexpr bool value =
3820  has_to_json<BasicJsonType, CompatibleType>::value;
3821 };
3822 
3823 template<typename BasicJsonType, typename CompatibleType>
3824 struct is_compatible_type
3825  : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
3826 
3827 template<typename T1, typename T2>
3828 struct is_constructible_tuple : std::false_type {};
3829 
3830 template<typename T1, typename... Args>
3831 struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
3832 } // namespace detail
3833 } // namespace nlohmann
3834 
3835 // #include <nlohmann/detail/value_t.hpp>
3836 
3837 
3838 namespace nlohmann
3839 {
3840 namespace detail
3841 {
3842 template<typename BasicJsonType>
3843 void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
3844 {
3845  if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3846  {
3847  JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()), j));
3848  }
3849  n = nullptr;
3850 }
3851 
3852 // overloads for basic_json template parameters
3853 template < typename BasicJsonType, typename ArithmeticType,
3854  enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
3855  !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3856  int > = 0 >
3857 void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
3858 {
3859  switch (static_cast<value_t>(j))
3860  {
3861  case value_t::number_unsigned:
3862  {
3863  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3864  break;
3865  }
3866  case value_t::number_integer:
3867  {
3868  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3869  break;
3870  }
3871  case value_t::number_float:
3872  {
3873  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3874  break;
3875  }
3876 
3877  default:
3878  JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
3879  }
3880 }
3881 
3882 template<typename BasicJsonType>
3883 void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
3884 {
3885  if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
3886  {
3887  JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()), j));
3888  }
3889  b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
3890 }
3891 
3892 template<typename BasicJsonType>
3893 void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
3894 {
3895  if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3896  {
3897  JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
3898  }
3899  s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3900 }
3901 
3902 template <
3903  typename BasicJsonType, typename ConstructibleStringType,
3904  enable_if_t <
3905  is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&&
3906  !std::is_same<typename BasicJsonType::string_t,
3907  ConstructibleStringType>::value,
3908  int > = 0 >
3909 void from_json(const BasicJsonType& j, ConstructibleStringType& s)
3910 {
3911  if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3912  {
3913  JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
3914  }
3915 
3916  s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3917 }
3918 
3919 template<typename BasicJsonType>
3920 void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val)
3921 {
3922  get_arithmetic_value(j, val);
3923 }
3924 
3925 template<typename BasicJsonType>
3926 void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val)
3927 {
3928  get_arithmetic_value(j, val);
3929 }
3930 
3931 template<typename BasicJsonType>
3932 void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val)
3933 {
3934  get_arithmetic_value(j, val);
3935 }
3936 
3937 template<typename BasicJsonType, typename EnumType,
3938  enable_if_t<std::is_enum<EnumType>::value, int> = 0>
3939 void from_json(const BasicJsonType& j, EnumType& e)
3940 {
3941  typename std::underlying_type<EnumType>::type val;
3942  get_arithmetic_value(j, val);
3943  e = static_cast<EnumType>(val);
3944 }
3945 
3946 // forward_list doesn't have an insert method
3947 template<typename BasicJsonType, typename T, typename Allocator,
3948  enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
3949 void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
3950 {
3951  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3952  {
3953  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
3954  }
3955  l.clear();
3956  std::transform(j.rbegin(), j.rend(),
3957  std::front_inserter(l), [](const BasicJsonType & i)
3958  {
3959  return i.template get<T>();
3960  });
3961 }
3962 
3963 // valarray doesn't have an insert method
3964 template<typename BasicJsonType, typename T,
3965  enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
3966 void from_json(const BasicJsonType& j, std::valarray<T>& l)
3967 {
3968  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3969  {
3970  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
3971  }
3972  l.resize(j.size());
3973  std::transform(j.begin(), j.end(), std::begin(l),
3974  [](const BasicJsonType & elem)
3975  {
3976  return elem.template get<T>();
3977  });
3978 }
3979 
3980 template<typename BasicJsonType, typename T, std::size_t N>
3981 auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
3982 -> decltype(j.template get<T>(), void())
3983 {
3984  for (std::size_t i = 0; i < N; ++i)
3985  {
3986  arr[i] = j.at(i).template get<T>();
3987  }
3988 }
3989 
3990 template<typename BasicJsonType>
3991 void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/)
3992 {
3993  arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
3994 }
3995 
3996 template<typename BasicJsonType, typename T, std::size_t N>
3997 auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
3998  priority_tag<2> /*unused*/)
3999 -> decltype(j.template get<T>(), void())
4000 {
4001  for (std::size_t i = 0; i < N; ++i)
4002  {
4003  arr[i] = j.at(i).template get<T>();
4004  }
4005 }
4006 
4007 template<typename BasicJsonType, typename ConstructibleArrayType,
4008  enable_if_t<
4009  std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4010  int> = 0>
4011 auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/)
4012 -> decltype(
4013  arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4014  j.template get<typename ConstructibleArrayType::value_type>(),
4015  void())
4016 {
4017  using std::end;
4018 
4019  ConstructibleArrayType ret;
4020  ret.reserve(j.size());
4021  std::transform(j.begin(), j.end(),
4022  std::inserter(ret, end(ret)), [](const BasicJsonType & i)
4023  {
4024  // get<BasicJsonType>() returns *this, this won't call a from_json
4025  // method when value_type is BasicJsonType
4026  return i.template get<typename ConstructibleArrayType::value_type>();
4027  });
4028  arr = std::move(ret);
4029 }
4030 
4031 template<typename BasicJsonType, typename ConstructibleArrayType,
4032  enable_if_t<
4033  std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4034  int> = 0>
4035 void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
4036  priority_tag<0> /*unused*/)
4037 {
4038  using std::end;
4039 
4040  ConstructibleArrayType ret;
4041  std::transform(
4042  j.begin(), j.end(), std::inserter(ret, end(ret)),
4043  [](const BasicJsonType & i)
4044  {
4045  // get<BasicJsonType>() returns *this, this won't call a from_json
4046  // method when value_type is BasicJsonType
4047  return i.template get<typename ConstructibleArrayType::value_type>();
4048  });
4049  arr = std::move(ret);
4050 }
4051 
4052 template < typename BasicJsonType, typename ConstructibleArrayType,
4053  enable_if_t <
4054  is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
4055  !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
4056  !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
4057  !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
4058  !is_basic_json<ConstructibleArrayType>::value,
4059  int > = 0 >
4060 auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
4061 -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4062 j.template get<typename ConstructibleArrayType::value_type>(),
4063 void())
4064 {
4065  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4066  {
4067  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
4068  }
4069 
4070  from_json_array_impl(j, arr, priority_tag<3> {});
4071 }
4072 
4073 template < typename BasicJsonType, typename T, std::size_t... Idx >
4074 std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
4075  identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)
4076 {
4077  return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4078 }
4079 
4080 template < typename BasicJsonType, typename T, std::size_t N >
4081 auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
4082 -> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4083 {
4084  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4085  {
4086  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
4087  }
4088 
4089  return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4090 }
4091 
4092 template<typename BasicJsonType>
4093 void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
4094 {
4095  if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4096  {
4097  JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()), j));
4098  }
4099 
4100  bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4101 }
4102 
4103 template<typename BasicJsonType, typename ConstructibleObjectType,
4104  enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
4105 void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
4106 {
4107  if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4108  {
4109  JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()), j));
4110  }
4111 
4112  ConstructibleObjectType ret;
4113  const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4114  using value_type = typename ConstructibleObjectType::value_type;
4115  std::transform(
4116  inner_object->begin(), inner_object->end(),
4117  std::inserter(ret, ret.begin()),
4118  [](typename BasicJsonType::object_t::value_type const & p)
4119  {
4120  return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4121  });
4122  obj = std::move(ret);
4123 }
4124 
4125 // overload for arithmetic types, not chosen for basic_json template arguments
4126 // (BooleanType, etc..); note: Is it really necessary to provide explicit
4127 // overloads for boolean_t etc. in case of a custom BooleanType which is not
4128 // an arithmetic type?
4129 template < typename BasicJsonType, typename ArithmeticType,
4130  enable_if_t <
4131  std::is_arithmetic<ArithmeticType>::value&&
4132  !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
4133  !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
4134  !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
4135  !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4136  int > = 0 >
4137 void from_json(const BasicJsonType& j, ArithmeticType& val)
4138 {
4139  switch (static_cast<value_t>(j))
4140  {
4141  case value_t::number_unsigned:
4142  {
4143  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4144  break;
4145  }
4146  case value_t::number_integer:
4147  {
4148  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4149  break;
4150  }
4151  case value_t::number_float:
4152  {
4153  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4154  break;
4155  }
4156  case value_t::boolean:
4157  {
4158  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4159  break;
4160  }
4161 
4162  default:
4163  JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
4164  }
4165 }
4166 
4167 template<typename BasicJsonType, typename... Args, std::size_t... Idx>
4168 std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> /*unused*/)
4169 {
4170  return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).template get<Args>()...);
4171 }
4172 
4173 template < typename BasicJsonType, class A1, class A2 >
4174 std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)
4175 {
4176  return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
4177  std::forward<BasicJsonType>(j).at(1).template get<A2>()};
4178 }
4179 
4180 template<typename BasicJsonType, typename A1, typename A2>
4181 void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> /*unused*/)
4182 {
4183  p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
4184 }
4185 
4186 template<typename BasicJsonType, typename... Args>
4187 std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> /*unused*/, priority_tag<2> /*unused*/)
4188 {
4189  return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4190 }
4191 
4192 template<typename BasicJsonType, typename... Args>
4193 void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> /*unused*/)
4194 {
4195  t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4196 }
4197 
4198 template<typename BasicJsonType, typename TupleRelated>
4199 auto from_json(BasicJsonType&& j, TupleRelated&& t)
4200 -> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
4201 {
4202  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4203  {
4204  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
4205  }
4206 
4207  return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
4208 }
4209 
4210 template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
4211  typename = enable_if_t < !std::is_constructible <
4212  typename BasicJsonType::string_t, Key >::value >>
4213 void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
4214 {
4215  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4216  {
4217  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
4218  }
4219  m.clear();
4220  for (const auto& p : j)
4221  {
4222  if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4223  {
4224  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
4225  }
4226  m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4227  }
4228 }
4229 
4230 template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,
4231  typename = enable_if_t < !std::is_constructible <
4232  typename BasicJsonType::string_t, Key >::value >>
4233 void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
4234 {
4235  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4236  {
4237  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
4238  }
4239  m.clear();
4240  for (const auto& p : j)
4241  {
4242  if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4243  {
4244  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
4245  }
4246  m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4247  }
4248 }
4249 
4250 struct from_json_fn
4251 {
4252  template<typename BasicJsonType, typename T>
4253  auto operator()(const BasicJsonType& j, T&& val) const
4254  noexcept(noexcept(from_json(j, std::forward<T>(val))))
4255  -> decltype(from_json(j, std::forward<T>(val)))
4256  {
4257  return from_json(j, std::forward<T>(val));
4258  }
4259 };
4260 } // namespace detail
4261 
4265 namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)
4266 {
4267 constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value; // NOLINT(misc-definitions-in-headers)
4268 } // namespace
4269 } // namespace nlohmann
4270 
4271 // #include <nlohmann/detail/conversions/to_json.hpp>
4272 
4273 
4274 #include <algorithm> // copy
4275 #include <iterator> // begin, end
4276 #include <string> // string
4277 #include <tuple> // tuple, get
4278 #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
4279 #include <utility> // move, forward, declval, pair
4280 #include <valarray> // valarray
4281 #include <vector> // vector
4282 
4283 // #include <nlohmann/detail/iterators/iteration_proxy.hpp>
4284 
4285 
4286 #include <cstddef> // size_t
4287 #include <iterator> // input_iterator_tag
4288 #include <string> // string, to_string
4289 #include <tuple> // tuple_size, get, tuple_element
4290 #include <utility> // move
4291 
4292 // #include <nlohmann/detail/meta/type_traits.hpp>
4293 
4294 // #include <nlohmann/detail/value_t.hpp>
4295 
4296 
4297 namespace nlohmann
4298 {
4299 namespace detail
4300 {
4301 template<typename string_type>
4302 void int_to_string( string_type& target, std::size_t value )
4303 {
4304  // For ADL
4305  using std::to_string;
4306  target = to_string(value);
4307 }
4308 template<typename IteratorType> class iteration_proxy_value
4309 {
4310  public:
4311  using difference_type = std::ptrdiff_t;
4312  using value_type = iteration_proxy_value;
4313  using pointer = value_type * ;
4314  using reference = value_type & ;
4315  using iterator_category = std::input_iterator_tag;
4316  using string_type = typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
4317 
4318  private:
4320  IteratorType anchor;
4322  std::size_t array_index = 0;
4324  mutable std::size_t array_index_last = 0;
4326  mutable string_type array_index_str = "0";
4328  const string_type empty_str{};
4329 
4330  public:
4331  explicit iteration_proxy_value(IteratorType it) noexcept
4332  : anchor(std::move(it))
4333  {}
4334 
4336  iteration_proxy_value& operator*()
4337  {
4338  return *this;
4339  }
4340 
4342  iteration_proxy_value& operator++()
4343  {
4344  ++anchor;
4345  ++array_index;
4346 
4347  return *this;
4348  }
4349 
4351  bool operator==(const iteration_proxy_value& o) const
4352  {
4353  return anchor == o.anchor;
4354  }
4355 
4357  bool operator!=(const iteration_proxy_value& o) const
4358  {
4359  return anchor != o.anchor;
4360  }
4361 
4363  const string_type& key() const
4364  {
4365  JSON_ASSERT(anchor.m_object != nullptr);
4366 
4367  switch (anchor.m_object->type())
4368  {
4369  // use integer array index as key
4370  case value_t::array:
4371  {
4372  if (array_index != array_index_last)
4373  {
4374  int_to_string( array_index_str, array_index );
4375  array_index_last = array_index;
4376  }
4377  return array_index_str;
4378  }
4379 
4380  // use key from the object
4381  case value_t::object:
4382  return anchor.key();
4383 
4384  // use an empty key for all primitive types
4385  default:
4386  return empty_str;
4387  }
4388  }
4389 
4391  typename IteratorType::reference value() const
4392  {
4393  return anchor.value();
4394  }
4395 };
4396 
4398 template<typename IteratorType> class iteration_proxy
4399 {
4400  private:
4402  typename IteratorType::reference container;
4403 
4404  public:
4406  explicit iteration_proxy(typename IteratorType::reference cont) noexcept
4407  : container(cont) {}
4408 
4410  iteration_proxy_value<IteratorType> begin() noexcept
4411  {
4412  return iteration_proxy_value<IteratorType>(container.begin());
4413  }
4414 
4416  iteration_proxy_value<IteratorType> end() noexcept
4417  {
4418  return iteration_proxy_value<IteratorType>(container.end());
4419  }
4420 };
4421 // Structured Bindings Support
4422 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
4423 // And see https://github.com/nlohmann/json/pull/1391
4424 template<std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0>
4425 auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
4426 {
4427  return i.key();
4428 }
4429 // Structured Bindings Support
4430 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
4431 // And see https://github.com/nlohmann/json/pull/1391
4432 template<std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0>
4433 auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
4434 {
4435  return i.value();
4436 }
4437 } // namespace detail
4438 } // namespace nlohmann
4439 
4440 // The Addition to the STD Namespace is required to add
4441 // Structured Bindings Support to the iteration_proxy_value class
4442 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
4443 // And see https://github.com/nlohmann/json/pull/1391
4444 namespace std
4445 {
4446 #if defined(__clang__)
4447  // Fix: https://github.com/nlohmann/json/issues/1401
4448  #pragma clang diagnostic push
4449  #pragma clang diagnostic ignored "-Wmismatched-tags"
4450 #endif
4451 template<typename IteratorType>
4452 class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
4453  : public std::integral_constant<std::size_t, 2> {};
4454 
4455 template<std::size_t N, typename IteratorType>
4456 class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
4457 {
4458  public:
4459  using type = decltype(
4460  get<N>(std::declval <
4461  ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
4462 };
4463 #if defined(__clang__)
4464  #pragma clang diagnostic pop
4465 #endif
4466 } // namespace std
4467 
4468 // #include <nlohmann/detail/meta/cpp_future.hpp>
4469 
4470 // #include <nlohmann/detail/meta/type_traits.hpp>
4471 
4472 // #include <nlohmann/detail/value_t.hpp>
4473 
4474 
4475 namespace nlohmann
4476 {
4477 namespace detail
4478 {
4480 // constructors //
4482 
4483 /*
4484  * Note all external_constructor<>::construct functions need to call
4485  * j.m_value.destroy(j.m_type) to avoid a memory leak in case j contains an
4486  * allocated value (e.g., a string). See bug issue
4487  * https://github.com/nlohmann/json/issues/2865 for more information.
4488  */
4489 
4490 template<value_t> struct external_constructor;
4491 
4492 template<>
4493 struct external_constructor<value_t::boolean>
4494 {
4495  template<typename BasicJsonType>
4496  static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept
4497  {
4498  j.m_value.destroy(j.m_type);
4499  j.m_type = value_t::boolean;
4500  j.m_value = b;
4501  j.assert_invariant();
4502  }
4503 };
4504 
4505 template<>
4506 struct external_constructor<value_t::string>
4507 {
4508  template<typename BasicJsonType>
4509  static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s)
4510  {
4511  j.m_value.destroy(j.m_type);
4512  j.m_type = value_t::string;
4513  j.m_value = s;
4514  j.assert_invariant();
4515  }
4516 
4517  template<typename BasicJsonType>
4518  static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s)
4519  {
4520  j.m_value.destroy(j.m_type);
4521  j.m_type = value_t::string;
4522  j.m_value = std::move(s);
4523  j.assert_invariant();
4524  }
4525 
4526  template < typename BasicJsonType, typename CompatibleStringType,
4527  enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
4528  int > = 0 >
4529  static void construct(BasicJsonType& j, const CompatibleStringType& str)
4530  {
4531  j.m_value.destroy(j.m_type);
4532  j.m_type = value_t::string;
4533  j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
4534  j.assert_invariant();
4535  }
4536 };
4537 
4538 template<>
4539 struct external_constructor<value_t::binary>
4540 {
4541  template<typename BasicJsonType>
4542  static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
4543  {
4544  j.m_value.destroy(j.m_type);
4545  j.m_type = value_t::binary;
4546  j.m_value = typename BasicJsonType::binary_t(b);
4547  j.assert_invariant();
4548  }
4549 
4550  template<typename BasicJsonType>
4551  static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
4552  {
4553  j.m_value.destroy(j.m_type);
4554  j.m_type = value_t::binary;
4555  j.m_value = typename BasicJsonType::binary_t(std::move(b));;
4556  j.assert_invariant();
4557  }
4558 };
4559 
4560 template<>
4561 struct external_constructor<value_t::number_float>
4562 {
4563  template<typename BasicJsonType>
4564  static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept
4565  {
4566  j.m_value.destroy(j.m_type);
4567  j.m_type = value_t::number_float;
4568  j.m_value = val;
4569  j.assert_invariant();
4570  }
4571 };
4572 
4573 template<>
4574 struct external_constructor<value_t::number_unsigned>
4575 {
4576  template<typename BasicJsonType>
4577  static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept
4578  {
4579  j.m_value.destroy(j.m_type);
4580  j.m_type = value_t::number_unsigned;
4581  j.m_value = val;
4582  j.assert_invariant();
4583  }
4584 };
4585 
4586 template<>
4587 struct external_constructor<value_t::number_integer>
4588 {
4589  template<typename BasicJsonType>
4590  static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept
4591  {
4592  j.m_value.destroy(j.m_type);
4593  j.m_type = value_t::number_integer;
4594  j.m_value = val;
4595  j.assert_invariant();
4596  }
4597 };
4598 
4599 template<>
4600 struct external_constructor<value_t::array>
4601 {
4602  template<typename BasicJsonType>
4603  static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr)
4604  {
4605  j.m_value.destroy(j.m_type);
4606  j.m_type = value_t::array;
4607  j.m_value = arr;
4608  j.set_parents();
4609  j.assert_invariant();
4610  }
4611 
4612  template<typename BasicJsonType>
4613  static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
4614  {
4615  j.m_value.destroy(j.m_type);
4616  j.m_type = value_t::array;
4617  j.m_value = std::move(arr);
4618  j.set_parents();
4619  j.assert_invariant();
4620  }
4621 
4622  template < typename BasicJsonType, typename CompatibleArrayType,
4623  enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
4624  int > = 0 >
4625  static void construct(BasicJsonType& j, const CompatibleArrayType& arr)
4626  {
4627  using std::begin;
4628  using std::end;
4629 
4630  j.m_value.destroy(j.m_type);
4631  j.m_type = value_t::array;
4632  j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
4633  j.set_parents();
4634  j.assert_invariant();
4635  }
4636 
4637  template<typename BasicJsonType>
4638  static void construct(BasicJsonType& j, const std::vector<bool>& arr)
4639  {
4640  j.m_value.destroy(j.m_type);
4641  j.m_type = value_t::array;
4642  j.m_value = value_t::array;
4643  j.m_value.array->reserve(arr.size());
4644  for (const bool x : arr)
4645  {
4646  j.m_value.array->push_back(x);
4647  j.set_parent(j.m_value.array->back());
4648  }
4649  j.assert_invariant();
4650  }
4651 
4652  template<typename BasicJsonType, typename T,
4653  enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
4654  static void construct(BasicJsonType& j, const std::valarray<T>& arr)
4655  {
4656  j.m_value.destroy(j.m_type);
4657  j.m_type = value_t::array;
4658  j.m_value = value_t::array;
4659  j.m_value.array->resize(arr.size());
4660  if (arr.size() > 0)
4661  {
4662  std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
4663  }
4664  j.set_parents();
4665  j.assert_invariant();
4666  }
4667 };
4668 
4669 template<>
4670 struct external_constructor<value_t::object>
4671 {
4672  template<typename BasicJsonType>
4673  static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj)
4674  {
4675  j.m_value.destroy(j.m_type);
4676  j.m_type = value_t::object;
4677  j.m_value = obj;
4678  j.set_parents();
4679  j.assert_invariant();
4680  }
4681 
4682  template<typename BasicJsonType>
4683  static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
4684  {
4685  j.m_value.destroy(j.m_type);
4686  j.m_type = value_t::object;
4687  j.m_value = std::move(obj);
4688  j.set_parents();
4689  j.assert_invariant();
4690  }
4691 
4692  template < typename BasicJsonType, typename CompatibleObjectType,
4693  enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int > = 0 >
4694  static void construct(BasicJsonType& j, const CompatibleObjectType& obj)
4695  {
4696  using std::begin;
4697  using std::end;
4698 
4699  j.m_value.destroy(j.m_type);
4700  j.m_type = value_t::object;
4701  j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
4702  j.set_parents();
4703  j.assert_invariant();
4704  }
4705 };
4706 
4708 // to_json //
4710 
4711 template<typename BasicJsonType, typename T,
4712  enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0>
4713 void to_json(BasicJsonType& j, T b) noexcept
4714 {
4715  external_constructor<value_t::boolean>::construct(j, b);
4716 }
4717 
4718 template<typename BasicJsonType, typename CompatibleString,
4719  enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
4720 void to_json(BasicJsonType& j, const CompatibleString& s)
4721 {
4722  external_constructor<value_t::string>::construct(j, s);
4723 }
4724 
4725 template<typename BasicJsonType>
4726 void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s)
4727 {
4728  external_constructor<value_t::string>::construct(j, std::move(s));
4729 }
4730 
4731 template<typename BasicJsonType, typename FloatType,
4732  enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
4733 void to_json(BasicJsonType& j, FloatType val) noexcept
4734 {
4735  external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val));
4736 }
4737 
4738 template<typename BasicJsonType, typename CompatibleNumberUnsignedType,
4739  enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0>
4740 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
4741 {
4742  external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val));
4743 }
4744 
4745 template<typename BasicJsonType, typename CompatibleNumberIntegerType,
4746  enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0>
4747 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
4748 {
4749  external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val));
4750 }
4751 
4752 template<typename BasicJsonType, typename EnumType,
4753  enable_if_t<std::is_enum<EnumType>::value, int> = 0>
4754 void to_json(BasicJsonType& j, EnumType e) noexcept
4755 {
4756  using underlying_type = typename std::underlying_type<EnumType>::type;
4757  external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));
4758 }
4759 
4760 template<typename BasicJsonType>
4761 void to_json(BasicJsonType& j, const std::vector<bool>& e)
4762 {
4763  external_constructor<value_t::array>::construct(j, e);
4764 }
4765 
4766 template < typename BasicJsonType, typename CompatibleArrayType,
4767  enable_if_t < is_compatible_array_type<BasicJsonType,
4768  CompatibleArrayType>::value&&
4769  !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
4770  !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
4771  !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
4772  !is_basic_json<CompatibleArrayType>::value,
4773  int > = 0 >
4774 void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
4775 {
4776  external_constructor<value_t::array>::construct(j, arr);
4777 }
4778 
4779 template<typename BasicJsonType>
4780 void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
4781 {
4782  external_constructor<value_t::binary>::construct(j, bin);
4783 }
4784 
4785 template<typename BasicJsonType, typename T,
4786  enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
4787 void to_json(BasicJsonType& j, const std::valarray<T>& arr)
4788 {
4789  external_constructor<value_t::array>::construct(j, std::move(arr));
4790 }
4791 
4792 template<typename BasicJsonType>
4793 void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
4794 {
4795  external_constructor<value_t::array>::construct(j, std::move(arr));
4796 }
4797 
4798 template < typename BasicJsonType, typename CompatibleObjectType,
4799  enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value, int > = 0 >
4800 void to_json(BasicJsonType& j, const CompatibleObjectType& obj)
4801 {
4802  external_constructor<value_t::object>::construct(j, obj);
4803 }
4804 
4805 template<typename BasicJsonType>
4806 void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
4807 {
4808  external_constructor<value_t::object>::construct(j, std::move(obj));
4809 }
4810 
4811 template <
4812  typename BasicJsonType, typename T, std::size_t N,
4813  enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
4814  const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
4815  int > = 0 >
4816 void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
4817 {
4818  external_constructor<value_t::array>::construct(j, arr);
4819 }
4820 
4821 template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value, int > = 0 >
4822 void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
4823 {
4824  j = { p.first, p.second };
4825 }
4826 
4827 // for https://github.com/nlohmann/json/pull/1134
4828 template<typename BasicJsonType, typename T,
4829  enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
4830 void to_json(BasicJsonType& j, const T& b)
4831 {
4832  j = { {b.key(), b.value()} };
4833 }
4834 
4835 template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
4836 void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
4837 {
4838  j = { std::get<Idx>(t)... };
4839 }
4840 
4841 template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int > = 0>
4842 void to_json(BasicJsonType& j, const T& t)
4843 {
4844  to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
4845 }
4846 
4847 struct to_json_fn
4848 {
4849  template<typename BasicJsonType, typename T>
4850  auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val))))
4851  -> decltype(to_json(j, std::forward<T>(val)), void())
4852  {
4853  return to_json(j, std::forward<T>(val));
4854  }
4855 };
4856 } // namespace detail
4857 
4861 namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)
4862 {
4863 constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value; // NOLINT(misc-definitions-in-headers)
4864 } // namespace
4865 } // namespace nlohmann
4866 
4867 // #include <nlohmann/detail/meta/identity_tag.hpp>
4868 
4869 // #include <nlohmann/detail/meta/type_traits.hpp>
4870 
4871 
4872 namespace nlohmann
4873 {
4874 
4875 template<typename ValueType, typename>
4877 {
4889  template<typename BasicJsonType, typename TargetType = ValueType>
4890  static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
4891  noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
4892  -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
4893  {
4894  ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
4895  }
4896 
4909  template<typename BasicJsonType, typename TargetType = ValueType>
4910  static auto from_json(BasicJsonType && j) noexcept(
4911  noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
4912  -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
4913  {
4914  return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
4915  }
4916 
4926  template<typename BasicJsonType, typename TargetType = ValueType>
4927  static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
4928  noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
4929  -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
4930  {
4931  ::nlohmann::to_json(j, std::forward<TargetType>(val));
4932  }
4933 };
4934 } // namespace nlohmann
4935 
4936 // #include <nlohmann/byte_container_with_subtype.hpp>
4937 
4938 
4939 #include <cstdint> // uint8_t
4940 #include <tuple> // tie
4941 #include <utility> // move
4942 
4943 namespace nlohmann
4944 {
4945 
4959 template<typename BinaryType>
4960 class byte_container_with_subtype : public BinaryType
4961 {
4962  public:
4964  using container_type = BinaryType;
4965 
4967  : container_type()
4968  {}
4969 
4971  : container_type(b)
4972  {}
4973 
4974  byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
4975  : container_type(std::move(b))
4976  {}
4977 
4978  byte_container_with_subtype(const container_type& b, std::uint8_t subtype_) noexcept(noexcept(container_type(b)))
4979  : container_type(b)
4980  , m_subtype(subtype_)
4981  , m_has_subtype(true)
4982  {}
4983 
4984  byte_container_with_subtype(container_type&& b, std::uint8_t subtype_) noexcept(noexcept(container_type(std::move(b))))
4985  : container_type(std::move(b))
4986  , m_subtype(subtype_)
4987  , m_has_subtype(true)
4988  {}
4989 
4991  {
4992  return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==
4993  std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);
4994  }
4995 
4997  {
4998  return !(rhs == *this);
4999  }
5000 
5019  void set_subtype(std::uint8_t subtype_) noexcept
5020  {
5021  m_subtype = subtype_;
5022  m_has_subtype = true;
5023  }
5024 
5046  constexpr std::uint8_t subtype() const noexcept
5047  {
5048  return m_subtype;
5049  }
5050 
5067  constexpr bool has_subtype() const noexcept
5068  {
5069  return m_has_subtype;
5070  }
5071 
5091  void clear_subtype() noexcept
5092  {
5093  m_subtype = 0;
5094  m_has_subtype = false;
5095  }
5096 
5097  private:
5098  std::uint8_t m_subtype = 0;
5099  bool m_has_subtype = false;
5100 };
5101 
5102 } // namespace nlohmann
5103 
5104 // #include <nlohmann/detail/conversions/from_json.hpp>
5105 
5106 // #include <nlohmann/detail/conversions/to_json.hpp>
5107 
5108 // #include <nlohmann/detail/exceptions.hpp>
5109 
5110 // #include <nlohmann/detail/hash.hpp>
5111 
5112 
5113 #include <cstdint> // uint8_t
5114 #include <cstddef> // size_t
5115 #include <functional> // hash
5116 
5117 // #include <nlohmann/detail/macro_scope.hpp>
5118 
5119 
5120 namespace nlohmann
5121 {
5122 namespace detail
5123 {
5124 
5125 // boost::hash_combine
5126 inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
5127 {
5128  seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
5129  return seed;
5130 }
5131 
5143 template<typename BasicJsonType>
5144 std::size_t hash(const BasicJsonType& j)
5145 {
5146  using string_t = typename BasicJsonType::string_t;
5147  using number_integer_t = typename BasicJsonType::number_integer_t;
5148  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
5149  using number_float_t = typename BasicJsonType::number_float_t;
5150 
5151  const auto type = static_cast<std::size_t>(j.type());
5152  switch (j.type())
5153  {
5154  case BasicJsonType::value_t::null:
5155  case BasicJsonType::value_t::discarded:
5156  {
5157  return combine(type, 0);
5158  }
5159 
5160  case BasicJsonType::value_t::object:
5161  {
5162  auto seed = combine(type, j.size());
5163  for (const auto& element : j.items())
5164  {
5165  const auto h = std::hash<string_t> {}(element.key());
5166  seed = combine(seed, h);
5167  seed = combine(seed, hash(element.value()));
5168  }
5169  return seed;
5170  }
5171 
5172  case BasicJsonType::value_t::array:
5173  {
5174  auto seed = combine(type, j.size());
5175  for (const auto& element : j)
5176  {
5177  seed = combine(seed, hash(element));
5178  }
5179  return seed;
5180  }
5181 
5182  case BasicJsonType::value_t::string:
5183  {
5184  const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
5185  return combine(type, h);
5186  }
5187 
5188  case BasicJsonType::value_t::boolean:
5189  {
5190  const auto h = std::hash<bool> {}(j.template get<bool>());
5191  return combine(type, h);
5192  }
5193 
5194  case BasicJsonType::value_t::number_integer:
5195  {
5196  const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
5197  return combine(type, h);
5198  }
5199 
5200  case BasicJsonType::value_t::number_unsigned:
5201  {
5202  const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
5203  return combine(type, h);
5204  }
5205 
5206  case BasicJsonType::value_t::number_float:
5207  {
5208  const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
5209  return combine(type, h);
5210  }
5211 
5212  case BasicJsonType::value_t::binary:
5213  {
5214  auto seed = combine(type, j.get_binary().size());
5215  const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
5216  seed = combine(seed, h);
5217  seed = combine(seed, j.get_binary().subtype());
5218  for (const auto byte : j.get_binary())
5219  {
5220  seed = combine(seed, std::hash<std::uint8_t> {}(byte));
5221  }
5222  return seed;
5223  }
5224 
5225  default: // LCOV_EXCL_LINE
5226  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
5227  return 0; // LCOV_EXCL_LINE
5228  }
5229 }
5230 
5231 } // namespace detail
5232 } // namespace nlohmann
5233 
5234 // #include <nlohmann/detail/input/binary_reader.hpp>
5235 
5236 
5237 #include <algorithm> // generate_n
5238 #include <array> // array
5239 #include <cmath> // ldexp
5240 #include <cstddef> // size_t
5241 #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
5242 #include <cstdio> // snprintf
5243 #include <cstring> // memcpy
5244 #include <iterator> // back_inserter
5245 #include <limits> // numeric_limits
5246 #include <string> // char_traits, string
5247 #include <utility> // make_pair, move
5248 #include <vector> // vector
5249 
5250 // #include <nlohmann/detail/exceptions.hpp>
5251 
5252 // #include <nlohmann/detail/input/input_adapters.hpp>
5253 
5254 
5255 #include <array> // array
5256 #include <cstddef> // size_t
5257 #include <cstring> // strlen
5258 #include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next
5259 #include <memory> // shared_ptr, make_shared, addressof
5260 #include <numeric> // accumulate
5261 #include <string> // string, char_traits
5262 #include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
5263 #include <utility> // pair, declval
5264 
5265 #ifndef JSON_NO_IO
5266  #include <cstdio> //FILE *
5267  #include <istream> // istream
5268 #endif // JSON_NO_IO
5269 
5270 // #include <nlohmann/detail/iterators/iterator_traits.hpp>
5271 
5272 // #include <nlohmann/detail/macro_scope.hpp>
5273 
5274 
5275 namespace nlohmann
5276 {
5277 namespace detail
5278 {
5280 enum class input_format_t { json, cbor, msgpack, ubjson, bson };
5281 
5283 // input adapters //
5285 
5286 #ifndef JSON_NO_IO
5291 class file_input_adapter
5292 {
5293  public:
5294  using char_type = char;
5295 
5296  JSON_HEDLEY_NON_NULL(2)
5297  explicit file_input_adapter(std::FILE* f) noexcept
5298  : m_file(f)
5299  {}
5300 
5301  // make class move-only
5302  file_input_adapter(const file_input_adapter&) = delete;
5303  file_input_adapter(file_input_adapter&&) noexcept = default;
5304  file_input_adapter& operator=(const file_input_adapter&) = delete;
5305  file_input_adapter& operator=(file_input_adapter&&) = delete;
5306  ~file_input_adapter() = default;
5307 
5308  std::char_traits<char>::int_type get_character() noexcept
5309  {
5310  return std::fgetc(m_file);
5311  }
5312 
5313  private:
5315  std::FILE* m_file;
5316 };
5317 
5318 
5328 class input_stream_adapter
5329 {
5330  public:
5331  using char_type = char;
5332 
5333  ~input_stream_adapter()
5334  {
5335  // clear stream flags; we use underlying streambuf I/O, do not
5336  // maintain ifstream flags, except eof
5337  if (is != nullptr)
5338  {
5339  is->clear(is->rdstate() & std::ios::eofbit);
5340  }
5341  }
5342 
5343  explicit input_stream_adapter(std::istream& i)
5344  : is(&i), sb(i.rdbuf())
5345  {}
5346 
5347  // delete because of pointer members
5348  input_stream_adapter(const input_stream_adapter&) = delete;
5349  input_stream_adapter& operator=(input_stream_adapter&) = delete;
5350  input_stream_adapter& operator=(input_stream_adapter&&) = delete;
5351 
5352  input_stream_adapter(input_stream_adapter&& rhs) noexcept
5353  : is(rhs.is), sb(rhs.sb)
5354  {
5355  rhs.is = nullptr;
5356  rhs.sb = nullptr;
5357  }
5358 
5359  // std::istream/std::streambuf use std::char_traits<char>::to_int_type, to
5360  // ensure that std::char_traits<char>::eof() and the character 0xFF do not
5361  // end up as the same value, eg. 0xFFFFFFFF.
5362  std::char_traits<char>::int_type get_character()
5363  {
5364  auto res = sb->sbumpc();
5365  // set eof manually, as we don't use the istream interface.
5366  if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
5367  {
5368  is->clear(is->rdstate() | std::ios::eofbit);
5369  }
5370  return res;
5371  }
5372 
5373  private:
5375  std::istream* is = nullptr;
5376  std::streambuf* sb = nullptr;
5377 };
5378 #endif // JSON_NO_IO
5379 
5380 // General-purpose iterator-based adapter. It might not be as fast as
5381 // theoretically possible for some containers, but it is extremely versatile.
5382 template<typename IteratorType>
5383 class iterator_input_adapter
5384 {
5385  public:
5386  using char_type = typename std::iterator_traits<IteratorType>::value_type;
5387 
5388  iterator_input_adapter(IteratorType first, IteratorType last)
5389  : current(std::move(first)), end(std::move(last))
5390  {}
5391 
5392  typename std::char_traits<char_type>::int_type get_character()
5393  {
5394  if (JSON_HEDLEY_LIKELY(current != end))
5395  {
5396  auto result = std::char_traits<char_type>::to_int_type(*current);
5397  std::advance(current, 1);
5398  return result;
5399  }
5400 
5401  return std::char_traits<char_type>::eof();
5402  }
5403 
5404  private:
5405  IteratorType current;
5406  IteratorType end;
5407 
5408  template<typename BaseInputAdapter, size_t T>
5409  friend struct wide_string_input_helper;
5410 
5411  bool empty() const
5412  {
5413  return current == end;
5414  }
5415 };
5416 
5417 
5418 template<typename BaseInputAdapter, size_t T>
5419 struct wide_string_input_helper;
5420 
5421 template<typename BaseInputAdapter>
5422 struct wide_string_input_helper<BaseInputAdapter, 4>
5423 {
5424  // UTF-32
5425  static void fill_buffer(BaseInputAdapter& input,
5426  std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5427  size_t& utf8_bytes_index,
5428  size_t& utf8_bytes_filled)
5429  {
5430  utf8_bytes_index = 0;
5431 
5432  if (JSON_HEDLEY_UNLIKELY(input.empty()))
5433  {
5434  utf8_bytes[0] = std::char_traits<char>::eof();
5435  utf8_bytes_filled = 1;
5436  }
5437  else
5438  {
5439  // get the current character
5440  const auto wc = input.get_character();
5441 
5442  // UTF-32 to UTF-8 encoding
5443  if (wc < 0x80)
5444  {
5445  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
5446  utf8_bytes_filled = 1;
5447  }
5448  else if (wc <= 0x7FF)
5449  {
5450  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
5451  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5452  utf8_bytes_filled = 2;
5453  }
5454  else if (wc <= 0xFFFF)
5455  {
5456  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
5457  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5458  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5459  utf8_bytes_filled = 3;
5460  }
5461  else if (wc <= 0x10FFFF)
5462  {
5463  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | ((static_cast<unsigned int>(wc) >> 18u) & 0x07u));
5464  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
5465  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5466  utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5467  utf8_bytes_filled = 4;
5468  }
5469  else
5470  {
5471  // unknown character
5472  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
5473  utf8_bytes_filled = 1;
5474  }
5475  }
5476  }
5477 };
5478 
5479 template<typename BaseInputAdapter>
5480 struct wide_string_input_helper<BaseInputAdapter, 2>
5481 {
5482  // UTF-16
5483  static void fill_buffer(BaseInputAdapter& input,
5484  std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5485  size_t& utf8_bytes_index,
5486  size_t& utf8_bytes_filled)
5487  {
5488  utf8_bytes_index = 0;
5489 
5490  if (JSON_HEDLEY_UNLIKELY(input.empty()))
5491  {
5492  utf8_bytes[0] = std::char_traits<char>::eof();
5493  utf8_bytes_filled = 1;
5494  }
5495  else
5496  {
5497  // get the current character
5498  const auto wc = input.get_character();
5499 
5500  // UTF-16 to UTF-8 encoding
5501  if (wc < 0x80)
5502  {
5503  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
5504  utf8_bytes_filled = 1;
5505  }
5506  else if (wc <= 0x7FF)
5507  {
5508  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u)));
5509  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5510  utf8_bytes_filled = 2;
5511  }
5512  else if (0xD800 > wc || wc >= 0xE000)
5513  {
5514  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u)));
5515  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5516  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5517  utf8_bytes_filled = 3;
5518  }
5519  else
5520  {
5521  if (JSON_HEDLEY_UNLIKELY(!input.empty()))
5522  {
5523  const auto wc2 = static_cast<unsigned int>(input.get_character());
5524  const auto charcode = 0x10000u + (((static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
5525  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | (charcode >> 18u));
5526  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 12u) & 0x3Fu));
5527  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 6u) & 0x3Fu));
5528  utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (charcode & 0x3Fu));
5529  utf8_bytes_filled = 4;
5530  }
5531  else
5532  {
5533  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
5534  utf8_bytes_filled = 1;
5535  }
5536  }
5537  }
5538  }
5539 };
5540 
5541 // Wraps another input apdater to convert wide character types into individual bytes.
5542 template<typename BaseInputAdapter, typename WideCharType>
5543 class wide_string_input_adapter
5544 {
5545  public:
5546  using char_type = char;
5547 
5548  wide_string_input_adapter(BaseInputAdapter base)
5549  : base_adapter(base) {}
5550 
5551  typename std::char_traits<char>::int_type get_character() noexcept
5552  {
5553  // check if buffer needs to be filled
5554  if (utf8_bytes_index == utf8_bytes_filled)
5555  {
5556  fill_buffer<sizeof(WideCharType)>();
5557 
5558  JSON_ASSERT(utf8_bytes_filled > 0);
5559  JSON_ASSERT(utf8_bytes_index == 0);
5560  }
5561 
5562  // use buffer
5563  JSON_ASSERT(utf8_bytes_filled > 0);
5564  JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
5565  return utf8_bytes[utf8_bytes_index++];
5566  }
5567 
5568  private:
5569  BaseInputAdapter base_adapter;
5570 
5571  template<size_t T>
5572  void fill_buffer()
5573  {
5574  wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
5575  }
5576 
5578  std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
5579 
5581  std::size_t utf8_bytes_index = 0;
5583  std::size_t utf8_bytes_filled = 0;
5584 };
5585 
5586 
5587 template<typename IteratorType, typename Enable = void>
5588 struct iterator_input_adapter_factory
5589 {
5590  using iterator_type = IteratorType;
5591  using char_type = typename std::iterator_traits<iterator_type>::value_type;
5592  using adapter_type = iterator_input_adapter<iterator_type>;
5593 
5594  static adapter_type create(IteratorType first, IteratorType last)
5595  {
5596  return adapter_type(std::move(first), std::move(last));
5597  }
5598 };
5599 
5600 template<typename T>
5601 struct is_iterator_of_multibyte
5602 {
5603  using value_type = typename std::iterator_traits<T>::value_type;
5604  enum
5605  {
5606  value = sizeof(value_type) > 1
5607  };
5608 };
5609 
5610 template<typename IteratorType>
5611 struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
5612 {
5613  using iterator_type = IteratorType;
5614  using char_type = typename std::iterator_traits<iterator_type>::value_type;
5615  using base_adapter_type = iterator_input_adapter<iterator_type>;
5616  using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
5617 
5618  static adapter_type create(IteratorType first, IteratorType last)
5619  {
5620  return adapter_type(base_adapter_type(std::move(first), std::move(last)));
5621  }
5622 };
5623 
5624 // General purpose iterator-based input
5625 template<typename IteratorType>
5626 typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
5627 {
5628  using factory_type = iterator_input_adapter_factory<IteratorType>;
5629  return factory_type::create(first, last);
5630 }
5631 
5632 // Convenience shorthand from container to iterator
5633 // Enables ADL on begin(container) and end(container)
5634 // Encloses the using declarations in namespace for not to leak them to outside scope
5635 
5636 namespace container_input_adapter_factory_impl
5637 {
5638 
5639 using std::begin;
5640 using std::end;
5641 
5642 template<typename ContainerType, typename Enable = void>
5643 struct container_input_adapter_factory {};
5644 
5645 template<typename ContainerType>
5646 struct container_input_adapter_factory< ContainerType,
5647  void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
5648  {
5649  using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
5650 
5651  static adapter_type create(const ContainerType& container)
5652 {
5653  return input_adapter(begin(container), end(container));
5654 }
5655  };
5656 
5657 } // namespace container_input_adapter_factory_impl
5658 
5659 template<typename ContainerType>
5660 typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(const ContainerType& container)
5661 {
5662  return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
5663 }
5664 
5665 #ifndef JSON_NO_IO
5666 // Special cases with fast paths
5667 inline file_input_adapter input_adapter(std::FILE* file)
5668 {
5669  return file_input_adapter(file);
5670 }
5671 
5672 inline input_stream_adapter input_adapter(std::istream& stream)
5673 {
5674  return input_stream_adapter(stream);
5675 }
5676 
5677 inline input_stream_adapter input_adapter(std::istream&& stream)
5678 {
5679  return input_stream_adapter(stream);
5680 }
5681 #endif // JSON_NO_IO
5682 
5683 using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
5684 
5685 // Null-delimited strings, and the like.
5686 template < typename CharT,
5687  typename std::enable_if <
5688  std::is_pointer<CharT>::value&&
5689  !std::is_array<CharT>::value&&
5690  std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5691  sizeof(typename std::remove_pointer<CharT>::type) == 1,
5692  int >::type = 0 >
5693 contiguous_bytes_input_adapter input_adapter(CharT b)
5694 {
5695  auto length = std::strlen(reinterpret_cast<const char*>(b));
5696  const auto* ptr = reinterpret_cast<const char*>(b);
5697  return input_adapter(ptr, ptr + length);
5698 }
5699 
5700 template<typename T, std::size_t N>
5701 auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
5702 {
5703  return input_adapter(array, array + N);
5704 }
5705 
5706 // This class only handles inputs of input_buffer_adapter type.
5707 // It's required so that expressions like {ptr, len} can be implicitely casted
5708 // to the correct adapter.
5709 class span_input_adapter
5710 {
5711  public:
5712  template < typename CharT,
5713  typename std::enable_if <
5714  std::is_pointer<CharT>::value&&
5715  std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5716  sizeof(typename std::remove_pointer<CharT>::type) == 1,
5717  int >::type = 0 >
5718  span_input_adapter(CharT b, std::size_t l)
5719  : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
5720 
5721  template<class IteratorType,
5722  typename std::enable_if<
5723  std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
5724  int>::type = 0>
5725  span_input_adapter(IteratorType first, IteratorType last)
5726  : ia(input_adapter(first, last)) {}
5727 
5728  contiguous_bytes_input_adapter&& get()
5729  {
5730  return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg)
5731  }
5732 
5733  private:
5734  contiguous_bytes_input_adapter ia;
5735 };
5736 } // namespace detail
5737 } // namespace nlohmann
5738 
5739 // #include <nlohmann/detail/input/json_sax.hpp>
5740 
5741 
5742 #include <cstddef>
5743 #include <string> // string
5744 #include <utility> // move
5745 #include <vector> // vector
5746 
5747 // #include <nlohmann/detail/exceptions.hpp>
5748 
5749 // #include <nlohmann/detail/macro_scope.hpp>
5750 
5751 
5752 namespace nlohmann
5753 {
5754 
5763 template<typename BasicJsonType>
5764 struct json_sax
5765 {
5766  using number_integer_t = typename BasicJsonType::number_integer_t;
5767  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
5768  using number_float_t = typename BasicJsonType::number_float_t;
5769  using string_t = typename BasicJsonType::string_t;
5770  using binary_t = typename BasicJsonType::binary_t;
5771 
5776  virtual bool null() = 0;
5777 
5783  virtual bool boolean(bool val) = 0;
5784 
5790  virtual bool number_integer(number_integer_t val) = 0;
5791 
5797  virtual bool number_unsigned(number_unsigned_t val) = 0;
5798 
5805  virtual bool number_float(number_float_t val, const string_t& s) = 0;
5806 
5813  virtual bool string(string_t& val) = 0;
5814 
5821  virtual bool binary(binary_t& val) = 0;
5822 
5829  virtual bool start_object(std::size_t elements) = 0;
5830 
5837  virtual bool key(string_t& val) = 0;
5838 
5843  virtual bool end_object() = 0;
5844 
5851  virtual bool start_array(std::size_t elements) = 0;
5852 
5857  virtual bool end_array() = 0;
5858 
5866  virtual bool parse_error(std::size_t position,
5867  const std::string& last_token,
5868  const detail::exception& ex) = 0;
5869 
5870  json_sax() = default;
5871  json_sax(const json_sax&) = default;
5872  json_sax(json_sax&&) noexcept = default;
5873  json_sax& operator=(const json_sax&) = default;
5874  json_sax& operator=(json_sax&&) noexcept = default;
5875  virtual ~json_sax() = default;
5876 };
5877 
5878 
5879 namespace detail
5880 {
5894 template<typename BasicJsonType>
5895 class json_sax_dom_parser
5896 {
5897  public:
5898  using number_integer_t = typename BasicJsonType::number_integer_t;
5899  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
5900  using number_float_t = typename BasicJsonType::number_float_t;
5901  using string_t = typename BasicJsonType::string_t;
5902  using binary_t = typename BasicJsonType::binary_t;
5903 
5909  explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)
5910  : root(r), allow_exceptions(allow_exceptions_)
5911  {}
5912 
5913  // make class move-only
5914  json_sax_dom_parser(const json_sax_dom_parser&) = delete;
5915  json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
5916  json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete;
5917  json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
5918  ~json_sax_dom_parser() = default;
5919 
5920  bool null()
5921  {
5922  handle_value(nullptr);
5923  return true;
5924  }
5925 
5926  bool boolean(bool val)
5927  {
5928  handle_value(val);
5929  return true;
5930  }
5931 
5933  {
5934  handle_value(val);
5935  return true;
5936  }
5937 
5939  {
5940  handle_value(val);
5941  return true;
5942  }
5943 
5944  bool number_float(number_float_t val, const string_t& /*unused*/)
5945  {
5946  handle_value(val);
5947  return true;
5948  }
5949 
5950  bool string(string_t& val)
5951  {
5952  handle_value(val);
5953  return true;
5954  }
5955 
5956  bool binary(binary_t& val)
5957  {
5958  handle_value(std::move(val));
5959  return true;
5960  }
5961 
5962  bool start_object(std::size_t len)
5963  {
5964  ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
5965 
5966  if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5967  {
5968  JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
5969  }
5970 
5971  return true;
5972  }
5973 
5974  bool key(string_t& val)
5975  {
5976  // add null at given key and store the reference for later
5977  object_element = &(ref_stack.back()->m_value.object->operator[](val));
5978  return true;
5979  }
5980 
5981  bool end_object()
5982  {
5983  ref_stack.back()->set_parents();
5984  ref_stack.pop_back();
5985  return true;
5986  }
5987 
5988  bool start_array(std::size_t len)
5989  {
5990  ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
5991 
5992  if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5993  {
5994  JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
5995  }
5996 
5997  return true;
5998  }
5999 
6000  bool end_array()
6001  {
6002  ref_stack.back()->set_parents();
6003  ref_stack.pop_back();
6004  return true;
6005  }
6006 
6007  template<class Exception>
6008  bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
6009  const Exception& ex)
6010  {
6011  errored = true;
6012  static_cast<void>(ex);
6013  if (allow_exceptions)
6014  {
6015  JSON_THROW(ex);
6016  }
6017  return false;
6018  }
6019 
6020  constexpr bool is_errored() const
6021  {
6022  return errored;
6023  }
6024 
6025  private:
6032  template<typename Value>
6033 
6034  BasicJsonType* handle_value(Value&& v)
6035  {
6036  if (ref_stack.empty())
6037  {
6038  root = BasicJsonType(std::forward<Value>(v));
6039  return &root;
6040  }
6041 
6042  JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6043 
6044  if (ref_stack.back()->is_array())
6045  {
6046  ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
6047  return &(ref_stack.back()->m_value.array->back());
6048  }
6049 
6050  JSON_ASSERT(ref_stack.back()->is_object());
6051  JSON_ASSERT(object_element);
6052  *object_element = BasicJsonType(std::forward<Value>(v));
6053  return object_element;
6054  }
6055 
6057  BasicJsonType& root;
6059  std::vector<BasicJsonType*> ref_stack {};
6061  BasicJsonType* object_element = nullptr;
6063  bool errored = false;
6065  const bool allow_exceptions = true;
6066 };
6067 
6068 template<typename BasicJsonType>
6069 class json_sax_dom_callback_parser
6070 {
6071  public:
6072  using number_integer_t = typename BasicJsonType::number_integer_t;
6073  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
6074  using number_float_t = typename BasicJsonType::number_float_t;
6075  using string_t = typename BasicJsonType::string_t;
6076  using binary_t = typename BasicJsonType::binary_t;
6077  using parser_callback_t = typename BasicJsonType::parser_callback_t;
6078  using parse_event_t = typename BasicJsonType::parse_event_t;
6079 
6080  json_sax_dom_callback_parser(BasicJsonType& r,
6081  const parser_callback_t cb,
6082  const bool allow_exceptions_ = true)
6083  : root(r), callback(cb), allow_exceptions(allow_exceptions_)
6084  {
6085  keep_stack.push_back(true);
6086  }
6087 
6088  // make class move-only
6089  json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete;
6090  json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
6091  json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete;
6092  json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
6093  ~json_sax_dom_callback_parser() = default;
6094 
6095  bool null()
6096  {
6097  handle_value(nullptr);
6098  return true;
6099  }
6100 
6101  bool boolean(bool val)
6102  {
6103  handle_value(val);
6104  return true;
6105  }
6106 
6108  {
6109  handle_value(val);
6110  return true;
6111  }
6112 
6114  {
6115  handle_value(val);
6116  return true;
6117  }
6118 
6119  bool number_float(number_float_t val, const string_t& /*unused*/)
6120  {
6121  handle_value(val);
6122  return true;
6123  }
6124 
6125  bool string(string_t& val)
6126  {
6127  handle_value(val);
6128  return true;
6129  }
6130 
6131  bool binary(binary_t& val)
6132  {
6133  handle_value(std::move(val));
6134  return true;
6135  }
6136 
6137  bool start_object(std::size_t len)
6138  {
6139  // check callback for object start
6140  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
6141  keep_stack.push_back(keep);
6142 
6143  auto val = handle_value(BasicJsonType::value_t::object, true);
6144  ref_stack.push_back(val.second);
6145 
6146  // check object limit
6147  if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6148  {
6149  JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
6150  }
6151 
6152  return true;
6153  }
6154 
6155  bool key(string_t& val)
6156  {
6157  BasicJsonType k = BasicJsonType(val);
6158 
6159  // check callback for key
6160  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);
6161  key_keep_stack.push_back(keep);
6162 
6163  // add discarded value at given key and store the reference for later
6164  if (keep && ref_stack.back())
6165  {
6166  object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
6167  }
6168 
6169  return true;
6170  }
6171 
6172  bool end_object()
6173  {
6174  if (ref_stack.back())
6175  {
6176  if (!callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
6177  {
6178  // discard object
6179  *ref_stack.back() = discarded;
6180  }
6181  else
6182  {
6183  ref_stack.back()->set_parents();
6184  }
6185  }
6186 
6187  JSON_ASSERT(!ref_stack.empty());
6188  JSON_ASSERT(!keep_stack.empty());
6189  ref_stack.pop_back();
6190  keep_stack.pop_back();
6191 
6192  if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
6193  {
6194  // remove discarded value
6195  for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
6196  {
6197  if (it->is_discarded())
6198  {
6199  ref_stack.back()->erase(it);
6200  break;
6201  }
6202  }
6203  }
6204 
6205  return true;
6206  }
6207 
6208  bool start_array(std::size_t len)
6209  {
6210  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
6211  keep_stack.push_back(keep);
6212 
6213  auto val = handle_value(BasicJsonType::value_t::array, true);
6214  ref_stack.push_back(val.second);
6215 
6216  // check array limit
6217  if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6218  {
6219  JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
6220  }
6221 
6222  return true;
6223  }
6224 
6225  bool end_array()
6226  {
6227  bool keep = true;
6228 
6229  if (ref_stack.back())
6230  {
6231  keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
6232  if (keep)
6233  {
6234  ref_stack.back()->set_parents();
6235  }
6236  else
6237  {
6238  // discard array
6239  *ref_stack.back() = discarded;
6240  }
6241  }
6242 
6243  JSON_ASSERT(!ref_stack.empty());
6244  JSON_ASSERT(!keep_stack.empty());
6245  ref_stack.pop_back();
6246  keep_stack.pop_back();
6247 
6248  // remove discarded value
6249  if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
6250  {
6251  ref_stack.back()->m_value.array->pop_back();
6252  }
6253 
6254  return true;
6255  }
6256 
6257  template<class Exception>
6258  bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
6259  const Exception& ex)
6260  {
6261  errored = true;
6262  static_cast<void>(ex);
6263  if (allow_exceptions)
6264  {
6265  JSON_THROW(ex);
6266  }
6267  return false;
6268  }
6269 
6270  constexpr bool is_errored() const
6271  {
6272  return errored;
6273  }
6274 
6275  private:
6291  template<typename Value>
6292  std::pair<bool, BasicJsonType*> handle_value(Value&& v, const bool skip_callback = false)
6293  {
6294  JSON_ASSERT(!keep_stack.empty());
6295 
6296  // do not handle this value if we know it would be added to a discarded
6297  // container
6298  if (!keep_stack.back())
6299  {
6300  return {false, nullptr};
6301  }
6302 
6303  // create value
6304  auto value = BasicJsonType(std::forward<Value>(v));
6305 
6306  // check callback
6307  const bool keep = skip_callback || callback(static_cast<int>(ref_stack.size()), parse_event_t::value, value);
6308 
6309  // do not handle this value if we just learnt it shall be discarded
6310  if (!keep)
6311  {
6312  return {false, nullptr};
6313  }
6314 
6315  if (ref_stack.empty())
6316  {
6317  root = std::move(value);
6318  return {true, &root};
6319  }
6320 
6321  // skip this value if we already decided to skip the parent
6322  // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
6323  if (!ref_stack.back())
6324  {
6325  return {false, nullptr};
6326  }
6327 
6328  // we now only expect arrays and objects
6329  JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6330 
6331  // array
6332  if (ref_stack.back()->is_array())
6333  {
6334  ref_stack.back()->m_value.array->emplace_back(std::move(value));
6335  return {true, &(ref_stack.back()->m_value.array->back())};
6336  }
6337 
6338  // object
6339  JSON_ASSERT(ref_stack.back()->is_object());
6340  // check if we should store an element for the current key
6341  JSON_ASSERT(!key_keep_stack.empty());
6342  const bool store_element = key_keep_stack.back();
6343  key_keep_stack.pop_back();
6344 
6345  if (!store_element)
6346  {
6347  return {false, nullptr};
6348  }
6349 
6350  JSON_ASSERT(object_element);
6351  *object_element = std::move(value);
6352  return {true, object_element};
6353  }
6354 
6356  BasicJsonType& root;
6358  std::vector<BasicJsonType*> ref_stack {};
6360  std::vector<bool> keep_stack {};
6362  std::vector<bool> key_keep_stack {};
6364  BasicJsonType* object_element = nullptr;
6366  bool errored = false;
6368  const parser_callback_t callback = nullptr;
6370  const bool allow_exceptions = true;
6372  BasicJsonType discarded = BasicJsonType::value_t::discarded;
6373 };
6374 
6375 template<typename BasicJsonType>
6376 class json_sax_acceptor
6377 {
6378  public:
6379  using number_integer_t = typename BasicJsonType::number_integer_t;
6380  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
6381  using number_float_t = typename BasicJsonType::number_float_t;
6382  using string_t = typename BasicJsonType::string_t;
6383  using binary_t = typename BasicJsonType::binary_t;
6384 
6385  bool null()
6386  {
6387  return true;
6388  }
6389 
6390  bool boolean(bool /*unused*/)
6391  {
6392  return true;
6393  }
6394 
6395  bool number_integer(number_integer_t /*unused*/)
6396  {
6397  return true;
6398  }
6399 
6400  bool number_unsigned(number_unsigned_t /*unused*/)
6401  {
6402  return true;
6403  }
6404 
6405  bool number_float(number_float_t /*unused*/, const string_t& /*unused*/)
6406  {
6407  return true;
6408  }
6409 
6410  bool string(string_t& /*unused*/)
6411  {
6412  return true;
6413  }
6414 
6415  bool binary(binary_t& /*unused*/)
6416  {
6417  return true;
6418  }
6419 
6420  bool start_object(std::size_t /*unused*/ = std::size_t(-1))
6421  {
6422  return true;
6423  }
6424 
6425  bool key(string_t& /*unused*/)
6426  {
6427  return true;
6428  }
6429 
6430  bool end_object()
6431  {
6432  return true;
6433  }
6434 
6435  bool start_array(std::size_t /*unused*/ = std::size_t(-1))
6436  {
6437  return true;
6438  }
6439 
6440  bool end_array()
6441  {
6442  return true;
6443  }
6444 
6445  bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& /*unused*/)
6446  {
6447  return false;
6448  }
6449 };
6450 } // namespace detail
6451 
6452 } // namespace nlohmann
6453 
6454 // #include <nlohmann/detail/input/lexer.hpp>
6455 
6456 
6457 #include <array> // array
6458 #include <clocale> // localeconv
6459 #include <cstddef> // size_t
6460 #include <cstdio> // snprintf
6461 #include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull
6462 #include <initializer_list> // initializer_list
6463 #include <string> // char_traits, string
6464 #include <utility> // move
6465 #include <vector> // vector
6466 
6467 // #include <nlohmann/detail/input/input_adapters.hpp>
6468 
6469 // #include <nlohmann/detail/input/position_t.hpp>
6470 
6471 // #include <nlohmann/detail/macro_scope.hpp>
6472 
6473 
6474 namespace nlohmann
6475 {
6476 namespace detail
6477 {
6479 // lexer //
6481 
6482 template<typename BasicJsonType>
6483 class lexer_base
6484 {
6485  public:
6487  enum class token_type
6488  {
6489  uninitialized,
6490  literal_true,
6491  literal_false,
6492  literal_null,
6493  value_string,
6494  value_unsigned,
6495  value_integer,
6496  value_float,
6497  begin_array,
6498  begin_object,
6499  end_array,
6500  end_object,
6501  name_separator,
6502  value_separator,
6503  parse_error,
6504  end_of_input,
6505  literal_or_value
6506  };
6507 
6509 
6510  JSON_HEDLEY_CONST
6511  static const char* token_type_name(const token_type t) noexcept
6512  {
6513  switch (t)
6514  {
6515  case token_type::uninitialized:
6516  return "<uninitialized>";
6517  case token_type::literal_true:
6518  return "true literal";
6519  case token_type::literal_false:
6520  return "false literal";
6521  case token_type::literal_null:
6522  return "null literal";
6523  case token_type::value_string:
6524  return "string literal";
6525  case token_type::value_unsigned:
6526  case token_type::value_integer:
6527  case token_type::value_float:
6528  return "number literal";
6529  case token_type::begin_array:
6530  return "'['";
6531  case token_type::begin_object:
6532  return "'{'";
6533  case token_type::end_array:
6534  return "']'";
6535  case token_type::end_object:
6536  return "'}'";
6537  case token_type::name_separator:
6538  return "':'";
6539  case token_type::value_separator:
6540  return "','";
6541  case token_type::parse_error:
6542  return "<parse error>";
6543  case token_type::end_of_input:
6544  return "end of input";
6545  case token_type::literal_or_value:
6546  return "'[', '{', or a literal";
6547  // LCOV_EXCL_START
6548  default: // catch non-enum values
6549  return "unknown token";
6550  // LCOV_EXCL_STOP
6551  }
6552  }
6553 };
6559 template<typename BasicJsonType, typename InputAdapterType>
6560 class lexer : public lexer_base<BasicJsonType>
6561 {
6562  using number_integer_t = typename BasicJsonType::number_integer_t;
6563  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
6564  using number_float_t = typename BasicJsonType::number_float_t;
6565  using string_t = typename BasicJsonType::string_t;
6566  using char_type = typename InputAdapterType::char_type;
6567  using char_int_type = typename std::char_traits<char_type>::int_type;
6568 
6569  public:
6570  using token_type = typename lexer_base<BasicJsonType>::token_type;
6571 
6572  explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept
6573  : ia(std::move(adapter))
6574  , ignore_comments(ignore_comments_)
6575  , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
6576  {}
6577 
6578  // delete because of pointer members
6579  lexer(const lexer&) = delete;
6580  lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
6581  lexer& operator=(lexer&) = delete;
6582  lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
6583  ~lexer() = default;
6584 
6585  private:
6587  // locales
6589 
6591  JSON_HEDLEY_PURE
6592  static char get_decimal_point() noexcept
6593  {
6594  const auto* loc = localeconv();
6595  JSON_ASSERT(loc != nullptr);
6596  return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point);
6597  }
6598 
6600  // scan functions
6602 
6618  int get_codepoint()
6619  {
6620  // this function only makes sense after reading `\u`
6621  JSON_ASSERT(current == 'u');
6622  int codepoint = 0;
6623 
6624  const auto factors = { 12u, 8u, 4u, 0u };
6625  for (const auto factor : factors)
6626  {
6627  get();
6628 
6629  if (current >= '0' && current <= '9')
6630  {
6631  codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor);
6632  }
6633  else if (current >= 'A' && current <= 'F')
6634  {
6635  codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor);
6636  }
6637  else if (current >= 'a' && current <= 'f')
6638  {
6639  codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor);
6640  }
6641  else
6642  {
6643  return -1;
6644  }
6645  }
6646 
6647  JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6648  return codepoint;
6649  }
6650 
6666  bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
6667  {
6668  JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
6669  add(current);
6670 
6671  for (auto range = ranges.begin(); range != ranges.end(); ++range)
6672  {
6673  get();
6674  if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
6675  {
6676  add(current);
6677  }
6678  else
6679  {
6680  error_message = "invalid string: ill-formed UTF-8 byte";
6681  return false;
6682  }
6683  }
6684 
6685  return true;
6686  }
6687 
6703  token_type scan_string()
6704  {
6705  // reset token_buffer (ignore opening quote)
6706  reset();
6707 
6708  // we entered the function by reading an open quote
6709  JSON_ASSERT(current == '\"');
6710 
6711  while (true)
6712  {
6713  // get next character
6714  switch (get())
6715  {
6716  // end of file while parsing string
6717  case std::char_traits<char_type>::eof():
6718  {
6719  error_message = "invalid string: missing closing quote";
6720  return token_type::parse_error;
6721  }
6722 
6723  // closing quote
6724  case '\"':
6725  {
6726  return token_type::value_string;
6727  }
6728 
6729  // escapes
6730  case '\\':
6731  {
6732  switch (get())
6733  {
6734  // quotation mark
6735  case '\"':
6736  add('\"');
6737  break;
6738  // reverse solidus
6739  case '\\':
6740  add('\\');
6741  break;
6742  // solidus
6743  case '/':
6744  add('/');
6745  break;
6746  // backspace
6747  case 'b':
6748  add('\b');
6749  break;
6750  // form feed
6751  case 'f':
6752  add('\f');
6753  break;
6754  // line feed
6755  case 'n':
6756  add('\n');
6757  break;
6758  // carriage return
6759  case 'r':
6760  add('\r');
6761  break;
6762  // tab
6763  case 't':
6764  add('\t');
6765  break;
6766 
6767  // unicode escapes
6768  case 'u':
6769  {
6770  const int codepoint1 = get_codepoint();
6771  int codepoint = codepoint1; // start with codepoint1
6772 
6773  if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
6774  {
6775  error_message = "invalid string: '\\u' must be followed by 4 hex digits";
6776  return token_type::parse_error;
6777  }
6778 
6779  // check if code point is a high surrogate
6780  if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
6781  {
6782  // expect next \uxxxx entry
6783  if (JSON_HEDLEY_LIKELY(get() == '\\' && get() == 'u'))
6784  {
6785  const int codepoint2 = get_codepoint();
6786 
6787  if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
6788  {
6789  error_message = "invalid string: '\\u' must be followed by 4 hex digits";
6790  return token_type::parse_error;
6791  }
6792 
6793  // check if codepoint2 is a low surrogate
6794  if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
6795  {
6796  // overwrite codepoint
6797  codepoint = static_cast<int>(
6798  // high surrogate occupies the most significant 22 bits
6799  (static_cast<unsigned int>(codepoint1) << 10u)
6800  // low surrogate occupies the least significant 15 bits
6801  + static_cast<unsigned int>(codepoint2)
6802  // there is still the 0xD800, 0xDC00 and 0x10000 noise
6803  // in the result so we have to subtract with:
6804  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
6805  - 0x35FDC00u);
6806  }
6807  else
6808  {
6809  error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6810  return token_type::parse_error;
6811  }
6812  }
6813  else
6814  {
6815  error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6816  return token_type::parse_error;
6817  }
6818  }
6819  else
6820  {
6821  if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
6822  {
6823  error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
6824  return token_type::parse_error;
6825  }
6826  }
6827 
6828  // result of the above calculation yields a proper codepoint
6829  JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
6830 
6831  // translate codepoint into bytes
6832  if (codepoint < 0x80)
6833  {
6834  // 1-byte characters: 0xxxxxxx (ASCII)
6835  add(static_cast<char_int_type>(codepoint));
6836  }
6837  else if (codepoint <= 0x7FF)
6838  {
6839  // 2-byte characters: 110xxxxx 10xxxxxx
6840  add(static_cast<char_int_type>(0xC0u | (static_cast<unsigned int>(codepoint) >> 6u)));
6841  add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
6842  }
6843  else if (codepoint <= 0xFFFF)
6844  {
6845  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
6846  add(static_cast<char_int_type>(0xE0u | (static_cast<unsigned int>(codepoint) >> 12u)));
6847  add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6848  add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
6849  }
6850  else
6851  {
6852  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
6853  add(static_cast<char_int_type>(0xF0u | (static_cast<unsigned int>(codepoint) >> 18u)));
6854  add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
6855  add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6856  add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
6857  }
6858 
6859  break;
6860  }
6861 
6862  // other characters after escape
6863  default:
6864  error_message = "invalid string: forbidden character after backslash";
6865  return token_type::parse_error;
6866  }
6867 
6868  break;
6869  }
6870 
6871  // invalid control characters
6872  case 0x00:
6873  {
6874  error_message = "invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
6875  return token_type::parse_error;
6876  }
6877 
6878  case 0x01:
6879  {
6880  error_message = "invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
6881  return token_type::parse_error;
6882  }
6883 
6884  case 0x02:
6885  {
6886  error_message = "invalid string: control character U+0002 (STX) must be escaped to \\u0002";
6887  return token_type::parse_error;
6888  }
6889 
6890  case 0x03:
6891  {
6892  error_message = "invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
6893  return token_type::parse_error;
6894  }
6895 
6896  case 0x04:
6897  {
6898  error_message = "invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
6899  return token_type::parse_error;
6900  }
6901 
6902  case 0x05:
6903  {
6904  error_message = "invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
6905  return token_type::parse_error;
6906  }
6907 
6908  case 0x06:
6909  {
6910  error_message = "invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
6911  return token_type::parse_error;
6912  }
6913 
6914  case 0x07:
6915  {
6916  error_message = "invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
6917  return token_type::parse_error;
6918  }
6919 
6920  case 0x08:
6921  {
6922  error_message = "invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
6923  return token_type::parse_error;
6924  }
6925 
6926  case 0x09:
6927  {
6928  error_message = "invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
6929  return token_type::parse_error;
6930  }
6931 
6932  case 0x0A:
6933  {
6934  error_message = "invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
6935  return token_type::parse_error;
6936  }
6937 
6938  case 0x0B:
6939  {
6940  error_message = "invalid string: control character U+000B (VT) must be escaped to \\u000B";
6941  return token_type::parse_error;
6942  }
6943 
6944  case 0x0C:
6945  {
6946  error_message = "invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
6947  return token_type::parse_error;
6948  }
6949 
6950  case 0x0D:
6951  {
6952  error_message = "invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
6953  return token_type::parse_error;
6954  }
6955 
6956  case 0x0E:
6957  {
6958  error_message = "invalid string: control character U+000E (SO) must be escaped to \\u000E";
6959  return token_type::parse_error;
6960  }
6961 
6962  case 0x0F:
6963  {
6964  error_message = "invalid string: control character U+000F (SI) must be escaped to \\u000F";
6965  return token_type::parse_error;
6966  }
6967 
6968  case 0x10:
6969  {
6970  error_message = "invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
6971  return token_type::parse_error;
6972  }
6973 
6974  case 0x11:
6975  {
6976  error_message = "invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
6977  return token_type::parse_error;
6978  }
6979 
6980  case 0x12:
6981  {
6982  error_message = "invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
6983  return token_type::parse_error;
6984  }
6985 
6986  case 0x13:
6987  {
6988  error_message = "invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
6989  return token_type::parse_error;
6990  }
6991 
6992  case 0x14:
6993  {
6994  error_message = "invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
6995  return token_type::parse_error;
6996  }
6997 
6998  case 0x15:
6999  {
7000  error_message = "invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7001  return token_type::parse_error;
7002  }
7003 
7004  case 0x16:
7005  {
7006  error_message = "invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7007  return token_type::parse_error;
7008  }
7009 
7010  case 0x17:
7011  {
7012  error_message = "invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7013  return token_type::parse_error;
7014  }
7015 
7016  case 0x18:
7017  {
7018  error_message = "invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7019  return token_type::parse_error;
7020  }
7021 
7022  case 0x19:
7023  {
7024  error_message = "invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7025  return token_type::parse_error;
7026  }
7027 
7028  case 0x1A:
7029  {
7030  error_message = "invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7031  return token_type::parse_error;
7032  }
7033 
7034  case 0x1B:
7035  {
7036  error_message = "invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7037  return token_type::parse_error;
7038  }
7039 
7040  case 0x1C:
7041  {
7042  error_message = "invalid string: control character U+001C (FS) must be escaped to \\u001C";
7043  return token_type::parse_error;
7044  }
7045 
7046  case 0x1D:
7047  {
7048  error_message = "invalid string: control character U+001D (GS) must be escaped to \\u001D";
7049  return token_type::parse_error;
7050  }
7051 
7052  case 0x1E:
7053  {
7054  error_message = "invalid string: control character U+001E (RS) must be escaped to \\u001E";
7055  return token_type::parse_error;
7056  }
7057 
7058  case 0x1F:
7059  {
7060  error_message = "invalid string: control character U+001F (US) must be escaped to \\u001F";
7061  return token_type::parse_error;
7062  }
7063 
7064  // U+0020..U+007F (except U+0022 (quote) and U+005C (backspace))
7065  case 0x20:
7066  case 0x21:
7067  case 0x23:
7068  case 0x24:
7069  case 0x25:
7070  case 0x26:
7071  case 0x27:
7072  case 0x28:
7073  case 0x29:
7074  case 0x2A:
7075  case 0x2B:
7076  case 0x2C:
7077  case 0x2D:
7078  case 0x2E:
7079  case 0x2F:
7080  case 0x30:
7081  case 0x31:
7082  case 0x32:
7083  case 0x33:
7084  case 0x34:
7085  case 0x35:
7086  case 0x36:
7087  case 0x37:
7088  case 0x38:
7089  case 0x39:
7090  case 0x3A:
7091  case 0x3B:
7092  case 0x3C:
7093  case 0x3D:
7094  case 0x3E:
7095  case 0x3F:
7096  case 0x40:
7097  case 0x41:
7098  case 0x42:
7099  case 0x43:
7100  case 0x44:
7101  case 0x45:
7102  case 0x46:
7103  case 0x47:
7104  case 0x48:
7105  case 0x49:
7106  case 0x4A:
7107  case 0x4B:
7108  case 0x4C:
7109  case 0x4D:
7110  case 0x4E:
7111  case 0x4F:
7112  case 0x50:
7113  case 0x51:
7114  case 0x52:
7115  case 0x53:
7116  case 0x54:
7117  case 0x55:
7118  case 0x56:
7119  case 0x57:
7120  case 0x58:
7121  case 0x59:
7122  case 0x5A:
7123  case 0x5B:
7124  case 0x5D:
7125  case 0x5E:
7126  case 0x5F:
7127  case 0x60:
7128  case 0x61:
7129  case 0x62:
7130  case 0x63:
7131  case 0x64:
7132  case 0x65:
7133  case 0x66:
7134  case 0x67:
7135  case 0x68:
7136  case 0x69:
7137  case 0x6A:
7138  case 0x6B:
7139  case 0x6C:
7140  case 0x6D:
7141  case 0x6E:
7142  case 0x6F:
7143  case 0x70:
7144  case 0x71:
7145  case 0x72:
7146  case 0x73:
7147  case 0x74:
7148  case 0x75:
7149  case 0x76:
7150  case 0x77:
7151  case 0x78:
7152  case 0x79:
7153  case 0x7A:
7154  case 0x7B:
7155  case 0x7C:
7156  case 0x7D:
7157  case 0x7E:
7158  case 0x7F:
7159  {
7160  add(current);
7161  break;
7162  }
7163 
7164  // U+0080..U+07FF: bytes C2..DF 80..BF
7165  case 0xC2:
7166  case 0xC3:
7167  case 0xC4:
7168  case 0xC5:
7169  case 0xC6:
7170  case 0xC7:
7171  case 0xC8:
7172  case 0xC9:
7173  case 0xCA:
7174  case 0xCB:
7175  case 0xCC:
7176  case 0xCD:
7177  case 0xCE:
7178  case 0xCF:
7179  case 0xD0:
7180  case 0xD1:
7181  case 0xD2:
7182  case 0xD3:
7183  case 0xD4:
7184  case 0xD5:
7185  case 0xD6:
7186  case 0xD7:
7187  case 0xD8:
7188  case 0xD9:
7189  case 0xDA:
7190  case 0xDB:
7191  case 0xDC:
7192  case 0xDD:
7193  case 0xDE:
7194  case 0xDF:
7195  {
7196  if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
7197  {
7198  return token_type::parse_error;
7199  }
7200  break;
7201  }
7202 
7203  // U+0800..U+0FFF: bytes E0 A0..BF 80..BF
7204  case 0xE0:
7205  {
7206  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7207  {
7208  return token_type::parse_error;
7209  }
7210  break;
7211  }
7212 
7213  // U+1000..U+CFFF: bytes E1..EC 80..BF 80..BF
7214  // U+E000..U+FFFF: bytes EE..EF 80..BF 80..BF
7215  case 0xE1:
7216  case 0xE2:
7217  case 0xE3:
7218  case 0xE4:
7219  case 0xE5:
7220  case 0xE6:
7221  case 0xE7:
7222  case 0xE8:
7223  case 0xE9:
7224  case 0xEA:
7225  case 0xEB:
7226  case 0xEC:
7227  case 0xEE:
7228  case 0xEF:
7229  {
7230  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7231  {
7232  return token_type::parse_error;
7233  }
7234  break;
7235  }
7236 
7237  // U+D000..U+D7FF: bytes ED 80..9F 80..BF
7238  case 0xED:
7239  {
7240  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7241  {
7242  return token_type::parse_error;
7243  }
7244  break;
7245  }
7246 
7247  // U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
7248  case 0xF0:
7249  {
7250  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7251  {
7252  return token_type::parse_error;
7253  }
7254  break;
7255  }
7256 
7257  // U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF
7258  case 0xF1:
7259  case 0xF2:
7260  case 0xF3:
7261  {
7262  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7263  {
7264  return token_type::parse_error;
7265  }
7266  break;
7267  }
7268 
7269  // U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
7270  case 0xF4:
7271  {
7272  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7273  {
7274  return token_type::parse_error;
7275  }
7276  break;
7277  }
7278 
7279  // remaining bytes (80..C1 and F5..FF) are ill-formed
7280  default:
7281  {
7282  error_message = "invalid string: ill-formed UTF-8 byte";
7283  return token_type::parse_error;
7284  }
7285  }
7286  }
7287  }
7288 
7293  bool scan_comment()
7294  {
7295  switch (get())
7296  {
7297  // single-line comments skip input until a newline or EOF is read
7298  case '/':
7299  {
7300  while (true)
7301  {
7302  switch (get())
7303  {
7304  case '\n':
7305  case '\r':
7306  case std::char_traits<char_type>::eof():
7307  case '\0':
7308  return true;
7309 
7310  default:
7311  break;
7312  }
7313  }
7314  }
7315 
7316  // multi-line comments skip input until */ is read
7317  case '*':
7318  {
7319  while (true)
7320  {
7321  switch (get())
7322  {
7323  case std::char_traits<char_type>::eof():
7324  case '\0':
7325  {
7326  error_message = "invalid comment; missing closing '*/'";
7327  return false;
7328  }
7329 
7330  case '*':
7331  {
7332  switch (get())
7333  {
7334  case '/':
7335  return true;
7336 
7337  default:
7338  {
7339  unget();
7340  continue;
7341  }
7342  }
7343  }
7344 
7345  default:
7346  continue;
7347  }
7348  }
7349  }
7350 
7351  // unexpected character after reading '/'
7352  default:
7353  {
7354  error_message = "invalid comment; expecting '/' or '*' after '/'";
7355  return false;
7356  }
7357  }
7358  }
7359 
7360  JSON_HEDLEY_NON_NULL(2)
7361  static void strtof(float& f, const char* str, char** endptr) noexcept
7362  {
7363  f = std::strtof(str, endptr);
7364  }
7365 
7366  JSON_HEDLEY_NON_NULL(2)
7367  static void strtof(double& f, const char* str, char** endptr) noexcept
7368  {
7369  f = std::strtod(str, endptr);
7370  }
7371 
7372  JSON_HEDLEY_NON_NULL(2)
7373  static void strtof(long double& f, const char* str, char** endptr) noexcept
7374  {
7375  f = std::strtold(str, endptr);
7376  }
7377 
7418  token_type scan_number() // lgtm [cpp/use-of-goto]
7419  {
7420  // reset token_buffer to store the number's bytes
7421  reset();
7422 
7423  // the type of the parsed number; initially set to unsigned; will be
7424  // changed if minus sign, decimal point or exponent is read
7425  token_type number_type = token_type::value_unsigned;
7426 
7427  // state (init): we just found out we need to scan a number
7428  switch (current)
7429  {
7430  case '-':
7431  {
7432  add(current);
7433  goto scan_number_minus;
7434  }
7435 
7436  case '0':
7437  {
7438  add(current);
7439  goto scan_number_zero;
7440  }
7441 
7442  case '1':
7443  case '2':
7444  case '3':
7445  case '4':
7446  case '5':
7447  case '6':
7448  case '7':
7449  case '8':
7450  case '9':
7451  {
7452  add(current);
7453  goto scan_number_any1;
7454  }
7455 
7456  // all other characters are rejected outside scan_number()
7457  default: // LCOV_EXCL_LINE
7458  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
7459  }
7460 
7461 scan_number_minus:
7462  // state: we just parsed a leading minus sign
7463  number_type = token_type::value_integer;
7464  switch (get())
7465  {
7466  case '0':
7467  {
7468  add(current);
7469  goto scan_number_zero;
7470  }
7471 
7472  case '1':
7473  case '2':
7474  case '3':
7475  case '4':
7476  case '5':
7477  case '6':
7478  case '7':
7479  case '8':
7480  case '9':
7481  {
7482  add(current);
7483  goto scan_number_any1;
7484  }
7485 
7486  default:
7487  {
7488  error_message = "invalid number; expected digit after '-'";
7489  return token_type::parse_error;
7490  }
7491  }
7492 
7493 scan_number_zero:
7494  // state: we just parse a zero (maybe with a leading minus sign)
7495  switch (get())
7496  {
7497  case '.':
7498  {
7499  add(decimal_point_char);
7500  goto scan_number_decimal1;
7501  }
7502 
7503  case 'e':
7504  case 'E':
7505  {
7506  add(current);
7507  goto scan_number_exponent;
7508  }
7509 
7510  default:
7511  goto scan_number_done;
7512  }
7513 
7514 scan_number_any1:
7515  // state: we just parsed a number 0-9 (maybe with a leading minus sign)
7516  switch (get())
7517  {
7518  case '0':
7519  case '1':
7520  case '2':
7521  case '3':
7522  case '4':
7523  case '5':
7524  case '6':
7525  case '7':
7526  case '8':
7527  case '9':
7528  {
7529  add(current);
7530  goto scan_number_any1;
7531  }
7532 
7533  case '.':
7534  {
7535  add(decimal_point_char);
7536  goto scan_number_decimal1;
7537  }
7538 
7539  case 'e':
7540  case 'E':
7541  {
7542  add(current);
7543  goto scan_number_exponent;
7544  }
7545 
7546  default:
7547  goto scan_number_done;
7548  }
7549 
7550 scan_number_decimal1:
7551  // state: we just parsed a decimal point
7552  number_type = token_type::value_float;
7553  switch (get())
7554  {
7555  case '0':
7556  case '1':
7557  case '2':
7558  case '3':
7559  case '4':
7560  case '5':
7561  case '6':
7562  case '7':
7563  case '8':
7564  case '9':
7565  {
7566  add(current);
7567  goto scan_number_decimal2;
7568  }
7569 
7570  default:
7571  {
7572  error_message = "invalid number; expected digit after '.'";
7573  return token_type::parse_error;
7574  }
7575  }
7576 
7577 scan_number_decimal2:
7578  // we just parsed at least one number after a decimal point
7579  switch (get())
7580  {
7581  case '0':
7582  case '1':
7583  case '2':
7584  case '3':
7585  case '4':
7586  case '5':
7587  case '6':
7588  case '7':
7589  case '8':
7590  case '9':
7591  {
7592  add(current);
7593  goto scan_number_decimal2;
7594  }
7595 
7596  case 'e':
7597  case 'E':
7598  {
7599  add(current);
7600  goto scan_number_exponent;
7601  }
7602 
7603  default:
7604  goto scan_number_done;
7605  }
7606 
7607 scan_number_exponent:
7608  // we just parsed an exponent
7609  number_type = token_type::value_float;
7610  switch (get())
7611  {
7612  case '+':
7613  case '-':
7614  {
7615  add(current);
7616  goto scan_number_sign;
7617  }
7618 
7619  case '0':
7620  case '1':
7621  case '2':
7622  case '3':
7623  case '4':
7624  case '5':
7625  case '6':
7626  case '7':
7627  case '8':
7628  case '9':
7629  {
7630  add(current);
7631  goto scan_number_any2;
7632  }
7633 
7634  default:
7635  {
7636  error_message =
7637  "invalid number; expected '+', '-', or digit after exponent";
7638  return token_type::parse_error;
7639  }
7640  }
7641 
7642 scan_number_sign:
7643  // we just parsed an exponent sign
7644  switch (get())
7645  {
7646  case '0':
7647  case '1':
7648  case '2':
7649  case '3':
7650  case '4':
7651  case '5':
7652  case '6':
7653  case '7':
7654  case '8':
7655  case '9':
7656  {
7657  add(current);
7658  goto scan_number_any2;
7659  }
7660 
7661  default:
7662  {
7663  error_message = "invalid number; expected digit after exponent sign";
7664  return token_type::parse_error;
7665  }
7666  }
7667 
7668 scan_number_any2:
7669  // we just parsed a number after the exponent or exponent sign
7670  switch (get())
7671  {
7672  case '0':
7673  case '1':
7674  case '2':
7675  case '3':
7676  case '4':
7677  case '5':
7678  case '6':
7679  case '7':
7680  case '8':
7681  case '9':
7682  {
7683  add(current);
7684  goto scan_number_any2;
7685  }
7686 
7687  default:
7688  goto scan_number_done;
7689  }
7690 
7691 scan_number_done:
7692  // unget the character after the number (we only read it to know that
7693  // we are done scanning a number)
7694  unget();
7695 
7696  char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
7697  errno = 0;
7698 
7699  // try to parse integers first and fall back to floats
7700  if (number_type == token_type::value_unsigned)
7701  {
7702  const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
7703 
7704  // we checked the number format before
7705  JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7706 
7707  if (errno == 0)
7708  {
7709  value_unsigned = static_cast<number_unsigned_t>(x);
7710  if (value_unsigned == x)
7711  {
7712  return token_type::value_unsigned;
7713  }
7714  }
7715  }
7716  else if (number_type == token_type::value_integer)
7717  {
7718  const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
7719 
7720  // we checked the number format before
7721  JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7722 
7723  if (errno == 0)
7724  {
7725  value_integer = static_cast<number_integer_t>(x);
7726  if (value_integer == x)
7727  {
7728  return token_type::value_integer;
7729  }
7730  }
7731  }
7732 
7733  // this code is reached if we parse a floating-point number or if an
7734  // integer conversion above failed
7735  strtof(value_float, token_buffer.data(), &endptr);
7736 
7737  // we checked the number format before
7738  JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7739 
7740  return token_type::value_float;
7741  }
7742 
7748  JSON_HEDLEY_NON_NULL(2)
7749  token_type scan_literal(const char_type* literal_text, const std::size_t length,
7750  token_type return_type)
7751  {
7752  JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
7753  for (std::size_t i = 1; i < length; ++i)
7754  {
7755  if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
7756  {
7757  error_message = "invalid literal";
7758  return token_type::parse_error;
7759  }
7760  }
7761  return return_type;
7762  }
7763 
7765  // input management
7767 
7769  void reset() noexcept
7770  {
7771  token_buffer.clear();
7772  token_string.clear();
7773  token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7774  }
7775 
7776  /*
7777  @brief get next character from the input
7778 
7779  This function provides the interface to the used input adapter. It does
7780  not throw in case the input reached EOF, but returns a
7781  `std::char_traits<char>::eof()` in that case. Stores the scanned characters
7782  for use in error messages.
7783 
7784  @return character read from the input
7785  */
7786  char_int_type get()
7787  {
7788  ++position.chars_read_total;
7789  ++position.chars_read_current_line;
7790 
7791  if (next_unget)
7792  {
7793  // just reset the next_unget variable and work with current
7794  next_unget = false;
7795  }
7796  else
7797  {
7798  current = ia.get_character();
7799  }
7800 
7801  if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7802  {
7803  token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7804  }
7805 
7806  if (current == '\n')
7807  {
7808  ++position.lines_read;
7809  position.chars_read_current_line = 0;
7810  }
7811 
7812  return current;
7813  }
7814 
7823  void unget()
7824  {
7825  next_unget = true;
7826 
7827  --position.chars_read_total;
7828 
7829  // in case we "unget" a newline, we have to also decrement the lines_read
7830  if (position.chars_read_current_line == 0)
7831  {
7832  if (position.lines_read > 0)
7833  {
7834  --position.lines_read;
7835  }
7836  }
7837  else
7838  {
7839  --position.chars_read_current_line;
7840  }
7841 
7842  if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7843  {
7844  JSON_ASSERT(!token_string.empty());
7845  token_string.pop_back();
7846  }
7847  }
7848 
7850  void add(char_int_type c)
7851  {
7852  token_buffer.push_back(static_cast<typename string_t::value_type>(c));
7853  }
7854 
7855  public:
7857  // value getters
7859 
7861  constexpr number_integer_t get_number_integer() const noexcept
7862  {
7863  return value_integer;
7864  }
7865 
7867  constexpr number_unsigned_t get_number_unsigned() const noexcept
7868  {
7869  return value_unsigned;
7870  }
7871 
7873  constexpr number_float_t get_number_float() const noexcept
7874  {
7875  return value_float;
7876  }
7877 
7879  string_t& get_string()
7880  {
7881  return token_buffer;
7882  }
7883 
7885  // diagnostics
7887 
7889  constexpr position_t get_position() const noexcept
7890  {
7891  return position;
7892  }
7893 
7897  std::string get_token_string() const
7898  {
7899  // escape control characters
7900  std::string result;
7901  for (const auto c : token_string)
7902  {
7903  if (static_cast<unsigned char>(c) <= '\x1F')
7904  {
7905  // escape control characters
7906  std::array<char, 9> cs{{}};
7907  (std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
7908  result += cs.data();
7909  }
7910  else
7911  {
7912  // add character as is
7913  result.push_back(static_cast<std::string::value_type>(c));
7914  }
7915  }
7916 
7917  return result;
7918  }
7919 
7921 
7922  constexpr const char* get_error_message() const noexcept
7923  {
7924  return error_message;
7925  }
7926 
7928  // actual scanner
7930 
7935  bool skip_bom()
7936  {
7937  if (get() == 0xEF)
7938  {
7939  // check if we completely parse the BOM
7940  return get() == 0xBB && get() == 0xBF;
7941  }
7942 
7943  // the first character is not the beginning of the BOM; unget it to
7944  // process is later
7945  unget();
7946  return true;
7947  }
7948 
7949  void skip_whitespace()
7950  {
7951  do
7952  {
7953  get();
7954  }
7955  while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
7956  }
7957 
7958  token_type scan()
7959  {
7960  // initially, skip the BOM
7961  if (position.chars_read_total == 0 && !skip_bom())
7962  {
7963  error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given";
7964  return token_type::parse_error;
7965  }
7966 
7967  // read next character and ignore whitespace
7968  skip_whitespace();
7969 
7970  // ignore comments
7971  while (ignore_comments && current == '/')
7972  {
7973  if (!scan_comment())
7974  {
7975  return token_type::parse_error;
7976  }
7977 
7978  // skip following whitespace
7979  skip_whitespace();
7980  }
7981 
7982  switch (current)
7983  {
7984  // structural characters
7985  case '[':
7986  return token_type::begin_array;
7987  case ']':
7988  return token_type::end_array;
7989  case '{':
7990  return token_type::begin_object;
7991  case '}':
7992  return token_type::end_object;
7993  case ':':
7994  return token_type::name_separator;
7995  case ',':
7996  return token_type::value_separator;
7997 
7998  // literals
7999  case 't':
8000  {
8001  std::array<char_type, 4> true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}};
8002  return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8003  }
8004  case 'f':
8005  {
8006  std::array<char_type, 5> false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}};
8007  return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8008  }
8009  case 'n':
8010  {
8011  std::array<char_type, 4> null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}};
8012  return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8013  }
8014 
8015  // string
8016  case '\"':
8017  return scan_string();
8018 
8019  // number
8020  case '-':
8021  case '0':
8022  case '1':
8023  case '2':
8024  case '3':
8025  case '4':
8026  case '5':
8027  case '6':
8028  case '7':
8029  case '8':
8030  case '9':
8031  return scan_number();
8032 
8033  // end of input (the null byte is needed when parsing from
8034  // string literals)
8035  case '\0':
8036  case std::char_traits<char_type>::eof():
8037  return token_type::end_of_input;
8038 
8039  // error
8040  default:
8041  error_message = "invalid literal";
8042  return token_type::parse_error;
8043  }
8044  }
8045 
8046  private:
8048  InputAdapterType ia;
8049 
8051  const bool ignore_comments = false;
8052 
8054  char_int_type current = std::char_traits<char_type>::eof();
8055 
8057  bool next_unget = false;
8058 
8060  position_t position {};
8061 
8063  std::vector<char_type> token_string {};
8064 
8066  string_t token_buffer {};
8067 
8069  const char* error_message = "";
8070 
8071  // number values
8072  number_integer_t value_integer = 0;
8073  number_unsigned_t value_unsigned = 0;
8074  number_float_t value_float = 0;
8075 
8077  const char_int_type decimal_point_char = '.';
8078 };
8079 } // namespace detail
8080 } // namespace nlohmann
8081 
8082 // #include <nlohmann/detail/macro_scope.hpp>
8083 
8084 // #include <nlohmann/detail/meta/is_sax.hpp>
8085 
8086 
8087 #include <cstdint> // size_t
8088 #include <utility> // declval
8089 #include <string> // string
8090 
8091 // #include <nlohmann/detail/meta/detected.hpp>
8092 
8093 // #include <nlohmann/detail/meta/type_traits.hpp>
8094 
8095 
8096 namespace nlohmann
8097 {
8098 namespace detail
8099 {
8100 template<typename T>
8101 using null_function_t = decltype(std::declval<T&>().null());
8102 
8103 template<typename T>
8104 using boolean_function_t =
8105  decltype(std::declval<T&>().boolean(std::declval<bool>()));
8106 
8107 template<typename T, typename Integer>
8108 using number_integer_function_t =
8109  decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
8110 
8111 template<typename T, typename Unsigned>
8112 using number_unsigned_function_t =
8113  decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
8114 
8115 template<typename T, typename Float, typename String>
8116 using number_float_function_t = decltype(std::declval<T&>().number_float(
8117  std::declval<Float>(), std::declval<const String&>()));
8118 
8119 template<typename T, typename String>
8120 using string_function_t =
8121  decltype(std::declval<T&>().string(std::declval<String&>()));
8122 
8123 template<typename T, typename Binary>
8124 using binary_function_t =
8125  decltype(std::declval<T&>().binary(std::declval<Binary&>()));
8126 
8127 template<typename T>
8128 using start_object_function_t =
8129  decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
8130 
8131 template<typename T, typename String>
8132 using key_function_t =
8133  decltype(std::declval<T&>().key(std::declval<String&>()));
8134 
8135 template<typename T>
8136 using end_object_function_t = decltype(std::declval<T&>().end_object());
8137 
8138 template<typename T>
8139 using start_array_function_t =
8140  decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
8141 
8142 template<typename T>
8143 using end_array_function_t = decltype(std::declval<T&>().end_array());
8144 
8145 template<typename T, typename Exception>
8146 using parse_error_function_t = decltype(std::declval<T&>().parse_error(
8147  std::declval<std::size_t>(), std::declval<const std::string&>(),
8148  std::declval<const Exception&>()));
8149 
8150 template<typename SAX, typename BasicJsonType>
8151 struct is_sax
8152 {
8153  private:
8154  static_assert(is_basic_json<BasicJsonType>::value,
8155  "BasicJsonType must be of type basic_json<...>");
8156 
8157  using number_integer_t = typename BasicJsonType::number_integer_t;
8158  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
8159  using number_float_t = typename BasicJsonType::number_float_t;
8160  using string_t = typename BasicJsonType::string_t;
8161  using binary_t = typename BasicJsonType::binary_t;
8162  using exception_t = typename BasicJsonType::exception;
8163 
8164  public:
8165  static constexpr bool value =
8166  is_detected_exact<bool, null_function_t, SAX>::value &&
8167  is_detected_exact<bool, boolean_function_t, SAX>::value &&
8168  is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
8169  is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
8170  is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
8171  is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
8172  is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
8173  is_detected_exact<bool, start_object_function_t, SAX>::value &&
8174  is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
8175  is_detected_exact<bool, end_object_function_t, SAX>::value &&
8176  is_detected_exact<bool, start_array_function_t, SAX>::value &&
8177  is_detected_exact<bool, end_array_function_t, SAX>::value &&
8178  is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
8179 };
8180 
8181 template<typename SAX, typename BasicJsonType>
8182 struct is_sax_static_asserts
8183 {
8184  private:
8185  static_assert(is_basic_json<BasicJsonType>::value,
8186  "BasicJsonType must be of type basic_json<...>");
8187 
8188  using number_integer_t = typename BasicJsonType::number_integer_t;
8189  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
8190  using number_float_t = typename BasicJsonType::number_float_t;
8191  using string_t = typename BasicJsonType::string_t;
8192  using binary_t = typename BasicJsonType::binary_t;
8193  using exception_t = typename BasicJsonType::exception;
8194 
8195  public:
8196  static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
8197  "Missing/invalid function: bool null()");
8198  static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8199  "Missing/invalid function: bool boolean(bool)");
8200  static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8201  "Missing/invalid function: bool boolean(bool)");
8202  static_assert(
8203  is_detected_exact<bool, number_integer_function_t, SAX,
8204  number_integer_t>::value,
8205  "Missing/invalid function: bool number_integer(number_integer_t)");
8206  static_assert(
8207  is_detected_exact<bool, number_unsigned_function_t, SAX,
8208  number_unsigned_t>::value,
8209  "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
8210  static_assert(is_detected_exact<bool, number_float_function_t, SAX,
8211  number_float_t, string_t>::value,
8212  "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
8213  static_assert(
8214  is_detected_exact<bool, string_function_t, SAX, string_t>::value,
8215  "Missing/invalid function: bool string(string_t&)");
8216  static_assert(
8217  is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
8218  "Missing/invalid function: bool binary(binary_t&)");
8219  static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
8220  "Missing/invalid function: bool start_object(std::size_t)");
8221  static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
8222  "Missing/invalid function: bool key(string_t&)");
8223  static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
8224  "Missing/invalid function: bool end_object()");
8225  static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
8226  "Missing/invalid function: bool start_array(std::size_t)");
8227  static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
8228  "Missing/invalid function: bool end_array()");
8229  static_assert(
8230  is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
8231  "Missing/invalid function: bool parse_error(std::size_t, const "
8232  "std::string&, const exception&)");
8233 };
8234 } // namespace detail
8235 } // namespace nlohmann
8236 
8237 // #include <nlohmann/detail/value_t.hpp>
8238 
8239 
8240 namespace nlohmann
8241 {
8242 namespace detail
8243 {
8244 
8246 enum class cbor_tag_handler_t
8247 {
8248  error,
8249  ignore
8250 };
8251 
8259 static inline bool little_endianess(int num = 1) noexcept
8260 {
8261  return *reinterpret_cast<char*>(&num) == 1;
8262 }
8263 
8264 
8266 // binary reader //
8268 
8272 template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>>
8273 class binary_reader
8274 {
8275  using number_integer_t = typename BasicJsonType::number_integer_t;
8276  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
8277  using number_float_t = typename BasicJsonType::number_float_t;
8278  using string_t = typename BasicJsonType::string_t;
8279  using binary_t = typename BasicJsonType::binary_t;
8280  using json_sax_t = SAX;
8281  using char_type = typename InputAdapterType::char_type;
8282  using char_int_type = typename std::char_traits<char_type>::int_type;
8283 
8284  public:
8290  explicit binary_reader(InputAdapterType&& adapter) noexcept : ia(std::move(adapter))
8291  {
8292  (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
8293  }
8294 
8295  // make class move-only
8296  binary_reader(const binary_reader&) = delete;
8297  binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
8298  binary_reader& operator=(const binary_reader&) = delete;
8299  binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
8300  ~binary_reader() = default;
8301 
8310  JSON_HEDLEY_NON_NULL(3)
8311  bool sax_parse(const input_format_t format,
8312  json_sax_t* sax_,
8313  const bool strict = true,
8314  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
8315  {
8316  sax = sax_;
8317  bool result = false;
8318 
8319  switch (format)
8320  {
8321  case input_format_t::bson:
8322  result = parse_bson_internal();
8323  break;
8324 
8325  case input_format_t::cbor:
8326  result = parse_cbor_internal(true, tag_handler);
8327  break;
8328 
8329  case input_format_t::msgpack:
8330  result = parse_msgpack_internal();
8331  break;
8332 
8333  case input_format_t::ubjson:
8334  result = parse_ubjson_internal();
8335  break;
8336 
8337  default: // LCOV_EXCL_LINE
8338  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
8339  }
8340 
8341  // strict mode: next byte must be EOF
8342  if (result && strict)
8343  {
8344  if (format == input_format_t::ubjson)
8345  {
8346  get_ignore_noop();
8347  }
8348  else
8349  {
8350  get();
8351  }
8352 
8353  if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
8354  {
8355  return sax->parse_error(chars_read, get_token_string(),
8356  parse_error::create(110, chars_read, exception_message(format, "expected end of input; last byte: 0x" + get_token_string(), "value"), BasicJsonType()));
8357  }
8358  }
8359 
8360  return result;
8361  }
8362 
8363  private:
8365  // BSON //
8367 
8372  bool parse_bson_internal()
8373  {
8374  std::int32_t document_size{};
8375  get_number<std::int32_t, true>(input_format_t::bson, document_size);
8376 
8377  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
8378  {
8379  return false;
8380  }
8381 
8382  if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/false)))
8383  {
8384  return false;
8385  }
8386 
8387  return sax->end_object();
8388  }
8389 
8397  bool get_bson_cstr(string_t& result)
8398  {
8399  auto out = std::back_inserter(result);
8400  while (true)
8401  {
8402  get();
8403  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "cstring")))
8404  {
8405  return false;
8406  }
8407  if (current == 0x00)
8408  {
8409  return true;
8410  }
8411  *out++ = static_cast<typename string_t::value_type>(current);
8412  }
8413  }
8414 
8426  template<typename NumberType>
8427  bool get_bson_string(const NumberType len, string_t& result)
8428  {
8429  if (JSON_HEDLEY_UNLIKELY(len < 1))
8430  {
8431  auto last_token = get_token_string();
8432  return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "string length must be at least 1, is " + std::to_string(len), "string"), BasicJsonType()));
8433  }
8434 
8435  return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != std::char_traits<char_type>::eof();
8436  }
8437 
8447  template<typename NumberType>
8448  bool get_bson_binary(const NumberType len, binary_t& result)
8449  {
8450  if (JSON_HEDLEY_UNLIKELY(len < 0))
8451  {
8452  auto last_token = get_token_string();
8453  return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "byte array length cannot be negative, is " + std::to_string(len), "binary"), BasicJsonType()));
8454  }
8455 
8456  // All BSON binary values have a subtype
8457  std::uint8_t subtype{};
8458  get_number<std::uint8_t>(input_format_t::bson, subtype);
8459  result.set_subtype(subtype);
8460 
8461  return get_binary(input_format_t::bson, len, result);
8462  }
8463 
8474  bool parse_bson_element_internal(const char_int_type element_type,
8475  const std::size_t element_type_parse_position)
8476  {
8477  switch (element_type)
8478  {
8479  case 0x01: // double
8480  {
8481  double number{};
8482  return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), "");
8483  }
8484 
8485  case 0x02: // string
8486  {
8487  std::int32_t len{};
8488  string_t value;
8489  return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
8490  }
8491 
8492  case 0x03: // object
8493  {
8494  return parse_bson_internal();
8495  }
8496 
8497  case 0x04: // array
8498  {
8499  return parse_bson_array();
8500  }
8501 
8502  case 0x05: // binary
8503  {
8504  std::int32_t len{};
8505  binary_t value;
8506  return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
8507  }
8508 
8509  case 0x08: // boolean
8510  {
8511  return sax->boolean(get() != 0);
8512  }
8513 
8514  case 0x0A: // null
8515  {
8516  return sax->null();
8517  }
8518 
8519  case 0x10: // int32
8520  {
8521  std::int32_t value{};
8522  return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8523  }
8524 
8525  case 0x12: // int64
8526  {
8527  std::int64_t value{};
8528  return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8529  }
8530 
8531  default: // anything else not supported (yet)
8532  {
8533  std::array<char, 3> cr{{}};
8534  (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
8535  return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data()), BasicJsonType()));
8536  }
8537  }
8538  }
8539 
8552  bool parse_bson_element_list(const bool is_array)
8553  {
8554  string_t key;
8555 
8556  while (auto element_type = get())
8557  {
8558  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "element list")))
8559  {
8560  return false;
8561  }
8562 
8563  const std::size_t element_type_parse_position = chars_read;
8564  if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
8565  {
8566  return false;
8567  }
8568 
8569  if (!is_array && !sax->key(key))
8570  {
8571  return false;
8572  }
8573 
8574  if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
8575  {
8576  return false;
8577  }
8578 
8579  // get_bson_cstr only appends
8580  key.clear();
8581  }
8582 
8583  return true;
8584  }
8585 
8590  bool parse_bson_array()
8591  {
8592  std::int32_t document_size{};
8593  get_number<std::int32_t, true>(input_format_t::bson, document_size);
8594 
8595  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
8596  {
8597  return false;
8598  }
8599 
8600  if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/true)))
8601  {
8602  return false;
8603  }
8604 
8605  return sax->end_array();
8606  }
8607 
8609  // CBOR //
8611 
8620  bool parse_cbor_internal(const bool get_char,
8621  const cbor_tag_handler_t tag_handler)
8622  {
8623  switch (get_char ? get() : current)
8624  {
8625  // EOF
8626  case std::char_traits<char_type>::eof():
8627  return unexpect_eof(input_format_t::cbor, "value");
8628 
8629  // Integer 0x00..0x17 (0..23)
8630  case 0x00:
8631  case 0x01:
8632  case 0x02:
8633  case 0x03:
8634  case 0x04:
8635  case 0x05:
8636  case 0x06:
8637  case 0x07:
8638  case 0x08:
8639  case 0x09:
8640  case 0x0A:
8641  case 0x0B:
8642  case 0x0C:
8643  case 0x0D:
8644  case 0x0E:
8645  case 0x0F:
8646  case 0x10:
8647  case 0x11:
8648  case 0x12:
8649  case 0x13:
8650  case 0x14:
8651  case 0x15:
8652  case 0x16:
8653  case 0x17:
8654  return sax->number_unsigned(static_cast<number_unsigned_t>(current));
8655 
8656  case 0x18: // Unsigned integer (one-byte uint8_t follows)
8657  {
8658  std::uint8_t number{};
8659  return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8660  }
8661 
8662  case 0x19: // Unsigned integer (two-byte uint16_t follows)
8663  {
8664  std::uint16_t number{};
8665  return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8666  }
8667 
8668  case 0x1A: // Unsigned integer (four-byte uint32_t follows)
8669  {
8670  std::uint32_t number{};
8671  return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8672  }
8673 
8674  case 0x1B: // Unsigned integer (eight-byte uint64_t follows)
8675  {
8676  std::uint64_t number{};
8677  return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8678  }
8679 
8680  // Negative integer -1-0x00..-1-0x17 (-1..-24)
8681  case 0x20:
8682  case 0x21:
8683  case 0x22:
8684  case 0x23:
8685  case 0x24:
8686  case 0x25:
8687  case 0x26:
8688  case 0x27:
8689  case 0x28:
8690  case 0x29:
8691  case 0x2A:
8692  case 0x2B:
8693  case 0x2C:
8694  case 0x2D:
8695  case 0x2E:
8696  case 0x2F:
8697  case 0x30:
8698  case 0x31:
8699  case 0x32:
8700  case 0x33:
8701  case 0x34:
8702  case 0x35:
8703  case 0x36:
8704  case 0x37:
8705  return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current));
8706 
8707  case 0x38: // Negative integer (one-byte uint8_t follows)
8708  {
8709  std::uint8_t number{};
8710  return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
8711  }
8712 
8713  case 0x39: // Negative integer -1-n (two-byte uint16_t follows)
8714  {
8715  std::uint16_t number{};
8716  return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
8717  }
8718 
8719  case 0x3A: // Negative integer -1-n (four-byte uint32_t follows)
8720  {
8721  std::uint32_t number{};
8722  return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
8723  }
8724 
8725  case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows)
8726  {
8727  std::uint64_t number{};
8728  return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1)
8729  - static_cast<number_integer_t>(number));
8730  }
8731 
8732  // Binary data (0x00..0x17 bytes follow)
8733  case 0x40:
8734  case 0x41:
8735  case 0x42:
8736  case 0x43:
8737  case 0x44:
8738  case 0x45:
8739  case 0x46:
8740  case 0x47:
8741  case 0x48:
8742  case 0x49:
8743  case 0x4A:
8744  case 0x4B:
8745  case 0x4C:
8746  case 0x4D:
8747  case 0x4E:
8748  case 0x4F:
8749  case 0x50:
8750  case 0x51:
8751  case 0x52:
8752  case 0x53:
8753  case 0x54:
8754  case 0x55:
8755  case 0x56:
8756  case 0x57:
8757  case 0x58: // Binary data (one-byte uint8_t for n follows)
8758  case 0x59: // Binary data (two-byte uint16_t for n follow)
8759  case 0x5A: // Binary data (four-byte uint32_t for n follow)
8760  case 0x5B: // Binary data (eight-byte uint64_t for n follow)
8761  case 0x5F: // Binary data (indefinite length)
8762  {
8763  binary_t b;
8764  return get_cbor_binary(b) && sax->binary(b);
8765  }
8766 
8767  // UTF-8 string (0x00..0x17 bytes follow)
8768  case 0x60:
8769  case 0x61:
8770  case 0x62:
8771  case 0x63:
8772  case 0x64:
8773  case 0x65:
8774  case 0x66:
8775  case 0x67:
8776  case 0x68:
8777  case 0x69:
8778  case 0x6A:
8779  case 0x6B:
8780  case 0x6C:
8781  case 0x6D:
8782  case 0x6E:
8783  case 0x6F:
8784  case 0x70:
8785  case 0x71:
8786  case 0x72:
8787  case 0x73:
8788  case 0x74:
8789  case 0x75:
8790  case 0x76:
8791  case 0x77:
8792  case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
8793  case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
8794  case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
8795  case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
8796  case 0x7F: // UTF-8 string (indefinite length)
8797  {
8798  string_t s;
8799  return get_cbor_string(s) && sax->string(s);
8800  }
8801 
8802  // array (0x00..0x17 data items follow)
8803  case 0x80:
8804  case 0x81:
8805  case 0x82:
8806  case 0x83:
8807  case 0x84:
8808  case 0x85:
8809  case 0x86:
8810  case 0x87:
8811  case 0x88:
8812  case 0x89:
8813  case 0x8A:
8814  case 0x8B:
8815  case 0x8C:
8816  case 0x8D:
8817  case 0x8E:
8818  case 0x8F:
8819  case 0x90:
8820  case 0x91:
8821  case 0x92:
8822  case 0x93:
8823  case 0x94:
8824  case 0x95:
8825  case 0x96:
8826  case 0x97:
8827  return get_cbor_array(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8828 
8829  case 0x98: // array (one-byte uint8_t for n follows)
8830  {
8831  std::uint8_t len{};
8832  return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
8833  }
8834 
8835  case 0x99: // array (two-byte uint16_t for n follow)
8836  {
8837  std::uint16_t len{};
8838  return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
8839  }
8840 
8841  case 0x9A: // array (four-byte uint32_t for n follow)
8842  {
8843  std::uint32_t len{};
8844  return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
8845  }
8846 
8847  case 0x9B: // array (eight-byte uint64_t for n follow)
8848  {
8849  std::uint64_t len{};
8850  return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
8851  }
8852 
8853  case 0x9F: // array (indefinite length)
8854  return get_cbor_array(std::size_t(-1), tag_handler);
8855 
8856  // map (0x00..0x17 pairs of data items follow)
8857  case 0xA0:
8858  case 0xA1:
8859  case 0xA2:
8860  case 0xA3:
8861  case 0xA4:
8862  case 0xA5:
8863  case 0xA6:
8864  case 0xA7:
8865  case 0xA8:
8866  case 0xA9:
8867  case 0xAA:
8868  case 0xAB:
8869  case 0xAC:
8870  case 0xAD:
8871  case 0xAE:
8872  case 0xAF:
8873  case 0xB0:
8874  case 0xB1:
8875  case 0xB2:
8876  case 0xB3:
8877  case 0xB4:
8878  case 0xB5:
8879  case 0xB6:
8880  case 0xB7:
8881  return get_cbor_object(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8882 
8883  case 0xB8: // map (one-byte uint8_t for n follows)
8884  {
8885  std::uint8_t len{};
8886  return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
8887  }
8888 
8889  case 0xB9: // map (two-byte uint16_t for n follow)
8890  {
8891  std::uint16_t len{};
8892  return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
8893  }
8894 
8895  case 0xBA: // map (four-byte uint32_t for n follow)
8896  {
8897  std::uint32_t len{};
8898  return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
8899  }
8900 
8901  case 0xBB: // map (eight-byte uint64_t for n follow)
8902  {
8903  std::uint64_t len{};
8904  return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
8905  }
8906 
8907  case 0xBF: // map (indefinite length)
8908  return get_cbor_object(std::size_t(-1), tag_handler);
8909 
8910  case 0xC6: // tagged item
8911  case 0xC7:
8912  case 0xC8:
8913  case 0xC9:
8914  case 0xCA:
8915  case 0xCB:
8916  case 0xCC:
8917  case 0xCD:
8918  case 0xCE:
8919  case 0xCF:
8920  case 0xD0:
8921  case 0xD1:
8922  case 0xD2:
8923  case 0xD3:
8924  case 0xD4:
8925  case 0xD8: // tagged item (1 bytes follow)
8926  case 0xD9: // tagged item (2 bytes follow)
8927  case 0xDA: // tagged item (4 bytes follow)
8928  case 0xDB: // tagged item (8 bytes follow)
8929  {
8930  switch (tag_handler)
8931  {
8932  case cbor_tag_handler_t::error:
8933  {
8934  auto last_token = get_token_string();
8935  return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
8936  }
8937 
8938  case cbor_tag_handler_t::ignore:
8939  {
8940  switch (current)
8941  {
8942  case 0xD8:
8943  {
8944  std::uint8_t len{};
8945  get_number(input_format_t::cbor, len);
8946  break;
8947  }
8948  case 0xD9:
8949  {
8950  std::uint16_t len{};
8951  get_number(input_format_t::cbor, len);
8952  break;
8953  }
8954  case 0xDA:
8955  {
8956  std::uint32_t len{};
8957  get_number(input_format_t::cbor, len);
8958  break;
8959  }
8960  case 0xDB:
8961  {
8962  std::uint64_t len{};
8963  get_number(input_format_t::cbor, len);
8964  break;
8965  }
8966  default:
8967  break;
8968  }
8969  return parse_cbor_internal(true, tag_handler);
8970  }
8971 
8972  default: // LCOV_EXCL_LINE
8973  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
8974  return false; // LCOV_EXCL_LINE
8975  }
8976  }
8977 
8978  case 0xF4: // false
8979  return sax->boolean(false);
8980 
8981  case 0xF5: // true
8982  return sax->boolean(true);
8983 
8984  case 0xF6: // null
8985  return sax->null();
8986 
8987  case 0xF9: // Half-Precision Float (two-byte IEEE 754)
8988  {
8989  const auto byte1_raw = get();
8990  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number")))
8991  {
8992  return false;
8993  }
8994  const auto byte2_raw = get();
8995  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number")))
8996  {
8997  return false;
8998  }
8999 
9000  const auto byte1 = static_cast<unsigned char>(byte1_raw);
9001  const auto byte2 = static_cast<unsigned char>(byte2_raw);
9002 
9003  // code from RFC 7049, Appendix D, Figure 3:
9004  // As half-precision floating-point numbers were only added
9005  // to IEEE 754 in 2008, today's programming platforms often
9006  // still only have limited support for them. It is very
9007  // easy to include at least decoding support for them even
9008  // without such support. An example of a small decoder for
9009  // half-precision floating-point numbers in the C language
9010  // is shown in Fig. 3.
9011  const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2);
9012  const double val = [&half]
9013  {
9014  const int exp = (half >> 10u) & 0x1Fu;
9015  const unsigned int mant = half & 0x3FFu;
9016  JSON_ASSERT(0 <= exp&& exp <= 32);
9017  JSON_ASSERT(mant <= 1024);
9018  switch (exp)
9019  {
9020  case 0:
9021  return std::ldexp(mant, -24);
9022  case 31:
9023  return (mant == 0)
9024  ? std::numeric_limits<double>::infinity()
9025  : std::numeric_limits<double>::quiet_NaN();
9026  default:
9027  return std::ldexp(mant + 1024, exp - 25);
9028  }
9029  }();
9030  return sax->number_float((half & 0x8000u) != 0
9031  ? static_cast<number_float_t>(-val)
9032  : static_cast<number_float_t>(val), "");
9033  }
9034 
9035  case 0xFA: // Single-Precision Float (four-byte IEEE 754)
9036  {
9037  float number{};
9038  return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), "");
9039  }
9040 
9041  case 0xFB: // Double-Precision Float (eight-byte IEEE 754)
9042  {
9043  double number{};
9044  return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), "");
9045  }
9046 
9047  default: // anything else (0xFF is handled inside the other types)
9048  {
9049  auto last_token = get_token_string();
9050  return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
9051  }
9052  }
9053  }
9054 
9066  bool get_cbor_string(string_t& result)
9067  {
9068  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
9069  {
9070  return false;
9071  }
9072 
9073  switch (current)
9074  {
9075  // UTF-8 string (0x00..0x17 bytes follow)
9076  case 0x60:
9077  case 0x61:
9078  case 0x62:
9079  case 0x63:
9080  case 0x64:
9081  case 0x65:
9082  case 0x66:
9083  case 0x67:
9084  case 0x68:
9085  case 0x69:
9086  case 0x6A:
9087  case 0x6B:
9088  case 0x6C:
9089  case 0x6D:
9090  case 0x6E:
9091  case 0x6F:
9092  case 0x70:
9093  case 0x71:
9094  case 0x72:
9095  case 0x73:
9096  case 0x74:
9097  case 0x75:
9098  case 0x76:
9099  case 0x77:
9100  {
9101  return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
9102  }
9103 
9104  case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
9105  {
9106  std::uint8_t len{};
9107  return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9108  }
9109 
9110  case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
9111  {
9112  std::uint16_t len{};
9113  return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9114  }
9115 
9116  case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
9117  {
9118  std::uint32_t len{};
9119  return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9120  }
9121 
9122  case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
9123  {
9124  std::uint64_t len{};
9125  return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9126  }
9127 
9128  case 0x7F: // UTF-8 string (indefinite length)
9129  {
9130  while (get() != 0xFF)
9131  {
9132  string_t chunk;
9133  if (!get_cbor_string(chunk))
9134  {
9135  return false;
9136  }
9137  result.append(chunk);
9138  }
9139  return true;
9140  }
9141 
9142  default:
9143  {
9144  auto last_token = get_token_string();
9145  return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_token, "string"), BasicJsonType()));
9146  }
9147  }
9148  }
9149 
9161  bool get_cbor_binary(binary_t& result)
9162  {
9163  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary")))
9164  {
9165  return false;
9166  }
9167 
9168  switch (current)
9169  {
9170  // Binary data (0x00..0x17 bytes follow)
9171  case 0x40:
9172  case 0x41:
9173  case 0x42:
9174  case 0x43:
9175  case 0x44:
9176  case 0x45:
9177  case 0x46:
9178  case 0x47:
9179  case 0x48:
9180  case 0x49:
9181  case 0x4A:
9182  case 0x4B:
9183  case 0x4C:
9184  case 0x4D:
9185  case 0x4E:
9186  case 0x4F:
9187  case 0x50:
9188  case 0x51:
9189  case 0x52:
9190  case 0x53:
9191  case 0x54:
9192  case 0x55:
9193  case 0x56:
9194  case 0x57:
9195  {
9196  return get_binary(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
9197  }
9198 
9199  case 0x58: // Binary data (one-byte uint8_t for n follows)
9200  {
9201  std::uint8_t len{};
9202  return get_number(input_format_t::cbor, len) &&
9203  get_binary(input_format_t::cbor, len, result);
9204  }
9205 
9206  case 0x59: // Binary data (two-byte uint16_t for n follow)
9207  {
9208  std::uint16_t len{};
9209  return get_number(input_format_t::cbor, len) &&
9210  get_binary(input_format_t::cbor, len, result);
9211  }
9212 
9213  case 0x5A: // Binary data (four-byte uint32_t for n follow)
9214  {
9215  std::uint32_t len{};
9216  return get_number(input_format_t::cbor, len) &&
9217  get_binary(input_format_t::cbor, len, result);
9218  }
9219 
9220  case 0x5B: // Binary data (eight-byte uint64_t for n follow)
9221  {
9222  std::uint64_t len{};
9223  return get_number(input_format_t::cbor, len) &&
9224  get_binary(input_format_t::cbor, len, result);
9225  }
9226 
9227  case 0x5F: // Binary data (indefinite length)
9228  {
9229  while (get() != 0xFF)
9230  {
9231  binary_t chunk;
9232  if (!get_cbor_binary(chunk))
9233  {
9234  return false;
9235  }
9236  result.insert(result.end(), chunk.begin(), chunk.end());
9237  }
9238  return true;
9239  }
9240 
9241  default:
9242  {
9243  auto last_token = get_token_string();
9244  return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x" + last_token, "binary"), BasicJsonType()));
9245  }
9246  }
9247  }
9248 
9255  bool get_cbor_array(const std::size_t len,
9256  const cbor_tag_handler_t tag_handler)
9257  {
9258  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9259  {
9260  return false;
9261  }
9262 
9263  if (len != std::size_t(-1))
9264  {
9265  for (std::size_t i = 0; i < len; ++i)
9266  {
9267  if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
9268  {
9269  return false;
9270  }
9271  }
9272  }
9273  else
9274  {
9275  while (get() != 0xFF)
9276  {
9277  if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(false, tag_handler)))
9278  {
9279  return false;
9280  }
9281  }
9282  }
9283 
9284  return sax->end_array();
9285  }
9286 
9293  bool get_cbor_object(const std::size_t len,
9294  const cbor_tag_handler_t tag_handler)
9295  {
9296  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9297  {
9298  return false;
9299  }
9300 
9301  if (len != 0)
9302  {
9303  string_t key;
9304  if (len != std::size_t(-1))
9305  {
9306  for (std::size_t i = 0; i < len; ++i)
9307  {
9308  get();
9309  if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9310  {
9311  return false;
9312  }
9313 
9314  if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
9315  {
9316  return false;
9317  }
9318  key.clear();
9319  }
9320  }
9321  else
9322  {
9323  while (get() != 0xFF)
9324  {
9325  if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9326  {
9327  return false;
9328  }
9329 
9330  if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
9331  {
9332  return false;
9333  }
9334  key.clear();
9335  }
9336  }
9337  }
9338 
9339  return sax->end_object();
9340  }
9341 
9343  // MsgPack //
9345 
9349  bool parse_msgpack_internal()
9350  {
9351  switch (get())
9352  {
9353  // EOF
9354  case std::char_traits<char_type>::eof():
9355  return unexpect_eof(input_format_t::msgpack, "value");
9356 
9357  // positive fixint
9358  case 0x00:
9359  case 0x01:
9360  case 0x02:
9361  case 0x03:
9362  case 0x04:
9363  case 0x05:
9364  case 0x06:
9365  case 0x07:
9366  case 0x08:
9367  case 0x09:
9368  case 0x0A:
9369  case 0x0B:
9370  case 0x0C:
9371  case 0x0D:
9372  case 0x0E:
9373  case 0x0F:
9374  case 0x10:
9375  case 0x11:
9376  case 0x12:
9377  case 0x13:
9378  case 0x14:
9379  case 0x15:
9380  case 0x16:
9381  case 0x17:
9382  case 0x18:
9383  case 0x19:
9384  case 0x1A:
9385  case 0x1B:
9386  case 0x1C:
9387  case 0x1D:
9388  case 0x1E:
9389  case 0x1F:
9390  case 0x20:
9391  case 0x21:
9392  case 0x22:
9393  case 0x23:
9394  case 0x24:
9395  case 0x25:
9396  case 0x26:
9397  case 0x27:
9398  case 0x28:
9399  case 0x29:
9400  case 0x2A:
9401  case 0x2B:
9402  case 0x2C:
9403  case 0x2D:
9404  case 0x2E:
9405  case 0x2F:
9406  case 0x30:
9407  case 0x31:
9408  case 0x32:
9409  case 0x33:
9410  case 0x34:
9411  case 0x35:
9412  case 0x36:
9413  case 0x37:
9414  case 0x38:
9415  case 0x39:
9416  case 0x3A:
9417  case 0x3B:
9418  case 0x3C:
9419  case 0x3D:
9420  case 0x3E:
9421  case 0x3F:
9422  case 0x40:
9423  case 0x41:
9424  case 0x42:
9425  case 0x43:
9426  case 0x44:
9427  case 0x45:
9428  case 0x46:
9429  case 0x47:
9430  case 0x48:
9431  case 0x49:
9432  case 0x4A:
9433  case 0x4B:
9434  case 0x4C:
9435  case 0x4D:
9436  case 0x4E:
9437  case 0x4F:
9438  case 0x50:
9439  case 0x51:
9440  case 0x52:
9441  case 0x53:
9442  case 0x54:
9443  case 0x55:
9444  case 0x56:
9445  case 0x57:
9446  case 0x58:
9447  case 0x59:
9448  case 0x5A:
9449  case 0x5B:
9450  case 0x5C:
9451  case 0x5D:
9452  case 0x5E:
9453  case 0x5F:
9454  case 0x60:
9455  case 0x61:
9456  case 0x62:
9457  case 0x63:
9458  case 0x64:
9459  case 0x65:
9460  case 0x66:
9461  case 0x67:
9462  case 0x68:
9463  case 0x69:
9464  case 0x6A:
9465  case 0x6B:
9466  case 0x6C:
9467  case 0x6D:
9468  case 0x6E:
9469  case 0x6F:
9470  case 0x70:
9471  case 0x71:
9472  case 0x72:
9473  case 0x73:
9474  case 0x74:
9475  case 0x75:
9476  case 0x76:
9477  case 0x77:
9478  case 0x78:
9479  case 0x79:
9480  case 0x7A:
9481  case 0x7B:
9482  case 0x7C:
9483  case 0x7D:
9484  case 0x7E:
9485  case 0x7F:
9486  return sax->number_unsigned(static_cast<number_unsigned_t>(current));
9487 
9488  // fixmap
9489  case 0x80:
9490  case 0x81:
9491  case 0x82:
9492  case 0x83:
9493  case 0x84:
9494  case 0x85:
9495  case 0x86:
9496  case 0x87:
9497  case 0x88:
9498  case 0x89:
9499  case 0x8A:
9500  case 0x8B:
9501  case 0x8C:
9502  case 0x8D:
9503  case 0x8E:
9504  case 0x8F:
9505  return get_msgpack_object(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
9506 
9507  // fixarray
9508  case 0x90:
9509  case 0x91:
9510  case 0x92:
9511  case 0x93:
9512  case 0x94:
9513  case 0x95:
9514  case 0x96:
9515  case 0x97:
9516  case 0x98:
9517  case 0x99:
9518  case 0x9A:
9519  case 0x9B:
9520  case 0x9C:
9521  case 0x9D:
9522  case 0x9E:
9523  case 0x9F:
9524  return get_msgpack_array(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
9525 
9526  // fixstr
9527  case 0xA0:
9528  case 0xA1:
9529  case 0xA2:
9530  case 0xA3:
9531  case 0xA4:
9532  case 0xA5:
9533  case 0xA6:
9534  case 0xA7:
9535  case 0xA8:
9536  case 0xA9:
9537  case 0xAA:
9538  case 0xAB:
9539  case 0xAC:
9540  case 0xAD:
9541  case 0xAE:
9542  case 0xAF:
9543  case 0xB0:
9544  case 0xB1:
9545  case 0xB2:
9546  case 0xB3:
9547  case 0xB4:
9548  case 0xB5:
9549  case 0xB6:
9550  case 0xB7:
9551  case 0xB8:
9552  case 0xB9:
9553  case 0xBA:
9554  case 0xBB:
9555  case 0xBC:
9556  case 0xBD:
9557  case 0xBE:
9558  case 0xBF:
9559  case 0xD9: // str 8
9560  case 0xDA: // str 16
9561  case 0xDB: // str 32
9562  {
9563  string_t s;
9564  return get_msgpack_string(s) && sax->string(s);
9565  }
9566 
9567  case 0xC0: // nil
9568  return sax->null();
9569 
9570  case 0xC2: // false
9571  return sax->boolean(false);
9572 
9573  case 0xC3: // true
9574  return sax->boolean(true);
9575 
9576  case 0xC4: // bin 8
9577  case 0xC5: // bin 16
9578  case 0xC6: // bin 32
9579  case 0xC7: // ext 8
9580  case 0xC8: // ext 16
9581  case 0xC9: // ext 32
9582  case 0xD4: // fixext 1
9583  case 0xD5: // fixext 2
9584  case 0xD6: // fixext 4
9585  case 0xD7: // fixext 8
9586  case 0xD8: // fixext 16
9587  {
9588  binary_t b;
9589  return get_msgpack_binary(b) && sax->binary(b);
9590  }
9591 
9592  case 0xCA: // float 32
9593  {
9594  float number{};
9595  return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), "");
9596  }
9597 
9598  case 0xCB: // float 64
9599  {
9600  double number{};
9601  return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), "");
9602  }
9603 
9604  case 0xCC: // uint 8
9605  {
9606  std::uint8_t number{};
9607  return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9608  }
9609 
9610  case 0xCD: // uint 16
9611  {
9612  std::uint16_t number{};
9613  return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9614  }
9615 
9616  case 0xCE: // uint 32
9617  {
9618  std::uint32_t number{};
9619  return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9620  }
9621 
9622  case 0xCF: // uint 64
9623  {
9624  std::uint64_t number{};
9625  return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9626  }
9627 
9628  case 0xD0: // int 8
9629  {
9630  std::int8_t number{};
9631  return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9632  }
9633 
9634  case 0xD1: // int 16
9635  {
9636  std::int16_t number{};
9637  return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9638  }
9639 
9640  case 0xD2: // int 32
9641  {
9642  std::int32_t number{};
9643  return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9644  }
9645 
9646  case 0xD3: // int 64
9647  {
9648  std::int64_t number{};
9649  return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9650  }
9651 
9652  case 0xDC: // array 16
9653  {
9654  std::uint16_t len{};
9655  return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len));
9656  }
9657 
9658  case 0xDD: // array 32
9659  {
9660  std::uint32_t len{};
9661  return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len));
9662  }
9663 
9664  case 0xDE: // map 16
9665  {
9666  std::uint16_t len{};
9667  return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len));
9668  }
9669 
9670  case 0xDF: // map 32
9671  {
9672  std::uint32_t len{};
9673  return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len));
9674  }
9675 
9676  // negative fixint
9677  case 0xE0:
9678  case 0xE1:
9679  case 0xE2:
9680  case 0xE3:
9681  case 0xE4:
9682  case 0xE5:
9683  case 0xE6:
9684  case 0xE7:
9685  case 0xE8:
9686  case 0xE9:
9687  case 0xEA:
9688  case 0xEB:
9689  case 0xEC:
9690  case 0xED:
9691  case 0xEE:
9692  case 0xEF:
9693  case 0xF0:
9694  case 0xF1:
9695  case 0xF2:
9696  case 0xF3:
9697  case 0xF4:
9698  case 0xF5:
9699  case 0xF6:
9700  case 0xF7:
9701  case 0xF8:
9702  case 0xF9:
9703  case 0xFA:
9704  case 0xFB:
9705  case 0xFC:
9706  case 0xFD:
9707  case 0xFE:
9708  case 0xFF:
9709  return sax->number_integer(static_cast<std::int8_t>(current));
9710 
9711  default: // anything else
9712  {
9713  auto last_token = get_token_string();
9714  return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
9715  }
9716  }
9717  }
9718 
9729  bool get_msgpack_string(string_t& result)
9730  {
9731  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack, "string")))
9732  {
9733  return false;
9734  }
9735 
9736  switch (current)
9737  {
9738  // fixstr
9739  case 0xA0:
9740  case 0xA1:
9741  case 0xA2:
9742  case 0xA3:
9743  case 0xA4:
9744  case 0xA5:
9745  case 0xA6:
9746  case 0xA7:
9747  case 0xA8:
9748  case 0xA9:
9749  case 0xAA:
9750  case 0xAB:
9751  case 0xAC:
9752  case 0xAD:
9753  case 0xAE:
9754  case 0xAF:
9755  case 0xB0:
9756  case 0xB1:
9757  case 0xB2:
9758  case 0xB3:
9759  case 0xB4:
9760  case 0xB5:
9761  case 0xB6:
9762  case 0xB7:
9763  case 0xB8:
9764  case 0xB9:
9765  case 0xBA:
9766  case 0xBB:
9767  case 0xBC:
9768  case 0xBD:
9769  case 0xBE:
9770  case 0xBF:
9771  {
9772  return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result);
9773  }
9774 
9775  case 0xD9: // str 8
9776  {
9777  std::uint8_t len{};
9778  return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9779  }
9780 
9781  case 0xDA: // str 16
9782  {
9783  std::uint16_t len{};
9784  return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9785  }
9786 
9787  case 0xDB: // str 32
9788  {
9789  std::uint32_t len{};
9790  return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9791  }
9792 
9793  default:
9794  {
9795  auto last_token = get_token_string();
9796  return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack, "expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x" + last_token, "string"), BasicJsonType()));
9797  }
9798  }
9799  }
9800 
9811  bool get_msgpack_binary(binary_t& result)
9812  {
9813  // helper function to set the subtype
9814  auto assign_and_return_true = [&result](std::int8_t subtype)
9815  {
9816  result.set_subtype(static_cast<std::uint8_t>(subtype));
9817  return true;
9818  };
9819 
9820  switch (current)
9821  {
9822  case 0xC4: // bin 8
9823  {
9824  std::uint8_t len{};
9825  return get_number(input_format_t::msgpack, len) &&
9826  get_binary(input_format_t::msgpack, len, result);
9827  }
9828 
9829  case 0xC5: // bin 16
9830  {
9831  std::uint16_t len{};
9832  return get_number(input_format_t::msgpack, len) &&
9833  get_binary(input_format_t::msgpack, len, result);
9834  }
9835 
9836  case 0xC6: // bin 32
9837  {
9838  std::uint32_t len{};
9839  return get_number(input_format_t::msgpack, len) &&
9840  get_binary(input_format_t::msgpack, len, result);
9841  }
9842 
9843  case 0xC7: // ext 8
9844  {
9845  std::uint8_t len{};
9846  std::int8_t subtype{};
9847  return get_number(input_format_t::msgpack, len) &&
9848  get_number(input_format_t::msgpack, subtype) &&
9849  get_binary(input_format_t::msgpack, len, result) &&
9850  assign_and_return_true(subtype);
9851  }
9852 
9853  case 0xC8: // ext 16
9854  {
9855  std::uint16_t len{};
9856  std::int8_t subtype{};
9857  return get_number(input_format_t::msgpack, len) &&
9858  get_number(input_format_t::msgpack, subtype) &&
9859  get_binary(input_format_t::msgpack, len, result) &&
9860  assign_and_return_true(subtype);
9861  }
9862 
9863  case 0xC9: // ext 32
9864  {
9865  std::uint32_t len{};
9866  std::int8_t subtype{};
9867  return get_number(input_format_t::msgpack, len) &&
9868  get_number(input_format_t::msgpack, subtype) &&
9869  get_binary(input_format_t::msgpack, len, result) &&
9870  assign_and_return_true(subtype);
9871  }
9872 
9873  case 0xD4: // fixext 1
9874  {
9875  std::int8_t subtype{};
9876  return get_number(input_format_t::msgpack, subtype) &&
9877  get_binary(input_format_t::msgpack, 1, result) &&
9878  assign_and_return_true(subtype);
9879  }
9880 
9881  case 0xD5: // fixext 2
9882  {
9883  std::int8_t subtype{};
9884  return get_number(input_format_t::msgpack, subtype) &&
9885  get_binary(input_format_t::msgpack, 2, result) &&
9886  assign_and_return_true(subtype);
9887  }
9888 
9889  case 0xD6: // fixext 4
9890  {
9891  std::int8_t subtype{};
9892  return get_number(input_format_t::msgpack, subtype) &&
9893  get_binary(input_format_t::msgpack, 4, result) &&
9894  assign_and_return_true(subtype);
9895  }
9896 
9897  case 0xD7: // fixext 8
9898  {
9899  std::int8_t subtype{};
9900  return get_number(input_format_t::msgpack, subtype) &&
9901  get_binary(input_format_t::msgpack, 8, result) &&
9902  assign_and_return_true(subtype);
9903  }
9904 
9905  case 0xD8: // fixext 16
9906  {
9907  std::int8_t subtype{};
9908  return get_number(input_format_t::msgpack, subtype) &&
9909  get_binary(input_format_t::msgpack, 16, result) &&
9910  assign_and_return_true(subtype);
9911  }
9912 
9913  default: // LCOV_EXCL_LINE
9914  return false; // LCOV_EXCL_LINE
9915  }
9916  }
9917 
9922  bool get_msgpack_array(const std::size_t len)
9923  {
9924  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9925  {
9926  return false;
9927  }
9928 
9929  for (std::size_t i = 0; i < len; ++i)
9930  {
9931  if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
9932  {
9933  return false;
9934  }
9935  }
9936 
9937  return sax->end_array();
9938  }
9939 
9944  bool get_msgpack_object(const std::size_t len)
9945  {
9946  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9947  {
9948  return false;
9949  }
9950 
9951  string_t key;
9952  for (std::size_t i = 0; i < len; ++i)
9953  {
9954  get();
9955  if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
9956  {
9957  return false;
9958  }
9959 
9960  if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
9961  {
9962  return false;
9963  }
9964  key.clear();
9965  }
9966 
9967  return sax->end_object();
9968  }
9969 
9971  // UBJSON //
9973 
9981  bool parse_ubjson_internal(const bool get_char = true)
9982  {
9983  return get_ubjson_value(get_char ? get_ignore_noop() : current);
9984  }
9985 
10000  bool get_ubjson_string(string_t& result, const bool get_char = true)
10001  {
10002  if (get_char)
10003  {
10004  get(); // TODO(niels): may we ignore N here?
10005  }
10006 
10007  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "value")))
10008  {
10009  return false;
10010  }
10011 
10012  switch (current)
10013  {
10014  case 'U':
10015  {
10016  std::uint8_t len{};
10017  return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10018  }
10019 
10020  case 'i':
10021  {
10022  std::int8_t len{};
10023  return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10024  }
10025 
10026  case 'I':
10027  {
10028  std::int16_t len{};
10029  return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10030  }
10031 
10032  case 'l':
10033  {
10034  std::int32_t len{};
10035  return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10036  }
10037 
10038  case 'L':
10039  {
10040  std::int64_t len{};
10041  return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10042  }
10043 
10044  default:
10045  auto last_token = get_token_string();
10046  return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token, "string"), BasicJsonType()));
10047  }
10048  }
10049 
10054  bool get_ubjson_size_value(std::size_t& result)
10055  {
10056  switch (get_ignore_noop())
10057  {
10058  case 'U':
10059  {
10060  std::uint8_t number{};
10061  if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10062  {
10063  return false;
10064  }
10065  result = static_cast<std::size_t>(number);
10066  return true;
10067  }
10068 
10069  case 'i':
10070  {
10071  std::int8_t number{};
10072  if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10073  {
10074  return false;
10075  }
10076  result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char
10077  return true;
10078  }
10079 
10080  case 'I':
10081  {
10082  std::int16_t number{};
10083  if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10084  {
10085  return false;
10086  }
10087  result = static_cast<std::size_t>(number);
10088  return true;
10089  }
10090 
10091  case 'l':
10092  {
10093  std::int32_t number{};
10094  if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10095  {
10096  return false;
10097  }
10098  result = static_cast<std::size_t>(number);
10099  return true;
10100  }
10101 
10102  case 'L':
10103  {
10104  std::int64_t number{};
10105  if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10106  {
10107  return false;
10108  }
10109  result = static_cast<std::size_t>(number);
10110  return true;
10111  }
10112 
10113  default:
10114  {
10115  auto last_token = get_token_string();
10116  return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token, "size"), BasicJsonType()));
10117  }
10118  }
10119  }
10120 
10131  bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result)
10132  {
10133  result.first = string_t::npos; // size
10134  result.second = 0; // type
10135 
10136  get_ignore_noop();
10137 
10138  if (current == '$')
10139  {
10140  result.second = get(); // must not ignore 'N', because 'N' maybe the type
10141  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "type")))
10142  {
10143  return false;
10144  }
10145 
10146  get_ignore_noop();
10147  if (JSON_HEDLEY_UNLIKELY(current != '#'))
10148  {
10149  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "value")))
10150  {
10151  return false;
10152  }
10153  auto last_token = get_token_string();
10154  return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "expected '#' after type information; last byte: 0x" + last_token, "size"), BasicJsonType()));
10155  }
10156 
10157  return get_ubjson_size_value(result.first);
10158  }
10159 
10160  if (current == '#')
10161  {
10162  return get_ubjson_size_value(result.first);
10163  }
10164 
10165  return true;
10166  }
10167 
10172  bool get_ubjson_value(const char_int_type prefix)
10173  {
10174  switch (prefix)
10175  {
10176  case std::char_traits<char_type>::eof(): // EOF
10177  return unexpect_eof(input_format_t::ubjson, "value");
10178 
10179  case 'T': // true
10180  return sax->boolean(true);
10181  case 'F': // false
10182  return sax->boolean(false);
10183 
10184  case 'Z': // null
10185  return sax->null();
10186 
10187  case 'U':
10188  {
10189  std::uint8_t number{};
10190  return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number);
10191  }
10192 
10193  case 'i':
10194  {
10195  std::int8_t number{};
10196  return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10197  }
10198 
10199  case 'I':
10200  {
10201  std::int16_t number{};
10202  return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10203  }
10204 
10205  case 'l':
10206  {
10207  std::int32_t number{};
10208  return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10209  }
10210 
10211  case 'L':
10212  {
10213  std::int64_t number{};
10214  return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10215  }
10216 
10217  case 'd':
10218  {
10219  float number{};
10220  return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast<number_float_t>(number), "");
10221  }
10222 
10223  case 'D':
10224  {
10225  double number{};
10226  return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast<number_float_t>(number), "");
10227  }
10228 
10229  case 'H':
10230  {
10231  return get_ubjson_high_precision_number();
10232  }
10233 
10234  case 'C': // char
10235  {
10236  get();
10237  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "char")))
10238  {
10239  return false;
10240  }
10241  if (JSON_HEDLEY_UNLIKELY(current > 127))
10242  {
10243  auto last_token = get_token_string();
10244  return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "byte after 'C' must be in range 0x00..0x7F; last byte: 0x" + last_token, "char"), BasicJsonType()));
10245  }
10246  string_t s(1, static_cast<typename string_t::value_type>(current));
10247  return sax->string(s);
10248  }
10249 
10250  case 'S': // string
10251  {
10252  string_t s;
10253  return get_ubjson_string(s) && sax->string(s);
10254  }
10255 
10256  case '[': // array
10257  return get_ubjson_array();
10258 
10259  case '{': // object
10260  return get_ubjson_object();
10261 
10262  default: // anything else
10263  {
10264  auto last_token = get_token_string();
10265  return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
10266  }
10267  }
10268  }
10269 
10273  bool get_ubjson_array()
10274  {
10275  std::pair<std::size_t, char_int_type> size_and_type;
10276  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10277  {
10278  return false;
10279  }
10280 
10281  if (size_and_type.first != string_t::npos)
10282  {
10283  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
10284  {
10285  return false;
10286  }
10287 
10288  if (size_and_type.second != 0)
10289  {
10290  if (size_and_type.second != 'N')
10291  {
10292  for (std::size_t i = 0; i < size_and_type.first; ++i)
10293  {
10294  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10295  {
10296  return false;
10297  }
10298  }
10299  }
10300  }
10301  else
10302  {
10303  for (std::size_t i = 0; i < size_and_type.first; ++i)
10304  {
10305  if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10306  {
10307  return false;
10308  }
10309  }
10310  }
10311  }
10312  else
10313  {
10314  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10315  {
10316  return false;
10317  }
10318 
10319  while (current != ']')
10320  {
10321  if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(false)))
10322  {
10323  return false;
10324  }
10325  get_ignore_noop();
10326  }
10327  }
10328 
10329  return sax->end_array();
10330  }
10331 
10335  bool get_ubjson_object()
10336  {
10337  std::pair<std::size_t, char_int_type> size_and_type;
10338  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10339  {
10340  return false;
10341  }
10342 
10343  string_t key;
10344  if (size_and_type.first != string_t::npos)
10345  {
10346  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
10347  {
10348  return false;
10349  }
10350 
10351  if (size_and_type.second != 0)
10352  {
10353  for (std::size_t i = 0; i < size_and_type.first; ++i)
10354  {
10355  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10356  {
10357  return false;
10358  }
10359  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10360  {
10361  return false;
10362  }
10363  key.clear();
10364  }
10365  }
10366  else
10367  {
10368  for (std::size_t i = 0; i < size_and_type.first; ++i)
10369  {
10370  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10371  {
10372  return false;
10373  }
10374  if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10375  {
10376  return false;
10377  }
10378  key.clear();
10379  }
10380  }
10381  }
10382  else
10383  {
10384  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10385  {
10386  return false;
10387  }
10388 
10389  while (current != '}')
10390  {
10391  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key, false) || !sax->key(key)))
10392  {
10393  return false;
10394  }
10395  if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10396  {
10397  return false;
10398  }
10399  get_ignore_noop();
10400  key.clear();
10401  }
10402  }
10403 
10404  return sax->end_object();
10405  }
10406 
10407  // Note, no reader for UBJSON binary types is implemented because they do
10408  // not exist
10409 
10410  bool get_ubjson_high_precision_number()
10411  {
10412  // get size of following number string
10413  std::size_t size{};
10414  auto res = get_ubjson_size_value(size);
10415  if (JSON_HEDLEY_UNLIKELY(!res))
10416  {
10417  return res;
10418  }
10419 
10420  // get number string
10421  std::vector<char> number_vector;
10422  for (std::size_t i = 0; i < size; ++i)
10423  {
10424  get();
10425  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "number")))
10426  {
10427  return false;
10428  }
10429  number_vector.push_back(static_cast<char>(current));
10430  }
10431 
10432  // parse number string
10433  using ia_type = decltype(detail::input_adapter(number_vector));
10434  auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector), false);
10435  const auto result_number = number_lexer.scan();
10436  const auto number_string = number_lexer.get_token_string();
10437  const auto result_remainder = number_lexer.scan();
10438 
10439  using token_type = typename detail::lexer_base<BasicJsonType>::token_type;
10440 
10441  if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
10442  {
10443  return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), BasicJsonType()));
10444  }
10445 
10446  switch (result_number)
10447  {
10448  case token_type::value_integer:
10449  return sax->number_integer(number_lexer.get_number_integer());
10450  case token_type::value_unsigned:
10451  return sax->number_unsigned(number_lexer.get_number_unsigned());
10452  case token_type::value_float:
10453  return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
10454  default:
10455  return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), BasicJsonType()));
10456  }
10457  }
10458 
10460  // Utility functions //
10462 
10472  char_int_type get()
10473  {
10474  ++chars_read;
10475  return current = ia.get_character();
10476  }
10477 
10481  char_int_type get_ignore_noop()
10482  {
10483  do
10484  {
10485  get();
10486  }
10487  while (current == 'N');
10488 
10489  return current;
10490  }
10491 
10492  /*
10493  @brief read a number from the input
10494 
10495  @tparam NumberType the type of the number
10496  @param[in] format the current format (for diagnostics)
10497  @param[out] result number of type @a NumberType
10498 
10499  @return whether conversion completed
10500 
10501  @note This function needs to respect the system's endianess, because
10502  bytes in CBOR, MessagePack, and UBJSON are stored in network order
10503  (big endian) and therefore need reordering on little endian systems.
10504  */
10505  template<typename NumberType, bool InputIsLittleEndian = false>
10506  bool get_number(const input_format_t format, NumberType& result)
10507  {
10508  // step 1: read input into array with system's byte order
10509  std::array<std::uint8_t, sizeof(NumberType)> vec{};
10510  for (std::size_t i = 0; i < sizeof(NumberType); ++i)
10511  {
10512  get();
10513  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number")))
10514  {
10515  return false;
10516  }
10517 
10518  // reverse byte order prior to conversion if necessary
10519  if (is_little_endian != InputIsLittleEndian)
10520  {
10521  vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);
10522  }
10523  else
10524  {
10525  vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE
10526  }
10527  }
10528 
10529  // step 2: convert array into number of type T and return
10530  std::memcpy(&result, vec.data(), sizeof(NumberType));
10531  return true;
10532  }
10533 
10548  template<typename NumberType>
10549  bool get_string(const input_format_t format,
10550  const NumberType len,
10551  string_t& result)
10552  {
10553  bool success = true;
10554  for (NumberType i = 0; i < len; i++)
10555  {
10556  get();
10557  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "string")))
10558  {
10559  success = false;
10560  break;
10561  }
10562  result.push_back(static_cast<typename string_t::value_type>(current));
10563  }
10564  return success;
10565  }
10566 
10581  template<typename NumberType>
10582  bool get_binary(const input_format_t format,
10583  const NumberType len,
10584  binary_t& result)
10585  {
10586  bool success = true;
10587  for (NumberType i = 0; i < len; i++)
10588  {
10589  get();
10590  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "binary")))
10591  {
10592  success = false;
10593  break;
10594  }
10595  result.push_back(static_cast<std::uint8_t>(current));
10596  }
10597  return success;
10598  }
10599 
10605  JSON_HEDLEY_NON_NULL(3)
10606  bool unexpect_eof(const input_format_t format, const char* context) const
10607  {
10608  if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
10609  {
10610  return sax->parse_error(chars_read, "<end of file>",
10611  parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), BasicJsonType()));
10612  }
10613  return true;
10614  }
10615 
10619  std::string get_token_string() const
10620  {
10621  std::array<char, 3> cr{{}};
10622  (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
10623  return std::string{cr.data()};
10624  }
10625 
10632  std::string exception_message(const input_format_t format,
10633  const std::string& detail,
10634  const std::string& context) const
10635  {
10636  std::string error_msg = "syntax error while parsing ";
10637 
10638  switch (format)
10639  {
10640  case input_format_t::cbor:
10641  error_msg += "CBOR";
10642  break;
10643 
10644  case input_format_t::msgpack:
10645  error_msg += "MessagePack";
10646  break;
10647 
10648  case input_format_t::ubjson:
10649  error_msg += "UBJSON";
10650  break;
10651 
10652  case input_format_t::bson:
10653  error_msg += "BSON";
10654  break;
10655 
10656  default: // LCOV_EXCL_LINE
10657  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
10658  }
10659 
10660  return error_msg + " " + context + ": " + detail;
10661  }
10662 
10663  private:
10665  InputAdapterType ia;
10666 
10668  char_int_type current = std::char_traits<char_type>::eof();
10669 
10671  std::size_t chars_read = 0;
10672 
10674  const bool is_little_endian = little_endianess();
10675 
10677  json_sax_t* sax = nullptr;
10678 };
10679 } // namespace detail
10680 } // namespace nlohmann
10681 
10682 // #include <nlohmann/detail/input/input_adapters.hpp>
10683 
10684 // #include <nlohmann/detail/input/lexer.hpp>
10685 
10686 // #include <nlohmann/detail/input/parser.hpp>
10687 
10688 
10689 #include <cmath> // isfinite
10690 #include <cstdint> // uint8_t
10691 #include <functional> // function
10692 #include <string> // string
10693 #include <utility> // move
10694 #include <vector> // vector
10695 
10696 // #include <nlohmann/detail/exceptions.hpp>
10697 
10698 // #include <nlohmann/detail/input/input_adapters.hpp>
10699 
10700 // #include <nlohmann/detail/input/json_sax.hpp>
10701 
10702 // #include <nlohmann/detail/input/lexer.hpp>
10703 
10704 // #include <nlohmann/detail/macro_scope.hpp>
10705 
10706 // #include <nlohmann/detail/meta/is_sax.hpp>
10707 
10708 // #include <nlohmann/detail/value_t.hpp>
10709 
10710 
10711 namespace nlohmann
10712 {
10713 namespace detail
10714 {
10716 // parser //
10718 
10719 enum class parse_event_t : uint8_t
10720 {
10722  object_start,
10724  object_end,
10726  array_start,
10728  array_end,
10730  key,
10732  value
10733 };
10734 
10735 template<typename BasicJsonType>
10736 using parser_callback_t =
10737  std::function<bool(int /*depth*/, parse_event_t /*event*/, BasicJsonType& /*parsed*/)>;
10738 
10744 template<typename BasicJsonType, typename InputAdapterType>
10745 class parser
10746 {
10747  using number_integer_t = typename BasicJsonType::number_integer_t;
10748  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
10749  using number_float_t = typename BasicJsonType::number_float_t;
10750  using string_t = typename BasicJsonType::string_t;
10751  using lexer_t = lexer<BasicJsonType, InputAdapterType>;
10752  using token_type = typename lexer_t::token_type;
10753 
10754  public:
10756  explicit parser(InputAdapterType&& adapter,
10757  const parser_callback_t<BasicJsonType> cb = nullptr,
10758  const bool allow_exceptions_ = true,
10759  const bool skip_comments = false)
10760  : callback(cb)
10761  , m_lexer(std::move(adapter), skip_comments)
10762  , allow_exceptions(allow_exceptions_)
10763  {
10764  // read first token
10765  get_token();
10766  }
10767 
10778  void parse(const bool strict, BasicJsonType& result)
10779  {
10780  if (callback)
10781  {
10782  json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
10783  sax_parse_internal(&sdp);
10784 
10785  // in strict mode, input must be completely read
10786  if (strict && (get_token() != token_type::end_of_input))
10787  {
10788  sdp.parse_error(m_lexer.get_position(),
10789  m_lexer.get_token_string(),
10790  parse_error::create(101, m_lexer.get_position(),
10791  exception_message(token_type::end_of_input, "value"), BasicJsonType()));
10792  }
10793 
10794  // in case of an error, return discarded value
10795  if (sdp.is_errored())
10796  {
10797  result = value_t::discarded;
10798  return;
10799  }
10800 
10801  // set top-level value to null if it was discarded by the callback
10802  // function
10803  if (result.is_discarded())
10804  {
10805  result = nullptr;
10806  }
10807  }
10808  else
10809  {
10810  json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
10811  sax_parse_internal(&sdp);
10812 
10813  // in strict mode, input must be completely read
10814  if (strict && (get_token() != token_type::end_of_input))
10815  {
10816  sdp.parse_error(m_lexer.get_position(),
10817  m_lexer.get_token_string(),
10818  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
10819  }
10820 
10821  // in case of an error, return discarded value
10822  if (sdp.is_errored())
10823  {
10824  result = value_t::discarded;
10825  return;
10826  }
10827  }
10828 
10829  result.assert_invariant();
10830  }
10831 
10838  bool accept(const bool strict = true)
10839  {
10840  json_sax_acceptor<BasicJsonType> sax_acceptor;
10841  return sax_parse(&sax_acceptor, strict);
10842  }
10843 
10844  template<typename SAX>
10845  JSON_HEDLEY_NON_NULL(2)
10846  bool sax_parse(SAX* sax, const bool strict = true)
10847  {
10848  (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
10849  const bool result = sax_parse_internal(sax);
10850 
10851  // strict mode: next byte must be EOF
10852  if (result && strict && (get_token() != token_type::end_of_input))
10853  {
10854  return sax->parse_error(m_lexer.get_position(),
10855  m_lexer.get_token_string(),
10856  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
10857  }
10858 
10859  return result;
10860  }
10861 
10862  private:
10863  template<typename SAX>
10864  JSON_HEDLEY_NON_NULL(2)
10865  bool sax_parse_internal(SAX* sax)
10866  {
10867  // stack to remember the hierarchy of structured values we are parsing
10868  // true = array; false = object
10869  std::vector<bool> states;
10870  // value to avoid a goto (see comment where set to true)
10871  bool skip_to_state_evaluation = false;
10872 
10873  while (true)
10874  {
10875  if (!skip_to_state_evaluation)
10876  {
10877  // invariant: get_token() was called before each iteration
10878  switch (last_token)
10879  {
10880  case token_type::begin_object:
10881  {
10882  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10883  {
10884  return false;
10885  }
10886 
10887  // closing } -> we are done
10888  if (get_token() == token_type::end_object)
10889  {
10890  if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
10891  {
10892  return false;
10893  }
10894  break;
10895  }
10896 
10897  // parse key
10898  if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
10899  {
10900  return sax->parse_error(m_lexer.get_position(),
10901  m_lexer.get_token_string(),
10902  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
10903  }
10904  if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
10905  {
10906  return false;
10907  }
10908 
10909  // parse separator (:)
10910  if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
10911  {
10912  return sax->parse_error(m_lexer.get_position(),
10913  m_lexer.get_token_string(),
10914  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
10915  }
10916 
10917  // remember we are now inside an object
10918  states.push_back(false);
10919 
10920  // parse values
10921  get_token();
10922  continue;
10923  }
10924 
10925  case token_type::begin_array:
10926  {
10927  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10928  {
10929  return false;
10930  }
10931 
10932  // closing ] -> we are done
10933  if (get_token() == token_type::end_array)
10934  {
10935  if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
10936  {
10937  return false;
10938  }
10939  break;
10940  }
10941 
10942  // remember we are now inside an array
10943  states.push_back(true);
10944 
10945  // parse values (no need to call get_token)
10946  continue;
10947  }
10948 
10949  case token_type::value_float:
10950  {
10951  const auto res = m_lexer.get_number_float();
10952 
10953  if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
10954  {
10955  return sax->parse_error(m_lexer.get_position(),
10956  m_lexer.get_token_string(),
10957  out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'", BasicJsonType()));
10958  }
10959 
10960  if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
10961  {
10962  return false;
10963  }
10964 
10965  break;
10966  }
10967 
10968  case token_type::literal_false:
10969  {
10970  if (JSON_HEDLEY_UNLIKELY(!sax->boolean(false)))
10971  {
10972  return false;
10973  }
10974  break;
10975  }
10976 
10977  case token_type::literal_null:
10978  {
10979  if (JSON_HEDLEY_UNLIKELY(!sax->null()))
10980  {
10981  return false;
10982  }
10983  break;
10984  }
10985 
10986  case token_type::literal_true:
10987  {
10988  if (JSON_HEDLEY_UNLIKELY(!sax->boolean(true)))
10989  {
10990  return false;
10991  }
10992  break;
10993  }
10994 
10995  case token_type::value_integer:
10996  {
10997  if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
10998  {
10999  return false;
11000  }
11001  break;
11002  }
11003 
11004  case token_type::value_string:
11005  {
11006  if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
11007  {
11008  return false;
11009  }
11010  break;
11011  }
11012 
11013  case token_type::value_unsigned:
11014  {
11015  if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
11016  {
11017  return false;
11018  }
11019  break;
11020  }
11021 
11022  case token_type::parse_error:
11023  {
11024  // using "uninitialized" to avoid "expected" message
11025  return sax->parse_error(m_lexer.get_position(),
11026  m_lexer.get_token_string(),
11027  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), BasicJsonType()));
11028  }
11029 
11030  default: // the last token was unexpected
11031  {
11032  return sax->parse_error(m_lexer.get_position(),
11033  m_lexer.get_token_string(),
11034  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), BasicJsonType()));
11035  }
11036  }
11037  }
11038  else
11039  {
11040  skip_to_state_evaluation = false;
11041  }
11042 
11043  // we reached this line after we successfully parsed a value
11044  if (states.empty())
11045  {
11046  // empty stack: we reached the end of the hierarchy: done
11047  return true;
11048  }
11049 
11050  if (states.back()) // array
11051  {
11052  // comma -> next value
11053  if (get_token() == token_type::value_separator)
11054  {
11055  // parse a new value
11056  get_token();
11057  continue;
11058  }
11059 
11060  // closing ]
11061  if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
11062  {
11063  if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
11064  {
11065  return false;
11066  }
11067 
11068  // We are done with this array. Before we can parse a
11069  // new value, we need to evaluate the new state first.
11070  // By setting skip_to_state_evaluation to false, we
11071  // are effectively jumping to the beginning of this if.
11072  JSON_ASSERT(!states.empty());
11073  states.pop_back();
11074  skip_to_state_evaluation = true;
11075  continue;
11076  }
11077 
11078  return sax->parse_error(m_lexer.get_position(),
11079  m_lexer.get_token_string(),
11080  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, "array"), BasicJsonType()));
11081  }
11082 
11083  // states.back() is false -> object
11084 
11085  // comma -> next value
11086  if (get_token() == token_type::value_separator)
11087  {
11088  // parse key
11089  if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
11090  {
11091  return sax->parse_error(m_lexer.get_position(),
11092  m_lexer.get_token_string(),
11093  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
11094  }
11095 
11096  if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
11097  {
11098  return false;
11099  }
11100 
11101  // parse separator (:)
11102  if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
11103  {
11104  return sax->parse_error(m_lexer.get_position(),
11105  m_lexer.get_token_string(),
11106  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
11107  }
11108 
11109  // parse values
11110  get_token();
11111  continue;
11112  }
11113 
11114  // closing }
11115  if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
11116  {
11117  if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
11118  {
11119  return false;
11120  }
11121 
11122  // We are done with this object. Before we can parse a
11123  // new value, we need to evaluate the new state first.
11124  // By setting skip_to_state_evaluation to false, we
11125  // are effectively jumping to the beginning of this if.
11126  JSON_ASSERT(!states.empty());
11127  states.pop_back();
11128  skip_to_state_evaluation = true;
11129  continue;
11130  }
11131 
11132  return sax->parse_error(m_lexer.get_position(),
11133  m_lexer.get_token_string(),
11134  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, "object"), BasicJsonType()));
11135  }
11136  }
11137 
11139  token_type get_token()
11140  {
11141  return last_token = m_lexer.scan();
11142  }
11143 
11144  std::string exception_message(const token_type expected, const std::string& context)
11145  {
11146  std::string error_msg = "syntax error ";
11147 
11148  if (!context.empty())
11149  {
11150  error_msg += "while parsing " + context + " ";
11151  }
11152 
11153  error_msg += "- ";
11154 
11155  if (last_token == token_type::parse_error)
11156  {
11157  error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" +
11158  m_lexer.get_token_string() + "'";
11159  }
11160  else
11161  {
11162  error_msg += "unexpected " + std::string(lexer_t::token_type_name(last_token));
11163  }
11164 
11165  if (expected != token_type::uninitialized)
11166  {
11167  error_msg += "; expected " + std::string(lexer_t::token_type_name(expected));
11168  }
11169 
11170  return error_msg;
11171  }
11172 
11173  private:
11175  const parser_callback_t<BasicJsonType> callback = nullptr;
11177  token_type last_token = token_type::uninitialized;
11179  lexer_t m_lexer;
11181  const bool allow_exceptions = true;
11182 };
11183 
11184 } // namespace detail
11185 } // namespace nlohmann
11186 
11187 // #include <nlohmann/detail/iterators/internal_iterator.hpp>
11188 
11189 
11190 // #include <nlohmann/detail/iterators/primitive_iterator.hpp>
11191 
11192 
11193 #include <cstddef> // ptrdiff_t
11194 #include <limits> // numeric_limits
11195 
11196 // #include <nlohmann/detail/macro_scope.hpp>
11197 
11198 
11199 namespace nlohmann
11200 {
11201 namespace detail
11202 {
11203 /*
11204 @brief an iterator for primitive JSON types
11205 
11206 This class models an iterator for primitive JSON types (boolean, number,
11207 string). It's only purpose is to allow the iterator/const_iterator classes
11208 to "iterate" over primitive values. Internally, the iterator is modeled by
11209 a `difference_type` variable. Value begin_value (`0`) models the begin,
11210 end_value (`1`) models past the end.
11211 */
11212 class primitive_iterator_t
11213 {
11214  private:
11215  using difference_type = std::ptrdiff_t;
11216  static constexpr difference_type begin_value = 0;
11217  static constexpr difference_type end_value = begin_value + 1;
11218 
11219  JSON_PRIVATE_UNLESS_TESTED:
11221  difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
11222 
11223  public:
11224  constexpr difference_type get_value() const noexcept
11225  {
11226  return m_it;
11227  }
11228 
11230  void set_begin() noexcept
11231  {
11232  m_it = begin_value;
11233  }
11234 
11236  void set_end() noexcept
11237  {
11238  m_it = end_value;
11239  }
11240 
11242  constexpr bool is_begin() const noexcept
11243  {
11244  return m_it == begin_value;
11245  }
11246 
11248  constexpr bool is_end() const noexcept
11249  {
11250  return m_it == end_value;
11251  }
11252 
11253  friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11254  {
11255  return lhs.m_it == rhs.m_it;
11256  }
11257 
11258  friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11259  {
11260  return lhs.m_it < rhs.m_it;
11261  }
11262 
11263  primitive_iterator_t operator+(difference_type n) noexcept
11264  {
11265  auto result = *this;
11266  result += n;
11267  return result;
11268  }
11269 
11270  friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11271  {
11272  return lhs.m_it - rhs.m_it;
11273  }
11274 
11275  primitive_iterator_t& operator++() noexcept
11276  {
11277  ++m_it;
11278  return *this;
11279  }
11280 
11281  primitive_iterator_t const operator++(int) noexcept // NOLINT(readability-const-return-type)
11282  {
11283  auto result = *this;
11284  ++m_it;
11285  return result;
11286  }
11287 
11288  primitive_iterator_t& operator--() noexcept
11289  {
11290  --m_it;
11291  return *this;
11292  }
11293 
11294  primitive_iterator_t const operator--(int) noexcept // NOLINT(readability-const-return-type)
11295  {
11296  auto result = *this;
11297  --m_it;
11298  return result;
11299  }
11300 
11301  primitive_iterator_t& operator+=(difference_type n) noexcept
11302  {
11303  m_it += n;
11304  return *this;
11305  }
11306 
11307  primitive_iterator_t& operator-=(difference_type n) noexcept
11308  {
11309  m_it -= n;
11310  return *this;
11311  }
11312 };
11313 } // namespace detail
11314 } // namespace nlohmann
11315 
11316 
11317 namespace nlohmann
11318 {
11319 namespace detail
11320 {
11327 template<typename BasicJsonType> struct internal_iterator
11328 {
11330  typename BasicJsonType::object_t::iterator object_iterator {};
11332  typename BasicJsonType::array_t::iterator array_iterator {};
11334  primitive_iterator_t primitive_iterator {};
11335 };
11336 } // namespace detail
11337 } // namespace nlohmann
11338 
11339 // #include <nlohmann/detail/iterators/iter_impl.hpp>
11340 
11341 
11342 #include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next
11343 #include <type_traits> // conditional, is_const, remove_const
11344 
11345 // #include <nlohmann/detail/exceptions.hpp>
11346 
11347 // #include <nlohmann/detail/iterators/internal_iterator.hpp>
11348 
11349 // #include <nlohmann/detail/iterators/primitive_iterator.hpp>
11350 
11351 // #include <nlohmann/detail/macro_scope.hpp>
11352 
11353 // #include <nlohmann/detail/meta/cpp_future.hpp>
11354 
11355 // #include <nlohmann/detail/meta/type_traits.hpp>
11356 
11357 // #include <nlohmann/detail/value_t.hpp>
11358 
11359 
11360 namespace nlohmann
11361 {
11362 namespace detail
11363 {
11364 // forward declare, to be able to friend it later on
11365 template<typename IteratorType> class iteration_proxy;
11366 template<typename IteratorType> class iteration_proxy_value;
11367 
11384 template<typename BasicJsonType>
11385 class iter_impl
11386 {
11388  using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
11390  friend other_iter_impl;
11391  friend BasicJsonType;
11392  friend iteration_proxy<iter_impl>;
11393  friend iteration_proxy_value<iter_impl>;
11394 
11395  using object_t = typename BasicJsonType::object_t;
11396  using array_t = typename BasicJsonType::array_t;
11397  // make sure BasicJsonType is basic_json or const basic_json
11398  static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
11399  "iter_impl only accepts (const) basic_json");
11400 
11401  public:
11402 
11408  using iterator_category = std::bidirectional_iterator_tag;
11409 
11411  using value_type = typename BasicJsonType::value_type;
11413  using difference_type = typename BasicJsonType::difference_type;
11415  using pointer = typename std::conditional<std::is_const<BasicJsonType>::value,
11416  typename BasicJsonType::const_pointer,
11417  typename BasicJsonType::pointer>::type;
11419  using reference =
11420  typename std::conditional<std::is_const<BasicJsonType>::value,
11421  typename BasicJsonType::const_reference,
11422  typename BasicJsonType::reference>::type;
11423 
11424  iter_impl() = default;
11425  ~iter_impl() = default;
11426  iter_impl(iter_impl&&) noexcept = default;
11427  iter_impl& operator=(iter_impl&&) noexcept = default;
11428 
11435  explicit iter_impl(pointer object) noexcept : m_object(object)
11436  {
11437  JSON_ASSERT(m_object != nullptr);
11438 
11439  switch (m_object->m_type)
11440  {
11441  case value_t::object:
11442  {
11443  m_it.object_iterator = typename object_t::iterator();
11444  break;
11445  }
11446 
11447  case value_t::array:
11448  {
11449  m_it.array_iterator = typename array_t::iterator();
11450  break;
11451  }
11452 
11453  default:
11454  {
11455  m_it.primitive_iterator = primitive_iterator_t();
11456  break;
11457  }
11458  }
11459  }
11460 
11477  iter_impl(const iter_impl<const BasicJsonType>& other) noexcept
11478  : m_object(other.m_object), m_it(other.m_it)
11479  {}
11480 
11487  iter_impl& operator=(const iter_impl<const BasicJsonType>& other) noexcept
11488  {
11489  if (&other != this)
11490  {
11491  m_object = other.m_object;
11492  m_it = other.m_it;
11493  }
11494  return *this;
11495  }
11496 
11502  iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept
11503  : m_object(other.m_object), m_it(other.m_it)
11504  {}
11505 
11512  iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp)
11513  {
11514  m_object = other.m_object;
11515  m_it = other.m_it;
11516  return *this;
11517  }
11518 
11519  JSON_PRIVATE_UNLESS_TESTED:
11524  void set_begin() noexcept
11525  {
11526  JSON_ASSERT(m_object != nullptr);
11527 
11528  switch (m_object->m_type)
11529  {
11530  case value_t::object:
11531  {
11532  m_it.object_iterator = m_object->m_value.object->begin();
11533  break;
11534  }
11535 
11536  case value_t::array:
11537  {
11538  m_it.array_iterator = m_object->m_value.array->begin();
11539  break;
11540  }
11541 
11542  case value_t::null:
11543  {
11544  // set to end so begin()==end() is true: null is empty
11545  m_it.primitive_iterator.set_end();
11546  break;
11547  }
11548 
11549  default:
11550  {
11551  m_it.primitive_iterator.set_begin();
11552  break;
11553  }
11554  }
11555  }
11556 
11561  void set_end() noexcept
11562  {
11563  JSON_ASSERT(m_object != nullptr);
11564 
11565  switch (m_object->m_type)
11566  {
11567  case value_t::object:
11568  {
11569  m_it.object_iterator = m_object->m_value.object->end();
11570  break;
11571  }
11572 
11573  case value_t::array:
11574  {
11575  m_it.array_iterator = m_object->m_value.array->end();
11576  break;
11577  }
11578 
11579  default:
11580  {
11581  m_it.primitive_iterator.set_end();
11582  break;
11583  }
11584  }
11585  }
11586 
11587  public:
11592  reference operator*() const
11593  {
11594  JSON_ASSERT(m_object != nullptr);
11595 
11596  switch (m_object->m_type)
11597  {
11598  case value_t::object:
11599  {
11600  JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11601  return m_it.object_iterator->second;
11602  }
11603 
11604  case value_t::array:
11605  {
11606  JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11607  return *m_it.array_iterator;
11608  }
11609 
11610  case value_t::null:
11611  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11612 
11613  default:
11614  {
11615  if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11616  {
11617  return *m_object;
11618  }
11619 
11620  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11621  }
11622  }
11623  }
11624 
11629  pointer operator->() const
11630  {
11631  JSON_ASSERT(m_object != nullptr);
11632 
11633  switch (m_object->m_type)
11634  {
11635  case value_t::object:
11636  {
11637  JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11638  return &(m_it.object_iterator->second);
11639  }
11640 
11641  case value_t::array:
11642  {
11643  JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11644  return &*m_it.array_iterator;
11645  }
11646 
11647  default:
11648  {
11649  if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11650  {
11651  return m_object;
11652  }
11653 
11654  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11655  }
11656  }
11657  }
11658 
11663  iter_impl const operator++(int) // NOLINT(readability-const-return-type)
11664  {
11665  auto result = *this;
11666  ++(*this);
11667  return result;
11668  }
11669 
11674  iter_impl& operator++()
11675  {
11676  JSON_ASSERT(m_object != nullptr);
11677 
11678  switch (m_object->m_type)
11679  {
11680  case value_t::object:
11681  {
11682  std::advance(m_it.object_iterator, 1);
11683  break;
11684  }
11685 
11686  case value_t::array:
11687  {
11688  std::advance(m_it.array_iterator, 1);
11689  break;
11690  }
11691 
11692  default:
11693  {
11694  ++m_it.primitive_iterator;
11695  break;
11696  }
11697  }
11698 
11699  return *this;
11700  }
11701 
11706  iter_impl const operator--(int) // NOLINT(readability-const-return-type)
11707  {
11708  auto result = *this;
11709  --(*this);
11710  return result;
11711  }
11712 
11717  iter_impl& operator--()
11718  {
11719  JSON_ASSERT(m_object != nullptr);
11720 
11721  switch (m_object->m_type)
11722  {
11723  case value_t::object:
11724  {
11725  std::advance(m_it.object_iterator, -1);
11726  break;
11727  }
11728 
11729  case value_t::array:
11730  {
11731  std::advance(m_it.array_iterator, -1);
11732  break;
11733  }
11734 
11735  default:
11736  {
11737  --m_it.primitive_iterator;
11738  break;
11739  }
11740  }
11741 
11742  return *this;
11743  }
11744 
11749  template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >
11750  bool operator==(const IterImpl& other) const
11751  {
11752  // if objects are not the same, the comparison is undefined
11753  if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11754  {
11755  JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
11756  }
11757 
11758  JSON_ASSERT(m_object != nullptr);
11759 
11760  switch (m_object->m_type)
11761  {
11762  case value_t::object:
11763  return (m_it.object_iterator == other.m_it.object_iterator);
11764 
11765  case value_t::array:
11766  return (m_it.array_iterator == other.m_it.array_iterator);
11767 
11768  default:
11769  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
11770  }
11771  }
11772 
11777  template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >
11778  bool operator!=(const IterImpl& other) const
11779  {
11780  return !operator==(other);
11781  }
11782 
11787  bool operator<(const iter_impl& other) const
11788  {
11789  // if objects are not the same, the comparison is undefined
11790  if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11791  {
11792  JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
11793  }
11794 
11795  JSON_ASSERT(m_object != nullptr);
11796 
11797  switch (m_object->m_type)
11798  {
11799  case value_t::object:
11800  JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", *m_object));
11801 
11802  case value_t::array:
11803  return (m_it.array_iterator < other.m_it.array_iterator);
11804 
11805  default:
11806  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
11807  }
11808  }
11809 
11814  bool operator<=(const iter_impl& other) const
11815  {
11816  return !other.operator < (*this);
11817  }
11818 
11823  bool operator>(const iter_impl& other) const
11824  {
11825  return !operator<=(other);
11826  }
11827 
11832  bool operator>=(const iter_impl& other) const
11833  {
11834  return !operator<(other);
11835  }
11836 
11841  iter_impl& operator+=(difference_type i)
11842  {
11843  JSON_ASSERT(m_object != nullptr);
11844 
11845  switch (m_object->m_type)
11846  {
11847  case value_t::object:
11848  JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
11849 
11850  case value_t::array:
11851  {
11852  std::advance(m_it.array_iterator, i);
11853  break;
11854  }
11855 
11856  default:
11857  {
11858  m_it.primitive_iterator += i;
11859  break;
11860  }
11861  }
11862 
11863  return *this;
11864  }
11865 
11870  iter_impl& operator-=(difference_type i)
11871  {
11872  return operator+=(-i);
11873  }
11874 
11879  iter_impl operator+(difference_type i) const
11880  {
11881  auto result = *this;
11882  result += i;
11883  return result;
11884  }
11885 
11890  friend iter_impl operator+(difference_type i, const iter_impl& it)
11891  {
11892  auto result = it;
11893  result += i;
11894  return result;
11895  }
11896 
11901  iter_impl operator-(difference_type i) const
11902  {
11903  auto result = *this;
11904  result -= i;
11905  return result;
11906  }
11907 
11912  difference_type operator-(const iter_impl& other) const
11913  {
11914  JSON_ASSERT(m_object != nullptr);
11915 
11916  switch (m_object->m_type)
11917  {
11918  case value_t::object:
11919  JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
11920 
11921  case value_t::array:
11922  return m_it.array_iterator - other.m_it.array_iterator;
11923 
11924  default:
11925  return m_it.primitive_iterator - other.m_it.primitive_iterator;
11926  }
11927  }
11928 
11933  reference operator[](difference_type n) const
11934  {
11935  JSON_ASSERT(m_object != nullptr);
11936 
11937  switch (m_object->m_type)
11938  {
11939  case value_t::object:
11940  JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", *m_object));
11941 
11942  case value_t::array:
11943  return *std::next(m_it.array_iterator, n);
11944 
11945  case value_t::null:
11946  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11947 
11948  default:
11949  {
11950  if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
11951  {
11952  return *m_object;
11953  }
11954 
11955  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11956  }
11957  }
11958  }
11959 
11964  const typename object_t::key_type& key() const
11965  {
11966  JSON_ASSERT(m_object != nullptr);
11967 
11968  if (JSON_HEDLEY_LIKELY(m_object->is_object()))
11969  {
11970  return m_it.object_iterator->first;
11971  }
11972 
11973  JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", *m_object));
11974  }
11975 
11980  reference value() const
11981  {
11982  return operator*();
11983  }
11984 
11985  JSON_PRIVATE_UNLESS_TESTED:
11987  pointer m_object = nullptr;
11989  internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
11990 };
11991 } // namespace detail
11992 } // namespace nlohmann
11993 
11994 // #include <nlohmann/detail/iterators/iteration_proxy.hpp>
11995 
11996 // #include <nlohmann/detail/iterators/json_reverse_iterator.hpp>
11997 
11998 
11999 #include <cstddef> // ptrdiff_t
12000 #include <iterator> // reverse_iterator
12001 #include <utility> // declval
12002 
12003 namespace nlohmann
12004 {
12005 namespace detail
12006 {
12008 // reverse_iterator //
12010 
12029 template<typename Base>
12030 class json_reverse_iterator : public std::reverse_iterator<Base>
12031 {
12032  public:
12033  using difference_type = std::ptrdiff_t;
12035  using base_iterator = std::reverse_iterator<Base>;
12037  using reference = typename Base::reference;
12038 
12040  explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
12041  : base_iterator(it) {}
12042 
12044  explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}
12045 
12047  json_reverse_iterator const operator++(int) // NOLINT(readability-const-return-type)
12048  {
12049  return static_cast<json_reverse_iterator>(base_iterator::operator++(1));
12050  }
12051 
12053  json_reverse_iterator& operator++()
12054  {
12055  return static_cast<json_reverse_iterator&>(base_iterator::operator++());
12056  }
12057 
12059  json_reverse_iterator const operator--(int) // NOLINT(readability-const-return-type)
12060  {
12061  return static_cast<json_reverse_iterator>(base_iterator::operator--(1));
12062  }
12063 
12065  json_reverse_iterator& operator--()
12066  {
12067  return static_cast<json_reverse_iterator&>(base_iterator::operator--());
12068  }
12069 
12071  json_reverse_iterator& operator+=(difference_type i)
12072  {
12073  return static_cast<json_reverse_iterator&>(base_iterator::operator+=(i));
12074  }
12075 
12077  json_reverse_iterator operator+(difference_type i) const
12078  {
12079  return static_cast<json_reverse_iterator>(base_iterator::operator+(i));
12080  }
12081 
12083  json_reverse_iterator operator-(difference_type i) const
12084  {
12085  return static_cast<json_reverse_iterator>(base_iterator::operator-(i));
12086  }
12087 
12089  difference_type operator-(const json_reverse_iterator& other) const
12090  {
12091  return base_iterator(*this) - base_iterator(other);
12092  }
12093 
12095  reference operator[](difference_type n) const
12096  {
12097  return *(this->operator+(n));
12098  }
12099 
12101  auto key() const -> decltype(std::declval<Base>().key())
12102  {
12103  auto it = --this->base();
12104  return it.key();
12105  }
12106 
12108  reference value() const
12109  {
12110  auto it = --this->base();
12111  return it.operator * ();
12112  }
12113 };
12114 } // namespace detail
12115 } // namespace nlohmann
12116 
12117 // #include <nlohmann/detail/iterators/primitive_iterator.hpp>
12118 
12119 // #include <nlohmann/detail/json_pointer.hpp>
12120 
12121 
12122 #include <algorithm> // all_of
12123 #include <cctype> // isdigit
12124 #include <limits> // max
12125 #include <numeric> // accumulate
12126 #include <string> // string
12127 #include <utility> // move
12128 #include <vector> // vector
12129 
12130 // #include <nlohmann/detail/exceptions.hpp>
12131 
12132 // #include <nlohmann/detail/macro_scope.hpp>
12133 
12134 // #include <nlohmann/detail/string_escape.hpp>
12135 
12136 // #include <nlohmann/detail/value_t.hpp>
12137 
12138 
12139 namespace nlohmann
12140 {
12141 template<typename BasicJsonType>
12143 {
12144  // allow basic_json to access private members
12145  NLOHMANN_BASIC_JSON_TPL_DECLARATION
12146  friend class basic_json;
12147 
12148  public:
12170  explicit json_pointer(const std::string& s = "")
12171  : reference_tokens(split(s))
12172  {}
12173 
12188  std::string to_string() const
12189  {
12190  return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
12191  std::string{},
12192  [](const std::string & a, const std::string & b)
12193  {
12194  return a + "/" + detail::escape(b);
12195  });
12196  }
12197 
12199  operator std::string() const
12200  {
12201  return to_string();
12202  }
12203 
12221  {
12222  reference_tokens.insert(reference_tokens.end(),
12223  ptr.reference_tokens.begin(),
12224  ptr.reference_tokens.end());
12225  return *this;
12226  }
12227 
12244  json_pointer& operator/=(std::string token)
12245  {
12246  push_back(std::move(token));
12247  return *this;
12248  }
12249 
12266  json_pointer& operator/=(std::size_t array_idx)
12267  {
12268  return *this /= std::to_string(array_idx);
12269  }
12270 
12287  const json_pointer& rhs)
12288  {
12289  return json_pointer(lhs) /= rhs;
12290  }
12291 
12307  friend json_pointer operator/(const json_pointer& ptr, std::string token) // NOLINT(performance-unnecessary-value-param)
12308  {
12309  return json_pointer(ptr) /= std::move(token);
12310  }
12311 
12327  friend json_pointer operator/(const json_pointer& ptr, std::size_t array_idx)
12328  {
12329  return json_pointer(ptr) /= array_idx;
12330  }
12331 
12346  {
12347  if (empty())
12348  {
12349  return *this;
12350  }
12351 
12352  json_pointer res = *this;
12353  res.pop_back();
12354  return res;
12355  }
12356 
12370  void pop_back()
12371  {
12372  if (JSON_HEDLEY_UNLIKELY(empty()))
12373  {
12374  JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
12375  }
12376 
12377  reference_tokens.pop_back();
12378  }
12379 
12394  const std::string& back() const
12395  {
12396  if (JSON_HEDLEY_UNLIKELY(empty()))
12397  {
12398  JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
12399  }
12400 
12401  return reference_tokens.back();
12402  }
12403 
12416  void push_back(const std::string& token)
12417  {
12418  reference_tokens.push_back(token);
12419  }
12420 
12422  void push_back(std::string&& token)
12423  {
12424  reference_tokens.push_back(std::move(token));
12425  }
12426 
12441  bool empty() const noexcept
12442  {
12443  return reference_tokens.empty();
12444  }
12445 
12446  private:
12457  static typename BasicJsonType::size_type array_index(const std::string& s)
12458  {
12459  using size_type = typename BasicJsonType::size_type;
12460 
12461  // error condition (cf. RFC 6901, Sect. 4)
12462  if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))
12463  {
12464  JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", BasicJsonType()));
12465  }
12466 
12467  // error condition (cf. RFC 6901, Sect. 4)
12468  if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9')))
12469  {
12470  JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", BasicJsonType()));
12471  }
12472 
12473  std::size_t processed_chars = 0;
12474  unsigned long long res = 0; // NOLINT(runtime/int)
12475  JSON_TRY
12476  {
12477  res = std::stoull(s, &processed_chars);
12478  }
12479  JSON_CATCH(std::out_of_range&)
12480  {
12481  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
12482  }
12483 
12484  // check if the string was completely read
12485  if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
12486  {
12487  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
12488  }
12489 
12490  // only triggered on special platforms (like 32bit), see also
12491  // https://github.com/nlohmann/json/pull/2203
12492  if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) // NOLINT(runtime/int)
12493  {
12494  JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", BasicJsonType())); // LCOV_EXCL_LINE
12495  }
12496 
12497  return static_cast<size_type>(res);
12498  }
12499 
12500  JSON_PRIVATE_UNLESS_TESTED:
12501  json_pointer top() const
12502  {
12503  if (JSON_HEDLEY_UNLIKELY(empty()))
12504  {
12505  JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
12506  }
12507 
12508  json_pointer result = *this;
12509  result.reference_tokens = {reference_tokens[0]};
12510  return result;
12511  }
12512 
12513  private:
12522  BasicJsonType& get_and_create(BasicJsonType& j) const
12523  {
12524  auto* result = &j;
12525 
12526  // in case no reference tokens exist, return a reference to the JSON value
12527  // j which will be overwritten by a primitive value
12528  for (const auto& reference_token : reference_tokens)
12529  {
12530  switch (result->type())
12531  {
12532  case detail::value_t::null:
12533  {
12534  if (reference_token == "0")
12535  {
12536  // start a new array if reference token is 0
12537  result = &result->operator[](0);
12538  }
12539  else
12540  {
12541  // start a new object otherwise
12542  result = &result->operator[](reference_token);
12543  }
12544  break;
12545  }
12546 
12547  case detail::value_t::object:
12548  {
12549  // create an entry in the object
12550  result = &result->operator[](reference_token);
12551  break;
12552  }
12553 
12554  case detail::value_t::array:
12555  {
12556  // create an entry in the array
12557  result = &result->operator[](array_index(reference_token));
12558  break;
12559  }
12560 
12561  /*
12562  The following code is only reached if there exists a reference
12563  token _and_ the current value is primitive. In this case, we have
12564  an error situation, because primitive values may only occur as
12565  single value; that is, with an empty list of reference tokens.
12566  */
12567  default:
12568  JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", j));
12569  }
12570  }
12571 
12572  return *result;
12573  }
12574 
12594  BasicJsonType& get_unchecked(BasicJsonType* ptr) const
12595  {
12596  for (const auto& reference_token : reference_tokens)
12597  {
12598  // convert null values to arrays or objects before continuing
12599  if (ptr->is_null())
12600  {
12601  // check if reference token is a number
12602  const bool nums =
12603  std::all_of(reference_token.begin(), reference_token.end(),
12604  [](const unsigned char x)
12605  {
12606  return std::isdigit(x);
12607  });
12608 
12609  // change value to array for numbers or "-" or to object otherwise
12610  *ptr = (nums || reference_token == "-")
12611  ? detail::value_t::array
12612  : detail::value_t::object;
12613  }
12614 
12615  switch (ptr->type())
12616  {
12617  case detail::value_t::object:
12618  {
12619  // use unchecked object access
12620  ptr = &ptr->operator[](reference_token);
12621  break;
12622  }
12623 
12624  case detail::value_t::array:
12625  {
12626  if (reference_token == "-")
12627  {
12628  // explicitly treat "-" as index beyond the end
12629  ptr = &ptr->operator[](ptr->m_value.array->size());
12630  }
12631  else
12632  {
12633  // convert array index to number; unchecked access
12634  ptr = &ptr->operator[](array_index(reference_token));
12635  }
12636  break;
12637  }
12638 
12639  default:
12640  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
12641  }
12642  }
12643 
12644  return *ptr;
12645  }
12646 
12653  BasicJsonType& get_checked(BasicJsonType* ptr) const
12654  {
12655  for (const auto& reference_token : reference_tokens)
12656  {
12657  switch (ptr->type())
12658  {
12659  case detail::value_t::object:
12660  {
12661  // note: at performs range check
12662  ptr = &ptr->at(reference_token);
12663  break;
12664  }
12665 
12666  case detail::value_t::array:
12667  {
12668  if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12669  {
12670  // "-" always fails the range check
12671  JSON_THROW(detail::out_of_range::create(402,
12672  "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12673  ") is out of range", *ptr));
12674  }
12675 
12676  // note: at performs range check
12677  ptr = &ptr->at(array_index(reference_token));
12678  break;
12679  }
12680 
12681  default:
12682  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
12683  }
12684  }
12685 
12686  return *ptr;
12687  }
12688 
12702  const BasicJsonType& get_unchecked(const BasicJsonType* ptr) const
12703  {
12704  for (const auto& reference_token : reference_tokens)
12705  {
12706  switch (ptr->type())
12707  {
12708  case detail::value_t::object:
12709  {
12710  // use unchecked object access
12711  ptr = &ptr->operator[](reference_token);
12712  break;
12713  }
12714 
12715  case detail::value_t::array:
12716  {
12717  if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12718  {
12719  // "-" cannot be used for const access
12720  JSON_THROW(detail::out_of_range::create(402, "array index '-' (" + std::to_string(ptr->m_value.array->size()) + ") is out of range", *ptr));
12721  }
12722 
12723  // use unchecked array access
12724  ptr = &ptr->operator[](array_index(reference_token));
12725  break;
12726  }
12727 
12728  default:
12729  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
12730  }
12731  }
12732 
12733  return *ptr;
12734  }
12735 
12742  const BasicJsonType& get_checked(const BasicJsonType* ptr) const
12743  {
12744  for (const auto& reference_token : reference_tokens)
12745  {
12746  switch (ptr->type())
12747  {
12748  case detail::value_t::object:
12749  {
12750  // note: at performs range check
12751  ptr = &ptr->at(reference_token);
12752  break;
12753  }
12754 
12755  case detail::value_t::array:
12756  {
12757  if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12758  {
12759  // "-" always fails the range check
12760  JSON_THROW(detail::out_of_range::create(402,
12761  "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12762  ") is out of range", *ptr));
12763  }
12764 
12765  // note: at performs range check
12766  ptr = &ptr->at(array_index(reference_token));
12767  break;
12768  }
12769 
12770  default:
12771  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
12772  }
12773  }
12774 
12775  return *ptr;
12776  }
12777 
12782  bool contains(const BasicJsonType* ptr) const
12783  {
12784  for (const auto& reference_token : reference_tokens)
12785  {
12786  switch (ptr->type())
12787  {
12788  case detail::value_t::object:
12789  {
12790  if (!ptr->contains(reference_token))
12791  {
12792  // we did not find the key in the object
12793  return false;
12794  }
12795 
12796  ptr = &ptr->operator[](reference_token);
12797  break;
12798  }
12799 
12800  case detail::value_t::array:
12801  {
12802  if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12803  {
12804  // "-" always fails the range check
12805  return false;
12806  }
12807  if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !("0" <= reference_token && reference_token <= "9")))
12808  {
12809  // invalid char
12810  return false;
12811  }
12812  if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
12813  {
12814  if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9')))
12815  {
12816  // first char should be between '1' and '9'
12817  return false;
12818  }
12819  for (std::size_t i = 1; i < reference_token.size(); i++)
12820  {
12821  if (JSON_HEDLEY_UNLIKELY(!('0' <= reference_token[i] && reference_token[i] <= '9')))
12822  {
12823  // other char should be between '0' and '9'
12824  return false;
12825  }
12826  }
12827  }
12828 
12829  const auto idx = array_index(reference_token);
12830  if (idx >= ptr->size())
12831  {
12832  // index out of range
12833  return false;
12834  }
12835 
12836  ptr = &ptr->operator[](idx);
12837  break;
12838  }
12839 
12840  default:
12841  {
12842  // we do not expect primitive values if there is still a
12843  // reference token to process
12844  return false;
12845  }
12846  }
12847  }
12848 
12849  // no reference token left means we found a primitive value
12850  return true;
12851  }
12852 
12862  static std::vector<std::string> split(const std::string& reference_string)
12863  {
12864  std::vector<std::string> result;
12865 
12866  // special case: empty reference string -> no reference tokens
12867  if (reference_string.empty())
12868  {
12869  return result;
12870  }
12871 
12872  // check if nonempty reference string begins with slash
12873  if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
12874  {
12875  JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", BasicJsonType()));
12876  }
12877 
12878  // extract the reference tokens:
12879  // - slash: position of the last read slash (or end of string)
12880  // - start: position after the previous slash
12881  for (
12882  // search for the first slash after the first character
12883  std::size_t slash = reference_string.find_first_of('/', 1),
12884  // set the beginning of the first reference token
12885  start = 1;
12886  // we can stop if start == 0 (if slash == std::string::npos)
12887  start != 0;
12888  // set the beginning of the next reference token
12889  // (will eventually be 0 if slash == std::string::npos)
12890  start = (slash == std::string::npos) ? 0 : slash + 1,
12891  // find next slash
12892  slash = reference_string.find_first_of('/', start))
12893  {
12894  // use the text between the beginning of the reference token
12895  // (start) and the last slash (slash).
12896  auto reference_token = reference_string.substr(start, slash - start);
12897 
12898  // check reference tokens are properly escaped
12899  for (std::size_t pos = reference_token.find_first_of('~');
12900  pos != std::string::npos;
12901  pos = reference_token.find_first_of('~', pos + 1))
12902  {
12903  JSON_ASSERT(reference_token[pos] == '~');
12904 
12905  // ~ must be followed by 0 or 1
12906  if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
12907  (reference_token[pos + 1] != '0' &&
12908  reference_token[pos + 1] != '1')))
12909  {
12910  JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", BasicJsonType()));
12911  }
12912  }
12913 
12914  // finally, store the reference token
12915  detail::unescape(reference_token);
12916  result.push_back(reference_token);
12917  }
12918 
12919  return result;
12920  }
12921 
12922  private:
12930  static void flatten(const std::string& reference_string,
12931  const BasicJsonType& value,
12932  BasicJsonType& result)
12933  {
12934  switch (value.type())
12935  {
12936  case detail::value_t::array:
12937  {
12938  if (value.m_value.array->empty())
12939  {
12940  // flatten empty array as null
12941  result[reference_string] = nullptr;
12942  }
12943  else
12944  {
12945  // iterate array and use index as reference string
12946  for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
12947  {
12948  flatten(reference_string + "/" + std::to_string(i),
12949  value.m_value.array->operator[](i), result);
12950  }
12951  }
12952  break;
12953  }
12954 
12955  case detail::value_t::object:
12956  {
12957  if (value.m_value.object->empty())
12958  {
12959  // flatten empty object as null
12960  result[reference_string] = nullptr;
12961  }
12962  else
12963  {
12964  // iterate object and use keys as reference string
12965  for (const auto& element : *value.m_value.object)
12966  {
12967  flatten(reference_string + "/" + detail::escape(element.first), element.second, result);
12968  }
12969  }
12970  break;
12971  }
12972 
12973  default:
12974  {
12975  // add primitive value with its reference string
12976  result[reference_string] = value;
12977  break;
12978  }
12979  }
12980  }
12981 
12992  static BasicJsonType
12993  unflatten(const BasicJsonType& value)
12994  {
12995  if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
12996  {
12997  JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", value));
12998  }
12999 
13000  BasicJsonType result;
13001 
13002  // iterate the JSON object values
13003  for (const auto& element : *value.m_value.object)
13004  {
13005  if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
13006  {
13007  JSON_THROW(detail::type_error::create(315, "values in object must be primitive", element.second));
13008  }
13009 
13010  // assign value to reference pointed to by JSON pointer; Note that if
13011  // the JSON pointer is "" (i.e., points to the whole value), function
13012  // get_and_create returns a reference to result itself. An assignment
13013  // will then create a primitive value.
13014  json_pointer(element.first).get_and_create(result) = element.second;
13015  }
13016 
13017  return result;
13018  }
13019 
13031  friend bool operator==(json_pointer const& lhs,
13032  json_pointer const& rhs) noexcept
13033  {
13034  return lhs.reference_tokens == rhs.reference_tokens;
13035  }
13036 
13048  friend bool operator!=(json_pointer const& lhs,
13049  json_pointer const& rhs) noexcept
13050  {
13051  return !(lhs == rhs);
13052  }
13053 
13055  std::vector<std::string> reference_tokens;
13056 };
13057 } // namespace nlohmann
13058 
13059 // #include <nlohmann/detail/json_ref.hpp>
13060 
13061 
13062 #include <initializer_list>
13063 #include <utility>
13064 
13065 // #include <nlohmann/detail/meta/type_traits.hpp>
13066 
13067 
13068 namespace nlohmann
13069 {
13070 namespace detail
13071 {
13072 template<typename BasicJsonType>
13073 class json_ref
13074 {
13075  public:
13076  using value_type = BasicJsonType;
13077 
13078  json_ref(value_type&& value)
13079  : owned_value(std::move(value))
13080  {}
13081 
13082  json_ref(const value_type& value)
13083  : value_ref(&value)
13084  {}
13085 
13086  json_ref(std::initializer_list<json_ref> init)
13087  : owned_value(init)
13088  {}
13089 
13090  template <
13091  class... Args,
13092  enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
13093  json_ref(Args && ... args)
13094  : owned_value(std::forward<Args>(args)...)
13095  {}
13096 
13097  // class should be movable only
13098  json_ref(json_ref&&) noexcept = default;
13099  json_ref(const json_ref&) = delete;
13100  json_ref& operator=(const json_ref&) = delete;
13101  json_ref& operator=(json_ref&&) = delete;
13102  ~json_ref() = default;
13103 
13104  value_type moved_or_copied() const
13105  {
13106  if (value_ref == nullptr)
13107  {
13108  return std::move(owned_value);
13109  }
13110  return *value_ref;
13111  }
13112 
13113  value_type const& operator*() const
13114  {
13115  return value_ref ? *value_ref : owned_value;
13116  }
13117 
13118  value_type const* operator->() const
13119  {
13120  return &** this;
13121  }
13122 
13123  private:
13124  mutable value_type owned_value = nullptr;
13125  value_type const* value_ref = nullptr;
13126 };
13127 } // namespace detail
13128 } // namespace nlohmann
13129 
13130 // #include <nlohmann/detail/macro_scope.hpp>
13131 
13132 // #include <nlohmann/detail/string_escape.hpp>
13133 
13134 // #include <nlohmann/detail/meta/cpp_future.hpp>
13135 
13136 // #include <nlohmann/detail/meta/type_traits.hpp>
13137 
13138 // #include <nlohmann/detail/output/binary_writer.hpp>
13139 
13140 
13141 #include <algorithm> // reverse
13142 #include <array> // array
13143 #include <cmath> // isnan, isinf
13144 #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
13145 #include <cstring> // memcpy
13146 #include <limits> // numeric_limits
13147 #include <string> // string
13148 #include <utility> // move
13149 
13150 // #include <nlohmann/detail/input/binary_reader.hpp>
13151 
13152 // #include <nlohmann/detail/macro_scope.hpp>
13153 
13154 // #include <nlohmann/detail/output/output_adapters.hpp>
13155 
13156 
13157 #include <algorithm> // copy
13158 #include <cstddef> // size_t
13159 #include <iterator> // back_inserter
13160 #include <memory> // shared_ptr, make_shared
13161 #include <string> // basic_string
13162 #include <vector> // vector
13163 
13164 #ifndef JSON_NO_IO
13165  #include <ios> // streamsize
13166  #include <ostream> // basic_ostream
13167 #endif // JSON_NO_IO
13168 
13169 // #include <nlohmann/detail/macro_scope.hpp>
13170 
13171 
13172 namespace nlohmann
13173 {
13174 namespace detail
13175 {
13177 template<typename CharType> struct output_adapter_protocol
13178 {
13179  virtual void write_character(CharType c) = 0;
13180  virtual void write_characters(const CharType* s, std::size_t length) = 0;
13181  virtual ~output_adapter_protocol() = default;
13182 
13183  output_adapter_protocol() = default;
13184  output_adapter_protocol(const output_adapter_protocol&) = default;
13185  output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
13186  output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
13187  output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
13188 };
13189 
13191 template<typename CharType>
13192 using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
13193 
13195 template<typename CharType>
13196 class output_vector_adapter : public output_adapter_protocol<CharType>
13197 {
13198  public:
13199  explicit output_vector_adapter(std::vector<CharType>& vec) noexcept
13200  : v(vec)
13201  {}
13202 
13203  void write_character(CharType c) override
13204  {
13205  v.push_back(c);
13206  }
13207 
13208  JSON_HEDLEY_NON_NULL(2)
13209  void write_characters(const CharType* s, std::size_t length) override
13210  {
13211  std::copy(s, s + length, std::back_inserter(v));
13212  }
13213 
13214  private:
13215  std::vector<CharType>& v;
13216 };
13217 
13218 #ifndef JSON_NO_IO
13220 template<typename CharType>
13221 class output_stream_adapter : public output_adapter_protocol<CharType>
13222 {
13223  public:
13224  explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
13225  : stream(s)
13226  {}
13227 
13228  void write_character(CharType c) override
13229  {
13230  stream.put(c);
13231  }
13232 
13233  JSON_HEDLEY_NON_NULL(2)
13234  void write_characters(const CharType* s, std::size_t length) override
13235  {
13236  stream.write(s, static_cast<std::streamsize>(length));
13237  }
13238 
13239  private:
13240  std::basic_ostream<CharType>& stream;
13241 };
13242 #endif // JSON_NO_IO
13243 
13245 template<typename CharType, typename StringType = std::basic_string<CharType>>
13246 class output_string_adapter : public output_adapter_protocol<CharType>
13247 {
13248  public:
13249  explicit output_string_adapter(StringType& s) noexcept
13250  : str(s)
13251  {}
13252 
13253  void write_character(CharType c) override
13254  {
13255  str.push_back(c);
13256  }
13257 
13258  JSON_HEDLEY_NON_NULL(2)
13259  void write_characters(const CharType* s, std::size_t length) override
13260  {
13261  str.append(s, length);
13262  }
13263 
13264  private:
13265  StringType& str;
13266 };
13267 
13268 template<typename CharType, typename StringType = std::basic_string<CharType>>
13269 class output_adapter
13270 {
13271  public:
13272  output_adapter(std::vector<CharType>& vec)
13273  : oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {}
13274 
13275 #ifndef JSON_NO_IO
13276  output_adapter(std::basic_ostream<CharType>& s)
13277  : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
13278 #endif // JSON_NO_IO
13279 
13280  output_adapter(StringType& s)
13281  : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
13282 
13283  operator output_adapter_t<CharType>()
13284  {
13285  return oa;
13286  }
13287 
13288  private:
13289  output_adapter_t<CharType> oa = nullptr;
13290 };
13291 } // namespace detail
13292 } // namespace nlohmann
13293 
13294 
13295 namespace nlohmann
13296 {
13297 namespace detail
13298 {
13300 // binary writer //
13302 
13306 template<typename BasicJsonType, typename CharType>
13307 class binary_writer
13308 {
13309  using string_t = typename BasicJsonType::string_t;
13310  using binary_t = typename BasicJsonType::binary_t;
13311  using number_float_t = typename BasicJsonType::number_float_t;
13312 
13313  public:
13319  explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
13320  {
13321  JSON_ASSERT(oa);
13322  }
13323 
13328  void write_bson(const BasicJsonType& j)
13329  {
13330  switch (j.type())
13331  {
13332  case value_t::object:
13333  {
13334  write_bson_object(*j.m_value.object);
13335  break;
13336  }
13337 
13338  default:
13339  {
13340  JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));;
13341  }
13342  }
13343  }
13344 
13348  void write_cbor(const BasicJsonType& j)
13349  {
13350  switch (j.type())
13351  {
13352  case value_t::null:
13353  {
13354  oa->write_character(to_char_type(0xF6));
13355  break;
13356  }
13357 
13358  case value_t::boolean:
13359  {
13360  oa->write_character(j.m_value.boolean
13361  ? to_char_type(0xF5)
13362  : to_char_type(0xF4));
13363  break;
13364  }
13365 
13366  case value_t::number_integer:
13367  {
13368  if (j.m_value.number_integer >= 0)
13369  {
13370  // CBOR does not differentiate between positive signed
13371  // integers and unsigned integers. Therefore, we used the
13372  // code from the value_t::number_unsigned case here.
13373  if (j.m_value.number_integer <= 0x17)
13374  {
13375  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13376  }
13377  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
13378  {
13379  oa->write_character(to_char_type(0x18));
13380  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13381  }
13382  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
13383  {
13384  oa->write_character(to_char_type(0x19));
13385  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
13386  }
13387  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
13388  {
13389  oa->write_character(to_char_type(0x1A));
13390  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
13391  }
13392  else
13393  {
13394  oa->write_character(to_char_type(0x1B));
13395  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
13396  }
13397  }
13398  else
13399  {
13400  // The conversions below encode the sign in the first
13401  // byte, and the value is converted to a positive number.
13402  const auto positive_number = -1 - j.m_value.number_integer;
13403  if (j.m_value.number_integer >= -24)
13404  {
13405  write_number(static_cast<std::uint8_t>(0x20 + positive_number));
13406  }
13407  else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
13408  {
13409  oa->write_character(to_char_type(0x38));
13410  write_number(static_cast<std::uint8_t>(positive_number));
13411  }
13412  else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
13413  {
13414  oa->write_character(to_char_type(0x39));
13415  write_number(static_cast<std::uint16_t>(positive_number));
13416  }
13417  else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
13418  {
13419  oa->write_character(to_char_type(0x3A));
13420  write_number(static_cast<std::uint32_t>(positive_number));
13421  }
13422  else
13423  {
13424  oa->write_character(to_char_type(0x3B));
13425  write_number(static_cast<std::uint64_t>(positive_number));
13426  }
13427  }
13428  break;
13429  }
13430 
13431  case value_t::number_unsigned:
13432  {
13433  if (j.m_value.number_unsigned <= 0x17)
13434  {
13435  write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
13436  }
13437  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13438  {
13439  oa->write_character(to_char_type(0x18));
13440  write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
13441  }
13442  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13443  {
13444  oa->write_character(to_char_type(0x19));
13445  write_number(static_cast<std::uint16_t>(j.m_value.number_unsigned));
13446  }
13447  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13448  {
13449  oa->write_character(to_char_type(0x1A));
13450  write_number(static_cast<std::uint32_t>(j.m_value.number_unsigned));
13451  }
13452  else
13453  {
13454  oa->write_character(to_char_type(0x1B));
13455  write_number(static_cast<std::uint64_t>(j.m_value.number_unsigned));
13456  }
13457  break;
13458  }
13459 
13460  case value_t::number_float:
13461  {
13462  if (std::isnan(j.m_value.number_float))
13463  {
13464  // NaN is 0xf97e00 in CBOR
13465  oa->write_character(to_char_type(0xF9));
13466  oa->write_character(to_char_type(0x7E));
13467  oa->write_character(to_char_type(0x00));
13468  }
13469  else if (std::isinf(j.m_value.number_float))
13470  {
13471  // Infinity is 0xf97c00, -Infinity is 0xf9fc00
13472  oa->write_character(to_char_type(0xf9));
13473  oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
13474  oa->write_character(to_char_type(0x00));
13475  }
13476  else
13477  {
13478  write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
13479  }
13480  break;
13481  }
13482 
13483  case value_t::string:
13484  {
13485  // step 1: write control byte and the string length
13486  const auto N = j.m_value.string->size();
13487  if (N <= 0x17)
13488  {
13489  write_number(static_cast<std::uint8_t>(0x60 + N));
13490  }
13491  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13492  {
13493  oa->write_character(to_char_type(0x78));
13494  write_number(static_cast<std::uint8_t>(N));
13495  }
13496  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13497  {
13498  oa->write_character(to_char_type(0x79));
13499  write_number(static_cast<std::uint16_t>(N));
13500  }
13501  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13502  {
13503  oa->write_character(to_char_type(0x7A));
13504  write_number(static_cast<std::uint32_t>(N));
13505  }
13506  // LCOV_EXCL_START
13507  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13508  {
13509  oa->write_character(to_char_type(0x7B));
13510  write_number(static_cast<std::uint64_t>(N));
13511  }
13512  // LCOV_EXCL_STOP
13513 
13514  // step 2: write the string
13515  oa->write_characters(
13516  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
13517  j.m_value.string->size());
13518  break;
13519  }
13520 
13521  case value_t::array:
13522  {
13523  // step 1: write control byte and the array size
13524  const auto N = j.m_value.array->size();
13525  if (N <= 0x17)
13526  {
13527  write_number(static_cast<std::uint8_t>(0x80 + N));
13528  }
13529  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13530  {
13531  oa->write_character(to_char_type(0x98));
13532  write_number(static_cast<std::uint8_t>(N));
13533  }
13534  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13535  {
13536  oa->write_character(to_char_type(0x99));
13537  write_number(static_cast<std::uint16_t>(N));
13538  }
13539  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13540  {
13541  oa->write_character(to_char_type(0x9A));
13542  write_number(static_cast<std::uint32_t>(N));
13543  }
13544  // LCOV_EXCL_START
13545  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13546  {
13547  oa->write_character(to_char_type(0x9B));
13548  write_number(static_cast<std::uint64_t>(N));
13549  }
13550  // LCOV_EXCL_STOP
13551 
13552  // step 2: write each element
13553  for (const auto& el : *j.m_value.array)
13554  {
13555  write_cbor(el);
13556  }
13557  break;
13558  }
13559 
13560  case value_t::binary:
13561  {
13562  if (j.m_value.binary->has_subtype())
13563  {
13564  write_number(static_cast<std::uint8_t>(0xd8));
13565  write_number(j.m_value.binary->subtype());
13566  }
13567 
13568  // step 1: write control byte and the binary array size
13569  const auto N = j.m_value.binary->size();
13570  if (N <= 0x17)
13571  {
13572  write_number(static_cast<std::uint8_t>(0x40 + N));
13573  }
13574  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13575  {
13576  oa->write_character(to_char_type(0x58));
13577  write_number(static_cast<std::uint8_t>(N));
13578  }
13579  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13580  {
13581  oa->write_character(to_char_type(0x59));
13582  write_number(static_cast<std::uint16_t>(N));
13583  }
13584  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13585  {
13586  oa->write_character(to_char_type(0x5A));
13587  write_number(static_cast<std::uint32_t>(N));
13588  }
13589  // LCOV_EXCL_START
13590  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13591  {
13592  oa->write_character(to_char_type(0x5B));
13593  write_number(static_cast<std::uint64_t>(N));
13594  }
13595  // LCOV_EXCL_STOP
13596 
13597  // step 2: write each element
13598  oa->write_characters(
13599  reinterpret_cast<const CharType*>(j.m_value.binary->data()),
13600  N);
13601 
13602  break;
13603  }
13604 
13605  case value_t::object:
13606  {
13607  // step 1: write control byte and the object size
13608  const auto N = j.m_value.object->size();
13609  if (N <= 0x17)
13610  {
13611  write_number(static_cast<std::uint8_t>(0xA0 + N));
13612  }
13613  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13614  {
13615  oa->write_character(to_char_type(0xB8));
13616  write_number(static_cast<std::uint8_t>(N));
13617  }
13618  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13619  {
13620  oa->write_character(to_char_type(0xB9));
13621  write_number(static_cast<std::uint16_t>(N));
13622  }
13623  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13624  {
13625  oa->write_character(to_char_type(0xBA));
13626  write_number(static_cast<std::uint32_t>(N));
13627  }
13628  // LCOV_EXCL_START
13629  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13630  {
13631  oa->write_character(to_char_type(0xBB));
13632  write_number(static_cast<std::uint64_t>(N));
13633  }
13634  // LCOV_EXCL_STOP
13635 
13636  // step 2: write each element
13637  for (const auto& el : *j.m_value.object)
13638  {
13639  write_cbor(el.first);
13640  write_cbor(el.second);
13641  }
13642  break;
13643  }
13644 
13645  default:
13646  break;
13647  }
13648  }
13649 
13653  void write_msgpack(const BasicJsonType& j)
13654  {
13655  switch (j.type())
13656  {
13657  case value_t::null: // nil
13658  {
13659  oa->write_character(to_char_type(0xC0));
13660  break;
13661  }
13662 
13663  case value_t::boolean: // true and false
13664  {
13665  oa->write_character(j.m_value.boolean
13666  ? to_char_type(0xC3)
13667  : to_char_type(0xC2));
13668  break;
13669  }
13670 
13671  case value_t::number_integer:
13672  {
13673  if (j.m_value.number_integer >= 0)
13674  {
13675  // MessagePack does not differentiate between positive
13676  // signed integers and unsigned integers. Therefore, we used
13677  // the code from the value_t::number_unsigned case here.
13678  if (j.m_value.number_unsigned < 128)
13679  {
13680  // positive fixnum
13681  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13682  }
13683  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13684  {
13685  // uint 8
13686  oa->write_character(to_char_type(0xCC));
13687  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13688  }
13689  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13690  {
13691  // uint 16
13692  oa->write_character(to_char_type(0xCD));
13693  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
13694  }
13695  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13696  {
13697  // uint 32
13698  oa->write_character(to_char_type(0xCE));
13699  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
13700  }
13701  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13702  {
13703  // uint 64
13704  oa->write_character(to_char_type(0xCF));
13705  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
13706  }
13707  }
13708  else
13709  {
13710  if (j.m_value.number_integer >= -32)
13711  {
13712  // negative fixnum
13713  write_number(static_cast<std::int8_t>(j.m_value.number_integer));
13714  }
13715  else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
13716  j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
13717  {
13718  // int 8
13719  oa->write_character(to_char_type(0xD0));
13720  write_number(static_cast<std::int8_t>(j.m_value.number_integer));
13721  }
13722  else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
13723  j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
13724  {
13725  // int 16
13726  oa->write_character(to_char_type(0xD1));
13727  write_number(static_cast<std::int16_t>(j.m_value.number_integer));
13728  }
13729  else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
13730  j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
13731  {
13732  // int 32
13733  oa->write_character(to_char_type(0xD2));
13734  write_number(static_cast<std::int32_t>(j.m_value.number_integer));
13735  }
13736  else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
13737  j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
13738  {
13739  // int 64
13740  oa->write_character(to_char_type(0xD3));
13741  write_number(static_cast<std::int64_t>(j.m_value.number_integer));
13742  }
13743  }
13744  break;
13745  }
13746 
13747  case value_t::number_unsigned:
13748  {
13749  if (j.m_value.number_unsigned < 128)
13750  {
13751  // positive fixnum
13752  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13753  }
13754  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13755  {
13756  // uint 8
13757  oa->write_character(to_char_type(0xCC));
13758  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13759  }
13760  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13761  {
13762  // uint 16
13763  oa->write_character(to_char_type(0xCD));
13764  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
13765  }
13766  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13767  {
13768  // uint 32
13769  oa->write_character(to_char_type(0xCE));
13770  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
13771  }
13772  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13773  {
13774  // uint 64
13775  oa->write_character(to_char_type(0xCF));
13776  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
13777  }
13778  break;
13779  }
13780 
13781  case value_t::number_float:
13782  {
13783  write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
13784  break;
13785  }
13786 
13787  case value_t::string:
13788  {
13789  // step 1: write control byte and the string length
13790  const auto N = j.m_value.string->size();
13791  if (N <= 31)
13792  {
13793  // fixstr
13794  write_number(static_cast<std::uint8_t>(0xA0 | N));
13795  }
13796  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13797  {
13798  // str 8
13799  oa->write_character(to_char_type(0xD9));
13800  write_number(static_cast<std::uint8_t>(N));
13801  }
13802  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13803  {
13804  // str 16
13805  oa->write_character(to_char_type(0xDA));
13806  write_number(static_cast<std::uint16_t>(N));
13807  }
13808  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13809  {
13810  // str 32
13811  oa->write_character(to_char_type(0xDB));
13812  write_number(static_cast<std::uint32_t>(N));
13813  }
13814 
13815  // step 2: write the string
13816  oa->write_characters(
13817  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
13818  j.m_value.string->size());
13819  break;
13820  }
13821 
13822  case value_t::array:
13823  {
13824  // step 1: write control byte and the array size
13825  const auto N = j.m_value.array->size();
13826  if (N <= 15)
13827  {
13828  // fixarray
13829  write_number(static_cast<std::uint8_t>(0x90 | N));
13830  }
13831  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13832  {
13833  // array 16
13834  oa->write_character(to_char_type(0xDC));
13835  write_number(static_cast<std::uint16_t>(N));
13836  }
13837  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13838  {
13839  // array 32
13840  oa->write_character(to_char_type(0xDD));
13841  write_number(static_cast<std::uint32_t>(N));
13842  }
13843 
13844  // step 2: write each element
13845  for (const auto& el : *j.m_value.array)
13846  {
13847  write_msgpack(el);
13848  }
13849  break;
13850  }
13851 
13852  case value_t::binary:
13853  {
13854  // step 0: determine if the binary type has a set subtype to
13855  // determine whether or not to use the ext or fixext types
13856  const bool use_ext = j.m_value.binary->has_subtype();
13857 
13858  // step 1: write control byte and the byte string length
13859  const auto N = j.m_value.binary->size();
13860  if (N <= (std::numeric_limits<std::uint8_t>::max)())
13861  {
13862  std::uint8_t output_type{};
13863  bool fixed = true;
13864  if (use_ext)
13865  {
13866  switch (N)
13867  {
13868  case 1:
13869  output_type = 0xD4; // fixext 1
13870  break;
13871  case 2:
13872  output_type = 0xD5; // fixext 2
13873  break;
13874  case 4:
13875  output_type = 0xD6; // fixext 4
13876  break;
13877  case 8:
13878  output_type = 0xD7; // fixext 8
13879  break;
13880  case 16:
13881  output_type = 0xD8; // fixext 16
13882  break;
13883  default:
13884  output_type = 0xC7; // ext 8
13885  fixed = false;
13886  break;
13887  }
13888 
13889  }
13890  else
13891  {
13892  output_type = 0xC4; // bin 8
13893  fixed = false;
13894  }
13895 
13896  oa->write_character(to_char_type(output_type));
13897  if (!fixed)
13898  {
13899  write_number(static_cast<std::uint8_t>(N));
13900  }
13901  }
13902  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13903  {
13904  std::uint8_t output_type = use_ext
13905  ? 0xC8 // ext 16
13906  : 0xC5; // bin 16
13907 
13908  oa->write_character(to_char_type(output_type));
13909  write_number(static_cast<std::uint16_t>(N));
13910  }
13911  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13912  {
13913  std::uint8_t output_type = use_ext
13914  ? 0xC9 // ext 32
13915  : 0xC6; // bin 32
13916 
13917  oa->write_character(to_char_type(output_type));
13918  write_number(static_cast<std::uint32_t>(N));
13919  }
13920 
13921  // step 1.5: if this is an ext type, write the subtype
13922  if (use_ext)
13923  {
13924  write_number(static_cast<std::int8_t>(j.m_value.binary->subtype()));
13925  }
13926 
13927  // step 2: write the byte string
13928  oa->write_characters(
13929  reinterpret_cast<const CharType*>(j.m_value.binary->data()),
13930  N);
13931 
13932  break;
13933  }
13934 
13935  case value_t::object:
13936  {
13937  // step 1: write control byte and the object size
13938  const auto N = j.m_value.object->size();
13939  if (N <= 15)
13940  {
13941  // fixmap
13942  write_number(static_cast<std::uint8_t>(0x80 | (N & 0xF)));
13943  }
13944  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13945  {
13946  // map 16
13947  oa->write_character(to_char_type(0xDE));
13948  write_number(static_cast<std::uint16_t>(N));
13949  }
13950  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13951  {
13952  // map 32
13953  oa->write_character(to_char_type(0xDF));
13954  write_number(static_cast<std::uint32_t>(N));
13955  }
13956 
13957  // step 2: write each element
13958  for (const auto& el : *j.m_value.object)
13959  {
13960  write_msgpack(el.first);
13961  write_msgpack(el.second);
13962  }
13963  break;
13964  }
13965 
13966  default:
13967  break;
13968  }
13969  }
13970 
13977  void write_ubjson(const BasicJsonType& j, const bool use_count,
13978  const bool use_type, const bool add_prefix = true)
13979  {
13980  switch (j.type())
13981  {
13982  case value_t::null:
13983  {
13984  if (add_prefix)
13985  {
13986  oa->write_character(to_char_type('Z'));
13987  }
13988  break;
13989  }
13990 
13991  case value_t::boolean:
13992  {
13993  if (add_prefix)
13994  {
13995  oa->write_character(j.m_value.boolean
13996  ? to_char_type('T')
13997  : to_char_type('F'));
13998  }
13999  break;
14000  }
14001 
14002  case value_t::number_integer:
14003  {
14004  write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
14005  break;
14006  }
14007 
14008  case value_t::number_unsigned:
14009  {
14010  write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
14011  break;
14012  }
14013 
14014  case value_t::number_float:
14015  {
14016  write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
14017  break;
14018  }
14019 
14020  case value_t::string:
14021  {
14022  if (add_prefix)
14023  {
14024  oa->write_character(to_char_type('S'));
14025  }
14026  write_number_with_ubjson_prefix(j.m_value.string->size(), true);
14027  oa->write_characters(
14028  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
14029  j.m_value.string->size());
14030  break;
14031  }
14032 
14033  case value_t::array:
14034  {
14035  if (add_prefix)
14036  {
14037  oa->write_character(to_char_type('['));
14038  }
14039 
14040  bool prefix_required = true;
14041  if (use_type && !j.m_value.array->empty())
14042  {
14043  JSON_ASSERT(use_count);
14044  const CharType first_prefix = ubjson_prefix(j.front());
14045  const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
14046  [this, first_prefix](const BasicJsonType & v)
14047  {
14048  return ubjson_prefix(v) == first_prefix;
14049  });
14050 
14051  if (same_prefix)
14052  {
14053  prefix_required = false;
14054  oa->write_character(to_char_type('$'));
14055  oa->write_character(first_prefix);
14056  }
14057  }
14058 
14059  if (use_count)
14060  {
14061  oa->write_character(to_char_type('#'));
14062  write_number_with_ubjson_prefix(j.m_value.array->size(), true);
14063  }
14064 
14065  for (const auto& el : *j.m_value.array)
14066  {
14067  write_ubjson(el, use_count, use_type, prefix_required);
14068  }
14069 
14070  if (!use_count)
14071  {
14072  oa->write_character(to_char_type(']'));
14073  }
14074 
14075  break;
14076  }
14077 
14078  case value_t::binary:
14079  {
14080  if (add_prefix)
14081  {
14082  oa->write_character(to_char_type('['));
14083  }
14084 
14085  if (use_type && !j.m_value.binary->empty())
14086  {
14087  JSON_ASSERT(use_count);
14088  oa->write_character(to_char_type('$'));
14089  oa->write_character('U');
14090  }
14091 
14092  if (use_count)
14093  {
14094  oa->write_character(to_char_type('#'));
14095  write_number_with_ubjson_prefix(j.m_value.binary->size(), true);
14096  }
14097 
14098  if (use_type)
14099  {
14100  oa->write_characters(
14101  reinterpret_cast<const CharType*>(j.m_value.binary->data()),
14102  j.m_value.binary->size());
14103  }
14104  else
14105  {
14106  for (size_t i = 0; i < j.m_value.binary->size(); ++i)
14107  {
14108  oa->write_character(to_char_type('U'));
14109  oa->write_character(j.m_value.binary->data()[i]);
14110  }
14111  }
14112 
14113  if (!use_count)
14114  {
14115  oa->write_character(to_char_type(']'));
14116  }
14117 
14118  break;
14119  }
14120 
14121  case value_t::object:
14122  {
14123  if (add_prefix)
14124  {
14125  oa->write_character(to_char_type('{'));
14126  }
14127 
14128  bool prefix_required = true;
14129  if (use_type && !j.m_value.object->empty())
14130  {
14131  JSON_ASSERT(use_count);
14132  const CharType first_prefix = ubjson_prefix(j.front());
14133  const bool same_prefix = std::all_of(j.begin(), j.end(),
14134  [this, first_prefix](const BasicJsonType & v)
14135  {
14136  return ubjson_prefix(v) == first_prefix;
14137  });
14138 
14139  if (same_prefix)
14140  {
14141  prefix_required = false;
14142  oa->write_character(to_char_type('$'));
14143  oa->write_character(first_prefix);
14144  }
14145  }
14146 
14147  if (use_count)
14148  {
14149  oa->write_character(to_char_type('#'));
14150  write_number_with_ubjson_prefix(j.m_value.object->size(), true);
14151  }
14152 
14153  for (const auto& el : *j.m_value.object)
14154  {
14155  write_number_with_ubjson_prefix(el.first.size(), true);
14156  oa->write_characters(
14157  reinterpret_cast<const CharType*>(el.first.c_str()),
14158  el.first.size());
14159  write_ubjson(el.second, use_count, use_type, prefix_required);
14160  }
14161 
14162  if (!use_count)
14163  {
14164  oa->write_character(to_char_type('}'));
14165  }
14166 
14167  break;
14168  }
14169 
14170  default:
14171  break;
14172  }
14173  }
14174 
14175  private:
14177  // BSON //
14179 
14184  static std::size_t calc_bson_entry_header_size(const string_t& name, const BasicJsonType& j)
14185  {
14186  const auto it = name.find(static_cast<typename string_t::value_type>(0));
14187  if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
14188  {
14189  JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", j));
14190  }
14191 
14192  return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;
14193  }
14194 
14198  void write_bson_entry_header(const string_t& name,
14199  const std::uint8_t element_type)
14200  {
14201  oa->write_character(to_char_type(element_type)); // boolean
14202  oa->write_characters(
14203  reinterpret_cast<const CharType*>(name.c_str()),
14204  name.size() + 1u);
14205  }
14206 
14210  void write_bson_boolean(const string_t& name,
14211  const bool value)
14212  {
14213  write_bson_entry_header(name, 0x08);
14214  oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
14215  }
14216 
14220  void write_bson_double(const string_t& name,
14221  const double value)
14222  {
14223  write_bson_entry_header(name, 0x01);
14224  write_number<double, true>(value);
14225  }
14226 
14230  static std::size_t calc_bson_string_size(const string_t& value)
14231  {
14232  return sizeof(std::int32_t) + value.size() + 1ul;
14233  }
14234 
14238  void write_bson_string(const string_t& name,
14239  const string_t& value)
14240  {
14241  write_bson_entry_header(name, 0x02);
14242 
14243  write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size() + 1ul));
14244  oa->write_characters(
14245  reinterpret_cast<const CharType*>(value.c_str()),
14246  value.size() + 1);
14247  }
14248 
14252  void write_bson_null(const string_t& name)
14253  {
14254  write_bson_entry_header(name, 0x0A);
14255  }
14256 
14260  static std::size_t calc_bson_integer_size(const std::int64_t value)
14261  {
14262  return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
14263  ? sizeof(std::int32_t)
14264  : sizeof(std::int64_t);
14265  }
14266 
14270  void write_bson_integer(const string_t& name,
14271  const std::int64_t value)
14272  {
14273  if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
14274  {
14275  write_bson_entry_header(name, 0x10); // int32
14276  write_number<std::int32_t, true>(static_cast<std::int32_t>(value));
14277  }
14278  else
14279  {
14280  write_bson_entry_header(name, 0x12); // int64
14281  write_number<std::int64_t, true>(static_cast<std::int64_t>(value));
14282  }
14283  }
14284 
14288  static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept
14289  {
14290  return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
14291  ? sizeof(std::int32_t)
14292  : sizeof(std::int64_t);
14293  }
14294 
14298  void write_bson_unsigned(const string_t& name,
14299  const BasicJsonType& j)
14300  {
14301  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
14302  {
14303  write_bson_entry_header(name, 0x10 /* int32 */);
14304  write_number<std::int32_t, true>(static_cast<std::int32_t>(j.m_value.number_unsigned));
14305  }
14306  else if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
14307  {
14308  write_bson_entry_header(name, 0x12 /* int64 */);
14309  write_number<std::int64_t, true>(static_cast<std::int64_t>(j.m_value.number_unsigned));
14310  }
14311  else
14312  {
14313  JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BSON as it does not fit int64", j));
14314  }
14315  }
14316 
14320  void write_bson_object_entry(const string_t& name,
14321  const typename BasicJsonType::object_t& value)
14322  {
14323  write_bson_entry_header(name, 0x03); // object
14324  write_bson_object(value);
14325  }
14326 
14330  static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value)
14331  {
14332  std::size_t array_index = 0ul;
14333 
14334  const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), std::size_t(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el)
14335  {
14336  return result + calc_bson_element_size(std::to_string(array_index++), el);
14337  });
14338 
14339  return sizeof(std::int32_t) + embedded_document_size + 1ul;
14340  }
14341 
14345  static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t& value)
14346  {
14347  return sizeof(std::int32_t) + value.size() + 1ul;
14348  }
14349 
14353  void write_bson_array(const string_t& name,
14354  const typename BasicJsonType::array_t& value)
14355  {
14356  write_bson_entry_header(name, 0x04); // array
14357  write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_array_size(value)));
14358 
14359  std::size_t array_index = 0ul;
14360 
14361  for (const auto& el : value)
14362  {
14363  write_bson_element(std::to_string(array_index++), el);
14364  }
14365 
14366  oa->write_character(to_char_type(0x00));
14367  }
14368 
14372  void write_bson_binary(const string_t& name,
14373  const binary_t& value)
14374  {
14375  write_bson_entry_header(name, 0x05);
14376 
14377  write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size()));
14378  write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00));
14379 
14380  oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
14381  }
14382 
14387  static std::size_t calc_bson_element_size(const string_t& name,
14388  const BasicJsonType& j)
14389  {
14390  const auto header_size = calc_bson_entry_header_size(name, j);
14391  switch (j.type())
14392  {
14393  case value_t::object:
14394  return header_size + calc_bson_object_size(*j.m_value.object);
14395 
14396  case value_t::array:
14397  return header_size + calc_bson_array_size(*j.m_value.array);
14398 
14399  case value_t::binary:
14400  return header_size + calc_bson_binary_size(*j.m_value.binary);
14401 
14402  case value_t::boolean:
14403  return header_size + 1ul;
14404 
14405  case value_t::number_float:
14406  return header_size + 8ul;
14407 
14408  case value_t::number_integer:
14409  return header_size + calc_bson_integer_size(j.m_value.number_integer);
14410 
14411  case value_t::number_unsigned:
14412  return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
14413 
14414  case value_t::string:
14415  return header_size + calc_bson_string_size(*j.m_value.string);
14416 
14417  case value_t::null:
14418  return header_size + 0ul;
14419 
14420  // LCOV_EXCL_START
14421  default:
14422  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
14423  return 0ul;
14424  // LCOV_EXCL_STOP
14425  }
14426  }
14427 
14434  void write_bson_element(const string_t& name,
14435  const BasicJsonType& j)
14436  {
14437  switch (j.type())
14438  {
14439  case value_t::object:
14440  return write_bson_object_entry(name, *j.m_value.object);
14441 
14442  case value_t::array:
14443  return write_bson_array(name, *j.m_value.array);
14444 
14445  case value_t::binary:
14446  return write_bson_binary(name, *j.m_value.binary);
14447 
14448  case value_t::boolean:
14449  return write_bson_boolean(name, j.m_value.boolean);
14450 
14451  case value_t::number_float:
14452  return write_bson_double(name, j.m_value.number_float);
14453 
14454  case value_t::number_integer:
14455  return write_bson_integer(name, j.m_value.number_integer);
14456 
14457  case value_t::number_unsigned:
14458  return write_bson_unsigned(name, j);
14459 
14460  case value_t::string:
14461  return write_bson_string(name, *j.m_value.string);
14462 
14463  case value_t::null:
14464  return write_bson_null(name);
14465 
14466  // LCOV_EXCL_START
14467  default:
14468  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
14469  return;
14470  // LCOV_EXCL_STOP
14471  }
14472  }
14473 
14480  static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value)
14481  {
14482  std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
14483  [](size_t result, const typename BasicJsonType::object_t::value_type & el)
14484  {
14485  return result += calc_bson_element_size(el.first, el.second);
14486  });
14487 
14488  return sizeof(std::int32_t) + document_size + 1ul;
14489  }
14490 
14495  void write_bson_object(const typename BasicJsonType::object_t& value)
14496  {
14497  write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_object_size(value)));
14498 
14499  for (const auto& el : value)
14500  {
14501  write_bson_element(el.first, el.second);
14502  }
14503 
14504  oa->write_character(to_char_type(0x00));
14505  }
14506 
14508  // CBOR //
14510 
14511  static constexpr CharType get_cbor_float_prefix(float /*unused*/)
14512  {
14513  return to_char_type(0xFA); // Single-Precision Float
14514  }
14515 
14516  static constexpr CharType get_cbor_float_prefix(double /*unused*/)
14517  {
14518  return to_char_type(0xFB); // Double-Precision Float
14519  }
14520 
14522  // MsgPack //
14524 
14525  static constexpr CharType get_msgpack_float_prefix(float /*unused*/)
14526  {
14527  return to_char_type(0xCA); // float 32
14528  }
14529 
14530  static constexpr CharType get_msgpack_float_prefix(double /*unused*/)
14531  {
14532  return to_char_type(0xCB); // float 64
14533  }
14534 
14536  // UBJSON //
14538 
14539  // UBJSON: write number (floating point)
14540  template<typename NumberType, typename std::enable_if<
14541  std::is_floating_point<NumberType>::value, int>::type = 0>
14542  void write_number_with_ubjson_prefix(const NumberType n,
14543  const bool add_prefix)
14544  {
14545  if (add_prefix)
14546  {
14547  oa->write_character(get_ubjson_float_prefix(n));
14548  }
14549  write_number(n);
14550  }
14551 
14552  // UBJSON: write number (unsigned integer)
14553  template<typename NumberType, typename std::enable_if<
14554  std::is_unsigned<NumberType>::value, int>::type = 0>
14555  void write_number_with_ubjson_prefix(const NumberType n,
14556  const bool add_prefix)
14557  {
14558  if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
14559  {
14560  if (add_prefix)
14561  {
14562  oa->write_character(to_char_type('i')); // int8
14563  }
14564  write_number(static_cast<std::uint8_t>(n));
14565  }
14566  else if (n <= (std::numeric_limits<std::uint8_t>::max)())
14567  {
14568  if (add_prefix)
14569  {
14570  oa->write_character(to_char_type('U')); // uint8
14571  }
14572  write_number(static_cast<std::uint8_t>(n));
14573  }
14574  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
14575  {
14576  if (add_prefix)
14577  {
14578  oa->write_character(to_char_type('I')); // int16
14579  }
14580  write_number(static_cast<std::int16_t>(n));
14581  }
14582  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
14583  {
14584  if (add_prefix)
14585  {
14586  oa->write_character(to_char_type('l')); // int32
14587  }
14588  write_number(static_cast<std::int32_t>(n));
14589  }
14590  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
14591  {
14592  if (add_prefix)
14593  {
14594  oa->write_character(to_char_type('L')); // int64
14595  }
14596  write_number(static_cast<std::int64_t>(n));
14597  }
14598  else
14599  {
14600  if (add_prefix)
14601  {
14602  oa->write_character(to_char_type('H')); // high-precision number
14603  }
14604 
14605  const auto number = BasicJsonType(n).dump();
14606  write_number_with_ubjson_prefix(number.size(), true);
14607  for (std::size_t i = 0; i < number.size(); ++i)
14608  {
14609  oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));
14610  }
14611  }
14612  }
14613 
14614  // UBJSON: write number (signed integer)
14615  template < typename NumberType, typename std::enable_if <
14616  std::is_signed<NumberType>::value&&
14617  !std::is_floating_point<NumberType>::value, int >::type = 0 >
14618  void write_number_with_ubjson_prefix(const NumberType n,
14619  const bool add_prefix)
14620  {
14621  if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
14622  {
14623  if (add_prefix)
14624  {
14625  oa->write_character(to_char_type('i')); // int8
14626  }
14627  write_number(static_cast<std::int8_t>(n));
14628  }
14629  else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)()))
14630  {
14631  if (add_prefix)
14632  {
14633  oa->write_character(to_char_type('U')); // uint8
14634  }
14635  write_number(static_cast<std::uint8_t>(n));
14636  }
14637  else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
14638  {
14639  if (add_prefix)
14640  {
14641  oa->write_character(to_char_type('I')); // int16
14642  }
14643  write_number(static_cast<std::int16_t>(n));
14644  }
14645  else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
14646  {
14647  if (add_prefix)
14648  {
14649  oa->write_character(to_char_type('l')); // int32
14650  }
14651  write_number(static_cast<std::int32_t>(n));
14652  }
14653  else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
14654  {
14655  if (add_prefix)
14656  {
14657  oa->write_character(to_char_type('L')); // int64
14658  }
14659  write_number(static_cast<std::int64_t>(n));
14660  }
14661  // LCOV_EXCL_START
14662  else
14663  {
14664  if (add_prefix)
14665  {
14666  oa->write_character(to_char_type('H')); // high-precision number
14667  }
14668 
14669  const auto number = BasicJsonType(n).dump();
14670  write_number_with_ubjson_prefix(number.size(), true);
14671  for (std::size_t i = 0; i < number.size(); ++i)
14672  {
14673  oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));
14674  }
14675  }
14676  // LCOV_EXCL_STOP
14677  }
14678 
14682  CharType ubjson_prefix(const BasicJsonType& j) const noexcept
14683  {
14684  switch (j.type())
14685  {
14686  case value_t::null:
14687  return 'Z';
14688 
14689  case value_t::boolean:
14690  return j.m_value.boolean ? 'T' : 'F';
14691 
14692  case value_t::number_integer:
14693  {
14694  if ((std::numeric_limits<std::int8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
14695  {
14696  return 'i';
14697  }
14698  if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
14699  {
14700  return 'U';
14701  }
14702  if ((std::numeric_limits<std::int16_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
14703  {
14704  return 'I';
14705  }
14706  if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
14707  {
14708  return 'l';
14709  }
14710  if ((std::numeric_limits<std::int64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
14711  {
14712  return 'L';
14713  }
14714  // anything else is treated as high-precision number
14715  return 'H'; // LCOV_EXCL_LINE
14716  }
14717 
14718  case value_t::number_unsigned:
14719  {
14720  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
14721  {
14722  return 'i';
14723  }
14724  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint8_t>::max)()))
14725  {
14726  return 'U';
14727  }
14728  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
14729  {
14730  return 'I';
14731  }
14732  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
14733  {
14734  return 'l';
14735  }
14736  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
14737  {
14738  return 'L';
14739  }
14740  // anything else is treated as high-precision number
14741  return 'H'; // LCOV_EXCL_LINE
14742  }
14743 
14744  case value_t::number_float:
14745  return get_ubjson_float_prefix(j.m_value.number_float);
14746 
14747  case value_t::string:
14748  return 'S';
14749 
14750  case value_t::array: // fallthrough
14751  case value_t::binary:
14752  return '[';
14753 
14754  case value_t::object:
14755  return '{';
14756 
14757  default: // discarded values
14758  return 'N';
14759  }
14760  }
14761 
14762  static constexpr CharType get_ubjson_float_prefix(float /*unused*/)
14763  {
14764  return 'd'; // float 32
14765  }
14766 
14767  static constexpr CharType get_ubjson_float_prefix(double /*unused*/)
14768  {
14769  return 'D'; // float 64
14770  }
14771 
14773  // Utility functions //
14775 
14776  /*
14777  @brief write a number to output input
14778  @param[in] n number of type @a NumberType
14779  @tparam NumberType the type of the number
14780  @tparam OutputIsLittleEndian Set to true if output data is
14781  required to be little endian
14782 
14783  @note This function needs to respect the system's endianess, because bytes
14784  in CBOR, MessagePack, and UBJSON are stored in network order (big
14785  endian) and therefore need reordering on little endian systems.
14786  */
14787  template<typename NumberType, bool OutputIsLittleEndian = false>
14788  void write_number(const NumberType n)
14789  {
14790  // step 1: write number to array of length NumberType
14791  std::array<CharType, sizeof(NumberType)> vec{};
14792  std::memcpy(vec.data(), &n, sizeof(NumberType));
14793 
14794  // step 2: write array to output (with possible reordering)
14795  if (is_little_endian != OutputIsLittleEndian)
14796  {
14797  // reverse byte order prior to conversion if necessary
14798  std::reverse(vec.begin(), vec.end());
14799  }
14800 
14801  oa->write_characters(vec.data(), sizeof(NumberType));
14802  }
14803 
14804  void write_compact_float(const number_float_t n, detail::input_format_t format)
14805  {
14806  if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) &&
14807  static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&
14808  static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))
14809  {
14810  oa->write_character(format == detail::input_format_t::cbor
14811  ? get_cbor_float_prefix(static_cast<float>(n))
14812  : get_msgpack_float_prefix(static_cast<float>(n)));
14813  write_number(static_cast<float>(n));
14814  }
14815  else
14816  {
14817  oa->write_character(format == detail::input_format_t::cbor
14818  ? get_cbor_float_prefix(n)
14819  : get_msgpack_float_prefix(n));
14820  write_number(n);
14821  }
14822  }
14823 
14824  public:
14825  // The following to_char_type functions are implement the conversion
14826  // between uint8_t and CharType. In case CharType is not unsigned,
14827  // such a conversion is required to allow values greater than 128.
14828  // See <https://github.com/nlohmann/json/issues/1286> for a discussion.
14829  template < typename C = CharType,
14830  enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * = nullptr >
14831  static constexpr CharType to_char_type(std::uint8_t x) noexcept
14832  {
14833  return *reinterpret_cast<char*>(&x);
14834  }
14835 
14836  template < typename C = CharType,
14837  enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr >
14838  static CharType to_char_type(std::uint8_t x) noexcept
14839  {
14840  static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
14841  static_assert(std::is_trivial<CharType>::value, "CharType must be trivial");
14842  CharType result;
14843  std::memcpy(&result, &x, sizeof(x));
14844  return result;
14845  }
14846 
14847  template<typename C = CharType,
14848  enable_if_t<std::is_unsigned<C>::value>* = nullptr>
14849  static constexpr CharType to_char_type(std::uint8_t x) noexcept
14850  {
14851  return x;
14852  }
14853 
14854  template < typename InputCharType, typename C = CharType,
14855  enable_if_t <
14856  std::is_signed<C>::value &&
14857  std::is_signed<char>::value &&
14858  std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
14859  > * = nullptr >
14860  static constexpr CharType to_char_type(InputCharType x) noexcept
14861  {
14862  return x;
14863  }
14864 
14865  private:
14867  const bool is_little_endian = little_endianess();
14868 
14870  output_adapter_t<CharType> oa = nullptr;
14871 };
14872 } // namespace detail
14873 } // namespace nlohmann
14874 
14875 // #include <nlohmann/detail/output/output_adapters.hpp>
14876 
14877 // #include <nlohmann/detail/output/serializer.hpp>
14878 
14879 
14880 #include <algorithm> // reverse, remove, fill, find, none_of
14881 #include <array> // array
14882 #include <clocale> // localeconv, lconv
14883 #include <cmath> // labs, isfinite, isnan, signbit
14884 #include <cstddef> // size_t, ptrdiff_t
14885 #include <cstdint> // uint8_t
14886 #include <cstdio> // snprintf
14887 #include <limits> // numeric_limits
14888 #include <string> // string, char_traits
14889 #include <type_traits> // is_same
14890 #include <utility> // move
14891 
14892 // #include <nlohmann/detail/conversions/to_chars.hpp>
14893 
14894 
14895 #include <array> // array
14896 #include <cmath> // signbit, isfinite
14897 #include <cstdint> // intN_t, uintN_t
14898 #include <cstring> // memcpy, memmove
14899 #include <limits> // numeric_limits
14900 #include <type_traits> // conditional
14901 
14902 // #include <nlohmann/detail/macro_scope.hpp>
14903 
14904 
14905 namespace nlohmann
14906 {
14907 namespace detail
14908 {
14909 
14929 namespace dtoa_impl
14930 {
14931 
14932 template<typename Target, typename Source>
14933 Target reinterpret_bits(const Source source)
14934 {
14935  static_assert(sizeof(Target) == sizeof(Source), "size mismatch");
14936 
14937  Target target;
14938  std::memcpy(&target, &source, sizeof(Source));
14939  return target;
14940 }
14941 
14942 struct diyfp // f * 2^e
14943 {
14944  static constexpr int kPrecision = 64; // = q
14945 
14946  std::uint64_t f = 0;
14947  int e = 0;
14948 
14949  constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {}
14950 
14955  static diyfp sub(const diyfp& x, const diyfp& y) noexcept
14956  {
14957  JSON_ASSERT(x.e == y.e);
14958  JSON_ASSERT(x.f >= y.f);
14959 
14960  return {x.f - y.f, x.e};
14961  }
14962 
14967  static diyfp mul(const diyfp& x, const diyfp& y) noexcept
14968  {
14969  static_assert(kPrecision == 64, "internal error");
14970 
14971  // Computes:
14972  // f = round((x.f * y.f) / 2^q)
14973  // e = x.e + y.e + q
14974 
14975  // Emulate the 64-bit * 64-bit multiplication:
14976  //
14977  // p = u * v
14978  // = (u_lo + 2^32 u_hi) (v_lo + 2^32 v_hi)
14979  // = (u_lo v_lo ) + 2^32 ((u_lo v_hi ) + (u_hi v_lo )) + 2^64 (u_hi v_hi )
14980  // = (p0 ) + 2^32 ((p1 ) + (p2 )) + 2^64 (p3 )
14981  // = (p0_lo + 2^32 p0_hi) + 2^32 ((p1_lo + 2^32 p1_hi) + (p2_lo + 2^32 p2_hi)) + 2^64 (p3 )
14982  // = (p0_lo ) + 2^32 (p0_hi + p1_lo + p2_lo ) + 2^64 (p1_hi + p2_hi + p3)
14983  // = (p0_lo ) + 2^32 (Q ) + 2^64 (H )
14984  // = (p0_lo ) + 2^32 (Q_lo + 2^32 Q_hi ) + 2^64 (H )
14985  //
14986  // (Since Q might be larger than 2^32 - 1)
14987  //
14988  // = (p0_lo + 2^32 Q_lo) + 2^64 (Q_hi + H)
14989  //
14990  // (Q_hi + H does not overflow a 64-bit int)
14991  //
14992  // = p_lo + 2^64 p_hi
14993 
14994  const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
14995  const std::uint64_t u_hi = x.f >> 32u;
14996  const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
14997  const std::uint64_t v_hi = y.f >> 32u;
14998 
14999  const std::uint64_t p0 = u_lo * v_lo;
15000  const std::uint64_t p1 = u_lo * v_hi;
15001  const std::uint64_t p2 = u_hi * v_lo;
15002  const std::uint64_t p3 = u_hi * v_hi;
15003 
15004  const std::uint64_t p0_hi = p0 >> 32u;
15005  const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
15006  const std::uint64_t p1_hi = p1 >> 32u;
15007  const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
15008  const std::uint64_t p2_hi = p2 >> 32u;
15009 
15010  std::uint64_t Q = p0_hi + p1_lo + p2_lo;
15011 
15012  // The full product might now be computed as
15013  //
15014  // p_hi = p3 + p2_hi + p1_hi + (Q >> 32)
15015  // p_lo = p0_lo + (Q << 32)
15016  //
15017  // But in this particular case here, the full p_lo is not required.
15018  // Effectively we only need to add the highest bit in p_lo to p_hi (and
15019  // Q_hi + 1 does not overflow).
15020 
15021  Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up
15022 
15023  const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
15024 
15025  return {h, x.e + y.e + 64};
15026  }
15027 
15032  static diyfp normalize(diyfp x) noexcept
15033  {
15034  JSON_ASSERT(x.f != 0);
15035 
15036  while ((x.f >> 63u) == 0)
15037  {
15038  x.f <<= 1u;
15039  x.e--;
15040  }
15041 
15042  return x;
15043  }
15044 
15049  static diyfp normalize_to(const diyfp& x, const int target_exponent) noexcept
15050  {
15051  const int delta = x.e - target_exponent;
15052 
15053  JSON_ASSERT(delta >= 0);
15054  JSON_ASSERT(((x.f << delta) >> delta) == x.f);
15055 
15056  return {x.f << delta, target_exponent};
15057  }
15058 };
15059 
15060 struct boundaries
15061 {
15062  diyfp w;
15063  diyfp minus;
15064  diyfp plus;
15065 };
15066 
15073 template<typename FloatType>
15074 boundaries compute_boundaries(FloatType value)
15075 {
15076  JSON_ASSERT(std::isfinite(value));
15077  JSON_ASSERT(value > 0);
15078 
15079  // Convert the IEEE representation into a diyfp.
15080  //
15081  // If v is denormal:
15082  // value = 0.F * 2^(1 - bias) = ( F) * 2^(1 - bias - (p-1))
15083  // If v is normalized:
15084  // value = 1.F * 2^(E - bias) = (2^(p-1) + F) * 2^(E - bias - (p-1))
15085 
15086  static_assert(std::numeric_limits<FloatType>::is_iec559,
15087  "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
15088 
15089  constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit)
15090  constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
15091  constexpr int kMinExp = 1 - kBias;
15092  constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1)
15093 
15094  using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
15095 
15096  const auto bits = static_cast<std::uint64_t>(reinterpret_bits<bits_type>(value));
15097  const std::uint64_t E = bits >> (kPrecision - 1);
15098  const std::uint64_t F = bits & (kHiddenBit - 1);
15099 
15100  const bool is_denormal = E == 0;
15101  const diyfp v = is_denormal
15102  ? diyfp(F, kMinExp)
15103  : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
15104 
15105  // Compute the boundaries m- and m+ of the floating-point value
15106  // v = f * 2^e.
15107  //
15108  // Determine v- and v+, the floating-point predecessor and successor if v,
15109  // respectively.
15110  //
15111  // v- = v - 2^e if f != 2^(p-1) or e == e_min (A)
15112  // = v - 2^(e-1) if f == 2^(p-1) and e > e_min (B)
15113  //
15114  // v+ = v + 2^e
15115  //
15116  // Let m- = (v- + v) / 2 and m+ = (v + v+) / 2. All real numbers _strictly_
15117  // between m- and m+ round to v, regardless of how the input rounding
15118  // algorithm breaks ties.
15119  //
15120  // ---+-------------+-------------+-------------+-------------+--- (A)
15121  // v- m- v m+ v+
15122  //
15123  // -----------------+------+------+-------------+-------------+--- (B)
15124  // v- m- v m+ v+
15125 
15126  const bool lower_boundary_is_closer = F == 0 && E > 1;
15127  const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
15128  const diyfp m_minus = lower_boundary_is_closer
15129  ? diyfp(4 * v.f - 1, v.e - 2) // (B)
15130  : diyfp(2 * v.f - 1, v.e - 1); // (A)
15131 
15132  // Determine the normalized w+ = m+.
15133  const diyfp w_plus = diyfp::normalize(m_plus);
15134 
15135  // Determine w- = m- such that e_(w-) = e_(w+).
15136  const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
15137 
15138  return {diyfp::normalize(v), w_minus, w_plus};
15139 }
15140 
15141 // Given normalized diyfp w, Grisu needs to find a (normalized) cached
15142 // power-of-ten c, such that the exponent of the product c * w = f * 2^e lies
15143 // within a certain range [alpha, gamma] (Definition 3.2 from [1])
15144 //
15145 // alpha <= e = e_c + e_w + q <= gamma
15146 //
15147 // or
15148 //
15149 // f_c * f_w * 2^alpha <= f_c 2^(e_c) * f_w 2^(e_w) * 2^q
15150 // <= f_c * f_w * 2^gamma
15151 //
15152 // Since c and w are normalized, i.e. 2^(q-1) <= f < 2^q, this implies
15153 //
15154 // 2^(q-1) * 2^(q-1) * 2^alpha <= c * w * 2^q < 2^q * 2^q * 2^gamma
15155 //
15156 // or
15157 //
15158 // 2^(q - 2 + alpha) <= c * w < 2^(q + gamma)
15159 //
15160 // The choice of (alpha,gamma) determines the size of the table and the form of
15161 // the digit generation procedure. Using (alpha,gamma)=(-60,-32) works out well
15162 // in practice:
15163 //
15164 // The idea is to cut the number c * w = f * 2^e into two parts, which can be
15165 // processed independently: An integral part p1, and a fractional part p2:
15166 //
15167 // f * 2^e = ( (f div 2^-e) * 2^-e + (f mod 2^-e) ) * 2^e
15168 // = (f div 2^-e) + (f mod 2^-e) * 2^e
15169 // = p1 + p2 * 2^e
15170 //
15171 // The conversion of p1 into decimal form requires a series of divisions and
15172 // modulos by (a power of) 10. These operations are faster for 32-bit than for
15173 // 64-bit integers, so p1 should ideally fit into a 32-bit integer. This can be
15174 // achieved by choosing
15175 //
15176 // -e >= 32 or e <= -32 := gamma
15177 //
15178 // In order to convert the fractional part
15179 //
15180 // p2 * 2^e = p2 / 2^-e = d[-1] / 10^1 + d[-2] / 10^2 + ...
15181 //
15182 // into decimal form, the fraction is repeatedly multiplied by 10 and the digits
15183 // d[-i] are extracted in order:
15184 //
15185 // (10 * p2) div 2^-e = d[-1]
15186 // (10 * p2) mod 2^-e = d[-2] / 10^1 + ...
15187 //
15188 // The multiplication by 10 must not overflow. It is sufficient to choose
15189 //
15190 // 10 * p2 < 16 * p2 = 2^4 * p2 <= 2^64.
15191 //
15192 // Since p2 = f mod 2^-e < 2^-e,
15193 //
15194 // -e <= 60 or e >= -60 := alpha
15195 
15196 constexpr int kAlpha = -60;
15197 constexpr int kGamma = -32;
15198 
15199 struct cached_power // c = f * 2^e ~= 10^k
15200 {
15201  std::uint64_t f;
15202  int e;
15203  int k;
15204 };
15205 
15213 inline cached_power get_cached_power_for_binary_exponent(int e)
15214 {
15215  // Now
15216  //
15217  // alpha <= e_c + e + q <= gamma (1)
15218  // ==> f_c * 2^alpha <= c * 2^e * 2^q
15219  //
15220  // and since the c's are normalized, 2^(q-1) <= f_c,
15221  //
15222  // ==> 2^(q - 1 + alpha) <= c * 2^(e + q)
15223  // ==> 2^(alpha - e - 1) <= c
15224  //
15225  // If c were an exact power of ten, i.e. c = 10^k, one may determine k as
15226  //
15227  // k = ceil( log_10( 2^(alpha - e - 1) ) )
15228  // = ceil( (alpha - e - 1) * log_10(2) )
15229  //
15230  // From the paper:
15231  // "In theory the result of the procedure could be wrong since c is rounded,
15232  // and the computation itself is approximated [...]. In practice, however,
15233  // this simple function is sufficient."
15234  //
15235  // For IEEE double precision floating-point numbers converted into
15236  // normalized diyfp's w = f * 2^e, with q = 64,
15237  //
15238  // e >= -1022 (min IEEE exponent)
15239  // -52 (p - 1)
15240  // -52 (p - 1, possibly normalize denormal IEEE numbers)
15241  // -11 (normalize the diyfp)
15242  // = -1137
15243  //
15244  // and
15245  //
15246  // e <= +1023 (max IEEE exponent)
15247  // -52 (p - 1)
15248  // -11 (normalize the diyfp)
15249  // = 960
15250  //
15251  // This binary exponent range [-1137,960] results in a decimal exponent
15252  // range [-307,324]. One does not need to store a cached power for each
15253  // k in this range. For each such k it suffices to find a cached power
15254  // such that the exponent of the product lies in [alpha,gamma].
15255  // This implies that the difference of the decimal exponents of adjacent
15256  // table entries must be less than or equal to
15257  //
15258  // floor( (gamma - alpha) * log_10(2) ) = 8.
15259  //
15260  // (A smaller distance gamma-alpha would require a larger table.)
15261 
15262  // NB:
15263  // Actually this function returns c, such that -60 <= e_c + e + 64 <= -34.
15264 
15265  constexpr int kCachedPowersMinDecExp = -300;
15266  constexpr int kCachedPowersDecStep = 8;
15267 
15268  static constexpr std::array<cached_power, 79> kCachedPowers =
15269  {
15270  {
15271  { 0xAB70FE17C79AC6CA, -1060, -300 },
15272  { 0xFF77B1FCBEBCDC4F, -1034, -292 },
15273  { 0xBE5691EF416BD60C, -1007, -284 },
15274  { 0x8DD01FAD907FFC3C, -980, -276 },
15275  { 0xD3515C2831559A83, -954, -268 },
15276  { 0x9D71AC8FADA6C9B5, -927, -260 },
15277  { 0xEA9C227723EE8BCB, -901, -252 },
15278  { 0xAECC49914078536D, -874, -244 },
15279  { 0x823C12795DB6CE57, -847, -236 },
15280  { 0xC21094364DFB5637, -821, -228 },
15281  { 0x9096EA6F3848984F, -794, -220 },
15282  { 0xD77485CB25823AC7, -768, -212 },
15283  { 0xA086CFCD97BF97F4, -741, -204 },
15284  { 0xEF340A98172AACE5, -715, -196 },
15285  { 0xB23867FB2A35B28E, -688, -188 },
15286  { 0x84C8D4DFD2C63F3B, -661, -180 },
15287  { 0xC5DD44271AD3CDBA, -635, -172 },
15288  { 0x936B9FCEBB25C996, -608, -164 },
15289  { 0xDBAC6C247D62A584, -582, -156 },
15290  { 0xA3AB66580D5FDAF6, -555, -148 },
15291  { 0xF3E2F893DEC3F126, -529, -140 },
15292  { 0xB5B5ADA8AAFF80B8, -502, -132 },
15293  { 0x87625F056C7C4A8B, -475, -124 },
15294  { 0xC9BCFF6034C13053, -449, -116 },
15295  { 0x964E858C91BA2655, -422, -108 },
15296  { 0xDFF9772470297EBD, -396, -100 },
15297  { 0xA6DFBD9FB8E5B88F, -369, -92 },
15298  { 0xF8A95FCF88747D94, -343, -84 },
15299  { 0xB94470938FA89BCF, -316, -76 },
15300  { 0x8A08F0F8BF0F156B, -289, -68 },
15301  { 0xCDB02555653131B6, -263, -60 },
15302  { 0x993FE2C6D07B7FAC, -236, -52 },
15303  { 0xE45C10C42A2B3B06, -210, -44 },
15304  { 0xAA242499697392D3, -183, -36 },
15305  { 0xFD87B5F28300CA0E, -157, -28 },
15306  { 0xBCE5086492111AEB, -130, -20 },
15307  { 0x8CBCCC096F5088CC, -103, -12 },
15308  { 0xD1B71758E219652C, -77, -4 },
15309  { 0x9C40000000000000, -50, 4 },
15310  { 0xE8D4A51000000000, -24, 12 },
15311  { 0xAD78EBC5AC620000, 3, 20 },
15312  { 0x813F3978F8940984, 30, 28 },
15313  { 0xC097CE7BC90715B3, 56, 36 },
15314  { 0x8F7E32CE7BEA5C70, 83, 44 },
15315  { 0xD5D238A4ABE98068, 109, 52 },
15316  { 0x9F4F2726179A2245, 136, 60 },
15317  { 0xED63A231D4C4FB27, 162, 68 },
15318  { 0xB0DE65388CC8ADA8, 189, 76 },
15319  { 0x83C7088E1AAB65DB, 216, 84 },
15320  { 0xC45D1DF942711D9A, 242, 92 },
15321  { 0x924D692CA61BE758, 269, 100 },
15322  { 0xDA01EE641A708DEA, 295, 108 },
15323  { 0xA26DA3999AEF774A, 322, 116 },
15324  { 0xF209787BB47D6B85, 348, 124 },
15325  { 0xB454E4A179DD1877, 375, 132 },
15326  { 0x865B86925B9BC5C2, 402, 140 },
15327  { 0xC83553C5C8965D3D, 428, 148 },
15328  { 0x952AB45CFA97A0B3, 455, 156 },
15329  { 0xDE469FBD99A05FE3, 481, 164 },
15330  { 0xA59BC234DB398C25, 508, 172 },
15331  { 0xF6C69A72A3989F5C, 534, 180 },
15332  { 0xB7DCBF5354E9BECE, 561, 188 },
15333  { 0x88FCF317F22241E2, 588, 196 },
15334  { 0xCC20CE9BD35C78A5, 614, 204 },
15335  { 0x98165AF37B2153DF, 641, 212 },
15336  { 0xE2A0B5DC971F303A, 667, 220 },
15337  { 0xA8D9D1535CE3B396, 694, 228 },
15338  { 0xFB9B7CD9A4A7443C, 720, 236 },
15339  { 0xBB764C4CA7A44410, 747, 244 },
15340  { 0x8BAB8EEFB6409C1A, 774, 252 },
15341  { 0xD01FEF10A657842C, 800, 260 },
15342  { 0x9B10A4E5E9913129, 827, 268 },
15343  { 0xE7109BFBA19C0C9D, 853, 276 },
15344  { 0xAC2820D9623BF429, 880, 284 },
15345  { 0x80444B5E7AA7CF85, 907, 292 },
15346  { 0xBF21E44003ACDD2D, 933, 300 },
15347  { 0x8E679C2F5E44FF8F, 960, 308 },
15348  { 0xD433179D9C8CB841, 986, 316 },
15349  { 0x9E19DB92B4E31BA9, 1013, 324 },
15350  }
15351  };
15352 
15353  // This computation gives exactly the same results for k as
15354  // k = ceil((kAlpha - e - 1) * 0.30102999566398114)
15355  // for |e| <= 1500, but doesn't require floating-point operations.
15356  // NB: log_10(2) ~= 78913 / 2^18
15357  JSON_ASSERT(e >= -1500);
15358  JSON_ASSERT(e <= 1500);
15359  const int f = kAlpha - e - 1;
15360  const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0);
15361 
15362  const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
15363  JSON_ASSERT(index >= 0);
15364  JSON_ASSERT(static_cast<std::size_t>(index) < kCachedPowers.size());
15365 
15366  const cached_power cached = kCachedPowers[static_cast<std::size_t>(index)];
15367  JSON_ASSERT(kAlpha <= cached.e + e + 64);
15368  JSON_ASSERT(kGamma >= cached.e + e + 64);
15369 
15370  return cached;
15371 }
15372 
15377 inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10)
15378 {
15379  // LCOV_EXCL_START
15380  if (n >= 1000000000)
15381  {
15382  pow10 = 1000000000;
15383  return 10;
15384  }
15385  // LCOV_EXCL_STOP
15386  if (n >= 100000000)
15387  {
15388  pow10 = 100000000;
15389  return 9;
15390  }
15391  if (n >= 10000000)
15392  {
15393  pow10 = 10000000;
15394  return 8;
15395  }
15396  if (n >= 1000000)
15397  {
15398  pow10 = 1000000;
15399  return 7;
15400  }
15401  if (n >= 100000)
15402  {
15403  pow10 = 100000;
15404  return 6;
15405  }
15406  if (n >= 10000)
15407  {
15408  pow10 = 10000;
15409  return 5;
15410  }
15411  if (n >= 1000)
15412  {
15413  pow10 = 1000;
15414  return 4;
15415  }
15416  if (n >= 100)
15417  {
15418  pow10 = 100;
15419  return 3;
15420  }
15421  if (n >= 10)
15422  {
15423  pow10 = 10;
15424  return 2;
15425  }
15426 
15427  pow10 = 1;
15428  return 1;
15429 }
15430 
15431 inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,
15432  std::uint64_t rest, std::uint64_t ten_k)
15433 {
15434  JSON_ASSERT(len >= 1);
15435  JSON_ASSERT(dist <= delta);
15436  JSON_ASSERT(rest <= delta);
15437  JSON_ASSERT(ten_k > 0);
15438 
15439  // <--------------------------- delta ---->
15440  // <---- dist --------->
15441  // --------------[------------------+-------------------]--------------
15442  // M- w M+
15443  //
15444  // ten_k
15445  // <------>
15446  // <---- rest ---->
15447  // --------------[------------------+----+--------------]--------------
15448  // w V
15449  // = buf * 10^k
15450  //
15451  // ten_k represents a unit-in-the-last-place in the decimal representation
15452  // stored in buf.
15453  // Decrement buf by ten_k while this takes buf closer to w.
15454 
15455  // The tests are written in this order to avoid overflow in unsigned
15456  // integer arithmetic.
15457 
15458  while (rest < dist
15459  && delta - rest >= ten_k
15460  && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
15461  {
15462  JSON_ASSERT(buf[len - 1] != '0');
15463  buf[len - 1]--;
15464  rest += ten_k;
15465  }
15466 }
15467 
15472 inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,
15473  diyfp M_minus, diyfp w, diyfp M_plus)
15474 {
15475  static_assert(kAlpha >= -60, "internal error");
15476  static_assert(kGamma <= -32, "internal error");
15477 
15478  // Generates the digits (and the exponent) of a decimal floating-point
15479  // number V = buffer * 10^decimal_exponent in the range [M-, M+]. The diyfp's
15480  // w, M- and M+ share the same exponent e, which satisfies alpha <= e <= gamma.
15481  //
15482  // <--------------------------- delta ---->
15483  // <---- dist --------->
15484  // --------------[------------------+-------------------]--------------
15485  // M- w M+
15486  //
15487  // Grisu2 generates the digits of M+ from left to right and stops as soon as
15488  // V is in [M-,M+].
15489 
15490  JSON_ASSERT(M_plus.e >= kAlpha);
15491  JSON_ASSERT(M_plus.e <= kGamma);
15492 
15493  std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e)
15494  std::uint64_t dist = diyfp::sub(M_plus, w ).f; // (significand of (M+ - w ), implicit exponent is e)
15495 
15496  // Split M+ = f * 2^e into two parts p1 and p2 (note: e < 0):
15497  //
15498  // M+ = f * 2^e
15499  // = ((f div 2^-e) * 2^-e + (f mod 2^-e)) * 2^e
15500  // = ((p1 ) * 2^-e + (p2 )) * 2^e
15501  // = p1 + p2 * 2^e
15502 
15503  const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
15504 
15505  auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
15506  std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e
15507 
15508  // 1)
15509  //
15510  // Generate the digits of the integral part p1 = d[n-1]...d[1]d[0]
15511 
15512  JSON_ASSERT(p1 > 0);
15513 
15514  std::uint32_t pow10{};
15515  const int k = find_largest_pow10(p1, pow10);
15516 
15517  // 10^(k-1) <= p1 < 10^k, pow10 = 10^(k-1)
15518  //
15519  // p1 = (p1 div 10^(k-1)) * 10^(k-1) + (p1 mod 10^(k-1))
15520  // = (d[k-1] ) * 10^(k-1) + (p1 mod 10^(k-1))
15521  //
15522  // M+ = p1 + p2 * 2^e
15523  // = d[k-1] * 10^(k-1) + (p1 mod 10^(k-1)) + p2 * 2^e
15524  // = d[k-1] * 10^(k-1) + ((p1 mod 10^(k-1)) * 2^-e + p2) * 2^e
15525  // = d[k-1] * 10^(k-1) + ( rest) * 2^e
15526  //
15527  // Now generate the digits d[n] of p1 from left to right (n = k-1,...,0)
15528  //
15529  // p1 = d[k-1]...d[n] * 10^n + d[n-1]...d[0]
15530  //
15531  // but stop as soon as
15532  //
15533  // rest * 2^e = (d[n-1]...d[0] * 2^-e + p2) * 2^e <= delta * 2^e
15534 
15535  int n = k;
15536  while (n > 0)
15537  {
15538  // Invariants:
15539  // M+ = buffer * 10^n + (p1 + p2 * 2^e) (buffer = 0 for n = k)
15540  // pow10 = 10^(n-1) <= p1 < 10^n
15541  //
15542  const std::uint32_t d = p1 / pow10; // d = p1 div 10^(n-1)
15543  const std::uint32_t r = p1 % pow10; // r = p1 mod 10^(n-1)
15544  //
15545  // M+ = buffer * 10^n + (d * 10^(n-1) + r) + p2 * 2^e
15546  // = (buffer * 10 + d) * 10^(n-1) + (r + p2 * 2^e)
15547  //
15548  JSON_ASSERT(d <= 9);
15549  buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d
15550  //
15551  // M+ = buffer * 10^(n-1) + (r + p2 * 2^e)
15552  //
15553  p1 = r;
15554  n--;
15555  //
15556  // M+ = buffer * 10^n + (p1 + p2 * 2^e)
15557  // pow10 = 10^n
15558  //
15559 
15560  // Now check if enough digits have been generated.
15561  // Compute
15562  //
15563  // p1 + p2 * 2^e = (p1 * 2^-e + p2) * 2^e = rest * 2^e
15564  //
15565  // Note:
15566  // Since rest and delta share the same exponent e, it suffices to
15567  // compare the significands.
15568  const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
15569  if (rest <= delta)
15570  {
15571  // V = buffer * 10^n, with M- <= V <= M+.
15572 
15573  decimal_exponent += n;
15574 
15575  // We may now just stop. But instead look if the buffer could be
15576  // decremented to bring V closer to w.
15577  //
15578  // pow10 = 10^n is now 1 ulp in the decimal representation V.
15579  // The rounding procedure works with diyfp's with an implicit
15580  // exponent of e.
15581  //
15582  // 10^n = (10^n * 2^-e) * 2^e = ulp * 2^e
15583  //
15584  const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
15585  grisu2_round(buffer, length, dist, delta, rest, ten_n);
15586 
15587  return;
15588  }
15589 
15590  pow10 /= 10;
15591  //
15592  // pow10 = 10^(n-1) <= p1 < 10^n
15593  // Invariants restored.
15594  }
15595 
15596  // 2)
15597  //
15598  // The digits of the integral part have been generated:
15599  //
15600  // M+ = d[k-1]...d[1]d[0] + p2 * 2^e
15601  // = buffer + p2 * 2^e
15602  //
15603  // Now generate the digits of the fractional part p2 * 2^e.
15604  //
15605  // Note:
15606  // No decimal point is generated: the exponent is adjusted instead.
15607  //
15608  // p2 actually represents the fraction
15609  //
15610  // p2 * 2^e
15611  // = p2 / 2^-e
15612  // = d[-1] / 10^1 + d[-2] / 10^2 + ...
15613  //
15614  // Now generate the digits d[-m] of p1 from left to right (m = 1,2,...)
15615  //
15616  // p2 * 2^e = d[-1]d[-2]...d[-m] * 10^-m
15617  // + 10^-m * (d[-m-1] / 10^1 + d[-m-2] / 10^2 + ...)
15618  //
15619  // using
15620  //
15621  // 10^m * p2 = ((10^m * p2) div 2^-e) * 2^-e + ((10^m * p2) mod 2^-e)
15622  // = ( d) * 2^-e + ( r)
15623  //
15624  // or
15625  // 10^m * p2 * 2^e = d + r * 2^e
15626  //
15627  // i.e.
15628  //
15629  // M+ = buffer + p2 * 2^e
15630  // = buffer + 10^-m * (d + r * 2^e)
15631  // = (buffer * 10^m + d) * 10^-m + 10^-m * r * 2^e
15632  //
15633  // and stop as soon as 10^-m * r * 2^e <= delta * 2^e
15634 
15635  JSON_ASSERT(p2 > delta);
15636 
15637  int m = 0;
15638  for (;;)
15639  {
15640  // Invariant:
15641  // M+ = buffer * 10^-m + 10^-m * (d[-m-1] / 10 + d[-m-2] / 10^2 + ...) * 2^e
15642  // = buffer * 10^-m + 10^-m * (p2 ) * 2^e
15643  // = buffer * 10^-m + 10^-m * (1/10 * (10 * p2) ) * 2^e
15644  // = buffer * 10^-m + 10^-m * (1/10 * ((10*p2 div 2^-e) * 2^-e + (10*p2 mod 2^-e)) * 2^e
15645  //
15646  JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
15647  p2 *= 10;
15648  const std::uint64_t d = p2 >> -one.e; // d = (10 * p2) div 2^-e
15649  const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e
15650  //
15651  // M+ = buffer * 10^-m + 10^-m * (1/10 * (d * 2^-e + r) * 2^e
15652  // = buffer * 10^-m + 10^-m * (1/10 * (d + r * 2^e))
15653  // = (buffer * 10 + d) * 10^(-m-1) + 10^(-m-1) * r * 2^e
15654  //
15655  JSON_ASSERT(d <= 9);
15656  buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d
15657  //
15658  // M+ = buffer * 10^(-m-1) + 10^(-m-1) * r * 2^e
15659  //
15660  p2 = r;
15661  m++;
15662  //
15663  // M+ = buffer * 10^-m + 10^-m * p2 * 2^e
15664  // Invariant restored.
15665 
15666  // Check if enough digits have been generated.
15667  //
15668  // 10^-m * p2 * 2^e <= delta * 2^e
15669  // p2 * 2^e <= 10^m * delta * 2^e
15670  // p2 <= 10^m * delta
15671  delta *= 10;
15672  dist *= 10;
15673  if (p2 <= delta)
15674  {
15675  break;
15676  }
15677  }
15678 
15679  // V = buffer * 10^-m, with M- <= V <= M+.
15680 
15681  decimal_exponent -= m;
15682 
15683  // 1 ulp in the decimal representation is now 10^-m.
15684  // Since delta and dist are now scaled by 10^m, we need to do the
15685  // same with ulp in order to keep the units in sync.
15686  //
15687  // 10^m * 10^-m = 1 = 2^-e * 2^e = ten_m * 2^e
15688  //
15689  const std::uint64_t ten_m = one.f;
15690  grisu2_round(buffer, length, dist, delta, p2, ten_m);
15691 
15692  // By construction this algorithm generates the shortest possible decimal
15693  // number (Loitsch, Theorem 6.2) which rounds back to w.
15694  // For an input number of precision p, at least
15695  //
15696  // N = 1 + ceil(p * log_10(2))
15697  //
15698  // decimal digits are sufficient to identify all binary floating-point
15699  // numbers (Matula, "In-and-Out conversions").
15700  // This implies that the algorithm does not produce more than N decimal
15701  // digits.
15702  //
15703  // N = 17 for p = 53 (IEEE double precision)
15704  // N = 9 for p = 24 (IEEE single precision)
15705 }
15706 
15712 JSON_HEDLEY_NON_NULL(1)
15713 inline void grisu2(char* buf, int& len, int& decimal_exponent,
15714  diyfp m_minus, diyfp v, diyfp m_plus)
15715 {
15716  JSON_ASSERT(m_plus.e == m_minus.e);
15717  JSON_ASSERT(m_plus.e == v.e);
15718 
15719  // --------(-----------------------+-----------------------)-------- (A)
15720  // m- v m+
15721  //
15722  // --------------------(-----------+-----------------------)-------- (B)
15723  // m- v m+
15724  //
15725  // First scale v (and m- and m+) such that the exponent is in the range
15726  // [alpha, gamma].
15727 
15728  const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
15729 
15730  const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k
15731 
15732  // The exponent of the products is = v.e + c_minus_k.e + q and is in the range [alpha,gamma]
15733  const diyfp w = diyfp::mul(v, c_minus_k);
15734  const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
15735  const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
15736 
15737  // ----(---+---)---------------(---+---)---------------(---+---)----
15738  // w- w w+
15739  // = c*m- = c*v = c*m+
15740  //
15741  // diyfp::mul rounds its result and c_minus_k is approximated too. w, w- and
15742  // w+ are now off by a small amount.
15743  // In fact:
15744  //
15745  // w - v * 10^k < 1 ulp
15746  //
15747  // To account for this inaccuracy, add resp. subtract 1 ulp.
15748  //
15749  // --------+---[---------------(---+---)---------------]---+--------
15750  // w- M- w M+ w+
15751  //
15752  // Now any number in [M-, M+] (bounds included) will round to w when input,
15753  // regardless of how the input rounding algorithm breaks ties.
15754  //
15755  // And digit_gen generates the shortest possible such number in [M-, M+].
15756  // Note that this does not mean that Grisu2 always generates the shortest
15757  // possible number in the interval (m-, m+).
15758  const diyfp M_minus(w_minus.f + 1, w_minus.e);
15759  const diyfp M_plus (w_plus.f - 1, w_plus.e );
15760 
15761  decimal_exponent = -cached.k; // = -(-k) = k
15762 
15763  grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
15764 }
15765 
15771 template<typename FloatType>
15772 JSON_HEDLEY_NON_NULL(1)
15773 void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)
15774 {
15775  static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
15776  "internal error: not enough precision");
15777 
15778  JSON_ASSERT(std::isfinite(value));
15779  JSON_ASSERT(value > 0);
15780 
15781  // If the neighbors (and boundaries) of 'value' are always computed for double-precision
15782  // numbers, all float's can be recovered using strtod (and strtof). However, the resulting
15783  // decimal representations are not exactly "short".
15784  //
15785  // The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars)
15786  // says "value is converted to a string as if by std::sprintf in the default ("C") locale"
15787  // and since sprintf promotes float's to double's, I think this is exactly what 'std::to_chars'
15788  // does.
15789  // On the other hand, the documentation for 'std::to_chars' requires that "parsing the
15790  // representation using the corresponding std::from_chars function recovers value exactly". That
15791  // indicates that single precision floating-point numbers should be recovered using
15792  // 'std::strtof'.
15793  //
15794  // NB: If the neighbors are computed for single-precision numbers, there is a single float
15795  // (7.0385307e-26f) which can't be recovered using strtod. The resulting double precision
15796  // value is off by 1 ulp.
15797 #if 0
15798  const boundaries w = compute_boundaries(static_cast<double>(value));
15799 #else
15800  const boundaries w = compute_boundaries(value);
15801 #endif
15802 
15803  grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
15804 }
15805 
15811 JSON_HEDLEY_NON_NULL(1)
15812 
15813 inline char* append_exponent(char* buf, int e)
15814 {
15815  JSON_ASSERT(e > -1000);
15816  JSON_ASSERT(e < 1000);
15817 
15818  if (e < 0)
15819  {
15820  e = -e;
15821  *buf++ = '-';
15822  }
15823  else
15824  {
15825  *buf++ = '+';
15826  }
15827 
15828  auto k = static_cast<std::uint32_t>(e);
15829  if (k < 10)
15830  {
15831  // Always print at least two digits in the exponent.
15832  // This is for compatibility with printf("%g").
15833  *buf++ = '0';
15834  *buf++ = static_cast<char>('0' + k);
15835  }
15836  else if (k < 100)
15837  {
15838  *buf++ = static_cast<char>('0' + k / 10);
15839  k %= 10;
15840  *buf++ = static_cast<char>('0' + k);
15841  }
15842  else
15843  {
15844  *buf++ = static_cast<char>('0' + k / 100);
15845  k %= 100;
15846  *buf++ = static_cast<char>('0' + k / 10);
15847  k %= 10;
15848  *buf++ = static_cast<char>('0' + k);
15849  }
15850 
15851  return buf;
15852 }
15853 
15863 JSON_HEDLEY_NON_NULL(1)
15864 
15865 inline char* format_buffer(char* buf, int len, int decimal_exponent,
15866  int min_exp, int max_exp)
15867 {
15868  JSON_ASSERT(min_exp < 0);
15869  JSON_ASSERT(max_exp > 0);
15870 
15871  const int k = len;
15872  const int n = len + decimal_exponent;
15873 
15874  // v = buf * 10^(n-k)
15875  // k is the length of the buffer (number of decimal digits)
15876  // n is the position of the decimal point relative to the start of the buffer.
15877 
15878  if (k <= n && n <= max_exp)
15879  {
15880  // digits[000]
15881  // len <= max_exp + 2
15882 
15883  std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k));
15884  // Make it look like a floating-point number (#362, #378)
15885  buf[n + 0] = '.';
15886  buf[n + 1] = '0';
15887  return buf + (static_cast<size_t>(n) + 2);
15888  }
15889 
15890  if (0 < n && n <= max_exp)
15891  {
15892  // dig.its
15893  // len <= max_digits10 + 1
15894 
15895  JSON_ASSERT(k > n);
15896 
15897  std::memmove(buf + (static_cast<size_t>(n) + 1), buf + n, static_cast<size_t>(k) - static_cast<size_t>(n));
15898  buf[n] = '.';
15899  return buf + (static_cast<size_t>(k) + 1U);
15900  }
15901 
15902  if (min_exp < n && n <= 0)
15903  {
15904  // 0.[000]digits
15905  // len <= 2 + (-min_exp - 1) + max_digits10
15906 
15907  std::memmove(buf + (2 + static_cast<size_t>(-n)), buf, static_cast<size_t>(k));
15908  buf[0] = '0';
15909  buf[1] = '.';
15910  std::memset(buf + 2, '0', static_cast<size_t>(-n));
15911  return buf + (2U + static_cast<size_t>(-n) + static_cast<size_t>(k));
15912  }
15913 
15914  if (k == 1)
15915  {
15916  // dE+123
15917  // len <= 1 + 5
15918 
15919  buf += 1;
15920  }
15921  else
15922  {
15923  // d.igitsE+123
15924  // len <= max_digits10 + 1 + 5
15925 
15926  std::memmove(buf + 2, buf + 1, static_cast<size_t>(k) - 1);
15927  buf[1] = '.';
15928  buf += 1 + static_cast<size_t>(k);
15929  }
15930 
15931  *buf++ = 'e';
15932  return append_exponent(buf, n - 1);
15933 }
15934 
15935 } // namespace dtoa_impl
15936 
15947 template<typename FloatType>
15948 JSON_HEDLEY_NON_NULL(1, 2)
15949 
15950 char* to_chars(char* first, const char* last, FloatType value)
15951 {
15952  static_cast<void>(last); // maybe unused - fix warning
15953  JSON_ASSERT(std::isfinite(value));
15954 
15955  // Use signbit(value) instead of (value < 0) since signbit works for -0.
15956  if (std::signbit(value))
15957  {
15958  value = -value;
15959  *first++ = '-';
15960  }
15961 
15962  if (value == 0) // +-0
15963  {
15964  *first++ = '0';
15965  // Make it look like a floating-point number (#362, #378)
15966  *first++ = '.';
15967  *first++ = '0';
15968  return first;
15969  }
15970 
15971  JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
15972 
15973  // Compute v = buffer * 10^decimal_exponent.
15974  // The decimal digits are stored in the buffer, which needs to be interpreted
15975  // as an unsigned decimal integer.
15976  // len is the length of the buffer, i.e. the number of decimal digits.
15977  int len = 0;
15978  int decimal_exponent = 0;
15979  dtoa_impl::grisu2(first, len, decimal_exponent, value);
15980 
15981  JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
15982 
15983  // Format the buffer like printf("%.*g", prec, value)
15984  constexpr int kMinExp = -4;
15985  // Use digits10 here to increase compatibility with version 2.
15986  constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
15987 
15988  JSON_ASSERT(last - first >= kMaxExp + 2);
15989  JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
15990  JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
15991 
15992  return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
15993 }
15994 
15995 } // namespace detail
15996 } // namespace nlohmann
15997 
15998 // #include <nlohmann/detail/exceptions.hpp>
15999 
16000 // #include <nlohmann/detail/macro_scope.hpp>
16001 
16002 // #include <nlohmann/detail/meta/cpp_future.hpp>
16003 
16004 // #include <nlohmann/detail/output/binary_writer.hpp>
16005 
16006 // #include <nlohmann/detail/output/output_adapters.hpp>
16007 
16008 // #include <nlohmann/detail/value_t.hpp>
16009 
16010 
16011 namespace nlohmann
16012 {
16013 namespace detail
16014 {
16016 // serialization //
16018 
16020 enum class error_handler_t
16021 {
16022  strict,
16023  replace,
16024  ignore
16025 };
16026 
16027 template<typename BasicJsonType>
16028 class serializer
16029 {
16030  using string_t = typename BasicJsonType::string_t;
16031  using number_float_t = typename BasicJsonType::number_float_t;
16032  using number_integer_t = typename BasicJsonType::number_integer_t;
16033  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
16034  using binary_char_t = typename BasicJsonType::binary_t::value_type;
16035  static constexpr std::uint8_t UTF8_ACCEPT = 0;
16036  static constexpr std::uint8_t UTF8_REJECT = 1;
16037 
16038  public:
16044  serializer(output_adapter_t<char> s, const char ichar,
16045  error_handler_t error_handler_ = error_handler_t::strict)
16046  : o(std::move(s))
16047  , loc(std::localeconv())
16048  , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
16049  , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
16050  , indent_char(ichar)
16051  , indent_string(512, indent_char)
16052  , error_handler(error_handler_)
16053  {}
16054 
16055  // delete because of pointer members
16056  serializer(const serializer&) = delete;
16057  serializer& operator=(const serializer&) = delete;
16058  serializer(serializer&&) = delete;
16059  serializer& operator=(serializer&&) = delete;
16060  ~serializer() = default;
16061 
16084  void dump(const BasicJsonType& val,
16085  const bool pretty_print,
16086  const bool ensure_ascii,
16087  const unsigned int indent_step,
16088  const unsigned int current_indent = 0)
16089  {
16090  switch (val.m_type)
16091  {
16092  case value_t::object:
16093  {
16094  if (val.m_value.object->empty())
16095  {
16096  o->write_characters("{}", 2);
16097  return;
16098  }
16099 
16100  if (pretty_print)
16101  {
16102  o->write_characters("{\n", 2);
16103 
16104  // variable to hold indentation for recursive calls
16105  const auto new_indent = current_indent + indent_step;
16106  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16107  {
16108  indent_string.resize(indent_string.size() * 2, ' ');
16109  }
16110 
16111  // first n-1 elements
16112  auto i = val.m_value.object->cbegin();
16113  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16114  {
16115  o->write_characters(indent_string.c_str(), new_indent);
16116  o->write_character('\"');
16117  dump_escaped(i->first, ensure_ascii);
16118  o->write_characters("\": ", 3);
16119  dump(i->second, true, ensure_ascii, indent_step, new_indent);
16120  o->write_characters(",\n", 2);
16121  }
16122 
16123  // last element
16124  JSON_ASSERT(i != val.m_value.object->cend());
16125  JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16126  o->write_characters(indent_string.c_str(), new_indent);
16127  o->write_character('\"');
16128  dump_escaped(i->first, ensure_ascii);
16129  o->write_characters("\": ", 3);
16130  dump(i->second, true, ensure_ascii, indent_step, new_indent);
16131 
16132  o->write_character('\n');
16133  o->write_characters(indent_string.c_str(), current_indent);
16134  o->write_character('}');
16135  }
16136  else
16137  {
16138  o->write_character('{');
16139 
16140  // first n-1 elements
16141  auto i = val.m_value.object->cbegin();
16142  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16143  {
16144  o->write_character('\"');
16145  dump_escaped(i->first, ensure_ascii);
16146  o->write_characters("\":", 2);
16147  dump(i->second, false, ensure_ascii, indent_step, current_indent);
16148  o->write_character(',');
16149  }
16150 
16151  // last element
16152  JSON_ASSERT(i != val.m_value.object->cend());
16153  JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16154  o->write_character('\"');
16155  dump_escaped(i->first, ensure_ascii);
16156  o->write_characters("\":", 2);
16157  dump(i->second, false, ensure_ascii, indent_step, current_indent);
16158 
16159  o->write_character('}');
16160  }
16161 
16162  return;
16163  }
16164 
16165  case value_t::array:
16166  {
16167  if (val.m_value.array->empty())
16168  {
16169  o->write_characters("[]", 2);
16170  return;
16171  }
16172 
16173  if (pretty_print)
16174  {
16175  o->write_characters("[\n", 2);
16176 
16177  // variable to hold indentation for recursive calls
16178  const auto new_indent = current_indent + indent_step;
16179  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16180  {
16181  indent_string.resize(indent_string.size() * 2, ' ');
16182  }
16183 
16184  // first n-1 elements
16185  for (auto i = val.m_value.array->cbegin();
16186  i != val.m_value.array->cend() - 1; ++i)
16187  {
16188  o->write_characters(indent_string.c_str(), new_indent);
16189  dump(*i, true, ensure_ascii, indent_step, new_indent);
16190  o->write_characters(",\n", 2);
16191  }
16192 
16193  // last element
16194  JSON_ASSERT(!val.m_value.array->empty());
16195  o->write_characters(indent_string.c_str(), new_indent);
16196  dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);
16197 
16198  o->write_character('\n');
16199  o->write_characters(indent_string.c_str(), current_indent);
16200  o->write_character(']');
16201  }
16202  else
16203  {
16204  o->write_character('[');
16205 
16206  // first n-1 elements
16207  for (auto i = val.m_value.array->cbegin();
16208  i != val.m_value.array->cend() - 1; ++i)
16209  {
16210  dump(*i, false, ensure_ascii, indent_step, current_indent);
16211  o->write_character(',');
16212  }
16213 
16214  // last element
16215  JSON_ASSERT(!val.m_value.array->empty());
16216  dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);
16217 
16218  o->write_character(']');
16219  }
16220 
16221  return;
16222  }
16223 
16224  case value_t::string:
16225  {
16226  o->write_character('\"');
16227  dump_escaped(*val.m_value.string, ensure_ascii);
16228  o->write_character('\"');
16229  return;
16230  }
16231 
16232  case value_t::binary:
16233  {
16234  if (pretty_print)
16235  {
16236  o->write_characters("{\n", 2);
16237 
16238  // variable to hold indentation for recursive calls
16239  const auto new_indent = current_indent + indent_step;
16240  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16241  {
16242  indent_string.resize(indent_string.size() * 2, ' ');
16243  }
16244 
16245  o->write_characters(indent_string.c_str(), new_indent);
16246 
16247  o->write_characters("\"bytes\": [", 10);
16248 
16249  if (!val.m_value.binary->empty())
16250  {
16251  for (auto i = val.m_value.binary->cbegin();
16252  i != val.m_value.binary->cend() - 1; ++i)
16253  {
16254  dump_integer(*i);
16255  o->write_characters(", ", 2);
16256  }
16257  dump_integer(val.m_value.binary->back());
16258  }
16259 
16260  o->write_characters("],\n", 3);
16261  o->write_characters(indent_string.c_str(), new_indent);
16262 
16263  o->write_characters("\"subtype\": ", 11);
16264  if (val.m_value.binary->has_subtype())
16265  {
16266  dump_integer(val.m_value.binary->subtype());
16267  }
16268  else
16269  {
16270  o->write_characters("null", 4);
16271  }
16272  o->write_character('\n');
16273  o->write_characters(indent_string.c_str(), current_indent);
16274  o->write_character('}');
16275  }
16276  else
16277  {
16278  o->write_characters("{\"bytes\":[", 10);
16279 
16280  if (!val.m_value.binary->empty())
16281  {
16282  for (auto i = val.m_value.binary->cbegin();
16283  i != val.m_value.binary->cend() - 1; ++i)
16284  {
16285  dump_integer(*i);
16286  o->write_character(',');
16287  }
16288  dump_integer(val.m_value.binary->back());
16289  }
16290 
16291  o->write_characters("],\"subtype\":", 12);
16292  if (val.m_value.binary->has_subtype())
16293  {
16294  dump_integer(val.m_value.binary->subtype());
16295  o->write_character('}');
16296  }
16297  else
16298  {
16299  o->write_characters("null}", 5);
16300  }
16301  }
16302  return;
16303  }
16304 
16305  case value_t::boolean:
16306  {
16307  if (val.m_value.boolean)
16308  {
16309  o->write_characters("true", 4);
16310  }
16311  else
16312  {
16313  o->write_characters("false", 5);
16314  }
16315  return;
16316  }
16317 
16318  case value_t::number_integer:
16319  {
16320  dump_integer(val.m_value.number_integer);
16321  return;
16322  }
16323 
16324  case value_t::number_unsigned:
16325  {
16326  dump_integer(val.m_value.number_unsigned);
16327  return;
16328  }
16329 
16330  case value_t::number_float:
16331  {
16332  dump_float(val.m_value.number_float);
16333  return;
16334  }
16335 
16336  case value_t::discarded:
16337  {
16338  o->write_characters("<discarded>", 11);
16339  return;
16340  }
16341 
16342  case value_t::null:
16343  {
16344  o->write_characters("null", 4);
16345  return;
16346  }
16347 
16348  default: // LCOV_EXCL_LINE
16349  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
16350  }
16351  }
16352 
16353  JSON_PRIVATE_UNLESS_TESTED:
16368  void dump_escaped(const string_t& s, const bool ensure_ascii)
16369  {
16370  std::uint32_t codepoint{};
16371  std::uint8_t state = UTF8_ACCEPT;
16372  std::size_t bytes = 0; // number of bytes written to string_buffer
16373 
16374  // number of bytes written at the point of the last valid byte
16375  std::size_t bytes_after_last_accept = 0;
16376  std::size_t undumped_chars = 0;
16377 
16378  for (std::size_t i = 0; i < s.size(); ++i)
16379  {
16380  const auto byte = static_cast<uint8_t>(s[i]);
16381 
16382  switch (decode(state, codepoint, byte))
16383  {
16384  case UTF8_ACCEPT: // decode found a new code point
16385  {
16386  switch (codepoint)
16387  {
16388  case 0x08: // backspace
16389  {
16390  string_buffer[bytes++] = '\\';
16391  string_buffer[bytes++] = 'b';
16392  break;
16393  }
16394 
16395  case 0x09: // horizontal tab
16396  {
16397  string_buffer[bytes++] = '\\';
16398  string_buffer[bytes++] = 't';
16399  break;
16400  }
16401 
16402  case 0x0A: // newline
16403  {
16404  string_buffer[bytes++] = '\\';
16405  string_buffer[bytes++] = 'n';
16406  break;
16407  }
16408 
16409  case 0x0C: // formfeed
16410  {
16411  string_buffer[bytes++] = '\\';
16412  string_buffer[bytes++] = 'f';
16413  break;
16414  }
16415 
16416  case 0x0D: // carriage return
16417  {
16418  string_buffer[bytes++] = '\\';
16419  string_buffer[bytes++] = 'r';
16420  break;
16421  }
16422 
16423  case 0x22: // quotation mark
16424  {
16425  string_buffer[bytes++] = '\\';
16426  string_buffer[bytes++] = '\"';
16427  break;
16428  }
16429 
16430  case 0x5C: // reverse solidus
16431  {
16432  string_buffer[bytes++] = '\\';
16433  string_buffer[bytes++] = '\\';
16434  break;
16435  }
16436 
16437  default:
16438  {
16439  // escape control characters (0x00..0x1F) or, if
16440  // ensure_ascii parameter is used, non-ASCII characters
16441  if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
16442  {
16443  if (codepoint <= 0xFFFF)
16444  {
16445  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16446  (std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x",
16447  static_cast<std::uint16_t>(codepoint));
16448  bytes += 6;
16449  }
16450  else
16451  {
16452  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16453  (std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x",
16454  static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),
16455  static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)));
16456  bytes += 12;
16457  }
16458  }
16459  else
16460  {
16461  // copy byte to buffer (all previous bytes
16462  // been copied have in default case above)
16463  string_buffer[bytes++] = s[i];
16464  }
16465  break;
16466  }
16467  }
16468 
16469  // write buffer and reset index; there must be 13 bytes
16470  // left, as this is the maximal number of bytes to be
16471  // written ("\uxxxx\uxxxx\0") for one code point
16472  if (string_buffer.size() - bytes < 13)
16473  {
16474  o->write_characters(string_buffer.data(), bytes);
16475  bytes = 0;
16476  }
16477 
16478  // remember the byte position of this accept
16479  bytes_after_last_accept = bytes;
16480  undumped_chars = 0;
16481  break;
16482  }
16483 
16484  case UTF8_REJECT: // decode found invalid UTF-8 byte
16485  {
16486  switch (error_handler)
16487  {
16488  case error_handler_t::strict:
16489  {
16490  std::string sn(9, '\0');
16491  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16492  (std::snprintf)(&sn[0], sn.size(), "%.2X", byte);
16493  JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, BasicJsonType()));
16494  }
16495 
16496  case error_handler_t::ignore:
16497  case error_handler_t::replace:
16498  {
16499  // in case we saw this character the first time, we
16500  // would like to read it again, because the byte
16501  // may be OK for itself, but just not OK for the
16502  // previous sequence
16503  if (undumped_chars > 0)
16504  {
16505  --i;
16506  }
16507 
16508  // reset length buffer to the last accepted index;
16509  // thus removing/ignoring the invalid characters
16510  bytes = bytes_after_last_accept;
16511 
16512  if (error_handler == error_handler_t::replace)
16513  {
16514  // add a replacement character
16515  if (ensure_ascii)
16516  {
16517  string_buffer[bytes++] = '\\';
16518  string_buffer[bytes++] = 'u';
16519  string_buffer[bytes++] = 'f';
16520  string_buffer[bytes++] = 'f';
16521  string_buffer[bytes++] = 'f';
16522  string_buffer[bytes++] = 'd';
16523  }
16524  else
16525  {
16526  string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xEF');
16527  string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBF');
16528  string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBD');
16529  }
16530 
16531  // write buffer and reset index; there must be 13 bytes
16532  // left, as this is the maximal number of bytes to be
16533  // written ("\uxxxx\uxxxx\0") for one code point
16534  if (string_buffer.size() - bytes < 13)
16535  {
16536  o->write_characters(string_buffer.data(), bytes);
16537  bytes = 0;
16538  }
16539 
16540  bytes_after_last_accept = bytes;
16541  }
16542 
16543  undumped_chars = 0;
16544 
16545  // continue processing the string
16546  state = UTF8_ACCEPT;
16547  break;
16548  }
16549 
16550  default: // LCOV_EXCL_LINE
16551  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
16552  }
16553  break;
16554  }
16555 
16556  default: // decode found yet incomplete multi-byte code point
16557  {
16558  if (!ensure_ascii)
16559  {
16560  // code point will not be escaped - copy byte to buffer
16561  string_buffer[bytes++] = s[i];
16562  }
16563  ++undumped_chars;
16564  break;
16565  }
16566  }
16567  }
16568 
16569  // we finished processing the string
16570  if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
16571  {
16572  // write buffer
16573  if (bytes > 0)
16574  {
16575  o->write_characters(string_buffer.data(), bytes);
16576  }
16577  }
16578  else
16579  {
16580  // we finish reading, but do not accept: string was incomplete
16581  switch (error_handler)
16582  {
16583  case error_handler_t::strict:
16584  {
16585  std::string sn(9, '\0');
16586  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16587  (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back()));
16588  JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
16589  }
16590 
16591  case error_handler_t::ignore:
16592  {
16593  // write all accepted bytes
16594  o->write_characters(string_buffer.data(), bytes_after_last_accept);
16595  break;
16596  }
16597 
16598  case error_handler_t::replace:
16599  {
16600  // write all accepted bytes
16601  o->write_characters(string_buffer.data(), bytes_after_last_accept);
16602  // add a replacement character
16603  if (ensure_ascii)
16604  {
16605  o->write_characters("\\ufffd", 6);
16606  }
16607  else
16608  {
16609  o->write_characters("\xEF\xBF\xBD", 3);
16610  }
16611  break;
16612  }
16613 
16614  default: // LCOV_EXCL_LINE
16615  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
16616  }
16617  }
16618  }
16619 
16620  private:
16629  inline unsigned int count_digits(number_unsigned_t x) noexcept
16630  {
16631  unsigned int n_digits = 1;
16632  for (;;)
16633  {
16634  if (x < 10)
16635  {
16636  return n_digits;
16637  }
16638  if (x < 100)
16639  {
16640  return n_digits + 1;
16641  }
16642  if (x < 1000)
16643  {
16644  return n_digits + 2;
16645  }
16646  if (x < 10000)
16647  {
16648  return n_digits + 3;
16649  }
16650  x = x / 10000u;
16651  n_digits += 4;
16652  }
16653  }
16654 
16664  template < typename NumberType, detail::enable_if_t <
16665  std::is_same<NumberType, number_unsigned_t>::value ||
16666  std::is_same<NumberType, number_integer_t>::value ||
16667  std::is_same<NumberType, binary_char_t>::value,
16668  int > = 0 >
16669  void dump_integer(NumberType x)
16670  {
16671  static constexpr std::array<std::array<char, 2>, 100> digits_to_99
16672  {
16673  {
16674  {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
16675  {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
16676  {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
16677  {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
16678  {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
16679  {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
16680  {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
16681  {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
16682  {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
16683  {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
16684  }
16685  };
16686 
16687  // special case for "0"
16688  if (x == 0)
16689  {
16690  o->write_character('0');
16691  return;
16692  }
16693 
16694  // use a pointer to fill the buffer
16695  auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16696 
16697  const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0); // see issue #755
16698  number_unsigned_t abs_value;
16699 
16700  unsigned int n_chars{};
16701 
16702  if (is_negative)
16703  {
16704  *buffer_ptr = '-';
16705  abs_value = remove_sign(static_cast<number_integer_t>(x));
16706 
16707  // account one more byte for the minus sign
16708  n_chars = 1 + count_digits(abs_value);
16709  }
16710  else
16711  {
16712  abs_value = static_cast<number_unsigned_t>(x);
16713  n_chars = count_digits(abs_value);
16714  }
16715 
16716  // spare 1 byte for '\0'
16717  JSON_ASSERT(n_chars < number_buffer.size() - 1);
16718 
16719  // jump to the end to generate the string from backward
16720  // so we later avoid reversing the result
16721  buffer_ptr += n_chars;
16722 
16723  // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu
16724  // See: https://www.youtube.com/watch?v=o4-CwDo2zpg
16725  while (abs_value >= 100)
16726  {
16727  const auto digits_index = static_cast<unsigned>((abs_value % 100));
16728  abs_value /= 100;
16729  *(--buffer_ptr) = digits_to_99[digits_index][1];
16730  *(--buffer_ptr) = digits_to_99[digits_index][0];
16731  }
16732 
16733  if (abs_value >= 10)
16734  {
16735  const auto digits_index = static_cast<unsigned>(abs_value);
16736  *(--buffer_ptr) = digits_to_99[digits_index][1];
16737  *(--buffer_ptr) = digits_to_99[digits_index][0];
16738  }
16739  else
16740  {
16741  *(--buffer_ptr) = static_cast<char>('0' + abs_value);
16742  }
16743 
16744  o->write_characters(number_buffer.data(), n_chars);
16745  }
16746 
16755  void dump_float(number_float_t x)
16756  {
16757  // NaN / inf
16758  if (!std::isfinite(x))
16759  {
16760  o->write_characters("null", 4);
16761  return;
16762  }
16763 
16764  // If number_float_t is an IEEE-754 single or double precision number,
16765  // use the Grisu2 algorithm to produce short numbers which are
16766  // guaranteed to round-trip, using strtof and strtod, resp.
16767  //
16768  // NB: The test below works if <long double> == <double>.
16769  static constexpr bool is_ieee_single_or_double
16770  = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
16771  (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
16772 
16773  dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
16774  }
16775 
16776  void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/)
16777  {
16778  auto* begin = number_buffer.data();
16779  auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
16780 
16781  o->write_characters(begin, static_cast<size_t>(end - begin));
16782  }
16783 
16784  void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/)
16785  {
16786  // get number of digits for a float -> text -> float round-trip
16787  static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
16788 
16789  // the actual conversion
16790  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16791  std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
16792 
16793  // negative value indicates an error
16794  JSON_ASSERT(len > 0);
16795  // check if buffer was large enough
16796  JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());
16797 
16798  // erase thousands separator
16799  if (thousands_sep != '\0')
16800  {
16801  auto* const end = std::remove(number_buffer.begin(),
16802  number_buffer.begin() + len, thousands_sep);
16803  std::fill(end, number_buffer.end(), '\0');
16804  JSON_ASSERT((end - number_buffer.begin()) <= len);
16805  len = (end - number_buffer.begin());
16806  }
16807 
16808  // convert decimal point to '.'
16809  if (decimal_point != '\0' && decimal_point != '.')
16810  {
16811  auto* const dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
16812  if (dec_pos != number_buffer.end())
16813  {
16814  *dec_pos = '.';
16815  }
16816  }
16817 
16818  o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));
16819 
16820  // determine if need to append ".0"
16821  const bool value_is_int_like =
16822  std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
16823  [](char c)
16824  {
16825  return c == '.' || c == 'e';
16826  });
16827 
16828  if (value_is_int_like)
16829  {
16830  o->write_characters(".0", 2);
16831  }
16832  }
16833 
16855  static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept
16856  {
16857  static const std::array<std::uint8_t, 400> utf8d =
16858  {
16859  {
16860  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F
16861  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F
16862  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F
16863  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F
16864  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F
16865  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF
16866  8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF
16867  0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF
16868  0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF
16869  0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0
16870  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2
16871  1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4
16872  1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6
16873  1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8
16874  }
16875  };
16876 
16877  JSON_ASSERT(byte < utf8d.size());
16878  const std::uint8_t type = utf8d[byte];
16879 
16880  codep = (state != UTF8_ACCEPT)
16881  ? (byte & 0x3fu) | (codep << 6u)
16882  : (0xFFu >> type) & (byte);
16883 
16884  std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type);
16885  JSON_ASSERT(index < 400);
16886  state = utf8d[index];
16887  return state;
16888  }
16889 
16890  /*
16891  * Overload to make the compiler happy while it is instantiating
16892  * dump_integer for number_unsigned_t.
16893  * Must never be called.
16894  */
16895  number_unsigned_t remove_sign(number_unsigned_t x)
16896  {
16897  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
16898  return x; // LCOV_EXCL_LINE
16899  }
16900 
16901  /*
16902  * Helper function for dump_integer
16903  *
16904  * This function takes a negative signed integer and returns its absolute
16905  * value as unsigned integer. The plus/minus shuffling is necessary as we can
16906  * not directly remove the sign of an arbitrary signed integer as the
16907  * absolute values of INT_MIN and INT_MAX are usually not the same. See
16908  * #1708 for details.
16909  */
16910  inline number_unsigned_t remove_sign(number_integer_t x) noexcept
16911  {
16912  JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression)
16913  return static_cast<number_unsigned_t>(-(x + 1)) + 1;
16914  }
16915 
16916  private:
16918  output_adapter_t<char> o = nullptr;
16919 
16921  std::array<char, 64> number_buffer{{}};
16922 
16924  const std::lconv* loc = nullptr;
16926  const char thousands_sep = '\0';
16928  const char decimal_point = '\0';
16929 
16931  std::array<char, 512> string_buffer{{}};
16932 
16934  const char indent_char;
16936  string_t indent_string;
16937 
16939  const error_handler_t error_handler;
16940 };
16941 } // namespace detail
16942 } // namespace nlohmann
16943 
16944 // #include <nlohmann/detail/value_t.hpp>
16945 
16946 // #include <nlohmann/json_fwd.hpp>
16947 
16948 // #include <nlohmann/ordered_map.hpp>
16949 
16950 
16951 #include <functional> // less
16952 #include <initializer_list> // initializer_list
16953 #include <iterator> // input_iterator_tag, iterator_traits
16954 #include <memory> // allocator
16955 #include <stdexcept> // for out_of_range
16956 #include <type_traits> // enable_if, is_convertible
16957 #include <utility> // pair
16958 #include <vector> // vector
16959 
16960 // #include <nlohmann/detail/macro_scope.hpp>
16961 
16962 
16963 namespace nlohmann
16964 {
16965 
16968 template <class Key, class T, class IgnoredLess = std::less<Key>,
16969  class Allocator = std::allocator<std::pair<const Key, T>>>
16970  struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
16971 {
16972  using key_type = Key;
16973  using mapped_type = T;
16974  using Container = std::vector<std::pair<const Key, T>, Allocator>;
16975  using typename Container::iterator;
16976  using typename Container::const_iterator;
16977  using typename Container::size_type;
16978  using typename Container::value_type;
16979 
16980  // Explicit constructors instead of `using Container::Container`
16981  // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4)
16982  ordered_map(const Allocator& alloc = Allocator()) : Container{alloc} {}
16983  template <class It>
16984  ordered_map(It first, It last, const Allocator& alloc = Allocator())
16985  : Container{first, last, alloc} {}
16986  ordered_map(std::initializer_list<T> init, const Allocator& alloc = Allocator() )
16987  : Container{init, alloc} {}
16988 
16989  std::pair<iterator, bool> emplace(const key_type& key, T&& t)
16990  {
16991  for (auto it = this->begin(); it != this->end(); ++it)
16992  {
16993  if (it->first == key)
16994  {
16995  return {it, false};
16996  }
16997  }
16998  Container::emplace_back(key, t);
16999  return {--this->end(), true};
17000  }
17001 
17002  T& operator[](const Key& key)
17003  {
17004  return emplace(key, T{}).first->second;
17005  }
17006 
17007  const T& operator[](const Key& key) const
17008  {
17009  return at(key);
17010  }
17011 
17012  T& at(const Key& key)
17013  {
17014  for (auto it = this->begin(); it != this->end(); ++it)
17015  {
17016  if (it->first == key)
17017  {
17018  return it->second;
17019  }
17020  }
17021 
17022  JSON_THROW(std::out_of_range("key not found"));
17023  }
17024 
17025  const T& at(const Key& key) const
17026  {
17027  for (auto it = this->begin(); it != this->end(); ++it)
17028  {
17029  if (it->first == key)
17030  {
17031  return it->second;
17032  }
17033  }
17034 
17035  JSON_THROW(std::out_of_range("key not found"));
17036  }
17037 
17038  size_type erase(const Key& key)
17039  {
17040  for (auto it = this->begin(); it != this->end(); ++it)
17041  {
17042  if (it->first == key)
17043  {
17044  // Since we cannot move const Keys, re-construct them in place
17045  for (auto next = it; ++next != this->end(); ++it)
17046  {
17047  it->~value_type(); // Destroy but keep allocation
17048  new (&*it) value_type{std::move(*next)};
17049  }
17050  Container::pop_back();
17051  return 1;
17052  }
17053  }
17054  return 0;
17055  }
17056 
17057  iterator erase(iterator pos)
17058  {
17059  auto it = pos;
17060 
17061  // Since we cannot move const Keys, re-construct them in place
17062  for (auto next = it; ++next != this->end(); ++it)
17063  {
17064  it->~value_type(); // Destroy but keep allocation
17065  new (&*it) value_type{std::move(*next)};
17066  }
17067  Container::pop_back();
17068  return pos;
17069  }
17070 
17071  size_type count(const Key& key) const
17072  {
17073  for (auto it = this->begin(); it != this->end(); ++it)
17074  {
17075  if (it->first == key)
17076  {
17077  return 1;
17078  }
17079  }
17080  return 0;
17081  }
17082 
17083  iterator find(const Key& key)
17084  {
17085  for (auto it = this->begin(); it != this->end(); ++it)
17086  {
17087  if (it->first == key)
17088  {
17089  return it;
17090  }
17091  }
17092  return Container::end();
17093  }
17094 
17095  const_iterator find(const Key& key) const
17096  {
17097  for (auto it = this->begin(); it != this->end(); ++it)
17098  {
17099  if (it->first == key)
17100  {
17101  return it;
17102  }
17103  }
17104  return Container::end();
17105  }
17106 
17107  std::pair<iterator, bool> insert( value_type&& value )
17108  {
17109  return emplace(value.first, std::move(value.second));
17110  }
17111 
17112  std::pair<iterator, bool> insert( const value_type& value )
17113  {
17114  for (auto it = this->begin(); it != this->end(); ++it)
17115  {
17116  if (it->first == value.first)
17117  {
17118  return {it, false};
17119  }
17120  }
17121  Container::push_back(value);
17122  return {--this->end(), true};
17123  }
17124 
17125  template<typename InputIt>
17126  using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
17127  std::input_iterator_tag>::value>::type;
17128 
17129  template<typename InputIt, typename = require_input_iter<InputIt>>
17130  void insert(InputIt first, InputIt last)
17131  {
17132  for (auto it = first; it != last; ++it)
17133  {
17134  insert(*it);
17135  }
17136  }
17137 };
17138 
17139 } // namespace nlohmann
17140 
17141 
17142 #if defined(JSON_HAS_CPP_17)
17143  #include <string_view>
17144 #endif
17145 
17151 namespace nlohmann
17152 {
17153 
17238 NLOHMANN_BASIC_JSON_TPL_DECLARATION
17239 class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
17240 {
17241  private:
17242  template<detail::value_t> friend struct detail::external_constructor;
17243  friend ::nlohmann::json_pointer<basic_json>;
17244 
17245  template<typename BasicJsonType, typename InputType>
17246  friend class ::nlohmann::detail::parser;
17247  friend ::nlohmann::detail::serializer<basic_json>;
17248  template<typename BasicJsonType>
17249  friend class ::nlohmann::detail::iter_impl;
17250  template<typename BasicJsonType, typename CharType>
17251  friend class ::nlohmann::detail::binary_writer;
17252  template<typename BasicJsonType, typename InputType, typename SAX>
17253  friend class ::nlohmann::detail::binary_reader;
17254  template<typename BasicJsonType>
17255  friend class ::nlohmann::detail::json_sax_dom_parser;
17256  template<typename BasicJsonType>
17257  friend class ::nlohmann::detail::json_sax_dom_callback_parser;
17258  friend class ::nlohmann::detail::exception;
17259 
17261  using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
17262 
17263  JSON_PRIVATE_UNLESS_TESTED:
17264  // convenience aliases for types residing in namespace detail;
17265  using lexer = ::nlohmann::detail::lexer_base<basic_json>;
17266 
17267  template<typename InputAdapterType>
17268  static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
17269  InputAdapterType adapter,
17270  detail::parser_callback_t<basic_json>cb = nullptr,
17271  const bool allow_exceptions = true,
17272  const bool ignore_comments = false
17273  )
17274  {
17275  return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
17276  std::move(cb), allow_exceptions, ignore_comments);
17277  }
17278 
17279  private:
17280  using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
17281  template<typename BasicJsonType>
17282  using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
17283  template<typename BasicJsonType>
17284  using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
17285  template<typename Iterator>
17286  using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
17287  template<typename Base> using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
17288 
17289  template<typename CharType>
17290  using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
17291 
17292  template<typename InputType>
17293  using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
17294  template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
17295 
17296  JSON_PRIVATE_UNLESS_TESTED:
17297  using serializer = ::nlohmann::detail::serializer<basic_json>;
17298 
17299  public:
17300  using value_t = detail::value_t;
17303  template<typename T, typename SFINAE>
17304  using json_serializer = JSONSerializer<T, SFINAE>;
17306  using error_handler_t = detail::error_handler_t;
17308  using cbor_tag_handler_t = detail::cbor_tag_handler_t;
17310  using initializer_list_t = std::initializer_list<detail::json_ref<basic_json>>;
17311 
17312  using input_format_t = detail::input_format_t;
17315 
17317  // exceptions //
17319 
17323 
17325  using exception = detail::exception;
17327  using parse_error = detail::parse_error;
17329  using invalid_iterator = detail::invalid_iterator;
17331  using type_error = detail::type_error;
17333  using out_of_range = detail::out_of_range;
17335  using other_error = detail::other_error;
17336 
17338 
17339 
17341  // container types //
17343 
17348 
17351 
17355  using const_reference = const value_type&;
17356 
17358  using difference_type = std::ptrdiff_t;
17360  using size_type = std::size_t;
17361 
17363  using allocator_type = AllocatorType<basic_json>;
17364 
17366  using pointer = typename std::allocator_traits<allocator_type>::pointer;
17368  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
17369 
17371  using iterator = iter_impl<basic_json>;
17373  using const_iterator = iter_impl<const basic_json>;
17375  using reverse_iterator = json_reverse_iterator<typename basic_json::iterator>;
17377  using const_reverse_iterator = json_reverse_iterator<typename basic_json::const_iterator>;
17378 
17380 
17381 
17386  {
17387  return allocator_type();
17388  }
17389 
17416 
17417  static basic_json meta()
17418  {
17419  basic_json result;
17420 
17421  result["copyright"] = "(C) 2013-2021 Niels Lohmann";
17422  result["name"] = "JSON for Modern C++";
17423  result["url"] = "https://github.com/nlohmann/json";
17424  result["version"]["string"] =
17425  std::to_string(NLOHMANN_JSON_VERSION_MAJOR) + "." +
17426  std::to_string(NLOHMANN_JSON_VERSION_MINOR) + "." +
17427  std::to_string(NLOHMANN_JSON_VERSION_PATCH);
17428  result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR;
17429  result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR;
17430  result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH;
17431 
17432 #ifdef _WIN32
17433  result["platform"] = "win32";
17434 #elif defined __linux__
17435  result["platform"] = "linux";
17436 #elif defined __APPLE__
17437  result["platform"] = "apple";
17438 #elif defined __unix__
17439  result["platform"] = "unix";
17440 #else
17441  result["platform"] = "unknown";
17442 #endif
17443 
17444 #if defined(__ICC) || defined(__INTEL_COMPILER)
17445  result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}};
17446 #elif defined(__clang__)
17447  result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}};
17448 #elif defined(__GNUC__) || defined(__GNUG__)
17449  result["compiler"] = {{"family", "gcc"}, {"version", std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__)}};
17450 #elif defined(__HP_cc) || defined(__HP_aCC)
17451  result["compiler"] = "hp"
17452 #elif defined(__IBMCPP__)
17453  result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}};
17454 #elif defined(_MSC_VER)
17455  result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}};
17456 #elif defined(__PGI)
17457  result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}};
17458 #elif defined(__SUNPRO_CC)
17459  result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}};
17460 #else
17461  result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}};
17462 #endif
17463 
17464 #ifdef __cplusplus
17465  result["compiler"]["c++"] = std::to_string(__cplusplus);
17466 #else
17467  result["compiler"]["c++"] = "unknown";
17468 #endif
17469  return result;
17470  }
17471 
17472 
17474  // JSON value data types //
17476 
17481 
17482 #if defined(JSON_HAS_CPP_14)
17483  // Use transparent comparator if possible, combined with perfect forwarding
17484  // on find() and count() calls prevents unnecessary string construction.
17485  using object_comparator_t = std::less<>;
17486 #else
17487  using object_comparator_t = std::less<StringType>;
17488 #endif
17489 
17573  using object_t = ObjectType<StringType,
17574  basic_json,
17576  AllocatorType<std::pair<const StringType,
17577  basic_json>>>;
17578 
17623  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
17624 
17676  using string_t = StringType;
17677 
17702  using boolean_t = BooleanType;
17703 
17774  using number_integer_t = NumberIntegerType;
17775 
17845  using number_unsigned_t = NumberUnsignedType;
17846 
17913  using number_float_t = NumberFloatType;
17914 
17986 
17987  private:
17988 
17990  template<typename T, typename... Args>
17991 
17992  static T* create(Args&& ... args)
17993  {
17994  AllocatorType<T> alloc;
17995  using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
17996 
17997  auto deleter = [&](T * obj)
17998  {
17999  AllocatorTraits::deallocate(alloc, obj, 1);
18000  };
18001  std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
18002  AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
18003  JSON_ASSERT(obj != nullptr);
18004  return obj.release();
18005  }
18006 
18008  // JSON value storage //
18010 
18011  JSON_PRIVATE_UNLESS_TESTED:
18037  union json_value
18038  {
18040  object_t* object;
18042  array_t* array;
18044  string_t* string;
18046  binary_t* binary;
18048  boolean_t boolean;
18050  number_integer_t number_integer;
18052  number_unsigned_t number_unsigned;
18054  number_float_t number_float;
18055 
18057  json_value() = default;
18059  json_value(boolean_t v) noexcept : boolean(v) {}
18061  json_value(number_integer_t v) noexcept : number_integer(v) {}
18063  json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}
18065  json_value(number_float_t v) noexcept : number_float(v) {}
18067  json_value(value_t t)
18068  {
18069  switch (t)
18070  {
18071  case value_t::object:
18072  {
18073  object = create<object_t>();
18074  break;
18075  }
18076 
18077  case value_t::array:
18078  {
18079  array = create<array_t>();
18080  break;
18081  }
18082 
18083  case value_t::string:
18084  {
18085  string = create<string_t>("");
18086  break;
18087  }
18088 
18089  case value_t::binary:
18090  {
18091  binary = create<binary_t>();
18092  break;
18093  }
18094 
18095  case value_t::boolean:
18096  {
18097  boolean = boolean_t(false);
18098  break;
18099  }
18100 
18101  case value_t::number_integer:
18102  {
18103  number_integer = number_integer_t(0);
18104  break;
18105  }
18106 
18107  case value_t::number_unsigned:
18108  {
18109  number_unsigned = number_unsigned_t(0);
18110  break;
18111  }
18112 
18113  case value_t::number_float:
18114  {
18115  number_float = number_float_t(0.0);
18116  break;
18117  }
18118 
18119  case value_t::null:
18120  {
18121  object = nullptr; // silence warning, see #821
18122  break;
18123  }
18124 
18125  default:
18126  {
18127  object = nullptr; // silence warning, see #821
18128  if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
18129  {
18130  JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.9.1", basic_json())); // LCOV_EXCL_LINE
18131  }
18132  break;
18133  }
18134  }
18135  }
18136 
18138  json_value(const string_t& value)
18139  {
18140  string = create<string_t>(value);
18141  }
18142 
18144  json_value(string_t&& value)
18145  {
18146  string = create<string_t>(std::move(value));
18147  }
18148 
18150  json_value(const object_t& value)
18151  {
18152  object = create<object_t>(value);
18153  }
18154 
18156  json_value(object_t&& value)
18157  {
18158  object = create<object_t>(std::move(value));
18159  }
18160 
18162  json_value(const array_t& value)
18163  {
18164  array = create<array_t>(value);
18165  }
18166 
18168  json_value(array_t&& value)
18169  {
18170  array = create<array_t>(std::move(value));
18171  }
18172 
18174  json_value(const typename binary_t::container_type& value)
18175  {
18176  binary = create<binary_t>(value);
18177  }
18178 
18180  json_value(typename binary_t::container_type&& value)
18181  {
18182  binary = create<binary_t>(std::move(value));
18183  }
18184 
18186  json_value(const binary_t& value)
18187  {
18188  binary = create<binary_t>(value);
18189  }
18190 
18192  json_value(binary_t&& value)
18193  {
18194  binary = create<binary_t>(std::move(value));
18195  }
18196 
18197  void destroy(value_t t)
18198  {
18199  if (t == value_t::array || t == value_t::object)
18200  {
18201  // flatten the current json_value to a heap-allocated stack
18202  std::vector<basic_json> stack;
18203 
18204  // move the top-level items to stack
18205  if (t == value_t::array)
18206  {
18207  stack.reserve(array->size());
18208  std::move(array->begin(), array->end(), std::back_inserter(stack));
18209  }
18210  else
18211  {
18212  stack.reserve(object->size());
18213  for (auto&& it : *object)
18214  {
18215  stack.push_back(std::move(it.second));
18216  }
18217  }
18218 
18219  while (!stack.empty())
18220  {
18221  // move the last item to local variable to be processed
18222  basic_json current_item(std::move(stack.back()));
18223  stack.pop_back();
18224 
18225  // if current_item is array/object, move
18226  // its children to the stack to be processed later
18227  if (current_item.is_array())
18228  {
18229  std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
18230 
18231  current_item.m_value.array->clear();
18232  }
18233  else if (current_item.is_object())
18234  {
18235  for (auto&& it : *current_item.m_value.object)
18236  {
18237  stack.push_back(std::move(it.second));
18238  }
18239 
18240  current_item.m_value.object->clear();
18241  }
18242 
18243  // it's now safe that current_item get destructed
18244  // since it doesn't have any children
18245  }
18246  }
18247 
18248  switch (t)
18249  {
18250  case value_t::object:
18251  {
18252  AllocatorType<object_t> alloc;
18253  std::allocator_traits<decltype(alloc)>::destroy(alloc, object);
18254  std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1);
18255  break;
18256  }
18257 
18258  case value_t::array:
18259  {
18260  AllocatorType<array_t> alloc;
18261  std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
18262  std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
18263  break;
18264  }
18265 
18266  case value_t::string:
18267  {
18268  AllocatorType<string_t> alloc;
18269  std::allocator_traits<decltype(alloc)>::destroy(alloc, string);
18270  std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);
18271  break;
18272  }
18273 
18274  case value_t::binary:
18275  {
18276  AllocatorType<binary_t> alloc;
18277  std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
18278  std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
18279  break;
18280  }
18281 
18282  default:
18283  {
18284  break;
18285  }
18286  }
18287  }
18288  };
18289 
18290  private:
18309  void assert_invariant(bool check_parents = true) const noexcept
18310  {
18311  JSON_ASSERT(m_type != value_t::object || m_value.object != nullptr);
18312  JSON_ASSERT(m_type != value_t::array || m_value.array != nullptr);
18313  JSON_ASSERT(m_type != value_t::string || m_value.string != nullptr);
18314  JSON_ASSERT(m_type != value_t::binary || m_value.binary != nullptr);
18315 
18316 #if JSON_DIAGNOSTICS
18317  JSON_TRY
18318  {
18319  // cppcheck-suppress assertWithSideEffect
18320  JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j)
18321  {
18322  return j.m_parent == this;
18323  }));
18324  }
18325  JSON_CATCH(...) {} // LCOV_EXCL_LINE
18326 #endif
18327  static_cast<void>(check_parents);
18328  }
18329 
18330  void set_parents()
18331  {
18332 #if JSON_DIAGNOSTICS
18333  switch (m_type)
18334  {
18335  case value_t::array:
18336  {
18337  for (auto& element : *m_value.array)
18338  {
18339  element.m_parent = this;
18340  }
18341  break;
18342  }
18343 
18344  case value_t::object:
18345  {
18346  for (auto& element : *m_value.object)
18347  {
18348  element.second.m_parent = this;
18349  }
18350  break;
18351  }
18352 
18353  default:
18354  break;
18355  }
18356 #endif
18357  }
18358 
18359  iterator set_parents(iterator it, typename iterator::difference_type count)
18360  {
18361 #if JSON_DIAGNOSTICS
18362  for (typename iterator::difference_type i = 0; i < count; ++i)
18363  {
18364  (it + i)->m_parent = this;
18365  }
18366 #else
18367  static_cast<void>(count);
18368 #endif
18369  return it;
18370  }
18371 
18372  reference set_parent(reference j, std::size_t old_capacity = std::size_t(-1))
18373  {
18374 #if JSON_DIAGNOSTICS
18375  if (old_capacity != std::size_t(-1))
18376  {
18377  // see https://github.com/nlohmann/json/issues/2838
18378  JSON_ASSERT(type() == value_t::array);
18379  if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity))
18380  {
18381  // capacity has changed: update all parents
18382  set_parents();
18383  return j;
18384  }
18385  }
18386 
18387  j.m_parent = this;
18388 #else
18389  static_cast<void>(j);
18390  static_cast<void>(old_capacity);
18391 #endif
18392  return j;
18393  }
18394 
18395  public:
18397  // JSON parser callback //
18399 
18415  using parse_event_t = detail::parse_event_t;
18416 
18466  using parser_callback_t = detail::parser_callback_t<basic_json>;
18467 
18469  // constructors //
18471 
18476 
18507  basic_json(const value_t v)
18508  : m_type(v), m_value(v)
18509  {
18510  assert_invariant();
18511  }
18512 
18531  basic_json(std::nullptr_t = nullptr) noexcept
18532  : basic_json(value_t::null)
18533  {
18534  assert_invariant();
18535  }
18536 
18599  template < typename CompatibleType,
18600  typename U = detail::uncvref_t<CompatibleType>,
18601  detail::enable_if_t <
18602  !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, int > = 0 >
18603  basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape)
18604  JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
18605  std::forward<CompatibleType>(val))))
18606  {
18607  JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val));
18608  set_parents();
18609  assert_invariant();
18610  }
18611 
18638  template < typename BasicJsonType,
18639  detail::enable_if_t <
18640  detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value, int > = 0 >
18641  basic_json(const BasicJsonType& val)
18642  {
18643  using other_boolean_t = typename BasicJsonType::boolean_t;
18644  using other_number_float_t = typename BasicJsonType::number_float_t;
18645  using other_number_integer_t = typename BasicJsonType::number_integer_t;
18646  using other_number_unsigned_t = typename BasicJsonType::number_unsigned_t;
18647  using other_string_t = typename BasicJsonType::string_t;
18648  using other_object_t = typename BasicJsonType::object_t;
18649  using other_array_t = typename BasicJsonType::array_t;
18650  using other_binary_t = typename BasicJsonType::binary_t;
18651 
18652  switch (val.type())
18653  {
18654  case value_t::boolean:
18655  JSONSerializer<other_boolean_t>::to_json(*this, val.template get<other_boolean_t>());
18656  break;
18657  case value_t::number_float:
18658  JSONSerializer<other_number_float_t>::to_json(*this, val.template get<other_number_float_t>());
18659  break;
18660  case value_t::number_integer:
18661  JSONSerializer<other_number_integer_t>::to_json(*this, val.template get<other_number_integer_t>());
18662  break;
18663  case value_t::number_unsigned:
18664  JSONSerializer<other_number_unsigned_t>::to_json(*this, val.template get<other_number_unsigned_t>());
18665  break;
18666  case value_t::string:
18667  JSONSerializer<other_string_t>::to_json(*this, val.template get_ref<const other_string_t&>());
18668  break;
18669  case value_t::object:
18670  JSONSerializer<other_object_t>::to_json(*this, val.template get_ref<const other_object_t&>());
18671  break;
18672  case value_t::array:
18673  JSONSerializer<other_array_t>::to_json(*this, val.template get_ref<const other_array_t&>());
18674  break;
18675  case value_t::binary:
18676  JSONSerializer<other_binary_t>::to_json(*this, val.template get_ref<const other_binary_t&>());
18677  break;
18678  case value_t::null:
18679  *this = nullptr;
18680  break;
18681  case value_t::discarded:
18682  m_type = value_t::discarded;
18683  break;
18684  default: // LCOV_EXCL_LINE
18685  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
18686  }
18687  set_parents();
18688  assert_invariant();
18689  }
18690 
18766  bool type_deduction = true,
18767  value_t manual_type = value_t::array)
18768  {
18769  // check if each element is an array with two elements whose first
18770  // element is a string
18771  bool is_an_object = std::all_of(init.begin(), init.end(),
18772  [](const detail::json_ref<basic_json>& element_ref)
18773  {
18774  return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
18775  });
18776 
18777  // adjust type if type deduction is not wanted
18778  if (!type_deduction)
18779  {
18780  // if array is wanted, do not create an object though possible
18781  if (manual_type == value_t::array)
18782  {
18783  is_an_object = false;
18784  }
18785 
18786  // if object is wanted but impossible, throw an exception
18787  if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
18788  {
18789  JSON_THROW(type_error::create(301, "cannot create object from initializer list", basic_json()));
18790  }
18791  }
18792 
18793  if (is_an_object)
18794  {
18795  // the initializer list is a list of pairs -> create object
18796  m_type = value_t::object;
18797  m_value = value_t::object;
18798 
18799  for (auto& element_ref : init)
18800  {
18801  auto element = element_ref.moved_or_copied();
18802  m_value.object->emplace(
18803  std::move(*((*element.m_value.array)[0].m_value.string)),
18804  std::move((*element.m_value.array)[1]));
18805  }
18806  }
18807  else
18808  {
18809  // the initializer list describes an array -> create array
18810  m_type = value_t::array;
18811  m_value.array = create<array_t>(init.begin(), init.end());
18812  }
18813 
18814  set_parents();
18815  assert_invariant();
18816  }
18817 
18845 
18846  static basic_json binary(const typename binary_t::container_type& init)
18847  {
18848  auto res = basic_json();
18849  res.m_type = value_t::binary;
18850  res.m_value = init;
18851  return res;
18852  }
18853 
18882 
18883  static basic_json binary(const typename binary_t::container_type& init, std::uint8_t subtype)
18884  {
18885  auto res = basic_json();
18886  res.m_type = value_t::binary;
18887  res.m_value = binary_t(init, subtype);
18888  return res;
18889  }
18890 
18892 
18894  {
18895  auto res = basic_json();
18896  res.m_type = value_t::binary;
18897  res.m_value = std::move(init);
18898  return res;
18899  }
18900 
18902 
18903  static basic_json binary(typename binary_t::container_type&& init, std::uint8_t subtype)
18904  {
18905  auto res = basic_json();
18906  res.m_type = value_t::binary;
18907  res.m_value = binary_t(std::move(init), subtype);
18908  return res;
18909  }
18910 
18948 
18950  {
18951  return basic_json(init, false, value_t::array);
18952  }
18953 
18992 
18994  {
18995  return basic_json(init, false, value_t::object);
18996  }
18997 
19021  : m_type(value_t::array)
19022  {
19023  m_value.array = create<array_t>(cnt, val);
19024  set_parents();
19025  assert_invariant();
19026  }
19027 
19083  template < class InputIT, typename std::enable_if <
19084  std::is_same<InputIT, typename basic_json_t::iterator>::value ||
19085  std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int >::type = 0 >
19086  basic_json(InputIT first, InputIT last)
19087  {
19088  JSON_ASSERT(first.m_object != nullptr);
19089  JSON_ASSERT(last.m_object != nullptr);
19090 
19091  // make sure iterator fits the current value
19092  if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
19093  {
19094  JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", basic_json()));
19095  }
19096 
19097  // copy type from first iterator
19098  m_type = first.m_object->m_type;
19099 
19100  // check if iterator range is complete for primitive values
19101  switch (m_type)
19102  {
19103  case value_t::boolean:
19104  case value_t::number_float:
19105  case value_t::number_integer:
19106  case value_t::number_unsigned:
19107  case value_t::string:
19108  {
19109  if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
19110  || !last.m_it.primitive_iterator.is_end()))
19111  {
19112  JSON_THROW(invalid_iterator::create(204, "iterators out of range", *first.m_object));
19113  }
19114  break;
19115  }
19116 
19117  default:
19118  break;
19119  }
19120 
19121  switch (m_type)
19122  {
19123  case value_t::number_integer:
19124  {
19125  m_value.number_integer = first.m_object->m_value.number_integer;
19126  break;
19127  }
19128 
19129  case value_t::number_unsigned:
19130  {
19131  m_value.number_unsigned = first.m_object->m_value.number_unsigned;
19132  break;
19133  }
19134 
19135  case value_t::number_float:
19136  {
19137  m_value.number_float = first.m_object->m_value.number_float;
19138  break;
19139  }
19140 
19141  case value_t::boolean:
19142  {
19143  m_value.boolean = first.m_object->m_value.boolean;
19144  break;
19145  }
19146 
19147  case value_t::string:
19148  {
19149  m_value = *first.m_object->m_value.string;
19150  break;
19151  }
19152 
19153  case value_t::object:
19154  {
19155  m_value.object = create<object_t>(first.m_it.object_iterator,
19156  last.m_it.object_iterator);
19157  break;
19158  }
19159 
19160  case value_t::array:
19161  {
19162  m_value.array = create<array_t>(first.m_it.array_iterator,
19163  last.m_it.array_iterator);
19164  break;
19165  }
19166 
19167  case value_t::binary:
19168  {
19169  m_value = *first.m_object->m_value.binary;
19170  break;
19171  }
19172 
19173  default:
19174  JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
19175  }
19176 
19177  set_parents();
19178  assert_invariant();
19179  }
19180 
19181 
19183  // other constructors and destructor //
19185 
19186  template<typename JsonRef,
19187  detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
19188  std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 >
19189  basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {}
19190 
19216  basic_json(const basic_json& other)
19217  : m_type(other.m_type)
19218  {
19219  // check of passed value is valid
19220  other.assert_invariant();
19221 
19222  switch (m_type)
19223  {
19224  case value_t::object:
19225  {
19226  m_value = *other.m_value.object;
19227  break;
19228  }
19229 
19230  case value_t::array:
19231  {
19232  m_value = *other.m_value.array;
19233  break;
19234  }
19235 
19236  case value_t::string:
19237  {
19238  m_value = *other.m_value.string;
19239  break;
19240  }
19241 
19242  case value_t::boolean:
19243  {
19244  m_value = other.m_value.boolean;
19245  break;
19246  }
19247 
19248  case value_t::number_integer:
19249  {
19250  m_value = other.m_value.number_integer;
19251  break;
19252  }
19253 
19254  case value_t::number_unsigned:
19255  {
19256  m_value = other.m_value.number_unsigned;
19257  break;
19258  }
19259 
19260  case value_t::number_float:
19261  {
19262  m_value = other.m_value.number_float;
19263  break;
19264  }
19265 
19266  case value_t::binary:
19267  {
19268  m_value = *other.m_value.binary;
19269  break;
19270  }
19271 
19272  default:
19273  break;
19274  }
19275 
19276  set_parents();
19277  assert_invariant();
19278  }
19279 
19306  basic_json(basic_json&& other) noexcept
19307  : m_type(std::move(other.m_type)),
19308  m_value(std::move(other.m_value))
19309  {
19310  // check that passed value is valid
19311  other.assert_invariant(false);
19312 
19313  // invalidate payload
19314  other.m_type = value_t::null;
19315  other.m_value = {};
19316 
19317  set_parents();
19318  assert_invariant();
19319  }
19320 
19344  basic_json& operator=(basic_json other) noexcept (
19345  std::is_nothrow_move_constructible<value_t>::value&&
19346  std::is_nothrow_move_assignable<value_t>::value&&
19347  std::is_nothrow_move_constructible<json_value>::value&&
19348  std::is_nothrow_move_assignable<json_value>::value
19349  )
19350  {
19351  // check that passed value is valid
19352  other.assert_invariant();
19353 
19354  using std::swap;
19355  swap(m_type, other.m_type);
19356  swap(m_value, other.m_value);
19357 
19358  set_parents();
19359  assert_invariant();
19360  return *this;
19361  }
19362 
19378  ~basic_json() noexcept
19379  {
19380  assert_invariant(false);
19381  m_value.destroy(m_type);
19382  }
19383 
19385 
19386  public:
19388  // object inspection //
19390 
19394 
19442  string_t dump(const int indent = -1,
19443  const char indent_char = ' ',
19444  const bool ensure_ascii = false,
19445  const error_handler_t error_handler = error_handler_t::strict) const
19446  {
19447  string_t result;
19448  serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
19449 
19450  if (indent >= 0)
19451  {
19452  s.dump(*this, true, ensure_ascii, static_cast<unsigned int>(indent));
19453  }
19454  else
19455  {
19456  s.dump(*this, false, ensure_ascii, 0);
19457  }
19458 
19459  return result;
19460  }
19461 
19495  constexpr value_t type() const noexcept
19496  {
19497  return m_type;
19498  }
19499 
19526  constexpr bool is_primitive() const noexcept
19527  {
19528  return is_null() || is_string() || is_boolean() || is_number() || is_binary();
19529  }
19530 
19553  constexpr bool is_structured() const noexcept
19554  {
19555  return is_array() || is_object();
19556  }
19557 
19575  constexpr bool is_null() const noexcept
19576  {
19577  return m_type == value_t::null;
19578  }
19579 
19597  constexpr bool is_boolean() const noexcept
19598  {
19599  return m_type == value_t::boolean;
19600  }
19601 
19627  constexpr bool is_number() const noexcept
19628  {
19629  return is_number_integer() || is_number_float();
19630  }
19631 
19656  constexpr bool is_number_integer() const noexcept
19657  {
19658  return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
19659  }
19660 
19684  constexpr bool is_number_unsigned() const noexcept
19685  {
19686  return m_type == value_t::number_unsigned;
19687  }
19688 
19712  constexpr bool is_number_float() const noexcept
19713  {
19714  return m_type == value_t::number_float;
19715  }
19716 
19734  constexpr bool is_object() const noexcept
19735  {
19736  return m_type == value_t::object;
19737  }
19738 
19756  constexpr bool is_array() const noexcept
19757  {
19758  return m_type == value_t::array;
19759  }
19760 
19778  constexpr bool is_string() const noexcept
19779  {
19780  return m_type == value_t::string;
19781  }
19782 
19800  constexpr bool is_binary() const noexcept
19801  {
19802  return m_type == value_t::binary;
19803  }
19804 
19827  constexpr bool is_discarded() const noexcept
19828  {
19829  return m_type == value_t::discarded;
19830  }
19831 
19853  constexpr operator value_t() const noexcept
19854  {
19855  return m_type;
19856  }
19857 
19859 
19860  private:
19862  // value access //
19864 
19866  boolean_t get_impl(boolean_t* /*unused*/) const
19867  {
19868  if (JSON_HEDLEY_LIKELY(is_boolean()))
19869  {
19870  return m_value.boolean;
19871  }
19872 
19873  JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(type_name()), *this));
19874  }
19875 
19877  object_t* get_impl_ptr(object_t* /*unused*/) noexcept
19878  {
19879  return is_object() ? m_value.object : nullptr;
19880  }
19881 
19883  constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept
19884  {
19885  return is_object() ? m_value.object : nullptr;
19886  }
19887 
19889  array_t* get_impl_ptr(array_t* /*unused*/) noexcept
19890  {
19891  return is_array() ? m_value.array : nullptr;
19892  }
19893 
19895  constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept
19896  {
19897  return is_array() ? m_value.array : nullptr;
19898  }
19899 
19901  string_t* get_impl_ptr(string_t* /*unused*/) noexcept
19902  {
19903  return is_string() ? m_value.string : nullptr;
19904  }
19905 
19907  constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept
19908  {
19909  return is_string() ? m_value.string : nullptr;
19910  }
19911 
19913  boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept
19914  {
19915  return is_boolean() ? &m_value.boolean : nullptr;
19916  }
19917 
19919  constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept
19920  {
19921  return is_boolean() ? &m_value.boolean : nullptr;
19922  }
19923 
19925  number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept
19926  {
19927  return is_number_integer() ? &m_value.number_integer : nullptr;
19928  }
19929 
19931  constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept
19932  {
19933  return is_number_integer() ? &m_value.number_integer : nullptr;
19934  }
19935 
19937  number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept
19938  {
19939  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
19940  }
19941 
19943  constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept
19944  {
19945  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
19946  }
19947 
19949  number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept
19950  {
19951  return is_number_float() ? &m_value.number_float : nullptr;
19952  }
19953 
19955  constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept
19956  {
19957  return is_number_float() ? &m_value.number_float : nullptr;
19958  }
19959 
19961  binary_t* get_impl_ptr(binary_t* /*unused*/) noexcept
19962  {
19963  return is_binary() ? m_value.binary : nullptr;
19964  }
19965 
19967  constexpr const binary_t* get_impl_ptr(const binary_t* /*unused*/) const noexcept
19968  {
19969  return is_binary() ? m_value.binary : nullptr;
19970  }
19971 
19983  template<typename ReferenceType, typename ThisType>
19984  static ReferenceType get_ref_impl(ThisType& obj)
19985  {
19986  // delegate the call to get_ptr<>()
19987  auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
19988 
19989  if (JSON_HEDLEY_LIKELY(ptr != nullptr))
19990  {
19991  return *ptr;
19992  }
19993 
19994  JSON_THROW(type_error::create(303, "incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
19995  }
19996 
19997  public:
20001 
20028  template<typename PointerType, typename std::enable_if<
20029  std::is_pointer<PointerType>::value, int>::type = 0>
20030  auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20031  {
20032  // delegate the call to get_impl_ptr<>()
20033  return get_impl_ptr(static_cast<PointerType>(nullptr));
20034  }
20035 
20040  template < typename PointerType, typename std::enable_if <
20041  std::is_pointer<PointerType>::value&&
20042  std::is_const<typename std::remove_pointer<PointerType>::type>::value, int >::type = 0 >
20043  constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20044  {
20045  // delegate the call to get_impl_ptr<>() const
20046  return get_impl_ptr(static_cast<PointerType>(nullptr));
20047  }
20048 
20049  private:
20088  template < typename ValueType,
20089  detail::enable_if_t <
20090  detail::is_default_constructible<ValueType>::value&&
20091  detail::has_from_json<basic_json_t, ValueType>::value,
20092  int > = 0 >
20093  ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept(
20094  JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
20095  {
20096  ValueType ret{};
20097  JSONSerializer<ValueType>::from_json(*this, ret);
20098  return ret;
20099  }
20100 
20131  template < typename ValueType,
20132  detail::enable_if_t <
20133  detail::has_non_default_from_json<basic_json_t, ValueType>::value,
20134  int > = 0 >
20135  ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept(
20136  JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
20137  {
20138  return JSONSerializer<ValueType>::from_json(*this);
20139  }
20140 
20156  template < typename BasicJsonType,
20157  detail::enable_if_t <
20158  detail::is_basic_json<BasicJsonType>::value,
20159  int > = 0 >
20160  BasicJsonType get_impl(detail::priority_tag<2> /*unused*/) const
20161  {
20162  return *this;
20163  }
20164 
20179  template<typename BasicJsonType,
20180  detail::enable_if_t<
20181  std::is_same<BasicJsonType, basic_json_t>::value,
20182  int> = 0>
20183  basic_json get_impl(detail::priority_tag<3> /*unused*/) const
20184  {
20185  return *this;
20186  }
20187 
20192  template<typename PointerType,
20193  detail::enable_if_t<
20194  std::is_pointer<PointerType>::value,
20195  int> = 0>
20196  constexpr auto get_impl(detail::priority_tag<4> /*unused*/) const noexcept
20197  -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
20198  {
20199  // delegate the call to get_ptr
20200  return get_ptr<PointerType>();
20201  }
20202 
20203  public:
20227  template < typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>>
20228 #if defined(JSON_HAS_CPP_14)
20229  constexpr
20230 #endif
20231  auto get() const noexcept(
20232  noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})))
20233  -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))
20234  {
20235  // we cannot static_assert on ValueTypeCV being non-const, because
20236  // there is support for get<const basic_json_t>(), which is why we
20237  // still need the uncvref
20238  static_assert(!std::is_reference<ValueTypeCV>::value,
20239  "get() cannot be used with reference types, you might want to use get_ref()");
20240  return get_impl<ValueType>(detail::priority_tag<4> {});
20241  }
20242 
20270  template<typename PointerType, typename std::enable_if<
20271  std::is_pointer<PointerType>::value, int>::type = 0>
20272  auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
20273  {
20274  // delegate the call to get_ptr
20275  return get_ptr<PointerType>();
20276  }
20277 
20311  template < typename ValueType,
20312  detail::enable_if_t <
20313  !detail::is_basic_json<ValueType>::value&&
20314  detail::has_from_json<basic_json_t, ValueType>::value,
20315  int > = 0 >
20316  ValueType & get_to(ValueType& v) const noexcept(noexcept(
20317  JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
20318  {
20319  JSONSerializer<ValueType>::from_json(*this, v);
20320  return v;
20321  }
20322 
20323  // specialization to allow to call get_to with a basic_json value
20324  // see https://github.com/nlohmann/json/issues/2175
20325  template<typename ValueType,
20326  detail::enable_if_t <
20327  detail::is_basic_json<ValueType>::value,
20328  int> = 0>
20329  ValueType & get_to(ValueType& v) const
20330  {
20331  v = *this;
20332  return v;
20333  }
20334 
20335  template <
20336  typename T, std::size_t N,
20337  typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
20338  detail::enable_if_t <
20339  detail::has_from_json<basic_json_t, Array>::value, int > = 0 >
20340  Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
20341  noexcept(noexcept(JSONSerializer<Array>::from_json(
20342  std::declval<const basic_json_t&>(), v)))
20343  {
20344  JSONSerializer<Array>::from_json(*this, v);
20345  return v;
20346  }
20347 
20374  template<typename ReferenceType, typename std::enable_if<
20375  std::is_reference<ReferenceType>::value, int>::type = 0>
20376  ReferenceType get_ref()
20377  {
20378  // delegate call to get_ref_impl
20379  return get_ref_impl<ReferenceType>(*this);
20380  }
20381 
20386  template < typename ReferenceType, typename std::enable_if <
20387  std::is_reference<ReferenceType>::value&&
20388  std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int >::type = 0 >
20389  ReferenceType get_ref() const
20390  {
20391  // delegate call to get_ref_impl
20392  return get_ref_impl<ReferenceType>(*this);
20393  }
20394 
20424  template < typename ValueType, typename std::enable_if <
20425  !std::is_pointer<ValueType>::value&&
20426  !std::is_same<ValueType, detail::json_ref<basic_json>>::value&&
20427  !std::is_same<ValueType, typename string_t::value_type>::value&&
20428  !detail::is_basic_json<ValueType>::value
20429  && !std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
20430 #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
20431  && !std::is_same<ValueType, typename std::string_view>::value
20432 #endif
20433  && detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
20434  , int >::type = 0 >
20435  JSON_EXPLICIT operator ValueType() const
20436  {
20437  // delegate the call to get<>() const
20438  return get<ValueType>();
20439  }
20440 
20451  {
20452  if (!is_binary())
20453  {
20454  JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this));
20455  }
20456 
20457  return *get_ptr<binary_t*>();
20458  }
20459 
20461  const binary_t& get_binary() const
20462  {
20463  if (!is_binary())
20464  {
20465  JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this));
20466  }
20467 
20468  return *get_ptr<const binary_t*>();
20469  }
20470 
20472 
20473 
20475  // element access //
20477 
20481 
20509  {
20510  // at only works for arrays
20511  if (JSON_HEDLEY_LIKELY(is_array()))
20512  {
20513  JSON_TRY
20514  {
20515  return set_parent(m_value.array->at(idx));
20516  }
20517  JSON_CATCH (std::out_of_range&)
20518  {
20519  // create better exception explanation
20520  JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
20521  }
20522  }
20523  else
20524  {
20525  JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
20526  }
20527  }
20528 
20555  const_reference at(size_type idx) const
20556  {
20557  // at only works for arrays
20558  if (JSON_HEDLEY_LIKELY(is_array()))
20559  {
20560  JSON_TRY
20561  {
20562  return m_value.array->at(idx);
20563  }
20564  JSON_CATCH (std::out_of_range&)
20565  {
20566  // create better exception explanation
20567  JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
20568  }
20569  }
20570  else
20571  {
20572  JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
20573  }
20574  }
20575 
20606  reference at(const typename object_t::key_type& key)
20607  {
20608  // at only works for objects
20609  if (JSON_HEDLEY_LIKELY(is_object()))
20610  {
20611  JSON_TRY
20612  {
20613  return set_parent(m_value.object->at(key));
20614  }
20615  JSON_CATCH (std::out_of_range&)
20616  {
20617  // create better exception explanation
20618  JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this));
20619  }
20620  }
20621  else
20622  {
20623  JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
20624  }
20625  }
20626 
20657  const_reference at(const typename object_t::key_type& key) const
20658  {
20659  // at only works for objects
20660  if (JSON_HEDLEY_LIKELY(is_object()))
20661  {
20662  JSON_TRY
20663  {
20664  return m_value.object->at(key);
20665  }
20666  JSON_CATCH (std::out_of_range&)
20667  {
20668  // create better exception explanation
20669  JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this));
20670  }
20671  }
20672  else
20673  {
20674  JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
20675  }
20676  }
20677 
20704  {
20705  // implicitly convert null value to an empty array
20706  if (is_null())
20707  {
20708  m_type = value_t::array;
20709  m_value.array = create<array_t>();
20710  assert_invariant();
20711  }
20712 
20713  // operator[] only works for arrays
20714  if (JSON_HEDLEY_LIKELY(is_array()))
20715  {
20716  // fill up array with null values if given idx is outside range
20717  if (idx >= m_value.array->size())
20718  {
20719 #if JSON_DIAGNOSTICS
20720  // remember array size before resizing
20721  const auto previous_size = m_value.array->size();
20722 #endif
20723  m_value.array->resize(idx + 1);
20724 
20725 #if JSON_DIAGNOSTICS
20726  // set parent for values added above
20727  set_parents(begin() + static_cast<typename iterator::difference_type>(previous_size), static_cast<typename iterator::difference_type>(idx + 1 - previous_size));
20728 #endif
20729  }
20730 
20731  return m_value.array->operator[](idx);
20732  }
20733 
20734  JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
20735  }
20736 
20757  {
20758  // const operator[] only works for arrays
20759  if (JSON_HEDLEY_LIKELY(is_array()))
20760  {
20761  return m_value.array->operator[](idx);
20762  }
20763 
20764  JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
20765  }
20794  reference operator[](const typename object_t::key_type& key)
20795  {
20796  // implicitly convert null value to an empty object
20797  if (is_null())
20798  {
20799  m_type = value_t::object;
20800  m_value.object = create<object_t>();
20801  assert_invariant();
20802  }
20803 
20804  // operator[] only works for objects
20805  if (JSON_HEDLEY_LIKELY(is_object()))
20806  {
20807  return set_parent(m_value.object->operator[](key));
20808  }
20809 
20810  JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
20811  }
20812 
20843  const_reference operator[](const typename object_t::key_type& key) const
20844  {
20845  // const operator[] only works for objects
20846  if (JSON_HEDLEY_LIKELY(is_object()))
20847  {
20848  JSON_ASSERT(m_value.object->find(key) != m_value.object->end());
20849  return m_value.object->find(key)->second;
20850  }
20851 
20852  JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
20853  }
20854 
20882  template<typename T>
20883  JSON_HEDLEY_NON_NULL(2)
20884  reference operator[](T* key)
20885  {
20886  // implicitly convert null to object
20887  if (is_null())
20888  {
20889  m_type = value_t::object;
20890  m_value = value_t::object;
20891  assert_invariant();
20892  }
20893 
20894  // at only works for objects
20895  if (JSON_HEDLEY_LIKELY(is_object()))
20896  {
20897  return set_parent(m_value.object->operator[](key));
20898  }
20899 
20900  JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
20901  }
20902 
20933  template<typename T>
20934  JSON_HEDLEY_NON_NULL(2)
20935  const_reference operator[](T* key) const
20936  {
20937  // at only works for objects
20938  if (JSON_HEDLEY_LIKELY(is_object()))
20939  {
20940  JSON_ASSERT(m_value.object->find(key) != m_value.object->end());
20941  return m_value.object->find(key)->second;
20942  }
20943 
20944  JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
20945  }
20946 
20997  // using std::is_convertible in a std::enable_if will fail when using explicit conversions
20998  template < class ValueType, typename std::enable_if <
20999  detail::is_getable<basic_json_t, ValueType>::value
21000  && !std::is_same<value_t, ValueType>::value, int >::type = 0 >
21001  ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
21002  {
21003  // at only works for objects
21004  if (JSON_HEDLEY_LIKELY(is_object()))
21005  {
21006  // if key is found, return value and given default value otherwise
21007  const auto it = find(key);
21008  if (it != end())
21009  {
21010  return it->template get<ValueType>();
21011  }
21012 
21013  return default_value;
21014  }
21015 
21016  JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this));
21017  }
21018 
21023  string_t value(const typename object_t::key_type& key, const char* default_value) const
21024  {
21025  return value(key, string_t(default_value));
21026  }
21027 
21071  template<class ValueType, typename std::enable_if<
21072  detail::is_getable<basic_json_t, ValueType>::value, int>::type = 0>
21073  ValueType value(const json_pointer& ptr, const ValueType& default_value) const
21074  {
21075  // at only works for objects
21076  if (JSON_HEDLEY_LIKELY(is_object()))
21077  {
21078  // if pointer resolves a value, return it or use default value
21079  JSON_TRY
21080  {
21081  return ptr.get_checked(this).template get<ValueType>();
21082  }
21083  JSON_INTERNAL_CATCH (out_of_range&)
21084  {
21085  return default_value;
21086  }
21087  }
21088 
21089  JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this));
21090  }
21091 
21096  JSON_HEDLEY_NON_NULL(3)
21097  string_t value(const json_pointer& ptr, const char* default_value) const
21098  {
21099  return value(ptr, string_t(default_value));
21100  }
21101 
21127  reference front()
21128  {
21129  return *begin();
21130  }
21131 
21135  const_reference front() const
21136  {
21137  return *cbegin();
21138  }
21139 
21171  reference back()
21172  {
21173  auto tmp = end();
21174  --tmp;
21175  return *tmp;
21176  }
21177 
21182  {
21183  auto tmp = cend();
21184  --tmp;
21185  return *tmp;
21186  }
21187 
21234  template < class IteratorType, typename std::enable_if <
21235  std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21236  std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int >::type
21237  = 0 >
21238  IteratorType erase(IteratorType pos)
21239  {
21240  // make sure iterator fits the current value
21241  if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))
21242  {
21243  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
21244  }
21245 
21246  IteratorType result = end();
21247 
21248  switch (m_type)
21249  {
21250  case value_t::boolean:
21251  case value_t::number_float:
21252  case value_t::number_integer:
21253  case value_t::number_unsigned:
21254  case value_t::string:
21255  case value_t::binary:
21256  {
21257  if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21258  {
21259  JSON_THROW(invalid_iterator::create(205, "iterator out of range", *this));
21260  }
21261 
21262  if (is_string())
21263  {
21264  AllocatorType<string_t> alloc;
21265  std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
21266  std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
21267  m_value.string = nullptr;
21268  }
21269  else if (is_binary())
21270  {
21271  AllocatorType<binary_t> alloc;
21272  std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
21273  std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
21274  m_value.binary = nullptr;
21275  }
21276 
21277  m_type = value_t::null;
21278  assert_invariant();
21279  break;
21280  }
21281 
21282  case value_t::object:
21283  {
21284  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
21285  break;
21286  }
21287 
21288  case value_t::array:
21289  {
21290  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
21291  break;
21292  }
21293 
21294  default:
21295  JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
21296  }
21297 
21298  return result;
21299  }
21300 
21347  template < class IteratorType, typename std::enable_if <
21348  std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21349  std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int >::type
21350  = 0 >
21351  IteratorType erase(IteratorType first, IteratorType last)
21352  {
21353  // make sure iterator fits the current value
21354  if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object))
21355  {
21356  JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", *this));
21357  }
21358 
21359  IteratorType result = end();
21360 
21361  switch (m_type)
21362  {
21363  case value_t::boolean:
21364  case value_t::number_float:
21365  case value_t::number_integer:
21366  case value_t::number_unsigned:
21367  case value_t::string:
21368  case value_t::binary:
21369  {
21370  if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21371  || !last.m_it.primitive_iterator.is_end()))
21372  {
21373  JSON_THROW(invalid_iterator::create(204, "iterators out of range", *this));
21374  }
21375 
21376  if (is_string())
21377  {
21378  AllocatorType<string_t> alloc;
21379  std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
21380  std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
21381  m_value.string = nullptr;
21382  }
21383  else if (is_binary())
21384  {
21385  AllocatorType<binary_t> alloc;
21386  std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
21387  std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
21388  m_value.binary = nullptr;
21389  }
21390 
21391  m_type = value_t::null;
21392  assert_invariant();
21393  break;
21394  }
21395 
21396  case value_t::object:
21397  {
21398  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
21399  last.m_it.object_iterator);
21400  break;
21401  }
21402 
21403  case value_t::array:
21404  {
21405  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
21406  last.m_it.array_iterator);
21407  break;
21408  }
21409 
21410  default:
21411  JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
21412  }
21413 
21414  return result;
21415  }
21416 
21446  size_type erase(const typename object_t::key_type& key)
21447  {
21448  // this erase only works for objects
21449  if (JSON_HEDLEY_LIKELY(is_object()))
21450  {
21451  return m_value.object->erase(key);
21452  }
21453 
21454  JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
21455  }
21481  void erase(const size_type idx)
21482  {
21483  // this erase only works for arrays
21484  if (JSON_HEDLEY_LIKELY(is_array()))
21485  {
21486  if (JSON_HEDLEY_UNLIKELY(idx >= size()))
21487  {
21488  JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
21489  }
21490 
21491  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
21492  }
21493  else
21494  {
21495  JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
21496  }
21497  }
21498 
21500 
21501 
21503  // lookup //
21505 
21508 
21533  template<typename KeyT>
21534  iterator find(KeyT&& key)
21535  {
21536  auto result = end();
21537 
21538  if (is_object())
21539  {
21540  result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
21541  }
21542 
21543  return result;
21544  }
21545 
21550  template<typename KeyT>
21551  const_iterator find(KeyT&& key) const
21552  {
21553  auto result = cend();
21554 
21555  if (is_object())
21556  {
21557  result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
21558  }
21559 
21560  return result;
21561  }
21562 
21584  template<typename KeyT>
21585  size_type count(KeyT&& key) const
21586  {
21587  // return 0 for all nonobject types
21588  return is_object() ? m_value.object->count(std::forward<KeyT>(key)) : 0;
21589  }
21590 
21616  template < typename KeyT, typename std::enable_if <
21617  !std::is_same<typename std::decay<KeyT>::type, json_pointer>::value, int >::type = 0 >
21618  bool contains(KeyT && key) const
21619  {
21620  return is_object() && m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
21621  }
21622 
21649  bool contains(const json_pointer& ptr) const
21650  {
21651  return ptr.contains(this);
21652  }
21653 
21655 
21656 
21658  // iterators //
21660 
21663 
21688  iterator begin() noexcept
21689  {
21690  iterator result(this);
21691  result.set_begin();
21692  return result;
21693  }
21694 
21698  const_iterator begin() const noexcept
21699  {
21700  return cbegin();
21701  }
21702 
21728  const_iterator cbegin() const noexcept
21729  {
21730  const_iterator result(this);
21731  result.set_begin();
21732  return result;
21733  }
21734 
21759  iterator end() noexcept
21760  {
21761  iterator result(this);
21762  result.set_end();
21763  return result;
21764  }
21765 
21769  const_iterator end() const noexcept
21770  {
21771  return cend();
21772  }
21773 
21799  const_iterator cend() const noexcept
21800  {
21801  const_iterator result(this);
21802  result.set_end();
21803  return result;
21804  }
21805 
21829  reverse_iterator rbegin() noexcept
21830  {
21831  return reverse_iterator(end());
21832  }
21833 
21837  const_reverse_iterator rbegin() const noexcept
21838  {
21839  return crbegin();
21840  }
21841 
21866  reverse_iterator rend() noexcept
21867  {
21868  return reverse_iterator(begin());
21869  }
21870 
21874  const_reverse_iterator rend() const noexcept
21875  {
21876  return crend();
21877  }
21878 
21903  const_reverse_iterator crbegin() const noexcept
21904  {
21905  return const_reverse_iterator(cend());
21906  }
21907 
21932  const_reverse_iterator crend() const noexcept
21933  {
21934  return const_reverse_iterator(cbegin());
21935  }
21936 
21937  public:
21995  JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
21996  static iteration_proxy<iterator> iterator_wrapper(reference ref) noexcept
21997  {
21998  return ref.items();
21999  }
22000 
22004  JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22005  static iteration_proxy<const_iterator> iterator_wrapper(const_reference ref) noexcept
22006  {
22007  return ref.items();
22008  }
22009 
22078  iteration_proxy<iterator> items() noexcept
22079  {
22080  return iteration_proxy<iterator>(*this);
22081  }
22082 
22086  iteration_proxy<const_iterator> items() const noexcept
22087  {
22088  return iteration_proxy<const_iterator>(*this);
22089  }
22090 
22092 
22093 
22095  // capacity //
22097 
22100 
22143  bool empty() const noexcept
22144  {
22145  switch (m_type)
22146  {
22147  case value_t::null:
22148  {
22149  // null values are empty
22150  return true;
22151  }
22152 
22153  case value_t::array:
22154  {
22155  // delegate call to array_t::empty()
22156  return m_value.array->empty();
22157  }
22158 
22159  case value_t::object:
22160  {
22161  // delegate call to object_t::empty()
22162  return m_value.object->empty();
22163  }
22164 
22165  default:
22166  {
22167  // all other types are nonempty
22168  return false;
22169  }
22170  }
22171  }
22172 
22216  size_type size() const noexcept
22217  {
22218  switch (m_type)
22219  {
22220  case value_t::null:
22221  {
22222  // null values are empty
22223  return 0;
22224  }
22225 
22226  case value_t::array:
22227  {
22228  // delegate call to array_t::size()
22229  return m_value.array->size();
22230  }
22231 
22232  case value_t::object:
22233  {
22234  // delegate call to object_t::size()
22235  return m_value.object->size();
22236  }
22237 
22238  default:
22239  {
22240  // all other types have size 1
22241  return 1;
22242  }
22243  }
22244  }
22245 
22287  size_type max_size() const noexcept
22288  {
22289  switch (m_type)
22290  {
22291  case value_t::array:
22292  {
22293  // delegate call to array_t::max_size()
22294  return m_value.array->max_size();
22295  }
22296 
22297  case value_t::object:
22298  {
22299  // delegate call to object_t::max_size()
22300  return m_value.object->max_size();
22301  }
22302 
22303  default:
22304  {
22305  // all other types have max_size() == size()
22306  return size();
22307  }
22308  }
22309  }
22310 
22312 
22313 
22315  // modifiers //
22317 
22320 
22358  void clear() noexcept
22359  {
22360  switch (m_type)
22361  {
22362  case value_t::number_integer:
22363  {
22364  m_value.number_integer = 0;
22365  break;
22366  }
22367 
22368  case value_t::number_unsigned:
22369  {
22370  m_value.number_unsigned = 0;
22371  break;
22372  }
22373 
22374  case value_t::number_float:
22375  {
22376  m_value.number_float = 0.0;
22377  break;
22378  }
22379 
22380  case value_t::boolean:
22381  {
22382  m_value.boolean = false;
22383  break;
22384  }
22385 
22386  case value_t::string:
22387  {
22388  m_value.string->clear();
22389  break;
22390  }
22391 
22392  case value_t::binary:
22393  {
22394  m_value.binary->clear();
22395  break;
22396  }
22397 
22398  case value_t::array:
22399  {
22400  m_value.array->clear();
22401  break;
22402  }
22403 
22404  case value_t::object:
22405  {
22406  m_value.object->clear();
22407  break;
22408  }
22409 
22410  default:
22411  break;
22412  }
22413  }
22414 
22435  void push_back(basic_json&& val)
22436  {
22437  // push_back only works for null objects or arrays
22438  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22439  {
22440  JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
22441  }
22442 
22443  // transform null object into an array
22444  if (is_null())
22445  {
22446  m_type = value_t::array;
22447  m_value = value_t::array;
22448  assert_invariant();
22449  }
22450 
22451  // add element to array (move semantics)
22452  const auto old_capacity = m_value.array->capacity();
22453  m_value.array->push_back(std::move(val));
22454  set_parent(m_value.array->back(), old_capacity);
22455  // if val is moved from, basic_json move constructor marks it null so we do not call the destructor
22456  }
22457 
22463  {
22464  push_back(std::move(val));
22465  return *this;
22466  }
22467 
22472  void push_back(const basic_json& val)
22473  {
22474  // push_back only works for null objects or arrays
22475  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22476  {
22477  JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
22478  }
22479 
22480  // transform null object into an array
22481  if (is_null())
22482  {
22483  m_type = value_t::array;
22484  m_value = value_t::array;
22485  assert_invariant();
22486  }
22487 
22488  // add element to array
22489  const auto old_capacity = m_value.array->capacity();
22490  m_value.array->push_back(val);
22491  set_parent(m_value.array->back(), old_capacity);
22492  }
22493 
22498  reference operator+=(const basic_json& val)
22499  {
22500  push_back(val);
22501  return *this;
22502  }
22503 
22524  void push_back(const typename object_t::value_type& val)
22525  {
22526  // push_back only works for null objects or objects
22527  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22528  {
22529  JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
22530  }
22531 
22532  // transform null object into an object
22533  if (is_null())
22534  {
22535  m_type = value_t::object;
22536  m_value = value_t::object;
22537  assert_invariant();
22538  }
22539 
22540  // add element to object
22541  auto res = m_value.object->insert(val);
22542  set_parent(res.first->second);
22543  }
22544 
22549  reference operator+=(const typename object_t::value_type& val)
22550  {
22551  push_back(val);
22552  return *this;
22553  }
22554 
22580  void push_back(initializer_list_t init)
22581  {
22582  if (is_object() && init.size() == 2 && (*init.begin())->is_string())
22583  {
22584  basic_json&& key = init.begin()->moved_or_copied();
22585  push_back(typename object_t::value_type(
22586  std::move(key.get_ref<string_t&>()), (init.begin() + 1)->moved_or_copied()));
22587  }
22588  else
22589  {
22591  }
22592  }
22593 
22599  {
22600  push_back(init);
22601  return *this;
22602  }
22603 
22627  template<class... Args>
22628  reference emplace_back(Args&& ... args)
22629  {
22630  // emplace_back only works for null objects or arrays
22631  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22632  {
22633  JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name()), *this));
22634  }
22635 
22636  // transform null object into an array
22637  if (is_null())
22638  {
22639  m_type = value_t::array;
22640  m_value = value_t::array;
22641  assert_invariant();
22642  }
22643 
22644  // add element to array (perfect forwarding)
22645  const auto old_capacity = m_value.array->capacity();
22646  m_value.array->emplace_back(std::forward<Args>(args)...);
22647  return set_parent(m_value.array->back(), old_capacity);
22648  }
22649 
22677  template<class... Args>
22678  std::pair<iterator, bool> emplace(Args&& ... args)
22679  {
22680  // emplace only works for null objects or arrays
22681  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22682  {
22683  JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()), *this));
22684  }
22685 
22686  // transform null object into an object
22687  if (is_null())
22688  {
22689  m_type = value_t::object;
22690  m_value = value_t::object;
22691  assert_invariant();
22692  }
22693 
22694  // add element to array (perfect forwarding)
22695  auto res = m_value.object->emplace(std::forward<Args>(args)...);
22696  set_parent(res.first->second);
22697 
22698  // create result iterator and set iterator to the result of emplace
22699  auto it = begin();
22700  it.m_it.object_iterator = res.first;
22701 
22702  // return pair of iterator and boolean
22703  return {it, res.second};
22704  }
22705 
22709  template<typename... Args>
22710  iterator insert_iterator(const_iterator pos, Args&& ... args)
22711  {
22712  iterator result(this);
22713  JSON_ASSERT(m_value.array != nullptr);
22714 
22715  auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
22716  m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22717  result.m_it.array_iterator = m_value.array->begin() + insert_pos;
22718 
22719  // This could have been written as:
22720  // result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
22721  // but the return value of insert is missing in GCC 4.8, so it is written this way instead.
22722 
22723  set_parents();
22724  return result;
22725  }
22726 
22749  iterator insert(const_iterator pos, const basic_json& val)
22750  {
22751  // insert only works for arrays
22752  if (JSON_HEDLEY_LIKELY(is_array()))
22753  {
22754  // check if iterator pos fits to this JSON value
22755  if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
22756  {
22757  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
22758  }
22760  // insert to array and return iterator
22761  return insert_iterator(pos, val);
22762  }
22763 
22764  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22765  }
22766 
22772  {
22773  return insert(pos, val);
22774  }
22775 
22800  iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
22801  {
22802  // insert only works for arrays
22803  if (JSON_HEDLEY_LIKELY(is_array()))
22804  {
22805  // check if iterator pos fits to this JSON value
22806  if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
22807  {
22808  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
22809  }
22811  // insert to array and return iterator
22812  return insert_iterator(pos, cnt, val);
22813  }
22814 
22815  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22816  }
22817 
22849  {
22850  // insert only works for arrays
22851  if (JSON_HEDLEY_UNLIKELY(!is_array()))
22852  {
22853  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22854  }
22855 
22856  // check if iterator pos fits to this JSON value
22857  if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
22858  {
22859  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
22860  }
22861 
22862  // check if range iterators belong to the same JSON object
22863  if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22864  {
22865  JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
22866  }
22867 
22868  if (JSON_HEDLEY_UNLIKELY(first.m_object == this))
22869  {
22870  JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container", *this));
22871  }
22872 
22873  // insert to array and return iterator
22874  return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
22875  }
22876 
22902  {
22903  // insert only works for arrays
22904  if (JSON_HEDLEY_UNLIKELY(!is_array()))
22905  {
22906  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22907  }
22908 
22909  // check if iterator pos fits to this JSON value
22910  if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
22911  {
22912  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
22913  }
22914 
22915  // insert to array and return iterator
22916  return insert_iterator(pos, ilist.begin(), ilist.end());
22917  }
22918 
22942  void insert(const_iterator first, const_iterator last)
22943  {
22944  // insert only works for objects
22945  if (JSON_HEDLEY_UNLIKELY(!is_object()))
22946  {
22947  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22948  }
22949 
22950  // check if range iterators belong to the same JSON object
22951  if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22952  {
22953  JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
22954  }
22955 
22956  // passed iterators must belong to objects
22957  if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22958  {
22959  JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
22960  }
22961 
22962  m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22963  }
22964 
22984  void update(const_reference j)
22985  {
22986  // implicitly convert null value to an empty object
22987  if (is_null())
22988  {
22989  m_type = value_t::object;
22990  m_value.object = create<object_t>();
22991  assert_invariant();
22992  }
22993 
22994  if (JSON_HEDLEY_UNLIKELY(!is_object()))
22995  {
22996  JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
22997  }
22998  if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
22999  {
23000  JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this));
23001  }
23002 
23003  for (auto it = j.cbegin(); it != j.cend(); ++it)
23004  {
23005  m_value.object->operator[](it.key()) = it.value();
23006  }
23007  }
23008 
23035  void update(const_iterator first, const_iterator last)
23036  {
23037  // implicitly convert null value to an empty object
23038  if (is_null())
23039  {
23040  m_type = value_t::object;
23041  m_value.object = create<object_t>();
23042  assert_invariant();
23043  }
23044 
23045  if (JSON_HEDLEY_UNLIKELY(!is_object()))
23046  {
23047  JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
23048  }
23049 
23050  // check if range iterators belong to the same JSON object
23051  if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23052  {
23053  JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
23054  }
23055 
23056  // passed iterators must belong to objects
23057  if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
23058  || !last.m_object->is_object()))
23059  {
23060  JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
23061  }
23062 
23063  for (auto it = first; it != last; ++it)
23064  {
23065  m_value.object->operator[](it.key()) = it.value();
23066  }
23067  }
23068 
23086  void swap(reference other) noexcept (
23087  std::is_nothrow_move_constructible<value_t>::value&&
23088  std::is_nothrow_move_assignable<value_t>::value&&
23089  std::is_nothrow_move_constructible<json_value>::value&&
23090  std::is_nothrow_move_assignable<json_value>::value
23091  )
23092  {
23093  std::swap(m_type, other.m_type);
23094  std::swap(m_value, other.m_value);
23095 
23096  set_parents();
23097  other.set_parents();
23098  assert_invariant();
23099  }
23100 
23119  friend void swap(reference left, reference right) noexcept (
23120  std::is_nothrow_move_constructible<value_t>::value&&
23121  std::is_nothrow_move_assignable<value_t>::value&&
23122  std::is_nothrow_move_constructible<json_value>::value&&
23123  std::is_nothrow_move_assignable<json_value>::value
23124  )
23125  {
23126  left.swap(right);
23127  }
23128 
23149  void swap(array_t& other) // NOLINT(bugprone-exception-escape)
23150  {
23151  // swap only works for arrays
23152  if (JSON_HEDLEY_LIKELY(is_array()))
23153  {
23154  std::swap(*(m_value.array), other);
23155  }
23156  else
23157  {
23158  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
23159  }
23160  }
23161 
23182  void swap(object_t& other) // NOLINT(bugprone-exception-escape)
23183  {
23184  // swap only works for objects
23185  if (JSON_HEDLEY_LIKELY(is_object()))
23186  {
23187  std::swap(*(m_value.object), other);
23188  }
23189  else
23190  {
23191  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
23192  }
23193  }
23194 
23215  void swap(string_t& other) // NOLINT(bugprone-exception-escape)
23216  {
23217  // swap only works for strings
23218  if (JSON_HEDLEY_LIKELY(is_string()))
23219  {
23220  std::swap(*(m_value.string), other);
23221  }
23222  else
23223  {
23224  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
23225  }
23226  }
23227 
23248  void swap(binary_t& other) // NOLINT(bugprone-exception-escape)
23249  {
23250  // swap only works for strings
23251  if (JSON_HEDLEY_LIKELY(is_binary()))
23252  {
23253  std::swap(*(m_value.binary), other);
23254  }
23255  else
23256  {
23257  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
23258  }
23259  }
23260 
23262  void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape)
23263  {
23264  // swap only works for strings
23265  if (JSON_HEDLEY_LIKELY(is_binary()))
23266  {
23267  std::swap(*(m_value.binary), other);
23268  }
23269  else
23270  {
23271  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
23272  }
23273  }
23274 
23276 
23277  public:
23279  // lexicographical comparison operators //
23281 
23284 
23340  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
23341  {
23342  const auto lhs_type = lhs.type();
23343  const auto rhs_type = rhs.type();
23344 
23345  if (lhs_type == rhs_type)
23346  {
23347  switch (lhs_type)
23348  {
23349  case value_t::array:
23350  return *lhs.m_value.array == *rhs.m_value.array;
23351 
23352  case value_t::object:
23353  return *lhs.m_value.object == *rhs.m_value.object;
23354 
23355  case value_t::null:
23356  return true;
23357 
23358  case value_t::string:
23359  return *lhs.m_value.string == *rhs.m_value.string;
23360 
23361  case value_t::boolean:
23362  return lhs.m_value.boolean == rhs.m_value.boolean;
23363 
23364  case value_t::number_integer:
23365  return lhs.m_value.number_integer == rhs.m_value.number_integer;
23366 
23367  case value_t::number_unsigned:
23368  return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
23369 
23370  case value_t::number_float:
23371  return lhs.m_value.number_float == rhs.m_value.number_float;
23372 
23373  case value_t::binary:
23374  return *lhs.m_value.binary == *rhs.m_value.binary;
23375 
23376  default:
23377  return false;
23378  }
23379  }
23380  else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23381  {
23382  return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
23383  }
23384  else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23385  {
23386  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
23387  }
23388  else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23389  {
23390  return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
23391  }
23392  else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23393  {
23394  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
23395  }
23396  else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23397  {
23398  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
23399  }
23400  else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23401  {
23402  return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23403  }
23404 
23405  return false;
23406  }
23407 
23412  template<typename ScalarType, typename std::enable_if<
23413  std::is_scalar<ScalarType>::value, int>::type = 0>
23414  friend bool operator==(const_reference lhs, ScalarType rhs) noexcept
23415  {
23416  return lhs == basic_json(rhs);
23417  }
23418 
23423  template<typename ScalarType, typename std::enable_if<
23424  std::is_scalar<ScalarType>::value, int>::type = 0>
23425  friend bool operator==(ScalarType lhs, const_reference rhs) noexcept
23426  {
23427  return basic_json(lhs) == rhs;
23428  }
23429 
23448  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
23449  {
23450  return !(lhs == rhs);
23451  }
23452 
23457  template<typename ScalarType, typename std::enable_if<
23458  std::is_scalar<ScalarType>::value, int>::type = 0>
23459  friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept
23460  {
23461  return lhs != basic_json(rhs);
23462  }
23463 
23468  template<typename ScalarType, typename std::enable_if<
23469  std::is_scalar<ScalarType>::value, int>::type = 0>
23470  friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept
23471  {
23472  return basic_json(lhs) != rhs;
23473  }
23474 
23501  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
23502  {
23503  const auto lhs_type = lhs.type();
23504  const auto rhs_type = rhs.type();
23505 
23506  if (lhs_type == rhs_type)
23507  {
23508  switch (lhs_type)
23509  {
23510  case value_t::array:
23511  // note parentheses are necessary, see
23512  // https://github.com/nlohmann/json/issues/1530
23513  return (*lhs.m_value.array) < (*rhs.m_value.array);
23514 
23515  case value_t::object:
23516  return (*lhs.m_value.object) < (*rhs.m_value.object);
23517 
23518  case value_t::null:
23519  return false;
23520 
23521  case value_t::string:
23522  return (*lhs.m_value.string) < (*rhs.m_value.string);
23523 
23524  case value_t::boolean:
23525  return (lhs.m_value.boolean) < (rhs.m_value.boolean);
23526 
23527  case value_t::number_integer:
23528  return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
23529 
23530  case value_t::number_unsigned:
23531  return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
23532 
23533  case value_t::number_float:
23534  return (lhs.m_value.number_float) < (rhs.m_value.number_float);
23535 
23536  case value_t::binary:
23537  return (*lhs.m_value.binary) < (*rhs.m_value.binary);
23538 
23539  default:
23540  return false;
23541  }
23542  }
23543  else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23544  {
23545  return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
23546  }
23547  else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23548  {
23549  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
23550  }
23551  else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23552  {
23553  return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
23554  }
23555  else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23556  {
23557  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
23558  }
23559  else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23560  {
23561  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23562  }
23563  else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23564  {
23565  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
23566  }
23567 
23568  // We only reach this line if we cannot compare values. In that case,
23569  // we compare types. Note we have to call the operator explicitly,
23570  // because MSVC has problems otherwise.
23571  return operator<(lhs_type, rhs_type);
23572  }
23573 
23578  template<typename ScalarType, typename std::enable_if<
23579  std::is_scalar<ScalarType>::value, int>::type = 0>
23580  friend bool operator<(const_reference lhs, ScalarType rhs) noexcept
23581  {
23582  return lhs < basic_json(rhs);
23583  }
23584 
23589  template<typename ScalarType, typename std::enable_if<
23590  std::is_scalar<ScalarType>::value, int>::type = 0>
23591  friend bool operator<(ScalarType lhs, const_reference rhs) noexcept
23592  {
23593  return basic_json(lhs) < rhs;
23594  }
23595 
23615  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
23616  {
23617  return !(rhs < lhs);
23618  }
23619 
23624  template<typename ScalarType, typename std::enable_if<
23625  std::is_scalar<ScalarType>::value, int>::type = 0>
23626  friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept
23627  {
23628  return lhs <= basic_json(rhs);
23629  }
23630 
23635  template<typename ScalarType, typename std::enable_if<
23636  std::is_scalar<ScalarType>::value, int>::type = 0>
23637  friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept
23638  {
23639  return basic_json(lhs) <= rhs;
23640  }
23641 
23661  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
23662  {
23663  return !(lhs <= rhs);
23664  }
23665 
23670  template<typename ScalarType, typename std::enable_if<
23671  std::is_scalar<ScalarType>::value, int>::type = 0>
23672  friend bool operator>(const_reference lhs, ScalarType rhs) noexcept
23673  {
23674  return lhs > basic_json(rhs);
23675  }
23676 
23681  template<typename ScalarType, typename std::enable_if<
23682  std::is_scalar<ScalarType>::value, int>::type = 0>
23683  friend bool operator>(ScalarType lhs, const_reference rhs) noexcept
23684  {
23685  return basic_json(lhs) > rhs;
23686  }
23687 
23707  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
23708  {
23709  return !(lhs < rhs);
23710  }
23711 
23716  template<typename ScalarType, typename std::enable_if<
23717  std::is_scalar<ScalarType>::value, int>::type = 0>
23718  friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept
23719  {
23720  return lhs >= basic_json(rhs);
23721  }
23722 
23727  template<typename ScalarType, typename std::enable_if<
23728  std::is_scalar<ScalarType>::value, int>::type = 0>
23729  friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept
23730  {
23731  return basic_json(lhs) >= rhs;
23732  }
23733 
23735 
23737  // serialization //
23742 #ifndef JSON_NO_IO
23774  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
23775  {
23776  // read width member and use it as indentation parameter if nonzero
23777  const bool pretty_print = o.width() > 0;
23778  const auto indentation = pretty_print ? o.width() : 0;
23779 
23780  // reset width to 0 for subsequent calls to this stream
23781  o.width(0);
23782 
23783  // do the actual serialization
23784  serializer s(detail::output_adapter<char>(o), o.fill());
23785  s.dump(j, pretty_print, false, static_cast<unsigned int>(indentation));
23786  return o;
23787  }
23788 
23797  JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&))
23798  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
23799  {
23800  return o << j;
23801  }
23802 #endif // JSON_NO_IO
23804 
23805 
23807  // deserialization //
23809 
23812 
23864  template<typename InputType>
23865 
23866  static basic_json parse(InputType&& i,
23867  const parser_callback_t cb = nullptr,
23868  const bool allow_exceptions = true,
23869  const bool ignore_comments = false)
23870  {
23871  basic_json result;
23872  parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result);
23873  return result;
23874  }
23875 
23902  template<typename IteratorType>
23903 
23904  static basic_json parse(IteratorType first,
23905  IteratorType last,
23906  const parser_callback_t cb = nullptr,
23907  const bool allow_exceptions = true,
23908  const bool ignore_comments = false)
23909  {
23910  basic_json result;
23911  parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result);
23912  return result;
23913  }
23915 
23916  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
23917  static basic_json parse(detail::span_input_adapter&& i,
23918  const parser_callback_t cb = nullptr,
23919  const bool allow_exceptions = true,
23920  const bool ignore_comments = false)
23921  {
23922  basic_json result;
23923  parser(i.get(), cb, allow_exceptions, ignore_comments).parse(true, result);
23924  return result;
23925  }
23926 
23957  template<typename InputType>
23958  static bool accept(InputType&& i,
23959  const bool ignore_comments = false)
23960  {
23961  return parser(detail::input_adapter(std::forward<InputType>(i)), nullptr, false, ignore_comments).accept(true);
23962  }
23963 
23964  template<typename IteratorType>
23965  static bool accept(IteratorType first, IteratorType last,
23966  const bool ignore_comments = false)
23967  {
23968  return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true);
23969  }
23970 
23971 
23972  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
23973  static bool accept(detail::span_input_adapter&& i,
23974  const bool ignore_comments = false)
23975  {
23976  return parser(i.get(), nullptr, false, ignore_comments).accept(true);
23977  }
23978 
24019  template <typename InputType, typename SAX>
24020  JSON_HEDLEY_NON_NULL(2)
24021  static bool sax_parse(InputType&& i, SAX* sax,
24023  const bool strict = true,
24024  const bool ignore_comments = false)
24025  {
24026  auto ia = detail::input_adapter(std::forward<InputType>(i));
24027  return format == input_format_t::json
24028  ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
24029  : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24030  }
24032  template<class IteratorType, class SAX>
24033  JSON_HEDLEY_NON_NULL(3)
24034  static bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
24035  input_format_t format = input_format_t::json,
24036  const bool strict = true,
24037  const bool ignore_comments = false)
24038  {
24039  auto ia = detail::input_adapter(std::move(first), std::move(last));
24040  return format == input_format_t::json
24041  ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
24042  : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24043  }
24045  template <typename SAX>
24046  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
24047  JSON_HEDLEY_NON_NULL(2)
24048  static bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
24049  input_format_t format = input_format_t::json,
24050  const bool strict = true,
24051  const bool ignore_comments = false)
24052  {
24053  auto ia = i.get();
24054  return format == input_format_t::json
24055  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
24056  ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
24057  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
24058  : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24059  }
24060 #ifndef JSON_NO_IO
24069  JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&))
24070  friend std::istream& operator<<(basic_json& j, std::istream& i)
24071  {
24072  return operator>>(i, j);
24073  }
24074 
24100  friend std::istream& operator>>(std::istream& i, basic_json& j)
24101  {
24102  parser(detail::input_adapter(i)).parse(false, j);
24103  return i;
24104  }
24105 #endif // JSON_NO_IO
24107 
24109  // convenience functions //
24111 
24143 
24144  const char* type_name() const noexcept
24145  {
24146  {
24147  switch (m_type)
24148  {
24149  case value_t::null:
24150  return "null";
24151  case value_t::object:
24152  return "object";
24153  case value_t::array:
24154  return "array";
24155  case value_t::string:
24156  return "string";
24157  case value_t::boolean:
24158  return "boolean";
24159  case value_t::binary:
24160  return "binary";
24161  case value_t::discarded:
24162  return "discarded";
24163  default:
24164  return "number";
24165  }
24166  }
24167  }
24168 
24169 
24170  JSON_PRIVATE_UNLESS_TESTED:
24172  // member variables //
24174 
24176  value_t m_type = value_t::null;
24177 
24179  json_value m_value = {};
24181 #if JSON_DIAGNOSTICS
24183  basic_json* m_parent = nullptr;
24184 #endif
24185 
24187  // binary serialization/deserialization //
24192 
24193  public:
24288  static std::vector<uint8_t> to_cbor(const basic_json& j)
24289  {
24290  std::vector<uint8_t> result;
24291  to_cbor(j, result);
24292  return result;
24293  }
24294 
24295  static void to_cbor(const basic_json& j, detail::output_adapter<uint8_t> o)
24296  {
24297  binary_writer<uint8_t>(o).write_cbor(j);
24298  }
24299 
24300  static void to_cbor(const basic_json& j, detail::output_adapter<char> o)
24301  {
24302  binary_writer<char>(o).write_cbor(j);
24303  }
24304 
24383  static std::vector<uint8_t> to_msgpack(const basic_json& j)
24384  {
24385  std::vector<uint8_t> result;
24386  to_msgpack(j, result);
24387  return result;
24388  }
24389 
24390  static void to_msgpack(const basic_json& j, detail::output_adapter<uint8_t> o)
24391  {
24392  binary_writer<uint8_t>(o).write_msgpack(j);
24393  }
24394 
24395  static void to_msgpack(const basic_json& j, detail::output_adapter<char> o)
24396  {
24397  binary_writer<char>(o).write_msgpack(j);
24398  }
24399 
24486  static std::vector<uint8_t> to_ubjson(const basic_json& j,
24487  const bool use_size = false,
24488  const bool use_type = false)
24489  {
24490  std::vector<uint8_t> result;
24491  to_ubjson(j, result, use_size, use_type);
24492  return result;
24493  }
24494 
24495  static void to_ubjson(const basic_json& j, detail::output_adapter<uint8_t> o,
24496  const bool use_size = false, const bool use_type = false)
24497  {
24498  binary_writer<uint8_t>(o).write_ubjson(j, use_size, use_type);
24499  }
24500 
24501  static void to_ubjson(const basic_json& j, detail::output_adapter<char> o,
24502  const bool use_size = false, const bool use_type = false)
24503  {
24504  binary_writer<char>(o).write_ubjson(j, use_size, use_type);
24505  }
24506 
24507 
24564  static std::vector<uint8_t> to_bson(const basic_json& j)
24565  {
24566  std::vector<uint8_t> result;
24567  to_bson(j, result);
24568  return result;
24569  }
24570 
24579  static void to_bson(const basic_json& j, detail::output_adapter<uint8_t> o)
24580  {
24581  binary_writer<uint8_t>(o).write_bson(j);
24582  }
24583 
24587  static void to_bson(const basic_json& j, detail::output_adapter<char> o)
24588  {
24589  binary_writer<char>(o).write_bson(j);
24590  }
24591 
24592 
24695  template<typename InputType>
24696 
24697  static basic_json from_cbor(InputType&& i,
24698  const bool strict = true,
24699  const bool allow_exceptions = true,
24700  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24701  {
24702  basic_json result;
24703  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24704  auto ia = detail::input_adapter(std::forward<InputType>(i));
24705  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24706  return res ? result : basic_json(value_t::discarded);
24707  }
24708 
24712  template<typename IteratorType>
24713 
24714  static basic_json from_cbor(IteratorType first, IteratorType last,
24715  const bool strict = true,
24716  const bool allow_exceptions = true,
24717  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24718  {
24719  basic_json result;
24720  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24721  auto ia = detail::input_adapter(std::move(first), std::move(last));
24722  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24723  return res ? result : basic_json(value_t::discarded);
24724  }
24725 
24726  template<typename T>
24727 
24728  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24729  static basic_json from_cbor(const T* ptr, std::size_t len,
24730  const bool strict = true,
24731  const bool allow_exceptions = true,
24732  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24733  {
24734  return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
24735  }
24736 
24737 
24738 
24739  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24740  static basic_json from_cbor(detail::span_input_adapter&& i,
24741  const bool strict = true,
24742  const bool allow_exceptions = true,
24743  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24744  {
24745  basic_json result;
24746  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24747  auto ia = i.get();
24748  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
24749  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24750  return res ? result : basic_json(value_t::discarded);
24751  }
24752 
24839  template<typename InputType>
24840 
24841  static basic_json from_msgpack(InputType&& i,
24842  const bool strict = true,
24843  const bool allow_exceptions = true)
24844  {
24845  basic_json result;
24846  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24847  auto ia = detail::input_adapter(std::forward<InputType>(i));
24848  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24849  return res ? result : basic_json(value_t::discarded);
24850  }
24855  template<typename IteratorType>
24856 
24857  static basic_json from_msgpack(IteratorType first, IteratorType last,
24858  const bool strict = true,
24859  const bool allow_exceptions = true)
24860  {
24861  basic_json result;
24862  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24863  auto ia = detail::input_adapter(std::move(first), std::move(last));
24864  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24865  return res ? result : basic_json(value_t::discarded);
24866  }
24868 
24869  template<typename T>
24870 
24871  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24872  static basic_json from_msgpack(const T* ptr, std::size_t len,
24873  const bool strict = true,
24874  const bool allow_exceptions = true)
24875  {
24876  return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
24877  }
24878 
24879 
24880  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24881  static basic_json from_msgpack(detail::span_input_adapter&& i,
24882  const bool strict = true,
24883  const bool allow_exceptions = true)
24884  {
24885  basic_json result;
24886  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24887  auto ia = i.get();
24888  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
24889  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24890  return res ? result : basic_json(value_t::discarded);
24891  }
24892 
24893 
24956  template<typename InputType>
24957 
24958  static basic_json from_ubjson(InputType&& i,
24959  const bool strict = true,
24960  const bool allow_exceptions = true)
24961  {
24962  basic_json result;
24963  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24964  auto ia = detail::input_adapter(std::forward<InputType>(i));
24965  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24966  return res ? result : basic_json(value_t::discarded);
24967  }
24972  template<typename IteratorType>
24973 
24974  static basic_json from_ubjson(IteratorType first, IteratorType last,
24975  const bool strict = true,
24976  const bool allow_exceptions = true)
24977  {
24978  basic_json result;
24979  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24980  auto ia = detail::input_adapter(std::move(first), std::move(last));
24981  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24982  return res ? result : basic_json(value_t::discarded);
24983  }
24985  template<typename T>
24986 
24987  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24988  static basic_json from_ubjson(const T* ptr, std::size_t len,
24989  const bool strict = true,
24990  const bool allow_exceptions = true)
24991  {
24992  return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
24993  }
24994 
24995 
24996  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24997  static basic_json from_ubjson(detail::span_input_adapter&& i,
24998  const bool strict = true,
24999  const bool allow_exceptions = true)
25000  {
25001  basic_json result;
25002  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25003  auto ia = i.get();
25004  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
25005  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25006  return res ? result : basic_json(value_t::discarded);
25007  }
25008 
25009 
25070  template<typename InputType>
25071 
25072  static basic_json from_bson(InputType&& i,
25073  const bool strict = true,
25074  const bool allow_exceptions = true)
25075  {
25076  basic_json result;
25077  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25078  auto ia = detail::input_adapter(std::forward<InputType>(i));
25079  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25080  return res ? result : basic_json(value_t::discarded);
25081  }
25086  template<typename IteratorType>
25087 
25088  static basic_json from_bson(IteratorType first, IteratorType last,
25089  const bool strict = true,
25090  const bool allow_exceptions = true)
25091  {
25092  basic_json result;
25093  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25094  auto ia = detail::input_adapter(std::move(first), std::move(last));
25095  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25096  return res ? result : basic_json(value_t::discarded);
25097  }
25099  template<typename T>
25100 
25101  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
25102  static basic_json from_bson(const T* ptr, std::size_t len,
25103  const bool strict = true,
25104  const bool allow_exceptions = true)
25105  {
25106  return from_bson(ptr, ptr + len, strict, allow_exceptions);
25107  }
25108 
25109 
25110  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
25111  static basic_json from_bson(detail::span_input_adapter&& i,
25112  const bool strict = true,
25113  const bool allow_exceptions = true)
25114  {
25115  basic_json result;
25116  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25117  auto ia = i.get();
25118  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
25119  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25120  return res ? result : basic_json(value_t::discarded);
25121  }
25123 
25125  // JSON Pointer support //
25127 
25130 
25164  reference operator[](const json_pointer& ptr)
25165  {
25166  return ptr.get_unchecked(this);
25167  }
25168 
25192  const_reference operator[](const json_pointer& ptr) const
25193  {
25194  return ptr.get_unchecked(this);
25195  }
25196 
25235  reference at(const json_pointer& ptr)
25236  {
25237  return ptr.get_checked(this);
25238  }
25239 
25278  const_reference at(const json_pointer& ptr) const
25279  {
25280  return ptr.get_checked(this);
25281  }
25282 
25305  basic_json flatten() const
25306  {
25307  basic_json result(value_t::object);
25308  json_pointer::flatten("", *this, result);
25309  return result;
25310  }
25311 
25342  basic_json unflatten() const
25343  {
25344  return json_pointer::unflatten(*this);
25345  }
25346 
25348 
25350  // JSON Patch functions //
25355 
25403  basic_json patch(const basic_json& json_patch) const
25404  {
25405  // make a working copy to apply the patch to
25406  basic_json result = *this;
25407 
25408  // the valid JSON Patch operations
25409  enum class patch_operations {add, remove, replace, move, copy, test, invalid};
25410 
25411  const auto get_op = [](const std::string & op)
25412  {
25413  if (op == "add")
25414  {
25415  return patch_operations::add;
25416  }
25417  if (op == "remove")
25418  {
25419  return patch_operations::remove;
25420  }
25421  if (op == "replace")
25422  {
25423  return patch_operations::replace;
25424  }
25425  if (op == "move")
25426  {
25427  return patch_operations::move;
25428  }
25429  if (op == "copy")
25430  {
25431  return patch_operations::copy;
25432  }
25433  if (op == "test")
25434  {
25435  return patch_operations::test;
25436  }
25437 
25438  return patch_operations::invalid;
25439  };
25440 
25441  // wrapper for "add" operation; add value at ptr
25442  const auto operation_add = [&result](json_pointer & ptr, basic_json val)
25443  {
25444  // adding to the root of the target document means replacing it
25445  if (ptr.empty())
25446  {
25447  result = val;
25448  return;
25449  }
25450 
25451  // make sure the top element of the pointer exists
25452  json_pointer top_pointer = ptr.top();
25453  if (top_pointer != ptr)
25454  {
25455  result.at(top_pointer);
25456  }
25457 
25458  // get reference to parent of JSON pointer ptr
25459  const auto last_path = ptr.back();
25460  ptr.pop_back();
25461  basic_json& parent = result[ptr];
25462 
25463  switch (parent.m_type)
25464  {
25465  case value_t::null:
25466  case value_t::object:
25467  {
25468  // use operator[] to add value
25469  parent[last_path] = val;
25470  break;
25471  }
25472 
25473  case value_t::array:
25474  {
25475  if (last_path == "-")
25476  {
25477  // special case: append to back
25478  parent.push_back(val);
25479  }
25480  else
25481  {
25482  const auto idx = json_pointer::array_index(last_path);
25483  if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
25484  {
25485  // avoid undefined behavior
25486  JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", parent));
25487  }
25488 
25489  // default case: insert add offset
25490  parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
25491  }
25492  break;
25493  }
25494 
25495  // if there exists a parent it cannot be primitive
25496  default: // LCOV_EXCL_LINE
25497  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
25498  }
25499  };
25500 
25501  // wrapper for "remove" operation; remove value at ptr
25502  const auto operation_remove = [this, &result](json_pointer & ptr)
25503  {
25504  // get reference to parent of JSON pointer ptr
25505  const auto last_path = ptr.back();
25506  ptr.pop_back();
25507  basic_json& parent = result.at(ptr);
25508 
25509  // remove child
25510  if (parent.is_object())
25511  {
25512  // perform range check
25513  auto it = parent.find(last_path);
25514  if (JSON_HEDLEY_LIKELY(it != parent.end()))
25515  {
25516  parent.erase(it);
25517  }
25518  else
25519  {
25520  JSON_THROW(out_of_range::create(403, "key '" + last_path + "' not found", *this));
25521  }
25522  }
25523  else if (parent.is_array())
25524  {
25525  // note erase performs range check
25526  parent.erase(json_pointer::array_index(last_path));
25527  }
25528  };
25529 
25530  // type check: top level value must be an array
25531  if (JSON_HEDLEY_UNLIKELY(!json_patch.is_array()))
25532  {
25533  JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", json_patch));
25534  }
25535 
25536  // iterate and apply the operations
25537  for (const auto& val : json_patch)
25538  {
25539  // wrapper to get a value for an operation
25540  const auto get_value = [&val](const std::string & op,
25541  const std::string & member,
25542  bool string_type) -> basic_json &
25543  {
25544  // find value
25545  auto it = val.m_value.object->find(member);
25546 
25547  // context-sensitive error message
25548  const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
25549 
25550  // check if desired value is present
25551  if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
25552  {
25553  // NOLINTNEXTLINE(performance-inefficient-string-concatenation)
25554  JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'", val));
25555  }
25556 
25557  // check if result is of type string
25558  if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
25559  {
25560  // NOLINTNEXTLINE(performance-inefficient-string-concatenation)
25561  JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'", val));
25562  }
25563 
25564  // no error: return value
25565  return it->second;
25566  };
25567 
25568  // type check: every element of the array must be an object
25569  if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
25570  {
25571  JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", val));
25572  }
25573 
25574  // collect mandatory members
25575  const auto op = get_value("op", "op", true).template get<std::string>();
25576  const auto path = get_value(op, "path", true).template get<std::string>();
25577  json_pointer ptr(path);
25578 
25579  switch (get_op(op))
25580  {
25581  case patch_operations::add:
25582  {
25583  operation_add(ptr, get_value("add", "value", false));
25584  break;
25585  }
25586 
25587  case patch_operations::remove:
25588  {
25589  operation_remove(ptr);
25590  break;
25591  }
25592 
25593  case patch_operations::replace:
25594  {
25595  // the "path" location must exist - use at()
25596  result.at(ptr) = get_value("replace", "value", false);
25597  break;
25598  }
25599 
25600  case patch_operations::move:
25601  {
25602  const auto from_path = get_value("move", "from", true).template get<std::string>();
25603  json_pointer from_ptr(from_path);
25604 
25605  // the "from" location must exist - use at()
25606  basic_json v = result.at(from_ptr);
25607 
25608  // The move operation is functionally identical to a
25609  // "remove" operation on the "from" location, followed
25610  // immediately by an "add" operation at the target
25611  // location with the value that was just removed.
25612  operation_remove(from_ptr);
25613  operation_add(ptr, v);
25614  break;
25615  }
25616 
25617  case patch_operations::copy:
25618  {
25619  const auto from_path = get_value("copy", "from", true).template get<std::string>();
25620  const json_pointer from_ptr(from_path);
25621 
25622  // the "from" location must exist - use at()
25623  basic_json v = result.at(from_ptr);
25624 
25625  // The copy is functionally identical to an "add"
25626  // operation at the target location using the value
25627  // specified in the "from" member.
25628  operation_add(ptr, v);
25629  break;
25630  }
25631 
25632  case patch_operations::test:
25633  {
25634  bool success = false;
25635  JSON_TRY
25636  {
25637  // check if "value" matches the one at "path"
25638  // the "path" location must exist - use at()
25639  success = (result.at(ptr) == get_value("test", "value", false));
25640  }
25641  JSON_INTERNAL_CATCH (out_of_range&)
25642  {
25643  // ignore out of range errors: success remains false
25644  }
25645 
25646  // throw an exception if test fails
25647  if (JSON_HEDLEY_UNLIKELY(!success))
25648  {
25649  JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump(), val));
25650  }
25651 
25652  break;
25653  }
25654 
25655  default:
25656  {
25657  // op must be "add", "remove", "replace", "move", "copy", or
25658  // "test"
25659  JSON_THROW(parse_error::create(105, 0, "operation value '" + op + "' is invalid", val));
25660  }
25661  }
25662  }
25663 
25664  return result;
25665  }
25666 
25700 
25701  static basic_json diff(const basic_json& source, const basic_json& target,
25702  const std::string& path = "")
25703  {
25704  // the patch
25705  basic_json result(value_t::array);
25706 
25707  // if the values are the same, return empty patch
25708  if (source == target)
25709  {
25710  return result;
25711  }
25712 
25713  if (source.type() != target.type())
25714  {
25715  // different types: replace value
25716  result.push_back(
25717  {
25718  {"op", "replace"}, {"path", path}, {"value", target}
25719  });
25720  return result;
25721  }
25722 
25723  switch (source.type())
25724  {
25725  case value_t::array:
25726  {
25727  // first pass: traverse common elements
25728  std::size_t i = 0;
25729  while (i < source.size() && i < target.size())
25730  {
25731  // recursive call to compare array values at index i
25732  auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i));
25733  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
25734  ++i;
25735  }
25736 
25737  // i now reached the end of at least one array
25738  // in a second pass, traverse the remaining elements
25739 
25740  // remove my remaining elements
25741  const auto end_index = static_cast<difference_type>(result.size());
25742  while (i < source.size())
25743  {
25744  // add operations in reverse order to avoid invalid
25745  // indices
25746  result.insert(result.begin() + end_index, object(
25747  {
25748  {"op", "remove"},
25749  {"path", path + "/" + std::to_string(i)}
25750  }));
25751  ++i;
25752  }
25753 
25754  // add other remaining elements
25755  while (i < target.size())
25756  {
25757  result.push_back(
25758  {
25759  {"op", "add"},
25760  {"path", path + "/-"},
25761  {"value", target[i]}
25762  });
25763  ++i;
25764  }
25765 
25766  break;
25767  }
25768 
25769  case value_t::object:
25770  {
25771  // first pass: traverse this object's elements
25772  for (auto it = source.cbegin(); it != source.cend(); ++it)
25773  {
25774  // escape the key name to be used in a JSON patch
25775  const auto path_key = path + "/" + detail::escape(it.key());
25776 
25777  if (target.find(it.key()) != target.end())
25778  {
25779  // recursive call to compare object values at key it
25780  auto temp_diff = diff(it.value(), target[it.key()], path_key);
25781  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
25782  }
25783  else
25784  {
25785  // found a key that is not in o -> remove it
25786  result.push_back(object(
25787  {
25788  {"op", "remove"}, {"path", path_key}
25789  }));
25790  }
25791  }
25792 
25793  // second pass: traverse other object's elements
25794  for (auto it = target.cbegin(); it != target.cend(); ++it)
25795  {
25796  if (source.find(it.key()) == source.end())
25797  {
25798  // found a key that is not in this -> add it
25799  const auto path_key = path + "/" + detail::escape(it.key());
25800  result.push_back(
25801  {
25802  {"op", "add"}, {"path", path_key},
25803  {"value", it.value()}
25804  });
25805  }
25806  }
25807 
25808  break;
25809  }
25810 
25811  default:
25812  {
25813  // both primitive type: replace value
25814  result.push_back(
25815  {
25816  {"op", "replace"}, {"path", path}, {"value", target}
25817  });
25818  break;
25819  }
25820  }
25821 
25822  return result;
25823  }
25824 
25826 
25828  // JSON Merge Patch functions //
25830 
25833 
25876  void merge_patch(const basic_json& apply_patch)
25877  {
25878  if (apply_patch.is_object())
25879  {
25880  if (!is_object())
25881  {
25882  *this = object();
25883  }
25884  for (auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
25885  {
25886  if (it.value().is_null())
25887  {
25888  erase(it.key());
25889  }
25890  else
25891  {
25892  operator[](it.key()).merge_patch(it.value());
25893  }
25894  }
25895  }
25896  else
25897  {
25898  *this = apply_patch;
25899  }
25900  }
25901 
25903 };
25904 
25914 NLOHMANN_BASIC_JSON_TPL_DECLARATION
25915 std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j)
25916 {
25917  return j.dump();
25918 }
25919 } // namespace nlohmann
25920 
25922 // nonmember support //
25924 
25925 // specialization of std::swap, and std::hash
25926 namespace std
25927 {
25928 
25930 template<>
25931 struct hash<nlohmann::json>
25932 {
25938  std::size_t operator()(const nlohmann::json& j) const
25939  {
25940  return nlohmann::detail::hash(j);
25941  }
25942 };
25943 
25947 template<>
25948 struct less<::nlohmann::detail::value_t>
25949 {
25954  bool operator()(nlohmann::detail::value_t lhs,
25955  nlohmann::detail::value_t rhs) const noexcept
25956  {
25957  return nlohmann::detail::operator<(lhs, rhs);
25958  }
25959 };
25960 
25961 // C++20 prohibit function specialization in the std namespace.
25962 #ifndef JSON_HAS_CPP_20
25963 
25969 template<>
25970 inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name)
25971  is_nothrow_move_constructible<nlohmann::json>::value&& // NOLINT(misc-redundant-expression)
25972  is_nothrow_move_assignable<nlohmann::json>::value
25973  )
25974 {
25975  j1.swap(j2);
25976 }
25977 
25978 #endif
25979 
25980 } // namespace std
25981 
25995 JSON_HEDLEY_NON_NULL(1)
25996 inline nlohmann::json operator "" _json(const char* s, std::size_t n)
25997 {
25998  return nlohmann::json::parse(s, s + n);
25999 }
26000 
26014 JSON_HEDLEY_NON_NULL(1)
26015 inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
26016 {
26017  return nlohmann::json::json_pointer(std::string(s, n));
26018 }
26019 
26020 // #include <nlohmann/detail/macro_unscope.hpp>
26021 
26022 
26023 // restore GCC/clang diagnostic settings
26024 #if defined(__clang__)
26025  #pragma GCC diagnostic pop
26026 #endif
26027 
26028 // clean up
26029 #undef JSON_ASSERT
26030 #undef JSON_INTERNAL_CATCH
26031 #undef JSON_CATCH
26032 #undef JSON_THROW
26033 #undef JSON_TRY
26034 #undef JSON_PRIVATE_UNLESS_TESTED
26035 #undef JSON_HAS_CPP_11
26036 #undef JSON_HAS_CPP_14
26037 #undef JSON_HAS_CPP_17
26038 #undef JSON_HAS_CPP_20
26039 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
26040 #undef NLOHMANN_BASIC_JSON_TPL
26041 #undef JSON_EXPLICIT
26042 
26043 // #include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
26044 
26045 
26046 #undef JSON_HEDLEY_ALWAYS_INLINE
26047 #undef JSON_HEDLEY_ARM_VERSION
26048 #undef JSON_HEDLEY_ARM_VERSION_CHECK
26049 #undef JSON_HEDLEY_ARRAY_PARAM
26050 #undef JSON_HEDLEY_ASSUME
26051 #undef JSON_HEDLEY_BEGIN_C_DECLS
26052 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
26053 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
26054 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
26055 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
26056 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
26057 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
26058 #undef JSON_HEDLEY_CLANG_HAS_WARNING
26059 #undef JSON_HEDLEY_COMPCERT_VERSION
26060 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
26061 #undef JSON_HEDLEY_CONCAT
26062 #undef JSON_HEDLEY_CONCAT3
26063 #undef JSON_HEDLEY_CONCAT3_EX
26064 #undef JSON_HEDLEY_CONCAT_EX
26065 #undef JSON_HEDLEY_CONST
26066 #undef JSON_HEDLEY_CONSTEXPR
26067 #undef JSON_HEDLEY_CONST_CAST
26068 #undef JSON_HEDLEY_CPP_CAST
26069 #undef JSON_HEDLEY_CRAY_VERSION
26070 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
26071 #undef JSON_HEDLEY_C_DECL
26072 #undef JSON_HEDLEY_DEPRECATED
26073 #undef JSON_HEDLEY_DEPRECATED_FOR
26074 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
26075 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
26076 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
26077 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
26078 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
26079 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
26080 #undef JSON_HEDLEY_DIAGNOSTIC_POP
26081 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
26082 #undef JSON_HEDLEY_DMC_VERSION
26083 #undef JSON_HEDLEY_DMC_VERSION_CHECK
26084 #undef JSON_HEDLEY_EMPTY_BASES
26085 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
26086 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
26087 #undef JSON_HEDLEY_END_C_DECLS
26088 #undef JSON_HEDLEY_FLAGS
26089 #undef JSON_HEDLEY_FLAGS_CAST
26090 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
26091 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
26092 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
26093 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
26094 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
26095 #undef JSON_HEDLEY_GCC_HAS_FEATURE
26096 #undef JSON_HEDLEY_GCC_HAS_WARNING
26097 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
26098 #undef JSON_HEDLEY_GCC_VERSION
26099 #undef JSON_HEDLEY_GCC_VERSION_CHECK
26100 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
26101 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
26102 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
26103 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
26104 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
26105 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
26106 #undef JSON_HEDLEY_GNUC_HAS_WARNING
26107 #undef JSON_HEDLEY_GNUC_VERSION
26108 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
26109 #undef JSON_HEDLEY_HAS_ATTRIBUTE
26110 #undef JSON_HEDLEY_HAS_BUILTIN
26111 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
26112 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
26113 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
26114 #undef JSON_HEDLEY_HAS_EXTENSION
26115 #undef JSON_HEDLEY_HAS_FEATURE
26116 #undef JSON_HEDLEY_HAS_WARNING
26117 #undef JSON_HEDLEY_IAR_VERSION
26118 #undef JSON_HEDLEY_IAR_VERSION_CHECK
26119 #undef JSON_HEDLEY_IBM_VERSION
26120 #undef JSON_HEDLEY_IBM_VERSION_CHECK
26121 #undef JSON_HEDLEY_IMPORT
26122 #undef JSON_HEDLEY_INLINE
26123 #undef JSON_HEDLEY_INTEL_CL_VERSION
26124 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
26125 #undef JSON_HEDLEY_INTEL_VERSION
26126 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
26127 #undef JSON_HEDLEY_IS_CONSTANT
26128 #undef JSON_HEDLEY_IS_CONSTEXPR_
26129 #undef JSON_HEDLEY_LIKELY
26130 #undef JSON_HEDLEY_MALLOC
26131 #undef JSON_HEDLEY_MCST_LCC_VERSION
26132 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
26133 #undef JSON_HEDLEY_MESSAGE
26134 #undef JSON_HEDLEY_MSVC_VERSION
26135 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
26136 #undef JSON_HEDLEY_NEVER_INLINE
26137 #undef JSON_HEDLEY_NON_NULL
26138 #undef JSON_HEDLEY_NO_ESCAPE
26139 #undef JSON_HEDLEY_NO_RETURN
26140 #undef JSON_HEDLEY_NO_THROW
26141 #undef JSON_HEDLEY_NULL
26142 #undef JSON_HEDLEY_PELLES_VERSION
26143 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
26144 #undef JSON_HEDLEY_PGI_VERSION
26145 #undef JSON_HEDLEY_PGI_VERSION_CHECK
26146 #undef JSON_HEDLEY_PREDICT
26147 #undef JSON_HEDLEY_PRINTF_FORMAT
26148 #undef JSON_HEDLEY_PRIVATE
26149 #undef JSON_HEDLEY_PUBLIC
26150 #undef JSON_HEDLEY_PURE
26151 #undef JSON_HEDLEY_REINTERPRET_CAST
26152 #undef JSON_HEDLEY_REQUIRE
26153 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
26154 #undef JSON_HEDLEY_REQUIRE_MSG
26155 #undef JSON_HEDLEY_RESTRICT
26156 #undef
26157 #undef JSON_HEDLEY_SENTINEL
26158 #undef JSON_HEDLEY_STATIC_ASSERT
26159 #undef JSON_HEDLEY_STATIC_CAST
26160 #undef JSON_HEDLEY_STRINGIFY
26161 #undef JSON_HEDLEY_STRINGIFY_EX
26162 #undef JSON_HEDLEY_SUNPRO_VERSION
26163 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
26164 #undef JSON_HEDLEY_TINYC_VERSION
26165 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
26166 #undef JSON_HEDLEY_TI_ARMCL_VERSION
26167 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
26168 #undef JSON_HEDLEY_TI_CL2000_VERSION
26169 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
26170 #undef JSON_HEDLEY_TI_CL430_VERSION
26171 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
26172 #undef JSON_HEDLEY_TI_CL6X_VERSION
26173 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
26174 #undef JSON_HEDLEY_TI_CL7X_VERSION
26175 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
26176 #undef JSON_HEDLEY_TI_CLPRU_VERSION
26177 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
26178 #undef JSON_HEDLEY_TI_VERSION
26179 #undef JSON_HEDLEY_TI_VERSION_CHECK
26180 #undef JSON_HEDLEY_UNAVAILABLE
26181 #undef JSON_HEDLEY_UNLIKELY
26182 #undef JSON_HEDLEY_UNPREDICTABLE
26183 #undef JSON_HEDLEY_UNREACHABLE
26184 #undef JSON_HEDLEY_UNREACHABLE_RETURN
26185 #undef JSON_HEDLEY_VERSION
26186 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
26187 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
26188 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
26189 #undef JSON_HEDLEY_VERSION_ENCODE
26190 #undef JSON_HEDLEY_WARNING
26191 #undef
26192 #undef _MSG
26193 #undef JSON_HEDLEY_FALL_THROUGH
26194 
26195 
26196 
26197 #endif // INCLUDE_NLOHMANN_JSON_HPP_
static basic_json binary(typename binary_t::container_type &&init, std::uint8_t subtype)
explicitly create a binary array (with subtype)
Definition: json.hpp:18903
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
Definition: json.hpp:18466
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
Definition: json.hpp:21628
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.hpp:21913
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:21011
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition: json.hpp:19712
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:17774
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.hpp:23350
static bool sax_parse(InputType &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)
generate SAX events
Definition: json.hpp:24031
detail::exception exception
general exception of the basic_json class
Definition: json.hpp:17325
ReferenceType get_ref()
get a reference value (implicit)
Definition: json.hpp:20376
static basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
Definition: json.hpp:23876
reference emplace_back(Args &&... args)
add an object to an array
Definition: json.hpp:22638
static basic_json from_cbor(const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
Definition: json.hpp:24739
basic_json(const value_t v)
create an empty value with a given type
Definition: json.hpp:18507
basic_json & operator=(basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
copy assignment
Definition: json.hpp:19344
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition: json.hpp:22297
static basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
Definition: json.hpp:25711
detail::input_format_t input_format_t
Definition: json.hpp:17312
value_type & reference
the type of an element reference
Definition: json.hpp:17353
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.hpp:21942
detail::out_of_range out_of_range
exception indicating access out of the defined range
Definition: json.hpp:17333
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
wrapper to access iterator member functions in range-based for
Definition: json.hpp:22006
iterator begin() noexcept
returns an iterator to the first element
Definition: json.hpp:21698
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition: json.hpp:19086
static std::vector< uint8_t > to_ubjson(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition: json.hpp:24496
basic_json(const JsonRef &ref)
Definition: json.hpp:19189
static basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition: json.hpp:18949
const_iterator cend() const noexcept
returns a const iterator to one past the last element
Definition: json.hpp:21809
reference back()
access the last element
Definition: json.hpp:21181
static bool accept(InputType &&i, const bool ignore_comments=false)
check if the input is valid JSON
Definition: json.hpp:23968
StringType string_t
a type for a string
Definition: json.hpp:17676
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:22226
friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
Definition: json.hpp:23808
static basic_json meta()
returns version information on the library
Definition: json.hpp:17417
void update(const_reference j)
updates a JSON object from another object, overwriting existing keys
Definition: json.hpp:22994
std::size_t size_type
a type to represent container sizes
Definition: json.hpp:17360
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition: json.hpp:17358
static basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
Definition: json.hpp:18846
reference operator+=(basic_json &&val)
add an object to an array
Definition: json.hpp:22472
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition: json.hpp:18641
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition: json.hpp:17368
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition: json.hpp:17366
static basic_json from_cbor(InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
Definition: json.hpp:24707
BooleanType boolean_t
a type for a boolean
Definition: json.hpp:17702
void push_back(initializer_list_t init)
add an object to an object
Definition: json.hpp:22590
const char * type_name() const noexcept
return the type as string
Definition: json.hpp:24154
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
Definition: json.hpp:19442
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition: json.hpp:21248
static basic_json from_bson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
Create a JSON value from an input in BSON format.
Definition: json.hpp:25082
constexpr bool is_structured() const noexcept
return whether type is structured
Definition: json.hpp:19553
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:20508
reference front()
access the first element
Definition: json.hpp:21137
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition: json.hpp:19526
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition: json.hpp:19684
detail::cbor_tag_handler_t cbor_tag_handler_t
how to treat CBOR tags
Definition: json.hpp:17308
detail::parse_error parse_error
exception indicating a parse error
Definition: json.hpp:17327
constexpr bool is_object() const noexcept
return whether value is an object
Definition: json.hpp:19734
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.hpp:19495
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:17913
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition: json.hpp:17375
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.hpp:23625
bool empty() const noexcept
checks whether the container is empty.
Definition: json.hpp:22153
friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
serialize to stream
Definition: json.hpp:23784
basic_json(const basic_json &other)
copy constructor
Definition: json.hpp:19216
~basic_json() noexcept
destructor
Definition: json.hpp:19378
friend struct detail::external_constructor
Definition: json.hpp:17242
basic_json(basic_json &&other) noexcept
move constructor
Definition: json.hpp:19306
detail::invalid_iterator invalid_iterator
exception indicating errors with iterators
Definition: json.hpp:17329
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.hpp:23458
detail::other_error other_error
exception indicating other library errors
Definition: json.hpp:17335
json_value m_value
the value of the current element
Definition: json.hpp:24189
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:23717
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition: json.hpp:21876
ReferenceType get_ref() const
get a reference value (implicit)
Definition: json.hpp:20389
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition: json.hpp:20272
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition: json.hpp:25886
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition: json.hpp:20030
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition: json.hpp:17623
Array get_to(T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v)))
Definition: json.hpp:20340
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.hpp:23671
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition: json.hpp:19597
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition: json.hpp:22088
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:21769
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition: json.hpp:23096
void clear() noexcept
clears the contents
Definition: json.hpp:22368
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition: json.hpp:19800
static std::vector< uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition: json.hpp:24393
static basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition: json.hpp:18993
reference operator[](size_type idx)
access specified array element
Definition: json.hpp:20713
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
Definition: json.hpp:20316
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition: json.hpp:17371
static std::vector< uint8_t > to_bson(const basic_json &j)
Serializes the given JSON object j to BSON and returns a vector containing the corresponding BSON-rep...
Definition: json.hpp:24574
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition: json.hpp:17377
static basic_json from_ubjson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
Definition: json.hpp:24968
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition: json.hpp:17302
binary_t & get_binary()
Definition: json.hpp:20450
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.hpp:23511
static basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array (without subtype)
Definition: json.hpp:18893
constexpr bool is_string() const noexcept
return whether value is a string
Definition: json.hpp:19778
constexpr bool is_array() const noexcept
return whether value is an array
Definition: json.hpp:19756
iterator insert_iterator(const_iterator pos, Args &&... args)
Definition: json.hpp:22720
basic_json flatten() const
return flattened JSON value
Definition: json.hpp:25315
const value_type & const_reference
the type of an element const reference
Definition: json.hpp:17355
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:22445
size_type count(KeyT &&key) const
returns the number of occurrences of a key in a JSON object
Definition: json.hpp:21595
const binary_t & get_binary() const
Definition: json.hpp:20461
constexpr bool is_number() const noexcept
return whether value is a number
Definition: json.hpp:19627
std::less< StringType > object_comparator_t
Definition: json.hpp:17487
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition: json.hpp:22688
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition: json.hpp:19656
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition: json.hpp:17310
detail::value_t value_t
Definition: json.hpp:17300
ValueType & get_to(ValueType &v) const
Definition: json.hpp:20329
static basic_json binary(const typename binary_t::container_type &init, std::uint8_t subtype)
explicitly create a binary array (with subtype)
Definition: json.hpp:18883
iterator find(KeyT &&key)
find an element in a JSON object
Definition: json.hpp:21544
detail::type_error type_error
exception indicating executing a member function with a wrong type
Definition: json.hpp:17331
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition: json.hpp:18531
AllocatorType< basic_json > allocator_type
the allocator type
Definition: json.hpp:17363
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition: json.hpp:17984
JSONSerializer< T, SFINAE > json_serializer
Definition: json.hpp:17304
static std::vector< uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition: json.hpp:24298
static basic_json from_msgpack(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition: json.hpp:24851
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
Definition: json.hpp:25413
basic_json(CompatibleType &&val) noexcept(noexcept(//NOLINT(bugprone-forwarding-reference-overload, bugprone-exception-escape) JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value
Definition: json.hpp:18603
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition: json.hpp:25352
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition: json.hpp:17845
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition: json.hpp:21738
basic_json(initializer_list_t init, bool type_deduction=true, value_t manual_type=value_t::array)
create a container (array or object) from an initializer list
Definition: json.hpp:18765
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:22759
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition: json.hpp:17373
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition: json.hpp:19827
constexpr bool is_null() const noexcept
return whether value is null
Definition: json.hpp:19575
ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > >> object_t
a type for an object
Definition: json.hpp:17577
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)
Definition: json.hpp:20231
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition: json.hpp:19020
static allocator_type get_allocator()
returns the allocator associated with the container
Definition: json.hpp:17385
constexpr auto get_ptr() const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition: json.hpp:20043
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition: json.hpp:21839
a class to store JSON values
Definition: json.hpp:17240
BinaryType container_type
the type of the underlying container
Definition: json.hpp:4964
void set_subtype(std::uint8_t subtype_) noexcept
sets the binary subtype
Definition: json.hpp:5019
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition: json.hpp:4970
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition: json.hpp:4974
bool operator!=(const byte_container_with_subtype &rhs) const
Definition: json.hpp:4996
void clear_subtype() noexcept
clears the binary subtype
Definition: json.hpp:5091
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition: json.hpp:4966
byte_container_with_subtype(const container_type &b, std::uint8_t subtype_) noexcept(noexcept(container_type(b)))
Definition: json.hpp:4978
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition: json.hpp:5067
byte_container_with_subtype(container_type &&b, std::uint8_t subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition: json.hpp:4984
constexpr std::uint8_t subtype() const noexcept
return the binary subtype
Definition: json.hpp:5046
bool operator==(const byte_container_with_subtype &rhs) const
Definition: json.hpp:4990
an internal type for a backed binary type
Definition: json.hpp:4961
const std::string & back() const
return last reference token
Definition: json.hpp:12394
std::string to_string() const
return a string representation of the JSON pointer
Definition: json.hpp:12188
friend bool operator==(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for equality
Definition: json.hpp:13031
void pop_back()
remove last reference token
Definition: json.hpp:12370
bool empty() const noexcept
return whether pointer points to the root document
Definition: json.hpp:12441
friend bool operator!=(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for inequality
Definition: json.hpp:13048
void push_back(const std::string &token)
append an unescaped token at the end of the reference pointer
Definition: json.hpp:12416
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition: json.hpp:12220
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition: json.hpp:12266
json_pointer(const std::string &s="")
create JSON pointer
Definition: json.hpp:12170
friend json_pointer operator/(const json_pointer &lhs, const json_pointer &rhs)
create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer
Definition: json.hpp:12286
friend json_pointer operator/(const json_pointer &ptr, std::string token)
create a new JSON pointer by appending the unescaped token at the end of the JSON pointer
Definition: json.hpp:12307
json_pointer & operator/=(std::string token)
append an unescaped reference token at the end of this JSON pointer
Definition: json.hpp:12244
void push_back(std::string &&token)
append an unescaped token at the end of the reference pointer
Definition: json.hpp:12422
friend json_pointer operator/(const json_pointer &ptr, std::size_t array_idx)
create a new JSON pointer by appending the array-index-token at the end of the JSON pointer
Definition: json.hpp:12327
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition: json.hpp:12345
JSON Pointer.
Definition: json.hpp:12143
constexpr const auto & to_json
Definition: json.hpp:4863
constexpr const auto & from_json
Definition: json.hpp:4267
basic_json<> json
default JSON class
Definition: json.hpp:3392
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:25925
namespace for Niels Lohmann
Definition: json.hpp:89
static auto from_json(BasicJsonType &&j, TargetType &val) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), val))) -> decltype(::nlohmann::from_json(std::forward< BasicJsonType >(j), val), void())
convert a JSON value to any value type
Definition: json.hpp:4890
static auto from_json(BasicJsonType &&j) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), detail::identity_tag< TargetType > {}))) -> decltype(::nlohmann::from_json(std::forward< BasicJsonType >(j), detail::identity_tag< TargetType > {}))
convert a JSON value to any value type
Definition: json.hpp:4910
static auto to_json(BasicJsonType &j, TargetType &&val) noexcept(noexcept(::nlohmann::to_json(j, std::forward< TargetType >(val)))) -> decltype(::nlohmann::to_json(j, std::forward< TargetType >(val)), void())
convert any value type to a JSON value
Definition: json.hpp:4927
default JSONSerializer template argument
Definition: json.hpp:4877
virtual bool start_object(std::size_t elements)=0
the beginning of an object was read
virtual bool string(string_t &val)=0
a string was read
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:5766
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:5770
json_sax & operator=(const json_sax &)=default
virtual bool end_array()=0
the end of an array was read
virtual bool key(string_t &val)=0
an object key was read
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:5767
virtual bool binary(binary_t &val)=0
a binary string was read
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:5768
virtual bool start_array(std::size_t elements)=0
the beginning of an array was read
virtual bool parse_error(std::size_t position, const std::string &last_token, const detail::exception &ex)=0
a parse error occurred
json_sax(json_sax &&) noexcept=default
virtual bool boolean(bool val)=0
a boolean value was read
json_sax(const json_sax &)=default
virtual bool end_object()=0
the end of an object was read
virtual bool number_unsigned(number_unsigned_t val)=0
an unsigned integer number was read
typename BasicJsonType::string_t string_t
Definition: json.hpp:5769
virtual bool number_float(number_float_t val, const string_t &s)=0
an floating-point number was read
virtual bool number_integer(number_integer_t val)=0
an integer number was read
SAX interface.
Definition: json.hpp:5765
std::pair< iterator, bool > insert(const value_type &value)
Definition: json.hpp:17112
ordered_map(std::initializer_list< T > init, const Allocator &alloc=Allocator())
Definition: json.hpp:16986
std::vector< std::pair< const Key, T >, Allocator > Container
Definition: json.hpp:16974
iterator find(const Key &key)
Definition: json.hpp:17083
iterator erase(iterator pos)
Definition: json.hpp:17057
void insert(InputIt first, InputIt last)
Definition: json.hpp:17130
std::pair< iterator, bool > emplace(const key_type &key, T &&t)
Definition: json.hpp:16989
const_iterator find(const Key &key) const
Definition: json.hpp:17095
std::pair< iterator, bool > insert(value_type &&value)
Definition: json.hpp:17107
size_type erase(const Key &key)
Definition: json.hpp:17038
const T & operator[](const Key &key) const
Definition: json.hpp:17007
ordered_map(const Allocator &alloc=Allocator())
Definition: json.hpp:16982
typename std::enable_if< std::is_convertible< typename std::iterator_traits< InputIt >::iterator_category, std::input_iterator_tag >::value >::type require_input_iter
Definition: json.hpp:17127
const T & at(const Key &key) const
Definition: json.hpp:17025
ordered_map(It first, It last, const Allocator &alloc=Allocator())
Definition: json.hpp:16984
T & at(const Key &key)
Definition: json.hpp:17012
T & operator[](const Key &key)
Definition: json.hpp:17002
size_type count(const Key &key) const
Definition: json.hpp:17071