NDDEM
json.hpp
Go to the documentation of this file.
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 #include <iosfwd> // istream, ostream
42 #include <iterator> // random_access_iterator_tag
43 #include <memory> // unique_ptr
44 #include <numeric> // accumulate
45 #include <string> // string, stoi, to_string
46 #include <utility> // declval, forward, move, pair, swap
47 #include <vector> // vector
48 
49 // #include <nlohmann/adl_serializer.hpp>
50 
51 
52 #include <utility>
53 
54 // #include <nlohmann/detail/conversions/from_json.hpp>
55 
56 
57 #include <algorithm> // transform
58 #include <array> // array
59 #include <forward_list> // forward_list
60 #include <iterator> // inserter, front_inserter, end
61 #include <map> // map
62 #include <string> // string
63 #include <tuple> // tuple, make_tuple
64 #include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible
65 #include <unordered_map> // unordered_map
66 #include <utility> // pair, declval
67 #include <valarray> // valarray
68 
69 // #include <nlohmann/detail/exceptions.hpp>
70 
71 
72 #include <exception> // exception
73 #include <stdexcept> // runtime_error
74 #include <string> // to_string
75 #include <vector> // vector
76 
77 // #include <nlohmann/detail/value_t.hpp>
78 
79 
80 #include <array> // array
81 #include <cstddef> // size_t
82 #include <cstdint> // uint8_t
83 #include <string> // string
84 
85 namespace nlohmann
86 {
87 namespace detail
88 {
90 // JSON type enumeration //
92 
117 enum class value_t : std::uint8_t
118 {
119  null,
120  object,
121  array,
122  string,
123  boolean,
126  number_float,
127  binary,
128  discarded
129 };
130 
144 inline bool operator<(const value_t lhs, const value_t rhs) noexcept
145 {
146  static constexpr std::array<std::uint8_t, 9> order = {{
147  0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,
148  1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */,
149  6 /* binary */
150  }
151  };
152 
153  const auto l_index = static_cast<std::size_t>(lhs);
154  const auto r_index = static_cast<std::size_t>(rhs);
155  return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
156 }
157 } // namespace detail
158 } // namespace nlohmann
159 
160 // #include <nlohmann/detail/string_escape.hpp>
161 
162 
163 #include <string>
164 // #include <nlohmann/detail/macro_scope.hpp>
165 
166 
167 #include <utility> // pair
168 // #include <nlohmann/thirdparty/hedley/hedley.hpp>
169 
170 
171 /* Hedley - https://nemequ.github.io/hedley
172  * Created by Evan Nemerson <evan@nemerson.com>
173  *
174  * To the extent possible under law, the author(s) have dedicated all
175  * copyright and related and neighboring rights to this software to
176  * the public domain worldwide. This software is distributed without
177  * any warranty.
178  *
179  * For details, see <http://creativecommons.org/publicdomain/zero/1.0/>.
180  * SPDX-License-Identifier: CC0-1.0
181  */
182 
183 #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
184 #if defined(JSON_HEDLEY_VERSION)
185  #undef JSON_HEDLEY_VERSION
186 #endif
187 #define JSON_HEDLEY_VERSION 15
188 
189 #if defined(JSON_HEDLEY_STRINGIFY_EX)
190  #undef JSON_HEDLEY_STRINGIFY_EX
191 #endif
192 #define JSON_HEDLEY_STRINGIFY_EX(x) #x
193 
194 #if defined(JSON_HEDLEY_STRINGIFY)
195  #undef JSON_HEDLEY_STRINGIFY
196 #endif
197 #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
198 
199 #if defined(JSON_HEDLEY_CONCAT_EX)
200  #undef JSON_HEDLEY_CONCAT_EX
201 #endif
202 #define JSON_HEDLEY_CONCAT_EX(a,b) a##b
203 
204 #if defined(JSON_HEDLEY_CONCAT)
205  #undef JSON_HEDLEY_CONCAT
206 #endif
207 #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
208 
209 #if defined(JSON_HEDLEY_CONCAT3_EX)
210  #undef JSON_HEDLEY_CONCAT3_EX
211 #endif
212 #define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
213 
214 #if defined(JSON_HEDLEY_CONCAT3)
215  #undef JSON_HEDLEY_CONCAT3
216 #endif
217 #define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
218 
219 #if defined(JSON_HEDLEY_VERSION_ENCODE)
220  #undef JSON_HEDLEY_VERSION_ENCODE
221 #endif
222 #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
223 
224 #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
225  #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
226 #endif
227 #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
228 
229 #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
230  #undef JSON_HEDLEY_VERSION_DECODE_MINOR
231 #endif
232 #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
233 
234 #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
235  #undef JSON_HEDLEY_VERSION_DECODE_REVISION
236 #endif
237 #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
238 
239 #if defined(JSON_HEDLEY_GNUC_VERSION)
240  #undef JSON_HEDLEY_GNUC_VERSION
241 #endif
242 #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
243  #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
244 #elif defined(__GNUC__)
245  #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
246 #endif
247 
248 #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
249  #undef JSON_HEDLEY_GNUC_VERSION_CHECK
250 #endif
251 #if defined(JSON_HEDLEY_GNUC_VERSION)
252  #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
253 #else
254  #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
255 #endif
256 
257 #if defined(JSON_HEDLEY_MSVC_VERSION)
258  #undef JSON_HEDLEY_MSVC_VERSION
259 #endif
260 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
261  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
262 #elif defined(_MSC_FULL_VER) && !defined(__ICL)
263  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
264 #elif defined(_MSC_VER) && !defined(__ICL)
265  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
266 #endif
267 
268 #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
269  #undef JSON_HEDLEY_MSVC_VERSION_CHECK
270 #endif
271 #if !defined(JSON_HEDLEY_MSVC_VERSION)
272  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
273 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
274  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
275 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
276  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
277 #else
278  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
279 #endif
280 
281 #if defined(JSON_HEDLEY_INTEL_VERSION)
282  #undef JSON_HEDLEY_INTEL_VERSION
283 #endif
284 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
285  #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
286 #elif defined(__INTEL_COMPILER) && !defined(__ICL)
287  #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
288 #endif
289 
290 #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
291  #undef JSON_HEDLEY_INTEL_VERSION_CHECK
292 #endif
293 #if defined(JSON_HEDLEY_INTEL_VERSION)
294  #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
295 #else
296  #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
297 #endif
298 
299 #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
300  #undef JSON_HEDLEY_INTEL_CL_VERSION
301 #endif
302 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
303  #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
304 #endif
305 
306 #if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
307  #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
308 #endif
309 #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
310  #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
311 #else
312  #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
313 #endif
314 
315 #if defined(JSON_HEDLEY_PGI_VERSION)
316  #undef JSON_HEDLEY_PGI_VERSION
317 #endif
318 #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
319  #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
320 #endif
321 
322 #if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
323  #undef JSON_HEDLEY_PGI_VERSION_CHECK
324 #endif
325 #if defined(JSON_HEDLEY_PGI_VERSION)
326  #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
327 #else
328  #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
329 #endif
330 
331 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
332  #undef JSON_HEDLEY_SUNPRO_VERSION
333 #endif
334 #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
335  #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)
336 #elif defined(__SUNPRO_C)
337  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
338 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
339  #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)
340 #elif defined(__SUNPRO_CC)
341  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
342 #endif
343 
344 #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
345  #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
346 #endif
347 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
348  #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
349 #else
350  #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
351 #endif
352 
353 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
354  #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
355 #endif
356 #if defined(__EMSCRIPTEN__)
357  #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
358 #endif
359 
360 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
361  #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
362 #endif
363 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
364  #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
365 #else
366  #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
367 #endif
368 
369 #if defined(JSON_HEDLEY_ARM_VERSION)
370  #undef JSON_HEDLEY_ARM_VERSION
371 #endif
372 #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
373  #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
374 #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
375  #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
376 #endif
377 
378 #if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
379  #undef JSON_HEDLEY_ARM_VERSION_CHECK
380 #endif
381 #if defined(JSON_HEDLEY_ARM_VERSION)
382  #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
383 #else
384  #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
385 #endif
386 
387 #if defined(JSON_HEDLEY_IBM_VERSION)
388  #undef JSON_HEDLEY_IBM_VERSION
389 #endif
390 #if defined(__ibmxl__)
391  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
392 #elif defined(__xlC__) && defined(__xlC_ver__)
393  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
394 #elif defined(__xlC__)
395  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
396 #endif
397 
398 #if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
399  #undef JSON_HEDLEY_IBM_VERSION_CHECK
400 #endif
401 #if defined(JSON_HEDLEY_IBM_VERSION)
402  #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
403 #else
404  #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
405 #endif
406 
407 #if defined(JSON_HEDLEY_TI_VERSION)
408  #undef JSON_HEDLEY_TI_VERSION
409 #endif
410 #if \
411  defined(__TI_COMPILER_VERSION__) && \
412  ( \
413  defined(__TMS470__) || defined(__TI_ARM__) || \
414  defined(__MSP430__) || \
415  defined(__TMS320C2000__) \
416  )
417 #if (__TI_COMPILER_VERSION__ >= 16000000)
418  #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
419 #endif
420 #endif
421 
422 #if defined(JSON_HEDLEY_TI_VERSION_CHECK)
423  #undef JSON_HEDLEY_TI_VERSION_CHECK
424 #endif
425 #if defined(JSON_HEDLEY_TI_VERSION)
426  #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
427 #else
428  #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
429 #endif
430 
431 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
432  #undef JSON_HEDLEY_TI_CL2000_VERSION
433 #endif
434 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
435  #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
436 #endif
437 
438 #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
439  #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
440 #endif
441 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
442  #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
443 #else
444  #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
445 #endif
446 
447 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
448  #undef JSON_HEDLEY_TI_CL430_VERSION
449 #endif
450 #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
451  #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
452 #endif
453 
454 #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
455  #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
456 #endif
457 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
458  #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
459 #else
460  #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
461 #endif
462 
463 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
464  #undef JSON_HEDLEY_TI_ARMCL_VERSION
465 #endif
466 #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
467  #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
468 #endif
469 
470 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
471  #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
472 #endif
473 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
474  #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
475 #else
476  #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
477 #endif
478 
479 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
480  #undef JSON_HEDLEY_TI_CL6X_VERSION
481 #endif
482 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
483  #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
484 #endif
485 
486 #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
487  #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
488 #endif
489 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
490  #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
491 #else
492  #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
493 #endif
494 
495 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
496  #undef JSON_HEDLEY_TI_CL7X_VERSION
497 #endif
498 #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
499  #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
500 #endif
501 
502 #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
503  #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
504 #endif
505 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
506  #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
507 #else
508  #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
509 #endif
510 
511 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
512  #undef JSON_HEDLEY_TI_CLPRU_VERSION
513 #endif
514 #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
515  #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
516 #endif
517 
518 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
519  #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
520 #endif
521 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
522  #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
523 #else
524  #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
525 #endif
526 
527 #if defined(JSON_HEDLEY_CRAY_VERSION)
528  #undef JSON_HEDLEY_CRAY_VERSION
529 #endif
530 #if defined(_CRAYC)
531  #if defined(_RELEASE_PATCHLEVEL)
532  #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
533  #else
534  #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
535  #endif
536 #endif
537 
538 #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
539  #undef JSON_HEDLEY_CRAY_VERSION_CHECK
540 #endif
541 #if defined(JSON_HEDLEY_CRAY_VERSION)
542  #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
543 #else
544  #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
545 #endif
546 
547 #if defined(JSON_HEDLEY_IAR_VERSION)
548  #undef JSON_HEDLEY_IAR_VERSION
549 #endif
550 #if defined(__IAR_SYSTEMS_ICC__)
551  #if __VER__ > 1000
552  #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
553  #else
554  #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
555  #endif
556 #endif
557 
558 #if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
559  #undef JSON_HEDLEY_IAR_VERSION_CHECK
560 #endif
561 #if defined(JSON_HEDLEY_IAR_VERSION)
562  #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
563 #else
564  #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
565 #endif
566 
567 #if defined(JSON_HEDLEY_TINYC_VERSION)
568  #undef JSON_HEDLEY_TINYC_VERSION
569 #endif
570 #if defined(__TINYC__)
571  #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
572 #endif
573 
574 #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
575  #undef JSON_HEDLEY_TINYC_VERSION_CHECK
576 #endif
577 #if defined(JSON_HEDLEY_TINYC_VERSION)
578  #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
579 #else
580  #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
581 #endif
582 
583 #if defined(JSON_HEDLEY_DMC_VERSION)
584  #undef JSON_HEDLEY_DMC_VERSION
585 #endif
586 #if defined(__DMC__)
587  #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
588 #endif
589 
590 #if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
591  #undef JSON_HEDLEY_DMC_VERSION_CHECK
592 #endif
593 #if defined(JSON_HEDLEY_DMC_VERSION)
594  #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
595 #else
596  #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
597 #endif
598 
599 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
600  #undef JSON_HEDLEY_COMPCERT_VERSION
601 #endif
602 #if defined(__COMPCERT_VERSION__)
603  #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
604 #endif
605 
606 #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
607  #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
608 #endif
609 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
610  #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
611 #else
612  #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
613 #endif
614 
615 #if defined(JSON_HEDLEY_PELLES_VERSION)
616  #undef JSON_HEDLEY_PELLES_VERSION
617 #endif
618 #if defined(__POCC__)
619  #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
620 #endif
621 
622 #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
623  #undef JSON_HEDLEY_PELLES_VERSION_CHECK
624 #endif
625 #if defined(JSON_HEDLEY_PELLES_VERSION)
626  #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
627 #else
628  #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
629 #endif
630 
631 #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
632  #undef JSON_HEDLEY_MCST_LCC_VERSION
633 #endif
634 #if defined(__LCC__) && defined(__LCC_MINOR__)
635  #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
636 #endif
637 
638 #if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
639  #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
640 #endif
641 #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
642  #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
643 #else
644  #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
645 #endif
646 
647 #if defined(JSON_HEDLEY_GCC_VERSION)
648  #undef JSON_HEDLEY_GCC_VERSION
649 #endif
650 #if \
651  defined(JSON_HEDLEY_GNUC_VERSION) && \
652  !defined(__clang__) && \
653  !defined(JSON_HEDLEY_INTEL_VERSION) && \
654  !defined(JSON_HEDLEY_PGI_VERSION) && \
655  !defined(JSON_HEDLEY_ARM_VERSION) && \
656  !defined(JSON_HEDLEY_CRAY_VERSION) && \
657  !defined(JSON_HEDLEY_TI_VERSION) && \
658  !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
659  !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
660  !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
661  !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
662  !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
663  !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
664  !defined(__COMPCERT__) && \
665  !defined(JSON_HEDLEY_MCST_LCC_VERSION)
666  #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
667 #endif
668 
669 #if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
670  #undef JSON_HEDLEY_GCC_VERSION_CHECK
671 #endif
672 #if defined(JSON_HEDLEY_GCC_VERSION)
673  #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
674 #else
675  #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
676 #endif
677 
678 #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
679  #undef JSON_HEDLEY_HAS_ATTRIBUTE
680 #endif
681 #if \
682  defined(__has_attribute) && \
683  ( \
684  (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
685  )
686 # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
687 #else
688 # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
689 #endif
690 
691 #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
692  #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
693 #endif
694 #if defined(__has_attribute)
695  #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
696 #else
697  #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
698 #endif
699 
700 #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
701  #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
702 #endif
703 #if defined(__has_attribute)
704  #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
705 #else
706  #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
707 #endif
708 
709 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
710  #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
711 #endif
712 #if \
713  defined(__has_cpp_attribute) && \
714  defined(__cplusplus) && \
715  (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
716  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
717 #else
718  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
719 #endif
720 
721 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
722  #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
723 #endif
724 #if !defined(__cplusplus) || !defined(__has_cpp_attribute)
725  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
726 #elif \
727  !defined(JSON_HEDLEY_PGI_VERSION) && \
728  !defined(JSON_HEDLEY_IAR_VERSION) && \
729  (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
730  (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
731  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
732 #else
733  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
734 #endif
735 
736 #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
737  #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
738 #endif
739 #if defined(__has_cpp_attribute) && defined(__cplusplus)
740  #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
741 #else
742  #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
743 #endif
744 
745 #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
746  #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
747 #endif
748 #if defined(__has_cpp_attribute) && defined(__cplusplus)
749  #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
750 #else
751  #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
752 #endif
753 
754 #if defined(JSON_HEDLEY_HAS_BUILTIN)
755  #undef JSON_HEDLEY_HAS_BUILTIN
756 #endif
757 #if defined(__has_builtin)
758  #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
759 #else
760  #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
761 #endif
762 
763 #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
764  #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
765 #endif
766 #if defined(__has_builtin)
767  #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
768 #else
769  #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
770 #endif
771 
772 #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
773  #undef JSON_HEDLEY_GCC_HAS_BUILTIN
774 #endif
775 #if defined(__has_builtin)
776  #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
777 #else
778  #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
779 #endif
780 
781 #if defined(JSON_HEDLEY_HAS_FEATURE)
782  #undef JSON_HEDLEY_HAS_FEATURE
783 #endif
784 #if defined(__has_feature)
785  #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
786 #else
787  #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
788 #endif
789 
790 #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
791  #undef JSON_HEDLEY_GNUC_HAS_FEATURE
792 #endif
793 #if defined(__has_feature)
794  #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
795 #else
796  #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
797 #endif
798 
799 #if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
800  #undef JSON_HEDLEY_GCC_HAS_FEATURE
801 #endif
802 #if defined(__has_feature)
803  #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
804 #else
805  #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
806 #endif
807 
808 #if defined(JSON_HEDLEY_HAS_EXTENSION)
809  #undef JSON_HEDLEY_HAS_EXTENSION
810 #endif
811 #if defined(__has_extension)
812  #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
813 #else
814  #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
815 #endif
816 
817 #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
818  #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
819 #endif
820 #if defined(__has_extension)
821  #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
822 #else
823  #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
824 #endif
825 
826 #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
827  #undef JSON_HEDLEY_GCC_HAS_EXTENSION
828 #endif
829 #if defined(__has_extension)
830  #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
831 #else
832  #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
833 #endif
834 
835 #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
836  #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
837 #endif
838 #if defined(__has_declspec_attribute)
839  #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
840 #else
841  #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
842 #endif
843 
844 #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
845  #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
846 #endif
847 #if defined(__has_declspec_attribute)
848  #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
849 #else
850  #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
851 #endif
852 
853 #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
854  #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
855 #endif
856 #if defined(__has_declspec_attribute)
857  #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
858 #else
859  #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
860 #endif
861 
862 #if defined(JSON_HEDLEY_HAS_WARNING)
863  #undef JSON_HEDLEY_HAS_WARNING
864 #endif
865 #if defined(__has_warning)
866  #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
867 #else
868  #define JSON_HEDLEY_HAS_WARNING(warning) (0)
869 #endif
870 
871 #if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
872  #undef JSON_HEDLEY_GNUC_HAS_WARNING
873 #endif
874 #if defined(__has_warning)
875  #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
876 #else
877  #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
878 #endif
879 
880 #if defined(JSON_HEDLEY_GCC_HAS_WARNING)
881  #undef JSON_HEDLEY_GCC_HAS_WARNING
882 #endif
883 #if defined(__has_warning)
884  #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
885 #else
886  #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
887 #endif
888 
889 #if \
890  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
891  defined(__clang__) || \
892  JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
893  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
894  JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
895  JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
896  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
897  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
898  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
899  JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
900  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
901  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
902  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
903  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
904  JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
905  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
906  JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
907  (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
908  #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
909 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
910  #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
911 #else
912  #define JSON_HEDLEY_PRAGMA(value)
913 #endif
914 
915 #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
916  #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
917 #endif
918 #if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
919  #undef JSON_HEDLEY_DIAGNOSTIC_POP
920 #endif
921 #if defined(__clang__)
922  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
923  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
924 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
925  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
926  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
927 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
928  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
929  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
930 #elif \
931  JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
932  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
933  #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
934  #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
935 #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
936  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
937  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
938 #elif \
939  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
940  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
941  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
942  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
943  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
944  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
945  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
946  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
947 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
948  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
949  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
950 #else
951  #define JSON_HEDLEY_DIAGNOSTIC_PUSH
952  #define JSON_HEDLEY_DIAGNOSTIC_POP
953 #endif
954 
955 /* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for
956  HEDLEY INTERNAL USE ONLY. API subject to change without notice. */
957 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
958  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
959 #endif
960 #if defined(__cplusplus)
961 # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
962 # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
963 # if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
964 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
965  JSON_HEDLEY_DIAGNOSTIC_PUSH \
966  _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
967  _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
968  _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
969  xpr \
970  JSON_HEDLEY_DIAGNOSTIC_POP
971 # else
972 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
973  JSON_HEDLEY_DIAGNOSTIC_PUSH \
974  _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
975  _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
976  xpr \
977  JSON_HEDLEY_DIAGNOSTIC_POP
978 # endif
979 # else
980 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
981  JSON_HEDLEY_DIAGNOSTIC_PUSH \
982  _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
983  xpr \
984  JSON_HEDLEY_DIAGNOSTIC_POP
985 # endif
986 # endif
987 #endif
988 #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
989  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
990 #endif
991 
992 #if defined(JSON_HEDLEY_CONST_CAST)
993  #undef JSON_HEDLEY_CONST_CAST
994 #endif
995 #if defined(__cplusplus)
996 # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
997 #elif \
998  JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
999  JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1000  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1001 # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1002  JSON_HEDLEY_DIAGNOSTIC_PUSH \
1003  JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1004  ((T) (expr)); \
1005  JSON_HEDLEY_DIAGNOSTIC_POP \
1006  }))
1007 #else
1008 # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1009 #endif
1010 
1011 #if defined(JSON_HEDLEY_REINTERPRET_CAST)
1012  #undef JSON_HEDLEY_REINTERPRET_CAST
1013 #endif
1014 #if defined(__cplusplus)
1015  #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1016 #else
1017  #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1018 #endif
1019 
1020 #if defined(JSON_HEDLEY_STATIC_CAST)
1021  #undef JSON_HEDLEY_STATIC_CAST
1022 #endif
1023 #if defined(__cplusplus)
1024  #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1025 #else
1026  #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1027 #endif
1028 
1029 #if defined(JSON_HEDLEY_CPP_CAST)
1030  #undef JSON_HEDLEY_CPP_CAST
1031 #endif
1032 #if defined(__cplusplus)
1033 # if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1034 # define JSON_HEDLEY_CPP_CAST(T, expr) \
1035  JSON_HEDLEY_DIAGNOSTIC_PUSH \
1036  _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1037  ((T) (expr)) \
1038  JSON_HEDLEY_DIAGNOSTIC_POP
1039 # elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1040 # define JSON_HEDLEY_CPP_CAST(T, expr) \
1041  JSON_HEDLEY_DIAGNOSTIC_PUSH \
1042  _Pragma("diag_suppress=Pe137") \
1043  JSON_HEDLEY_DIAGNOSTIC_POP
1044 # else
1045 # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1046 # endif
1047 #else
1048 # define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1049 #endif
1050 
1051 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1052  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1053 #endif
1054 #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1055  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1056 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1057  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1058 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1059  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1060 #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1061  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1062 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1063  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1064 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1065  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1066 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1067  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1068 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1069  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1070 #elif \
1071  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1072  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1073  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1074  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1075  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1076  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1077  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1078  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1079  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1080  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1081  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1082  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1083 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1084  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1085 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1086  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1087 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1088  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1089 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1090  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1091 #else
1092  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1093 #endif
1094 
1095 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1096  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1097 #endif
1098 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1099  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1100 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1101  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1102 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1103  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1104 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1105  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1106 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1107  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1108 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1109  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1110 #elif \
1111  JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1112  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1113  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1114  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1115  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1116 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1117  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1118 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1119  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1120 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1121  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1122 #else
1123  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1124 #endif
1125 
1126 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1127  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1128 #endif
1129 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1130  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1131 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1132  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1133 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1134  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1135 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1136  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1137 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1138  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1139 #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1140  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1141 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1142  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1143 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1144  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1145 #elif \
1146  JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1147  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1148  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1149  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1150 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1151  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1152 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1153  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1154 #else
1155  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1156 #endif
1157 
1158 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1159  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1160 #endif
1161 #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1162  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1163 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1164  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1165 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1166  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1167 #else
1168  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1169 #endif
1170 
1171 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1172  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1173 #endif
1174 #if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1175  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1176 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1177  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1178 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1179  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1180 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1181  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1182 #else
1183  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1184 #endif
1185 
1186 #if defined(JSON_HEDLEY_DEPRECATED)
1187  #undef JSON_HEDLEY_DEPRECATED
1188 #endif
1189 #if defined(JSON_HEDLEY_DEPRECATED_FOR)
1190  #undef JSON_HEDLEY_DEPRECATED_FOR
1191 #endif
1192 #if \
1193  JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1194  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1195  #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1196  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1197 #elif \
1198  (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1199  JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1200  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1201  JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1202  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1203  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1204  JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1205  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1206  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1207  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1208  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1209  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1210  #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1211  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1212 #elif defined(__cplusplus) && (__cplusplus >= 201402L)
1213  #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1214  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1215 #elif \
1216  JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1217  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1218  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1219  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1220  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1221  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1222  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1223  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1224  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1225  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1226  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1227  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1228  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1229  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1230  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1231  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1232  #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1233  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1234 #elif \
1235  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1236  JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1237  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1238  #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1239  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1240 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1241  #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1242  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1243 #else
1244  #define JSON_HEDLEY_DEPRECATED(since)
1245  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1246 #endif
1247 
1248 #if defined(JSON_HEDLEY_UNAVAILABLE)
1249  #undef JSON_HEDLEY_UNAVAILABLE
1250 #endif
1251 #if \
1252  JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1253  JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1254  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1255  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1256  #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1257 #else
1258  #define JSON_HEDLEY_UNAVAILABLE(available_since)
1259 #endif
1260 
1261 #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1262  #undef JSON_HEDLEY_WARN_UNUSED_RESULT
1263 #endif
1264 #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1265  #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1266 #endif
1267 #if \
1268  JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1269  JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1270  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1271  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1272  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1273  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1274  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1275  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1276  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1277  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1278  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1279  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1280  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1281  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1282  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1283  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1284  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1285  #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1286  #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1287 #elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1288  #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1289  #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1290 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1291  #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1292  #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1293 #elif defined(_Check_return_) /* SAL */
1294  #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1295  #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1296 #else
1297  #define JSON_HEDLEY_WARN_UNUSED_RESULT
1298  #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1299 #endif
1300 
1301 #if defined(JSON_HEDLEY_SENTINEL)
1302  #undef JSON_HEDLEY_SENTINEL
1303 #endif
1304 #if \
1305  JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1306  JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1307  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1308  JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1309  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1310  #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1311 #else
1312  #define JSON_HEDLEY_SENTINEL(position)
1313 #endif
1314 
1315 #if defined(JSON_HEDLEY_NO_RETURN)
1316  #undef JSON_HEDLEY_NO_RETURN
1317 #endif
1318 #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1319  #define JSON_HEDLEY_NO_RETURN __noreturn
1320 #elif \
1321  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1322  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1323  #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1324 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1325  #define JSON_HEDLEY_NO_RETURN _Noreturn
1326 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1327  #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1328 #elif \
1329  JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1330  JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1331  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1332  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1333  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1334  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1335  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1336  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1337  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1338  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1339  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1340  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1341  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1342  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1343  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1344  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1345  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1346  #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1347 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1348  #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1349 #elif \
1350  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1351  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1352  #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1353 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1354  #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1355 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1356  #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1357 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1358  #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1359 #else
1360  #define JSON_HEDLEY_NO_RETURN
1361 #endif
1362 
1363 #if defined(JSON_HEDLEY_NO_ESCAPE)
1364  #undef JSON_HEDLEY_NO_ESCAPE
1365 #endif
1366 #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1367  #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1368 #else
1369  #define JSON_HEDLEY_NO_ESCAPE
1370 #endif
1371 
1372 #if defined(JSON_HEDLEY_UNREACHABLE)
1373  #undef JSON_HEDLEY_UNREACHABLE
1374 #endif
1375 #if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1376  #undef JSON_HEDLEY_UNREACHABLE_RETURN
1377 #endif
1378 #if defined(JSON_HEDLEY_ASSUME)
1379  #undef JSON_HEDLEY_ASSUME
1380 #endif
1381 #if \
1382  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1383  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1384  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1385  #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1386 #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1387  #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1388 #elif \
1389  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1390  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1391  #if defined(__cplusplus)
1392  #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1393  #else
1394  #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1395  #endif
1396 #endif
1397 #if \
1398  (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1399  JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1400  JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1401  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1402  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1403  JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1404  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1405  #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1406 #elif defined(JSON_HEDLEY_ASSUME)
1407  #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1408 #endif
1409 #if !defined(JSON_HEDLEY_ASSUME)
1410  #if defined(JSON_HEDLEY_UNREACHABLE)
1411  #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1412  #else
1413  #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1414  #endif
1415 #endif
1416 #if defined(JSON_HEDLEY_UNREACHABLE)
1417  #if \
1418  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1419  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1420  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1421  #else
1422  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1423  #endif
1424 #else
1425  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1426 #endif
1427 #if !defined(JSON_HEDLEY_UNREACHABLE)
1428  #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1429 #endif
1430 
1432 #if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1433  #pragma clang diagnostic ignored "-Wpedantic"
1434 #endif
1435 #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1436  #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1437 #endif
1438 #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1439  #if defined(__clang__)
1440  #pragma clang diagnostic ignored "-Wvariadic-macros"
1441  #elif defined(JSON_HEDLEY_GCC_VERSION)
1442  #pragma GCC diagnostic ignored "-Wvariadic-macros"
1443  #endif
1444 #endif
1445 #if defined(JSON_HEDLEY_NON_NULL)
1446  #undef JSON_HEDLEY_NON_NULL
1447 #endif
1448 #if \
1449  JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1450  JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1451  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1452  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1453  #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1454 #else
1455  #define JSON_HEDLEY_NON_NULL(...)
1456 #endif
1458 
1459 #if defined(JSON_HEDLEY_PRINTF_FORMAT)
1460  #undef JSON_HEDLEY_PRINTF_FORMAT
1461 #endif
1462 #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1463  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1464 #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1465  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1466 #elif \
1467  JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1468  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1469  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1470  JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1471  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1472  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1473  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1474  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1475  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1476  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1477  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1478  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1479  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1480  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1481  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1482  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1483  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1484  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1485 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1486  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1487 #else
1488  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1489 #endif
1490 
1491 #if defined(JSON_HEDLEY_CONSTEXPR)
1492  #undef JSON_HEDLEY_CONSTEXPR
1493 #endif
1494 #if defined(__cplusplus)
1495  #if __cplusplus >= 201103L
1496  #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1497  #endif
1498 #endif
1499 #if !defined(JSON_HEDLEY_CONSTEXPR)
1500  #define JSON_HEDLEY_CONSTEXPR
1501 #endif
1502 
1503 #if defined(JSON_HEDLEY_PREDICT)
1504  #undef JSON_HEDLEY_PREDICT
1505 #endif
1506 #if defined(JSON_HEDLEY_LIKELY)
1507  #undef JSON_HEDLEY_LIKELY
1508 #endif
1509 #if defined(JSON_HEDLEY_UNLIKELY)
1510  #undef JSON_HEDLEY_UNLIKELY
1511 #endif
1512 #if defined(JSON_HEDLEY_UNPREDICTABLE)
1513  #undef JSON_HEDLEY_UNPREDICTABLE
1514 #endif
1515 #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1516  #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1517 #endif
1518 #if \
1519  (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1520  JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1521  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1522 # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1523 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1524 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1525 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1526 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1527 #elif \
1528  (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1529  JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1530  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1531  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1532  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1533  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1534  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1535  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1536  JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1537  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1538  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1539  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1540  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1541  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1542  JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1543  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1544 # define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1545  (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1546 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1547  (__extension__ ({ \
1548  double hedley_probability_ = (probability); \
1549  ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1550  }))
1551 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1552  (__extension__ ({ \
1553  double hedley_probability_ = (probability); \
1554  ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1555  }))
1556 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1557 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1558 #else
1559 # define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1560 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1561 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1562 # define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1563 # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1564 #endif
1565 #if !defined(JSON_HEDLEY_UNPREDICTABLE)
1566  #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1567 #endif
1568 
1569 #if defined(JSON_HEDLEY_MALLOC)
1570  #undef JSON_HEDLEY_MALLOC
1571 #endif
1572 #if \
1573  JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1574  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1575  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1576  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1577  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1578  JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1579  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1580  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1581  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1582  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1583  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1584  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1585  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1586  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1587  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1588  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1589  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1590  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1591  #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1592 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1593  #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1594 #elif \
1595  JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1596  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1597  #define JSON_HEDLEY_MALLOC __declspec(restrict)
1598 #else
1599  #define JSON_HEDLEY_MALLOC
1600 #endif
1601 
1602 #if defined(JSON_HEDLEY_PURE)
1603  #undef JSON_HEDLEY_PURE
1604 #endif
1605 #if \
1606  JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1607  JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1608  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1609  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1610  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1611  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1612  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1613  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1614  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1615  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1616  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1617  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1618  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1619  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1620  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1621  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1622  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1623  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1624  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1625 # define JSON_HEDLEY_PURE __attribute__((__pure__))
1626 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1627 # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1628 #elif defined(__cplusplus) && \
1629  ( \
1630  JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1631  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1632  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1633  )
1634 # define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1635 #else
1636 # define JSON_HEDLEY_PURE
1637 #endif
1638 
1639 #if defined(JSON_HEDLEY_CONST)
1640  #undef JSON_HEDLEY_CONST
1641 #endif
1642 #if \
1643  JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1644  JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1645  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1646  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1647  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1648  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1649  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1650  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1651  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1652  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1653  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1654  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1655  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1656  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1657  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1658  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1659  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1660  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1661  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1662  #define JSON_HEDLEY_CONST __attribute__((__const__))
1663 #elif \
1664  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1665  #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1666 #else
1667  #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1668 #endif
1669 
1670 #if defined(JSON_HEDLEY_RESTRICT)
1671  #undef JSON_HEDLEY_RESTRICT
1672 #endif
1673 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1674  #define JSON_HEDLEY_RESTRICT restrict
1675 #elif \
1676  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1677  JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1678  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1679  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1680  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1681  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1682  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1683  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1684  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1685  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1686  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1687  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1688  JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1689  defined(__clang__) || \
1690  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1691  #define JSON_HEDLEY_RESTRICT __restrict
1692 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1693  #define JSON_HEDLEY_RESTRICT _Restrict
1694 #else
1695  #define JSON_HEDLEY_RESTRICT
1696 #endif
1697 
1698 #if defined(JSON_HEDLEY_INLINE)
1699  #undef JSON_HEDLEY_INLINE
1700 #endif
1701 #if \
1702  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1703  (defined(__cplusplus) && (__cplusplus >= 199711L))
1704  #define JSON_HEDLEY_INLINE inline
1705 #elif \
1706  defined(JSON_HEDLEY_GCC_VERSION) || \
1707  JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1708  #define JSON_HEDLEY_INLINE __inline__
1709 #elif \
1710  JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1711  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1712  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1713  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1714  JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1715  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1716  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1717  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1718  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1719  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1720  #define JSON_HEDLEY_INLINE __inline
1721 #else
1722  #define JSON_HEDLEY_INLINE
1723 #endif
1724 
1725 #if defined(JSON_HEDLEY_ALWAYS_INLINE)
1726  #undef JSON_HEDLEY_ALWAYS_INLINE
1727 #endif
1728 #if \
1729  JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1730  JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1731  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1732  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1733  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1734  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1735  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1736  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1737  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1738  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1739  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1740  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1741  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1742  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1743  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1744  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1745  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1746  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1747  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1748 # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1749 #elif \
1750  JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1751  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1752 # define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1753 #elif defined(__cplusplus) && \
1754  ( \
1755  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1756  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1757  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1758  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1759  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1760  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1761  )
1762 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1763 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1764 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1765 #else
1766 # define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1767 #endif
1768 
1769 #if defined(JSON_HEDLEY_NEVER_INLINE)
1770  #undef JSON_HEDLEY_NEVER_INLINE
1771 #endif
1772 #if \
1773  JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1774  JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1775  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1776  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1777  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1778  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1779  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1780  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1781  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1782  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1783  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1784  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1785  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1786  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1787  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1788  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1789  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1790  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1791  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1792  #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1793 #elif \
1794  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1795  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1796  #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1797 #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1798  #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1799 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1800  #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1801 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1802  #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1803 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1804  #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1805 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1806  #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1807 #else
1808  #define JSON_HEDLEY_NEVER_INLINE
1809 #endif
1810 
1811 #if defined(JSON_HEDLEY_PRIVATE)
1812  #undef JSON_HEDLEY_PRIVATE
1813 #endif
1814 #if defined(JSON_HEDLEY_PUBLIC)
1815  #undef JSON_HEDLEY_PUBLIC
1816 #endif
1817 #if defined(JSON_HEDLEY_IMPORT)
1818  #undef JSON_HEDLEY_IMPORT
1819 #endif
1820 #if defined(_WIN32) || defined(__CYGWIN__)
1821 # define JSON_HEDLEY_PRIVATE
1822 # define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1823 # define JSON_HEDLEY_IMPORT __declspec(dllimport)
1824 #else
1825 # if \
1826  JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1827  JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1828  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1829  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1830  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1831  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1832  ( \
1833  defined(__TI_EABI__) && \
1834  ( \
1835  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1836  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1837  ) \
1838  ) || \
1839  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1840 # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1841 # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1842 # else
1843 # define JSON_HEDLEY_PRIVATE
1844 # define JSON_HEDLEY_PUBLIC
1845 # endif
1846 # define JSON_HEDLEY_IMPORT extern
1847 #endif
1848 
1849 #if defined(JSON_HEDLEY_NO_THROW)
1850  #undef JSON_HEDLEY_NO_THROW
1851 #endif
1852 #if \
1853  JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1854  JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1855  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1856  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1857  #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1858 #elif \
1859  JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1860  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1861  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1862  #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1863 #else
1864  #define JSON_HEDLEY_NO_THROW
1865 #endif
1866 
1867 #if defined(JSON_HEDLEY_FALL_THROUGH)
1868  #undef JSON_HEDLEY_FALL_THROUGH
1869 #endif
1870 #if \
1871  JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
1872  JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
1873  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1874  #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1875 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1876  #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1877 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1878  #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1879 #elif defined(__fallthrough) /* SAL */
1880  #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1881 #else
1882  #define JSON_HEDLEY_FALL_THROUGH
1883 #endif
1884 
1885 #if defined(JSON_HEDLEY_RETURNS_NON_NULL)
1886  #undef JSON_HEDLEY_RETURNS_NON_NULL
1887 #endif
1888 #if \
1889  JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1890  JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1891  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1892  #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
1893 #elif defined(_Ret_notnull_) /* SAL */
1894  #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
1895 #else
1896  #define JSON_HEDLEY_RETURNS_NON_NULL
1897 #endif
1898 
1899 #if defined(JSON_HEDLEY_ARRAY_PARAM)
1900  #undef JSON_HEDLEY_ARRAY_PARAM
1901 #endif
1902 #if \
1903  defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1904  !defined(__STDC_NO_VLA__) && \
1905  !defined(__cplusplus) && \
1906  !defined(JSON_HEDLEY_PGI_VERSION) && \
1907  !defined(JSON_HEDLEY_TINYC_VERSION)
1908  #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1909 #else
1910  #define JSON_HEDLEY_ARRAY_PARAM(name)
1911 #endif
1912 
1913 #if defined(JSON_HEDLEY_IS_CONSTANT)
1914  #undef JSON_HEDLEY_IS_CONSTANT
1915 #endif
1916 #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1917  #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1918 #endif
1919 /* JSON_HEDLEY_IS_CONSTEXPR_ is for
1920  HEDLEY INTERNAL USE ONLY. API subject to change without notice. */
1921 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1922  #undef JSON_HEDLEY_IS_CONSTEXPR_
1923 #endif
1924 #if \
1925  JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1926  JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1927  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1928  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1929  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1930  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1931  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1932  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1933  JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1934  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1935  #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1936 #endif
1937 #if !defined(__cplusplus)
1938 # if \
1939  JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1940  JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1941  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1942  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1943  JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1944  JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1945  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1946 #if defined(__INTPTR_TYPE__)
1947  #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1948 #else
1949  #include <stdint.h>
1950  #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1951 #endif
1952 # elif \
1953  ( \
1954  defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
1955  !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
1956  !defined(JSON_HEDLEY_PGI_VERSION) && \
1957  !defined(JSON_HEDLEY_IAR_VERSION)) || \
1958  (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1959  JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1960  JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1961  JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1962  JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1963 #if defined(__INTPTR_TYPE__)
1964  #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1965 #else
1966  #include <stdint.h>
1967  #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1968 #endif
1969 # elif \
1970  defined(JSON_HEDLEY_GCC_VERSION) || \
1971  defined(JSON_HEDLEY_INTEL_VERSION) || \
1972  defined(JSON_HEDLEY_TINYC_VERSION) || \
1973  defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
1974  JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
1975  defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
1976  defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
1977  defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
1978  defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
1979  defined(__clang__)
1980 # define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1981  sizeof(void) != \
1982  sizeof(*( \
1983  1 ? \
1984  ((void*) ((expr) * 0L) ) : \
1985 ((struct { char v[sizeof(void) * 2]; } *) 1) \
1986  ) \
1987  ) \
1988  )
1989 # endif
1990 #endif
1991 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1992  #if !defined(JSON_HEDLEY_IS_CONSTANT)
1993  #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1994  #endif
1995  #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
1996 #else
1997  #if !defined(JSON_HEDLEY_IS_CONSTANT)
1998  #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
1999  #endif
2000  #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2001 #endif
2002 
2003 #if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2004  #undef JSON_HEDLEY_BEGIN_C_DECLS
2005 #endif
2006 #if defined(JSON_HEDLEY_END_C_DECLS)
2007  #undef JSON_HEDLEY_END_C_DECLS
2008 #endif
2009 #if defined(JSON_HEDLEY_C_DECL)
2010  #undef JSON_HEDLEY_C_DECL
2011 #endif
2012 #if defined(__cplusplus)
2013  #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2014  #define JSON_HEDLEY_END_C_DECLS }
2015  #define JSON_HEDLEY_C_DECL extern "C"
2016 #else
2017  #define JSON_HEDLEY_BEGIN_C_DECLS
2018  #define JSON_HEDLEY_END_C_DECLS
2019  #define JSON_HEDLEY_C_DECL
2020 #endif
2021 
2022 #if defined(JSON_HEDLEY_STATIC_ASSERT)
2023  #undef JSON_HEDLEY_STATIC_ASSERT
2024 #endif
2025 #if \
2026  !defined(__cplusplus) && ( \
2027  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2028  (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2029  JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2030  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2031  defined(_Static_assert) \
2032  )
2033 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2034 #elif \
2035  (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2036  JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2037  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2038 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2039 #else
2040 # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2041 #endif
2042 
2043 #if defined(JSON_HEDLEY_NULL)
2044  #undef JSON_HEDLEY_NULL
2045 #endif
2046 #if defined(__cplusplus)
2047  #if __cplusplus >= 201103L
2048  #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2049  #elif defined(NULL)
2050  #define JSON_HEDLEY_NULL NULL
2051  #else
2052  #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2053  #endif
2054 #elif defined(NULL)
2055  #define JSON_HEDLEY_NULL NULL
2056 #else
2057  #define JSON_HEDLEY_NULL ((void*) 0)
2058 #endif
2059 
2060 #if defined(JSON_HEDLEY_MESSAGE)
2061  #undef JSON_HEDLEY_MESSAGE
2062 #endif
2063 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2064 # define JSON_HEDLEY_MESSAGE(msg) \
2065  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2066  JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2067  JSON_HEDLEY_PRAGMA(message msg) \
2068  JSON_HEDLEY_DIAGNOSTIC_POP
2069 #elif \
2070  JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2071  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2072 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2073 #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2074 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2075 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2076 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2077 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2078 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2079 #else
2080 # define JSON_HEDLEY_MESSAGE(msg)
2081 #endif
2082 
2083 #if defined(JSON_HEDLEY_WARNING)
2084  #undef JSON_HEDLEY_WARNING
2085 #endif
2086 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2087 # define JSON_HEDLEY_WARNING(msg) \
2088  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2089  JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2090  JSON_HEDLEY_PRAGMA(clang warning msg) \
2091  JSON_HEDLEY_DIAGNOSTIC_POP
2092 #elif \
2093  JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2094  JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2095  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2096 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2097 #elif \
2098  JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2099  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2100 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2101 #else
2102 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2103 #endif
2104 
2105 #if defined(JSON_HEDLEY_REQUIRE)
2106  #undef JSON_HEDLEY_REQUIRE
2107 #endif
2108 #if defined(JSON_HEDLEY_REQUIRE_MSG)
2109  #undef JSON_HEDLEY_REQUIRE_MSG
2110 #endif
2111 #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2112 # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2113 # define JSON_HEDLEY_REQUIRE(expr) \
2114  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2115  _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2116  __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2117  JSON_HEDLEY_DIAGNOSTIC_POP
2118 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2119  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2120  _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2121  __attribute__((diagnose_if(!(expr), msg, "error"))) \
2122  JSON_HEDLEY_DIAGNOSTIC_POP
2123 # else
2124 # define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2125 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2126 # endif
2127 #else
2128 # define JSON_HEDLEY_REQUIRE(expr)
2129 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2130 #endif
2131 
2132 #if defined(JSON_HEDLEY_FLAGS)
2133  #undef JSON_HEDLEY_FLAGS
2134 #endif
2135 #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2136  #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2137 #else
2138  #define JSON_HEDLEY_FLAGS
2139 #endif
2140 
2141 #if defined(JSON_HEDLEY_FLAGS_CAST)
2142  #undef JSON_HEDLEY_FLAGS_CAST
2143 #endif
2144 #if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2145 # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2146  JSON_HEDLEY_DIAGNOSTIC_PUSH \
2147  _Pragma("warning(disable:188)") \
2148  ((T) (expr)); \
2149  JSON_HEDLEY_DIAGNOSTIC_POP \
2150  }))
2151 #else
2152 # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2153 #endif
2154 
2155 #if defined(JSON_HEDLEY_EMPTY_BASES)
2156  #undef JSON_HEDLEY_EMPTY_BASES
2157 #endif
2158 #if \
2159  (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2160  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2161  #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2162 #else
2163  #define JSON_HEDLEY_EMPTY_BASES
2164 #endif
2165 
2166 /* Remaining macros are deprecated. */
2167 
2168 #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2169  #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2170 #endif
2171 #if defined(__clang__)
2172  #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2173 #else
2174  #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2175 #endif
2176 
2177 #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2178  #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2179 #endif
2180 #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2181 
2182 #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2183  #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2184 #endif
2185 #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2186 
2187 #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2188  #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2189 #endif
2190 #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2191 
2192 #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2193  #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2194 #endif
2195 #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2196 
2197 #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2198  #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2199 #endif
2200 #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2201 
2202 #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2203  #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2204 #endif
2205 #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2206 
2207 #if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2208  #undef JSON_HEDLEY_CLANG_HAS_WARNING
2209 #endif
2210 #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2211 
2212 #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */
2213 
2214 
2215 // This file contains all internal macro definitions
2216 // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
2217 
2218 // exclude unsupported compilers
2219 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2220  #if defined(__clang__)
2221  #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2222  #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2223  #endif
2224  #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2225  #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2226  #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2227  #endif
2228  #endif
2229 #endif
2230 
2231 // C++ language standard detection
2232 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2233  #define JSON_HAS_CPP_20
2234  #define JSON_HAS_CPP_17
2235  #define JSON_HAS_CPP_14
2236 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
2237  #define JSON_HAS_CPP_17
2238  #define JSON_HAS_CPP_14
2239 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2240  #define JSON_HAS_CPP_14
2241 #endif
2242 
2243 // disable documentation warnings on clang
2244 #if defined(__clang__)
2245  #pragma GCC diagnostic push
2246  #pragma GCC diagnostic ignored "-Wdocumentation"
2247 #endif
2248 
2249 // allow to disable exceptions
2250 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2251  #define JSON_THROW(exception) throw exception
2252  #define JSON_TRY try
2253  #define JSON_CATCH(exception) catch(exception)
2254  #define JSON_INTERNAL_CATCH(exception) catch(exception)
2255 #else
2256  #include <cstdlib>
2257  #define JSON_THROW(exception) std::abort()
2258  #define JSON_TRY if(true)
2259  #define JSON_CATCH(exception) if(false)
2260  #define JSON_INTERNAL_CATCH(exception) if(false)
2261 #endif
2262 
2263 // override exception macros
2264 #if defined(JSON_THROW_USER)
2265  #undef JSON_THROW
2266  #define JSON_THROW JSON_THROW_USER
2267 #endif
2268 #if defined(JSON_TRY_USER)
2269  #undef JSON_TRY
2270  #define JSON_TRY JSON_TRY_USER
2271 #endif
2272 #if defined(JSON_CATCH_USER)
2273  #undef JSON_CATCH
2274  #define JSON_CATCH JSON_CATCH_USER
2275  #undef JSON_INTERNAL_CATCH
2276  #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2277 #endif
2278 #if defined(JSON_INTERNAL_CATCH_USER)
2279  #undef JSON_INTERNAL_CATCH
2280  #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2281 #endif
2282 
2283 // allow to override assert
2284 #if !defined(JSON_ASSERT)
2285  #include <cassert> // assert
2286  #define JSON_ASSERT(x) assert(x)
2287 #endif
2288 
2289 // allow to access some private functions (needed by the test suite)
2290 #if defined(JSON_TESTS_PRIVATE)
2291  #define JSON_PRIVATE_UNLESS_TESTED public
2292 #else
2293  #define JSON_PRIVATE_UNLESS_TESTED private
2294 #endif
2295 
2301 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2302  template<typename BasicJsonType> \
2303  inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2304  { \
2305  static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2306  static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2307  auto it = std::find_if(std::begin(m), std::end(m), \
2308  [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2309  { \
2310  return ej_pair.first == e; \
2311  }); \
2312  j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2313  } \
2314  template<typename BasicJsonType> \
2315  inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2316  { \
2317  static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2318  static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2319  auto it = std::find_if(std::begin(m), std::end(m), \
2320  [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2321  { \
2322  return ej_pair.second == j; \
2323  }); \
2324  e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2325  }
2326 
2327 // Ugly macros to avoid uglier copy-paste when specializing basic_json. They
2328 // may be removed in the future once the class is split.
2329 
2330 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2331  template<template<typename, typename, typename...> class ObjectType, \
2332  template<typename, typename...> class ArrayType, \
2333  class StringType, class BooleanType, class NumberIntegerType, \
2334  class NumberUnsignedType, class NumberFloatType, \
2335  template<typename> class AllocatorType, \
2336  template<typename, typename = void> class JSONSerializer, \
2337  class BinaryType>
2338 
2339 #define NLOHMANN_BASIC_JSON_TPL \
2340  basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2341  NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2342  AllocatorType, JSONSerializer, BinaryType>
2343 
2344 // Macros to simplify conversion from/to types
2345 
2346 #define NLOHMANN_JSON_EXPAND( x ) x
2347 #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
2348 #define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2349  NLOHMANN_JSON_PASTE64, \
2350  NLOHMANN_JSON_PASTE63, \
2351  NLOHMANN_JSON_PASTE62, \
2352  NLOHMANN_JSON_PASTE61, \
2353  NLOHMANN_JSON_PASTE60, \
2354  NLOHMANN_JSON_PASTE59, \
2355  NLOHMANN_JSON_PASTE58, \
2356  NLOHMANN_JSON_PASTE57, \
2357  NLOHMANN_JSON_PASTE56, \
2358  NLOHMANN_JSON_PASTE55, \
2359  NLOHMANN_JSON_PASTE54, \
2360  NLOHMANN_JSON_PASTE53, \
2361  NLOHMANN_JSON_PASTE52, \
2362  NLOHMANN_JSON_PASTE51, \
2363  NLOHMANN_JSON_PASTE50, \
2364  NLOHMANN_JSON_PASTE49, \
2365  NLOHMANN_JSON_PASTE48, \
2366  NLOHMANN_JSON_PASTE47, \
2367  NLOHMANN_JSON_PASTE46, \
2368  NLOHMANN_JSON_PASTE45, \
2369  NLOHMANN_JSON_PASTE44, \
2370  NLOHMANN_JSON_PASTE43, \
2371  NLOHMANN_JSON_PASTE42, \
2372  NLOHMANN_JSON_PASTE41, \
2373  NLOHMANN_JSON_PASTE40, \
2374  NLOHMANN_JSON_PASTE39, \
2375  NLOHMANN_JSON_PASTE38, \
2376  NLOHMANN_JSON_PASTE37, \
2377  NLOHMANN_JSON_PASTE36, \
2378  NLOHMANN_JSON_PASTE35, \
2379  NLOHMANN_JSON_PASTE34, \
2380  NLOHMANN_JSON_PASTE33, \
2381  NLOHMANN_JSON_PASTE32, \
2382  NLOHMANN_JSON_PASTE31, \
2383  NLOHMANN_JSON_PASTE30, \
2384  NLOHMANN_JSON_PASTE29, \
2385  NLOHMANN_JSON_PASTE28, \
2386  NLOHMANN_JSON_PASTE27, \
2387  NLOHMANN_JSON_PASTE26, \
2388  NLOHMANN_JSON_PASTE25, \
2389  NLOHMANN_JSON_PASTE24, \
2390  NLOHMANN_JSON_PASTE23, \
2391  NLOHMANN_JSON_PASTE22, \
2392  NLOHMANN_JSON_PASTE21, \
2393  NLOHMANN_JSON_PASTE20, \
2394  NLOHMANN_JSON_PASTE19, \
2395  NLOHMANN_JSON_PASTE18, \
2396  NLOHMANN_JSON_PASTE17, \
2397  NLOHMANN_JSON_PASTE16, \
2398  NLOHMANN_JSON_PASTE15, \
2399  NLOHMANN_JSON_PASTE14, \
2400  NLOHMANN_JSON_PASTE13, \
2401  NLOHMANN_JSON_PASTE12, \
2402  NLOHMANN_JSON_PASTE11, \
2403  NLOHMANN_JSON_PASTE10, \
2404  NLOHMANN_JSON_PASTE9, \
2405  NLOHMANN_JSON_PASTE8, \
2406  NLOHMANN_JSON_PASTE7, \
2407  NLOHMANN_JSON_PASTE6, \
2408  NLOHMANN_JSON_PASTE5, \
2409  NLOHMANN_JSON_PASTE4, \
2410  NLOHMANN_JSON_PASTE3, \
2411  NLOHMANN_JSON_PASTE2, \
2412  NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2413 #define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2414 #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2415 #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2416 #define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2417 #define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2418 #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)
2419 #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)
2420 #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)
2421 #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)
2422 #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)
2423 #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)
2424 #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)
2425 #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)
2426 #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)
2427 #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)
2428 #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)
2429 #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)
2430 #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)
2431 #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)
2432 #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)
2433 #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)
2434 #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)
2435 #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)
2436 #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)
2437 #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)
2438 #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)
2439 #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)
2440 #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)
2441 #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)
2442 #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)
2443 #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)
2444 #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)
2445 #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)
2446 #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)
2447 #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)
2448 #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)
2449 #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)
2450 #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)
2451 #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)
2452 #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)
2453 #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)
2454 #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)
2455 #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)
2456 #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)
2457 #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)
2458 #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)
2459 #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)
2460 #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)
2461 #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)
2462 #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)
2463 #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)
2464 #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)
2465 #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)
2466 #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)
2467 #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)
2468 #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)
2469 #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)
2470 #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)
2471 #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)
2472 #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)
2473 #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)
2474 #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)
2475 #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)
2476 
2477 #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2478 #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2479 
2485 #define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2486  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__)) } \
2487  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__)) }
2488 
2494 #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2495  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__)) } \
2496  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__)) }
2497 
2498 #ifndef JSON_USE_IMPLICIT_CONVERSIONS
2499  #define JSON_USE_IMPLICIT_CONVERSIONS 1
2500 #endif
2501 
2502 #if JSON_USE_IMPLICIT_CONVERSIONS
2503  #define JSON_EXPLICIT
2504 #else
2505  #define JSON_EXPLICIT explicit
2506 #endif
2507 
2508 
2509 namespace nlohmann
2510 {
2511 namespace detail
2512 {
2513 
2527 inline void replace_substring(std::string& s, const std::string& f,
2528  const std::string& t)
2529 {
2530  JSON_ASSERT(!f.empty());
2531  for (auto pos = s.find(f); // find first occurrence of f
2532  pos != std::string::npos; // make sure f was found
2533  s.replace(pos, f.size(), t), // replace with t, and
2534  pos = s.find(f, pos + t.size())) // find next occurrence of f
2535  {}
2536 }
2537 
2545 inline std::string escape(std::string s)
2546 {
2547  replace_substring(s, "~", "~0");
2548  replace_substring(s, "/", "~1");
2549  return s;
2550 }
2551 
2559 static void unescape(std::string& s)
2560 {
2561  replace_substring(s, "~1", "/");
2562  replace_substring(s, "~0", "~");
2563 }
2564 
2565 } // namespace detail
2566 } // namespace nlohmann
2567 
2568 // #include <nlohmann/detail/input/position_t.hpp>
2569 
2570 
2571 #include <cstddef> // size_t
2572 
2573 namespace nlohmann
2574 {
2575 namespace detail
2576 {
2579 {
2581  std::size_t chars_read_total = 0;
2583  std::size_t chars_read_current_line = 0;
2585  std::size_t lines_read = 0;
2586 
2588  constexpr operator size_t() const
2589  {
2590  return chars_read_total;
2591  }
2592 };
2593 
2594 } // namespace detail
2595 } // namespace nlohmann
2596 
2597 // #include <nlohmann/detail/macro_scope.hpp>
2598 
2599 
2600 namespace nlohmann
2601 {
2602 namespace detail
2603 {
2605 // exceptions //
2607 
2636 class exception : public std::exception
2637 {
2638  public:
2640  const char* what() const noexcept override
2641  {
2642  return m.what();
2643  }
2644 
2646  const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
2647 
2648  protected:
2650  exception(int id_, const char* what_arg) : id(id_), m(what_arg) {}
2651 
2652  static std::string name(const std::string& ename, int id_)
2653  {
2654  return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
2655  }
2656 
2657  template<typename BasicJsonType>
2658  static std::string diagnostics(const BasicJsonType& leaf_element)
2659  {
2660 #if JSON_DIAGNOSTICS
2661  std::vector<std::string> tokens;
2662  for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent)
2663  {
2664  switch (current->m_parent->type())
2665  {
2666  case value_t::array:
2667  {
2668  for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
2669  {
2670  if (&current->m_parent->m_value.array->operator[](i) == current)
2671  {
2672  tokens.emplace_back(std::to_string(i));
2673  break;
2674  }
2675  }
2676  break;
2677  }
2678 
2679  case value_t::object:
2680  {
2681  for (const auto& element : *current->m_parent->m_value.object)
2682  {
2683  if (&element.second == current)
2684  {
2685  tokens.emplace_back(element.first.c_str());
2686  break;
2687  }
2688  }
2689  break;
2690  }
2691 
2692  default: // LCOV_EXCL_LINE
2693  break; // LCOV_EXCL_LINE
2694  }
2695  }
2696 
2697  if (tokens.empty())
2698  {
2699  return "";
2700  }
2701 
2702  return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
2703  [](const std::string & a, const std::string & b)
2704  {
2705  return a + "/" + detail::escape(b);
2706  }) + ") ";
2707 #else
2708  static_cast<void>(leaf_element);
2709  return "";
2710 #endif
2711  }
2712 
2713  private:
2715  std::runtime_error m;
2716 };
2717 
2763 class parse_error : public exception
2764 {
2765  public:
2775  template<typename BasicJsonType>
2776  static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context)
2777  {
2778  std::string w = exception::name("parse_error", id_) + "parse error" +
2779  position_string(pos) + ": " + exception::diagnostics(context) + what_arg;
2780  return parse_error(id_, pos.chars_read_total, w.c_str());
2781  }
2782 
2783  template<typename BasicJsonType>
2784  static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context)
2785  {
2786  std::string w = exception::name("parse_error", id_) + "parse error" +
2787  (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
2788  ": " + exception::diagnostics(context) + what_arg;
2789  return parse_error(id_, byte_, w.c_str());
2790  }
2791 
2801  const std::size_t byte;
2802 
2803  private:
2804  parse_error(int id_, std::size_t byte_, const char* what_arg)
2805  : exception(id_, what_arg), byte(byte_) {}
2806 
2807  static std::string position_string(const position_t& pos)
2808  {
2809  return " at line " + std::to_string(pos.lines_read + 1) +
2810  ", column " + std::to_string(pos.chars_read_current_line);
2811  }
2812 };
2813 
2852 {
2853  public:
2854  template<typename BasicJsonType>
2855  static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context)
2856  {
2857  std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
2858  return invalid_iterator(id_, w.c_str());
2859  }
2860 
2861  private:
2863  invalid_iterator(int id_, const char* what_arg)
2864  : exception(id_, what_arg) {}
2865 };
2866 
2906 class type_error : public exception
2907 {
2908  public:
2909  template<typename BasicJsonType>
2910  static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
2911  {
2912  std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg;
2913  return type_error(id_, w.c_str());
2914  }
2915 
2916  private:
2918  type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
2919 };
2920 
2954 class out_of_range : public exception
2955 {
2956  public:
2957  template<typename BasicJsonType>
2958  static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context)
2959  {
2960  std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg;
2961  return out_of_range(id_, w.c_str());
2962  }
2963 
2964  private:
2966  out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}
2967 };
2968 
2993 class other_error : public exception
2994 {
2995  public:
2996  template<typename BasicJsonType>
2997  static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
2998  {
2999  std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg;
3000  return other_error(id_, w.c_str());
3001  }
3002 
3003  private:
3005  other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
3006 };
3007 } // namespace detail
3008 } // namespace nlohmann
3009 
3010 // #include <nlohmann/detail/macro_scope.hpp>
3011 
3012 // #include <nlohmann/detail/meta/cpp_future.hpp>
3013 
3014 
3015 #include <cstddef> // size_t
3016 #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
3017 #include <utility> // index_sequence, make_index_sequence, index_sequence_for
3018 
3019 // #include <nlohmann/detail/macro_scope.hpp>
3020 
3021 
3022 namespace nlohmann
3023 {
3024 namespace detail
3025 {
3026 
3027 template<typename T>
3029 
3030 #ifdef JSON_HAS_CPP_14
3031 
3032 // the following utilities are natively available in C++14
3033 using std::enable_if_t;
3034 using std::index_sequence;
3037 
3038 #else
3039 
3040 // alias templates to reduce boilerplate
3041 template<bool B, typename T = void>
3043 
3044 // The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h
3045 // which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0.
3046 
3048 
3049 // integer_sequence
3050 //
3051 // Class template representing a compile-time integer sequence. An instantiation
3052 // of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its
3053 // type through its template arguments (which is a common need when
3054 // working with C++11 variadic templates). `absl::integer_sequence` is designed
3055 // to be a drop-in replacement for C++14's `std::integer_sequence`.
3056 //
3057 // Example:
3058 //
3059 // template< class T, T... Ints >
3060 // void user_function(integer_sequence<T, Ints...>);
3061 //
3062 // int main()
3063 // {
3064 // // user_function's `T` will be deduced to `int` and `Ints...`
3065 // // will be deduced to `0, 1, 2, 3, 4`.
3066 // user_function(make_integer_sequence<int, 5>());
3067 // }
3068 template <typename T, T... Ints>
3070 {
3071  using value_type = T;
3072  static constexpr std::size_t size() noexcept
3073  {
3074  return sizeof...(Ints);
3075  }
3076 };
3077 
3078 // index_sequence
3079 //
3080 // A helper template for an `integer_sequence` of `size_t`,
3081 // `absl::index_sequence` is designed to be a drop-in replacement for C++14's
3082 // `std::index_sequence`.
3083 template <size_t... Ints>
3084 using index_sequence = integer_sequence<size_t, Ints...>;
3085 
3086 namespace utility_internal
3087 {
3088 
3089 template <typename Seq, size_t SeqSize, size_t Rem>
3090 struct Extend;
3091 
3092 // Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency.
3093 template <typename T, T... Ints, size_t SeqSize>
3094 struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
3095 {
3096  using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
3097 };
3098 
3099 template <typename T, T... Ints, size_t SeqSize>
3100 struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
3101 {
3102  using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
3103 };
3104 
3105 // Recursion helper for 'make_integer_sequence<T, N>'.
3106 // 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'.
3107 template <typename T, size_t N>
3108 struct Gen
3109 {
3110  using type =
3111  typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3112 };
3113 
3114 template <typename T>
3115 struct Gen<T, 0>
3116 {
3118 };
3119 
3120 } // namespace utility_internal
3121 
3122 // Compile-time sequences of integers
3123 
3124 // make_integer_sequence
3125 //
3126 // This template alias is equivalent to
3127 // `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in
3128 // replacement for C++14's `std::make_integer_sequence`.
3129 template <typename T, T N>
3131 
3132 // make_index_sequence
3133 //
3134 // This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,
3135 // and is designed to be a drop-in replacement for C++14's
3136 // `std::make_index_sequence`.
3137 template <size_t N>
3139 
3140 // index_sequence_for
3141 //
3142 // Converts a typename pack into an index sequence of the same length, and
3143 // is designed to be a drop-in replacement for C++14's
3144 // `std::index_sequence_for()`
3145 template <typename... Ts>
3147 
3149 
3150 #endif
3151 
3152 // dispatch utility (taken from ranges-v3)
3153 template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
3154 template<> struct priority_tag<0> {};
3155 
3156 // taken from ranges-v3
3157 template<typename T>
3159 {
3160  static constexpr T value{};
3161 };
3162 
3163 template<typename T>
3164 constexpr T static_const<T>::value;
3165 
3166 } // namespace detail
3167 } // namespace nlohmann
3168 
3169 // #include <nlohmann/detail/meta/type_traits.hpp>
3170 
3171 
3172 #include <limits> // numeric_limits
3173 #include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
3174 #include <utility> // declval
3175 #include <tuple> // tuple
3176 
3177 // #include <nlohmann/detail/iterators/iterator_traits.hpp>
3178 
3179 
3180 #include <iterator> // random_access_iterator_tag
3181 
3182 // #include <nlohmann/detail/meta/void_t.hpp>
3183 
3184 
3185 namespace nlohmann
3186 {
3187 namespace detail
3188 {
3189 template<typename ...Ts> struct make_void
3190 {
3191  using type = void;
3192 };
3193 template<typename ...Ts> using void_t = typename make_void<Ts...>::type;
3194 } // namespace detail
3195 } // namespace nlohmann
3196 
3197 // #include <nlohmann/detail/meta/cpp_future.hpp>
3198 
3199 
3200 namespace nlohmann
3201 {
3202 namespace detail
3203 {
3204 template<typename It, typename = void>
3205 struct iterator_types {};
3206 
3207 template<typename It>
3209  It,
3210  void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3211  typename It::reference, typename It::iterator_category >>
3212 {
3213  using difference_type = typename It::difference_type;
3214  using value_type = typename It::value_type;
3215  using pointer = typename It::pointer;
3216  using reference = typename It::reference;
3217  using iterator_category = typename It::iterator_category;
3218 };
3219 
3220 // This is required as some compilers implement std::iterator_traits in a way that
3221 // doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341.
3222 template<typename T, typename = void>
3224 {
3225 };
3226 
3227 template<typename T>
3228 struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
3229  : iterator_types<T>
3230 {
3231 };
3232 
3233 template<typename T>
3235 {
3236  using iterator_category = std::random_access_iterator_tag;
3237  using value_type = T;
3238  using difference_type = ptrdiff_t;
3239  using pointer = T*;
3240  using reference = T&;
3241 };
3242 } // namespace detail
3243 } // namespace nlohmann
3244 
3245 // #include <nlohmann/detail/macro_scope.hpp>
3246 
3247 // #include <nlohmann/detail/meta/cpp_future.hpp>
3248 
3249 // #include <nlohmann/detail/meta/detected.hpp>
3250 
3251 
3252 #include <type_traits>
3253 
3254 // #include <nlohmann/detail/meta/void_t.hpp>
3255 
3256 
3257 // https://en.cppreference.com/w/cpp/experimental/is_detected
3258 namespace nlohmann
3259 {
3260 namespace detail
3261 {
3262 struct nonesuch
3263 {
3264  nonesuch() = delete;
3265  ~nonesuch() = delete;
3266  nonesuch(nonesuch const&) = delete;
3267  nonesuch(nonesuch const&&) = delete;
3268  void operator=(nonesuch const&) = delete;
3269  void operator=(nonesuch&&) = delete;
3270 };
3271 
3272 template<class Default,
3273  class AlwaysVoid,
3274  template<class...> class Op,
3275  class... Args>
3276 struct detector
3277 {
3278  using value_t = std::false_type;
3279  using type = Default;
3280 };
3281 
3282 template<class Default, template<class...> class Op, class... Args>
3283 struct detector<Default, void_t<Op<Args...>>, Op, Args...>
3284 {
3285  using value_t = std::true_type;
3286  using type = Op<Args...>;
3287 };
3288 
3289 template<template<class...> class Op, class... Args>
3290 using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
3291 
3292 template<template<class...> class Op, class... Args>
3293 using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
3294 
3295 template<class Default, template<class...> class Op, class... Args>
3296 using detected_or = detector<Default, void, Op, Args...>;
3297 
3298 template<class Default, template<class...> class Op, class... Args>
3299 using detected_or_t = typename detected_or<Default, Op, Args...>::type;
3300 
3301 template<class Expected, template<class...> class Op, class... Args>
3302 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
3303 
3304 template<class To, template<class...> class Op, class... Args>
3306  std::is_convertible<detected_t<Op, Args...>, To>;
3307 } // namespace detail
3308 } // namespace nlohmann
3309 
3310 // #include <nlohmann/json_fwd.hpp>
3311 #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3312 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3313 
3314 #include <cstdint> // int64_t, uint64_t
3315 #include <map> // map
3316 #include <memory> // allocator
3317 #include <string> // string
3318 #include <vector> // vector
3319 
3325 namespace nlohmann
3326 {
3334 template<typename T = void, typename SFINAE = void>
3335 struct adl_serializer;
3336 
3337 template<template<typename U, typename V, typename... Args> class ObjectType =
3338  std::map,
3339  template<typename U, typename... Args> class ArrayType = std::vector,
3340  class StringType = std::string, class BooleanType = bool,
3341  class NumberIntegerType = std::int64_t,
3342  class NumberUnsignedType = std::uint64_t,
3343  class NumberFloatType = double,
3344  template<typename U> class AllocatorType = std::allocator,
3345  template<typename T, typename SFINAE = void> class JSONSerializer =
3347  class BinaryType = std::vector<std::uint8_t>>
3348 class basic_json;
3349 
3361 template<typename BasicJsonType>
3362 class json_pointer;
3363 
3373 
3374 template<class Key, class T, class IgnoredLess, class Allocator>
3375 struct ordered_map;
3376 
3385 
3386 } // namespace nlohmann
3387 
3388 #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
3389 
3390 
3391 namespace nlohmann
3392 {
3401 namespace detail
3402 {
3404 // helpers //
3406 
3407 // Note to maintainers:
3408 //
3409 // Every trait in this file expects a non CV-qualified type.
3410 // The only exceptions are in the 'aliases for detected' section
3411 // (i.e. those of the form: decltype(T::member_function(std::declval<T>())))
3412 //
3413 // In this case, T has to be properly CV-qualified to constraint the function arguments
3414 // (e.g. to_json(BasicJsonType&, const T&))
3415 
3416 template<typename> struct is_basic_json : std::false_type {};
3417 
3419 struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
3420 
3422 // json_ref helpers //
3424 
3425 template<typename>
3426 class json_ref;
3427 
3428 template<typename>
3429 struct is_json_ref : std::false_type {};
3430 
3431 template<typename T>
3432 struct is_json_ref<json_ref<T>> : std::true_type {};
3433 
3435 // aliases for detected //
3437 
3438 template<typename T>
3439 using mapped_type_t = typename T::mapped_type;
3440 
3441 template<typename T>
3442 using key_type_t = typename T::key_type;
3443 
3444 template<typename T>
3445 using value_type_t = typename T::value_type;
3446 
3447 template<typename T>
3448 using difference_type_t = typename T::difference_type;
3449 
3450 template<typename T>
3451 using pointer_t = typename T::pointer;
3452 
3453 template<typename T>
3454 using reference_t = typename T::reference;
3455 
3456 template<typename T>
3457 using iterator_category_t = typename T::iterator_category;
3458 
3459 template<typename T>
3460 using iterator_t = typename T::iterator;
3461 
3462 template<typename T, typename... Args>
3463 using to_json_function = decltype(T::to_json(std::declval<Args>()...));
3464 
3465 template<typename T, typename... Args>
3466 using from_json_function = decltype(T::from_json(std::declval<Args>()...));
3467 
3468 template<typename T, typename U>
3469 using get_template_function = decltype(std::declval<T>().template get<U>());
3470 
3471 // trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
3472 template<typename BasicJsonType, typename T, typename = void>
3473 struct has_from_json : std::false_type {};
3474 
3475 // trait checking if j.get<T> is valid
3476 // use this trait instead of std::is_constructible or std::is_convertible,
3477 // both rely on, or make use of implicit conversions, and thus fail when T
3478 // has several constructors/operator= (see https://github.com/nlohmann/json/issues/958)
3479 template <typename BasicJsonType, typename T>
3481 {
3483 };
3484 
3485 template<typename BasicJsonType, typename T>
3486 struct has_from_json < BasicJsonType, T,
3487  enable_if_t < !is_basic_json<T>::value >>
3488 {
3489  using serializer = typename BasicJsonType::template json_serializer<T, void>;
3490 
3491  static constexpr bool value =
3493  const BasicJsonType&, T&>::value;
3494 };
3495 
3496 // This trait checks if JSONSerializer<T>::from_json(json const&) exists
3497 // this overload is used for non-default-constructible user-defined-types
3498 template<typename BasicJsonType, typename T, typename = void>
3499 struct has_non_default_from_json : std::false_type {};
3500 
3501 template<typename BasicJsonType, typename T>
3502 struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3503 {
3504  using serializer = typename BasicJsonType::template json_serializer<T, void>;
3505 
3506  static constexpr bool value =
3508  const BasicJsonType&>::value;
3509 };
3510 
3511 // This trait checks if BasicJsonType::json_serializer<T>::to_json exists
3512 // Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion.
3513 template<typename BasicJsonType, typename T, typename = void>
3514 struct has_to_json : std::false_type {};
3515 
3516 template<typename BasicJsonType, typename T>
3517 struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3518 {
3519  using serializer = typename BasicJsonType::template json_serializer<T, void>;
3520 
3521  static constexpr bool value =
3522  is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3523  T>::value;
3524 };
3525 
3526 
3528 // is_ functions //
3530 
3531 template<typename T, typename = void>
3532 struct is_iterator_traits : std::false_type {};
3533 
3534 template<typename T>
3536 {
3537  private:
3539 
3540  public:
3541  static constexpr auto value =
3547 };
3548 
3549 // The following implementation of is_complete_type is taken from
3550 // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/
3551 // and is written by Xiang Fan who agreed to using it in this library.
3552 
3553 template<typename T, typename = void>
3554 struct is_complete_type : std::false_type {};
3555 
3556 template<typename T>
3557 struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3558 
3559 template<typename BasicJsonType, typename CompatibleObjectType,
3560  typename = void>
3561 struct is_compatible_object_type_impl : std::false_type {};
3562 
3563 template<typename BasicJsonType, typename CompatibleObjectType>
3565  BasicJsonType, CompatibleObjectType,
3566  enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3567  is_detected<key_type_t, CompatibleObjectType>::value >>
3568 {
3569  using object_t = typename BasicJsonType::object_t;
3570 
3571  // macOS's is_constructible does not play well with nonesuch...
3572  static constexpr bool value =
3573  std::is_constructible<typename object_t::key_type,
3574  typename CompatibleObjectType::key_type>::value &&
3575  std::is_constructible<typename object_t::mapped_type,
3576  typename CompatibleObjectType::mapped_type>::value;
3577 };
3578 
3579 template<typename BasicJsonType, typename CompatibleObjectType>
3581  : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
3582 
3583 template<typename BasicJsonType, typename ConstructibleObjectType,
3584  typename = void>
3585 struct is_constructible_object_type_impl : std::false_type {};
3586 
3587 template<typename BasicJsonType, typename ConstructibleObjectType>
3589  BasicJsonType, ConstructibleObjectType,
3590  enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3591  is_detected<key_type_t, ConstructibleObjectType>::value >>
3592 {
3593  using object_t = typename BasicJsonType::object_t;
3594 
3595  static constexpr bool value =
3599  (std::is_constructible<typename ConstructibleObjectType::key_type,
3600  typename object_t::key_type>::value &&
3601  std::is_same <
3602  typename object_t::mapped_type,
3603  typename ConstructibleObjectType::mapped_type >::value)) ||
3604  (has_from_json<BasicJsonType,
3605  typename ConstructibleObjectType::mapped_type>::value ||
3607  BasicJsonType,
3608  typename ConstructibleObjectType::mapped_type >::value);
3609 };
3610 
3611 template<typename BasicJsonType, typename ConstructibleObjectType>
3613  : is_constructible_object_type_impl<BasicJsonType,
3614  ConstructibleObjectType> {};
3615 
3616 template<typename BasicJsonType, typename CompatibleStringType,
3617  typename = void>
3618 struct is_compatible_string_type_impl : std::false_type {};
3619 
3620 template<typename BasicJsonType, typename CompatibleStringType>
3622  BasicJsonType, CompatibleStringType,
3623  enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3624  value_type_t, CompatibleStringType>::value >>
3625 {
3626  static constexpr auto value =
3628 };
3629 
3630 template<typename BasicJsonType, typename ConstructibleStringType>
3632  : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3633 
3634 template<typename BasicJsonType, typename ConstructibleStringType,
3635  typename = void>
3636 struct is_constructible_string_type_impl : std::false_type {};
3637 
3638 template<typename BasicJsonType, typename ConstructibleStringType>
3640  BasicJsonType, ConstructibleStringType,
3641  enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3642  value_type_t, ConstructibleStringType>::value >>
3643 {
3644  static constexpr auto value =
3645  std::is_constructible<ConstructibleStringType,
3646  typename BasicJsonType::string_t>::value;
3647 };
3648 
3649 template<typename BasicJsonType, typename ConstructibleStringType>
3651  : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3652 
3653 template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
3654 struct is_compatible_array_type_impl : std::false_type {};
3655 
3656 template<typename BasicJsonType, typename CompatibleArrayType>
3658  BasicJsonType, CompatibleArrayType,
3659  enable_if_t < is_detected<value_type_t, CompatibleArrayType>::value&&
3660  is_detected<iterator_t, CompatibleArrayType>::value&&
3661 // This is needed because json_reverse_iterator has a ::iterator type...
3662 // Therefore it is detected as a CompatibleArrayType.
3663 // The real fix would be to have an Iterable concept.
3665  iterator_traits<CompatibleArrayType >>::value >>
3666 {
3667  static constexpr bool value =
3668  std::is_constructible<BasicJsonType,
3669  typename CompatibleArrayType::value_type>::value;
3670 };
3671 
3672 template<typename BasicJsonType, typename CompatibleArrayType>
3674  : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
3675 
3676 template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>
3677 struct is_constructible_array_type_impl : std::false_type {};
3678 
3679 template<typename BasicJsonType, typename ConstructibleArrayType>
3681  BasicJsonType, ConstructibleArrayType,
3682  enable_if_t<std::is_same<ConstructibleArrayType,
3683  typename BasicJsonType::value_type>::value >>
3684  : std::true_type {};
3685 
3686 template<typename BasicJsonType, typename ConstructibleArrayType>
3688  BasicJsonType, ConstructibleArrayType,
3689  enable_if_t < !std::is_same<ConstructibleArrayType,
3690  typename BasicJsonType::value_type>::value&&
3691  std::is_default_constructible<ConstructibleArrayType>::value&&
3692 (std::is_move_assignable<ConstructibleArrayType>::value ||
3693  std::is_copy_assignable<ConstructibleArrayType>::value)&&
3694 is_detected<value_type_t, ConstructibleArrayType>::value&&
3695 is_detected<iterator_t, ConstructibleArrayType>::value&&
3697 detected_t<value_type_t, ConstructibleArrayType >>::value >>
3698 {
3699  static constexpr bool value =
3700  // This is needed because json_reverse_iterator has a ::iterator type,
3701  // furthermore, std::back_insert_iterator (and other iterators) have a
3702  // base class `iterator`... Therefore it is detected as a
3703  // ConstructibleArrayType. The real fix would be to have an Iterable
3704  // concept.
3706 
3707  (std::is_same<typename ConstructibleArrayType::value_type,
3708  typename BasicJsonType::array_t::value_type>::value ||
3709  has_from_json<BasicJsonType,
3710  typename ConstructibleArrayType::value_type>::value ||
3712  BasicJsonType, typename ConstructibleArrayType::value_type >::value);
3713 };
3714 
3715 template<typename BasicJsonType, typename ConstructibleArrayType>
3717  : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
3718 
3719 template<typename RealIntegerType, typename CompatibleNumberIntegerType,
3720  typename = void>
3721 struct is_compatible_integer_type_impl : std::false_type {};
3722 
3723 template<typename RealIntegerType, typename CompatibleNumberIntegerType>
3725  RealIntegerType, CompatibleNumberIntegerType,
3726  enable_if_t < std::is_integral<RealIntegerType>::value&&
3727  std::is_integral<CompatibleNumberIntegerType>::value&&
3728  !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3729 {
3730  // is there an assert somewhere on overflows?
3731  using RealLimits = std::numeric_limits<RealIntegerType>;
3732  using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3733 
3734  static constexpr auto value =
3735  std::is_constructible<RealIntegerType,
3736  CompatibleNumberIntegerType>::value &&
3737  CompatibleLimits::is_integer &&
3738  RealLimits::is_signed == CompatibleLimits::is_signed;
3739 };
3740 
3741 template<typename RealIntegerType, typename CompatibleNumberIntegerType>
3743  : is_compatible_integer_type_impl<RealIntegerType,
3744  CompatibleNumberIntegerType> {};
3745 
3746 template<typename BasicJsonType, typename CompatibleType, typename = void>
3747 struct is_compatible_type_impl: std::false_type {};
3748 
3749 template<typename BasicJsonType, typename CompatibleType>
3751  BasicJsonType, CompatibleType,
3752  enable_if_t<is_complete_type<CompatibleType>::value >>
3753 {
3754  static constexpr bool value =
3756 };
3757 
3758 template<typename BasicJsonType, typename CompatibleType>
3760  : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
3761 
3762 // https://en.cppreference.com/w/cpp/types/conjunction
3763 template<class...> struct conjunction : std::true_type { };
3764 template<class B1> struct conjunction<B1> : B1 { };
3765 template<class B1, class... Bn>
3766 struct conjunction<B1, Bn...>
3767 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3768 
3769 template<typename T1, typename T2>
3770 struct is_constructible_tuple : std::false_type {};
3771 
3772 template<typename T1, typename... Args>
3773 struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<std::is_constructible<T1, Args>...> {};
3774 } // namespace detail
3775 } // namespace nlohmann
3776 
3777 // #include <nlohmann/detail/value_t.hpp>
3778 
3779 
3780 namespace nlohmann
3781 {
3782 namespace detail
3783 {
3784 template<typename BasicJsonType>
3785 void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
3786 {
3787  if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3788  {
3789  JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()), j));
3790  }
3791  n = nullptr;
3792 }
3793 
3794 // overloads for basic_json template parameters
3795 template < typename BasicJsonType, typename ArithmeticType,
3798  int > = 0 >
3799 void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
3800 {
3801  switch (static_cast<value_t>(j))
3802  {
3804  {
3805  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3806  break;
3807  }
3809  {
3810  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3811  break;
3812  }
3813  case value_t::number_float:
3814  {
3815  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3816  break;
3817  }
3818 
3819  default:
3820  JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
3821  }
3822 }
3823 
3824 template<typename BasicJsonType>
3825 void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
3826 {
3827  if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
3828  {
3829  JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()), j));
3830  }
3831  b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
3832 }
3833 
3834 template<typename BasicJsonType>
3835 void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
3836 {
3837  if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3838  {
3839  JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
3840  }
3841  s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3842 }
3843 
3844 template <
3845  typename BasicJsonType, typename ConstructibleStringType,
3846  enable_if_t <
3848  !std::is_same<typename BasicJsonType::string_t,
3849  ConstructibleStringType>::value,
3850  int > = 0 >
3851 void from_json(const BasicJsonType& j, ConstructibleStringType& s)
3852 {
3853  if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3854  {
3855  JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
3856  }
3857 
3858  s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3859 }
3860 
3861 template<typename BasicJsonType>
3862 void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val)
3863 {
3864  get_arithmetic_value(j, val);
3865 }
3866 
3867 template<typename BasicJsonType>
3868 void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val)
3869 {
3870  get_arithmetic_value(j, val);
3871 }
3872 
3873 template<typename BasicJsonType>
3874 void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val)
3875 {
3876  get_arithmetic_value(j, val);
3877 }
3878 
3879 template<typename BasicJsonType, typename EnumType,
3881 void from_json(const BasicJsonType& j, EnumType& e)
3882 {
3884  get_arithmetic_value(j, val);
3885  e = static_cast<EnumType>(val);
3886 }
3887 
3888 // forward_list doesn't have an insert method
3889 template<typename BasicJsonType, typename T, typename Allocator,
3891 void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
3892 {
3893  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3894  {
3895  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
3896  }
3897  l.clear();
3898  std::transform(j.rbegin(), j.rend(),
3899  std::front_inserter(l), [](const BasicJsonType & i)
3900  {
3901  return i.template get<T>();
3902  });
3903 }
3904 
3905 // valarray doesn't have an insert method
3906 template<typename BasicJsonType, typename T,
3908 void from_json(const BasicJsonType& j, std::valarray<T>& l)
3909 {
3910  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3911  {
3912  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
3913  }
3914  l.resize(j.size());
3915  std::transform(j.begin(), j.end(), std::begin(l),
3916  [](const BasicJsonType & elem)
3917  {
3918  return elem.template get<T>();
3919  });
3920 }
3921 
3922 template<typename BasicJsonType, typename T, std::size_t N>
3923 auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
3924 -> decltype(j.template get<T>(), void())
3925 {
3926  for (std::size_t i = 0; i < N; ++i)
3927  {
3928  arr[i] = j.at(i).template get<T>();
3929  }
3930 }
3931 
3932 template<typename BasicJsonType>
3933 void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/)
3934 {
3935  arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
3936 }
3937 
3938 template<typename BasicJsonType, typename T, std::size_t N>
3939 auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
3940  priority_tag<2> /*unused*/)
3941 -> decltype(j.template get<T>(), void())
3942 {
3943  for (std::size_t i = 0; i < N; ++i)
3944  {
3945  arr[i] = j.at(i).template get<T>();
3946  }
3947 }
3948 
3949 template<typename BasicJsonType, typename ConstructibleArrayType>
3950 auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/)
3951 -> decltype(
3952  arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
3953  j.template get<typename ConstructibleArrayType::value_type>(),
3954  void())
3955 {
3956  using std::end;
3957 
3958  ConstructibleArrayType ret;
3959  ret.reserve(j.size());
3960  std::transform(j.begin(), j.end(),
3961  std::inserter(ret, end(ret)), [](const BasicJsonType & i)
3962  {
3963  // get<BasicJsonType>() returns *this, this won't call a from_json
3964  // method when value_type is BasicJsonType
3965  return i.template get<typename ConstructibleArrayType::value_type>();
3966  });
3967  arr = std::move(ret);
3968 }
3969 
3970 template<typename BasicJsonType, typename ConstructibleArrayType>
3971 void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
3972  priority_tag<0> /*unused*/)
3973 {
3974  using std::end;
3975 
3976  ConstructibleArrayType ret;
3977  std::transform(
3978  j.begin(), j.end(), std::inserter(ret, end(ret)),
3979  [](const BasicJsonType & i)
3980  {
3981  // get<BasicJsonType>() returns *this, this won't call a from_json
3982  // method when value_type is BasicJsonType
3983  return i.template get<typename ConstructibleArrayType::value_type>();
3984  });
3985  arr = std::move(ret);
3986 }
3987 
3988 template < typename BasicJsonType, typename ConstructibleArrayType,
3989  enable_if_t <
3995  int > = 0 >
3996 auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
3997 -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
3998 j.template get<typename ConstructibleArrayType::value_type>(),
3999 void())
4000 {
4001  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4002  {
4003  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
4004  }
4005 
4006  from_json_array_impl(j, arr, priority_tag<3> {});
4007 }
4008 
4009 template<typename BasicJsonType>
4010 void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
4011 {
4012  if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4013  {
4014  JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()), j));
4015  }
4016 
4017  bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4018 }
4019 
4020 template<typename BasicJsonType, typename ConstructibleObjectType,
4022 void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
4023 {
4024  if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4025  {
4026  JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()), j));
4027  }
4028 
4029  ConstructibleObjectType ret;
4030  const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4031  using value_type = typename ConstructibleObjectType::value_type;
4032  std::transform(
4033  inner_object->begin(), inner_object->end(),
4034  std::inserter(ret, ret.begin()),
4035  [](typename BasicJsonType::object_t::value_type const & p)
4036  {
4037  return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4038  });
4039  obj = std::move(ret);
4040 }
4041 
4042 // overload for arithmetic types, not chosen for basic_json template arguments
4043 // (BooleanType, etc..); note: Is it really necessary to provide explicit
4044 // overloads for boolean_t etc. in case of a custom BooleanType which is not
4045 // an arithmetic type?
4046 template < typename BasicJsonType, typename ArithmeticType,
4047  enable_if_t <
4053  int > = 0 >
4054 void from_json(const BasicJsonType& j, ArithmeticType& val)
4055 {
4056  switch (static_cast<value_t>(j))
4057  {
4059  {
4060  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4061  break;
4062  }
4064  {
4065  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4066  break;
4067  }
4068  case value_t::number_float:
4069  {
4070  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4071  break;
4072  }
4073  case value_t::boolean:
4074  {
4075  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4076  break;
4077  }
4078 
4079  default:
4080  JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
4081  }
4082 }
4083 
4084 template<typename BasicJsonType, typename A1, typename A2>
4085 void from_json(const BasicJsonType& j, std::pair<A1, A2>& p)
4086 {
4087  p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
4088 }
4089 
4090 template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
4091 void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...> /*unused*/)
4092 {
4093  t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...);
4094 }
4095 
4096 template<typename BasicJsonType, typename... Args>
4097 void from_json(const BasicJsonType& j, std::tuple<Args...>& t)
4098 {
4100 }
4101 
4102 template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
4103  typename = enable_if_t < !std::is_constructible <
4104  typename BasicJsonType::string_t, Key >::value >>
4105 void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
4106 {
4107  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4108  {
4109  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
4110  }
4111  m.clear();
4112  for (const auto& p : j)
4113  {
4114  if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4115  {
4116  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
4117  }
4118  m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4119  }
4120 }
4121 
4122 template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,
4123  typename = enable_if_t < !std::is_constructible <
4124  typename BasicJsonType::string_t, Key >::value >>
4125 void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
4126 {
4127  if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4128  {
4129  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
4130  }
4131  m.clear();
4132  for (const auto& p : j)
4133  {
4134  if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4135  {
4136  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
4137  }
4138  m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4139  }
4140 }
4141 
4143 {
4144  template<typename BasicJsonType, typename T>
4145  auto operator()(const BasicJsonType& j, T& val) const
4146  noexcept(noexcept(from_json(j, val)))
4147  -> decltype(from_json(j, val), void())
4148  {
4149  return from_json(j, val);
4150  }
4151 };
4152 } // namespace detail
4153 
4157 namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)
4158 {
4159 constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value; // NOLINT(misc-definitions-in-headers)
4160 } // namespace
4161 } // namespace nlohmann
4162 
4163 // #include <nlohmann/detail/conversions/to_json.hpp>
4164 
4165 
4166 #include <algorithm> // copy
4167 #include <iterator> // begin, end
4168 #include <string> // string
4169 #include <tuple> // tuple, get
4170 #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
4171 #include <utility> // move, forward, declval, pair
4172 #include <valarray> // valarray
4173 #include <vector> // vector
4174 
4175 // #include <nlohmann/detail/iterators/iteration_proxy.hpp>
4176 
4177 
4178 #include <cstddef> // size_t
4179 #include <iterator> // input_iterator_tag
4180 #include <string> // string, to_string
4181 #include <tuple> // tuple_size, get, tuple_element
4182 #include <utility> // move
4183 
4184 // #include <nlohmann/detail/meta/type_traits.hpp>
4185 
4186 // #include <nlohmann/detail/value_t.hpp>
4187 
4188 
4189 namespace nlohmann
4190 {
4191 namespace detail
4192 {
4193 template<typename string_type>
4194 void int_to_string( string_type& target, std::size_t value )
4195 {
4196  // For ADL
4197  using std::to_string;
4198  target = to_string(value);
4199 }
4200 template<typename IteratorType> class iteration_proxy_value
4201 {
4202  public:
4203  using difference_type = std::ptrdiff_t;
4205  using pointer = value_type * ;
4206  using reference = value_type & ;
4207  using iterator_category = std::input_iterator_tag;
4208  using string_type = typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
4209 
4210  private:
4212  IteratorType anchor;
4214  std::size_t array_index = 0;
4216  mutable std::size_t array_index_last = 0;
4221 
4222  public:
4223  explicit iteration_proxy_value(IteratorType it) noexcept
4224  : anchor(std::move(it))
4225  {}
4226 
4229  {
4230  return *this;
4231  }
4232 
4235  {
4236  ++anchor;
4237  ++array_index;
4238 
4239  return *this;
4240  }
4241 
4243  bool operator==(const iteration_proxy_value& o) const
4244  {
4245  return anchor == o.anchor;
4246  }
4247 
4249  bool operator!=(const iteration_proxy_value& o) const
4250  {
4251  return anchor != o.anchor;
4252  }
4253 
4255  const string_type& key() const
4256  {
4257  JSON_ASSERT(anchor.m_object != nullptr);
4258 
4259  switch (anchor.m_object->type())
4260  {
4261  // use integer array index as key
4262  case value_t::array:
4263  {
4265  {
4268  }
4269  return array_index_str;
4270  }
4271 
4272  // use key from the object
4273  case value_t::object:
4274  return anchor.key();
4275 
4276  // use an empty key for all primitive types
4277  default:
4278  return empty_str;
4279  }
4280  }
4281 
4283  typename IteratorType::reference value() const
4284  {
4285  return anchor.value();
4286  }
4287 };
4288 
4290 template<typename IteratorType> class iteration_proxy
4291 {
4292  private:
4294  typename IteratorType::reference container;
4295 
4296  public:
4298  explicit iteration_proxy(typename IteratorType::reference cont) noexcept
4299  : container(cont) {}
4300 
4303  {
4305  }
4306 
4309  {
4311  }
4312 };
4313 // Structured Bindings Support
4314 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
4315 // And see https://github.com/nlohmann/json/pull/1391
4316 template<std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0>
4318 {
4319  return i.key();
4320 }
4321 // Structured Bindings Support
4322 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
4323 // And see https://github.com/nlohmann/json/pull/1391
4324 template<std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0>
4325 auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
4326 {
4327  return i.value();
4328 }
4329 } // namespace detail
4330 } // namespace nlohmann
4331 
4332 // The Addition to the STD Namespace is required to add
4333 // Structured Bindings Support to the iteration_proxy_value class
4334 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
4335 // And see https://github.com/nlohmann/json/pull/1391
4336 namespace std
4337 {
4338 #if defined(__clang__)
4339  // Fix: https://github.com/nlohmann/json/issues/1401
4340  #pragma clang diagnostic push
4341  #pragma clang diagnostic ignored "-Wmismatched-tags"
4342 #endif
4343 template<typename IteratorType>
4344 class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
4345  : public std::integral_constant<std::size_t, 2> {};
4346 
4347 template<std::size_t N, typename IteratorType>
4348 class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
4349 {
4350  public:
4351  using type = decltype(
4352  get<N>(std::declval <
4354 };
4355 #if defined(__clang__)
4356  #pragma clang diagnostic pop
4357 #endif
4358 } // namespace std
4359 
4360 // #include <nlohmann/detail/meta/cpp_future.hpp>
4361 
4362 // #include <nlohmann/detail/meta/type_traits.hpp>
4363 
4364 // #include <nlohmann/detail/value_t.hpp>
4365 
4366 
4367 namespace nlohmann
4368 {
4369 namespace detail
4370 {
4372 // constructors //
4374 
4375 template<value_t> struct external_constructor;
4376 
4377 template<>
4379 {
4380  template<typename BasicJsonType>
4381  static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept
4382  {
4383  j.m_type = value_t::boolean;
4384  j.m_value = b;
4385  j.assert_invariant();
4386  }
4387 };
4388 
4389 template<>
4391 {
4392  template<typename BasicJsonType>
4393  static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s)
4394  {
4395  j.m_type = value_t::string;
4396  j.m_value = s;
4397  j.assert_invariant();
4398  }
4399 
4400  template<typename BasicJsonType>
4401  static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s)
4402  {
4403  j.m_type = value_t::string;
4404  j.m_value = std::move(s);
4405  j.assert_invariant();
4406  }
4407 
4408  template < typename BasicJsonType, typename CompatibleStringType,
4410  int > = 0 >
4411  static void construct(BasicJsonType& j, const CompatibleStringType& str)
4412  {
4413  j.m_type = value_t::string;
4414  j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
4415  j.assert_invariant();
4416  }
4417 };
4418 
4419 template<>
4421 {
4422  template<typename BasicJsonType>
4423  static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
4424  {
4425  j.m_type = value_t::binary;
4426  j.m_value = typename BasicJsonType::binary_t(b);
4427  j.assert_invariant();
4428  }
4429 
4430  template<typename BasicJsonType>
4431  static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
4432  {
4433  j.m_type = value_t::binary;
4434  j.m_value = typename BasicJsonType::binary_t(std::move(b));;
4435  j.assert_invariant();
4436  }
4437 };
4438 
4439 template<>
4440 struct external_constructor<value_t::number_float>
4441 {
4442  template<typename BasicJsonType>
4443  static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept
4444  {
4445  j.m_type = value_t::number_float;
4446  j.m_value = val;
4447  j.assert_invariant();
4448  }
4449 };
4450 
4451 template<>
4452 struct external_constructor<value_t::number_unsigned>
4453 {
4454  template<typename BasicJsonType>
4455  static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept
4456  {
4457  j.m_type = value_t::number_unsigned;
4458  j.m_value = val;
4459  j.assert_invariant();
4460  }
4461 };
4462 
4463 template<>
4464 struct external_constructor<value_t::number_integer>
4465 {
4466  template<typename BasicJsonType>
4467  static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept
4468  {
4469  j.m_type = value_t::number_integer;
4470  j.m_value = val;
4471  j.assert_invariant();
4472  }
4473 };
4474 
4475 template<>
4477 {
4478  template<typename BasicJsonType>
4479  static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr)
4480  {
4481  j.m_type = value_t::array;
4482  j.m_value = arr;
4483  j.set_parents();
4484  j.assert_invariant();
4485  }
4486 
4487  template<typename BasicJsonType>
4488  static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
4489  {
4490  j.m_type = value_t::array;
4491  j.m_value = std::move(arr);
4492  j.set_parents();
4493  j.assert_invariant();
4494  }
4495 
4496  template < typename BasicJsonType, typename CompatibleArrayType,
4498  int > = 0 >
4499  static void construct(BasicJsonType& j, const CompatibleArrayType& arr)
4500  {
4501  using std::begin;
4502  using std::end;
4503  j.m_type = value_t::array;
4504  j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
4505  j.set_parents();
4506  j.assert_invariant();
4507  }
4508 
4509  template<typename BasicJsonType>
4510  static void construct(BasicJsonType& j, const std::vector<bool>& arr)
4511  {
4512  j.m_type = value_t::array;
4513  j.m_value = value_t::array;
4514  j.m_value.array->reserve(arr.size());
4515  for (const bool x : arr)
4516  {
4517  j.m_value.array->push_back(x);
4518  j.set_parent(j.m_value.array->back());
4519  }
4520  j.assert_invariant();
4521  }
4522 
4523  template<typename BasicJsonType, typename T,
4525  static void construct(BasicJsonType& j, const std::valarray<T>& arr)
4526  {
4527  j.m_type = value_t::array;
4528  j.m_value = value_t::array;
4529  j.m_value.array->resize(arr.size());
4530  if (arr.size() > 0)
4531  {
4532  std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
4533  }
4534  j.set_parents();
4535  j.assert_invariant();
4536  }
4537 };
4538 
4539 template<>
4541 {
4542  template<typename BasicJsonType>
4543  static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj)
4544  {
4545  j.m_type = value_t::object;
4546  j.m_value = obj;
4547  j.set_parents();
4548  j.assert_invariant();
4549  }
4550 
4551  template<typename BasicJsonType>
4552  static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
4553  {
4554  j.m_type = value_t::object;
4555  j.m_value = std::move(obj);
4556  j.set_parents();
4557  j.assert_invariant();
4558  }
4559 
4560  template < typename BasicJsonType, typename CompatibleObjectType,
4562  static void construct(BasicJsonType& j, const CompatibleObjectType& obj)
4563  {
4564  using std::begin;
4565  using std::end;
4566 
4567  j.m_type = value_t::object;
4568  j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
4569  j.set_parents();
4570  j.assert_invariant();
4571  }
4572 };
4573 
4575 // to_json //
4577 
4578 template<typename BasicJsonType, typename T,
4580 void to_json(BasicJsonType& j, T b) noexcept
4581 {
4583 }
4584 
4585 template<typename BasicJsonType, typename CompatibleString,
4587 void to_json(BasicJsonType& j, const CompatibleString& s)
4588 {
4590 }
4591 
4592 template<typename BasicJsonType>
4593 void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s)
4594 {
4596 }
4597 
4598 template<typename BasicJsonType, typename FloatType,
4600 void to_json(BasicJsonType& j, FloatType val) noexcept
4601 {
4602  external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val));
4603 }
4604 
4605 template<typename BasicJsonType, typename CompatibleNumberUnsignedType,
4607 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
4608 {
4609  external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val));
4610 }
4611 
4612 template<typename BasicJsonType, typename CompatibleNumberIntegerType,
4614 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
4615 {
4616  external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val));
4617 }
4618 
4619 template<typename BasicJsonType, typename EnumType,
4621 void to_json(BasicJsonType& j, EnumType e) noexcept
4622 {
4623  using underlying_type = typename std::underlying_type<EnumType>::type;
4624  external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));
4625 }
4626 
4627 template<typename BasicJsonType>
4628 void to_json(BasicJsonType& j, const std::vector<bool>& e)
4629 {
4631 }
4632 
4633 template < typename BasicJsonType, typename CompatibleArrayType,
4634  enable_if_t < is_compatible_array_type<BasicJsonType,
4635  CompatibleArrayType>::value&&
4640  int > = 0 >
4641 void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
4642 {
4644 }
4645 
4646 template<typename BasicJsonType>
4647 void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
4648 {
4650 }
4651 
4652 template<typename BasicJsonType, typename T,
4654 void to_json(BasicJsonType& j, const std::valarray<T>& arr)
4655 {
4657 }
4658 
4659 template<typename BasicJsonType>
4660 void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
4661 {
4663 }
4664 
4665 template < typename BasicJsonType, typename CompatibleObjectType,
4667 void to_json(BasicJsonType& j, const CompatibleObjectType& obj)
4668 {
4670 }
4671 
4672 template<typename BasicJsonType>
4673 void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
4674 {
4676 }
4677 
4678 template <
4679  typename BasicJsonType, typename T, std::size_t N,
4680  enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
4681  const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
4682  int > = 0 >
4683 void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
4684 {
4686 }
4687 
4689 void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
4690 {
4691  j = { p.first, p.second };
4692 }
4693 
4694 // for https://github.com/nlohmann/json/pull/1134
4695 template<typename BasicJsonType, typename T,
4696  enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
4697 void to_json(BasicJsonType& j, const T& b)
4698 {
4699  j = { {b.key(), b.value()} };
4700 }
4701 
4702 template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
4703 void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
4704 {
4705  j = { std::get<Idx>(t)... };
4706 }
4707 
4709 void to_json(BasicJsonType& j, const T& t)
4710 {
4712 }
4713 
4715 {
4716  template<typename BasicJsonType, typename T>
4717  auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val))))
4718  -> decltype(to_json(j, std::forward<T>(val)), void())
4719  {
4720  return to_json(j, std::forward<T>(val));
4721  }
4722 };
4723 } // namespace detail
4724 
4728 namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)
4729 {
4730 constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value; // NOLINT(misc-definitions-in-headers)
4731 } // namespace
4732 } // namespace nlohmann
4733 
4734 
4735 namespace nlohmann
4736 {
4737 
4738 template<typename, typename>
4740 {
4750  template<typename BasicJsonType, typename ValueType>
4751  static auto from_json(BasicJsonType&& j, ValueType& val) noexcept(
4752  noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
4753  -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
4754  {
4755  ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
4756  }
4757 
4767  template<typename BasicJsonType, typename ValueType>
4768  static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
4769  noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
4770  -> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)), void())
4771  {
4772  ::nlohmann::to_json(j, std::forward<ValueType>(val));
4773  }
4774 };
4775 
4776 } // namespace nlohmann
4777 
4778 // #include <nlohmann/byte_container_with_subtype.hpp>
4779 
4780 
4781 #include <cstdint> // uint8_t
4782 #include <tuple> // tie
4783 #include <utility> // move
4784 
4785 namespace nlohmann
4786 {
4787 
4801 template<typename BinaryType>
4802 class byte_container_with_subtype : public BinaryType
4803 {
4804  public:
4806  using container_type = BinaryType;
4807 
4809  : container_type()
4810  {}
4811 
4813  : container_type(b)
4814  {}
4815 
4816  byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
4817  : container_type(std::move(b))
4818  {}
4819 
4820  byte_container_with_subtype(const container_type& b, std::uint8_t subtype_) noexcept(noexcept(container_type(b)))
4821  : container_type(b)
4822  , m_subtype(subtype_)
4823  , m_has_subtype(true)
4824  {}
4825 
4826  byte_container_with_subtype(container_type&& b, std::uint8_t subtype_) noexcept(noexcept(container_type(std::move(b))))
4827  : container_type(std::move(b))
4828  , m_subtype(subtype_)
4829  , m_has_subtype(true)
4830  {}
4831 
4833  {
4834  return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==
4835  std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);
4836  }
4837 
4839  {
4840  return !(rhs == *this);
4841  }
4842 
4861  void set_subtype(std::uint8_t subtype_) noexcept
4862  {
4863  m_subtype = subtype_;
4864  m_has_subtype = true;
4865  }
4866 
4888  constexpr std::uint8_t subtype() const noexcept
4889  {
4890  return m_subtype;
4891  }
4892 
4909  constexpr bool has_subtype() const noexcept
4910  {
4911  return m_has_subtype;
4912  }
4913 
4933  void clear_subtype() noexcept
4934  {
4935  m_subtype = 0;
4936  m_has_subtype = false;
4937  }
4938 
4939  private:
4941  bool m_has_subtype = false;
4942 };
4943 
4944 } // namespace nlohmann
4945 
4946 // #include <nlohmann/detail/conversions/from_json.hpp>
4947 
4948 // #include <nlohmann/detail/conversions/to_json.hpp>
4949 
4950 // #include <nlohmann/detail/exceptions.hpp>
4951 
4952 // #include <nlohmann/detail/hash.hpp>
4953 
4954 
4955 #include <cstdint> // uint8_t
4956 #include <cstddef> // size_t
4957 #include <functional> // hash
4958 
4959 // #include <nlohmann/detail/macro_scope.hpp>
4960 
4961 
4962 namespace nlohmann
4963 {
4964 namespace detail
4965 {
4966 
4967 // boost::hash_combine
4968 inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
4969 {
4970  seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
4971  return seed;
4972 }
4973 
4985 template<typename BasicJsonType>
4986 std::size_t hash(const BasicJsonType& j)
4987 {
4988  using string_t = typename BasicJsonType::string_t;
4989  using number_integer_t = typename BasicJsonType::number_integer_t;
4990  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
4991  using number_float_t = typename BasicJsonType::number_float_t;
4992 
4993  const auto type = static_cast<std::size_t>(j.type());
4994  switch (j.type())
4995  {
4996  case BasicJsonType::value_t::null:
4997  case BasicJsonType::value_t::discarded:
4998  {
4999  return combine(type, 0);
5000  }
5001 
5002  case BasicJsonType::value_t::object:
5003  {
5004  auto seed = combine(type, j.size());
5005  for (const auto& element : j.items())
5006  {
5007  const auto h = std::hash<string_t> {}(element.key());
5008  seed = combine(seed, h);
5009  seed = combine(seed, hash(element.value()));
5010  }
5011  return seed;
5012  }
5013 
5014  case BasicJsonType::value_t::array:
5015  {
5016  auto seed = combine(type, j.size());
5017  for (const auto& element : j)
5018  {
5019  seed = combine(seed, hash(element));
5020  }
5021  return seed;
5022  }
5023 
5024  case BasicJsonType::value_t::string:
5025  {
5026  const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
5027  return combine(type, h);
5028  }
5029 
5030  case BasicJsonType::value_t::boolean:
5031  {
5032  const auto h = std::hash<bool> {}(j.template get<bool>());
5033  return combine(type, h);
5034  }
5035 
5036  case BasicJsonType::value_t::number_integer:
5037  {
5038  const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
5039  return combine(type, h);
5040  }
5041 
5042  case BasicJsonType::value_t::number_unsigned:
5043  {
5044  const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
5045  return combine(type, h);
5046  }
5047 
5048  case BasicJsonType::value_t::number_float:
5049  {
5050  const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
5051  return combine(type, h);
5052  }
5053 
5054  case BasicJsonType::value_t::binary:
5055  {
5056  auto seed = combine(type, j.get_binary().size());
5057  const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
5058  seed = combine(seed, h);
5059  seed = combine(seed, j.get_binary().subtype());
5060  for (const auto byte : j.get_binary())
5061  {
5062  seed = combine(seed, std::hash<std::uint8_t> {}(byte));
5063  }
5064  return seed;
5065  }
5066 
5067  default: // LCOV_EXCL_LINE
5068  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
5069  return 0; // LCOV_EXCL_LINE
5070  }
5071 }
5072 
5073 } // namespace detail
5074 } // namespace nlohmann
5075 
5076 // #include <nlohmann/detail/input/binary_reader.hpp>
5077 
5078 
5079 #include <algorithm> // generate_n
5080 #include <array> // array
5081 #include <cmath> // ldexp
5082 #include <cstddef> // size_t
5083 #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
5084 #include <cstdio> // snprintf
5085 #include <cstring> // memcpy
5086 #include <iterator> // back_inserter
5087 #include <limits> // numeric_limits
5088 #include <string> // char_traits, string
5089 #include <utility> // make_pair, move
5090 #include <vector> // vector
5091 
5092 // #include <nlohmann/detail/exceptions.hpp>
5093 
5094 // #include <nlohmann/detail/input/input_adapters.hpp>
5095 
5096 
5097 #include <array> // array
5098 #include <cstddef> // size_t
5099 #include <cstdio> //FILE *
5100 #include <cstring> // strlen
5101 #include <istream> // istream
5102 #include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next
5103 #include <memory> // shared_ptr, make_shared, addressof
5104 #include <numeric> // accumulate
5105 #include <string> // string, char_traits
5106 #include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
5107 #include <utility> // pair, declval
5108 
5109 // #include <nlohmann/detail/iterators/iterator_traits.hpp>
5110 
5111 // #include <nlohmann/detail/macro_scope.hpp>
5112 
5113 
5114 namespace nlohmann
5115 {
5116 namespace detail
5117 {
5120 
5122 // input adapters //
5124 
5130 {
5131  public:
5132  using char_type = char;
5133 
5135  explicit file_input_adapter(std::FILE* f) noexcept
5136  : m_file(f)
5137  {}
5138 
5139  // make class move-only
5143  file_input_adapter& operator=(file_input_adapter&&) = delete;
5144  ~file_input_adapter() = default;
5145 
5146  std::char_traits<char>::int_type get_character() noexcept
5147  {
5148  return std::fgetc(m_file);
5149  }
5150 
5151  private:
5153  std::FILE* m_file;
5154 };
5155 
5156 
5167 {
5168  public:
5169  using char_type = char;
5170 
5172  {
5173  // clear stream flags; we use underlying streambuf I/O, do not
5174  // maintain ifstream flags, except eof
5175  if (is != nullptr)
5176  {
5177  is->clear(is->rdstate() & std::ios::eofbit);
5178  }
5179  }
5180 
5181  explicit input_stream_adapter(std::istream& i)
5182  : is(&i), sb(i.rdbuf())
5183  {}
5184 
5185  // delete because of pointer members
5189 
5191  : is(rhs.is), sb(rhs.sb)
5192  {
5193  rhs.is = nullptr;
5194  rhs.sb = nullptr;
5195  }
5196 
5197  // std::istream/std::streambuf use std::char_traits<char>::to_int_type, to
5198  // ensure that std::char_traits<char>::eof() and the character 0xFF do not
5199  // end up as the same value, eg. 0xFFFFFFFF.
5200  std::char_traits<char>::int_type get_character()
5201  {
5202  auto res = sb->sbumpc();
5203  // set eof manually, as we don't use the istream interface.
5204  if (JSON_HEDLEY_UNLIKELY(res == EOF))
5205  {
5206  is->clear(is->rdstate() | std::ios::eofbit);
5207  }
5208  return res;
5209  }
5210 
5211  private:
5213  std::istream* is = nullptr;
5214  std::streambuf* sb = nullptr;
5215 };
5216 
5217 // General-purpose iterator-based adapter. It might not be as fast as
5218 // theoretically possible for some containers, but it is extremely versatile.
5219 template<typename IteratorType>
5221 {
5222  public:
5223  using char_type = typename std::iterator_traits<IteratorType>::value_type;
5224 
5225  iterator_input_adapter(IteratorType first, IteratorType last)
5226  : current(std::move(first)), end(std::move(last))
5227  {}
5228 
5229  typename std::char_traits<char_type>::int_type get_character()
5230  {
5231  if (JSON_HEDLEY_LIKELY(current != end))
5232  {
5233  auto result = std::char_traits<char_type>::to_int_type(*current);
5234  std::advance(current, 1);
5235  return result;
5236  }
5237 
5238  return std::char_traits<char_type>::eof();
5239  }
5240 
5241  private:
5242  IteratorType current;
5243  IteratorType end;
5244 
5245  template<typename BaseInputAdapter, size_t T>
5247 
5248  bool empty() const
5249  {
5250  return current == end;
5251  }
5252 };
5253 
5254 
5255 template<typename BaseInputAdapter, size_t T>
5257 
5258 template<typename BaseInputAdapter>
5259 struct wide_string_input_helper<BaseInputAdapter, 4>
5260 {
5261  // UTF-32
5262  static void fill_buffer(BaseInputAdapter& input,
5263  std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5264  size_t& utf8_bytes_index,
5265  size_t& utf8_bytes_filled)
5266  {
5267  utf8_bytes_index = 0;
5268 
5269  if (JSON_HEDLEY_UNLIKELY(input.empty()))
5270  {
5271  utf8_bytes[0] = std::char_traits<char>::eof();
5272  utf8_bytes_filled = 1;
5273  }
5274  else
5275  {
5276  // get the current character
5277  const auto wc = input.get_character();
5278 
5279  // UTF-32 to UTF-8 encoding
5280  if (wc < 0x80)
5281  {
5282  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
5283  utf8_bytes_filled = 1;
5284  }
5285  else if (wc <= 0x7FF)
5286  {
5287  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
5288  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5289  utf8_bytes_filled = 2;
5290  }
5291  else if (wc <= 0xFFFF)
5292  {
5293  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
5294  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5295  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5296  utf8_bytes_filled = 3;
5297  }
5298  else if (wc <= 0x10FFFF)
5299  {
5300  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | ((static_cast<unsigned int>(wc) >> 18u) & 0x07u));
5301  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
5302  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5303  utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5304  utf8_bytes_filled = 4;
5305  }
5306  else
5307  {
5308  // unknown character
5309  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
5310  utf8_bytes_filled = 1;
5311  }
5312  }
5313  }
5314 };
5315 
5316 template<typename BaseInputAdapter>
5317 struct wide_string_input_helper<BaseInputAdapter, 2>
5318 {
5319  // UTF-16
5320  static void fill_buffer(BaseInputAdapter& input,
5321  std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5322  size_t& utf8_bytes_index,
5323  size_t& utf8_bytes_filled)
5324  {
5325  utf8_bytes_index = 0;
5326 
5327  if (JSON_HEDLEY_UNLIKELY(input.empty()))
5328  {
5329  utf8_bytes[0] = std::char_traits<char>::eof();
5330  utf8_bytes_filled = 1;
5331  }
5332  else
5333  {
5334  // get the current character
5335  const auto wc = input.get_character();
5336 
5337  // UTF-16 to UTF-8 encoding
5338  if (wc < 0x80)
5339  {
5340  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
5341  utf8_bytes_filled = 1;
5342  }
5343  else if (wc <= 0x7FF)
5344  {
5345  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u)));
5346  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5347  utf8_bytes_filled = 2;
5348  }
5349  else if (0xD800 > wc || wc >= 0xE000)
5350  {
5351  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u)));
5352  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5353  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
5354  utf8_bytes_filled = 3;
5355  }
5356  else
5357  {
5358  if (JSON_HEDLEY_UNLIKELY(!input.empty()))
5359  {
5360  const auto wc2 = static_cast<unsigned int>(input.get_character());
5361  const auto charcode = 0x10000u + (((static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
5362  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | (charcode >> 18u));
5363  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 12u) & 0x3Fu));
5364  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 6u) & 0x3Fu));
5365  utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (charcode & 0x3Fu));
5366  utf8_bytes_filled = 4;
5367  }
5368  else
5369  {
5370  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
5371  utf8_bytes_filled = 1;
5372  }
5373  }
5374  }
5375  }
5376 };
5377 
5378 // Wraps another input apdater to convert wide character types into individual bytes.
5379 template<typename BaseInputAdapter, typename WideCharType>
5381 {
5382  public:
5383  using char_type = char;
5384 
5385  wide_string_input_adapter(BaseInputAdapter base)
5386  : base_adapter(base) {}
5387 
5388  typename std::char_traits<char>::int_type get_character() noexcept
5389  {
5390  // check if buffer needs to be filled
5392  {
5393  fill_buffer<sizeof(WideCharType)>();
5394 
5397  }
5398 
5399  // use buffer
5402  return utf8_bytes[utf8_bytes_index++];
5403  }
5404 
5405  private:
5406  BaseInputAdapter base_adapter;
5407 
5408  template<size_t T>
5410  {
5412  }
5413 
5415  std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
5416 
5418  std::size_t utf8_bytes_index = 0;
5420  std::size_t utf8_bytes_filled = 0;
5421 };
5422 
5423 
5424 template<typename IteratorType, typename Enable = void>
5426 {
5427  using iterator_type = IteratorType;
5428  using char_type = typename std::iterator_traits<iterator_type>::value_type;
5430 
5431  static adapter_type create(IteratorType first, IteratorType last)
5432  {
5433  return adapter_type(std::move(first), std::move(last));
5434  }
5435 };
5436 
5437 template<typename T>
5439 {
5440  using value_type = typename std::iterator_traits<T>::value_type;
5441  enum
5442  {
5443  value = sizeof(value_type) > 1
5444  };
5445 };
5446 
5447 template<typename IteratorType>
5449 {
5450  using iterator_type = IteratorType;
5451  using char_type = typename std::iterator_traits<iterator_type>::value_type;
5454 
5455  static adapter_type create(IteratorType first, IteratorType last)
5456  {
5457  return adapter_type(base_adapter_type(std::move(first), std::move(last)));
5458  }
5459 };
5460 
5461 // General purpose iterator-based input
5462 template<typename IteratorType>
5463 typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
5464 {
5465  using factory_type = iterator_input_adapter_factory<IteratorType>;
5466  return factory_type::create(first, last);
5467 }
5468 
5469 // Convenience shorthand from container to iterator
5470 // Enables ADL on begin(container) and end(container)
5471 // Encloses the using declarations in namespace for not to leak them to outside scope
5472 
5473 namespace container_input_adapter_factory_impl
5474 {
5475 
5476 using std::begin;
5477 using std::end;
5478 
5479 template<typename ContainerType, typename Enable = void>
5481 
5482 template<typename ContainerType>
5483 struct container_input_adapter_factory< ContainerType,
5484  void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
5485  {
5486  using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
5487 
5488  static adapter_type create(const ContainerType& container)
5489 {
5490  return input_adapter(begin(container), end(container));
5491 }
5492  };
5493 
5494 } // namespace container_input_adapter_factory_impl
5495 
5496 template<typename ContainerType>
5498 {
5500 }
5501 
5502 // Special cases with fast paths
5503 inline file_input_adapter input_adapter(std::FILE* file)
5504 {
5505  return file_input_adapter(file);
5506 }
5507 
5508 inline input_stream_adapter input_adapter(std::istream& stream)
5509 {
5510  return input_stream_adapter(stream);
5511 }
5512 
5513 inline input_stream_adapter input_adapter(std::istream&& stream)
5514 {
5515  return input_stream_adapter(stream);
5516 }
5517 
5518 using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
5519 
5520 // Null-delimited strings, and the like.
5521 template < typename CharT,
5522  typename std::enable_if <
5526  sizeof(typename std::remove_pointer<CharT>::type) == 1,
5527  int >::type = 0 >
5529 {
5530  auto length = std::strlen(reinterpret_cast<const char*>(b));
5531  const auto* ptr = reinterpret_cast<const char*>(b);
5532  return input_adapter(ptr, ptr + length);
5533 }
5534 
5535 template<typename T, std::size_t N>
5536 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)
5537 {
5538  return input_adapter(array, array + N);
5539 }
5540 
5541 // This class only handles inputs of input_buffer_adapter type.
5542 // It's required so that expressions like {ptr, len} can be implicitely casted
5543 // to the correct adapter.
5545 {
5546  public:
5547  template < typename CharT,
5548  typename std::enable_if <
5551  sizeof(typename std::remove_pointer<CharT>::type) == 1,
5552  int >::type = 0 >
5553  span_input_adapter(CharT b, std::size_t l)
5554  : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
5555 
5556  template<class IteratorType,
5557  typename std::enable_if<
5558  std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
5559  int>::type = 0>
5560  span_input_adapter(IteratorType first, IteratorType last)
5561  : ia(input_adapter(first, last)) {}
5562 
5564  {
5565  return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg)
5566  }
5567 
5568  private:
5570 };
5571 } // namespace detail
5572 } // namespace nlohmann
5573 
5574 // #include <nlohmann/detail/input/json_sax.hpp>
5575 
5576 
5577 #include <cstddef>
5578 #include <string> // string
5579 #include <utility> // move
5580 #include <vector> // vector
5581 
5582 // #include <nlohmann/detail/exceptions.hpp>
5583 
5584 // #include <nlohmann/detail/macro_scope.hpp>
5585 
5586 
5587 namespace nlohmann
5588 {
5589 
5598 template<typename BasicJsonType>
5599 struct json_sax
5600 {
5601  using number_integer_t = typename BasicJsonType::number_integer_t;
5602  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
5603  using number_float_t = typename BasicJsonType::number_float_t;
5605  using binary_t = typename BasicJsonType::binary_t;
5606 
5611  virtual bool null() = 0;
5612 
5618  virtual bool boolean(bool val) = 0;
5619 
5625  virtual bool number_integer(number_integer_t val) = 0;
5626 
5632  virtual bool number_unsigned(number_unsigned_t val) = 0;
5633 
5640  virtual bool number_float(number_float_t val, const string_t& s) = 0;
5641 
5648  virtual bool string(string_t& val) = 0;
5649 
5656  virtual bool binary(binary_t& val) = 0;
5657 
5664  virtual bool start_object(std::size_t elements) = 0;
5665 
5672  virtual bool key(string_t& val) = 0;
5673 
5678  virtual bool end_object() = 0;
5679 
5686  virtual bool start_array(std::size_t elements) = 0;
5687 
5692  virtual bool end_array() = 0;
5693 
5701  virtual bool parse_error(std::size_t position,
5702  const std::string& last_token,
5703  const detail::exception& ex) = 0;
5704 
5705  json_sax() = default;
5706  json_sax(const json_sax&) = default;
5707  json_sax(json_sax&&) noexcept = default;
5708  json_sax& operator=(const json_sax&) = default;
5709  json_sax& operator=(json_sax&&) noexcept = default;
5710  virtual ~json_sax() = default;
5711 };
5712 
5713 
5714 namespace detail
5715 {
5729 template<typename BasicJsonType>
5731 {
5732  public:
5733  using number_integer_t = typename BasicJsonType::number_integer_t;
5734  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
5735  using number_float_t = typename BasicJsonType::number_float_t;
5737  using binary_t = typename BasicJsonType::binary_t;
5738 
5744  explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)
5745  : root(r), allow_exceptions(allow_exceptions_)
5746  {}
5747 
5748  // make class move-only
5750  json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
5752  json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
5754 
5755  bool null()
5756  {
5757  handle_value(nullptr);
5758  return true;
5759  }
5760 
5761  bool boolean(bool val)
5762  {
5763  handle_value(val);
5764  return true;
5765  }
5766 
5768  {
5769  handle_value(val);
5770  return true;
5771  }
5772 
5774  {
5775  handle_value(val);
5776  return true;
5777  }
5778 
5779  bool number_float(number_float_t val, const string_t& /*unused*/)
5780  {
5781  handle_value(val);
5782  return true;
5783  }
5784 
5785  bool string(string_t& val)
5786  {
5787  handle_value(val);
5788  return true;
5789  }
5790 
5791  bool binary(binary_t& val)
5792  {
5793  handle_value(std::move(val));
5794  return true;
5795  }
5796 
5797  bool start_object(std::size_t len)
5798  {
5799  ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
5800 
5801  if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5802  {
5803  JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
5804  }
5805 
5806  return true;
5807  }
5808 
5809  bool key(string_t& val)
5810  {
5811  // add null at given key and store the reference for later
5812  object_element = &(ref_stack.back()->m_value.object->operator[](val));
5813  return true;
5814  }
5815 
5816  bool end_object()
5817  {
5818  ref_stack.back()->set_parents();
5819  ref_stack.pop_back();
5820  return true;
5821  }
5822 
5823  bool start_array(std::size_t len)
5824  {
5825  ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
5826 
5827  if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5828  {
5829  JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
5830  }
5831 
5832  return true;
5833  }
5834 
5835  bool end_array()
5836  {
5837  ref_stack.back()->set_parents();
5838  ref_stack.pop_back();
5839  return true;
5840  }
5841 
5842  template<class Exception>
5843  bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
5844  const Exception& ex)
5845  {
5846  errored = true;
5847  static_cast<void>(ex);
5848  if (allow_exceptions)
5849  {
5850  JSON_THROW(ex);
5851  }
5852  return false;
5853  }
5854 
5855  constexpr bool is_errored() const
5856  {
5857  return errored;
5858  }
5859 
5860  private:
5867  template<typename Value>
5869  BasicJsonType* handle_value(Value&& v)
5870  {
5871  if (ref_stack.empty())
5872  {
5873  root = BasicJsonType(std::forward<Value>(v));
5874  return &root;
5875  }
5876 
5877  JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
5878 
5879  if (ref_stack.back()->is_array())
5880  {
5881  ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
5882  return &(ref_stack.back()->m_value.array->back());
5883  }
5884 
5885  JSON_ASSERT(ref_stack.back()->is_object());
5886  JSON_ASSERT(object_element);
5887  *object_element = BasicJsonType(std::forward<Value>(v));
5888  return object_element;
5889  }
5890 
5892  BasicJsonType& root;
5894  std::vector<BasicJsonType*> ref_stack {};
5896  BasicJsonType* object_element = nullptr;
5898  bool errored = false;
5900  const bool allow_exceptions = true;
5901 };
5902 
5903 template<typename BasicJsonType>
5905 {
5906  public:
5907  using number_integer_t = typename BasicJsonType::number_integer_t;
5908  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
5909  using number_float_t = typename BasicJsonType::number_float_t;
5911  using binary_t = typename BasicJsonType::binary_t;
5914 
5916  const parser_callback_t cb,
5917  const bool allow_exceptions_ = true)
5918  : root(r), callback(cb), allow_exceptions(allow_exceptions_)
5919  {
5920  keep_stack.push_back(true);
5921  }
5922 
5923  // make class move-only
5925  json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
5927  json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
5929 
5930  bool null()
5931  {
5932  handle_value(nullptr);
5933  return true;
5934  }
5935 
5936  bool boolean(bool val)
5937  {
5938  handle_value(val);
5939  return true;
5940  }
5941 
5943  {
5944  handle_value(val);
5945  return true;
5946  }
5947 
5949  {
5950  handle_value(val);
5951  return true;
5952  }
5953 
5954  bool number_float(number_float_t val, const string_t& /*unused*/)
5955  {
5956  handle_value(val);
5957  return true;
5958  }
5959 
5960  bool string(string_t& val)
5961  {
5962  handle_value(val);
5963  return true;
5964  }
5965 
5966  bool binary(binary_t& val)
5967  {
5968  handle_value(std::move(val));
5969  return true;
5970  }
5971 
5972  bool start_object(std::size_t len)
5973  {
5974  // check callback for object start
5975  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
5976  keep_stack.push_back(keep);
5977 
5978  auto val = handle_value(BasicJsonType::value_t::object, true);
5979  ref_stack.push_back(val.second);
5980 
5981  // check object limit
5982  if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5983  {
5984  JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
5985  }
5986 
5987  return true;
5988  }
5989 
5990  bool key(string_t& val)
5991  {
5992  BasicJsonType k = BasicJsonType(val);
5993 
5994  // check callback for key
5995  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);
5996  key_keep_stack.push_back(keep);
5997 
5998  // add discarded value at given key and store the reference for later
5999  if (keep && ref_stack.back())
6000  {
6001  object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
6002  }
6003 
6004  return true;
6005  }
6006 
6007  bool end_object()
6008  {
6009  if (ref_stack.back())
6010  {
6011  if (!callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
6012  {
6013  // discard object
6014  *ref_stack.back() = discarded;
6015  }
6016  else
6017  {
6018  ref_stack.back()->set_parents();
6019  }
6020  }
6021 
6022  JSON_ASSERT(!ref_stack.empty());
6023  JSON_ASSERT(!keep_stack.empty());
6024  ref_stack.pop_back();
6025  keep_stack.pop_back();
6026 
6027  if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
6028  {
6029  // remove discarded value
6030  for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
6031  {
6032  if (it->is_discarded())
6033  {
6034  ref_stack.back()->erase(it);
6035  break;
6036  }
6037  }
6038  }
6039 
6040  return true;
6041  }
6042 
6043  bool start_array(std::size_t len)
6044  {
6045  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
6046  keep_stack.push_back(keep);
6047 
6048  auto val = handle_value(BasicJsonType::value_t::array, true);
6049  ref_stack.push_back(val.second);
6050 
6051  // check array limit
6052  if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6053  {
6054  JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
6055  }
6056 
6057  return true;
6058  }
6059 
6060  bool end_array()
6061  {
6062  bool keep = true;
6063 
6064  if (ref_stack.back())
6065  {
6066  keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
6067  if (keep)
6068  {
6069  ref_stack.back()->set_parents();
6070  }
6071  else
6072  {
6073  // discard array
6074  *ref_stack.back() = discarded;
6075  }
6076  }
6077 
6078  JSON_ASSERT(!ref_stack.empty());
6079  JSON_ASSERT(!keep_stack.empty());
6080  ref_stack.pop_back();
6081  keep_stack.pop_back();
6082 
6083  // remove discarded value
6084  if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
6085  {
6086  ref_stack.back()->m_value.array->pop_back();
6087  }
6088 
6089  return true;
6090  }
6091 
6092  template<class Exception>
6093  bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
6094  const Exception& ex)
6095  {
6096  errored = true;
6097  static_cast<void>(ex);
6098  if (allow_exceptions)
6099  {
6100  JSON_THROW(ex);
6101  }
6102  return false;
6103  }
6104 
6105  constexpr bool is_errored() const
6106  {
6107  return errored;
6108  }
6109 
6110  private:
6126  template<typename Value>
6127  std::pair<bool, BasicJsonType*> handle_value(Value&& v, const bool skip_callback = false)
6128  {
6129  JSON_ASSERT(!keep_stack.empty());
6130 
6131  // do not handle this value if we know it would be added to a discarded
6132  // container
6133  if (!keep_stack.back())
6134  {
6135  return {false, nullptr};
6136  }
6137 
6138  // create value
6139  auto value = BasicJsonType(std::forward<Value>(v));
6140 
6141  // check callback
6142  const bool keep = skip_callback || callback(static_cast<int>(ref_stack.size()), parse_event_t::value, value);
6143 
6144  // do not handle this value if we just learnt it shall be discarded
6145  if (!keep)
6146  {
6147  return {false, nullptr};
6148  }
6149 
6150  if (ref_stack.empty())
6151  {
6152  root = std::move(value);
6153  return {true, &root};
6154  }
6155 
6156  // skip this value if we already decided to skip the parent
6157  // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
6158  if (!ref_stack.back())
6159  {
6160  return {false, nullptr};
6161  }
6162 
6163  // we now only expect arrays and objects
6164  JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6165 
6166  // array
6167  if (ref_stack.back()->is_array())
6168  {
6169  ref_stack.back()->m_value.array->emplace_back(std::move(value));
6170  return {true, &(ref_stack.back()->m_value.array->back())};
6171  }
6172 
6173  // object
6174  JSON_ASSERT(ref_stack.back()->is_object());
6175  // check if we should store an element for the current key
6176  JSON_ASSERT(!key_keep_stack.empty());
6177  const bool store_element = key_keep_stack.back();
6178  key_keep_stack.pop_back();
6179 
6180  if (!store_element)
6181  {
6182  return {false, nullptr};
6183  }
6184 
6185  JSON_ASSERT(object_element);
6186  *object_element = std::move(value);
6187  return {true, object_element};
6188  }
6189 
6191  BasicJsonType& root;
6193  std::vector<BasicJsonType*> ref_stack {};
6195  std::vector<bool> keep_stack {};
6197  std::vector<bool> key_keep_stack {};
6199  BasicJsonType* object_element = nullptr;
6201  bool errored = false;
6203  const parser_callback_t callback = nullptr;
6205  const bool allow_exceptions = true;
6207  BasicJsonType discarded = BasicJsonType::value_t::discarded;
6208 };
6209 
6210 template<typename BasicJsonType>
6212 {
6213  public:
6214  using number_integer_t = typename BasicJsonType::number_integer_t;
6215  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
6216  using number_float_t = typename BasicJsonType::number_float_t;
6218  using binary_t = typename BasicJsonType::binary_t;
6219 
6220  bool null()
6221  {
6222  return true;
6223  }
6224 
6225  bool boolean(bool /*unused*/)
6226  {
6227  return true;
6228  }
6229 
6231  {
6232  return true;
6233  }
6234 
6236  {
6237  return true;
6238  }
6239 
6240  bool number_float(number_float_t /*unused*/, const string_t& /*unused*/)
6241  {
6242  return true;
6243  }
6244 
6245  bool string(string_t& /*unused*/)
6246  {
6247  return true;
6248  }
6249 
6250  bool binary(binary_t& /*unused*/)
6251  {
6252  return true;
6253  }
6254 
6255  bool start_object(std::size_t /*unused*/ = std::size_t(-1))
6256  {
6257  return true;
6258  }
6259 
6260  bool key(string_t& /*unused*/)
6261  {
6262  return true;
6263  }
6264 
6265  bool end_object()
6266  {
6267  return true;
6268  }
6269 
6270  bool start_array(std::size_t /*unused*/ = std::size_t(-1))
6271  {
6272  return true;
6273  }
6274 
6275  bool end_array()
6276  {
6277  return true;
6278  }
6279 
6280  bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& /*unused*/)
6281  {
6282  return false;
6283  }
6284 };
6285 } // namespace detail
6286 
6287 } // namespace nlohmann
6288 
6289 // #include <nlohmann/detail/input/lexer.hpp>
6290 
6291 
6292 #include <array> // array
6293 #include <clocale> // localeconv
6294 #include <cstddef> // size_t
6295 #include <cstdio> // snprintf
6296 #include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull
6297 #include <initializer_list> // initializer_list
6298 #include <string> // char_traits, string
6299 #include <utility> // move
6300 #include <vector> // vector
6301 
6302 // #include <nlohmann/detail/input/input_adapters.hpp>
6303 
6304 // #include <nlohmann/detail/input/position_t.hpp>
6305 
6306 // #include <nlohmann/detail/macro_scope.hpp>
6307 
6308 
6309 namespace nlohmann
6310 {
6311 namespace detail
6312 {
6314 // lexer //
6316 
6317 template<typename BasicJsonType>
6319 {
6320  public:
6322  enum class token_type
6323  {
6324  uninitialized,
6325  literal_true,
6326  literal_false,
6327  literal_null,
6328  value_string,
6329  value_unsigned,
6330  value_integer,
6331  value_float,
6332  begin_array,
6333  begin_object,
6334  end_array,
6335  end_object,
6336  name_separator,
6337  value_separator,
6338  parse_error,
6339  end_of_input,
6341  };
6342 
6346  static const char* token_type_name(const token_type t) noexcept
6347  {
6348  switch (t)
6349  {
6351  return "<uninitialized>";
6353  return "true literal";
6355  return "false literal";
6357  return "null literal";
6359  return "string literal";
6363  return "number literal";
6365  return "'['";
6367  return "'{'";
6368  case token_type::end_array:
6369  return "']'";
6371  return "'}'";
6373  return "':'";
6375  return "','";
6377  return "<parse error>";
6379  return "end of input";
6381  return "'[', '{', or a literal";
6382  // LCOV_EXCL_START
6383  default: // catch non-enum values
6384  return "unknown token";
6385  // LCOV_EXCL_STOP
6386  }
6387  }
6388 };
6394 template<typename BasicJsonType, typename InputAdapterType>
6395 class lexer : public lexer_base<BasicJsonType>
6396 {
6397  using number_integer_t = typename BasicJsonType::number_integer_t;
6398  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
6399  using number_float_t = typename BasicJsonType::number_float_t;
6401  using char_type = typename InputAdapterType::char_type;
6402  using char_int_type = typename std::char_traits<char_type>::int_type;
6403 
6404  public:
6406 
6407  explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept
6408  : ia(std::move(adapter))
6409  , ignore_comments(ignore_comments_)
6411  {}
6412 
6413  // delete because of pointer members
6414  lexer(const lexer&) = delete;
6415  lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
6416  lexer& operator=(lexer&) = delete;
6417  lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
6418  ~lexer() = default;
6419 
6420  private:
6422  // locales
6424 
6427  static char get_decimal_point() noexcept
6428  {
6429  const auto* loc = localeconv();
6430  JSON_ASSERT(loc != nullptr);
6431  return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point);
6432  }
6433 
6435  // scan functions
6437 
6454  {
6455  // this function only makes sense after reading `\u`
6456  JSON_ASSERT(current == 'u');
6457  int codepoint = 0;
6458 
6459  const auto factors = { 12u, 8u, 4u, 0u };
6460  for (const auto factor : factors)
6461  {
6462  get();
6463 
6464  if (current >= '0' && current <= '9')
6465  {
6466  codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor);
6467  }
6468  else if (current >= 'A' && current <= 'F')
6469  {
6470  codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor);
6471  }
6472  else if (current >= 'a' && current <= 'f')
6473  {
6474  codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor);
6475  }
6476  else
6477  {
6478  return -1;
6479  }
6480  }
6481 
6482  JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6483  return codepoint;
6484  }
6485 
6501  bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
6502  {
6503  JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
6504  add(current);
6505 
6506  for (auto range = ranges.begin(); range != ranges.end(); ++range)
6507  {
6508  get();
6509  if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
6510  {
6511  add(current);
6512  }
6513  else
6514  {
6515  error_message = "invalid string: ill-formed UTF-8 byte";
6516  return false;
6517  }
6518  }
6519 
6520  return true;
6521  }
6522 
6539  {
6540  // reset token_buffer (ignore opening quote)
6541  reset();
6542 
6543  // we entered the function by reading an open quote
6544  JSON_ASSERT(current == '\"');
6545 
6546  while (true)
6547  {
6548  // get next character
6549  switch (get())
6550  {
6551  // end of file while parsing string
6552  case std::char_traits<char_type>::eof():
6553  {
6554  error_message = "invalid string: missing closing quote";
6555  return token_type::parse_error;
6556  }
6557 
6558  // closing quote
6559  case '\"':
6560  {
6561  return token_type::value_string;
6562  }
6563 
6564  // escapes
6565  case '\\':
6566  {
6567  switch (get())
6568  {
6569  // quotation mark
6570  case '\"':
6571  add('\"');
6572  break;
6573  // reverse solidus
6574  case '\\':
6575  add('\\');
6576  break;
6577  // solidus
6578  case '/':
6579  add('/');
6580  break;
6581  // backspace
6582  case 'b':
6583  add('\b');
6584  break;
6585  // form feed
6586  case 'f':
6587  add('\f');
6588  break;
6589  // line feed
6590  case 'n':
6591  add('\n');
6592  break;
6593  // carriage return
6594  case 'r':
6595  add('\r');
6596  break;
6597  // tab
6598  case 't':
6599  add('\t');
6600  break;
6601 
6602  // unicode escapes
6603  case 'u':
6604  {
6605  const int codepoint1 = get_codepoint();
6606  int codepoint = codepoint1; // start with codepoint1
6607 
6608  if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
6609  {
6610  error_message = "invalid string: '\\u' must be followed by 4 hex digits";
6611  return token_type::parse_error;
6612  }
6613 
6614  // check if code point is a high surrogate
6615  if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
6616  {
6617  // expect next \uxxxx entry
6618  if (JSON_HEDLEY_LIKELY(get() == '\\' && get() == 'u'))
6619  {
6620  const int codepoint2 = get_codepoint();
6621 
6622  if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
6623  {
6624  error_message = "invalid string: '\\u' must be followed by 4 hex digits";
6625  return token_type::parse_error;
6626  }
6627 
6628  // check if codepoint2 is a low surrogate
6629  if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
6630  {
6631  // overwrite codepoint
6632  codepoint = static_cast<int>(
6633  // high surrogate occupies the most significant 22 bits
6634  (static_cast<unsigned int>(codepoint1) << 10u)
6635  // low surrogate occupies the least significant 15 bits
6636  + static_cast<unsigned int>(codepoint2)
6637  // there is still the 0xD800, 0xDC00 and 0x10000 noise
6638  // in the result so we have to subtract with:
6639  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
6640  - 0x35FDC00u);
6641  }
6642  else
6643  {
6644  error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6645  return token_type::parse_error;
6646  }
6647  }
6648  else
6649  {
6650  error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6651  return token_type::parse_error;
6652  }
6653  }
6654  else
6655  {
6656  if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
6657  {
6658  error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
6659  return token_type::parse_error;
6660  }
6661  }
6662 
6663  // result of the above calculation yields a proper codepoint
6664  JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
6665 
6666  // translate codepoint into bytes
6667  if (codepoint < 0x80)
6668  {
6669  // 1-byte characters: 0xxxxxxx (ASCII)
6670  add(static_cast<char_int_type>(codepoint));
6671  }
6672  else if (codepoint <= 0x7FF)
6673  {
6674  // 2-byte characters: 110xxxxx 10xxxxxx
6675  add(static_cast<char_int_type>(0xC0u | (static_cast<unsigned int>(codepoint) >> 6u)));
6676  add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
6677  }
6678  else if (codepoint <= 0xFFFF)
6679  {
6680  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
6681  add(static_cast<char_int_type>(0xE0u | (static_cast<unsigned int>(codepoint) >> 12u)));
6682  add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6683  add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
6684  }
6685  else
6686  {
6687  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
6688  add(static_cast<char_int_type>(0xF0u | (static_cast<unsigned int>(codepoint) >> 18u)));
6689  add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
6690  add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6691  add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
6692  }
6693 
6694  break;
6695  }
6696 
6697  // other characters after escape
6698  default:
6699  error_message = "invalid string: forbidden character after backslash";
6700  return token_type::parse_error;
6701  }
6702 
6703  break;
6704  }
6705 
6706  // invalid control characters
6707  case 0x00:
6708  {
6709  error_message = "invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
6710  return token_type::parse_error;
6711  }
6712 
6713  case 0x01:
6714  {
6715  error_message = "invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
6716  return token_type::parse_error;
6717  }
6718 
6719  case 0x02:
6720  {
6721  error_message = "invalid string: control character U+0002 (STX) must be escaped to \\u0002";
6722  return token_type::parse_error;
6723  }
6724 
6725  case 0x03:
6726  {
6727  error_message = "invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
6728  return token_type::parse_error;
6729  }
6730 
6731  case 0x04:
6732  {
6733  error_message = "invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
6734  return token_type::parse_error;
6735  }
6736 
6737  case 0x05:
6738  {
6739  error_message = "invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
6740  return token_type::parse_error;
6741  }
6742 
6743  case 0x06:
6744  {
6745  error_message = "invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
6746  return token_type::parse_error;
6747  }
6748 
6749  case 0x07:
6750  {
6751  error_message = "invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
6752  return token_type::parse_error;
6753  }
6754 
6755  case 0x08:
6756  {
6757  error_message = "invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
6758  return token_type::parse_error;
6759  }
6760 
6761  case 0x09:
6762  {
6763  error_message = "invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
6764  return token_type::parse_error;
6765  }
6766 
6767  case 0x0A:
6768  {
6769  error_message = "invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
6770  return token_type::parse_error;
6771  }
6772 
6773  case 0x0B:
6774  {
6775  error_message = "invalid string: control character U+000B (VT) must be escaped to \\u000B";
6776  return token_type::parse_error;
6777  }
6778 
6779  case 0x0C:
6780  {
6781  error_message = "invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
6782  return token_type::parse_error;
6783  }
6784 
6785  case 0x0D:
6786  {
6787  error_message = "invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
6788  return token_type::parse_error;
6789  }
6790 
6791  case 0x0E:
6792  {
6793  error_message = "invalid string: control character U+000E (SO) must be escaped to \\u000E";
6794  return token_type::parse_error;
6795  }
6796 
6797  case 0x0F:
6798  {
6799  error_message = "invalid string: control character U+000F (SI) must be escaped to \\u000F";
6800  return token_type::parse_error;
6801  }
6802 
6803  case 0x10:
6804  {
6805  error_message = "invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
6806  return token_type::parse_error;
6807  }
6808 
6809  case 0x11:
6810  {
6811  error_message = "invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
6812  return token_type::parse_error;
6813  }
6814 
6815  case 0x12:
6816  {
6817  error_message = "invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
6818  return token_type::parse_error;
6819  }
6820 
6821  case 0x13:
6822  {
6823  error_message = "invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
6824  return token_type::parse_error;
6825  }
6826 
6827  case 0x14:
6828  {
6829  error_message = "invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
6830  return token_type::parse_error;
6831  }
6832 
6833  case 0x15:
6834  {
6835  error_message = "invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
6836  return token_type::parse_error;
6837  }
6838 
6839  case 0x16:
6840  {
6841  error_message = "invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
6842  return token_type::parse_error;
6843  }
6844 
6845  case 0x17:
6846  {
6847  error_message = "invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
6848  return token_type::parse_error;
6849  }
6850 
6851  case 0x18:
6852  {
6853  error_message = "invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
6854  return token_type::parse_error;
6855  }
6856 
6857  case 0x19:
6858  {
6859  error_message = "invalid string: control character U+0019 (EM) must be escaped to \\u0019";
6860  return token_type::parse_error;
6861  }
6862 
6863  case 0x1A:
6864  {
6865  error_message = "invalid string: control character U+001A (SUB) must be escaped to \\u001A";
6866  return token_type::parse_error;
6867  }
6868 
6869  case 0x1B:
6870  {
6871  error_message = "invalid string: control character U+001B (ESC) must be escaped to \\u001B";
6872  return token_type::parse_error;
6873  }
6874 
6875  case 0x1C:
6876  {
6877  error_message = "invalid string: control character U+001C (FS) must be escaped to \\u001C";
6878  return token_type::parse_error;
6879  }
6880 
6881  case 0x1D:
6882  {
6883  error_message = "invalid string: control character U+001D (GS) must be escaped to \\u001D";
6884  return token_type::parse_error;
6885  }
6886 
6887  case 0x1E:
6888  {
6889  error_message = "invalid string: control character U+001E (RS) must be escaped to \\u001E";
6890  return token_type::parse_error;
6891  }
6892 
6893  case 0x1F:
6894  {
6895  error_message = "invalid string: control character U+001F (US) must be escaped to \\u001F";
6896  return token_type::parse_error;
6897  }
6898 
6899  // U+0020..U+007F (except U+0022 (quote) and U+005C (backspace))
6900  case 0x20:
6901  case 0x21:
6902  case 0x23:
6903  case 0x24:
6904  case 0x25:
6905  case 0x26:
6906  case 0x27:
6907  case 0x28:
6908  case 0x29:
6909  case 0x2A:
6910  case 0x2B:
6911  case 0x2C:
6912  case 0x2D:
6913  case 0x2E:
6914  case 0x2F:
6915  case 0x30:
6916  case 0x31:
6917  case 0x32:
6918  case 0x33:
6919  case 0x34:
6920  case 0x35:
6921  case 0x36:
6922  case 0x37:
6923  case 0x38:
6924  case 0x39:
6925  case 0x3A:
6926  case 0x3B:
6927  case 0x3C:
6928  case 0x3D:
6929  case 0x3E:
6930  case 0x3F:
6931  case 0x40:
6932  case 0x41:
6933  case 0x42:
6934  case 0x43:
6935  case 0x44:
6936  case 0x45:
6937  case 0x46:
6938  case 0x47:
6939  case 0x48:
6940  case 0x49:
6941  case 0x4A:
6942  case 0x4B:
6943  case 0x4C:
6944  case 0x4D:
6945  case 0x4E:
6946  case 0x4F:
6947  case 0x50:
6948  case 0x51:
6949  case 0x52:
6950  case 0x53:
6951  case 0x54:
6952  case 0x55:
6953  case 0x56:
6954  case 0x57:
6955  case 0x58:
6956  case 0x59:
6957  case 0x5A:
6958  case 0x5B:
6959  case 0x5D:
6960  case 0x5E:
6961  case 0x5F:
6962  case 0x60:
6963  case 0x61:
6964  case 0x62:
6965  case 0x63:
6966  case 0x64:
6967  case 0x65:
6968  case 0x66:
6969  case 0x67:
6970  case 0x68:
6971  case 0x69:
6972  case 0x6A:
6973  case 0x6B:
6974  case 0x6C:
6975  case 0x6D:
6976  case 0x6E:
6977  case 0x6F:
6978  case 0x70:
6979  case 0x71:
6980  case 0x72:
6981  case 0x73:
6982  case 0x74:
6983  case 0x75:
6984  case 0x76:
6985  case 0x77:
6986  case 0x78:
6987  case 0x79:
6988  case 0x7A:
6989  case 0x7B:
6990  case 0x7C:
6991  case 0x7D:
6992  case 0x7E:
6993  case 0x7F:
6994  {
6995  add(current);
6996  break;
6997  }
6998 
6999  // U+0080..U+07FF: bytes C2..DF 80..BF
7000  case 0xC2:
7001  case 0xC3:
7002  case 0xC4:
7003  case 0xC5:
7004  case 0xC6:
7005  case 0xC7:
7006  case 0xC8:
7007  case 0xC9:
7008  case 0xCA:
7009  case 0xCB:
7010  case 0xCC:
7011  case 0xCD:
7012  case 0xCE:
7013  case 0xCF:
7014  case 0xD0:
7015  case 0xD1:
7016  case 0xD2:
7017  case 0xD3:
7018  case 0xD4:
7019  case 0xD5:
7020  case 0xD6:
7021  case 0xD7:
7022  case 0xD8:
7023  case 0xD9:
7024  case 0xDA:
7025  case 0xDB:
7026  case 0xDC:
7027  case 0xDD:
7028  case 0xDE:
7029  case 0xDF:
7030  {
7031  if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
7032  {
7033  return token_type::parse_error;
7034  }
7035  break;
7036  }
7037 
7038  // U+0800..U+0FFF: bytes E0 A0..BF 80..BF
7039  case 0xE0:
7040  {
7041  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7042  {
7043  return token_type::parse_error;
7044  }
7045  break;
7046  }
7047 
7048  // U+1000..U+CFFF: bytes E1..EC 80..BF 80..BF
7049  // U+E000..U+FFFF: bytes EE..EF 80..BF 80..BF
7050  case 0xE1:
7051  case 0xE2:
7052  case 0xE3:
7053  case 0xE4:
7054  case 0xE5:
7055  case 0xE6:
7056  case 0xE7:
7057  case 0xE8:
7058  case 0xE9:
7059  case 0xEA:
7060  case 0xEB:
7061  case 0xEC:
7062  case 0xEE:
7063  case 0xEF:
7064  {
7065  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7066  {
7067  return token_type::parse_error;
7068  }
7069  break;
7070  }
7071 
7072  // U+D000..U+D7FF: bytes ED 80..9F 80..BF
7073  case 0xED:
7074  {
7075  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7076  {
7077  return token_type::parse_error;
7078  }
7079  break;
7080  }
7081 
7082  // U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
7083  case 0xF0:
7084  {
7085  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7086  {
7087  return token_type::parse_error;
7088  }
7089  break;
7090  }
7091 
7092  // U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF
7093  case 0xF1:
7094  case 0xF2:
7095  case 0xF3:
7096  {
7097  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7098  {
7099  return token_type::parse_error;
7100  }
7101  break;
7102  }
7103 
7104  // U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
7105  case 0xF4:
7106  {
7107  if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7108  {
7109  return token_type::parse_error;
7110  }
7111  break;
7112  }
7113 
7114  // remaining bytes (80..C1 and F5..FF) are ill-formed
7115  default:
7116  {
7117  error_message = "invalid string: ill-formed UTF-8 byte";
7118  return token_type::parse_error;
7119  }
7120  }
7121  }
7122  }
7123 
7129  {
7130  switch (get())
7131  {
7132  // single-line comments skip input until a newline or EOF is read
7133  case '/':
7134  {
7135  while (true)
7136  {
7137  switch (get())
7138  {
7139  case '\n':
7140  case '\r':
7141  case std::char_traits<char_type>::eof():
7142  case '\0':
7143  return true;
7144 
7145  default:
7146  break;
7147  }
7148  }
7149  }
7150 
7151  // multi-line comments skip input until */ is read
7152  case '*':
7153  {
7154  while (true)
7155  {
7156  switch (get())
7157  {
7158  case std::char_traits<char_type>::eof():
7159  case '\0':
7160  {
7161  error_message = "invalid comment; missing closing '*/'";
7162  return false;
7163  }
7164 
7165  case '*':
7166  {
7167  switch (get())
7168  {
7169  case '/':
7170  return true;
7171 
7172  default:
7173  {
7174  unget();
7175  continue;
7176  }
7177  }
7178  }
7179 
7180  default:
7181  continue;
7182  }
7183  }
7184  }
7185 
7186  // unexpected character after reading '/'
7187  default:
7188  {
7189  error_message = "invalid comment; expecting '/' or '*' after '/'";
7190  return false;
7191  }
7192  }
7193  }
7194 
7196  static void strtof(float& f, const char* str, char** endptr) noexcept
7197  {
7198  f = std::strtof(str, endptr);
7199  }
7200 
7202  static void strtof(double& f, const char* str, char** endptr) noexcept
7203  {
7204  f = std::strtod(str, endptr);
7205  }
7206 
7208  static void strtof(long double& f, const char* str, char** endptr) noexcept
7209  {
7210  f = std::strtold(str, endptr);
7211  }
7212 
7253  token_type scan_number() // lgtm [cpp/use-of-goto]
7254  {
7255  // reset token_buffer to store the number's bytes
7256  reset();
7257 
7258  // the type of the parsed number; initially set to unsigned; will be
7259  // changed if minus sign, decimal point or exponent is read
7260  token_type number_type = token_type::value_unsigned;
7261 
7262  // state (init): we just found out we need to scan a number
7263  switch (current)
7264  {
7265  case '-':
7266  {
7267  add(current);
7268  goto scan_number_minus;
7269  }
7270 
7271  case '0':
7272  {
7273  add(current);
7274  goto scan_number_zero;
7275  }
7276 
7277  case '1':
7278  case '2':
7279  case '3':
7280  case '4':
7281  case '5':
7282  case '6':
7283  case '7':
7284  case '8':
7285  case '9':
7286  {
7287  add(current);
7288  goto scan_number_any1;
7289  }
7290 
7291  // all other characters are rejected outside scan_number()
7292  default: // LCOV_EXCL_LINE
7293  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
7294  }
7295 
7296 scan_number_minus:
7297  // state: we just parsed a leading minus sign
7298  number_type = token_type::value_integer;
7299  switch (get())
7300  {
7301  case '0':
7302  {
7303  add(current);
7304  goto scan_number_zero;
7305  }
7306 
7307  case '1':
7308  case '2':
7309  case '3':
7310  case '4':
7311  case '5':
7312  case '6':
7313  case '7':
7314  case '8':
7315  case '9':
7316  {
7317  add(current);
7318  goto scan_number_any1;
7319  }
7320 
7321  default:
7322  {
7323  error_message = "invalid number; expected digit after '-'";
7324  return token_type::parse_error;
7325  }
7326  }
7327 
7328 scan_number_zero:
7329  // state: we just parse a zero (maybe with a leading minus sign)
7330  switch (get())
7331  {
7332  case '.':
7333  {
7335  goto scan_number_decimal1;
7336  }
7337 
7338  case 'e':
7339  case 'E':
7340  {
7341  add(current);
7342  goto scan_number_exponent;
7343  }
7344 
7345  default:
7346  goto scan_number_done;
7347  }
7348 
7349 scan_number_any1:
7350  // state: we just parsed a number 0-9 (maybe with a leading minus sign)
7351  switch (get())
7352  {
7353  case '0':
7354  case '1':
7355  case '2':
7356  case '3':
7357  case '4':
7358  case '5':
7359  case '6':
7360  case '7':
7361  case '8':
7362  case '9':
7363  {
7364  add(current);
7365  goto scan_number_any1;
7366  }
7367 
7368  case '.':
7369  {
7371  goto scan_number_decimal1;
7372  }
7373 
7374  case 'e':
7375  case 'E':
7376  {
7377  add(current);
7378  goto scan_number_exponent;
7379  }
7380 
7381  default:
7382  goto scan_number_done;
7383  }
7384 
7385 scan_number_decimal1:
7386  // state: we just parsed a decimal point
7387  number_type = token_type::value_float;
7388  switch (get())
7389  {
7390  case '0':
7391  case '1':
7392  case '2':
7393  case '3':
7394  case '4':
7395  case '5':
7396  case '6':
7397  case '7':
7398  case '8':
7399  case '9':
7400  {
7401  add(current);
7402  goto scan_number_decimal2;
7403  }
7404 
7405  default:
7406  {
7407  error_message = "invalid number; expected digit after '.'";
7408  return token_type::parse_error;
7409  }
7410  }
7411 
7412 scan_number_decimal2:
7413  // we just parsed at least one number after a decimal point
7414  switch (get())
7415  {
7416  case '0':
7417  case '1':
7418  case '2':
7419  case '3':
7420  case '4':
7421  case '5':
7422  case '6':
7423  case '7':
7424  case '8':
7425  case '9':
7426  {
7427  add(current);
7428  goto scan_number_decimal2;
7429  }
7430 
7431  case 'e':
7432  case 'E':
7433  {
7434  add(current);
7435  goto scan_number_exponent;
7436  }
7437 
7438  default:
7439  goto scan_number_done;
7440  }
7441 
7442 scan_number_exponent:
7443  // we just parsed an exponent
7444  number_type = token_type::value_float;
7445  switch (get())
7446  {
7447  case '+':
7448  case '-':
7449  {
7450  add(current);
7451  goto scan_number_sign;
7452  }
7453 
7454  case '0':
7455  case '1':
7456  case '2':
7457  case '3':
7458  case '4':
7459  case '5':
7460  case '6':
7461  case '7':
7462  case '8':
7463  case '9':
7464  {
7465  add(current);
7466  goto scan_number_any2;
7467  }
7468 
7469  default:
7470  {
7471  error_message =
7472  "invalid number; expected '+', '-', or digit after exponent";
7473  return token_type::parse_error;
7474  }
7475  }
7476 
7477 scan_number_sign:
7478  // we just parsed an exponent sign
7479  switch (get())
7480  {
7481  case '0':
7482  case '1':
7483  case '2':
7484  case '3':
7485  case '4':
7486  case '5':
7487  case '6':
7488  case '7':
7489  case '8':
7490  case '9':
7491  {
7492  add(current);
7493  goto scan_number_any2;
7494  }
7495 
7496  default:
7497  {
7498  error_message = "invalid number; expected digit after exponent sign";
7499  return token_type::parse_error;
7500  }
7501  }
7502 
7503 scan_number_any2:
7504  // we just parsed a number after the exponent or exponent sign
7505  switch (get())
7506  {
7507  case '0':
7508  case '1':
7509  case '2':
7510  case '3':
7511  case '4':
7512  case '5':
7513  case '6':
7514  case '7':
7515  case '8':
7516  case '9':
7517  {
7518  add(current);
7519  goto scan_number_any2;
7520  }
7521 
7522  default:
7523  goto scan_number_done;
7524  }
7525 
7526 scan_number_done:
7527  // unget the character after the number (we only read it to know that
7528  // we are done scanning a number)
7529  unget();
7530 
7531  char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
7532  errno = 0;
7533 
7534  // try to parse integers first and fall back to floats
7535  if (number_type == token_type::value_unsigned)
7536  {
7537  const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
7538 
7539  // we checked the number format before
7540  JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7541 
7542  if (errno == 0)
7543  {
7544  value_unsigned = static_cast<number_unsigned_t>(x);
7545  if (value_unsigned == x)
7546  {
7547  return token_type::value_unsigned;
7548  }
7549  }
7550  }
7551  else if (number_type == token_type::value_integer)
7552  {
7553  const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
7554 
7555  // we checked the number format before
7556  JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7557 
7558  if (errno == 0)
7559  {
7560  value_integer = static_cast<number_integer_t>(x);
7561  if (value_integer == x)
7562  {
7563  return token_type::value_integer;
7564  }
7565  }
7566  }
7567 
7568  // this code is reached if we parse a floating-point number or if an
7569  // integer conversion above failed
7570  strtof(value_float, token_buffer.data(), &endptr);
7571 
7572  // we checked the number format before
7573  JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7574 
7575  return token_type::value_float;
7576  }
7577 
7584  token_type scan_literal(const char_type* literal_text, const std::size_t length,
7585  token_type return_type)
7586  {
7587  JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
7588  for (std::size_t i = 1; i < length; ++i)
7589  {
7590  if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
7591  {
7592  error_message = "invalid literal";
7593  return token_type::parse_error;
7594  }
7595  }
7596  return return_type;
7597  }
7598 
7600  // input management
7602 
7604  void reset() noexcept
7605  {
7606  token_buffer.clear();
7607  token_string.clear();
7608  token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7609  }
7610 
7611  /*
7612  @brief get next character from the input
7613 
7614  This function provides the interface to the used input adapter. It does
7615  not throw in case the input reached EOF, but returns a
7616  `std::char_traits<char>::eof()` in that case. Stores the scanned characters
7617  for use in error messages.
7618 
7619  @return character read from the input
7620  */
7622  {
7625 
7626  if (next_unget)
7627  {
7628  // just reset the next_unget variable and work with current
7629  next_unget = false;
7630  }
7631  else
7632  {
7633  current = ia.get_character();
7634  }
7635 
7636  if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7637  {
7638  token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7639  }
7640 
7641  if (current == '\n')
7642  {
7643  ++position.lines_read;
7645  }
7646 
7647  return current;
7648  }
7649 
7658  void unget()
7659  {
7660  next_unget = true;
7661 
7663 
7664  // in case we "unget" a newline, we have to also decrement the lines_read
7666  {
7667  if (position.lines_read > 0)
7668  {
7669  --position.lines_read;
7670  }
7671  }
7672  else
7673  {
7675  }
7676 
7677  if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7678  {
7679  JSON_ASSERT(!token_string.empty());
7680  token_string.pop_back();
7681  }
7682  }
7683 
7686  {
7687  token_buffer.push_back(static_cast<typename string_t::value_type>(c));
7688  }
7689 
7690  public:
7692  // value getters
7694 
7697  {
7698  return value_integer;
7699  }
7700 
7703  {
7704  return value_unsigned;
7705  }
7706 
7709  {
7710  return value_float;
7711  }
7712 
7715  {
7716  return token_buffer;
7717  }
7718 
7720  // diagnostics
7722 
7724  constexpr position_t get_position() const noexcept
7725  {
7726  return position;
7727  }
7728 
7732  std::string get_token_string() const
7733  {
7734  // escape control characters
7735  std::string result;
7736  for (const auto c : token_string)
7737  {
7738  if (static_cast<unsigned char>(c) <= '\x1F')
7739  {
7740  // escape control characters
7741  std::array<char, 9> cs{{}};
7742  (std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
7743  result += cs.data();
7744  }
7745  else
7746  {
7747  // add character as is
7748  result.push_back(static_cast<std::string::value_type>(c));
7749  }
7750  }
7751 
7752  return result;
7753  }
7754 
7757  constexpr const char* get_error_message() const noexcept
7758  {
7759  return error_message;
7760  }
7761 
7763  // actual scanner
7765 
7770  bool skip_bom()
7771  {
7772  if (get() == 0xEF)
7773  {
7774  // check if we completely parse the BOM
7775  return get() == 0xBB && get() == 0xBF;
7776  }
7777 
7778  // the first character is not the beginning of the BOM; unget it to
7779  // process is later
7780  unget();
7781  return true;
7782  }
7783 
7785  {
7786  do
7787  {
7788  get();
7789  }
7790  while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
7791  }
7792 
7794  {
7795  // initially, skip the BOM
7796  if (position.chars_read_total == 0 && !skip_bom())
7797  {
7798  error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given";
7799  return token_type::parse_error;
7800  }
7801 
7802  // read next character and ignore whitespace
7803  skip_whitespace();
7804 
7805  // ignore comments
7806  while (ignore_comments && current == '/')
7807  {
7808  if (!scan_comment())
7809  {
7810  return token_type::parse_error;
7811  }
7812 
7813  // skip following whitespace
7814  skip_whitespace();
7815  }
7816 
7817  switch (current)
7818  {
7819  // structural characters
7820  case '[':
7821  return token_type::begin_array;
7822  case ']':
7823  return token_type::end_array;
7824  case '{':
7825  return token_type::begin_object;
7826  case '}':
7827  return token_type::end_object;
7828  case ':':
7829  return token_type::name_separator;
7830  case ',':
7831  return token_type::value_separator;
7832 
7833  // literals
7834  case 't':
7835  {
7836  std::array<char_type, 4> true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}};
7837  return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
7838  }
7839  case 'f':
7840  {
7841  std::array<char_type, 5> false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}};
7842  return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
7843  }
7844  case 'n':
7845  {
7846  std::array<char_type, 4> null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}};
7847  return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
7848  }
7849 
7850  // string
7851  case '\"':
7852  return scan_string();
7853 
7854  // number
7855  case '-':
7856  case '0':
7857  case '1':
7858  case '2':
7859  case '3':
7860  case '4':
7861  case '5':
7862  case '6':
7863  case '7':
7864  case '8':
7865  case '9':
7866  return scan_number();
7867 
7868  // end of input (the null byte is needed when parsing from
7869  // string literals)
7870  case '\0':
7871  case std::char_traits<char_type>::eof():
7872  return token_type::end_of_input;
7873 
7874  // error
7875  default:
7876  error_message = "invalid literal";
7877  return token_type::parse_error;
7878  }
7879  }
7880 
7881  private:
7883  InputAdapterType ia;
7884 
7886  const bool ignore_comments = false;
7887 
7889  char_int_type current = std::char_traits<char_type>::eof();
7890 
7892  bool next_unget = false;
7893 
7896 
7898  std::vector<char_type> token_string {};
7899 
7902 
7904  const char* error_message = "";
7905 
7906  // number values
7910 
7913 };
7914 } // namespace detail
7915 } // namespace nlohmann
7916 
7917 // #include <nlohmann/detail/macro_scope.hpp>
7918 
7919 // #include <nlohmann/detail/meta/is_sax.hpp>
7920 
7921 
7922 #include <cstdint> // size_t
7923 #include <utility> // declval
7924 #include <string> // string
7925 
7926 // #include <nlohmann/detail/meta/detected.hpp>
7927 
7928 // #include <nlohmann/detail/meta/type_traits.hpp>
7929 
7930 
7931 namespace nlohmann
7932 {
7933 namespace detail
7934 {
7935 template<typename T>
7936 using null_function_t = decltype(std::declval<T&>().null());
7937 
7938 template<typename T>
7940  decltype(std::declval<T&>().boolean(std::declval<bool>()));
7941 
7942 template<typename T, typename Integer>
7944  decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
7945 
7946 template<typename T, typename Unsigned>
7948  decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
7949 
7950 template<typename T, typename Float, typename String>
7951 using number_float_function_t = decltype(std::declval<T&>().number_float(
7952  std::declval<Float>(), std::declval<const String&>()));
7953 
7954 template<typename T, typename String>
7956  decltype(std::declval<T&>().string(std::declval<String&>()));
7957 
7958 template<typename T, typename Binary>
7960  decltype(std::declval<T&>().binary(std::declval<Binary&>()));
7961 
7962 template<typename T>
7964  decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
7965 
7966 template<typename T, typename String>
7968  decltype(std::declval<T&>().key(std::declval<String&>()));
7969 
7970 template<typename T>
7971 using end_object_function_t = decltype(std::declval<T&>().end_object());
7972 
7973 template<typename T>
7975  decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
7976 
7977 template<typename T>
7978 using end_array_function_t = decltype(std::declval<T&>().end_array());
7979 
7980 template<typename T, typename Exception>
7981 using parse_error_function_t = decltype(std::declval<T&>().parse_error(
7982  std::declval<std::size_t>(), std::declval<const std::string&>(),
7983  std::declval<const Exception&>()));
7984 
7985 template<typename SAX, typename BasicJsonType>
7986 struct is_sax
7987 {
7988  private:
7990  "BasicJsonType must be of type basic_json<...>");
7991 
7992  using number_integer_t = typename BasicJsonType::number_integer_t;
7993  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
7994  using number_float_t = typename BasicJsonType::number_float_t;
7996  using binary_t = typename BasicJsonType::binary_t;
7997  using exception_t = typename BasicJsonType::exception;
7998 
7999  public:
8000  static constexpr bool value =
8014 };
8015 
8016 template<typename SAX, typename BasicJsonType>
8018 {
8019  private:
8021  "BasicJsonType must be of type basic_json<...>");
8022 
8023  using number_integer_t = typename BasicJsonType::number_integer_t;
8024  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
8025  using number_float_t = typename BasicJsonType::number_float_t;
8027  using binary_t = typename BasicJsonType::binary_t;
8028  using exception_t = typename BasicJsonType::exception;
8029 
8030  public:
8032  "Missing/invalid function: bool null()");
8034  "Missing/invalid function: bool boolean(bool)");
8036  "Missing/invalid function: bool boolean(bool)");
8037  static_assert(
8039  number_integer_t>::value,
8040  "Missing/invalid function: bool number_integer(number_integer_t)");
8041  static_assert(
8043  number_unsigned_t>::value,
8044  "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
8045  static_assert(is_detected_exact<bool, number_float_function_t, SAX,
8046  number_float_t, string_t>::value,
8047  "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
8048  static_assert(
8050  "Missing/invalid function: bool string(string_t&)");
8051  static_assert(
8053  "Missing/invalid function: bool binary(binary_t&)");
8055  "Missing/invalid function: bool start_object(std::size_t)");
8057  "Missing/invalid function: bool key(string_t&)");
8059  "Missing/invalid function: bool end_object()");
8061  "Missing/invalid function: bool start_array(std::size_t)");
8063  "Missing/invalid function: bool end_array()");
8064  static_assert(
8066  "Missing/invalid function: bool parse_error(std::size_t, const "
8067  "std::string&, const exception&)");
8068 };
8069 } // namespace detail
8070 } // namespace nlohmann
8071 
8072 // #include <nlohmann/detail/value_t.hpp>
8073 
8074 
8075 namespace nlohmann
8076 {
8077 namespace detail
8078 {
8079 
8082 {
8083  error,
8084  ignore
8085 };
8086 
8094 static inline bool little_endianess(int num = 1) noexcept
8095 {
8096  return *reinterpret_cast<char*>(&num) == 1;
8097 }
8098 
8099 
8101 // binary reader //
8103 
8107 template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>>
8109 {
8110  using number_integer_t = typename BasicJsonType::number_integer_t;
8111  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
8112  using number_float_t = typename BasicJsonType::number_float_t;
8114  using binary_t = typename BasicJsonType::binary_t;
8115  using json_sax_t = SAX;
8116  using char_type = typename InputAdapterType::char_type;
8117  using char_int_type = typename std::char_traits<char_type>::int_type;
8118 
8119  public:
8125  explicit binary_reader(InputAdapterType&& adapter) noexcept : ia(std::move(adapter))
8126  {
8128  }
8129 
8130  // make class move-only
8131  binary_reader(const binary_reader&) = delete;
8132  binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
8134  binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
8135  ~binary_reader() = default;
8136 
8147  json_sax_t* sax_,
8148  const bool strict = true,
8149  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
8150  {
8151  sax = sax_;
8152  bool result = false;
8153 
8154  switch (format)
8155  {
8156  case input_format_t::bson:
8157  result = parse_bson_internal();
8158  break;
8159 
8160  case input_format_t::cbor:
8161  result = parse_cbor_internal(true, tag_handler);
8162  break;
8163 
8165  result = parse_msgpack_internal();
8166  break;
8167 
8169  result = parse_ubjson_internal();
8170  break;
8171 
8172  default: // LCOV_EXCL_LINE
8173  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
8174  }
8175 
8176  // strict mode: next byte must be EOF
8177  if (result && strict)
8178  {
8179  if (format == input_format_t::ubjson)
8180  {
8181  get_ignore_noop();
8182  }
8183  else
8184  {
8185  get();
8186  }
8187 
8188  if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
8189  {
8190  return sax->parse_error(chars_read, get_token_string(),
8191  parse_error::create(110, chars_read, exception_message(format, "expected end of input; last byte: 0x" + get_token_string(), "value"), BasicJsonType()));
8192  }
8193  }
8194 
8195  return result;
8196  }
8197 
8198  private:
8200  // BSON //
8202 
8208  {
8209  std::int32_t document_size{};
8210  get_number<std::int32_t, true>(input_format_t::bson, document_size);
8211 
8212  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
8213  {
8214  return false;
8215  }
8216 
8217  if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/false)))
8218  {
8219  return false;
8220  }
8221 
8222  return sax->end_object();
8223  }
8224 
8232  bool get_bson_cstr(string_t& result)
8233  {
8234  auto out = std::back_inserter(result);
8235  while (true)
8236  {
8237  get();
8239  {
8240  return false;
8241  }
8242  if (current == 0x00)
8243  {
8244  return true;
8245  }
8246  *out++ = static_cast<typename string_t::value_type>(current);
8247  }
8248  }
8249 
8261  template<typename NumberType>
8262  bool get_bson_string(const NumberType len, string_t& result)
8263  {
8264  if (JSON_HEDLEY_UNLIKELY(len < 1))
8265  {
8266  auto last_token = get_token_string();
8267  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()));
8268  }
8269 
8270  return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != std::char_traits<char_type>::eof();
8271  }
8272 
8282  template<typename NumberType>
8283  bool get_bson_binary(const NumberType len, binary_t& result)
8284  {
8285  if (JSON_HEDLEY_UNLIKELY(len < 0))
8286  {
8287  auto last_token = get_token_string();
8288  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()));
8289  }
8290 
8291  // All BSON binary values have a subtype
8292  std::uint8_t subtype{};
8293  get_number<std::uint8_t>(input_format_t::bson, subtype);
8294  result.set_subtype(subtype);
8295 
8296  return get_binary(input_format_t::bson, len, result);
8297  }
8298 
8310  const std::size_t element_type_parse_position)
8311  {
8312  switch (element_type)
8313  {
8314  case 0x01: // double
8315  {
8316  double number{};
8317  return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), "");
8318  }
8319 
8320  case 0x02: // string
8321  {
8322  std::int32_t len{};
8323  string_t value;
8324  return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
8325  }
8326 
8327  case 0x03: // object
8328  {
8329  return parse_bson_internal();
8330  }
8331 
8332  case 0x04: // array
8333  {
8334  return parse_bson_array();
8335  }
8336 
8337  case 0x05: // binary
8338  {
8339  std::int32_t len{};
8340  binary_t value;
8341  return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
8342  }
8343 
8344  case 0x08: // boolean
8345  {
8346  return sax->boolean(get() != 0);
8347  }
8348 
8349  case 0x0A: // null
8350  {
8351  return sax->null();
8352  }
8353 
8354  case 0x10: // int32
8355  {
8356  std::int32_t value{};
8357  return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8358  }
8359 
8360  case 0x12: // int64
8361  {
8362  std::int64_t value{};
8363  return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8364  }
8365 
8366  default: // anything else not supported (yet)
8367  {
8368  std::array<char, 3> cr{{}};
8369  (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
8370  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()));
8371  }
8372  }
8373  }
8374 
8387  bool parse_bson_element_list(const bool is_array)
8388  {
8389  string_t key;
8390 
8391  while (auto element_type = get())
8392  {
8394  {
8395  return false;
8396  }
8397 
8398  const std::size_t element_type_parse_position = chars_read;
8400  {
8401  return false;
8402  }
8403 
8404  if (!is_array && !sax->key(key))
8405  {
8406  return false;
8407  }
8408 
8409  if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
8410  {
8411  return false;
8412  }
8413 
8414  // get_bson_cstr only appends
8415  key.clear();
8416  }
8417 
8418  return true;
8419  }
8420 
8426  {
8427  std::int32_t document_size{};
8428  get_number<std::int32_t, true>(input_format_t::bson, document_size);
8429 
8430  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
8431  {
8432  return false;
8433  }
8434 
8435  if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/true)))
8436  {
8437  return false;
8438  }
8439 
8440  return sax->end_array();
8441  }
8442 
8444  // CBOR //
8446 
8455  bool parse_cbor_internal(const bool get_char,
8456  const cbor_tag_handler_t tag_handler)
8457  {
8458  switch (get_char ? get() : current)
8459  {
8460  // EOF
8461  case std::char_traits<char_type>::eof():
8462  return unexpect_eof(input_format_t::cbor, "value");
8463 
8464  // Integer 0x00..0x17 (0..23)
8465  case 0x00:
8466  case 0x01:
8467  case 0x02:
8468  case 0x03:
8469  case 0x04:
8470  case 0x05:
8471  case 0x06:
8472  case 0x07:
8473  case 0x08:
8474  case 0x09:
8475  case 0x0A:
8476  case 0x0B:
8477  case 0x0C:
8478  case 0x0D:
8479  case 0x0E:
8480  case 0x0F:
8481  case 0x10:
8482  case 0x11:
8483  case 0x12:
8484  case 0x13:
8485  case 0x14:
8486  case 0x15:
8487  case 0x16:
8488  case 0x17:
8489  return sax->number_unsigned(static_cast<number_unsigned_t>(current));
8490 
8491  case 0x18: // Unsigned integer (one-byte uint8_t follows)
8492  {
8493  std::uint8_t number{};
8494  return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8495  }
8496 
8497  case 0x19: // Unsigned integer (two-byte uint16_t follows)
8498  {
8499  std::uint16_t number{};
8500  return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8501  }
8502 
8503  case 0x1A: // Unsigned integer (four-byte uint32_t follows)
8504  {
8505  std::uint32_t number{};
8506  return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8507  }
8508 
8509  case 0x1B: // Unsigned integer (eight-byte uint64_t follows)
8510  {
8511  std::uint64_t number{};
8512  return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8513  }
8514 
8515  // Negative integer -1-0x00..-1-0x17 (-1..-24)
8516  case 0x20:
8517  case 0x21:
8518  case 0x22:
8519  case 0x23:
8520  case 0x24:
8521  case 0x25:
8522  case 0x26:
8523  case 0x27:
8524  case 0x28:
8525  case 0x29:
8526  case 0x2A:
8527  case 0x2B:
8528  case 0x2C:
8529  case 0x2D:
8530  case 0x2E:
8531  case 0x2F:
8532  case 0x30:
8533  case 0x31:
8534  case 0x32:
8535  case 0x33:
8536  case 0x34:
8537  case 0x35:
8538  case 0x36:
8539  case 0x37:
8540  return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current));
8541 
8542  case 0x38: // Negative integer (one-byte uint8_t follows)
8543  {
8544  std::uint8_t number{};
8545  return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
8546  }
8547 
8548  case 0x39: // Negative integer -1-n (two-byte uint16_t follows)
8549  {
8550  std::uint16_t number{};
8551  return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
8552  }
8553 
8554  case 0x3A: // Negative integer -1-n (four-byte uint32_t follows)
8555  {
8556  std::uint32_t number{};
8557  return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
8558  }
8559 
8560  case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows)
8561  {
8562  std::uint64_t number{};
8563  return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1)
8564  - static_cast<number_integer_t>(number));
8565  }
8566 
8567  // Binary data (0x00..0x17 bytes follow)
8568  case 0x40:
8569  case 0x41:
8570  case 0x42:
8571  case 0x43:
8572  case 0x44:
8573  case 0x45:
8574  case 0x46:
8575  case 0x47:
8576  case 0x48:
8577  case 0x49:
8578  case 0x4A:
8579  case 0x4B:
8580  case 0x4C:
8581  case 0x4D:
8582  case 0x4E:
8583  case 0x4F:
8584  case 0x50:
8585  case 0x51:
8586  case 0x52:
8587  case 0x53:
8588  case 0x54:
8589  case 0x55:
8590  case 0x56:
8591  case 0x57:
8592  case 0x58: // Binary data (one-byte uint8_t for n follows)
8593  case 0x59: // Binary data (two-byte uint16_t for n follow)
8594  case 0x5A: // Binary data (four-byte uint32_t for n follow)
8595  case 0x5B: // Binary data (eight-byte uint64_t for n follow)
8596  case 0x5F: // Binary data (indefinite length)
8597  {
8598  binary_t b;
8599  return get_cbor_binary(b) && sax->binary(b);
8600  }
8601 
8602  // UTF-8 string (0x00..0x17 bytes follow)
8603  case 0x60:
8604  case 0x61:
8605  case 0x62:
8606  case 0x63:
8607  case 0x64:
8608  case 0x65:
8609  case 0x66:
8610  case 0x67:
8611  case 0x68:
8612  case 0x69:
8613  case 0x6A:
8614  case 0x6B:
8615  case 0x6C:
8616  case 0x6D:
8617  case 0x6E:
8618  case 0x6F:
8619  case 0x70:
8620  case 0x71:
8621  case 0x72:
8622  case 0x73:
8623  case 0x74:
8624  case 0x75:
8625  case 0x76:
8626  case 0x77:
8627  case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
8628  case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
8629  case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
8630  case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
8631  case 0x7F: // UTF-8 string (indefinite length)
8632  {
8633  string_t s;
8634  return get_cbor_string(s) && sax->string(s);
8635  }
8636 
8637  // array (0x00..0x17 data items follow)
8638  case 0x80:
8639  case 0x81:
8640  case 0x82:
8641  case 0x83:
8642  case 0x84:
8643  case 0x85:
8644  case 0x86:
8645  case 0x87:
8646  case 0x88:
8647  case 0x89:
8648  case 0x8A:
8649  case 0x8B:
8650  case 0x8C:
8651  case 0x8D:
8652  case 0x8E:
8653  case 0x8F:
8654  case 0x90:
8655  case 0x91:
8656  case 0x92:
8657  case 0x93:
8658  case 0x94:
8659  case 0x95:
8660  case 0x96:
8661  case 0x97:
8662  return get_cbor_array(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8663 
8664  case 0x98: // array (one-byte uint8_t for n follows)
8665  {
8666  std::uint8_t len{};
8667  return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
8668  }
8669 
8670  case 0x99: // array (two-byte uint16_t for n follow)
8671  {
8672  std::uint16_t len{};
8673  return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
8674  }
8675 
8676  case 0x9A: // array (four-byte uint32_t for n follow)
8677  {
8678  std::uint32_t len{};
8679  return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
8680  }
8681 
8682  case 0x9B: // array (eight-byte uint64_t for n follow)
8683  {
8684  std::uint64_t len{};
8685  return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
8686  }
8687 
8688  case 0x9F: // array (indefinite length)
8689  return get_cbor_array(std::size_t(-1), tag_handler);
8690 
8691  // map (0x00..0x17 pairs of data items follow)
8692  case 0xA0:
8693  case 0xA1:
8694  case 0xA2:
8695  case 0xA3:
8696  case 0xA4:
8697  case 0xA5:
8698  case 0xA6:
8699  case 0xA7:
8700  case 0xA8:
8701  case 0xA9:
8702  case 0xAA:
8703  case 0xAB:
8704  case 0xAC:
8705  case 0xAD:
8706  case 0xAE:
8707  case 0xAF:
8708  case 0xB0:
8709  case 0xB1:
8710  case 0xB2:
8711  case 0xB3:
8712  case 0xB4:
8713  case 0xB5:
8714  case 0xB6:
8715  case 0xB7:
8716  return get_cbor_object(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8717 
8718  case 0xB8: // map (one-byte uint8_t for n follows)
8719  {
8720  std::uint8_t len{};
8721  return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
8722  }
8723 
8724  case 0xB9: // map (two-byte uint16_t for n follow)
8725  {
8726  std::uint16_t len{};
8727  return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
8728  }
8729 
8730  case 0xBA: // map (four-byte uint32_t for n follow)
8731  {
8732  std::uint32_t len{};
8733  return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
8734  }
8735 
8736  case 0xBB: // map (eight-byte uint64_t for n follow)
8737  {
8738  std::uint64_t len{};
8739  return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
8740  }
8741 
8742  case 0xBF: // map (indefinite length)
8743  return get_cbor_object(std::size_t(-1), tag_handler);
8744 
8745  case 0xC6: // tagged item
8746  case 0xC7:
8747  case 0xC8:
8748  case 0xC9:
8749  case 0xCA:
8750  case 0xCB:
8751  case 0xCC:
8752  case 0xCD:
8753  case 0xCE:
8754  case 0xCF:
8755  case 0xD0:
8756  case 0xD1:
8757  case 0xD2:
8758  case 0xD3:
8759  case 0xD4:
8760  case 0xD8: // tagged item (1 bytes follow)
8761  case 0xD9: // tagged item (2 bytes follow)
8762  case 0xDA: // tagged item (4 bytes follow)
8763  case 0xDB: // tagged item (8 bytes follow)
8764  {
8765  switch (tag_handler)
8766  {
8768  {
8769  auto last_token = get_token_string();
8770  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()));
8771  }
8772 
8774  {
8775  switch (current)
8776  {
8777  case 0xD8:
8778  {
8779  std::uint8_t len{};
8781  break;
8782  }
8783  case 0xD9:
8784  {
8785  std::uint16_t len{};
8787  break;
8788  }
8789  case 0xDA:
8790  {
8791  std::uint32_t len{};
8793  break;
8794  }
8795  case 0xDB:
8796  {
8797  std::uint64_t len{};
8799  break;
8800  }
8801  default:
8802  break;
8803  }
8804  return parse_cbor_internal(true, tag_handler);
8805  }
8806 
8807  default: // LCOV_EXCL_LINE
8808  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
8809  return false; // LCOV_EXCL_LINE
8810  }
8811  }
8812 
8813  case 0xF4: // false
8814  return sax->boolean(false);
8815 
8816  case 0xF5: // true
8817  return sax->boolean(true);
8818 
8819  case 0xF6: // null
8820  return sax->null();
8821 
8822  case 0xF9: // Half-Precision Float (two-byte IEEE 754)
8823  {
8824  const auto byte1_raw = get();
8826  {
8827  return false;
8828  }
8829  const auto byte2_raw = get();
8831  {
8832  return false;
8833  }
8834 
8835  const auto byte1 = static_cast<unsigned char>(byte1_raw);
8836  const auto byte2 = static_cast<unsigned char>(byte2_raw);
8837 
8838  // code from RFC 7049, Appendix D, Figure 3:
8839  // As half-precision floating-point numbers were only added
8840  // to IEEE 754 in 2008, today's programming platforms often
8841  // still only have limited support for them. It is very
8842  // easy to include at least decoding support for them even
8843  // without such support. An example of a small decoder for
8844  // half-precision floating-point numbers in the C language
8845  // is shown in Fig. 3.
8846  const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2);
8847  const double val = [&half]
8848  {
8849  const int exp = (half >> 10u) & 0x1Fu;
8850  const unsigned int mant = half & 0x3FFu;
8851  JSON_ASSERT(0 <= exp&& exp <= 32);
8852  JSON_ASSERT(mant <= 1024);
8853  switch (exp)
8854  {
8855  case 0:
8856  return std::ldexp(mant, -24);
8857  case 31:
8858  return (mant == 0)
8859  ? std::numeric_limits<double>::infinity()
8860  : std::numeric_limits<double>::quiet_NaN();
8861  default:
8862  return std::ldexp(mant + 1024, exp - 25);
8863  }
8864  }();
8865  return sax->number_float((half & 0x8000u) != 0
8866  ? static_cast<number_float_t>(-val)
8867  : static_cast<number_float_t>(val), "");
8868  }
8869 
8870  case 0xFA: // Single-Precision Float (four-byte IEEE 754)
8871  {
8872  float number{};
8873  return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), "");
8874  }
8875 
8876  case 0xFB: // Double-Precision Float (eight-byte IEEE 754)
8877  {
8878  double number{};
8879  return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), "");
8880  }
8881 
8882  default: // anything else (0xFF is handled inside the other types)
8883  {
8884  auto last_token = get_token_string();
8885  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()));
8886  }
8887  }
8888  }
8889 
8902  {
8904  {
8905  return false;
8906  }
8907 
8908  switch (current)
8909  {
8910  // UTF-8 string (0x00..0x17 bytes follow)
8911  case 0x60:
8912  case 0x61:
8913  case 0x62:
8914  case 0x63:
8915  case 0x64:
8916  case 0x65:
8917  case 0x66:
8918  case 0x67:
8919  case 0x68:
8920  case 0x69:
8921  case 0x6A:
8922  case 0x6B:
8923  case 0x6C:
8924  case 0x6D:
8925  case 0x6E:
8926  case 0x6F:
8927  case 0x70:
8928  case 0x71:
8929  case 0x72:
8930  case 0x73:
8931  case 0x74:
8932  case 0x75:
8933  case 0x76:
8934  case 0x77:
8935  {
8936  return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
8937  }
8938 
8939  case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
8940  {
8941  std::uint8_t len{};
8942  return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8943  }
8944 
8945  case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
8946  {
8947  std::uint16_t len{};
8948  return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8949  }
8950 
8951  case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
8952  {
8953  std::uint32_t len{};
8954  return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8955  }
8956 
8957  case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
8958  {
8959  std::uint64_t len{};
8960  return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8961  }
8962 
8963  case 0x7F: // UTF-8 string (indefinite length)
8964  {
8965  while (get() != 0xFF)
8966  {
8967  string_t chunk;
8968  if (!get_cbor_string(chunk))
8969  {
8970  return false;
8971  }
8972  result.append(chunk);
8973  }
8974  return true;
8975  }
8976 
8977  default:
8978  {
8979  auto last_token = get_token_string();
8980  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()));
8981  }
8982  }
8983  }
8984 
8997  {
8999  {
9000  return false;
9001  }
9002 
9003  switch (current)
9004  {
9005  // Binary data (0x00..0x17 bytes follow)
9006  case 0x40:
9007  case 0x41:
9008  case 0x42:
9009  case 0x43:
9010  case 0x44:
9011  case 0x45:
9012  case 0x46:
9013  case 0x47:
9014  case 0x48:
9015  case 0x49:
9016  case 0x4A:
9017  case 0x4B:
9018  case 0x4C:
9019  case 0x4D:
9020  case 0x4E:
9021  case 0x4F:
9022  case 0x50:
9023  case 0x51:
9024  case 0x52:
9025  case 0x53:
9026  case 0x54:
9027  case 0x55:
9028  case 0x56:
9029  case 0x57:
9030  {
9031  return get_binary(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
9032  }
9033 
9034  case 0x58: // Binary data (one-byte uint8_t for n follows)
9035  {
9036  std::uint8_t len{};
9037  return get_number(input_format_t::cbor, len) &&
9038  get_binary(input_format_t::cbor, len, result);
9039  }
9040 
9041  case 0x59: // Binary data (two-byte uint16_t for n follow)
9042  {
9043  std::uint16_t len{};
9044  return get_number(input_format_t::cbor, len) &&
9045  get_binary(input_format_t::cbor, len, result);
9046  }
9047 
9048  case 0x5A: // Binary data (four-byte uint32_t for n follow)
9049  {
9050  std::uint32_t len{};
9051  return get_number(input_format_t::cbor, len) &&
9052  get_binary(input_format_t::cbor, len, result);
9053  }
9054 
9055  case 0x5B: // Binary data (eight-byte uint64_t for n follow)
9056  {
9057  std::uint64_t len{};
9058  return get_number(input_format_t::cbor, len) &&
9059  get_binary(input_format_t::cbor, len, result);
9060  }
9061 
9062  case 0x5F: // Binary data (indefinite length)
9063  {
9064  while (get() != 0xFF)
9065  {
9066  binary_t chunk;
9067  if (!get_cbor_binary(chunk))
9068  {
9069  return false;
9070  }
9071  result.insert(result.end(), chunk.begin(), chunk.end());
9072  }
9073  return true;
9074  }
9075 
9076  default:
9077  {
9078  auto last_token = get_token_string();
9079  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()));
9080  }
9081  }
9082  }
9083 
9090  bool get_cbor_array(const std::size_t len,
9091  const cbor_tag_handler_t tag_handler)
9092  {
9093  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9094  {
9095  return false;
9096  }
9097 
9098  if (len != std::size_t(-1))
9099  {
9100  for (std::size_t i = 0; i < len; ++i)
9101  {
9102  if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
9103  {
9104  return false;
9105  }
9106  }
9107  }
9108  else
9109  {
9110  while (get() != 0xFF)
9111  {
9112  if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(false, tag_handler)))
9113  {
9114  return false;
9115  }
9116  }
9117  }
9118 
9119  return sax->end_array();
9120  }
9121 
9128  bool get_cbor_object(const std::size_t len,
9129  const cbor_tag_handler_t tag_handler)
9130  {
9131  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9132  {
9133  return false;
9134  }
9135 
9136  string_t key;
9137  if (len != std::size_t(-1))
9138  {
9139  for (std::size_t i = 0; i < len; ++i)
9140  {
9141  get();
9142  if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9143  {
9144  return false;
9145  }
9146 
9147  if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
9148  {
9149  return false;
9150  }
9151  key.clear();
9152  }
9153  }
9154  else
9155  {
9156  while (get() != 0xFF)
9157  {
9158  if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9159  {
9160  return false;
9161  }
9162 
9163  if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
9164  {
9165  return false;
9166  }
9167  key.clear();
9168  }
9169  }
9170 
9171  return sax->end_object();
9172  }
9173 
9175  // MsgPack //
9177 
9182  {
9183  switch (get())
9184  {
9185  // EOF
9186  case std::char_traits<char_type>::eof():
9187  return unexpect_eof(input_format_t::msgpack, "value");
9188 
9189  // positive fixint
9190  case 0x00:
9191  case 0x01:
9192  case 0x02:
9193  case 0x03:
9194  case 0x04:
9195  case 0x05:
9196  case 0x06:
9197  case 0x07:
9198  case 0x08:
9199  case 0x09:
9200  case 0x0A:
9201  case 0x0B:
9202  case 0x0C:
9203  case 0x0D:
9204  case 0x0E:
9205  case 0x0F:
9206  case 0x10:
9207  case 0x11:
9208  case 0x12:
9209  case 0x13:
9210  case 0x14:
9211  case 0x15:
9212  case 0x16:
9213  case 0x17:
9214  case 0x18:
9215  case 0x19:
9216  case 0x1A:
9217  case 0x1B:
9218  case 0x1C:
9219  case 0x1D:
9220  case 0x1E:
9221  case 0x1F:
9222  case 0x20:
9223  case 0x21:
9224  case 0x22:
9225  case 0x23:
9226  case 0x24:
9227  case 0x25:
9228  case 0x26:
9229  case 0x27:
9230  case 0x28:
9231  case 0x29:
9232  case 0x2A:
9233  case 0x2B:
9234  case 0x2C:
9235  case 0x2D:
9236  case 0x2E:
9237  case 0x2F:
9238  case 0x30:
9239  case 0x31:
9240  case 0x32:
9241  case 0x33:
9242  case 0x34:
9243  case 0x35:
9244  case 0x36:
9245  case 0x37:
9246  case 0x38:
9247  case 0x39:
9248  case 0x3A:
9249  case 0x3B:
9250  case 0x3C:
9251  case 0x3D:
9252  case 0x3E:
9253  case 0x3F:
9254  case 0x40:
9255  case 0x41:
9256  case 0x42:
9257  case 0x43:
9258  case 0x44:
9259  case 0x45:
9260  case 0x46:
9261  case 0x47:
9262  case 0x48:
9263  case 0x49:
9264  case 0x4A:
9265  case 0x4B:
9266  case 0x4C:
9267  case 0x4D:
9268  case 0x4E:
9269  case 0x4F:
9270  case 0x50:
9271  case 0x51:
9272  case 0x52:
9273  case 0x53:
9274  case 0x54:
9275  case 0x55:
9276  case 0x56:
9277  case 0x57:
9278  case 0x58:
9279  case 0x59:
9280  case 0x5A:
9281  case 0x5B:
9282  case 0x5C:
9283  case 0x5D:
9284  case 0x5E:
9285  case 0x5F:
9286  case 0x60:
9287  case 0x61:
9288  case 0x62:
9289  case 0x63:
9290  case 0x64:
9291  case 0x65:
9292  case 0x66:
9293  case 0x67:
9294  case 0x68:
9295  case 0x69:
9296  case 0x6A:
9297  case 0x6B:
9298  case 0x6C:
9299  case 0x6D:
9300  case 0x6E:
9301  case 0x6F:
9302  case 0x70:
9303  case 0x71:
9304  case 0x72:
9305  case 0x73:
9306  case 0x74:
9307  case 0x75:
9308  case 0x76:
9309  case 0x77:
9310  case 0x78:
9311  case 0x79:
9312  case 0x7A:
9313  case 0x7B:
9314  case 0x7C:
9315  case 0x7D:
9316  case 0x7E:
9317  case 0x7F:
9318  return sax->number_unsigned(static_cast<number_unsigned_t>(current));
9319 
9320  // fixmap
9321  case 0x80:
9322  case 0x81:
9323  case 0x82:
9324  case 0x83:
9325  case 0x84:
9326  case 0x85:
9327  case 0x86:
9328  case 0x87:
9329  case 0x88:
9330  case 0x89:
9331  case 0x8A:
9332  case 0x8B:
9333  case 0x8C:
9334  case 0x8D:
9335  case 0x8E:
9336  case 0x8F:
9337  return get_msgpack_object(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
9338 
9339  // fixarray
9340  case 0x90:
9341  case 0x91:
9342  case 0x92:
9343  case 0x93:
9344  case 0x94:
9345  case 0x95:
9346  case 0x96:
9347  case 0x97:
9348  case 0x98:
9349  case 0x99:
9350  case 0x9A:
9351  case 0x9B:
9352  case 0x9C:
9353  case 0x9D:
9354  case 0x9E:
9355  case 0x9F:
9356  return get_msgpack_array(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
9357 
9358  // fixstr
9359  case 0xA0:
9360  case 0xA1:
9361  case 0xA2:
9362  case 0xA3:
9363  case 0xA4:
9364  case 0xA5:
9365  case 0xA6:
9366  case 0xA7:
9367  case 0xA8:
9368  case 0xA9:
9369  case 0xAA:
9370  case 0xAB:
9371  case 0xAC:
9372  case 0xAD:
9373  case 0xAE:
9374  case 0xAF:
9375  case 0xB0:
9376  case 0xB1:
9377  case 0xB2:
9378  case 0xB3:
9379  case 0xB4:
9380  case 0xB5:
9381  case 0xB6:
9382  case 0xB7:
9383  case 0xB8:
9384  case 0xB9:
9385  case 0xBA:
9386  case 0xBB:
9387  case 0xBC:
9388  case 0xBD:
9389  case 0xBE:
9390  case 0xBF:
9391  case 0xD9: // str 8
9392  case 0xDA: // str 16
9393  case 0xDB: // str 32
9394  {
9395  string_t s;
9396  return get_msgpack_string(s) && sax->string(s);
9397  }
9398 
9399  case 0xC0: // nil
9400  return sax->null();
9401 
9402  case 0xC2: // false
9403  return sax->boolean(false);
9404 
9405  case 0xC3: // true
9406  return sax->boolean(true);
9407 
9408  case 0xC4: // bin 8
9409  case 0xC5: // bin 16
9410  case 0xC6: // bin 32
9411  case 0xC7: // ext 8
9412  case 0xC8: // ext 16
9413  case 0xC9: // ext 32
9414  case 0xD4: // fixext 1
9415  case 0xD5: // fixext 2
9416  case 0xD6: // fixext 4
9417  case 0xD7: // fixext 8
9418  case 0xD8: // fixext 16
9419  {
9420  binary_t b;
9421  return get_msgpack_binary(b) && sax->binary(b);
9422  }
9423 
9424  case 0xCA: // float 32
9425  {
9426  float number{};
9427  return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), "");
9428  }
9429 
9430  case 0xCB: // float 64
9431  {
9432  double number{};
9433  return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), "");
9434  }
9435 
9436  case 0xCC: // uint 8
9437  {
9438  std::uint8_t number{};
9439  return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9440  }
9441 
9442  case 0xCD: // uint 16
9443  {
9444  std::uint16_t number{};
9445  return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9446  }
9447 
9448  case 0xCE: // uint 32
9449  {
9450  std::uint32_t number{};
9451  return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9452  }
9453 
9454  case 0xCF: // uint 64
9455  {
9456  std::uint64_t number{};
9457  return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9458  }
9459 
9460  case 0xD0: // int 8
9461  {
9462  std::int8_t number{};
9463  return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9464  }
9465 
9466  case 0xD1: // int 16
9467  {
9468  std::int16_t number{};
9469  return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9470  }
9471 
9472  case 0xD2: // int 32
9473  {
9474  std::int32_t number{};
9475  return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9476  }
9477 
9478  case 0xD3: // int 64
9479  {
9480  std::int64_t number{};
9481  return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9482  }
9483 
9484  case 0xDC: // array 16
9485  {
9486  std::uint16_t len{};
9487  return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len));
9488  }
9489 
9490  case 0xDD: // array 32
9491  {
9492  std::uint32_t len{};
9493  return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len));
9494  }
9495 
9496  case 0xDE: // map 16
9497  {
9498  std::uint16_t len{};
9499  return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len));
9500  }
9501 
9502  case 0xDF: // map 32
9503  {
9504  std::uint32_t len{};
9505  return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len));
9506  }
9507 
9508  // negative fixint
9509  case 0xE0:
9510  case 0xE1:
9511  case 0xE2:
9512  case 0xE3:
9513  case 0xE4:
9514  case 0xE5:
9515  case 0xE6:
9516  case 0xE7:
9517  case 0xE8:
9518  case 0xE9:
9519  case 0xEA:
9520  case 0xEB:
9521  case 0xEC:
9522  case 0xED:
9523  case 0xEE:
9524  case 0xEF:
9525  case 0xF0:
9526  case 0xF1:
9527  case 0xF2:
9528  case 0xF3:
9529  case 0xF4:
9530  case 0xF5:
9531  case 0xF6:
9532  case 0xF7:
9533  case 0xF8:
9534  case 0xF9:
9535  case 0xFA:
9536  case 0xFB:
9537  case 0xFC:
9538  case 0xFD:
9539  case 0xFE:
9540  case 0xFF:
9541  return sax->number_integer(static_cast<std::int8_t>(current));
9542 
9543  default: // anything else
9544  {
9545  auto last_token = get_token_string();
9546  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()));
9547  }
9548  }
9549  }
9550 
9562  {
9564  {
9565  return false;
9566  }
9567 
9568  switch (current)
9569  {
9570  // fixstr
9571  case 0xA0:
9572  case 0xA1:
9573  case 0xA2:
9574  case 0xA3:
9575  case 0xA4:
9576  case 0xA5:
9577  case 0xA6:
9578  case 0xA7:
9579  case 0xA8:
9580  case 0xA9:
9581  case 0xAA:
9582  case 0xAB:
9583  case 0xAC:
9584  case 0xAD:
9585  case 0xAE:
9586  case 0xAF:
9587  case 0xB0:
9588  case 0xB1:
9589  case 0xB2:
9590  case 0xB3:
9591  case 0xB4:
9592  case 0xB5:
9593  case 0xB6:
9594  case 0xB7:
9595  case 0xB8:
9596  case 0xB9:
9597  case 0xBA:
9598  case 0xBB:
9599  case 0xBC:
9600  case 0xBD:
9601  case 0xBE:
9602  case 0xBF:
9603  {
9604  return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result);
9605  }
9606 
9607  case 0xD9: // str 8
9608  {
9609  std::uint8_t len{};
9611  }
9612 
9613  case 0xDA: // str 16
9614  {
9615  std::uint16_t len{};
9617  }
9618 
9619  case 0xDB: // str 32
9620  {
9621  std::uint32_t len{};
9623  }
9624 
9625  default:
9626  {
9627  auto last_token = get_token_string();
9628  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()));
9629  }
9630  }
9631  }
9632 
9644  {
9645  // helper function to set the subtype
9646  auto assign_and_return_true = [&result](std::int8_t subtype)
9647  {
9648  result.set_subtype(static_cast<std::uint8_t>(subtype));
9649  return true;
9650  };
9651 
9652  switch (current)
9653  {
9654  case 0xC4: // bin 8
9655  {
9656  std::uint8_t len{};
9657  return get_number(input_format_t::msgpack, len) &&
9658  get_binary(input_format_t::msgpack, len, result);
9659  }
9660 
9661  case 0xC5: // bin 16
9662  {
9663  std::uint16_t len{};
9664  return get_number(input_format_t::msgpack, len) &&
9665  get_binary(input_format_t::msgpack, len, result);
9666  }
9667 
9668  case 0xC6: // bin 32
9669  {
9670  std::uint32_t len{};
9671  return get_number(input_format_t::msgpack, len) &&
9672  get_binary(input_format_t::msgpack, len, result);
9673  }
9674 
9675  case 0xC7: // ext 8
9676  {
9677  std::uint8_t len{};
9678  std::int8_t subtype{};
9679  return get_number(input_format_t::msgpack, len) &&
9680  get_number(input_format_t::msgpack, subtype) &&
9681  get_binary(input_format_t::msgpack, len, result) &&
9682  assign_and_return_true(subtype);
9683  }
9684 
9685  case 0xC8: // ext 16
9686  {
9687  std::uint16_t len{};
9688  std::int8_t subtype{};
9689  return get_number(input_format_t::msgpack, len) &&
9690  get_number(input_format_t::msgpack, subtype) &&
9691  get_binary(input_format_t::msgpack, len, result) &&
9692  assign_and_return_true(subtype);
9693  }
9694 
9695  case 0xC9: // ext 32
9696  {
9697  std::uint32_t len{};
9698  std::int8_t subtype{};
9699  return get_number(input_format_t::msgpack, len) &&
9700  get_number(input_format_t::msgpack, subtype) &&
9701  get_binary(input_format_t::msgpack, len, result) &&
9702  assign_and_return_true(subtype);
9703  }
9704 
9705  case 0xD4: // fixext 1
9706  {
9707  std::int8_t subtype{};
9708  return get_number(input_format_t::msgpack, subtype) &&
9709  get_binary(input_format_t::msgpack, 1, result) &&
9710  assign_and_return_true(subtype);
9711  }
9712 
9713  case 0xD5: // fixext 2
9714  {
9715  std::int8_t subtype{};
9716  return get_number(input_format_t::msgpack, subtype) &&
9717  get_binary(input_format_t::msgpack, 2, result) &&
9718  assign_and_return_true(subtype);
9719  }
9720 
9721  case 0xD6: // fixext 4
9722  {
9723  std::int8_t subtype{};
9724  return get_number(input_format_t::msgpack, subtype) &&
9725  get_binary(input_format_t::msgpack, 4, result) &&
9726  assign_and_return_true(subtype);
9727  }
9728 
9729  case 0xD7: // fixext 8
9730  {
9731  std::int8_t subtype{};
9732  return get_number(input_format_t::msgpack, subtype) &&
9733  get_binary(input_format_t::msgpack, 8, result) &&
9734  assign_and_return_true(subtype);
9735  }
9736 
9737  case 0xD8: // fixext 16
9738  {
9739  std::int8_t subtype{};
9740  return get_number(input_format_t::msgpack, subtype) &&
9741  get_binary(input_format_t::msgpack, 16, result) &&
9742  assign_and_return_true(subtype);
9743  }
9744 
9745  default: // LCOV_EXCL_LINE
9746  return false; // LCOV_EXCL_LINE
9747  }
9748  }
9749 
9754  bool get_msgpack_array(const std::size_t len)
9755  {
9756  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9757  {
9758  return false;
9759  }
9760 
9761  for (std::size_t i = 0; i < len; ++i)
9762  {
9764  {
9765  return false;
9766  }
9767  }
9768 
9769  return sax->end_array();
9770  }
9771 
9776  bool get_msgpack_object(const std::size_t len)
9777  {
9778  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9779  {
9780  return false;
9781  }
9782 
9783  string_t key;
9784  for (std::size_t i = 0; i < len; ++i)
9785  {
9786  get();
9787  if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
9788  {
9789  return false;
9790  }
9791 
9793  {
9794  return false;
9795  }
9796  key.clear();
9797  }
9798 
9799  return sax->end_object();
9800  }
9801 
9803  // UBJSON //
9805 
9813  bool parse_ubjson_internal(const bool get_char = true)
9814  {
9815  return get_ubjson_value(get_char ? get_ignore_noop() : current);
9816  }
9817 
9832  bool get_ubjson_string(string_t& result, const bool get_char = true)
9833  {
9834  if (get_char)
9835  {
9836  get(); // TODO(niels): may we ignore N here?
9837  }
9838 
9840  {
9841  return false;
9842  }
9843 
9844  switch (current)
9845  {
9846  case 'U':
9847  {
9848  std::uint8_t len{};
9850  }
9851 
9852  case 'i':
9853  {
9854  std::int8_t len{};
9856  }
9857 
9858  case 'I':
9859  {
9860  std::int16_t len{};
9862  }
9863 
9864  case 'l':
9865  {
9866  std::int32_t len{};
9868  }
9869 
9870  case 'L':
9871  {
9872  std::int64_t len{};
9874  }
9875 
9876  default:
9877  auto last_token = get_token_string();
9878  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()));
9879  }
9880  }
9881 
9886  bool get_ubjson_size_value(std::size_t& result)
9887  {
9888  switch (get_ignore_noop())
9889  {
9890  case 'U':
9891  {
9892  std::uint8_t number{};
9894  {
9895  return false;
9896  }
9897  result = static_cast<std::size_t>(number);
9898  return true;
9899  }
9900 
9901  case 'i':
9902  {
9903  std::int8_t number{};
9905  {
9906  return false;
9907  }
9908  result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char
9909  return true;
9910  }
9911 
9912  case 'I':
9913  {
9914  std::int16_t number{};
9916  {
9917  return false;
9918  }
9919  result = static_cast<std::size_t>(number);
9920  return true;
9921  }
9922 
9923  case 'l':
9924  {
9925  std::int32_t number{};
9927  {
9928  return false;
9929  }
9930  result = static_cast<std::size_t>(number);
9931  return true;
9932  }
9933 
9934  case 'L':
9935  {
9936  std::int64_t number{};
9938  {
9939  return false;
9940  }
9941  result = static_cast<std::size_t>(number);
9942  return true;
9943  }
9944 
9945  default:
9946  {
9947  auto last_token = get_token_string();
9948  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()));
9949  }
9950  }
9951  }
9952 
9963  bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result)
9964  {
9965  result.first = string_t::npos; // size
9966  result.second = 0; // type
9967 
9968  get_ignore_noop();
9969 
9970  if (current == '$')
9971  {
9972  result.second = get(); // must not ignore 'N', because 'N' maybe the type
9974  {
9975  return false;
9976  }
9977 
9978  get_ignore_noop();
9979  if (JSON_HEDLEY_UNLIKELY(current != '#'))
9980  {
9982  {
9983  return false;
9984  }
9985  auto last_token = get_token_string();
9986  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()));
9987  }
9988 
9989  return get_ubjson_size_value(result.first);
9990  }
9991 
9992  if (current == '#')
9993  {
9994  return get_ubjson_size_value(result.first);
9995  }
9996 
9997  return true;
9998  }
9999 
10004  bool get_ubjson_value(const char_int_type prefix)
10005  {
10006  switch (prefix)
10007  {
10008  case std::char_traits<char_type>::eof(): // EOF
10009  return unexpect_eof(input_format_t::ubjson, "value");
10010 
10011  case 'T': // true
10012  return sax->boolean(true);
10013  case 'F': // false
10014  return sax->boolean(false);
10015 
10016  case 'Z': // null
10017  return sax->null();
10018 
10019  case 'U':
10020  {
10021  std::uint8_t number{};
10022  return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number);
10023  }
10024 
10025  case 'i':
10026  {
10027  std::int8_t number{};
10028  return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10029  }
10030 
10031  case 'I':
10032  {
10033  std::int16_t number{};
10034  return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10035  }
10036 
10037  case 'l':
10038  {
10039  std::int32_t number{};
10040  return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10041  }
10042 
10043  case 'L':
10044  {
10045  std::int64_t number{};
10046  return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10047  }
10048 
10049  case 'd':
10050  {
10051  float number{};
10052  return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast<number_float_t>(number), "");
10053  }
10054 
10055  case 'D':
10056  {
10057  double number{};
10058  return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast<number_float_t>(number), "");
10059  }
10060 
10061  case 'H':
10062  {
10064  }
10065 
10066  case 'C': // char
10067  {
10068  get();
10070  {
10071  return false;
10072  }
10073  if (JSON_HEDLEY_UNLIKELY(current > 127))
10074  {
10075  auto last_token = get_token_string();
10076  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()));
10077  }
10078  string_t s(1, static_cast<typename string_t::value_type>(current));
10079  return sax->string(s);
10080  }
10081 
10082  case 'S': // string
10083  {
10084  string_t s;
10085  return get_ubjson_string(s) && sax->string(s);
10086  }
10087 
10088  case '[': // array
10089  return get_ubjson_array();
10090 
10091  case '{': // object
10092  return get_ubjson_object();
10093 
10094  default: // anything else
10095  {
10096  auto last_token = get_token_string();
10097  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()));
10098  }
10099  }
10100  }
10101 
10106  {
10107  std::pair<std::size_t, char_int_type> size_and_type;
10108  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10109  {
10110  return false;
10111  }
10112 
10113  if (size_and_type.first != string_t::npos)
10114  {
10115  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
10116  {
10117  return false;
10118  }
10119 
10120  if (size_and_type.second != 0)
10121  {
10122  if (size_and_type.second != 'N')
10123  {
10124  for (std::size_t i = 0; i < size_and_type.first; ++i)
10125  {
10126  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10127  {
10128  return false;
10129  }
10130  }
10131  }
10132  }
10133  else
10134  {
10135  for (std::size_t i = 0; i < size_and_type.first; ++i)
10136  {
10138  {
10139  return false;
10140  }
10141  }
10142  }
10143  }
10144  else
10145  {
10146  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10147  {
10148  return false;
10149  }
10150 
10151  while (current != ']')
10152  {
10154  {
10155  return false;
10156  }
10157  get_ignore_noop();
10158  }
10159  }
10160 
10161  return sax->end_array();
10162  }
10163 
10168  {
10169  std::pair<std::size_t, char_int_type> size_and_type;
10170  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10171  {
10172  return false;
10173  }
10174 
10175  string_t key;
10176  if (size_and_type.first != string_t::npos)
10177  {
10178  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
10179  {
10180  return false;
10181  }
10182 
10183  if (size_and_type.second != 0)
10184  {
10185  for (std::size_t i = 0; i < size_and_type.first; ++i)
10186  {
10187  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10188  {
10189  return false;
10190  }
10191  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10192  {
10193  return false;
10194  }
10195  key.clear();
10196  }
10197  }
10198  else
10199  {
10200  for (std::size_t i = 0; i < size_and_type.first; ++i)
10201  {
10202  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10203  {
10204  return false;
10205  }
10207  {
10208  return false;
10209  }
10210  key.clear();
10211  }
10212  }
10213  }
10214  else
10215  {
10216  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10217  {
10218  return false;
10219  }
10220 
10221  while (current != '}')
10222  {
10223  if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key, false) || !sax->key(key)))
10224  {
10225  return false;
10226  }
10228  {
10229  return false;
10230  }
10231  get_ignore_noop();
10232  key.clear();
10233  }
10234  }
10235 
10236  return sax->end_object();
10237  }
10238 
10239  // Note, no reader for UBJSON binary types is implemented because they do
10240  // not exist
10241 
10243  {
10244  // get size of following number string
10245  std::size_t size{};
10246  auto res = get_ubjson_size_value(size);
10247  if (JSON_HEDLEY_UNLIKELY(!res))
10248  {
10249  return res;
10250  }
10251 
10252  // get number string
10253  std::vector<char> number_vector;
10254  for (std::size_t i = 0; i < size; ++i)
10255  {
10256  get();
10258  {
10259  return false;
10260  }
10261  number_vector.push_back(static_cast<char>(current));
10262  }
10263 
10264  // parse number string
10265  using ia_type = decltype(detail::input_adapter(number_vector));
10266  auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector), false);
10267  const auto result_number = number_lexer.scan();
10268  const auto number_string = number_lexer.get_token_string();
10269  const auto result_remainder = number_lexer.scan();
10270 
10271  using token_type = typename detail::lexer_base<BasicJsonType>::token_type;
10272 
10273  if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
10274  {
10275  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()));
10276  }
10277 
10278  switch (result_number)
10279  {
10280  case token_type::value_integer:
10281  return sax->number_integer(number_lexer.get_number_integer());
10282  case token_type::value_unsigned:
10283  return sax->number_unsigned(number_lexer.get_number_unsigned());
10284  case token_type::value_float:
10285  return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
10286  default:
10287  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()));
10288  }
10289  }
10290 
10292  // Utility functions //
10294 
10305  {
10306  ++chars_read;
10307  return current = ia.get_character();
10308  }
10309 
10314  {
10315  do
10316  {
10317  get();
10318  }
10319  while (current == 'N');
10320 
10321  return current;
10322  }
10323 
10324  /*
10325  @brief read a number from the input
10326 
10327  @tparam NumberType the type of the number
10328  @param[in] format the current format (for diagnostics)
10329  @param[out] result number of type @a NumberType
10330 
10331  @return whether conversion completed
10332 
10333  @note This function needs to respect the system's endianess, because
10334  bytes in CBOR, MessagePack, and UBJSON are stored in network order
10335  (big endian) and therefore need reordering on little endian systems.
10336  */
10337  template<typename NumberType, bool InputIsLittleEndian = false>
10338  bool get_number(const input_format_t format, NumberType& result)
10339  {
10340  // step 1: read input into array with system's byte order
10341  std::array<std::uint8_t, sizeof(NumberType)> vec{};
10342  for (std::size_t i = 0; i < sizeof(NumberType); ++i)
10343  {
10344  get();
10345  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number")))
10346  {
10347  return false;
10348  }
10349 
10350  // reverse byte order prior to conversion if necessary
10351  if (is_little_endian != InputIsLittleEndian)
10352  {
10353  vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);
10354  }
10355  else
10356  {
10357  vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE
10358  }
10359  }
10360 
10361  // step 2: convert array into number of type T and return
10362  std::memcpy(&result, vec.data(), sizeof(NumberType));
10363  return true;
10364  }
10365 
10380  template<typename NumberType>
10381  bool get_string(const input_format_t format,
10382  const NumberType len,
10383  string_t& result)
10384  {
10385  bool success = true;
10386  for (NumberType i = 0; i < len; i++)
10387  {
10388  get();
10389  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "string")))
10390  {
10391  success = false;
10392  break;
10393  }
10394  result.push_back(static_cast<typename string_t::value_type>(current));
10395  }
10396  return success;
10397  }
10398 
10413  template<typename NumberType>
10414  bool get_binary(const input_format_t format,
10415  const NumberType len,
10416  binary_t& result)
10417  {
10418  bool success = true;
10419  for (NumberType i = 0; i < len; i++)
10420  {
10421  get();
10422  if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "binary")))
10423  {
10424  success = false;
10425  break;
10426  }
10427  result.push_back(static_cast<std::uint8_t>(current));
10428  }
10429  return success;
10430  }
10431 
10438  bool unexpect_eof(const input_format_t format, const char* context) const
10439  {
10440  if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
10441  {
10442  return sax->parse_error(chars_read, "<end of file>",
10443  parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), BasicJsonType()));
10444  }
10445  return true;
10446  }
10447 
10451  std::string get_token_string() const
10452  {
10453  std::array<char, 3> cr{{}};
10454  (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
10455  return std::string{cr.data()};
10456  }
10457 
10464  std::string exception_message(const input_format_t format,
10465  const std::string& detail,
10466  const std::string& context) const
10467  {
10468  std::string error_msg = "syntax error while parsing ";
10469 
10470  switch (format)
10471  {
10472  case input_format_t::cbor:
10473  error_msg += "CBOR";
10474  break;
10475 
10477  error_msg += "MessagePack";
10478  break;
10479 
10481  error_msg += "UBJSON";
10482  break;
10483 
10484  case input_format_t::bson:
10485  error_msg += "BSON";
10486  break;
10487 
10488  default: // LCOV_EXCL_LINE
10489  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
10490  }
10491 
10492  return error_msg + " " + context + ": " + detail;
10493  }
10494 
10495  private:
10497  InputAdapterType ia;
10498 
10500  char_int_type current = std::char_traits<char_type>::eof();
10501 
10503  std::size_t chars_read = 0;
10504 
10507 
10509  json_sax_t* sax = nullptr;
10510 };
10511 } // namespace detail
10512 } // namespace nlohmann
10513 
10514 // #include <nlohmann/detail/input/input_adapters.hpp>
10515 
10516 // #include <nlohmann/detail/input/lexer.hpp>
10517 
10518 // #include <nlohmann/detail/input/parser.hpp>
10519 
10520 
10521 #include <cmath> // isfinite
10522 #include <cstdint> // uint8_t
10523 #include <functional> // function
10524 #include <string> // string
10525 #include <utility> // move
10526 #include <vector> // vector
10527 
10528 // #include <nlohmann/detail/exceptions.hpp>
10529 
10530 // #include <nlohmann/detail/input/input_adapters.hpp>
10531 
10532 // #include <nlohmann/detail/input/json_sax.hpp>
10533 
10534 // #include <nlohmann/detail/input/lexer.hpp>
10535 
10536 // #include <nlohmann/detail/macro_scope.hpp>
10537 
10538 // #include <nlohmann/detail/meta/is_sax.hpp>
10539 
10540 // #include <nlohmann/detail/value_t.hpp>
10541 
10542 
10543 namespace nlohmann
10544 {
10545 namespace detail
10546 {
10548 // parser //
10550 
10552 {
10554  object_start,
10556  object_end,
10558  array_start,
10560  array_end,
10562  key,
10564  value
10565 };
10566 
10567 template<typename BasicJsonType>
10569  std::function<bool(int /*depth*/, parse_event_t /*event*/, BasicJsonType& /*parsed*/)>;
10570 
10576 template<typename BasicJsonType, typename InputAdapterType>
10577 class parser
10578 {
10579  using number_integer_t = typename BasicJsonType::number_integer_t;
10580  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
10581  using number_float_t = typename BasicJsonType::number_float_t;
10585 
10586  public:
10588  explicit parser(InputAdapterType&& adapter,
10589  const parser_callback_t<BasicJsonType> cb = nullptr,
10590  const bool allow_exceptions_ = true,
10591  const bool skip_comments = false)
10592  : callback(cb)
10593  , m_lexer(std::move(adapter), skip_comments)
10594  , allow_exceptions(allow_exceptions_)
10595  {
10596  // read first token
10597  get_token();
10598  }
10599 
10610  void parse(const bool strict, BasicJsonType& result)
10611  {
10612  if (callback)
10613  {
10615  sax_parse_internal(&sdp);
10616 
10617  // in strict mode, input must be completely read
10618  if (strict && (get_token() != token_type::end_of_input))
10619  {
10623  exception_message(token_type::end_of_input, "value"), BasicJsonType()));
10624  }
10625 
10626  // in case of an error, return discarded value
10627  if (sdp.is_errored())
10628  {
10629  result = value_t::discarded;
10630  return;
10631  }
10632 
10633  // set top-level value to null if it was discarded by the callback
10634  // function
10635  if (result.is_discarded())
10636  {
10637  result = nullptr;
10638  }
10639  }
10640  else
10641  {
10643  sax_parse_internal(&sdp);
10644 
10645  // in strict mode, input must be completely read
10646  if (strict && (get_token() != token_type::end_of_input))
10647  {
10650  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
10651  }
10652 
10653  // in case of an error, return discarded value
10654  if (sdp.is_errored())
10655  {
10656  result = value_t::discarded;
10657  return;
10658  }
10659  }
10660 
10661  result.assert_invariant();
10662  }
10663 
10670  bool accept(const bool strict = true)
10671  {
10672  json_sax_acceptor<BasicJsonType> sax_acceptor;
10673  return sax_parse(&sax_acceptor, strict);
10674  }
10675 
10676  template<typename SAX>
10678  bool sax_parse(SAX* sax, const bool strict = true)
10679  {
10681  const bool result = sax_parse_internal(sax);
10682 
10683  // strict mode: next byte must be EOF
10684  if (result && strict && (get_token() != token_type::end_of_input))
10685  {
10686  return sax->parse_error(m_lexer.get_position(),
10688  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
10689  }
10690 
10691  return result;
10692  }
10693 
10694  private:
10695  template<typename SAX>
10697  bool sax_parse_internal(SAX* sax)
10698  {
10699  // stack to remember the hierarchy of structured values we are parsing
10700  // true = array; false = object
10701  std::vector<bool> states;
10702  // value to avoid a goto (see comment where set to true)
10703  bool skip_to_state_evaluation = false;
10704 
10705  while (true)
10706  {
10707  if (!skip_to_state_evaluation)
10708  {
10709  // invariant: get_token() was called before each iteration
10710  switch (last_token)
10711  {
10712  case token_type::begin_object:
10713  {
10714  if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10715  {
10716  return false;
10717  }
10718 
10719  // closing } -> we are done
10720  if (get_token() == token_type::end_object)
10721  {
10722  if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
10723  {
10724  return false;
10725  }
10726  break;
10727  }
10728 
10729  // parse key
10730  if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
10731  {
10732  return sax->parse_error(m_lexer.get_position(),
10734  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
10735  }
10736  if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
10737  {
10738  return false;
10739  }
10740 
10741  // parse separator (:)
10742  if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
10743  {
10744  return sax->parse_error(m_lexer.get_position(),
10746  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
10747  }
10748 
10749  // remember we are now inside an object
10750  states.push_back(false);
10751 
10752  // parse values
10753  get_token();
10754  continue;
10755  }
10756 
10757  case token_type::begin_array:
10758  {
10759  if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10760  {
10761  return false;
10762  }
10763 
10764  // closing ] -> we are done
10765  if (get_token() == token_type::end_array)
10766  {
10767  if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
10768  {
10769  return false;
10770  }
10771  break;
10772  }
10773 
10774  // remember we are now inside an array
10775  states.push_back(true);
10776 
10777  // parse values (no need to call get_token)
10778  continue;
10779  }
10780 
10781  case token_type::value_float:
10782  {
10783  const auto res = m_lexer.get_number_float();
10784 
10785  if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
10786  {
10787  return sax->parse_error(m_lexer.get_position(),
10789  out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'", BasicJsonType()));
10790  }
10791 
10792  if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
10793  {
10794  return false;
10795  }
10796 
10797  break;
10798  }
10799 
10800  case token_type::literal_false:
10801  {
10802  if (JSON_HEDLEY_UNLIKELY(!sax->boolean(false)))
10803  {
10804  return false;
10805  }
10806  break;
10807  }
10808 
10809  case token_type::literal_null:
10810  {
10811  if (JSON_HEDLEY_UNLIKELY(!sax->null()))
10812  {
10813  return false;
10814  }
10815  break;
10816  }
10817 
10818  case token_type::literal_true:
10819  {
10820  if (JSON_HEDLEY_UNLIKELY(!sax->boolean(true)))
10821  {
10822  return false;
10823  }
10824  break;
10825  }
10826 
10827  case token_type::value_integer:
10828  {
10829  if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
10830  {
10831  return false;
10832  }
10833  break;
10834  }
10835 
10836  case token_type::value_string:
10837  {
10838  if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
10839  {
10840  return false;
10841  }
10842  break;
10843  }
10844 
10845  case token_type::value_unsigned:
10846  {
10847  if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
10848  {
10849  return false;
10850  }
10851  break;
10852  }
10853 
10854  case token_type::parse_error:
10855  {
10856  // using "uninitialized" to avoid "expected" message
10857  return sax->parse_error(m_lexer.get_position(),
10859  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), BasicJsonType()));
10860  }
10861 
10862  default: // the last token was unexpected
10863  {
10864  return sax->parse_error(m_lexer.get_position(),
10866  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), BasicJsonType()));
10867  }
10868  }
10869  }
10870  else
10871  {
10872  skip_to_state_evaluation = false;
10873  }
10874 
10875  // we reached this line after we successfully parsed a value
10876  if (states.empty())
10877  {
10878  // empty stack: we reached the end of the hierarchy: done
10879  return true;
10880  }
10881 
10882  if (states.back()) // array
10883  {
10884  // comma -> next value
10885  if (get_token() == token_type::value_separator)
10886  {
10887  // parse a new value
10888  get_token();
10889  continue;
10890  }
10891 
10892  // closing ]
10893  if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
10894  {
10895  if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
10896  {
10897  return false;
10898  }
10899 
10900  // We are done with this array. Before we can parse a
10901  // new value, we need to evaluate the new state first.
10902  // By setting skip_to_state_evaluation to false, we
10903  // are effectively jumping to the beginning of this if.
10904  JSON_ASSERT(!states.empty());
10905  states.pop_back();
10906  skip_to_state_evaluation = true;
10907  continue;
10908  }
10909 
10910  return sax->parse_error(m_lexer.get_position(),
10912  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, "array"), BasicJsonType()));
10913  }
10914 
10915  // states.back() is false -> object
10916 
10917  // comma -> next value
10918  if (get_token() == token_type::value_separator)
10919  {
10920  // parse key
10921  if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
10922  {
10923  return sax->parse_error(m_lexer.get_position(),
10925  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
10926  }
10927 
10928  if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
10929  {
10930  return false;
10931  }
10932 
10933  // parse separator (:)
10934  if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
10935  {
10936  return sax->parse_error(m_lexer.get_position(),
10938  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
10939  }
10940 
10941  // parse values
10942  get_token();
10943  continue;
10944  }
10945 
10946  // closing }
10947  if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
10948  {
10949  if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
10950  {
10951  return false;
10952  }
10953 
10954  // We are done with this object. Before we can parse a
10955  // new value, we need to evaluate the new state first.
10956  // By setting skip_to_state_evaluation to false, we
10957  // are effectively jumping to the beginning of this if.
10958  JSON_ASSERT(!states.empty());
10959  states.pop_back();
10960  skip_to_state_evaluation = true;
10961  continue;
10962  }
10963 
10964  return sax->parse_error(m_lexer.get_position(),
10966  parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, "object"), BasicJsonType()));
10967  }
10968  }
10969 
10972  {
10973  return last_token = m_lexer.scan();
10974  }
10975 
10976  std::string exception_message(const token_type expected, const std::string& context)
10977  {
10978  std::string error_msg = "syntax error ";
10979 
10980  if (!context.empty())
10981  {
10982  error_msg += "while parsing " + context + " ";
10983  }
10984 
10985  error_msg += "- ";
10986 
10987  if (last_token == token_type::parse_error)
10988  {
10989  error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" +
10990  m_lexer.get_token_string() + "'";
10991  }
10992  else
10993  {
10994  error_msg += "unexpected " + std::string(lexer_t::token_type_name(last_token));
10995  }
10996 
10997  if (expected != token_type::uninitialized)
10998  {
10999  error_msg += "; expected " + std::string(lexer_t::token_type_name(expected));
11000  }
11001 
11002  return error_msg;
11003  }
11004 
11005  private:
11009  token_type last_token = token_type::uninitialized;
11013  const bool allow_exceptions = true;
11014 };
11015 
11016 } // namespace detail
11017 } // namespace nlohmann
11018 
11019 // #include <nlohmann/detail/iterators/internal_iterator.hpp>
11020 
11021 
11022 // #include <nlohmann/detail/iterators/primitive_iterator.hpp>
11023 
11024 
11025 #include <cstddef> // ptrdiff_t
11026 #include <limits> // numeric_limits
11027 
11028 // #include <nlohmann/detail/macro_scope.hpp>
11029 
11030 
11031 namespace nlohmann
11032 {
11033 namespace detail
11034 {
11035 /*
11036 @brief an iterator for primitive JSON types
11037 
11038 This class models an iterator for primitive JSON types (boolean, number,
11039 string). It's only purpose is to allow the iterator/const_iterator classes
11040 to "iterate" over primitive values. Internally, the iterator is modeled by
11041 a `difference_type` variable. Value begin_value (`0`) models the begin,
11042 end_value (`1`) models past the end.
11043 */
11045 {
11046  private:
11047  using difference_type = std::ptrdiff_t;
11048  static constexpr difference_type begin_value = 0;
11049  static constexpr difference_type end_value = begin_value + 1;
11050 
11053  difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
11054 
11055  public:
11056  constexpr difference_type get_value() const noexcept
11057  {
11058  return m_it;
11059  }
11060 
11062  void set_begin() noexcept
11063  {
11064  m_it = begin_value;
11065  }
11066 
11068  void set_end() noexcept
11069  {
11070  m_it = end_value;
11071  }
11072 
11074  constexpr bool is_begin() const noexcept
11075  {
11076  return m_it == begin_value;
11077  }
11078 
11080  constexpr bool is_end() const noexcept
11081  {
11082  return m_it == end_value;
11083  }
11084 
11085  friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11086  {
11087  return lhs.m_it == rhs.m_it;
11088  }
11089 
11090  friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11091  {
11092  return lhs.m_it < rhs.m_it;
11093  }
11094 
11096  {
11097  auto result = *this;
11098  result += n;
11099  return result;
11100  }
11101 
11103  {
11104  return lhs.m_it - rhs.m_it;
11105  }
11106 
11108  {
11109  ++m_it;
11110  return *this;
11111  }
11112 
11113  primitive_iterator_t const operator++(int) noexcept // NOLINT(readability-const-return-type)
11114  {
11115  auto result = *this;
11116  ++m_it;
11117  return result;
11118  }
11119 
11121  {
11122  --m_it;
11123  return *this;
11124  }
11125 
11126  primitive_iterator_t const operator--(int) noexcept // NOLINT(readability-const-return-type)
11127  {
11128  auto result = *this;
11129  --m_it;
11130  return result;
11131  }
11132 
11134  {
11135  m_it += n;
11136  return *this;
11137  }
11138 
11140  {
11141  m_it -= n;
11142  return *this;
11143  }
11144 };
11145 } // namespace detail
11146 } // namespace nlohmann
11147 
11148 
11149 namespace nlohmann
11150 {
11151 namespace detail
11152 {
11159 template<typename BasicJsonType> struct internal_iterator
11160 {
11162  typename BasicJsonType::object_t::iterator object_iterator {};
11164  typename BasicJsonType::array_t::iterator array_iterator {};
11167 };
11168 } // namespace detail
11169 } // namespace nlohmann
11170 
11171 // #include <nlohmann/detail/iterators/iter_impl.hpp>
11172 
11173 
11174 #include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next
11175 #include <type_traits> // conditional, is_const, remove_const
11176 
11177 // #include <nlohmann/detail/exceptions.hpp>
11178 
11179 // #include <nlohmann/detail/iterators/internal_iterator.hpp>
11180 
11181 // #include <nlohmann/detail/iterators/primitive_iterator.hpp>
11182 
11183 // #include <nlohmann/detail/macro_scope.hpp>
11184 
11185 // #include <nlohmann/detail/meta/cpp_future.hpp>
11186 
11187 // #include <nlohmann/detail/meta/type_traits.hpp>
11188 
11189 // #include <nlohmann/detail/value_t.hpp>
11190 
11191 
11192 namespace nlohmann
11193 {
11194 namespace detail
11195 {
11196 // forward declare, to be able to friend it later on
11197 template<typename IteratorType> class iteration_proxy;
11198 template<typename IteratorType> class iteration_proxy_value;
11199 
11216 template<typename BasicJsonType>
11218 {
11226 
11227  using object_t = typename BasicJsonType::object_t;
11228  using array_t = typename BasicJsonType::array_t;
11229  // make sure BasicJsonType is basic_json or const basic_json
11231  "iter_impl only accepts (const) basic_json");
11232 
11233  public:
11234 
11240  using iterator_category = std::bidirectional_iterator_tag;
11241 
11243  using value_type = typename BasicJsonType::value_type;
11245  using difference_type = typename BasicJsonType::difference_type;
11248  typename BasicJsonType::const_pointer,
11249  typename BasicJsonType::pointer>::type;
11251  using reference =
11253  typename BasicJsonType::const_reference,
11254  typename BasicJsonType::reference>::type;
11255 
11256  iter_impl() = default;
11257  ~iter_impl() = default;
11258  iter_impl(iter_impl&&) noexcept = default;
11259  iter_impl& operator=(iter_impl&&) noexcept = default;
11260 
11267  explicit iter_impl(pointer object) noexcept : m_object(object)
11268  {
11269  JSON_ASSERT(m_object != nullptr);
11270 
11271  switch (m_object->m_type)
11272  {
11273  case value_t::object:
11274  {
11275  m_it.object_iterator = typename object_t::iterator();
11276  break;
11277  }
11278 
11279  case value_t::array:
11280  {
11281  m_it.array_iterator = typename array_t::iterator();
11282  break;
11283  }
11284 
11285  default:
11286  {
11288  break;
11289  }
11290  }
11291  }
11292 
11310  : m_object(other.m_object), m_it(other.m_it)
11311  {}
11312 
11320  {
11321  if (&other != this)
11322  {
11323  m_object = other.m_object;
11324  m_it = other.m_it;
11325  }
11326  return *this;
11327  }
11328 
11335  : m_object(other.m_object), m_it(other.m_it)
11336  {}
11337 
11344  iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp)
11345  {
11346  m_object = other.m_object;
11347  m_it = other.m_it;
11348  return *this;
11349  }
11350 
11356  void set_begin() noexcept
11357  {
11358  JSON_ASSERT(m_object != nullptr);
11359 
11360  switch (m_object->m_type)
11361  {
11362  case value_t::object:
11363  {
11364  m_it.object_iterator = m_object->m_value.object->begin();
11365  break;
11366  }
11367 
11368  case value_t::array:
11369  {
11370  m_it.array_iterator = m_object->m_value.array->begin();
11371  break;
11372  }
11373 
11374  case value_t::null:
11375  {
11376  // set to end so begin()==end() is true: null is empty
11378  break;
11379  }
11380 
11381  default:
11382  {
11384  break;
11385  }
11386  }
11387  }
11388 
11393  void set_end() noexcept
11394  {
11395  JSON_ASSERT(m_object != nullptr);
11396 
11397  switch (m_object->m_type)
11398  {
11399  case value_t::object:
11400  {
11401  m_it.object_iterator = m_object->m_value.object->end();
11402  break;
11403  }
11404 
11405  case value_t::array:
11406  {
11407  m_it.array_iterator = m_object->m_value.array->end();
11408  break;
11409  }
11410 
11411  default:
11412  {
11414  break;
11415  }
11416  }
11417  }
11418 
11419  public:
11425  {
11426  JSON_ASSERT(m_object != nullptr);
11427 
11428  switch (m_object->m_type)
11429  {
11430  case value_t::object:
11431  {
11432  JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11433  return m_it.object_iterator->second;
11434  }
11435 
11436  case value_t::array:
11437  {
11438  JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11439  return *m_it.array_iterator;
11440  }
11441 
11442  case value_t::null:
11443  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11444 
11445  default:
11446  {
11448  {
11449  return *m_object;
11450  }
11451 
11452  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11453  }
11454  }
11455  }
11456 
11462  {
11463  JSON_ASSERT(m_object != nullptr);
11464 
11465  switch (m_object->m_type)
11466  {
11467  case value_t::object:
11468  {
11469  JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11470  return &(m_it.object_iterator->second);
11471  }
11472 
11473  case value_t::array:
11474  {
11475  JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11476  return &*m_it.array_iterator;
11477  }
11478 
11479  default:
11480  {
11482  {
11483  return m_object;
11484  }
11485 
11486  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11487  }
11488  }
11489  }
11490 
11495  iter_impl const operator++(int) // NOLINT(readability-const-return-type)
11496  {
11497  auto result = *this;
11498  ++(*this);
11499  return result;
11500  }
11501 
11507  {
11508  JSON_ASSERT(m_object != nullptr);
11509 
11510  switch (m_object->m_type)
11511  {
11512  case value_t::object:
11513  {
11514  std::advance(m_it.object_iterator, 1);
11515  break;
11516  }
11517 
11518  case value_t::array:
11519  {
11520  std::advance(m_it.array_iterator, 1);
11521  break;
11522  }
11523 
11524  default:
11525  {
11527  break;
11528  }
11529  }
11530 
11531  return *this;
11532  }
11533 
11538  iter_impl const operator--(int) // NOLINT(readability-const-return-type)
11539  {
11540  auto result = *this;
11541  --(*this);
11542  return result;
11543  }
11544 
11550  {
11551  JSON_ASSERT(m_object != nullptr);
11552 
11553  switch (m_object->m_type)
11554  {
11555  case value_t::object:
11556  {
11557  std::advance(m_it.object_iterator, -1);
11558  break;
11559  }
11560 
11561  case value_t::array:
11562  {
11563  std::advance(m_it.array_iterator, -1);
11564  break;
11565  }
11566 
11567  default:
11568  {
11570  break;
11571  }
11572  }
11573 
11574  return *this;
11575  }
11576 
11581  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 >
11582  bool operator==(const IterImpl& other) const
11583  {
11584  // if objects are not the same, the comparison is undefined
11585  if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11586  {
11587  JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
11588  }
11589 
11590  JSON_ASSERT(m_object != nullptr);
11591 
11592  switch (m_object->m_type)
11593  {
11594  case value_t::object:
11595  return (m_it.object_iterator == other.m_it.object_iterator);
11596 
11597  case value_t::array:
11598  return (m_it.array_iterator == other.m_it.array_iterator);
11599 
11600  default:
11601  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
11602  }
11603  }
11604 
11609  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 >
11610  bool operator!=(const IterImpl& other) const
11611  {
11612  return !operator==(other);
11613  }
11614 
11619  bool operator<(const iter_impl& other) const
11620  {
11621  // if objects are not the same, the comparison is undefined
11622  if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11623  {
11624  JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
11625  }
11626 
11627  JSON_ASSERT(m_object != nullptr);
11628 
11629  switch (m_object->m_type)
11630  {
11631  case value_t::object:
11632  JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", *m_object));
11633 
11634  case value_t::array:
11635  return (m_it.array_iterator < other.m_it.array_iterator);
11636 
11637  default:
11639  }
11640  }
11641 
11646  bool operator<=(const iter_impl& other) const
11647  {
11648  return !other.operator < (*this);
11649  }
11650 
11655  bool operator>(const iter_impl& other) const
11656  {
11657  return !operator<=(other);
11658  }
11659 
11664  bool operator>=(const iter_impl& other) const
11665  {
11666  return !operator<(other);
11667  }
11668 
11674  {
11675  JSON_ASSERT(m_object != nullptr);
11676 
11677  switch (m_object->m_type)
11678  {
11679  case value_t::object:
11680  JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
11681 
11682  case value_t::array:
11683  {
11684  std::advance(m_it.array_iterator, i);
11685  break;
11686  }
11687 
11688  default:
11689  {
11690  m_it.primitive_iterator += i;
11691  break;
11692  }
11693  }
11694 
11695  return *this;
11696  }
11697 
11703  {
11704  return operator+=(-i);
11705  }
11706 
11712  {
11713  auto result = *this;
11714  result += i;
11715  return result;
11716  }
11717 
11723  {
11724  auto result = it;
11725  result += i;
11726  return result;
11727  }
11728 
11734  {
11735  auto result = *this;
11736  result -= i;
11737  return result;
11738  }
11739 
11745  {
11746  JSON_ASSERT(m_object != nullptr);
11747 
11748  switch (m_object->m_type)
11749  {
11750  case value_t::object:
11751  JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
11752 
11753  case value_t::array:
11754  return m_it.array_iterator - other.m_it.array_iterator;
11755 
11756  default:
11758  }
11759  }
11760 
11766  {
11767  JSON_ASSERT(m_object != nullptr);
11768 
11769  switch (m_object->m_type)
11770  {
11771  case value_t::object:
11772  JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", *m_object));
11773 
11774  case value_t::array:
11775  return *std::next(m_it.array_iterator, n);
11776 
11777  case value_t::null:
11778  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11779 
11780  default:
11781  {
11783  {
11784  return *m_object;
11785  }
11786 
11787  JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
11788  }
11789  }
11790  }
11791 
11796  const typename object_t::key_type& key() const
11797  {
11798  JSON_ASSERT(m_object != nullptr);
11799 
11800  if (JSON_HEDLEY_LIKELY(m_object->is_object()))
11801  {
11802  return m_it.object_iterator->first;
11803  }
11804 
11805  JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", *m_object));
11806  }
11807 
11813  {
11814  return operator*();
11815  }
11816 
11819  pointer m_object = nullptr;
11822 };
11823 } // namespace detail
11824 } // namespace nlohmann
11825 
11826 // #include <nlohmann/detail/iterators/iteration_proxy.hpp>
11827 
11828 // #include <nlohmann/detail/iterators/json_reverse_iterator.hpp>
11829 
11830 
11831 #include <cstddef> // ptrdiff_t
11832 #include <iterator> // reverse_iterator
11833 #include <utility> // declval
11834 
11835 namespace nlohmann
11836 {
11837 namespace detail
11838 {
11840 // reverse_iterator //
11842 
11861 template<typename Base>
11862 class json_reverse_iterator : public std::reverse_iterator<Base>
11863 {
11864  public:
11865  using difference_type = std::ptrdiff_t;
11867  using base_iterator = std::reverse_iterator<Base>;
11869  using reference = typename Base::reference;
11870 
11872  explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
11873  : base_iterator(it) {}
11874 
11876  explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}
11877 
11879  json_reverse_iterator const operator++(int) // NOLINT(readability-const-return-type)
11880  {
11881  return static_cast<json_reverse_iterator>(base_iterator::operator++(1));
11882  }
11883 
11886  {
11887  return static_cast<json_reverse_iterator&>(base_iterator::operator++());
11888  }
11889 
11891  json_reverse_iterator const operator--(int) // NOLINT(readability-const-return-type)
11892  {
11893  return static_cast<json_reverse_iterator>(base_iterator::operator--(1));
11894  }
11895 
11898  {
11899  return static_cast<json_reverse_iterator&>(base_iterator::operator--());
11900  }
11901 
11904  {
11905  return static_cast<json_reverse_iterator&>(base_iterator::operator+=(i));
11906  }
11907 
11910  {
11911  return static_cast<json_reverse_iterator>(base_iterator::operator+(i));
11912  }
11913 
11916  {
11917  return static_cast<json_reverse_iterator>(base_iterator::operator-(i));
11918  }
11919 
11922  {
11923  return base_iterator(*this) - base_iterator(other);
11924  }
11925 
11928  {
11929  return *(this->operator+(n));
11930  }
11931 
11933  auto key() const -> decltype(std::declval<Base>().key())
11934  {
11935  auto it = --this->base();
11936  return it.key();
11937  }
11938 
11941  {
11942  auto it = --this->base();
11943  return it.operator * ();
11944  }
11945 };
11946 } // namespace detail
11947 } // namespace nlohmann
11948 
11949 // #include <nlohmann/detail/iterators/primitive_iterator.hpp>
11950 
11951 // #include <nlohmann/detail/json_pointer.hpp>
11952 
11953 
11954 #include <algorithm> // all_of
11955 #include <cctype> // isdigit
11956 #include <limits> // max
11957 #include <numeric> // accumulate
11958 #include <string> // string
11959 #include <utility> // move
11960 #include <vector> // vector
11961 
11962 // #include <nlohmann/detail/exceptions.hpp>
11963 
11964 // #include <nlohmann/detail/macro_scope.hpp>
11965 
11966 // #include <nlohmann/detail/string_escape.hpp>
11967 
11968 // #include <nlohmann/detail/value_t.hpp>
11969 
11970 
11971 namespace nlohmann
11972 {
11973 template<typename BasicJsonType>
11975 {
11976  // allow basic_json to access private members
11978  friend class basic_json;
11979 
11980  public:
12002  explicit json_pointer(const std::string& s = "")
12003  : reference_tokens(split(s))
12004  {}
12005 
12020  std::string to_string() const
12021  {
12022  return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
12023  std::string{},
12024  [](const std::string & a, const std::string & b)
12025  {
12026  return a + "/" + detail::escape(b);
12027  });
12028  }
12029 
12031  operator std::string() const
12032  {
12033  return to_string();
12034  }
12035 
12053  {
12054  reference_tokens.insert(reference_tokens.end(),
12055  ptr.reference_tokens.begin(),
12056  ptr.reference_tokens.end());
12057  return *this;
12058  }
12059 
12076  json_pointer& operator/=(std::string token)
12077  {
12078  push_back(std::move(token));
12079  return *this;
12080  }
12081 
12098  json_pointer& operator/=(std::size_t array_idx)
12099  {
12100  return *this /= std::to_string(array_idx);
12101  }
12102 
12119  const json_pointer& rhs)
12120  {
12121  return json_pointer(lhs) /= rhs;
12122  }
12123 
12139  friend json_pointer operator/(const json_pointer& ptr, std::string token) // NOLINT(performance-unnecessary-value-param)
12140  {
12141  return json_pointer(ptr) /= std::move(token);
12142  }
12143 
12159  friend json_pointer operator/(const json_pointer& ptr, std::size_t array_idx)
12160  {
12161  return json_pointer(ptr) /= array_idx;
12162  }
12163 
12178  {
12179  if (empty())
12180  {
12181  return *this;
12182  }
12183 
12184  json_pointer res = *this;
12185  res.pop_back();
12186  return res;
12187  }
12188 
12202  void pop_back()
12203  {
12204  if (JSON_HEDLEY_UNLIKELY(empty()))
12205  {
12206  JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
12207  }
12208 
12209  reference_tokens.pop_back();
12210  }
12211 
12226  const std::string& back() const
12227  {
12228  if (JSON_HEDLEY_UNLIKELY(empty()))
12229  {
12230  JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
12231  }
12232 
12233  return reference_tokens.back();
12234  }
12235 
12248  void push_back(const std::string& token)
12249  {
12250  reference_tokens.push_back(token);
12251  }
12252 
12254  void push_back(std::string&& token)
12255  {
12256  reference_tokens.push_back(std::move(token));
12257  }
12258 
12273  bool empty() const noexcept
12274  {
12275  return reference_tokens.empty();
12276  }
12277 
12278  private:
12289  static typename BasicJsonType::size_type array_index(const std::string& s)
12290  {
12291  using size_type = typename BasicJsonType::size_type;
12292 
12293  // error condition (cf. RFC 6901, Sect. 4)
12294  if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))
12295  {
12296  JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", BasicJsonType()));
12297  }
12298 
12299  // error condition (cf. RFC 6901, Sect. 4)
12300  if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9')))
12301  {
12302  JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", BasicJsonType()));
12303  }
12304 
12305  std::size_t processed_chars = 0;
12306  unsigned long long res = 0; // NOLINT(runtime/int)
12307  JSON_TRY
12308  {
12309  res = std::stoull(s, &processed_chars);
12310  }
12311  JSON_CATCH(std::out_of_range&)
12312  {
12313  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
12314  }
12315 
12316  // check if the string was completely read
12317  if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
12318  {
12319  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
12320  }
12321 
12322  // only triggered on special platforms (like 32bit), see also
12323  // https://github.com/nlohmann/json/pull/2203
12324  if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) // NOLINT(runtime/int)
12325  {
12326  JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", BasicJsonType())); // LCOV_EXCL_LINE
12327  }
12328 
12329  return static_cast<size_type>(res);
12330  }
12331 
12333  json_pointer top() const
12334  {
12335  if (JSON_HEDLEY_UNLIKELY(empty()))
12336  {
12337  JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
12338  }
12339 
12342  return result;
12343  }
12344 
12345  private:
12355  {
12356  auto* result = &j;
12357 
12358  // in case no reference tokens exist, return a reference to the JSON value
12359  // j which will be overwritten by a primitive value
12360  for (const auto& reference_token : reference_tokens)
12361  {
12362  switch (result->type())
12363  {
12364  case detail::value_t::null:
12365  {
12366  if (reference_token == "0")
12367  {
12368  // start a new array if reference token is 0
12369  result = &result->operator[](0);
12370  }
12371  else
12372  {
12373  // start a new object otherwise
12374  result = &result->operator[](reference_token);
12375  }
12376  break;
12377  }
12378 
12380  {
12381  // create an entry in the object
12382  result = &result->operator[](reference_token);
12383  break;
12384  }
12385 
12387  {
12388  // create an entry in the array
12389  result = &result->operator[](array_index(reference_token));
12390  break;
12391  }
12392 
12393  /*
12394  The following code is only reached if there exists a reference
12395  token _and_ the current value is primitive. In this case, we have
12396  an error situation, because primitive values may only occur as
12397  single value; that is, with an empty list of reference tokens.
12398  */
12399  default:
12400  JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", j));
12401  }
12402  }
12403 
12404  return *result;
12405  }
12406 
12427  {
12428  for (const auto& reference_token : reference_tokens)
12429  {
12430  // convert null values to arrays or objects before continuing
12431  if (ptr->is_null())
12432  {
12433  // check if reference token is a number
12434  const bool nums =
12435  std::all_of(reference_token.begin(), reference_token.end(),
12436  [](const unsigned char x)
12437  {
12438  return std::isdigit(x);
12439  });
12440 
12441  // change value to array for numbers or "-" or to object otherwise
12442  *ptr = (nums || reference_token == "-")
12445  }
12446 
12447  switch (ptr->type())
12448  {
12450  {
12451  // use unchecked object access
12452  ptr = &ptr->operator[](reference_token);
12453  break;
12454  }
12455 
12457  {
12458  if (reference_token == "-")
12459  {
12460  // explicitly treat "-" as index beyond the end
12461  ptr = &ptr->operator[](ptr->m_value.array->size());
12462  }
12463  else
12464  {
12465  // convert array index to number; unchecked access
12466  ptr = &ptr->operator[](array_index(reference_token));
12467  }
12468  break;
12469  }
12470 
12471  default:
12472  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
12473  }
12474  }
12475 
12476  return *ptr;
12477  }
12478 
12486  {
12487  for (const auto& reference_token : reference_tokens)
12488  {
12489  switch (ptr->type())
12490  {
12492  {
12493  // note: at performs range check
12494  ptr = &ptr->at(reference_token);
12495  break;
12496  }
12497 
12499  {
12500  if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12501  {
12502  // "-" always fails the range check
12504  "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12505  ") is out of range", *ptr));
12506  }
12507 
12508  // note: at performs range check
12509  ptr = &ptr->at(array_index(reference_token));
12510  break;
12511  }
12512 
12513  default:
12514  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
12515  }
12516  }
12517 
12518  return *ptr;
12519  }
12520 
12534  const BasicJsonType& get_unchecked(const BasicJsonType* ptr) const
12535  {
12536  for (const auto& reference_token : reference_tokens)
12537  {
12538  switch (ptr->type())
12539  {
12541  {
12542  // use unchecked object access
12543  ptr = &ptr->operator[](reference_token);
12544  break;
12545  }
12546 
12548  {
12549  if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12550  {
12551  // "-" cannot be used for const access
12552  JSON_THROW(detail::out_of_range::create(402, "array index '-' (" + std::to_string(ptr->m_value.array->size()) + ") is out of range", *ptr));
12553  }
12554 
12555  // use unchecked array access
12556  ptr = &ptr->operator[](array_index(reference_token));
12557  break;
12558  }
12559 
12560  default:
12561  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
12562  }
12563  }
12564 
12565  return *ptr;
12566  }
12567 
12574  const BasicJsonType& get_checked(const BasicJsonType* ptr) const
12575  {
12576  for (const auto& reference_token : reference_tokens)
12577  {
12578  switch (ptr->type())
12579  {
12581  {
12582  // note: at performs range check
12583  ptr = &ptr->at(reference_token);
12584  break;
12585  }
12586 
12588  {
12589  if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12590  {
12591  // "-" always fails the range check
12593  "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12594  ") is out of range", *ptr));
12595  }
12596 
12597  // note: at performs range check
12598  ptr = &ptr->at(array_index(reference_token));
12599  break;
12600  }
12601 
12602  default:
12603  JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
12604  }
12605  }
12606 
12607  return *ptr;
12608  }
12609 
12614  bool contains(const BasicJsonType* ptr) const
12615  {
12616  for (const auto& reference_token : reference_tokens)
12617  {
12618  switch (ptr->type())
12619  {
12621  {
12622  if (!ptr->contains(reference_token))
12623  {
12624  // we did not find the key in the object
12625  return false;
12626  }
12627 
12628  ptr = &ptr->operator[](reference_token);
12629  break;
12630  }
12631 
12633  {
12634  if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12635  {
12636  // "-" always fails the range check
12637  return false;
12638  }
12639  if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !("0" <= reference_token && reference_token <= "9")))
12640  {
12641  // invalid char
12642  return false;
12643  }
12644  if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
12645  {
12646  if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9')))
12647  {
12648  // first char should be between '1' and '9'
12649  return false;
12650  }
12651  for (std::size_t i = 1; i < reference_token.size(); i++)
12652  {
12653  if (JSON_HEDLEY_UNLIKELY(!('0' <= reference_token[i] && reference_token[i] <= '9')))
12654  {
12655  // other char should be between '0' and '9'
12656  return false;
12657  }
12658  }
12659  }
12660 
12661  const auto idx = array_index(reference_token);
12662  if (idx >= ptr->size())
12663  {
12664  // index out of range
12665  return false;
12666  }
12667 
12668  ptr = &ptr->operator[](idx);
12669  break;
12670  }
12671 
12672  default:
12673  {
12674  // we do not expect primitive values if there is still a
12675  // reference token to process
12676  return false;
12677  }
12678  }
12679  }
12680 
12681  // no reference token left means we found a primitive value
12682  return true;
12683  }
12684 
12694  static std::vector<std::string> split(const std::string& reference_string)
12695  {
12696  std::vector<std::string> result;
12697 
12698  // special case: empty reference string -> no reference tokens
12699  if (reference_string.empty())
12700  {
12701  return result;
12702  }
12703 
12704  // check if nonempty reference string begins with slash
12705  if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
12706  {
12707  JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", BasicJsonType()));
12708  }
12709 
12710  // extract the reference tokens:
12711  // - slash: position of the last read slash (or end of string)
12712  // - start: position after the previous slash
12713  for (
12714  // search for the first slash after the first character
12715  std::size_t slash = reference_string.find_first_of('/', 1),
12716  // set the beginning of the first reference token
12717  start = 1;
12718  // we can stop if start == 0 (if slash == std::string::npos)
12719  start != 0;
12720  // set the beginning of the next reference token
12721  // (will eventually be 0 if slash == std::string::npos)
12722  start = (slash == std::string::npos) ? 0 : slash + 1,
12723  // find next slash
12724  slash = reference_string.find_first_of('/', start))
12725  {
12726  // use the text between the beginning of the reference token
12727  // (start) and the last slash (slash).
12728  auto reference_token = reference_string.substr(start, slash - start);
12729 
12730  // check reference tokens are properly escaped
12731  for (std::size_t pos = reference_token.find_first_of('~');
12732  pos != std::string::npos;
12733  pos = reference_token.find_first_of('~', pos + 1))
12734  {
12735  JSON_ASSERT(reference_token[pos] == '~');
12736 
12737  // ~ must be followed by 0 or 1
12738  if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
12739  (reference_token[pos + 1] != '0' &&
12740  reference_token[pos + 1] != '1')))
12741  {
12742  JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", BasicJsonType()));
12743  }
12744  }
12745 
12746  // finally, store the reference token
12747  detail::unescape(reference_token);
12748  result.push_back(reference_token);
12749  }
12750 
12751  return result;
12752  }
12753 
12754  private:
12762  static void flatten(const std::string& reference_string,
12763  const BasicJsonType& value,
12765  {
12766  switch (value.type())
12767  {
12769  {
12770  if (value.m_value.array->empty())
12771  {
12772  // flatten empty array as null
12773  result[reference_string] = nullptr;
12774  }
12775  else
12776  {
12777  // iterate array and use index as reference string
12778  for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
12779  {
12780  flatten(reference_string + "/" + std::to_string(i),
12781  value.m_value.array->operator[](i), result);
12782  }
12783  }
12784  break;
12785  }
12786 
12788  {
12789  if (value.m_value.object->empty())
12790  {
12791  // flatten empty object as null
12792  result[reference_string] = nullptr;
12793  }
12794  else
12795  {
12796  // iterate object and use keys as reference string
12797  for (const auto& element : *value.m_value.object)
12798  {
12799  flatten(reference_string + "/" + detail::escape(element.first), element.second, result);
12800  }
12801  }
12802  break;
12803  }
12804 
12805  default:
12806  {
12807  // add primitive value with its reference string
12808  result[reference_string] = value;
12809  break;
12810  }
12811  }
12812  }
12813 
12824  static BasicJsonType
12826  {
12827  if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
12828  {
12829  JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", value));
12830  }
12831 
12833 
12834  // iterate the JSON object values
12835  for (const auto& element : *value.m_value.object)
12836  {
12837  if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
12838  {
12839  JSON_THROW(detail::type_error::create(315, "values in object must be primitive", element.second));
12840  }
12841 
12842  // assign value to reference pointed to by JSON pointer; Note that if
12843  // the JSON pointer is "" (i.e., points to the whole value), function
12844  // get_and_create returns a reference to result itself. An assignment
12845  // will then create a primitive value.
12846  json_pointer(element.first).get_and_create(result) = element.second;
12847  }
12848 
12849  return result;
12850  }
12851 
12863  friend bool operator==(json_pointer const& lhs,
12864  json_pointer const& rhs) noexcept
12865  {
12866  return lhs.reference_tokens == rhs.reference_tokens;
12867  }
12868 
12880  friend bool operator!=(json_pointer const& lhs,
12881  json_pointer const& rhs) noexcept
12882  {
12883  return !(lhs == rhs);
12884  }
12885 
12887  std::vector<std::string> reference_tokens;
12888 };
12889 } // namespace nlohmann
12890 
12891 // #include <nlohmann/detail/json_ref.hpp>
12892 
12893 
12894 #include <initializer_list>
12895 #include <utility>
12896 
12897 // #include <nlohmann/detail/meta/type_traits.hpp>
12898 
12899 
12900 namespace nlohmann
12901 {
12902 namespace detail
12903 {
12904 template<typename BasicJsonType>
12906 {
12907  public:
12908  using value_type = BasicJsonType;
12909 
12911  : owned_value(std::move(value))
12912  {}
12913 
12914  json_ref(const value_type& value)
12915  : value_ref(&value)
12916  {}
12917 
12918  json_ref(std::initializer_list<json_ref> init)
12919  : owned_value(init)
12920  {}
12921 
12922  template <
12923  class... Args,
12924  enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
12925  json_ref(Args && ... args)
12926  : owned_value(std::forward<Args>(args)...)
12927  {}
12928 
12929  // class should be movable only
12930  json_ref(json_ref&&) noexcept = default;
12932  json_ref& operator=(const json_ref&) = delete;
12933  json_ref& operator=(json_ref&&) = delete;
12934  ~json_ref() = default;
12935 
12937  {
12938  if (value_ref == nullptr)
12939  {
12940  return std::move(owned_value);
12941  }
12942  return *value_ref;
12943  }
12944 
12945  value_type const& operator*() const
12946  {
12947  return value_ref ? *value_ref : owned_value;
12948  }
12949 
12950  value_type const* operator->() const
12951  {
12952  return &** this;
12953  }
12954 
12955  private:
12956  mutable value_type owned_value = nullptr;
12957  value_type const* value_ref = nullptr;
12958 };
12959 } // namespace detail
12960 } // namespace nlohmann
12961 
12962 // #include <nlohmann/detail/macro_scope.hpp>
12963 
12964 // #include <nlohmann/detail/string_escape.hpp>
12965 
12966 // #include <nlohmann/detail/meta/cpp_future.hpp>
12967 
12968 // #include <nlohmann/detail/meta/type_traits.hpp>
12969 
12970 // #include <nlohmann/detail/output/binary_writer.hpp>
12971 
12972 
12973 #include <algorithm> // reverse
12974 #include <array> // array
12975 #include <cmath> // isnan, isinf
12976 #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
12977 #include <cstring> // memcpy
12978 #include <limits> // numeric_limits
12979 #include <string> // string
12980 #include <utility> // move
12981 
12982 // #include <nlohmann/detail/input/binary_reader.hpp>
12983 
12984 // #include <nlohmann/detail/macro_scope.hpp>
12985 
12986 // #include <nlohmann/detail/output/output_adapters.hpp>
12987 
12988 
12989 #include <algorithm> // copy
12990 #include <cstddef> // size_t
12991 #include <ios> // streamsize
12992 #include <iterator> // back_inserter
12993 #include <memory> // shared_ptr, make_shared
12994 #include <ostream> // basic_ostream
12995 #include <string> // basic_string
12996 #include <vector> // vector
12997 // #include <nlohmann/detail/macro_scope.hpp>
12998 
12999 
13000 namespace nlohmann
13001 {
13002 namespace detail
13003 {
13005 template<typename CharType> struct output_adapter_protocol
13006 {
13007  virtual void write_character(CharType c) = 0;
13008  virtual void write_characters(const CharType* s, std::size_t length) = 0;
13009  virtual ~output_adapter_protocol() = default;
13010 
13015  output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
13016 };
13017 
13019 template<typename CharType>
13020 using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
13021 
13023 template<typename CharType>
13025 {
13026  public:
13027  explicit output_vector_adapter(std::vector<CharType>& vec) noexcept
13028  : v(vec)
13029  {}
13030 
13031  void write_character(CharType c) override
13032  {
13033  v.push_back(c);
13034  }
13035 
13037  void write_characters(const CharType* s, std::size_t length) override
13038  {
13039  std::copy(s, s + length, std::back_inserter(v));
13040  }
13041 
13042  private:
13043  std::vector<CharType>& v;
13044 };
13045 
13047 template<typename CharType>
13049 {
13050  public:
13051  explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
13052  : stream(s)
13053  {}
13054 
13055  void write_character(CharType c) override
13056  {
13057  stream.put(c);
13058  }
13059 
13061  void write_characters(const CharType* s, std::size_t length) override
13062  {
13063  stream.write(s, static_cast<std::streamsize>(length));
13064  }
13065 
13066  private:
13067  std::basic_ostream<CharType>& stream;
13068 };
13069 
13071 template<typename CharType, typename StringType = std::basic_string<CharType>>
13073 {
13074  public:
13075  explicit output_string_adapter(StringType& s) noexcept
13076  : str(s)
13077  {}
13078 
13079  void write_character(CharType c) override
13080  {
13081  str.push_back(c);
13082  }
13083 
13085  void write_characters(const CharType* s, std::size_t length) override
13086  {
13087  str.append(s, length);
13088  }
13089 
13090  private:
13091  StringType& str;
13092 };
13093 
13094 template<typename CharType, typename StringType = std::basic_string<CharType>>
13096 {
13097  public:
13098  output_adapter(std::vector<CharType>& vec)
13099  : oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {}
13100 
13101  output_adapter(std::basic_ostream<CharType>& s)
13102  : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
13103 
13104  output_adapter(StringType& s)
13105  : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
13106 
13108  {
13109  return oa;
13110  }
13111 
13112  private:
13114 };
13115 } // namespace detail
13116 } // namespace nlohmann
13117 
13118 
13119 namespace nlohmann
13120 {
13121 namespace detail
13122 {
13124 // binary writer //
13126 
13130 template<typename BasicJsonType, typename CharType>
13132 {
13134  using binary_t = typename BasicJsonType::binary_t;
13135  using number_float_t = typename BasicJsonType::number_float_t;
13136 
13137  public:
13143  explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
13144  {
13145  JSON_ASSERT(oa);
13146  }
13147 
13152  void write_bson(const BasicJsonType& j)
13153  {
13154  switch (j.type())
13155  {
13156  case value_t::object:
13157  {
13158  write_bson_object(*j.m_value.object);
13159  break;
13160  }
13161 
13162  default:
13163  {
13164  JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));;
13165  }
13166  }
13167  }
13168 
13172  void write_cbor(const BasicJsonType& j)
13173  {
13174  switch (j.type())
13175  {
13176  case value_t::null:
13177  {
13178  oa->write_character(to_char_type(0xF6));
13179  break;
13180  }
13181 
13182  case value_t::boolean:
13183  {
13184  oa->write_character(j.m_value.boolean
13185  ? to_char_type(0xF5)
13186  : to_char_type(0xF4));
13187  break;
13188  }
13189 
13190  case value_t::number_integer:
13191  {
13192  if (j.m_value.number_integer >= 0)
13193  {
13194  // CBOR does not differentiate between positive signed
13195  // integers and unsigned integers. Therefore, we used the
13196  // code from the value_t::number_unsigned case here.
13197  if (j.m_value.number_integer <= 0x17)
13198  {
13199  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13200  }
13201  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
13202  {
13203  oa->write_character(to_char_type(0x18));
13204  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13205  }
13206  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
13207  {
13208  oa->write_character(to_char_type(0x19));
13209  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
13210  }
13211  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
13212  {
13213  oa->write_character(to_char_type(0x1A));
13214  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
13215  }
13216  else
13217  {
13218  oa->write_character(to_char_type(0x1B));
13219  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
13220  }
13221  }
13222  else
13223  {
13224  // The conversions below encode the sign in the first
13225  // byte, and the value is converted to a positive number.
13226  const auto positive_number = -1 - j.m_value.number_integer;
13227  if (j.m_value.number_integer >= -24)
13228  {
13229  write_number(static_cast<std::uint8_t>(0x20 + positive_number));
13230  }
13231  else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
13232  {
13233  oa->write_character(to_char_type(0x38));
13234  write_number(static_cast<std::uint8_t>(positive_number));
13235  }
13236  else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
13237  {
13238  oa->write_character(to_char_type(0x39));
13239  write_number(static_cast<std::uint16_t>(positive_number));
13240  }
13241  else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
13242  {
13243  oa->write_character(to_char_type(0x3A));
13244  write_number(static_cast<std::uint32_t>(positive_number));
13245  }
13246  else
13247  {
13248  oa->write_character(to_char_type(0x3B));
13249  write_number(static_cast<std::uint64_t>(positive_number));
13250  }
13251  }
13252  break;
13253  }
13254 
13255  case value_t::number_unsigned:
13256  {
13257  if (j.m_value.number_unsigned <= 0x17)
13258  {
13259  write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
13260  }
13261  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13262  {
13263  oa->write_character(to_char_type(0x18));
13264  write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
13265  }
13266  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13267  {
13268  oa->write_character(to_char_type(0x19));
13269  write_number(static_cast<std::uint16_t>(j.m_value.number_unsigned));
13270  }
13271  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13272  {
13273  oa->write_character(to_char_type(0x1A));
13274  write_number(static_cast<std::uint32_t>(j.m_value.number_unsigned));
13275  }
13276  else
13277  {
13278  oa->write_character(to_char_type(0x1B));
13279  write_number(static_cast<std::uint64_t>(j.m_value.number_unsigned));
13280  }
13281  break;
13282  }
13283 
13284  case value_t::number_float:
13285  {
13286  if (std::isnan(j.m_value.number_float))
13287  {
13288  // NaN is 0xf97e00 in CBOR
13289  oa->write_character(to_char_type(0xF9));
13290  oa->write_character(to_char_type(0x7E));
13291  oa->write_character(to_char_type(0x00));
13292  }
13293  else if (std::isinf(j.m_value.number_float))
13294  {
13295  // Infinity is 0xf97c00, -Infinity is 0xf9fc00
13296  oa->write_character(to_char_type(0xf9));
13297  oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
13298  oa->write_character(to_char_type(0x00));
13299  }
13300  else
13301  {
13302  write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
13303  }
13304  break;
13305  }
13306 
13307  case value_t::string:
13308  {
13309  // step 1: write control byte and the string length
13310  const auto N = j.m_value.string->size();
13311  if (N <= 0x17)
13312  {
13313  write_number(static_cast<std::uint8_t>(0x60 + N));
13314  }
13315  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13316  {
13317  oa->write_character(to_char_type(0x78));
13318  write_number(static_cast<std::uint8_t>(N));
13319  }
13320  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13321  {
13322  oa->write_character(to_char_type(0x79));
13323  write_number(static_cast<std::uint16_t>(N));
13324  }
13325  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13326  {
13327  oa->write_character(to_char_type(0x7A));
13328  write_number(static_cast<std::uint32_t>(N));
13329  }
13330  // LCOV_EXCL_START
13331  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13332  {
13333  oa->write_character(to_char_type(0x7B));
13334  write_number(static_cast<std::uint64_t>(N));
13335  }
13336  // LCOV_EXCL_STOP
13337 
13338  // step 2: write the string
13339  oa->write_characters(
13340  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
13341  j.m_value.string->size());
13342  break;
13343  }
13344 
13345  case value_t::array:
13346  {
13347  // step 1: write control byte and the array size
13348  const auto N = j.m_value.array->size();
13349  if (N <= 0x17)
13350  {
13351  write_number(static_cast<std::uint8_t>(0x80 + N));
13352  }
13353  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13354  {
13355  oa->write_character(to_char_type(0x98));
13356  write_number(static_cast<std::uint8_t>(N));
13357  }
13358  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13359  {
13360  oa->write_character(to_char_type(0x99));
13361  write_number(static_cast<std::uint16_t>(N));
13362  }
13363  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13364  {
13365  oa->write_character(to_char_type(0x9A));
13366  write_number(static_cast<std::uint32_t>(N));
13367  }
13368  // LCOV_EXCL_START
13369  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13370  {
13371  oa->write_character(to_char_type(0x9B));
13372  write_number(static_cast<std::uint64_t>(N));
13373  }
13374  // LCOV_EXCL_STOP
13375 
13376  // step 2: write each element
13377  for (const auto& el : *j.m_value.array)
13378  {
13379  write_cbor(el);
13380  }
13381  break;
13382  }
13383 
13384  case value_t::binary:
13385  {
13386  if (j.m_value.binary->has_subtype())
13387  {
13388  write_number(static_cast<std::uint8_t>(0xd8));
13389  write_number(j.m_value.binary->subtype());
13390  }
13391 
13392  // step 1: write control byte and the binary array size
13393  const auto N = j.m_value.binary->size();
13394  if (N <= 0x17)
13395  {
13396  write_number(static_cast<std::uint8_t>(0x40 + N));
13397  }
13398  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13399  {
13400  oa->write_character(to_char_type(0x58));
13401  write_number(static_cast<std::uint8_t>(N));
13402  }
13403  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13404  {
13405  oa->write_character(to_char_type(0x59));
13406  write_number(static_cast<std::uint16_t>(N));
13407  }
13408  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13409  {
13410  oa->write_character(to_char_type(0x5A));
13411  write_number(static_cast<std::uint32_t>(N));
13412  }
13413  // LCOV_EXCL_START
13414  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13415  {
13416  oa->write_character(to_char_type(0x5B));
13417  write_number(static_cast<std::uint64_t>(N));
13418  }
13419  // LCOV_EXCL_STOP
13420 
13421  // step 2: write each element
13422  oa->write_characters(
13423  reinterpret_cast<const CharType*>(j.m_value.binary->data()),
13424  N);
13425 
13426  break;
13427  }
13428 
13429  case value_t::object:
13430  {
13431  // step 1: write control byte and the object size
13432  const auto N = j.m_value.object->size();
13433  if (N <= 0x17)
13434  {
13435  write_number(static_cast<std::uint8_t>(0xA0 + N));
13436  }
13437  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13438  {
13439  oa->write_character(to_char_type(0xB8));
13440  write_number(static_cast<std::uint8_t>(N));
13441  }
13442  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13443  {
13444  oa->write_character(to_char_type(0xB9));
13445  write_number(static_cast<std::uint16_t>(N));
13446  }
13447  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13448  {
13449  oa->write_character(to_char_type(0xBA));
13450  write_number(static_cast<std::uint32_t>(N));
13451  }
13452  // LCOV_EXCL_START
13453  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13454  {
13455  oa->write_character(to_char_type(0xBB));
13456  write_number(static_cast<std::uint64_t>(N));
13457  }
13458  // LCOV_EXCL_STOP
13459 
13460  // step 2: write each element
13461  for (const auto& el : *j.m_value.object)
13462  {
13463  write_cbor(el.first);
13464  write_cbor(el.second);
13465  }
13466  break;
13467  }
13468 
13469  default:
13470  break;
13471  }
13472  }
13473 
13477  void write_msgpack(const BasicJsonType& j)
13478  {
13479  switch (j.type())
13480  {
13481  case value_t::null: // nil
13482  {
13483  oa->write_character(to_char_type(0xC0));
13484  break;
13485  }
13486 
13487  case value_t::boolean: // true and false
13488  {
13489  oa->write_character(j.m_value.boolean
13490  ? to_char_type(0xC3)
13491  : to_char_type(0xC2));
13492  break;
13493  }
13494 
13495  case value_t::number_integer:
13496  {
13497  if (j.m_value.number_integer >= 0)
13498  {
13499  // MessagePack does not differentiate between positive
13500  // signed integers and unsigned integers. Therefore, we used
13501  // the code from the value_t::number_unsigned case here.
13502  if (j.m_value.number_unsigned < 128)
13503  {
13504  // positive fixnum
13505  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13506  }
13507  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13508  {
13509  // uint 8
13510  oa->write_character(to_char_type(0xCC));
13511  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13512  }
13513  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13514  {
13515  // uint 16
13516  oa->write_character(to_char_type(0xCD));
13517  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
13518  }
13519  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13520  {
13521  // uint 32
13522  oa->write_character(to_char_type(0xCE));
13523  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
13524  }
13525  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13526  {
13527  // uint 64
13528  oa->write_character(to_char_type(0xCF));
13529  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
13530  }
13531  }
13532  else
13533  {
13534  if (j.m_value.number_integer >= -32)
13535  {
13536  // negative fixnum
13537  write_number(static_cast<std::int8_t>(j.m_value.number_integer));
13538  }
13539  else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
13540  j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
13541  {
13542  // int 8
13543  oa->write_character(to_char_type(0xD0));
13544  write_number(static_cast<std::int8_t>(j.m_value.number_integer));
13545  }
13546  else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
13547  j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
13548  {
13549  // int 16
13550  oa->write_character(to_char_type(0xD1));
13551  write_number(static_cast<std::int16_t>(j.m_value.number_integer));
13552  }
13553  else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
13554  j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
13555  {
13556  // int 32
13557  oa->write_character(to_char_type(0xD2));
13558  write_number(static_cast<std::int32_t>(j.m_value.number_integer));
13559  }
13560  else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
13561  j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
13562  {
13563  // int 64
13564  oa->write_character(to_char_type(0xD3));
13565  write_number(static_cast<std::int64_t>(j.m_value.number_integer));
13566  }
13567  }
13568  break;
13569  }
13570 
13571  case value_t::number_unsigned:
13572  {
13573  if (j.m_value.number_unsigned < 128)
13574  {
13575  // positive fixnum
13576  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13577  }
13578  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13579  {
13580  // uint 8
13581  oa->write_character(to_char_type(0xCC));
13582  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
13583  }
13584  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13585  {
13586  // uint 16
13587  oa->write_character(to_char_type(0xCD));
13588  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
13589  }
13590  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13591  {
13592  // uint 32
13593  oa->write_character(to_char_type(0xCE));
13594  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
13595  }
13596  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13597  {
13598  // uint 64
13599  oa->write_character(to_char_type(0xCF));
13600  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
13601  }
13602  break;
13603  }
13604 
13605  case value_t::number_float:
13606  {
13607  write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
13608  break;
13609  }
13610 
13611  case value_t::string:
13612  {
13613  // step 1: write control byte and the string length
13614  const auto N = j.m_value.string->size();
13615  if (N <= 31)
13616  {
13617  // fixstr
13618  write_number(static_cast<std::uint8_t>(0xA0 | N));
13619  }
13620  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13621  {
13622  // str 8
13623  oa->write_character(to_char_type(0xD9));
13624  write_number(static_cast<std::uint8_t>(N));
13625  }
13626  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13627  {
13628  // str 16
13629  oa->write_character(to_char_type(0xDA));
13630  write_number(static_cast<std::uint16_t>(N));
13631  }
13632  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13633  {
13634  // str 32
13635  oa->write_character(to_char_type(0xDB));
13636  write_number(static_cast<std::uint32_t>(N));
13637  }
13638 
13639  // step 2: write the string
13640  oa->write_characters(
13641  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
13642  j.m_value.string->size());
13643  break;
13644  }
13645 
13646  case value_t::array:
13647  {
13648  // step 1: write control byte and the array size
13649  const auto N = j.m_value.array->size();
13650  if (N <= 15)
13651  {
13652  // fixarray
13653  write_number(static_cast<std::uint8_t>(0x90 | N));
13654  }
13655  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13656  {
13657  // array 16
13658  oa->write_character(to_char_type(0xDC));
13659  write_number(static_cast<std::uint16_t>(N));
13660  }
13661  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13662  {
13663  // array 32
13664  oa->write_character(to_char_type(0xDD));
13665  write_number(static_cast<std::uint32_t>(N));
13666  }
13667 
13668  // step 2: write each element
13669  for (const auto& el : *j.m_value.array)
13670  {
13671  write_msgpack(el);
13672  }
13673  break;
13674  }
13675 
13676  case value_t::binary:
13677  {
13678  // step 0: determine if the binary type has a set subtype to
13679  // determine whether or not to use the ext or fixext types
13680  const bool use_ext = j.m_value.binary->has_subtype();
13681 
13682  // step 1: write control byte and the byte string length
13683  const auto N = j.m_value.binary->size();
13684  if (N <= (std::numeric_limits<std::uint8_t>::max)())
13685  {
13686  std::uint8_t output_type{};
13687  bool fixed = true;
13688  if (use_ext)
13689  {
13690  switch (N)
13691  {
13692  case 1:
13693  output_type = 0xD4; // fixext 1
13694  break;
13695  case 2:
13696  output_type = 0xD5; // fixext 2
13697  break;
13698  case 4:
13699  output_type = 0xD6; // fixext 4
13700  break;
13701  case 8:
13702  output_type = 0xD7; // fixext 8
13703  break;
13704  case 16:
13705  output_type = 0xD8; // fixext 16
13706  break;
13707  default:
13708  output_type = 0xC7; // ext 8
13709  fixed = false;
13710  break;
13711  }
13712 
13713  }
13714  else
13715  {
13716  output_type = 0xC4; // bin 8
13717  fixed = false;
13718  }
13719 
13720  oa->write_character(to_char_type(output_type));
13721  if (!fixed)
13722  {
13723  write_number(static_cast<std::uint8_t>(N));
13724  }
13725  }
13726  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13727  {
13728  std::uint8_t output_type = use_ext
13729  ? 0xC8 // ext 16
13730  : 0xC5; // bin 16
13731 
13732  oa->write_character(to_char_type(output_type));
13733  write_number(static_cast<std::uint16_t>(N));
13734  }
13735  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13736  {
13737  std::uint8_t output_type = use_ext
13738  ? 0xC9 // ext 32
13739  : 0xC6; // bin 32
13740 
13741  oa->write_character(to_char_type(output_type));
13742  write_number(static_cast<std::uint32_t>(N));
13743  }
13744 
13745  // step 1.5: if this is an ext type, write the subtype
13746  if (use_ext)
13747  {
13748  write_number(static_cast<std::int8_t>(j.m_value.binary->subtype()));
13749  }
13750 
13751  // step 2: write the byte string
13752  oa->write_characters(
13753  reinterpret_cast<const CharType*>(j.m_value.binary->data()),
13754  N);
13755 
13756  break;
13757  }
13758 
13759  case value_t::object:
13760  {
13761  // step 1: write control byte and the object size
13762  const auto N = j.m_value.object->size();
13763  if (N <= 15)
13764  {
13765  // fixmap
13766  write_number(static_cast<std::uint8_t>(0x80 | (N & 0xF)));
13767  }
13768  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13769  {
13770  // map 16
13771  oa->write_character(to_char_type(0xDE));
13772  write_number(static_cast<std::uint16_t>(N));
13773  }
13774  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13775  {
13776  // map 32
13777  oa->write_character(to_char_type(0xDF));
13778  write_number(static_cast<std::uint32_t>(N));
13779  }
13780 
13781  // step 2: write each element
13782  for (const auto& el : *j.m_value.object)
13783  {
13784  write_msgpack(el.first);
13785  write_msgpack(el.second);
13786  }
13787  break;
13788  }
13789 
13790  default:
13791  break;
13792  }
13793  }
13794 
13801  void write_ubjson(const BasicJsonType& j, const bool use_count,
13802  const bool use_type, const bool add_prefix = true)
13803  {
13804  switch (j.type())
13805  {
13806  case value_t::null:
13807  {
13808  if (add_prefix)
13809  {
13810  oa->write_character(to_char_type('Z'));
13811  }
13812  break;
13813  }
13814 
13815  case value_t::boolean:
13816  {
13817  if (add_prefix)
13818  {
13819  oa->write_character(j.m_value.boolean
13820  ? to_char_type('T')
13821  : to_char_type('F'));
13822  }
13823  break;
13824  }
13825 
13826  case value_t::number_integer:
13827  {
13828  write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
13829  break;
13830  }
13831 
13832  case value_t::number_unsigned:
13833  {
13834  write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
13835  break;
13836  }
13837 
13838  case value_t::number_float:
13839  {
13840  write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
13841  break;
13842  }
13843 
13844  case value_t::string:
13845  {
13846  if (add_prefix)
13847  {
13848  oa->write_character(to_char_type('S'));
13849  }
13850  write_number_with_ubjson_prefix(j.m_value.string->size(), true);
13851  oa->write_characters(
13852  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
13853  j.m_value.string->size());
13854  break;
13855  }
13856 
13857  case value_t::array:
13858  {
13859  if (add_prefix)
13860  {
13861  oa->write_character(to_char_type('['));
13862  }
13863 
13864  bool prefix_required = true;
13865  if (use_type && !j.m_value.array->empty())
13866  {
13867  JSON_ASSERT(use_count);
13868  const CharType first_prefix = ubjson_prefix(j.front());
13869  const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
13870  [this, first_prefix](const BasicJsonType & v)
13871  {
13872  return ubjson_prefix(v) == first_prefix;
13873  });
13874 
13875  if (same_prefix)
13876  {
13877  prefix_required = false;
13878  oa->write_character(to_char_type('$'));
13879  oa->write_character(first_prefix);
13880  }
13881  }
13882 
13883  if (use_count)
13884  {
13885  oa->write_character(to_char_type('#'));
13886  write_number_with_ubjson_prefix(j.m_value.array->size(), true);
13887  }
13888 
13889  for (const auto& el : *j.m_value.array)
13890  {
13891  write_ubjson(el, use_count, use_type, prefix_required);
13892  }
13893 
13894  if (!use_count)
13895  {
13896  oa->write_character(to_char_type(']'));
13897  }
13898 
13899  break;
13900  }
13901 
13902  case value_t::binary:
13903  {
13904  if (add_prefix)
13905  {
13906  oa->write_character(to_char_type('['));
13907  }
13908 
13909  if (use_type && !j.m_value.binary->empty())
13910  {
13911  JSON_ASSERT(use_count);
13912  oa->write_character(to_char_type('$'));
13913  oa->write_character('U');
13914  }
13915 
13916  if (use_count)
13917  {
13918  oa->write_character(to_char_type('#'));
13919  write_number_with_ubjson_prefix(j.m_value.binary->size(), true);
13920  }
13921 
13922  if (use_type)
13923  {
13924  oa->write_characters(
13925  reinterpret_cast<const CharType*>(j.m_value.binary->data()),
13926  j.m_value.binary->size());
13927  }
13928  else
13929  {
13930  for (size_t i = 0; i < j.m_value.binary->size(); ++i)
13931  {
13932  oa->write_character(to_char_type('U'));
13933  oa->write_character(j.m_value.binary->data()[i]);
13934  }
13935  }
13936 
13937  if (!use_count)
13938  {
13939  oa->write_character(to_char_type(']'));
13940  }
13941 
13942  break;
13943  }
13944 
13945  case value_t::object:
13946  {
13947  if (add_prefix)
13948  {
13949  oa->write_character(to_char_type('{'));
13950  }
13951 
13952  bool prefix_required = true;
13953  if (use_type && !j.m_value.object->empty())
13954  {
13955  JSON_ASSERT(use_count);
13956  const CharType first_prefix = ubjson_prefix(j.front());
13957  const bool same_prefix = std::all_of(j.begin(), j.end(),
13958  [this, first_prefix](const BasicJsonType & v)
13959  {
13960  return ubjson_prefix(v) == first_prefix;
13961  });
13962 
13963  if (same_prefix)
13964  {
13965  prefix_required = false;
13966  oa->write_character(to_char_type('$'));
13967  oa->write_character(first_prefix);
13968  }
13969  }
13970 
13971  if (use_count)
13972  {
13973  oa->write_character(to_char_type('#'));
13974  write_number_with_ubjson_prefix(j.m_value.object->size(), true);
13975  }
13976 
13977  for (const auto& el : *j.m_value.object)
13978  {
13979  write_number_with_ubjson_prefix(el.first.size(), true);
13980  oa->write_characters(
13981  reinterpret_cast<const CharType*>(el.first.c_str()),
13982  el.first.size());
13983  write_ubjson(el.second, use_count, use_type, prefix_required);
13984  }
13985 
13986  if (!use_count)
13987  {
13988  oa->write_character(to_char_type('}'));
13989  }
13990 
13991  break;
13992  }
13993 
13994  default:
13995  break;
13996  }
13997  }
13998 
13999  private:
14001  // BSON //
14003 
14008  static std::size_t calc_bson_entry_header_size(const string_t& name, const BasicJsonType& j)
14009  {
14010  const auto it = name.find(static_cast<typename string_t::value_type>(0));
14011  if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
14012  {
14013  JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", j));
14014  }
14015 
14016  return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;
14017  }
14018 
14023  const std::uint8_t element_type)
14024  {
14025  oa->write_character(to_char_type(element_type)); // boolean
14026  oa->write_characters(
14027  reinterpret_cast<const CharType*>(name.c_str()),
14028  name.size() + 1u);
14029  }
14030 
14034  void write_bson_boolean(const string_t& name,
14035  const bool value)
14036  {
14037  write_bson_entry_header(name, 0x08);
14038  oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
14039  }
14040 
14044  void write_bson_double(const string_t& name,
14045  const double value)
14046  {
14047  write_bson_entry_header(name, 0x01);
14048  write_number<double, true>(value);
14049  }
14050 
14054  static std::size_t calc_bson_string_size(const string_t& value)
14055  {
14056  return sizeof(std::int32_t) + value.size() + 1ul;
14057  }
14058 
14062  void write_bson_string(const string_t& name,
14063  const string_t& value)
14064  {
14065  write_bson_entry_header(name, 0x02);
14066 
14067  write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size() + 1ul));
14068  oa->write_characters(
14069  reinterpret_cast<const CharType*>(value.c_str()),
14070  value.size() + 1);
14071  }
14072 
14076  void write_bson_null(const string_t& name)
14077  {
14078  write_bson_entry_header(name, 0x0A);
14079  }
14080 
14084  static std::size_t calc_bson_integer_size(const std::int64_t value)
14085  {
14086  return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
14087  ? sizeof(std::int32_t)
14088  : sizeof(std::int64_t);
14089  }
14090 
14094  void write_bson_integer(const string_t& name,
14095  const std::int64_t value)
14096  {
14097  if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
14098  {
14099  write_bson_entry_header(name, 0x10); // int32
14100  write_number<std::int32_t, true>(static_cast<std::int32_t>(value));
14101  }
14102  else
14103  {
14104  write_bson_entry_header(name, 0x12); // int64
14105  write_number<std::int64_t, true>(static_cast<std::int64_t>(value));
14106  }
14107  }
14108 
14112  static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept
14113  {
14114  return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
14115  ? sizeof(std::int32_t)
14116  : sizeof(std::int64_t);
14117  }
14118 
14122  void write_bson_unsigned(const string_t& name,
14123  const BasicJsonType& j)
14124  {
14125  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
14126  {
14127  write_bson_entry_header(name, 0x10 /* int32 */);
14128  write_number<std::int32_t, true>(static_cast<std::int32_t>(j.m_value.number_unsigned));
14129  }
14130  else if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
14131  {
14132  write_bson_entry_header(name, 0x12 /* int64 */);
14133  write_number<std::int64_t, true>(static_cast<std::int64_t>(j.m_value.number_unsigned));
14134  }
14135  else
14136  {
14137  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));
14138  }
14139  }
14140 
14145  const typename BasicJsonType::object_t& value)
14146  {
14147  write_bson_entry_header(name, 0x03); // object
14148  write_bson_object(value);
14149  }
14150 
14154  static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value)
14155  {
14156  std::size_t array_index = 0ul;
14157 
14158  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)
14159  {
14160  return result + calc_bson_element_size(std::to_string(array_index++), el);
14161  });
14162 
14163  return sizeof(std::int32_t) + embedded_document_size + 1ul;
14164  }
14165 
14169  static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t& value)
14170  {
14171  return sizeof(std::int32_t) + value.size() + 1ul;
14172  }
14173 
14177  void write_bson_array(const string_t& name,
14178  const typename BasicJsonType::array_t& value)
14179  {
14180  write_bson_entry_header(name, 0x04); // array
14181  write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_array_size(value)));
14182 
14183  std::size_t array_index = 0ul;
14184 
14185  for (const auto& el : value)
14186  {
14187  write_bson_element(std::to_string(array_index++), el);
14188  }
14189 
14190  oa->write_character(to_char_type(0x00));
14191  }
14192 
14196  void write_bson_binary(const string_t& name,
14197  const binary_t& value)
14198  {
14199  write_bson_entry_header(name, 0x05);
14200 
14201  write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size()));
14202  write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00));
14203 
14204  oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
14205  }
14206 
14211  static std::size_t calc_bson_element_size(const string_t& name,
14212  const BasicJsonType& j)
14213  {
14214  const auto header_size = calc_bson_entry_header_size(name, j);
14215  switch (j.type())
14216  {
14217  case value_t::object:
14218  return header_size + calc_bson_object_size(*j.m_value.object);
14219 
14220  case value_t::array:
14221  return header_size + calc_bson_array_size(*j.m_value.array);
14222 
14223  case value_t::binary:
14224  return header_size + calc_bson_binary_size(*j.m_value.binary);
14225 
14226  case value_t::boolean:
14227  return header_size + 1ul;
14228 
14229  case value_t::number_float:
14230  return header_size + 8ul;
14231 
14232  case value_t::number_integer:
14233  return header_size + calc_bson_integer_size(j.m_value.number_integer);
14234 
14235  case value_t::number_unsigned:
14236  return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
14237 
14238  case value_t::string:
14239  return header_size + calc_bson_string_size(*j.m_value.string);
14240 
14241  case value_t::null:
14242  return header_size + 0ul;
14243 
14244  // LCOV_EXCL_START
14245  default:
14246  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
14247  return 0ul;
14248  // LCOV_EXCL_STOP
14249  }
14250  }
14251 
14258  void write_bson_element(const string_t& name,
14259  const BasicJsonType& j)
14260  {
14261  switch (j.type())
14262  {
14263  case value_t::object:
14264  return write_bson_object_entry(name, *j.m_value.object);
14265 
14266  case value_t::array:
14267  return write_bson_array(name, *j.m_value.array);
14268 
14269  case value_t::binary:
14270  return write_bson_binary(name, *j.m_value.binary);
14271 
14272  case value_t::boolean:
14273  return write_bson_boolean(name, j.m_value.boolean);
14274 
14275  case value_t::number_float:
14276  return write_bson_double(name, j.m_value.number_float);
14277 
14278  case value_t::number_integer:
14279  return write_bson_integer(name, j.m_value.number_integer);
14280 
14281  case value_t::number_unsigned:
14282  return write_bson_unsigned(name, j);
14283 
14284  case value_t::string:
14285  return write_bson_string(name, *j.m_value.string);
14286 
14287  case value_t::null:
14288  return write_bson_null(name);
14289 
14290  // LCOV_EXCL_START
14291  default:
14292  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
14293  return;
14294  // LCOV_EXCL_STOP
14295  }
14296  }
14297 
14304  static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value)
14305  {
14306  std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
14307  [](size_t result, const typename BasicJsonType::object_t::value_type & el)
14308  {
14309  return result += calc_bson_element_size(el.first, el.second);
14310  });
14311 
14312  return sizeof(std::int32_t) + document_size + 1ul;
14313  }
14314 
14319  void write_bson_object(const typename BasicJsonType::object_t& value)
14320  {
14321  write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_object_size(value)));
14322 
14323  for (const auto& el : value)
14324  {
14325  write_bson_element(el.first, el.second);
14326  }
14327 
14328  oa->write_character(to_char_type(0x00));
14329  }
14330 
14332  // CBOR //
14334 
14335  static constexpr CharType get_cbor_float_prefix(float /*unused*/)
14336  {
14337  return to_char_type(0xFA); // Single-Precision Float
14338  }
14339 
14340  static constexpr CharType get_cbor_float_prefix(double /*unused*/)
14341  {
14342  return to_char_type(0xFB); // Double-Precision Float
14343  }
14344 
14346  // MsgPack //
14348 
14349  static constexpr CharType get_msgpack_float_prefix(float /*unused*/)
14350  {
14351  return to_char_type(0xCA); // float 32
14352  }
14353 
14354  static constexpr CharType get_msgpack_float_prefix(double /*unused*/)
14355  {
14356  return to_char_type(0xCB); // float 64
14357  }
14358 
14360  // UBJSON //
14362 
14363  // UBJSON: write number (floating point)
14364  template<typename NumberType, typename std::enable_if<
14366  void write_number_with_ubjson_prefix(const NumberType n,
14367  const bool add_prefix)
14368  {
14369  if (add_prefix)
14370  {
14371  oa->write_character(get_ubjson_float_prefix(n));
14372  }
14373  write_number(n);
14374  }
14375 
14376  // UBJSON: write number (unsigned integer)
14377  template<typename NumberType, typename std::enable_if<
14379  void write_number_with_ubjson_prefix(const NumberType n,
14380  const bool add_prefix)
14381  {
14382  if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
14383  {
14384  if (add_prefix)
14385  {
14386  oa->write_character(to_char_type('i')); // int8
14387  }
14388  write_number(static_cast<std::uint8_t>(n));
14389  }
14390  else if (n <= (std::numeric_limits<std::uint8_t>::max)())
14391  {
14392  if (add_prefix)
14393  {
14394  oa->write_character(to_char_type('U')); // uint8
14395  }
14396  write_number(static_cast<std::uint8_t>(n));
14397  }
14398  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
14399  {
14400  if (add_prefix)
14401  {
14402  oa->write_character(to_char_type('I')); // int16
14403  }
14404  write_number(static_cast<std::int16_t>(n));
14405  }
14406  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
14407  {
14408  if (add_prefix)
14409  {
14410  oa->write_character(to_char_type('l')); // int32
14411  }
14412  write_number(static_cast<std::int32_t>(n));
14413  }
14414  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
14415  {
14416  if (add_prefix)
14417  {
14418  oa->write_character(to_char_type('L')); // int64
14419  }
14420  write_number(static_cast<std::int64_t>(n));
14421  }
14422  else
14423  {
14424  if (add_prefix)
14425  {
14426  oa->write_character(to_char_type('H')); // high-precision number
14427  }
14428 
14429  const auto number = BasicJsonType(n).dump();
14430  write_number_with_ubjson_prefix(number.size(), true);
14431  for (std::size_t i = 0; i < number.size(); ++i)
14432  {
14433  oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));
14434  }
14435  }
14436  }
14437 
14438  // UBJSON: write number (signed integer)
14439  template < typename NumberType, typename std::enable_if <
14442  void write_number_with_ubjson_prefix(const NumberType n,
14443  const bool add_prefix)
14444  {
14445  if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
14446  {
14447  if (add_prefix)
14448  {
14449  oa->write_character(to_char_type('i')); // int8
14450  }
14451  write_number(static_cast<std::int8_t>(n));
14452  }
14453  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)()))
14454  {
14455  if (add_prefix)
14456  {
14457  oa->write_character(to_char_type('U')); // uint8
14458  }
14459  write_number(static_cast<std::uint8_t>(n));
14460  }
14461  else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
14462  {
14463  if (add_prefix)
14464  {
14465  oa->write_character(to_char_type('I')); // int16
14466  }
14467  write_number(static_cast<std::int16_t>(n));
14468  }
14469  else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
14470  {
14471  if (add_prefix)
14472  {
14473  oa->write_character(to_char_type('l')); // int32
14474  }
14475  write_number(static_cast<std::int32_t>(n));
14476  }
14477  else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
14478  {
14479  if (add_prefix)
14480  {
14481  oa->write_character(to_char_type('L')); // int64
14482  }
14483  write_number(static_cast<std::int64_t>(n));
14484  }
14485  // LCOV_EXCL_START
14486  else
14487  {
14488  if (add_prefix)
14489  {
14490  oa->write_character(to_char_type('H')); // high-precision number
14491  }
14492 
14493  const auto number = BasicJsonType(n).dump();
14494  write_number_with_ubjson_prefix(number.size(), true);
14495  for (std::size_t i = 0; i < number.size(); ++i)
14496  {
14497  oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));
14498  }
14499  }
14500  // LCOV_EXCL_STOP
14501  }
14502 
14506  CharType ubjson_prefix(const BasicJsonType& j) const noexcept
14507  {
14508  switch (j.type())
14509  {
14510  case value_t::null:
14511  return 'Z';
14512 
14513  case value_t::boolean:
14514  return j.m_value.boolean ? 'T' : 'F';
14515 
14516  case value_t::number_integer:
14517  {
14518  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)())
14519  {
14520  return 'i';
14521  }
14522  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)())
14523  {
14524  return 'U';
14525  }
14526  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)())
14527  {
14528  return 'I';
14529  }
14530  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)())
14531  {
14532  return 'l';
14533  }
14534  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)())
14535  {
14536  return 'L';
14537  }
14538  // anything else is treated as high-precision number
14539  return 'H'; // LCOV_EXCL_LINE
14540  }
14541 
14542  case value_t::number_unsigned:
14543  {
14544  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
14545  {
14546  return 'i';
14547  }
14548  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint8_t>::max)()))
14549  {
14550  return 'U';
14551  }
14552  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
14553  {
14554  return 'I';
14555  }
14556  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
14557  {
14558  return 'l';
14559  }
14560  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
14561  {
14562  return 'L';
14563  }
14564  // anything else is treated as high-precision number
14565  return 'H'; // LCOV_EXCL_LINE
14566  }
14567 
14568  case value_t::number_float:
14569  return get_ubjson_float_prefix(j.m_value.number_float);
14570 
14571  case value_t::string:
14572  return 'S';
14573 
14574  case value_t::array: // fallthrough
14575  case value_t::binary:
14576  return '[';
14577 
14578  case value_t::object:
14579  return '{';
14580 
14581  default: // discarded values
14582  return 'N';
14583  }
14584  }
14585 
14586  static constexpr CharType get_ubjson_float_prefix(float /*unused*/)
14587  {
14588  return 'd'; // float 32
14589  }
14590 
14591  static constexpr CharType get_ubjson_float_prefix(double /*unused*/)
14592  {
14593  return 'D'; // float 64
14594  }
14595 
14597  // Utility functions //
14599 
14600  /*
14601  @brief write a number to output input
14602  @param[in] n number of type @a NumberType
14603  @tparam NumberType the type of the number
14604  @tparam OutputIsLittleEndian Set to true if output data is
14605  required to be little endian
14606 
14607  @note This function needs to respect the system's endianess, because bytes
14608  in CBOR, MessagePack, and UBJSON are stored in network order (big
14609  endian) and therefore need reordering on little endian systems.
14610  */
14611  template<typename NumberType, bool OutputIsLittleEndian = false>
14612  void write_number(const NumberType n)
14613  {
14614  // step 1: write number to array of length NumberType
14615  std::array<CharType, sizeof(NumberType)> vec{};
14616  std::memcpy(vec.data(), &n, sizeof(NumberType));
14617 
14618  // step 2: write array to output (with possible reordering)
14619  if (is_little_endian != OutputIsLittleEndian)
14620  {
14621  // reverse byte order prior to conversion if necessary
14622  std::reverse(vec.begin(), vec.end());
14623  }
14624 
14625  oa->write_characters(vec.data(), sizeof(NumberType));
14626  }
14627 
14629  {
14630  if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) &&
14631  static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&
14632  static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))
14633  {
14634  oa->write_character(format == detail::input_format_t::cbor
14635  ? get_cbor_float_prefix(static_cast<float>(n))
14636  : get_msgpack_float_prefix(static_cast<float>(n)));
14637  write_number(static_cast<float>(n));
14638  }
14639  else
14640  {
14641  oa->write_character(format == detail::input_format_t::cbor
14642  ? get_cbor_float_prefix(n)
14643  : get_msgpack_float_prefix(n));
14644  write_number(n);
14645  }
14646  }
14647 
14648  public:
14649  // The following to_char_type functions are implement the conversion
14650  // between uint8_t and CharType. In case CharType is not unsigned,
14651  // such a conversion is required to allow values greater than 128.
14652  // See <https://github.com/nlohmann/json/issues/1286> for a discussion.
14653  template < typename C = CharType,
14655  static constexpr CharType to_char_type(std::uint8_t x) noexcept
14656  {
14657  return *reinterpret_cast<char*>(&x);
14658  }
14659 
14660  template < typename C = CharType,
14662  static CharType to_char_type(std::uint8_t x) noexcept
14663  {
14664  static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
14665  static_assert(std::is_trivial<CharType>::value, "CharType must be trivial");
14666  CharType result;
14667  std::memcpy(&result, &x, sizeof(x));
14668  return result;
14669  }
14670 
14671  template<typename C = CharType,
14673  static constexpr CharType to_char_type(std::uint8_t x) noexcept
14674  {
14675  return x;
14676  }
14677 
14678  template < typename InputCharType, typename C = CharType,
14679  enable_if_t <
14683  > * = nullptr >
14684  static constexpr CharType to_char_type(InputCharType x) noexcept
14685  {
14686  return x;
14687  }
14688 
14689  private:
14692 
14695 };
14696 } // namespace detail
14697 } // namespace nlohmann
14698 
14699 // #include <nlohmann/detail/output/output_adapters.hpp>
14700 
14701 // #include <nlohmann/detail/output/serializer.hpp>
14702 
14703 
14704 #include <algorithm> // reverse, remove, fill, find, none_of
14705 #include <array> // array
14706 #include <clocale> // localeconv, lconv
14707 #include <cmath> // labs, isfinite, isnan, signbit
14708 #include <cstddef> // size_t, ptrdiff_t
14709 #include <cstdint> // uint8_t
14710 #include <cstdio> // snprintf
14711 #include <limits> // numeric_limits
14712 #include <string> // string, char_traits
14713 #include <type_traits> // is_same
14714 #include <utility> // move
14715 
14716 // #include <nlohmann/detail/conversions/to_chars.hpp>
14717 
14718 
14719 #include <array> // array
14720 #include <cmath> // signbit, isfinite
14721 #include <cstdint> // intN_t, uintN_t
14722 #include <cstring> // memcpy, memmove
14723 #include <limits> // numeric_limits
14724 #include <type_traits> // conditional
14725 
14726 // #include <nlohmann/detail/macro_scope.hpp>
14727 
14728 
14729 namespace nlohmann
14730 {
14731 namespace detail
14732 {
14733 
14753 namespace dtoa_impl
14754 {
14755 
14756 template<typename Target, typename Source>
14757 Target reinterpret_bits(const Source source)
14758 {
14759  static_assert(sizeof(Target) == sizeof(Source), "size mismatch");
14760 
14761  Target target;
14762  std::memcpy(&target, &source, sizeof(Source));
14763  return target;
14764 }
14765 
14766 struct diyfp // f * 2^e
14767 {
14768  static constexpr int kPrecision = 64; // = q
14769 
14771  int e = 0;
14772 
14773  constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {}
14774 
14779  static diyfp sub(const diyfp& x, const diyfp& y) noexcept
14780  {
14781  JSON_ASSERT(x.e == y.e);
14782  JSON_ASSERT(x.f >= y.f);
14783 
14784  return {x.f - y.f, x.e};
14785  }
14786 
14791  static diyfp mul(const diyfp& x, const diyfp& y) noexcept
14792  {
14793  static_assert(kPrecision == 64, "internal error");
14794 
14795  // Computes:
14796  // f = round((x.f * y.f) / 2^q)
14797  // e = x.e + y.e + q
14798 
14799  // Emulate the 64-bit * 64-bit multiplication:
14800  //
14801  // p = u * v
14802  // = (u_lo + 2^32 u_hi) (v_lo + 2^32 v_hi)
14803  // = (u_lo v_lo ) + 2^32 ((u_lo v_hi ) + (u_hi v_lo )) + 2^64 (u_hi v_hi )
14804  // = (p0 ) + 2^32 ((p1 ) + (p2 )) + 2^64 (p3 )
14805  // = (p0_lo + 2^32 p0_hi) + 2^32 ((p1_lo + 2^32 p1_hi) + (p2_lo + 2^32 p2_hi)) + 2^64 (p3 )
14806  // = (p0_lo ) + 2^32 (p0_hi + p1_lo + p2_lo ) + 2^64 (p1_hi + p2_hi + p3)
14807  // = (p0_lo ) + 2^32 (Q ) + 2^64 (H )
14808  // = (p0_lo ) + 2^32 (Q_lo + 2^32 Q_hi ) + 2^64 (H )
14809  //
14810  // (Since Q might be larger than 2^32 - 1)
14811  //
14812  // = (p0_lo + 2^32 Q_lo) + 2^64 (Q_hi + H)
14813  //
14814  // (Q_hi + H does not overflow a 64-bit int)
14815  //
14816  // = p_lo + 2^64 p_hi
14817 
14818  const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
14819  const std::uint64_t u_hi = x.f >> 32u;
14820  const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
14821  const std::uint64_t v_hi = y.f >> 32u;
14822 
14823  const std::uint64_t p0 = u_lo * v_lo;
14824  const std::uint64_t p1 = u_lo * v_hi;
14825  const std::uint64_t p2 = u_hi * v_lo;
14826  const std::uint64_t p3 = u_hi * v_hi;
14827 
14828  const std::uint64_t p0_hi = p0 >> 32u;
14829  const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
14830  const std::uint64_t p1_hi = p1 >> 32u;
14831  const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
14832  const std::uint64_t p2_hi = p2 >> 32u;
14833 
14834  std::uint64_t Q = p0_hi + p1_lo + p2_lo;
14835 
14836  // The full product might now be computed as
14837  //
14838  // p_hi = p3 + p2_hi + p1_hi + (Q >> 32)
14839  // p_lo = p0_lo + (Q << 32)
14840  //
14841  // But in this particular case here, the full p_lo is not required.
14842  // Effectively we only need to add the highest bit in p_lo to p_hi (and
14843  // Q_hi + 1 does not overflow).
14844 
14845  Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up
14846 
14847  const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
14848 
14849  return {h, x.e + y.e + 64};
14850  }
14851 
14856  static diyfp normalize(diyfp x) noexcept
14857  {
14858  JSON_ASSERT(x.f != 0);
14859 
14860  while ((x.f >> 63u) == 0)
14861  {
14862  x.f <<= 1u;
14863  x.e--;
14864  }
14865 
14866  return x;
14867  }
14868 
14873  static diyfp normalize_to(const diyfp& x, const int target_exponent) noexcept
14874  {
14875  const int delta = x.e - target_exponent;
14876 
14877  JSON_ASSERT(delta >= 0);
14878  JSON_ASSERT(((x.f << delta) >> delta) == x.f);
14879 
14880  return {x.f << delta, target_exponent};
14881  }
14882 };
14883 
14885 {
14889 };
14890 
14897 template<typename FloatType>
14899 {
14900  JSON_ASSERT(std::isfinite(value));
14901  JSON_ASSERT(value > 0);
14902 
14903  // Convert the IEEE representation into a diyfp.
14904  //
14905  // If v is denormal:
14906  // value = 0.F * 2^(1 - bias) = ( F) * 2^(1 - bias - (p-1))
14907  // If v is normalized:
14908  // value = 1.F * 2^(E - bias) = (2^(p-1) + F) * 2^(E - bias - (p-1))
14909 
14910  static_assert(std::numeric_limits<FloatType>::is_iec559,
14911  "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
14912 
14913  constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit)
14914  constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
14915  constexpr int kMinExp = 1 - kBias;
14916  constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1)
14917 
14919 
14920  const auto bits = static_cast<std::uint64_t>(reinterpret_bits<bits_type>(value));
14921  const std::uint64_t E = bits >> (kPrecision - 1);
14922  const std::uint64_t F = bits & (kHiddenBit - 1);
14923 
14924  const bool is_denormal = E == 0;
14925  const diyfp v = is_denormal
14926  ? diyfp(F, kMinExp)
14927  : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
14928 
14929  // Compute the boundaries m- and m+ of the floating-point value
14930  // v = f * 2^e.
14931  //
14932  // Determine v- and v+, the floating-point predecessor and successor if v,
14933  // respectively.
14934  //
14935  // v- = v - 2^e if f != 2^(p-1) or e == e_min (A)
14936  // = v - 2^(e-1) if f == 2^(p-1) and e > e_min (B)
14937  //
14938  // v+ = v + 2^e
14939  //
14940  // Let m- = (v- + v) / 2 and m+ = (v + v+) / 2. All real numbers _strictly_
14941  // between m- and m+ round to v, regardless of how the input rounding
14942  // algorithm breaks ties.
14943  //
14944  // ---+-------------+-------------+-------------+-------------+--- (A)
14945  // v- m- v m+ v+
14946  //
14947  // -----------------+------+------+-------------+-------------+--- (B)
14948  // v- m- v m+ v+
14949 
14950  const bool lower_boundary_is_closer = F == 0 && E > 1;
14951  const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
14952  const diyfp m_minus = lower_boundary_is_closer
14953  ? diyfp(4 * v.f - 1, v.e - 2) // (B)
14954  : diyfp(2 * v.f - 1, v.e - 1); // (A)
14955 
14956  // Determine the normalized w+ = m+.
14957  const diyfp w_plus = diyfp::normalize(m_plus);
14958 
14959  // Determine w- = m- such that e_(w-) = e_(w+).
14960  const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
14961 
14962  return {diyfp::normalize(v), w_minus, w_plus};
14963 }
14964 
14965 // Given normalized diyfp w, Grisu needs to find a (normalized) cached
14966 // power-of-ten c, such that the exponent of the product c * w = f * 2^e lies
14967 // within a certain range [alpha, gamma] (Definition 3.2 from [1])
14968 //
14969 // alpha <= e = e_c + e_w + q <= gamma
14970 //
14971 // or
14972 //
14973 // f_c * f_w * 2^alpha <= f_c 2^(e_c) * f_w 2^(e_w) * 2^q
14974 // <= f_c * f_w * 2^gamma
14975 //
14976 // Since c and w are normalized, i.e. 2^(q-1) <= f < 2^q, this implies
14977 //
14978 // 2^(q-1) * 2^(q-1) * 2^alpha <= c * w * 2^q < 2^q * 2^q * 2^gamma
14979 //
14980 // or
14981 //
14982 // 2^(q - 2 + alpha) <= c * w < 2^(q + gamma)
14983 //
14984 // The choice of (alpha,gamma) determines the size of the table and the form of
14985 // the digit generation procedure. Using (alpha,gamma)=(-60,-32) works out well
14986 // in practice:
14987 //
14988 // The idea is to cut the number c * w = f * 2^e into two parts, which can be
14989 // processed independently: An integral part p1, and a fractional part p2:
14990 //
14991 // f * 2^e = ( (f div 2^-e) * 2^-e + (f mod 2^-e) ) * 2^e
14992 // = (f div 2^-e) + (f mod 2^-e) * 2^e
14993 // = p1 + p2 * 2^e
14994 //
14995 // The conversion of p1 into decimal form requires a series of divisions and
14996 // modulos by (a power of) 10. These operations are faster for 32-bit than for
14997 // 64-bit integers, so p1 should ideally fit into a 32-bit integer. This can be
14998 // achieved by choosing
14999 //
15000 // -e >= 32 or e <= -32 := gamma
15001 //
15002 // In order to convert the fractional part
15003 //
15004 // p2 * 2^e = p2 / 2^-e = d[-1] / 10^1 + d[-2] / 10^2 + ...
15005 //
15006 // into decimal form, the fraction is repeatedly multiplied by 10 and the digits
15007 // d[-i] are extracted in order:
15008 //
15009 // (10 * p2) div 2^-e = d[-1]
15010 // (10 * p2) mod 2^-e = d[-2] / 10^1 + ...
15011 //
15012 // The multiplication by 10 must not overflow. It is sufficient to choose
15013 //
15014 // 10 * p2 < 16 * p2 = 2^4 * p2 <= 2^64.
15015 //
15016 // Since p2 = f mod 2^-e < 2^-e,
15017 //
15018 // -e <= 60 or e >= -60 := alpha
15019 
15020 constexpr int kAlpha = -60;
15021 constexpr int kGamma = -32;
15022 
15023 struct cached_power // c = f * 2^e ~= 10^k
15024 {
15026  int e;
15027  int k;
15028 };
15029 
15038 {
15039  // Now
15040  //
15041  // alpha <= e_c + e + q <= gamma (1)
15042  // ==> f_c * 2^alpha <= c * 2^e * 2^q
15043  //
15044  // and since the c's are normalized, 2^(q-1) <= f_c,
15045  //
15046  // ==> 2^(q - 1 + alpha) <= c * 2^(e + q)
15047  // ==> 2^(alpha - e - 1) <= c
15048  //
15049  // If c were an exact power of ten, i.e. c = 10^k, one may determine k as
15050  //
15051  // k = ceil( log_10( 2^(alpha - e - 1) ) )
15052  // = ceil( (alpha - e - 1) * log_10(2) )
15053  //
15054  // From the paper:
15055  // "In theory the result of the procedure could be wrong since c is rounded,
15056  // and the computation itself is approximated [...]. In practice, however,
15057  // this simple function is sufficient."
15058  //
15059  // For IEEE double precision floating-point numbers converted into
15060  // normalized diyfp's w = f * 2^e, with q = 64,
15061  //
15062  // e >= -1022 (min IEEE exponent)
15063  // -52 (p - 1)
15064  // -52 (p - 1, possibly normalize denormal IEEE numbers)
15065  // -11 (normalize the diyfp)
15066  // = -1137
15067  //
15068  // and
15069  //
15070  // e <= +1023 (max IEEE exponent)
15071  // -52 (p - 1)
15072  // -11 (normalize the diyfp)
15073  // = 960
15074  //
15075  // This binary exponent range [-1137,960] results in a decimal exponent
15076  // range [-307,324]. One does not need to store a cached power for each
15077  // k in this range. For each such k it suffices to find a cached power
15078  // such that the exponent of the product lies in [alpha,gamma].
15079  // This implies that the difference of the decimal exponents of adjacent
15080  // table entries must be less than or equal to
15081  //
15082  // floor( (gamma - alpha) * log_10(2) ) = 8.
15083  //
15084  // (A smaller distance gamma-alpha would require a larger table.)
15085 
15086  // NB:
15087  // Actually this function returns c, such that -60 <= e_c + e + 64 <= -34.
15088 
15089  constexpr int kCachedPowersMinDecExp = -300;
15090  constexpr int kCachedPowersDecStep = 8;
15091 
15092  static constexpr std::array<cached_power, 79> kCachedPowers =
15093  {
15094  {
15095  { 0xAB70FE17C79AC6CA, -1060, -300 },
15096  { 0xFF77B1FCBEBCDC4F, -1034, -292 },
15097  { 0xBE5691EF416BD60C, -1007, -284 },
15098  { 0x8DD01FAD907FFC3C, -980, -276 },
15099  { 0xD3515C2831559A83, -954, -268 },
15100  { 0x9D71AC8FADA6C9B5, -927, -260 },
15101  { 0xEA9C227723EE8BCB, -901, -252 },
15102  { 0xAECC49914078536D, -874, -244 },
15103  { 0x823C12795DB6CE57, -847, -236 },
15104  { 0xC21094364DFB5637, -821, -228 },
15105  { 0x9096EA6F3848984F, -794, -220 },
15106  { 0xD77485CB25823AC7, -768, -212 },
15107  { 0xA086CFCD97BF97F4, -741, -204 },
15108  { 0xEF340A98172AACE5, -715, -196 },
15109  { 0xB23867FB2A35B28E, -688, -188 },
15110  { 0x84C8D4DFD2C63F3B, -661, -180 },
15111  { 0xC5DD44271AD3CDBA, -635, -172 },
15112  { 0x936B9FCEBB25C996, -608, -164 },
15113  { 0xDBAC6C247D62A584, -582, -156 },
15114  { 0xA3AB66580D5FDAF6, -555, -148 },
15115  { 0xF3E2F893DEC3F126, -529, -140 },
15116  { 0xB5B5ADA8AAFF80B8, -502, -132 },
15117  { 0x87625F056C7C4A8B, -475, -124 },
15118  { 0xC9BCFF6034C13053, -449, -116 },
15119  { 0x964E858C91BA2655, -422, -108 },
15120  { 0xDFF9772470297EBD, -396, -100 },
15121  { 0xA6DFBD9FB8E5B88F, -369, -92 },
15122  { 0xF8A95FCF88747D94, -343, -84 },
15123  { 0xB94470938FA89BCF, -316, -76 },
15124  { 0x8A08F0F8BF0F156B, -289, -68 },
15125  { 0xCDB02555653131B6, -263, -60 },
15126  { 0x993FE2C6D07B7FAC, -236, -52 },
15127  { 0xE45C10C42A2B3B06, -210, -44 },
15128  { 0xAA242499697392D3, -183, -36 },
15129  { 0xFD87B5F28300CA0E, -157, -28 },
15130  { 0xBCE5086492111AEB, -130, -20 },
15131  { 0x8CBCCC096F5088CC, -103, -12 },
15132  { 0xD1B71758E219652C, -77, -4 },
15133  { 0x9C40000000000000, -50, 4 },
15134  { 0xE8D4A51000000000, -24, 12 },
15135  { 0xAD78EBC5AC620000, 3, 20 },
15136  { 0x813F3978F8940984, 30, 28 },
15137  { 0xC097CE7BC90715B3, 56, 36 },
15138  { 0x8F7E32CE7BEA5C70, 83, 44 },
15139  { 0xD5D238A4ABE98068, 109, 52 },
15140  { 0x9F4F2726179A2245, 136, 60 },
15141  { 0xED63A231D4C4FB27, 162, 68 },
15142  { 0xB0DE65388CC8ADA8, 189, 76 },
15143  { 0x83C7088E1AAB65DB, 216, 84 },
15144  { 0xC45D1DF942711D9A, 242, 92 },
15145  { 0x924D692CA61BE758, 269, 100 },
15146  { 0xDA01EE641A708DEA, 295, 108 },
15147  { 0xA26DA3999AEF774A, 322, 116 },
15148  { 0xF209787BB47D6B85, 348, 124 },
15149  { 0xB454E4A179DD1877, 375, 132 },
15150  { 0x865B86925B9BC5C2, 402, 140 },
15151  { 0xC83553C5C8965D3D, 428, 148 },
15152  { 0x952AB45CFA97A0B3, 455, 156 },
15153  { 0xDE469FBD99A05FE3, 481, 164 },
15154  { 0xA59BC234DB398C25, 508, 172 },
15155  { 0xF6C69A72A3989F5C, 534, 180 },
15156  { 0xB7DCBF5354E9BECE, 561, 188 },
15157  { 0x88FCF317F22241E2, 588, 196 },
15158  { 0xCC20CE9BD35C78A5, 614, 204 },
15159  { 0x98165AF37B2153DF, 641, 212 },
15160  { 0xE2A0B5DC971F303A, 667, 220 },
15161  { 0xA8D9D1535CE3B396, 694, 228 },
15162  { 0xFB9B7CD9A4A7443C, 720, 236 },
15163  { 0xBB764C4CA7A44410, 747, 244 },
15164  { 0x8BAB8EEFB6409C1A, 774, 252 },
15165  { 0xD01FEF10A657842C, 800, 260 },
15166  { 0x9B10A4E5E9913129, 827, 268 },
15167  { 0xE7109BFBA19C0C9D, 853, 276 },
15168  { 0xAC2820D9623BF429, 880, 284 },
15169  { 0x80444B5E7AA7CF85, 907, 292 },
15170  { 0xBF21E44003ACDD2D, 933, 300 },
15171  { 0x8E679C2F5E44FF8F, 960, 308 },
15172  { 0xD433179D9C8CB841, 986, 316 },
15173  { 0x9E19DB92B4E31BA9, 1013, 324 },
15174  }
15175  };
15176 
15177  // This computation gives exactly the same results for k as
15178  // k = ceil((kAlpha - e - 1) * 0.30102999566398114)
15179  // for |e| <= 1500, but doesn't require floating-point operations.
15180  // NB: log_10(2) ~= 78913 / 2^18
15181  JSON_ASSERT(e >= -1500);
15182  JSON_ASSERT(e <= 1500);
15183  const int f = kAlpha - e - 1;
15184  const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0);
15185 
15186  const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
15187  JSON_ASSERT(index >= 0);
15188  JSON_ASSERT(static_cast<std::size_t>(index) < kCachedPowers.size());
15189 
15190  const cached_power cached = kCachedPowers[static_cast<std::size_t>(index)];
15191  JSON_ASSERT(kAlpha <= cached.e + e + 64);
15192  JSON_ASSERT(kGamma >= cached.e + e + 64);
15193 
15194  return cached;
15195 }
15196 
15202 {
15203  // LCOV_EXCL_START
15204  if (n >= 1000000000)
15205  {
15206  pow10 = 1000000000;
15207  return 10;
15208  }
15209  // LCOV_EXCL_STOP
15210  if (n >= 100000000)
15211  {
15212  pow10 = 100000000;
15213  return 9;
15214  }
15215  if (n >= 10000000)
15216  {
15217  pow10 = 10000000;
15218  return 8;
15219  }
15220  if (n >= 1000000)
15221  {
15222  pow10 = 1000000;
15223  return 7;
15224  }
15225  if (n >= 100000)
15226  {
15227  pow10 = 100000;
15228  return 6;
15229  }
15230  if (n >= 10000)
15231  {
15232  pow10 = 10000;
15233  return 5;
15234  }
15235  if (n >= 1000)
15236  {
15237  pow10 = 1000;
15238  return 4;
15239  }
15240  if (n >= 100)
15241  {
15242  pow10 = 100;
15243  return 3;
15244  }
15245  if (n >= 10)
15246  {
15247  pow10 = 10;
15248  return 2;
15249  }
15250 
15251  pow10 = 1;
15252  return 1;
15253 }
15254 
15255 inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,
15256  std::uint64_t rest, std::uint64_t ten_k)
15257 {
15258  JSON_ASSERT(len >= 1);
15259  JSON_ASSERT(dist <= delta);
15260  JSON_ASSERT(rest <= delta);
15261  JSON_ASSERT(ten_k > 0);
15262 
15263  // <--------------------------- delta ---->
15264  // <---- dist --------->
15265  // --------------[------------------+-------------------]--------------
15266  // M- w M+
15267  //
15268  // ten_k
15269  // <------>
15270  // <---- rest ---->
15271  // --------------[------------------+----+--------------]--------------
15272  // w V
15273  // = buf * 10^k
15274  //
15275  // ten_k represents a unit-in-the-last-place in the decimal representation
15276  // stored in buf.
15277  // Decrement buf by ten_k while this takes buf closer to w.
15278 
15279  // The tests are written in this order to avoid overflow in unsigned
15280  // integer arithmetic.
15281 
15282  while (rest < dist
15283  && delta - rest >= ten_k
15284  && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
15285  {
15286  JSON_ASSERT(buf[len - 1] != '0');
15287  buf[len - 1]--;
15288  rest += ten_k;
15289  }
15290 }
15291 
15296 inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,
15297  diyfp M_minus, diyfp w, diyfp M_plus)
15298 {
15299  static_assert(kAlpha >= -60, "internal error");
15300  static_assert(kGamma <= -32, "internal error");
15301 
15302  // Generates the digits (and the exponent) of a decimal floating-point
15303  // number V = buffer * 10^decimal_exponent in the range [M-, M+]. The diyfp's
15304  // w, M- and M+ share the same exponent e, which satisfies alpha <= e <= gamma.
15305  //
15306  // <--------------------------- delta ---->
15307  // <---- dist --------->
15308  // --------------[------------------+-------------------]--------------
15309  // M- w M+
15310  //
15311  // Grisu2 generates the digits of M+ from left to right and stops as soon as
15312  // V is in [M-,M+].
15313 
15314  JSON_ASSERT(M_plus.e >= kAlpha);
15315  JSON_ASSERT(M_plus.e <= kGamma);
15316 
15317  std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e)
15318  std::uint64_t dist = diyfp::sub(M_plus, w ).f; // (significand of (M+ - w ), implicit exponent is e)
15319 
15320  // Split M+ = f * 2^e into two parts p1 and p2 (note: e < 0):
15321  //
15322  // M+ = f * 2^e
15323  // = ((f div 2^-e) * 2^-e + (f mod 2^-e)) * 2^e
15324  // = ((p1 ) * 2^-e + (p2 )) * 2^e
15325  // = p1 + p2 * 2^e
15326 
15327  const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
15328 
15329  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.)
15330  std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e
15331 
15332  // 1)
15333  //
15334  // Generate the digits of the integral part p1 = d[n-1]...d[1]d[0]
15335 
15336  JSON_ASSERT(p1 > 0);
15337 
15338  std::uint32_t pow10{};
15339  const int k = find_largest_pow10(p1, pow10);
15340 
15341  // 10^(k-1) <= p1 < 10^k, pow10 = 10^(k-1)
15342  //
15343  // p1 = (p1 div 10^(k-1)) * 10^(k-1) + (p1 mod 10^(k-1))
15344  // = (d[k-1] ) * 10^(k-1) + (p1 mod 10^(k-1))
15345  //
15346  // M+ = p1 + p2 * 2^e
15347  // = d[k-1] * 10^(k-1) + (p1 mod 10^(k-1)) + p2 * 2^e
15348  // = d[k-1] * 10^(k-1) + ((p1 mod 10^(k-1)) * 2^-e + p2) * 2^e
15349  // = d[k-1] * 10^(k-1) + ( rest) * 2^e
15350  //
15351  // Now generate the digits d[n] of p1 from left to right (n = k-1,...,0)
15352  //
15353  // p1 = d[k-1]...d[n] * 10^n + d[n-1]...d[0]
15354  //
15355  // but stop as soon as
15356  //
15357  // rest * 2^e = (d[n-1]...d[0] * 2^-e + p2) * 2^e <= delta * 2^e
15358 
15359  int n = k;
15360  while (n > 0)
15361  {
15362  // Invariants:
15363  // M+ = buffer * 10^n + (p1 + p2 * 2^e) (buffer = 0 for n = k)
15364  // pow10 = 10^(n-1) <= p1 < 10^n
15365  //
15366  const std::uint32_t d = p1 / pow10; // d = p1 div 10^(n-1)
15367  const std::uint32_t r = p1 % pow10; // r = p1 mod 10^(n-1)
15368  //
15369  // M+ = buffer * 10^n + (d * 10^(n-1) + r) + p2 * 2^e
15370  // = (buffer * 10 + d) * 10^(n-1) + (r + p2 * 2^e)
15371  //
15372  JSON_ASSERT(d <= 9);
15373  buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d
15374  //
15375  // M+ = buffer * 10^(n-1) + (r + p2 * 2^e)
15376  //
15377  p1 = r;
15378  n--;
15379  //
15380  // M+ = buffer * 10^n + (p1 + p2 * 2^e)
15381  // pow10 = 10^n
15382  //
15383 
15384  // Now check if enough digits have been generated.
15385  // Compute
15386  //
15387  // p1 + p2 * 2^e = (p1 * 2^-e + p2) * 2^e = rest * 2^e
15388  //
15389  // Note:
15390  // Since rest and delta share the same exponent e, it suffices to
15391  // compare the significands.
15392  const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
15393  if (rest <= delta)
15394  {
15395  // V = buffer * 10^n, with M- <= V <= M+.
15396 
15397  decimal_exponent += n;
15398 
15399  // We may now just stop. But instead look if the buffer could be
15400  // decremented to bring V closer to w.
15401  //
15402  // pow10 = 10^n is now 1 ulp in the decimal representation V.
15403  // The rounding procedure works with diyfp's with an implicit
15404  // exponent of e.
15405  //
15406  // 10^n = (10^n * 2^-e) * 2^e = ulp * 2^e
15407  //
15408  const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
15409  grisu2_round(buffer, length, dist, delta, rest, ten_n);
15410 
15411  return;
15412  }
15413 
15414  pow10 /= 10;
15415  //
15416  // pow10 = 10^(n-1) <= p1 < 10^n
15417  // Invariants restored.
15418  }
15419 
15420  // 2)
15421  //
15422  // The digits of the integral part have been generated:
15423  //
15424  // M+ = d[k-1]...d[1]d[0] + p2 * 2^e
15425  // = buffer + p2 * 2^e
15426  //
15427  // Now generate the digits of the fractional part p2 * 2^e.
15428  //
15429  // Note:
15430  // No decimal point is generated: the exponent is adjusted instead.
15431  //
15432  // p2 actually represents the fraction
15433  //
15434  // p2 * 2^e
15435  // = p2 / 2^-e
15436  // = d[-1] / 10^1 + d[-2] / 10^2 + ...
15437  //
15438  // Now generate the digits d[-m] of p1 from left to right (m = 1,2,...)
15439  //
15440  // p2 * 2^e = d[-1]d[-2]...d[-m] * 10^-m
15441  // + 10^-m * (d[-m-1] / 10^1 + d[-m-2] / 10^2 + ...)
15442  //
15443  // using
15444  //
15445  // 10^m * p2 = ((10^m * p2) div 2^-e) * 2^-e + ((10^m * p2) mod 2^-e)
15446  // = ( d) * 2^-e + ( r)
15447  //
15448  // or
15449  // 10^m * p2 * 2^e = d + r * 2^e
15450  //
15451  // i.e.
15452  //
15453  // M+ = buffer + p2 * 2^e
15454  // = buffer + 10^-m * (d + r * 2^e)
15455  // = (buffer * 10^m + d) * 10^-m + 10^-m * r * 2^e
15456  //
15457  // and stop as soon as 10^-m * r * 2^e <= delta * 2^e
15458 
15459  JSON_ASSERT(p2 > delta);
15460 
15461  int m = 0;
15462  for (;;)
15463  {
15464  // Invariant:
15465  // M+ = buffer * 10^-m + 10^-m * (d[-m-1] / 10 + d[-m-2] / 10^2 + ...) * 2^e
15466  // = buffer * 10^-m + 10^-m * (p2 ) * 2^e
15467  // = buffer * 10^-m + 10^-m * (1/10 * (10 * p2) ) * 2^e
15468  // = buffer * 10^-m + 10^-m * (1/10 * ((10*p2 div 2^-e) * 2^-e + (10*p2 mod 2^-e)) * 2^e
15469  //
15470  JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
15471  p2 *= 10;
15472  const std::uint64_t d = p2 >> -one.e; // d = (10 * p2) div 2^-e
15473  const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e
15474  //
15475  // M+ = buffer * 10^-m + 10^-m * (1/10 * (d * 2^-e + r) * 2^e
15476  // = buffer * 10^-m + 10^-m * (1/10 * (d + r * 2^e))
15477  // = (buffer * 10 + d) * 10^(-m-1) + 10^(-m-1) * r * 2^e
15478  //
15479  JSON_ASSERT(d <= 9);
15480  buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d
15481  //
15482  // M+ = buffer * 10^(-m-1) + 10^(-m-1) * r * 2^e
15483  //
15484  p2 = r;
15485  m++;
15486  //
15487  // M+ = buffer * 10^-m + 10^-m * p2 * 2^e
15488  // Invariant restored.
15489 
15490  // Check if enough digits have been generated.
15491  //
15492  // 10^-m * p2 * 2^e <= delta * 2^e
15493  // p2 * 2^e <= 10^m * delta * 2^e
15494  // p2 <= 10^m * delta
15495  delta *= 10;
15496  dist *= 10;
15497  if (p2 <= delta)
15498  {
15499  break;
15500  }
15501  }
15502 
15503  // V = buffer * 10^-m, with M- <= V <= M+.
15504 
15505  decimal_exponent -= m;
15506 
15507  // 1 ulp in the decimal representation is now 10^-m.
15508  // Since delta and dist are now scaled by 10^m, we need to do the
15509  // same with ulp in order to keep the units in sync.
15510  //
15511  // 10^m * 10^-m = 1 = 2^-e * 2^e = ten_m * 2^e
15512  //
15513  const std::uint64_t ten_m = one.f;
15514  grisu2_round(buffer, length, dist, delta, p2, ten_m);
15515 
15516  // By construction this algorithm generates the shortest possible decimal
15517  // number (Loitsch, Theorem 6.2) which rounds back to w.
15518  // For an input number of precision p, at least
15519  //
15520  // N = 1 + ceil(p * log_10(2))
15521  //
15522  // decimal digits are sufficient to identify all binary floating-point
15523  // numbers (Matula, "In-and-Out conversions").
15524  // This implies that the algorithm does not produce more than N decimal
15525  // digits.
15526  //
15527  // N = 17 for p = 53 (IEEE double precision)
15528  // N = 9 for p = 24 (IEEE single precision)
15529 }
15530 
15537 inline void grisu2(char* buf, int& len, int& decimal_exponent,
15538  diyfp m_minus, diyfp v, diyfp m_plus)
15539 {
15540  JSON_ASSERT(m_plus.e == m_minus.e);
15541  JSON_ASSERT(m_plus.e == v.e);
15542 
15543  // --------(-----------------------+-----------------------)-------- (A)
15544  // m- v m+
15545  //
15546  // --------------------(-----------+-----------------------)-------- (B)
15547  // m- v m+
15548  //
15549  // First scale v (and m- and m+) such that the exponent is in the range
15550  // [alpha, gamma].
15551 
15552  const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
15553 
15554  const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k
15555 
15556  // The exponent of the products is = v.e + c_minus_k.e + q and is in the range [alpha,gamma]
15557  const diyfp w = diyfp::mul(v, c_minus_k);
15558  const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
15559  const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
15560 
15561  // ----(---+---)---------------(---+---)---------------(---+---)----
15562  // w- w w+
15563  // = c*m- = c*v = c*m+
15564  //
15565  // diyfp::mul rounds its result and c_minus_k is approximated too. w, w- and
15566  // w+ are now off by a small amount.
15567  // In fact:
15568  //
15569  // w - v * 10^k < 1 ulp
15570  //
15571  // To account for this inaccuracy, add resp. subtract 1 ulp.
15572  //
15573  // --------+---[---------------(---+---)---------------]---+--------
15574  // w- M- w M+ w+
15575  //
15576  // Now any number in [M-, M+] (bounds included) will round to w when input,
15577  // regardless of how the input rounding algorithm breaks ties.
15578  //
15579  // And digit_gen generates the shortest possible such number in [M-, M+].
15580  // Note that this does not mean that Grisu2 always generates the shortest
15581  // possible number in the interval (m-, m+).
15582  const diyfp M_minus(w_minus.f + 1, w_minus.e);
15583  const diyfp M_plus (w_plus.f - 1, w_plus.e );
15584 
15585  decimal_exponent = -cached.k; // = -(-k) = k
15586 
15587  grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
15588 }
15589 
15595 template<typename FloatType>
15597 void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)
15598 {
15599  static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
15600  "internal error: not enough precision");
15601 
15602  JSON_ASSERT(std::isfinite(value));
15603  JSON_ASSERT(value > 0);
15604 
15605  // If the neighbors (and boundaries) of 'value' are always computed for double-precision
15606  // numbers, all float's can be recovered using strtod (and strtof). However, the resulting
15607  // decimal representations are not exactly "short".
15608  //
15609  // The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars)
15610  // says "value is converted to a string as if by std::sprintf in the default ("C") locale"
15611  // and since sprintf promotes float's to double's, I think this is exactly what 'std::to_chars'
15612  // does.
15613  // On the other hand, the documentation for 'std::to_chars' requires that "parsing the
15614  // representation using the corresponding std::from_chars function recovers value exactly". That
15615  // indicates that single precision floating-point numbers should be recovered using
15616  // 'std::strtof'.
15617  //
15618  // NB: If the neighbors are computed for single-precision numbers, there is a single float
15619  // (7.0385307e-26f) which can't be recovered using strtod. The resulting double precision
15620  // value is off by 1 ulp.
15621 #if 0
15622  const boundaries w = compute_boundaries(static_cast<double>(value));
15623 #else
15624  const boundaries w = compute_boundaries(value);
15625 #endif
15626 
15627  grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
15628 }
15629 
15637 inline char* append_exponent(char* buf, int e)
15638 {
15639  JSON_ASSERT(e > -1000);
15640  JSON_ASSERT(e < 1000);
15641 
15642  if (e < 0)
15643  {
15644  e = -e;
15645  *buf++ = '-';
15646  }
15647  else
15648  {
15649  *buf++ = '+';
15650  }
15651 
15652  auto k = static_cast<std::uint32_t>(e);
15653  if (k < 10)
15654  {
15655  // Always print at least two digits in the exponent.
15656  // This is for compatibility with printf("%g").
15657  *buf++ = '0';
15658  *buf++ = static_cast<char>('0' + k);
15659  }
15660  else if (k < 100)
15661  {
15662  *buf++ = static_cast<char>('0' + k / 10);
15663  k %= 10;
15664  *buf++ = static_cast<char>('0' + k);
15665  }
15666  else
15667  {
15668  *buf++ = static_cast<char>('0' + k / 100);
15669  k %= 100;
15670  *buf++ = static_cast<char>('0' + k / 10);
15671  k %= 10;
15672  *buf++ = static_cast<char>('0' + k);
15673  }
15674 
15675  return buf;
15676 }
15677 
15689 inline char* format_buffer(char* buf, int len, int decimal_exponent,
15690  int min_exp, int max_exp)
15691 {
15692  JSON_ASSERT(min_exp < 0);
15693  JSON_ASSERT(max_exp > 0);
15694 
15695  const int k = len;
15696  const int n = len + decimal_exponent;
15697 
15698  // v = buf * 10^(n-k)
15699  // k is the length of the buffer (number of decimal digits)
15700  // n is the position of the decimal point relative to the start of the buffer.
15701 
15702  if (k <= n && n <= max_exp)
15703  {
15704  // digits[000]
15705  // len <= max_exp + 2
15706 
15707  std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k));
15708  // Make it look like a floating-point number (#362, #378)
15709  buf[n + 0] = '.';
15710  buf[n + 1] = '0';
15711  return buf + (static_cast<size_t>(n) + 2);
15712  }
15713 
15714  if (0 < n && n <= max_exp)
15715  {
15716  // dig.its
15717  // len <= max_digits10 + 1
15718 
15719  JSON_ASSERT(k > n);
15720 
15721  std::memmove(buf + (static_cast<size_t>(n) + 1), buf + n, static_cast<size_t>(k) - static_cast<size_t>(n));
15722  buf[n] = '.';
15723  return buf + (static_cast<size_t>(k) + 1U);
15724  }
15725 
15726  if (min_exp < n && n <= 0)
15727  {
15728  // 0.[000]digits
15729  // len <= 2 + (-min_exp - 1) + max_digits10
15730 
15731  std::memmove(buf + (2 + static_cast<size_t>(-n)), buf, static_cast<size_t>(k));
15732  buf[0] = '0';
15733  buf[1] = '.';
15734  std::memset(buf + 2, '0', static_cast<size_t>(-n));
15735  return buf + (2U + static_cast<size_t>(-n) + static_cast<size_t>(k));
15736  }
15737 
15738  if (k == 1)
15739  {
15740  // dE+123
15741  // len <= 1 + 5
15742 
15743  buf += 1;
15744  }
15745  else
15746  {
15747  // d.igitsE+123
15748  // len <= max_digits10 + 1 + 5
15749 
15750  std::memmove(buf + 2, buf + 1, static_cast<size_t>(k) - 1);
15751  buf[1] = '.';
15752  buf += 1 + static_cast<size_t>(k);
15753  }
15754 
15755  *buf++ = 'e';
15756  return append_exponent(buf, n - 1);
15757 }
15758 
15759 } // namespace dtoa_impl
15760 
15771 template<typename FloatType>
15774 char* to_chars(char* first, const char* last, FloatType value)
15775 {
15776  static_cast<void>(last); // maybe unused - fix warning
15777  JSON_ASSERT(std::isfinite(value));
15778 
15779  // Use signbit(value) instead of (value < 0) since signbit works for -0.
15780  if (std::signbit(value))
15781  {
15782  value = -value;
15783  *first++ = '-';
15784  }
15785 
15786  if (value == 0) // +-0
15787  {
15788  *first++ = '0';
15789  // Make it look like a floating-point number (#362, #378)
15790  *first++ = '.';
15791  *first++ = '0';
15792  return first;
15793  }
15794 
15795  JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
15796 
15797  // Compute v = buffer * 10^decimal_exponent.
15798  // The decimal digits are stored in the buffer, which needs to be interpreted
15799  // as an unsigned decimal integer.
15800  // len is the length of the buffer, i.e. the number of decimal digits.
15801  int len = 0;
15802  int decimal_exponent = 0;
15803  dtoa_impl::grisu2(first, len, decimal_exponent, value);
15804 
15805  JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
15806 
15807  // Format the buffer like printf("%.*g", prec, value)
15808  constexpr int kMinExp = -4;
15809  // Use digits10 here to increase compatibility with version 2.
15810  constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
15811 
15812  JSON_ASSERT(last - first >= kMaxExp + 2);
15813  JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
15814  JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
15815 
15816  return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
15817 }
15818 
15819 } // namespace detail
15820 } // namespace nlohmann
15821 
15822 // #include <nlohmann/detail/exceptions.hpp>
15823 
15824 // #include <nlohmann/detail/macro_scope.hpp>
15825 
15826 // #include <nlohmann/detail/meta/cpp_future.hpp>
15827 
15828 // #include <nlohmann/detail/output/binary_writer.hpp>
15829 
15830 // #include <nlohmann/detail/output/output_adapters.hpp>
15831 
15832 // #include <nlohmann/detail/value_t.hpp>
15833 
15834 
15835 namespace nlohmann
15836 {
15837 namespace detail
15838 {
15840 // serialization //
15842 
15845 {
15846  strict,
15847  replace,
15848  ignore
15849 };
15850 
15851 template<typename BasicJsonType>
15853 {
15855  using number_float_t = typename BasicJsonType::number_float_t;
15856  using number_integer_t = typename BasicJsonType::number_integer_t;
15857  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
15858  using binary_char_t = typename BasicJsonType::binary_t::value_type;
15859  static constexpr std::uint8_t UTF8_ACCEPT = 0;
15860  static constexpr std::uint8_t UTF8_REJECT = 1;
15861 
15862  public:
15868  serializer(output_adapter_t<char> s, const char ichar,
15869  error_handler_t error_handler_ = error_handler_t::strict)
15870  : o(std::move(s))
15871  , loc(std::localeconv())
15872  , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
15873  , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
15874  , indent_char(ichar)
15875  , indent_string(512, indent_char)
15876  , error_handler(error_handler_)
15877  {}
15878 
15879  // delete because of pointer members
15880  serializer(const serializer&) = delete;
15881  serializer& operator=(const serializer&) = delete;
15882  serializer(serializer&&) = delete;
15884  ~serializer() = default;
15885 
15908  void dump(const BasicJsonType& val,
15909  const bool pretty_print,
15910  const bool ensure_ascii,
15911  const unsigned int indent_step,
15912  const unsigned int current_indent = 0)
15913  {
15914  switch (val.m_type)
15915  {
15916  case value_t::object:
15917  {
15918  if (val.m_value.object->empty())
15919  {
15920  o->write_characters("{}", 2);
15921  return;
15922  }
15923 
15924  if (pretty_print)
15925  {
15926  o->write_characters("{\n", 2);
15927 
15928  // variable to hold indentation for recursive calls
15929  const auto new_indent = current_indent + indent_step;
15930  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15931  {
15932  indent_string.resize(indent_string.size() * 2, ' ');
15933  }
15934 
15935  // first n-1 elements
15936  auto i = val.m_value.object->cbegin();
15937  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
15938  {
15939  o->write_characters(indent_string.c_str(), new_indent);
15940  o->write_character('\"');
15941  dump_escaped(i->first, ensure_ascii);
15942  o->write_characters("\": ", 3);
15943  dump(i->second, true, ensure_ascii, indent_step, new_indent);
15944  o->write_characters(",\n", 2);
15945  }
15946 
15947  // last element
15948  JSON_ASSERT(i != val.m_value.object->cend());
15949  JSON_ASSERT(std::next(i) == val.m_value.object->cend());
15950  o->write_characters(indent_string.c_str(), new_indent);
15951  o->write_character('\"');
15952  dump_escaped(i->first, ensure_ascii);
15953  o->write_characters("\": ", 3);
15954  dump(i->second, true, ensure_ascii, indent_step, new_indent);
15955 
15956  o->write_character('\n');
15957  o->write_characters(indent_string.c_str(), current_indent);
15958  o->write_character('}');
15959  }
15960  else
15961  {
15962  o->write_character('{');
15963 
15964  // first n-1 elements
15965  auto i = val.m_value.object->cbegin();
15966  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
15967  {
15968  o->write_character('\"');
15969  dump_escaped(i->first, ensure_ascii);
15970  o->write_characters("\":", 2);
15971  dump(i->second, false, ensure_ascii, indent_step, current_indent);
15972  o->write_character(',');
15973  }
15974 
15975  // last element
15976  JSON_ASSERT(i != val.m_value.object->cend());
15977  JSON_ASSERT(std::next(i) == val.m_value.object->cend());
15978  o->write_character('\"');
15979  dump_escaped(i->first, ensure_ascii);
15980  o->write_characters("\":", 2);
15981  dump(i->second, false, ensure_ascii, indent_step, current_indent);
15982 
15983  o->write_character('}');
15984  }
15985 
15986  return;
15987  }
15988 
15989  case value_t::array:
15990  {
15991  if (val.m_value.array->empty())
15992  {
15993  o->write_characters("[]", 2);
15994  return;
15995  }
15996 
15997  if (pretty_print)
15998  {
15999  o->write_characters("[\n", 2);
16000 
16001  // variable to hold indentation for recursive calls
16002  const auto new_indent = current_indent + indent_step;
16003  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16004  {
16005  indent_string.resize(indent_string.size() * 2, ' ');
16006  }
16007 
16008  // first n-1 elements
16009  for (auto i = val.m_value.array->cbegin();
16010  i != val.m_value.array->cend() - 1; ++i)
16011  {
16012  o->write_characters(indent_string.c_str(), new_indent);
16013  dump(*i, true, ensure_ascii, indent_step, new_indent);
16014  o->write_characters(",\n", 2);
16015  }
16016 
16017  // last element
16018  JSON_ASSERT(!val.m_value.array->empty());
16019  o->write_characters(indent_string.c_str(), new_indent);
16020  dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);
16021 
16022  o->write_character('\n');
16023  o->write_characters(indent_string.c_str(), current_indent);
16024  o->write_character(']');
16025  }
16026  else
16027  {
16028  o->write_character('[');
16029 
16030  // first n-1 elements
16031  for (auto i = val.m_value.array->cbegin();
16032  i != val.m_value.array->cend() - 1; ++i)
16033  {
16034  dump(*i, false, ensure_ascii, indent_step, current_indent);
16035  o->write_character(',');
16036  }
16037 
16038  // last element
16039  JSON_ASSERT(!val.m_value.array->empty());
16040  dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);
16041 
16042  o->write_character(']');
16043  }
16044 
16045  return;
16046  }
16047 
16048  case value_t::string:
16049  {
16050  o->write_character('\"');
16051  dump_escaped(*val.m_value.string, ensure_ascii);
16052  o->write_character('\"');
16053  return;
16054  }
16055 
16056  case value_t::binary:
16057  {
16058  if (pretty_print)
16059  {
16060  o->write_characters("{\n", 2);
16061 
16062  // variable to hold indentation for recursive calls
16063  const auto new_indent = current_indent + indent_step;
16064  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16065  {
16066  indent_string.resize(indent_string.size() * 2, ' ');
16067  }
16068 
16069  o->write_characters(indent_string.c_str(), new_indent);
16070 
16071  o->write_characters("\"bytes\": [", 10);
16072 
16073  if (!val.m_value.binary->empty())
16074  {
16075  for (auto i = val.m_value.binary->cbegin();
16076  i != val.m_value.binary->cend() - 1; ++i)
16077  {
16078  dump_integer(*i);
16079  o->write_characters(", ", 2);
16080  }
16081  dump_integer(val.m_value.binary->back());
16082  }
16083 
16084  o->write_characters("],\n", 3);
16085  o->write_characters(indent_string.c_str(), new_indent);
16086 
16087  o->write_characters("\"subtype\": ", 11);
16088  if (val.m_value.binary->has_subtype())
16089  {
16090  dump_integer(val.m_value.binary->subtype());
16091  }
16092  else
16093  {
16094  o->write_characters("null", 4);
16095  }
16096  o->write_character('\n');
16097  o->write_characters(indent_string.c_str(), current_indent);
16098  o->write_character('}');
16099  }
16100  else
16101  {
16102  o->write_characters("{\"bytes\":[", 10);
16103 
16104  if (!val.m_value.binary->empty())
16105  {
16106  for (auto i = val.m_value.binary->cbegin();
16107  i != val.m_value.binary->cend() - 1; ++i)
16108  {
16109  dump_integer(*i);
16110  o->write_character(',');
16111  }
16112  dump_integer(val.m_value.binary->back());
16113  }
16114 
16115  o->write_characters("],\"subtype\":", 12);
16116  if (val.m_value.binary->has_subtype())
16117  {
16118  dump_integer(val.m_value.binary->subtype());
16119  o->write_character('}');
16120  }
16121  else
16122  {
16123  o->write_characters("null}", 5);
16124  }
16125  }
16126  return;
16127  }
16128 
16129  case value_t::boolean:
16130  {
16131  if (val.m_value.boolean)
16132  {
16133  o->write_characters("true", 4);
16134  }
16135  else
16136  {
16137  o->write_characters("false", 5);
16138  }
16139  return;
16140  }
16141 
16143  {
16144  dump_integer(val.m_value.number_integer);
16145  return;
16146  }
16147 
16149  {
16150  dump_integer(val.m_value.number_unsigned);
16151  return;
16152  }
16153 
16154  case value_t::number_float:
16155  {
16156  dump_float(val.m_value.number_float);
16157  return;
16158  }
16159 
16160  case value_t::discarded:
16161  {
16162  o->write_characters("<discarded>", 11);
16163  return;
16164  }
16165 
16166  case value_t::null:
16167  {
16168  o->write_characters("null", 4);
16169  return;
16170  }
16171 
16172  default: // LCOV_EXCL_LINE
16173  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
16174  }
16175  }
16176 
16192  void dump_escaped(const string_t& s, const bool ensure_ascii)
16193  {
16194  std::uint32_t codepoint{};
16196  std::size_t bytes = 0; // number of bytes written to string_buffer
16197 
16198  // number of bytes written at the point of the last valid byte
16199  std::size_t bytes_after_last_accept = 0;
16200  std::size_t undumped_chars = 0;
16201 
16202  for (std::size_t i = 0; i < s.size(); ++i)
16203  {
16204  const auto byte = static_cast<uint8_t>(s[i]);
16205 
16206  switch (decode(state, codepoint, byte))
16207  {
16208  case UTF8_ACCEPT: // decode found a new code point
16209  {
16210  switch (codepoint)
16211  {
16212  case 0x08: // backspace
16213  {
16214  string_buffer[bytes++] = '\\';
16215  string_buffer[bytes++] = 'b';
16216  break;
16217  }
16218 
16219  case 0x09: // horizontal tab
16220  {
16221  string_buffer[bytes++] = '\\';
16222  string_buffer[bytes++] = 't';
16223  break;
16224  }
16225 
16226  case 0x0A: // newline
16227  {
16228  string_buffer[bytes++] = '\\';
16229  string_buffer[bytes++] = 'n';
16230  break;
16231  }
16232 
16233  case 0x0C: // formfeed
16234  {
16235  string_buffer[bytes++] = '\\';
16236  string_buffer[bytes++] = 'f';
16237  break;
16238  }
16239 
16240  case 0x0D: // carriage return
16241  {
16242  string_buffer[bytes++] = '\\';
16243  string_buffer[bytes++] = 'r';
16244  break;
16245  }
16246 
16247  case 0x22: // quotation mark
16248  {
16249  string_buffer[bytes++] = '\\';
16250  string_buffer[bytes++] = '\"';
16251  break;
16252  }
16253 
16254  case 0x5C: // reverse solidus
16255  {
16256  string_buffer[bytes++] = '\\';
16257  string_buffer[bytes++] = '\\';
16258  break;
16259  }
16260 
16261  default:
16262  {
16263  // escape control characters (0x00..0x1F) or, if
16264  // ensure_ascii parameter is used, non-ASCII characters
16265  if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
16266  {
16267  if (codepoint <= 0xFFFF)
16268  {
16269  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16270  (std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x",
16271  static_cast<std::uint16_t>(codepoint));
16272  bytes += 6;
16273  }
16274  else
16275  {
16276  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16277  (std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x",
16278  static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),
16279  static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)));
16280  bytes += 12;
16281  }
16282  }
16283  else
16284  {
16285  // copy byte to buffer (all previous bytes
16286  // been copied have in default case above)
16287  string_buffer[bytes++] = s[i];
16288  }
16289  break;
16290  }
16291  }
16292 
16293  // write buffer and reset index; there must be 13 bytes
16294  // left, as this is the maximal number of bytes to be
16295  // written ("\uxxxx\uxxxx\0") for one code point
16296  if (string_buffer.size() - bytes < 13)
16297  {
16298  o->write_characters(string_buffer.data(), bytes);
16299  bytes = 0;
16300  }
16301 
16302  // remember the byte position of this accept
16304  undumped_chars = 0;
16305  break;
16306  }
16307 
16308  case UTF8_REJECT: // decode found invalid UTF-8 byte
16309  {
16310  switch (error_handler)
16311  {
16313  {
16314  std::string sn(3, '\0');
16315  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16316  (std::snprintf)(&sn[0], sn.size(), "%.2X", byte);
16317  JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, BasicJsonType()));
16318  }
16319 
16322  {
16323  // in case we saw this character the first time, we
16324  // would like to read it again, because the byte
16325  // may be OK for itself, but just not OK for the
16326  // previous sequence
16327  if (undumped_chars > 0)
16328  {
16329  --i;
16330  }
16331 
16332  // reset length buffer to the last accepted index;
16333  // thus removing/ignoring the invalid characters
16335 
16337  {
16338  // add a replacement character
16339  if (ensure_ascii)
16340  {
16341  string_buffer[bytes++] = '\\';
16342  string_buffer[bytes++] = 'u';
16343  string_buffer[bytes++] = 'f';
16344  string_buffer[bytes++] = 'f';
16345  string_buffer[bytes++] = 'f';
16346  string_buffer[bytes++] = 'd';
16347  }
16348  else
16349  {
16353  }
16354 
16355  // write buffer and reset index; there must be 13 bytes
16356  // left, as this is the maximal number of bytes to be
16357  // written ("\uxxxx\uxxxx\0") for one code point
16358  if (string_buffer.size() - bytes < 13)
16359  {
16360  o->write_characters(string_buffer.data(), bytes);
16361  bytes = 0;
16362  }
16363 
16365  }
16366 
16367  undumped_chars = 0;
16368 
16369  // continue processing the string
16370  state = UTF8_ACCEPT;
16371  break;
16372  }
16373 
16374  default: // LCOV_EXCL_LINE
16375  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
16376  }
16377  break;
16378  }
16379 
16380  default: // decode found yet incomplete multi-byte code point
16381  {
16382  if (!ensure_ascii)
16383  {
16384  // code point will not be escaped - copy byte to buffer
16385  string_buffer[bytes++] = s[i];
16386  }
16387  ++undumped_chars;
16388  break;
16389  }
16390  }
16391  }
16392 
16393  // we finished processing the string
16395  {
16396  // write buffer
16397  if (bytes > 0)
16398  {
16399  o->write_characters(string_buffer.data(), bytes);
16400  }
16401  }
16402  else
16403  {
16404  // we finish reading, but do not accept: string was incomplete
16405  switch (error_handler)
16406  {
16408  {
16409  std::string sn(3, '\0');
16410  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16411  (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back()));
16412  JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
16413  }
16414 
16416  {
16417  // write all accepted bytes
16418  o->write_characters(string_buffer.data(), bytes_after_last_accept);
16419  break;
16420  }
16421 
16423  {
16424  // write all accepted bytes
16425  o->write_characters(string_buffer.data(), bytes_after_last_accept);
16426  // add a replacement character
16427  if (ensure_ascii)
16428  {
16429  o->write_characters("\\ufffd", 6);
16430  }
16431  else
16432  {
16433  o->write_characters("\xEF\xBF\xBD", 3);
16434  }
16435  break;
16436  }
16437 
16438  default: // LCOV_EXCL_LINE
16439  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
16440  }
16441  }
16442  }
16443 
16444  private:
16453  inline unsigned int count_digits(number_unsigned_t x) noexcept
16454  {
16455  unsigned int n_digits = 1;
16456  for (;;)
16457  {
16458  if (x < 10)
16459  {
16460  return n_digits;
16461  }
16462  if (x < 100)
16463  {
16464  return n_digits + 1;
16465  }
16466  if (x < 1000)
16467  {
16468  return n_digits + 2;
16469  }
16470  if (x < 10000)
16471  {
16472  return n_digits + 3;
16473  }
16474  x = x / 10000u;
16475  n_digits += 4;
16476  }
16477  }
16478 
16488  template < typename NumberType, detail::enable_if_t <
16492  int > = 0 >
16493  void dump_integer(NumberType x)
16494  {
16495  static constexpr std::array<std::array<char, 2>, 100> digits_to_99
16496  {
16497  {
16498  {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
16499  {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
16500  {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
16501  {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
16502  {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
16503  {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
16504  {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
16505  {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
16506  {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
16507  {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
16508  }
16509  };
16510 
16511  // special case for "0"
16512  if (x == 0)
16513  {
16514  o->write_character('0');
16515  return;
16516  }
16517 
16518  // use a pointer to fill the buffer
16519  auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16520 
16521  const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0); // see issue #755
16522  number_unsigned_t abs_value;
16523 
16524  unsigned int n_chars{};
16525 
16526  if (is_negative)
16527  {
16528  *buffer_ptr = '-';
16529  abs_value = remove_sign(static_cast<number_integer_t>(x));
16530 
16531  // account one more byte for the minus sign
16532  n_chars = 1 + count_digits(abs_value);
16533  }
16534  else
16535  {
16536  abs_value = static_cast<number_unsigned_t>(x);
16537  n_chars = count_digits(abs_value);
16538  }
16539 
16540  // spare 1 byte for '\0'
16541  JSON_ASSERT(n_chars < number_buffer.size() - 1);
16542 
16543  // jump to the end to generate the string from backward
16544  // so we later avoid reversing the result
16545  buffer_ptr += n_chars;
16546 
16547  // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu
16548  // See: https://www.youtube.com/watch?v=o4-CwDo2zpg
16549  while (abs_value >= 100)
16550  {
16551  const auto digits_index = static_cast<unsigned>((abs_value % 100));
16552  abs_value /= 100;
16553  *(--buffer_ptr) = digits_to_99[digits_index][1];
16554  *(--buffer_ptr) = digits_to_99[digits_index][0];
16555  }
16556 
16557  if (abs_value >= 10)
16558  {
16559  const auto digits_index = static_cast<unsigned>(abs_value);
16560  *(--buffer_ptr) = digits_to_99[digits_index][1];
16561  *(--buffer_ptr) = digits_to_99[digits_index][0];
16562  }
16563  else
16564  {
16565  *(--buffer_ptr) = static_cast<char>('0' + abs_value);
16566  }
16567 
16568  o->write_characters(number_buffer.data(), n_chars);
16569  }
16570 
16579  void dump_float(number_float_t x)
16580  {
16581  // NaN / inf
16582  if (!std::isfinite(x))
16583  {
16584  o->write_characters("null", 4);
16585  return;
16586  }
16587 
16588  // If number_float_t is an IEEE-754 single or double precision number,
16589  // use the Grisu2 algorithm to produce short numbers which are
16590  // guaranteed to round-trip, using strtof and strtod, resp.
16591  //
16592  // NB: The test below works if <long double> == <double>.
16593  static constexpr bool is_ieee_single_or_double
16594  = (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) ||
16595  (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);
16596 
16597  dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
16598  }
16599 
16600  void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/)
16601  {
16602  auto* begin = number_buffer.data();
16603  auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
16604 
16605  o->write_characters(begin, static_cast<size_t>(end - begin));
16606  }
16607 
16608  void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/)
16609  {
16610  // get number of digits for a float -> text -> float round-trip
16611  static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
16612 
16613  // the actual conversion
16614  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
16615  std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
16616 
16617  // negative value indicates an error
16618  JSON_ASSERT(len > 0);
16619  // check if buffer was large enough
16620  JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());
16621 
16622  // erase thousands separator
16623  if (thousands_sep != '\0')
16624  {
16625  auto* const end = std::remove(number_buffer.begin(),
16626  number_buffer.begin() + len, thousands_sep);
16627  std::fill(end, number_buffer.end(), '\0');
16628  JSON_ASSERT((end - number_buffer.begin()) <= len);
16629  len = (end - number_buffer.begin());
16630  }
16631 
16632  // convert decimal point to '.'
16633  if (decimal_point != '\0' && decimal_point != '.')
16634  {
16635  auto* const dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
16636  if (dec_pos != number_buffer.end())
16637  {
16638  *dec_pos = '.';
16639  }
16640  }
16641 
16642  o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));
16643 
16644  // determine if need to append ".0"
16645  const bool value_is_int_like =
16646  std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
16647  [](char c)
16648  {
16649  return c == '.' || c == 'e';
16650  });
16651 
16652  if (value_is_int_like)
16653  {
16654  o->write_characters(".0", 2);
16655  }
16656  }
16657 
16679  static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept
16680  {
16681  static const std::array<std::uint8_t, 400> utf8d =
16682  {
16683  {
16684  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
16685  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
16686  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
16687  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
16688  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
16689  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
16690  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
16691  0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF
16692  0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF
16693  0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0
16694  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
16695  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
16696  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
16697  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
16698  }
16699  };
16700 
16701  JSON_ASSERT(byte < utf8d.size());
16702  const std::uint8_t type = utf8d[byte];
16703 
16704  codep = (state != UTF8_ACCEPT)
16705  ? (byte & 0x3fu) | (codep << 6u)
16706  : (0xFFu >> type) & (byte);
16707 
16708  std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type);
16709  JSON_ASSERT(index < 400);
16710  state = utf8d[index];
16711  return state;
16712  }
16713 
16714  /*
16715  * Overload to make the compiler happy while it is instantiating
16716  * dump_integer for number_unsigned_t.
16717  * Must never be called.
16718  */
16719  number_unsigned_t remove_sign(number_unsigned_t x)
16720  {
16721  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
16722  return x; // LCOV_EXCL_LINE
16723  }
16724 
16725  /*
16726  * Helper function for dump_integer
16727  *
16728  * This function takes a negative signed integer and returns its absolute
16729  * value as unsigned integer. The plus/minus shuffling is necessary as we can
16730  * not directly remove the sign of an arbitrary signed integer as the
16731  * absolute values of INT_MIN and INT_MAX are usually not the same. See
16732  * #1708 for details.
16733  */
16734  inline number_unsigned_t remove_sign(number_integer_t x) noexcept
16735  {
16736  JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression)
16737  return static_cast<number_unsigned_t>(-(x + 1)) + 1;
16738  }
16739 
16740  private:
16742  output_adapter_t<char> o = nullptr;
16743 
16745  std::array<char, 64> number_buffer{{}};
16746 
16748  const std::lconv* loc = nullptr;
16750  const char thousands_sep = '\0';
16752  const char decimal_point = '\0';
16753 
16755  std::array<char, 512> string_buffer{{}};
16756 
16758  const char indent_char;
16761 
16764 };
16765 } // namespace detail
16766 } // namespace nlohmann
16767 
16768 // #include <nlohmann/detail/value_t.hpp>
16769 
16770 // #include <nlohmann/json_fwd.hpp>
16771 
16772 // #include <nlohmann/ordered_map.hpp>
16773 
16774 
16775 #include <functional> // less
16776 #include <initializer_list> // initializer_list
16777 #include <iterator> // input_iterator_tag, iterator_traits
16778 #include <memory> // allocator
16779 #include <stdexcept> // for out_of_range
16780 #include <type_traits> // enable_if, is_convertible
16781 #include <utility> // pair
16782 #include <vector> // vector
16783 
16784 // #include <nlohmann/detail/macro_scope.hpp>
16785 
16786 
16787 namespace nlohmann
16788 {
16789 
16792 template <class Key, class T, class IgnoredLess = std::less<Key>,
16793  class Allocator = std::allocator<std::pair<const Key, T>>>
16794  struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
16795 {
16796  using key_type = Key;
16797  using mapped_type = T;
16798  using Container = std::vector<std::pair<const Key, T>, Allocator>;
16799  using typename Container::iterator;
16800  using typename Container::const_iterator;
16801  using typename Container::size_type;
16802  using typename Container::value_type;
16803 
16804  // Explicit constructors instead of `using Container::Container`
16805  // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4)
16806  ordered_map(const Allocator& alloc = Allocator()) : Container{alloc} {}
16807  template <class It>
16808  ordered_map(It first, It last, const Allocator& alloc = Allocator())
16809  : Container{first, last, alloc} {}
16810  ordered_map(std::initializer_list<T> init, const Allocator& alloc = Allocator() )
16811  : Container{init, alloc} {}
16812 
16813  std::pair<iterator, bool> emplace(const key_type& key, T&& t)
16814  {
16815  for (auto it = this->begin(); it != this->end(); ++it)
16816  {
16817  if (it->first == key)
16818  {
16819  return {it, false};
16820  }
16821  }
16822  Container::emplace_back(key, t);
16823  return {--this->end(), true};
16824  }
16825 
16826  T& operator[](const Key& key)
16827  {
16828  return emplace(key, T{}).first->second;
16829  }
16830 
16831  const T& operator[](const Key& key) const
16832  {
16833  return at(key);
16834  }
16835 
16836  T& at(const Key& key)
16837  {
16838  for (auto it = this->begin(); it != this->end(); ++it)
16839  {
16840  if (it->first == key)
16841  {
16842  return it->second;
16843  }
16844  }
16845 
16846  JSON_THROW(std::out_of_range("key not found"));
16847  }
16848 
16849  const T& at(const Key& key) const
16850  {
16851  for (auto it = this->begin(); it != this->end(); ++it)
16852  {
16853  if (it->first == key)
16854  {
16855  return it->second;
16856  }
16857  }
16858 
16859  JSON_THROW(std::out_of_range("key not found"));
16860  }
16861 
16862  size_type erase(const Key& key)
16863  {
16864  for (auto it = this->begin(); it != this->end(); ++it)
16865  {
16866  if (it->first == key)
16867  {
16868  // Since we cannot move const Keys, re-construct them in place
16869  for (auto next = it; ++next != this->end(); ++it)
16870  {
16871  it->~value_type(); // Destroy but keep allocation
16872  new (&*it) value_type{std::move(*next)};
16873  }
16874  Container::pop_back();
16875  return 1;
16876  }
16877  }
16878  return 0;
16879  }
16880 
16881  iterator erase(iterator pos)
16882  {
16883  auto it = pos;
16884 
16885  // Since we cannot move const Keys, re-construct them in place
16886  for (auto next = it; ++next != this->end(); ++it)
16887  {
16888  it->~value_type(); // Destroy but keep allocation
16889  new (&*it) value_type{std::move(*next)};
16890  }
16891  Container::pop_back();
16892  return pos;
16893  }
16894 
16895  size_type count(const Key& key) const
16896  {
16897  for (auto it = this->begin(); it != this->end(); ++it)
16898  {
16899  if (it->first == key)
16900  {
16901  return 1;
16902  }
16903  }
16904  return 0;
16905  }
16906 
16907  iterator find(const Key& key)
16908  {
16909  for (auto it = this->begin(); it != this->end(); ++it)
16910  {
16911  if (it->first == key)
16912  {
16913  return it;
16914  }
16915  }
16916  return Container::end();
16917  }
16918 
16919  const_iterator find(const Key& key) const
16920  {
16921  for (auto it = this->begin(); it != this->end(); ++it)
16922  {
16923  if (it->first == key)
16924  {
16925  return it;
16926  }
16927  }
16928  return Container::end();
16929  }
16930 
16931  std::pair<iterator, bool> insert( value_type&& value )
16932  {
16933  return emplace(value.first, std::move(value.second));
16934  }
16935 
16936  std::pair<iterator, bool> insert( const value_type& value )
16937  {
16938  for (auto it = this->begin(); it != this->end(); ++it)
16939  {
16940  if (it->first == value.first)
16941  {
16942  return {it, false};
16943  }
16944  }
16945  Container::push_back(value);
16946  return {--this->end(), true};
16947  }
16948 
16949  template<typename InputIt>
16950  using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
16951  std::input_iterator_tag>::value>::type;
16952 
16953  template<typename InputIt, typename = require_input_iter<InputIt>>
16954  void insert(InputIt first, InputIt last)
16955  {
16956  for (auto it = first; it != last; ++it)
16957  {
16958  insert(*it);
16959  }
16960  }
16961 };
16962 
16963 } // namespace nlohmann
16964 
16965 
16966 #if defined(JSON_HAS_CPP_17)
16967  #include <string_view>
16968 #endif
16969 
16975 namespace nlohmann
16976 {
16977 
17063 class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
17064 {
17065  private:
17066  template<detail::value_t> friend struct detail::external_constructor;
17067  friend ::nlohmann::json_pointer<basic_json>;
17068 
17069  template<typename BasicJsonType, typename InputType>
17070  friend class ::nlohmann::detail::parser;
17071  friend ::nlohmann::detail::serializer<basic_json>;
17072  template<typename BasicJsonType>
17073  friend class ::nlohmann::detail::iter_impl;
17074  template<typename BasicJsonType, typename CharType>
17075  friend class ::nlohmann::detail::binary_writer;
17076  template<typename BasicJsonType, typename InputType, typename SAX>
17077  friend class ::nlohmann::detail::binary_reader;
17078  template<typename BasicJsonType>
17079  friend class ::nlohmann::detail::json_sax_dom_parser;
17080  template<typename BasicJsonType>
17081  friend class ::nlohmann::detail::json_sax_dom_callback_parser;
17082  friend class ::nlohmann::detail::exception;
17083 
17086 
17088  // convenience aliases for types residing in namespace detail;
17090 
17091  template<typename InputAdapterType>
17092  static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
17093  InputAdapterType adapter,
17095  const bool allow_exceptions = true,
17096  const bool ignore_comments = false
17097  )
17098  {
17099  return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
17100  std::move(cb), allow_exceptions, ignore_comments);
17101  }
17102 
17103  private:
17105  template<typename BasicJsonType>
17107  template<typename BasicJsonType>
17109  template<typename Iterator>
17112 
17113  template<typename CharType>
17115 
17116  template<typename InputType>
17119 
17121  using serializer = ::nlohmann::detail::serializer<basic_json>;
17122 
17123  public:
17127  template<typename T, typename SFINAE>
17128  using json_serializer = JSONSerializer<T, SFINAE>;
17134  using initializer_list_t = std::initializer_list<detail::json_ref<basic_json>>;
17135 
17139 
17141  // exceptions //
17143 
17147 
17160 
17162 
17163 
17165  // container types //
17167 
17172 
17175 
17179  using const_reference = const value_type&;
17180 
17182  using difference_type = std::ptrdiff_t;
17184  using size_type = std::size_t;
17185 
17187  using allocator_type = AllocatorType<basic_json>;
17188 
17192  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
17193 
17202 
17204 
17205 
17210  {
17211  return allocator_type();
17212  }
17213 
17241  static basic_json meta()
17242  {
17243  basic_json result;
17244 
17245  result["copyright"] = "(C) 2013-2021 Niels Lohmann";
17246  result["name"] = "JSON for Modern C++";
17247  result["url"] = "https://github.com/nlohmann/json";
17248  result["version"]["string"] =
17252  result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR;
17253  result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR;
17254  result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH;
17255 
17256 #ifdef _WIN32
17257  result["platform"] = "win32";
17258 #elif defined __linux__
17259  result["platform"] = "linux";
17260 #elif defined __APPLE__
17261  result["platform"] = "apple";
17262 #elif defined __unix__
17263  result["platform"] = "unix";
17264 #else
17265  result["platform"] = "unknown";
17266 #endif
17267 
17268 #if defined(__ICC) || defined(__INTEL_COMPILER)
17269  result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}};
17270 #elif defined(__clang__)
17271  result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}};
17272 #elif defined(__GNUC__) || defined(__GNUG__)
17273  result["compiler"] = {{"family", "gcc"}, {"version", std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__)}};
17274 #elif defined(__HP_cc) || defined(__HP_aCC)
17275  result["compiler"] = "hp"
17276 #elif defined(__IBMCPP__)
17277  result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}};
17278 #elif defined(_MSC_VER)
17279  result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}};
17280 #elif defined(__PGI)
17281  result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}};
17282 #elif defined(__SUNPRO_CC)
17283  result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}};
17284 #else
17285  result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}};
17286 #endif
17287 
17288 #ifdef __cplusplus
17289  result["compiler"]["c++"] = std::to_string(__cplusplus);
17290 #else
17291  result["compiler"]["c++"] = "unknown";
17292 #endif
17293  return result;
17294  }
17295 
17296 
17298  // JSON value data types //
17300 
17305 
17306 #if defined(JSON_HAS_CPP_14)
17307  // Use transparent comparator if possible, combined with perfect forwarding
17308  // on find() and count() calls prevents unnecessary string construction.
17309  using object_comparator_t = std::less<>;
17310 #else
17311  using object_comparator_t = std::less<StringType>;
17312 #endif
17313 
17397  using object_t = ObjectType<StringType,
17398  basic_json,
17400  AllocatorType<std::pair<const StringType,
17401  basic_json>>>;
17402 
17448 
17500  using string_t = StringType;
17501 
17526  using boolean_t = BooleanType;
17527 
17598  using number_integer_t = NumberIntegerType;
17599 
17669  using number_unsigned_t = NumberUnsignedType;
17670 
17737  using number_float_t = NumberFloatType;
17738 
17810 
17811  private:
17812 
17814  template<typename T, typename... Args>
17816  static T* create(Args&& ... args)
17817  {
17818  AllocatorType<T> alloc;
17819  using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
17820 
17821  auto deleter = [&](T * obj)
17822  {
17823  AllocatorTraits::deallocate(alloc, obj, 1);
17824  };
17825  std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
17826  AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
17827  JSON_ASSERT(obj != nullptr);
17828  return obj.release();
17829  }
17830 
17832  // JSON value storage //
17834 
17861  union json_value
17862  {
17864  object_t* object;
17879 
17881  json_value() = default;
17883  json_value(boolean_t v) noexcept : boolean(v) {}
17892  {
17893  switch (t)
17894  {
17895  case value_t::object:
17896  {
17897  object = create<object_t>();
17898  break;
17899  }
17900 
17901  case value_t::array:
17902  {
17903  array = create<array_t>();
17904  break;
17905  }
17906 
17907  case value_t::string:
17908  {
17909  string = create<string_t>("");
17910  break;
17911  }
17912 
17913  case value_t::binary:
17914  {
17915  binary = create<binary_t>();
17916  break;
17917  }
17918 
17919  case value_t::boolean:
17920  {
17921  boolean = boolean_t(false);
17922  break;
17923  }
17924 
17926  {
17928  break;
17929  }
17930 
17932  {
17934  break;
17935  }
17936 
17937  case value_t::number_float:
17938  {
17940  break;
17941  }
17942 
17943  case value_t::null:
17944  {
17945  object = nullptr; // silence warning, see #821
17946  break;
17947  }
17948 
17949  default:
17950  {
17951  object = nullptr; // silence warning, see #821
17953  {
17954  JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.9.1", basic_json())); // LCOV_EXCL_LINE
17955  }
17956  break;
17957  }
17958  }
17959  }
17960 
17963  {
17964  string = create<string_t>(value);
17965  }
17966 
17969  {
17970  string = create<string_t>(std::move(value));
17971  }
17972 
17975  {
17976  object = create<object_t>(value);
17977  }
17978 
17981  {
17982  object = create<object_t>(std::move(value));
17983  }
17984 
17987  {
17988  array = create<array_t>(value);
17989  }
17990 
17993  {
17994  array = create<array_t>(std::move(value));
17995  }
17996 
17999  {
18000  binary = create<binary_t>(value);
18001  }
18002 
18005  {
18006  binary = create<binary_t>(std::move(value));
18007  }
18008 
18011  {
18012  binary = create<binary_t>(value);
18013  }
18014 
18017  {
18018  binary = create<binary_t>(std::move(value));
18019  }
18020 
18021  void destroy(value_t t) noexcept
18022  {
18023  // flatten the current json_value to a heap-allocated stack
18024  std::vector<basic_json> stack;
18025 
18026  // move the top-level items to stack
18027  if (t == value_t::array)
18028  {
18029  stack.reserve(array->size());
18030  std::move(array->begin(), array->end(), std::back_inserter(stack));
18031  }
18032  else if (t == value_t::object)
18033  {
18034  stack.reserve(object->size());
18035  for (auto&& it : *object)
18036  {
18037  stack.push_back(std::move(it.second));
18038  }
18039  }
18040 
18041  while (!stack.empty())
18042  {
18043  // move the last item to local variable to be processed
18044  basic_json current_item(std::move(stack.back()));
18045  stack.pop_back();
18046 
18047  // if current_item is array/object, move
18048  // its children to the stack to be processed later
18049  if (current_item.is_array())
18050  {
18051  std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(),
18052  std::back_inserter(stack));
18053 
18054  current_item.m_value.array->clear();
18055  }
18056  else if (current_item.is_object())
18057  {
18058  for (auto&& it : *current_item.m_value.object)
18059  {
18060  stack.push_back(std::move(it.second));
18061  }
18062 
18063  current_item.m_value.object->clear();
18064  }
18065 
18066  // it's now safe that current_item get destructed
18067  // since it doesn't have any children
18068  }
18069 
18070  switch (t)
18071  {
18072  case value_t::object:
18073  {
18074  AllocatorType<object_t> alloc;
18075  std::allocator_traits<decltype(alloc)>::destroy(alloc, object);
18076  std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1);
18077  break;
18078  }
18079 
18080  case value_t::array:
18081  {
18082  AllocatorType<array_t> alloc;
18083  std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
18084  std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
18085  break;
18086  }
18087 
18088  case value_t::string:
18089  {
18090  AllocatorType<string_t> alloc;
18091  std::allocator_traits<decltype(alloc)>::destroy(alloc, string);
18092  std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);
18093  break;
18094  }
18095 
18096  case value_t::binary:
18097  {
18098  AllocatorType<binary_t> alloc;
18099  std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
18100  std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
18101  break;
18102  }
18103 
18104  default:
18105  {
18106  break;
18107  }
18108  }
18109  }
18110  };
18111 
18112  private:
18131  void assert_invariant(bool check_parents = true) const noexcept
18132  {
18133  JSON_ASSERT(m_type != value_t::object || m_value.object != nullptr);
18134  JSON_ASSERT(m_type != value_t::array || m_value.array != nullptr);
18135  JSON_ASSERT(m_type != value_t::string || m_value.string != nullptr);
18136  JSON_ASSERT(m_type != value_t::binary || m_value.binary != nullptr);
18137 
18138 #if JSON_DIAGNOSTICS
18139  JSON_TRY
18140  {
18141  // cppcheck-suppress assertWithSideEffect
18142  JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j)
18143  {
18144  return j.m_parent == this;
18145  }));
18146  }
18147  JSON_CATCH(...) {} // LCOV_EXCL_LINE
18148 #else
18149  static_cast<void>(check_parents);
18150 #endif
18151  }
18152 
18154  {
18155 #if JSON_DIAGNOSTICS
18156  switch (m_type)
18157  {
18158  case value_t::array:
18159  {
18160  for (auto& element : *m_value.array)
18161  {
18162  element.m_parent = this;
18163  }
18164  break;
18165  }
18166 
18167  case value_t::object:
18168  {
18169  for (auto& element : *m_value.object)
18170  {
18171  element.second.m_parent = this;
18172  }
18173  break;
18174  }
18175 
18176  default:
18177  break;
18178  }
18179 #endif
18180  }
18181 
18183  {
18184 #if JSON_DIAGNOSTICS
18185  for (typename iterator::difference_type i = 0; i < count; ++i)
18186  {
18187  (it + i)->m_parent = this;
18188  }
18189 #else
18190  static_cast<void>(count);
18191 #endif
18192  return it;
18193  }
18194 
18196  {
18197 #if JSON_DIAGNOSTICS
18198  j.m_parent = this;
18199 #else
18200  static_cast<void>(j);
18201 #endif
18202  return j;
18203  }
18204 
18205  public:
18207  // JSON parser callback //
18209 
18226 
18277 
18279  // constructors //
18281 
18286 
18318  : m_type(v), m_value(v)
18319  {
18320  assert_invariant();
18321  }
18322 
18341  basic_json(std::nullptr_t = nullptr) noexcept
18342  : basic_json(value_t::null)
18343  {
18344  assert_invariant();
18345  }
18346 
18409  template < typename CompatibleType,
18410  typename U = detail::uncvref_t<CompatibleType>,
18413  basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape)
18414  JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
18415  std::forward<CompatibleType>(val))))
18416  {
18417  JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val));
18418  set_parents();
18419  assert_invariant();
18420  }
18421 
18448  template < typename BasicJsonType,
18451  basic_json(const BasicJsonType& val)
18452  {
18453  using other_boolean_t = typename BasicJsonType::boolean_t;
18454  using other_number_float_t = typename BasicJsonType::number_float_t;
18455  using other_number_integer_t = typename BasicJsonType::number_integer_t;
18456  using other_number_unsigned_t = typename BasicJsonType::number_unsigned_t;
18457  using other_string_t = typename BasicJsonType::string_t;
18458  using other_object_t = typename BasicJsonType::object_t;
18459  using other_array_t = typename BasicJsonType::array_t;
18460  using other_binary_t = typename BasicJsonType::binary_t;
18461 
18462  switch (val.type())
18463  {
18464  case value_t::boolean:
18465  JSONSerializer<other_boolean_t>::to_json(*this, val.template get<other_boolean_t>());
18466  break;
18467  case value_t::number_float:
18468  JSONSerializer<other_number_float_t>::to_json(*this, val.template get<other_number_float_t>());
18469  break;
18471  JSONSerializer<other_number_integer_t>::to_json(*this, val.template get<other_number_integer_t>());
18472  break;
18474  JSONSerializer<other_number_unsigned_t>::to_json(*this, val.template get<other_number_unsigned_t>());
18475  break;
18476  case value_t::string:
18477  JSONSerializer<other_string_t>::to_json(*this, val.template get_ref<const other_string_t&>());
18478  break;
18479  case value_t::object:
18480  JSONSerializer<other_object_t>::to_json(*this, val.template get_ref<const other_object_t&>());
18481  break;
18482  case value_t::array:
18483  JSONSerializer<other_array_t>::to_json(*this, val.template get_ref<const other_array_t&>());
18484  break;
18485  case value_t::binary:
18486  JSONSerializer<other_binary_t>::to_json(*this, val.template get_ref<const other_binary_t&>());
18487  break;
18488  case value_t::null:
18489  *this = nullptr;
18490  break;
18491  case value_t::discarded:
18492  m_type = value_t::discarded;
18493  break;
18494  default: // LCOV_EXCL_LINE
18495  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
18496  }
18497  set_parents();
18498  assert_invariant();
18499  }
18500 
18576  bool type_deduction = true,
18577  value_t manual_type = value_t::array)
18578  {
18579  // check if each element is an array with two elements whose first
18580  // element is a string
18581  bool is_an_object = std::all_of(init.begin(), init.end(),
18582  [](const detail::json_ref<basic_json>& element_ref)
18583  {
18584  return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
18585  });
18586 
18587  // adjust type if type deduction is not wanted
18588  if (!type_deduction)
18589  {
18590  // if array is wanted, do not create an object though possible
18591  if (manual_type == value_t::array)
18592  {
18593  is_an_object = false;
18594  }
18595 
18596  // if object is wanted but impossible, throw an exception
18597  if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
18598  {
18599  JSON_THROW(type_error::create(301, "cannot create object from initializer list", basic_json()));
18600  }
18601  }
18602 
18603  if (is_an_object)
18604  {
18605  // the initializer list is a list of pairs -> create object
18606  m_type = value_t::object;
18608 
18609  for (auto& element_ref : init)
18610  {
18611  auto element = element_ref.moved_or_copied();
18612  m_value.object->emplace(
18613  std::move(*((*element.m_value.array)[0].m_value.string)),
18614  std::move((*element.m_value.array)[1]));
18615  }
18616  }
18617  else
18618  {
18619  // the initializer list describes an array -> create array
18620  m_type = value_t::array;
18621  m_value.array = create<array_t>(init.begin(), init.end());
18622  }
18623 
18624  set_parents();
18625  assert_invariant();
18626  }
18627 
18656  static basic_json binary(const typename binary_t::container_type& init)
18657  {
18658  auto res = basic_json();
18659  res.m_type = value_t::binary;
18660  res.m_value = init;
18661  return res;
18662  }
18663 
18693  static basic_json binary(const typename binary_t::container_type& init, std::uint8_t subtype)
18694  {
18695  auto res = basic_json();
18696  res.m_type = value_t::binary;
18697  res.m_value = binary_t(init, subtype);
18698  return res;
18699  }
18700 
18704  {
18705  auto res = basic_json();
18706  res.m_type = value_t::binary;
18707  res.m_value = std::move(init);
18708  return res;
18709  }
18710 
18713  static basic_json binary(typename binary_t::container_type&& init, std::uint8_t subtype)
18714  {
18715  auto res = basic_json();
18716  res.m_type = value_t::binary;
18717  res.m_value = binary_t(std::move(init), subtype);
18718  return res;
18719  }
18720 
18760  {
18761  return basic_json(init, false, value_t::array);
18762  }
18763 
18804  {
18805  return basic_json(init, false, value_t::object);
18806  }
18807 
18831  : m_type(value_t::array)
18832  {
18833  m_value.array = create<array_t>(cnt, val);
18834  set_parents();
18835  assert_invariant();
18836  }
18837 
18893  template < class InputIT, typename std::enable_if <
18896  basic_json(InputIT first, InputIT last)
18897  {
18898  JSON_ASSERT(first.m_object != nullptr);
18899  JSON_ASSERT(last.m_object != nullptr);
18900 
18901  // make sure iterator fits the current value
18902  if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
18903  {
18904  JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", basic_json()));
18905  }
18906 
18907  // copy type from first iterator
18908  m_type = first.m_object->m_type;
18909 
18910  // check if iterator range is complete for primitive values
18911  switch (m_type)
18912  {
18913  case value_t::boolean:
18914  case value_t::number_float:
18917  case value_t::string:
18918  {
18919  if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
18920  || !last.m_it.primitive_iterator.is_end()))
18921  {
18922  JSON_THROW(invalid_iterator::create(204, "iterators out of range", *first.m_object));
18923  }
18924  break;
18925  }
18926 
18927  default:
18928  break;
18929  }
18930 
18931  switch (m_type)
18932  {
18934  {
18935  m_value.number_integer = first.m_object->m_value.number_integer;
18936  break;
18937  }
18938 
18940  {
18941  m_value.number_unsigned = first.m_object->m_value.number_unsigned;
18942  break;
18943  }
18944 
18945  case value_t::number_float:
18946  {
18947  m_value.number_float = first.m_object->m_value.number_float;
18948  break;
18949  }
18950 
18951  case value_t::boolean:
18952  {
18953  m_value.boolean = first.m_object->m_value.boolean;
18954  break;
18955  }
18956 
18957  case value_t::string:
18958  {
18959  m_value = *first.m_object->m_value.string;
18960  break;
18961  }
18962 
18963  case value_t::object:
18964  {
18965  m_value.object = create<object_t>(first.m_it.object_iterator,
18966  last.m_it.object_iterator);
18967  break;
18968  }
18969 
18970  case value_t::array:
18971  {
18972  m_value.array = create<array_t>(first.m_it.array_iterator,
18973  last.m_it.array_iterator);
18974  break;
18975  }
18976 
18977  case value_t::binary:
18978  {
18979  m_value = *first.m_object->m_value.binary;
18980  break;
18981  }
18982 
18983  default:
18984  JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
18985  }
18986 
18987  set_parents();
18988  assert_invariant();
18989  }
18990 
18991 
18993  // other constructors and destructor //
18995 
18996  template<typename JsonRef,
18998  std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 >
18999  basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {}
19000 
19026  basic_json(const basic_json& other)
19027  : m_type(other.m_type)
19028  {
19029  // check of passed value is valid
19030  other.assert_invariant();
19031 
19032  switch (m_type)
19033  {
19034  case value_t::object:
19035  {
19036  m_value = *other.m_value.object;
19037  break;
19038  }
19039 
19040  case value_t::array:
19041  {
19042  m_value = *other.m_value.array;
19043  break;
19044  }
19045 
19046  case value_t::string:
19047  {
19048  m_value = *other.m_value.string;
19049  break;
19050  }
19051 
19052  case value_t::boolean:
19053  {
19054  m_value = other.m_value.boolean;
19055  break;
19056  }
19057 
19059  {
19060  m_value = other.m_value.number_integer;
19061  break;
19062  }
19063 
19065  {
19066  m_value = other.m_value.number_unsigned;
19067  break;
19068  }
19069 
19070  case value_t::number_float:
19071  {
19072  m_value = other.m_value.number_float;
19073  break;
19074  }
19075 
19076  case value_t::binary:
19077  {
19078  m_value = *other.m_value.binary;
19079  break;
19080  }
19081 
19082  default:
19083  break;
19084  }
19085 
19086  set_parents();
19087  assert_invariant();
19088  }
19089 
19116  basic_json(basic_json&& other) noexcept
19117  : m_type(std::move(other.m_type)),
19118  m_value(std::move(other.m_value))
19119  {
19120  // check that passed value is valid
19121  other.assert_invariant(false);
19122 
19123  // invalidate payload
19124  other.m_type = value_t::null;
19125  other.m_value = {};
19126 
19127  set_parents();
19128  assert_invariant();
19129  }
19130 
19154  basic_json& operator=(basic_json other) noexcept (
19159  )
19160  {
19161  // check that passed value is valid
19162  other.assert_invariant();
19163 
19164  using std::swap;
19165  swap(m_type, other.m_type);
19166  swap(m_value, other.m_value);
19167 
19168  set_parents();
19169  assert_invariant();
19170  return *this;
19171  }
19172 
19188  ~basic_json() noexcept
19189  {
19190  assert_invariant(false);
19191  m_value.destroy(m_type);
19192  }
19193 
19195 
19196  public:
19198  // object inspection //
19200 
19204 
19252  string_t dump(const int indent = -1,
19253  const char indent_char = ' ',
19254  const bool ensure_ascii = false,
19255  const error_handler_t error_handler = error_handler_t::strict) const
19256  {
19257  string_t result;
19258  serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
19259 
19260  if (indent >= 0)
19261  {
19262  s.dump(*this, true, ensure_ascii, static_cast<unsigned int>(indent));
19263  }
19264  else
19265  {
19266  s.dump(*this, false, ensure_ascii, 0);
19267  }
19268 
19269  return result;
19270  }
19271 
19305  constexpr value_t type() const noexcept
19306  {
19307  return m_type;
19308  }
19309 
19336  constexpr bool is_primitive() const noexcept
19337  {
19338  return is_null() || is_string() || is_boolean() || is_number() || is_binary();
19339  }
19340 
19363  constexpr bool is_structured() const noexcept
19364  {
19365  return is_array() || is_object();
19366  }
19367 
19385  constexpr bool is_null() const noexcept
19386  {
19387  return m_type == value_t::null;
19388  }
19389 
19407  constexpr bool is_boolean() const noexcept
19408  {
19409  return m_type == value_t::boolean;
19410  }
19411 
19437  constexpr bool is_number() const noexcept
19438  {
19439  return is_number_integer() || is_number_float();
19440  }
19441 
19466  constexpr bool is_number_integer() const noexcept
19467  {
19468  return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
19469  }
19470 
19494  constexpr bool is_number_unsigned() const noexcept
19495  {
19496  return m_type == value_t::number_unsigned;
19497  }
19498 
19522  constexpr bool is_number_float() const noexcept
19523  {
19524  return m_type == value_t::number_float;
19525  }
19526 
19544  constexpr bool is_object() const noexcept
19545  {
19546  return m_type == value_t::object;
19547  }
19548 
19566  constexpr bool is_array() const noexcept
19567  {
19568  return m_type == value_t::array;
19569  }
19570 
19588  constexpr bool is_string() const noexcept
19589  {
19590  return m_type == value_t::string;
19591  }
19592 
19610  constexpr bool is_binary() const noexcept
19611  {
19612  return m_type == value_t::binary;
19613  }
19614 
19637  constexpr bool is_discarded() const noexcept
19638  {
19639  return m_type == value_t::discarded;
19640  }
19641 
19663  constexpr operator value_t() const noexcept
19664  {
19665  return m_type;
19666  }
19667 
19669 
19670  private:
19672  // value access //
19674 
19676  boolean_t get_impl(boolean_t* /*unused*/) const
19677  {
19679  {
19680  return m_value.boolean;
19681  }
19682 
19683  JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(type_name()), *this));
19684  }
19685 
19687  object_t* get_impl_ptr(object_t* /*unused*/) noexcept
19688  {
19689  return is_object() ? m_value.object : nullptr;
19690  }
19691 
19693  constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept
19694  {
19695  return is_object() ? m_value.object : nullptr;
19696  }
19697 
19699  array_t* get_impl_ptr(array_t* /*unused*/) noexcept
19700  {
19701  return is_array() ? m_value.array : nullptr;
19702  }
19703 
19705  constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept
19706  {
19707  return is_array() ? m_value.array : nullptr;
19708  }
19709 
19711  string_t* get_impl_ptr(string_t* /*unused*/) noexcept
19712  {
19713  return is_string() ? m_value.string : nullptr;
19714  }
19715 
19717  constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept
19718  {
19719  return is_string() ? m_value.string : nullptr;
19720  }
19721 
19723  boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept
19724  {
19725  return is_boolean() ? &m_value.boolean : nullptr;
19726  }
19727 
19729  constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept
19730  {
19731  return is_boolean() ? &m_value.boolean : nullptr;
19732  }
19733 
19736  {
19737  return is_number_integer() ? &m_value.number_integer : nullptr;
19738  }
19739 
19741  constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept
19742  {
19743  return is_number_integer() ? &m_value.number_integer : nullptr;
19744  }
19745 
19748  {
19749  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
19750  }
19751 
19753  constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept
19754  {
19755  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
19756  }
19757 
19760  {
19761  return is_number_float() ? &m_value.number_float : nullptr;
19762  }
19763 
19765  constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept
19766  {
19767  return is_number_float() ? &m_value.number_float : nullptr;
19768  }
19769 
19771  binary_t* get_impl_ptr(binary_t* /*unused*/) noexcept
19772  {
19773  return is_binary() ? m_value.binary : nullptr;
19774  }
19775 
19777  constexpr const binary_t* get_impl_ptr(const binary_t* /*unused*/) const noexcept
19778  {
19779  return is_binary() ? m_value.binary : nullptr;
19780  }
19781 
19793  template<typename ReferenceType, typename ThisType>
19794  static ReferenceType get_ref_impl(ThisType& obj)
19795  {
19796  // delegate the call to get_ptr<>()
19797  auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
19798 
19799  if (JSON_HEDLEY_LIKELY(ptr != nullptr))
19800  {
19801  return *ptr;
19802  }
19803 
19804  JSON_THROW(type_error::create(303, "incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
19805  }
19806 
19807  public:
19811 
19826  template<typename BasicJsonType, detail::enable_if_t<
19828  int> = 0>
19829  basic_json get() const
19830  {
19831  return *this;
19832  }
19833 
19849  template < typename BasicJsonType, detail::enable_if_t <
19852  BasicJsonType get() const
19853  {
19854  return *this;
19855  }
19856 
19896  template < typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>,
19897  detail::enable_if_t <
19898  !detail::is_basic_json<ValueType>::value &&
19899  detail::has_from_json<basic_json_t, ValueType>::value &&
19900  !detail::has_non_default_from_json<basic_json_t, ValueType>::value,
19901  int > = 0 >
19902  ValueType get() const noexcept(noexcept(
19903  JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
19904  {
19905  // we cannot static_assert on ValueTypeCV being non-const, because
19906  // there is support for get<const basic_json_t>(), which is why we
19907  // still need the uncvref
19909  "get() cannot be used with reference types, you might want to use get_ref()");
19911  "types must be DefaultConstructible when used with get()");
19912 
19913  ValueType ret{};
19915  return ret;
19916  }
19917 
19949  template < typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>,
19950  detail::enable_if_t < !std::is_same<basic_json_t, ValueType>::value &&
19951  detail::has_non_default_from_json<basic_json_t, ValueType>::value,
19952  int > = 0 >
19953  ValueType get() const noexcept(noexcept(
19954  JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
19955  {
19957  "get() cannot be used with reference types, you might want to use get_ref()");
19959  }
19960 
19994  template < typename ValueType,
19998  int > = 0 >
19999  ValueType & get_to(ValueType& v) const noexcept(noexcept(
20000  JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
20001  {
20003  return v;
20004  }
20005 
20006  // specialization to allow to call get_to with a basic_json value
20007  // see https://github.com/nlohmann/json/issues/2175
20008  template<typename ValueType,
20011  int> = 0>
20012  ValueType & get_to(ValueType& v) const
20013  {
20014  v = *this;
20015  return v;
20016  }
20017 
20018  template <
20019  typename T, std::size_t N,
20020  typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
20023  Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
20024  noexcept(noexcept(JSONSerializer<Array>::from_json(
20025  std::declval<const basic_json_t&>(), v)))
20026  {
20028  return v;
20029  }
20030 
20031 
20058  template<typename PointerType, typename std::enable_if<
20060  auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20061  {
20062  // delegate the call to get_impl_ptr<>()
20063  return get_impl_ptr(static_cast<PointerType>(nullptr));
20064  }
20065 
20070  template < typename PointerType, typename std::enable_if <
20073  constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20074  {
20075  // delegate the call to get_impl_ptr<>() const
20076  return get_impl_ptr(static_cast<PointerType>(nullptr));
20077  }
20078 
20106  template<typename PointerType, typename std::enable_if<
20108  auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
20109  {
20110  // delegate the call to get_ptr
20111  return get_ptr<PointerType>();
20112  }
20113 
20118  template<typename PointerType, typename std::enable_if<
20120  constexpr auto get() const noexcept -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
20121  {
20122  // delegate the call to get_ptr
20123  return get_ptr<PointerType>();
20124  }
20125 
20152  template<typename ReferenceType, typename std::enable_if<
20154  ReferenceType get_ref()
20155  {
20156  // delegate call to get_ref_impl
20157  return get_ref_impl<ReferenceType>(*this);
20158  }
20159 
20164  template < typename ReferenceType, typename std::enable_if <
20167  ReferenceType get_ref() const
20168  {
20169  // delegate call to get_ref_impl
20170  return get_ref_impl<ReferenceType>(*this);
20171  }
20172 
20202  template < typename ValueType, typename std::enable_if <
20204  !std::is_same<ValueType, detail::json_ref<basic_json>>::value&&
20207  && !std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
20208 #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
20210 #endif
20212  , int >::type = 0 >
20213  JSON_EXPLICIT operator ValueType() const
20214  {
20215  // delegate the call to get<>() const
20216  return get<ValueType>();
20217  }
20218 
20229  {
20230  if (!is_binary())
20231  {
20232  JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this));
20233  }
20234 
20235  return *get_ptr<binary_t*>();
20236  }
20237 
20239  const binary_t& get_binary() const
20240  {
20241  if (!is_binary())
20242  {
20243  JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this));
20244  }
20245 
20246  return *get_ptr<const binary_t*>();
20247  }
20248 
20250 
20251 
20253  // element access //
20255 
20259 
20287  {
20288  // at only works for arrays
20290  {
20291  JSON_TRY
20292  {
20293  return set_parent(m_value.array->at(idx));
20294  }
20295  JSON_CATCH (std::out_of_range&)
20296  {
20297  // create better exception explanation
20298  JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
20299  }
20300  }
20301  else
20302  {
20303  JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
20304  }
20305  }
20306 
20334  {
20335  // at only works for arrays
20337  {
20338  JSON_TRY
20339  {
20340  return m_value.array->at(idx);
20341  }
20342  JSON_CATCH (std::out_of_range&)
20343  {
20344  // create better exception explanation
20345  JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
20346  }
20347  }
20348  else
20349  {
20350  JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
20351  }
20352  }
20353 
20384  reference at(const typename object_t::key_type& key)
20385  {
20386  // at only works for objects
20388  {
20389  JSON_TRY
20390  {
20391  return set_parent(m_value.object->at(key));
20392  }
20393  JSON_CATCH (std::out_of_range&)
20394  {
20395  // create better exception explanation
20396  JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this));
20397  }
20398  }
20399  else
20400  {
20401  JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
20402  }
20403  }
20404 
20435  const_reference at(const typename object_t::key_type& key) const
20436  {
20437  // at only works for objects
20439  {
20440  JSON_TRY
20441  {
20442  return m_value.object->at(key);
20443  }
20444  JSON_CATCH (std::out_of_range&)
20445  {
20446  // create better exception explanation
20447  JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this));
20448  }
20449  }
20450  else
20451  {
20452  JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
20453  }
20454  }
20455 
20482  {
20483  // implicitly convert null value to an empty array
20484  if (is_null())
20485  {
20486  m_type = value_t::array;
20487  m_value.array = create<array_t>();
20488  assert_invariant();
20489  }
20490 
20491  // operator[] only works for arrays
20493  {
20494  // fill up array with null values if given idx is outside range
20495  if (idx >= m_value.array->size())
20496  {
20497 #if JSON_DIAGNOSTICS
20498  // remember array size before resizing
20499  const auto previous_size = m_value.array->size();
20500 #endif
20501  m_value.array->resize(idx + 1);
20502 
20503 #if JSON_DIAGNOSTICS
20504  // set parent for values added above
20505  set_parents(begin() + static_cast<typename iterator::difference_type>(previous_size), static_cast<typename iterator::difference_type>(idx + 1 - previous_size));
20506 #endif
20507  }
20508 
20509  return m_value.array->operator[](idx);
20510  }
20511 
20512  JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
20513  }
20514 
20535  {
20536  // const operator[] only works for arrays
20538  {
20539  return m_value.array->operator[](idx);
20540  }
20541 
20542  JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
20543  }
20544 
20572  reference operator[](const typename object_t::key_type& key)
20573  {
20574  // implicitly convert null value to an empty object
20575  if (is_null())
20576  {
20577  m_type = value_t::object;
20578  m_value.object = create<object_t>();
20579  assert_invariant();
20580  }
20581 
20582  // operator[] only works for objects
20584  {
20585  return set_parent(m_value.object->operator[](key));
20586  }
20587 
20588  JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
20589  }
20590 
20621  const_reference operator[](const typename object_t::key_type& key) const
20622  {
20623  // const operator[] only works for objects
20625  {
20626  JSON_ASSERT(m_value.object->find(key) != m_value.object->end());
20627  return m_value.object->find(key)->second;
20628  }
20629 
20630  JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
20631  }
20632 
20660  template<typename T>
20662  reference operator[](T* key)
20663  {
20664  // implicitly convert null to object
20665  if (is_null())
20666  {
20667  m_type = value_t::object;
20669  assert_invariant();
20670  }
20671 
20672  // at only works for objects
20674  {
20675  return set_parent(m_value.object->operator[](key));
20676  }
20677 
20678  JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
20679  }
20680 
20711  template<typename T>
20713  const_reference operator[](T* key) const
20714  {
20715  // at only works for objects
20717  {
20718  JSON_ASSERT(m_value.object->find(key) != m_value.object->end());
20719  return m_value.object->find(key)->second;
20720  }
20721 
20722  JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
20723  }
20724 
20775  // using std::is_convertible in a std::enable_if will fail when using explicit conversions
20776  template < class ValueType, typename std::enable_if <
20779  ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
20780  {
20781  // at only works for objects
20783  {
20784  // if key is found, return value and given default value otherwise
20785  const auto it = find(key);
20786  if (it != end())
20787  {
20788  return it->template get<ValueType>();
20789  }
20790 
20791  return default_value;
20792  }
20793 
20794  JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this));
20795  }
20796 
20801  string_t value(const typename object_t::key_type& key, const char* default_value) const
20802  {
20803  return value(key, string_t(default_value));
20804  }
20805 
20849  template<class ValueType, typename std::enable_if<
20851  ValueType value(const json_pointer& ptr, const ValueType& default_value) const
20852  {
20853  // at only works for objects
20855  {
20856  // if pointer resolves a value, return it or use default value
20857  JSON_TRY
20858  {
20859  return ptr.get_checked(this).template get<ValueType>();
20860  }
20862  {
20863  return default_value;
20864  }
20865  }
20866 
20867  JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this));
20868  }
20869 
20875  string_t value(const json_pointer& ptr, const char* default_value) const
20876  {
20877  return value(ptr, string_t(default_value));
20878  }
20879 
20906  {
20907  return *begin();
20908  }
20909 
20914  {
20915  return *cbegin();
20916  }
20917 
20950  {
20951  auto tmp = end();
20952  --tmp;
20953  return *tmp;
20954  }
20955 
20960  {
20961  auto tmp = cend();
20962  --tmp;
20963  return *tmp;
20964  }
20965 
21012  template < class IteratorType, typename std::enable_if <
21015  = 0 >
21016  IteratorType erase(IteratorType pos)
21017  {
21018  // make sure iterator fits the current value
21019  if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))
21020  {
21021  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
21022  }
21023 
21024  IteratorType result = end();
21025 
21026  switch (m_type)
21027  {
21028  case value_t::boolean:
21029  case value_t::number_float:
21032  case value_t::string:
21033  case value_t::binary:
21034  {
21035  if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21036  {
21037  JSON_THROW(invalid_iterator::create(205, "iterator out of range", *this));
21038  }
21039 
21040  if (is_string())
21041  {
21042  AllocatorType<string_t> alloc;
21043  std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
21044  std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
21045  m_value.string = nullptr;
21046  }
21047  else if (is_binary())
21048  {
21049  AllocatorType<binary_t> alloc;
21050  std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
21051  std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
21052  m_value.binary = nullptr;
21053  }
21054 
21055  m_type = value_t::null;
21056  assert_invariant();
21057  break;
21058  }
21059 
21060  case value_t::object:
21061  {
21062  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
21063  break;
21064  }
21065 
21066  case value_t::array:
21067  {
21068  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
21069  break;
21070  }
21071 
21072  default:
21073  JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
21074  }
21075 
21076  return result;
21077  }
21078 
21125  template < class IteratorType, typename std::enable_if <
21128  = 0 >
21129  IteratorType erase(IteratorType first, IteratorType last)
21130  {
21131  // make sure iterator fits the current value
21132  if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object))
21133  {
21134  JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", *this));
21135  }
21136 
21137  IteratorType result = end();
21138 
21139  switch (m_type)
21140  {
21141  case value_t::boolean:
21142  case value_t::number_float:
21145  case value_t::string:
21146  case value_t::binary:
21147  {
21148  if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21149  || !last.m_it.primitive_iterator.is_end()))
21150  {
21151  JSON_THROW(invalid_iterator::create(204, "iterators out of range", *this));
21152  }
21153 
21154  if (is_string())
21155  {
21156  AllocatorType<string_t> alloc;
21157  std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
21158  std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
21159  m_value.string = nullptr;
21160  }
21161  else if (is_binary())
21162  {
21163  AllocatorType<binary_t> alloc;
21164  std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
21165  std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
21166  m_value.binary = nullptr;
21167  }
21168 
21169  m_type = value_t::null;
21170  assert_invariant();
21171  break;
21172  }
21173 
21174  case value_t::object:
21175  {
21176  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
21177  last.m_it.object_iterator);
21178  break;
21179  }
21180 
21181  case value_t::array:
21182  {
21183  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
21184  last.m_it.array_iterator);
21185  break;
21186  }
21187 
21188  default:
21189  JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
21190  }
21191 
21192  return result;
21193  }
21194 
21224  size_type erase(const typename object_t::key_type& key)
21225  {
21226  // this erase only works for objects
21228  {
21229  return m_value.object->erase(key);
21230  }
21231 
21232  JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
21233  }
21234 
21259  void erase(const size_type idx)
21260  {
21261  // this erase only works for arrays
21263  {
21264  if (JSON_HEDLEY_UNLIKELY(idx >= size()))
21265  {
21266  JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
21267  }
21268 
21269  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
21270  }
21271  else
21272  {
21273  JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
21274  }
21275  }
21276 
21278 
21279 
21281  // lookup //
21283 
21286 
21311  template<typename KeyT>
21312  iterator find(KeyT&& key)
21313  {
21314  auto result = end();
21315 
21316  if (is_object())
21317  {
21318  result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
21319  }
21320 
21321  return result;
21322  }
21323 
21328  template<typename KeyT>
21329  const_iterator find(KeyT&& key) const
21330  {
21331  auto result = cend();
21332 
21333  if (is_object())
21334  {
21335  result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
21336  }
21337 
21338  return result;
21339  }
21340 
21362  template<typename KeyT>
21363  size_type count(KeyT&& key) const
21364  {
21365  // return 0 for all nonobject types
21366  return is_object() ? m_value.object->count(std::forward<KeyT>(key)) : 0;
21367  }
21368 
21394  template < typename KeyT, typename std::enable_if <
21396  bool contains(KeyT && key) const
21397  {
21398  return is_object() && m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
21399  }
21400 
21427  bool contains(const json_pointer& ptr) const
21428  {
21429  return ptr.contains(this);
21430  }
21431 
21433 
21434 
21436  // iterators //
21438 
21441 
21466  iterator begin() noexcept
21467  {
21468  iterator result(this);
21469  result.set_begin();
21470  return result;
21471  }
21472 
21477  {
21478  return cbegin();
21479  }
21480 
21507  {
21508  const_iterator result(this);
21509  result.set_begin();
21510  return result;
21511  }
21512 
21537  iterator end() noexcept
21538  {
21539  iterator result(this);
21540  result.set_end();
21541  return result;
21542  }
21543 
21548  {
21549  return cend();
21550  }
21551 
21578  {
21579  const_iterator result(this);
21580  result.set_end();
21581  return result;
21582  }
21583 
21608  {
21609  return reverse_iterator(end());
21610  }
21611 
21616  {
21617  return crbegin();
21618  }
21619 
21645  {
21646  return reverse_iterator(begin());
21647  }
21648 
21653  {
21654  return crend();
21655  }
21656 
21682  {
21683  return const_reverse_iterator(cend());
21684  }
21685 
21711  {
21712  return const_reverse_iterator(cbegin());
21713  }
21714 
21715  public:
21775  {
21776  return ref.items();
21777  }
21778 
21784  {
21785  return ref.items();
21786  }
21787 
21857  {
21858  return iteration_proxy<iterator>(*this);
21859  }
21860 
21865  {
21866  return iteration_proxy<const_iterator>(*this);
21867  }
21868 
21870 
21871 
21873  // capacity //
21875 
21878 
21921  bool empty() const noexcept
21922  {
21923  switch (m_type)
21924  {
21925  case value_t::null:
21926  {
21927  // null values are empty
21928  return true;
21929  }
21930 
21931  case value_t::array:
21932  {
21933  // delegate call to array_t::empty()
21934  return m_value.array->empty();
21935  }
21936 
21937  case value_t::object:
21938  {
21939  // delegate call to object_t::empty()
21940  return m_value.object->empty();
21941  }
21942 
21943  default:
21944  {
21945  // all other types are nonempty
21946  return false;
21947  }
21948  }
21949  }
21950 
21994  size_type size() const noexcept
21995  {
21996  switch (m_type)
21997  {
21998  case value_t::null:
21999  {
22000  // null values are empty
22001  return 0;
22002  }
22003 
22004  case value_t::array:
22005  {
22006  // delegate call to array_t::size()
22007  return m_value.array->size();
22008  }
22009 
22010  case value_t::object:
22011  {
22012  // delegate call to object_t::size()
22013  return m_value.object->size();
22014  }
22015 
22016  default:
22017  {
22018  // all other types have size 1
22019  return 1;
22020  }
22021  }
22022  }
22023 
22066  {
22067  switch (m_type)
22068  {
22069  case value_t::array:
22070  {
22071  // delegate call to array_t::max_size()
22072  return m_value.array->max_size();
22073  }
22074 
22075  case value_t::object:
22076  {
22077  // delegate call to object_t::max_size()
22078  return m_value.object->max_size();
22079  }
22080 
22081  default:
22082  {
22083  // all other types have max_size() == size()
22084  return size();
22085  }
22086  }
22087  }
22088 
22090 
22091 
22093  // modifiers //
22095 
22098 
22136  void clear() noexcept
22137  {
22138  switch (m_type)
22139  {
22141  {
22142  m_value.number_integer = 0;
22143  break;
22144  }
22145 
22147  {
22148  m_value.number_unsigned = 0;
22149  break;
22150  }
22151 
22152  case value_t::number_float:
22153  {
22154  m_value.number_float = 0.0;
22155  break;
22156  }
22157 
22158  case value_t::boolean:
22159  {
22160  m_value.boolean = false;
22161  break;
22162  }
22163 
22164  case value_t::string:
22165  {
22166  m_value.string->clear();
22167  break;
22168  }
22169 
22170  case value_t::binary:
22171  {
22172  m_value.binary->clear();
22173  break;
22174  }
22175 
22176  case value_t::array:
22177  {
22178  m_value.array->clear();
22179  break;
22180  }
22181 
22182  case value_t::object:
22183  {
22184  m_value.object->clear();
22185  break;
22186  }
22187 
22188  default:
22189  break;
22190  }
22191  }
22192 
22213  void push_back(basic_json&& val)
22214  {
22215  // push_back only works for null objects or arrays
22216  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22217  {
22218  JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
22219  }
22220 
22221  // transform null object into an array
22222  if (is_null())
22223  {
22224  m_type = value_t::array;
22226  assert_invariant();
22227  }
22228 
22229  // add element to array (move semantics)
22230  m_value.array->push_back(std::move(val));
22231  set_parent(m_value.array->back());
22232  // if val is moved from, basic_json move constructor marks it null so we do not call the destructor
22233  }
22234 
22240  {
22241  push_back(std::move(val));
22242  return *this;
22243  }
22244 
22249  void push_back(const basic_json& val)
22250  {
22251  // push_back only works for null objects or arrays
22252  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22253  {
22254  JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
22255  }
22256 
22257  // transform null object into an array
22258  if (is_null())
22259  {
22260  m_type = value_t::array;
22262  assert_invariant();
22263  }
22264 
22265  // add element to array
22266  m_value.array->push_back(val);
22267  set_parent(m_value.array->back());
22268  }
22269 
22275  {
22276  push_back(val);
22277  return *this;
22278  }
22279 
22300  void push_back(const typename object_t::value_type& val)
22301  {
22302  // push_back only works for null objects or objects
22303  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22304  {
22305  JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
22306  }
22307 
22308  // transform null object into an object
22309  if (is_null())
22310  {
22311  m_type = value_t::object;
22313  assert_invariant();
22314  }
22315 
22316  // add element to object
22317  auto res = m_value.object->insert(val);
22318  set_parent(res.first->second);
22319  }
22320 
22325  reference operator+=(const typename object_t::value_type& val)
22326  {
22327  push_back(val);
22328  return *this;
22329  }
22330 
22357  {
22358  if (is_object() && init.size() == 2 && (*init.begin())->is_string())
22359  {
22360  basic_json&& key = init.begin()->moved_or_copied();
22361  push_back(typename object_t::value_type(
22362  std::move(key.get_ref<string_t&>()), (init.begin() + 1)->moved_or_copied()));
22363  }
22364  else
22365  {
22366  push_back(basic_json(init));
22367  }
22368  }
22369 
22375  {
22376  push_back(init);
22377  return *this;
22378  }
22379 
22403  template<class... Args>
22404  reference emplace_back(Args&& ... args)
22405  {
22406  // emplace_back only works for null objects or arrays
22407  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22408  {
22409  JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name()), *this));
22410  }
22411 
22412  // transform null object into an array
22413  if (is_null())
22414  {
22415  m_type = value_t::array;
22417  assert_invariant();
22418  }
22419 
22420  // add element to array (perfect forwarding)
22421 #ifdef JSON_HAS_CPP_17
22422  return set_parent(m_value.array->emplace_back(std::forward<Args>(args)...));
22423 #else
22424  m_value.array->emplace_back(std::forward<Args>(args)...);
22425  return set_parent(m_value.array->back());
22426 #endif
22427  }
22428 
22456  template<class... Args>
22457  std::pair<iterator, bool> emplace(Args&& ... args)
22458  {
22459  // emplace only works for null objects or arrays
22460  if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22461  {
22462  JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()), *this));
22463  }
22464 
22465  // transform null object into an object
22466  if (is_null())
22467  {
22468  m_type = value_t::object;
22470  assert_invariant();
22471  }
22472 
22473  // add element to array (perfect forwarding)
22474  auto res = m_value.object->emplace(std::forward<Args>(args)...);
22475  set_parent(res.first->second);
22476 
22477  // create result iterator and set iterator to the result of emplace
22478  auto it = begin();
22479  it.m_it.object_iterator = res.first;
22480 
22481  // return pair of iterator and boolean
22482  return {it, res.second};
22483  }
22484 
22488  template<typename... Args>
22490  {
22491  iterator result(this);
22492  JSON_ASSERT(m_value.array != nullptr);
22493 
22494  auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
22495  m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22496  result.m_it.array_iterator = m_value.array->begin() + insert_pos;
22497 
22498  // This could have been written as:
22499  // result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
22500  // but the return value of insert is missing in GCC 4.8, so it is written this way instead.
22501 
22502  return result;
22503  }
22504 
22528  {
22529  // insert only works for arrays
22531  {
22532  // check if iterator pos fits to this JSON value
22533  if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
22534  {
22535  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
22536  }
22537 
22538  // insert to array and return iterator
22539  return set_parents(insert_iterator(pos, val), static_cast<typename iterator::difference_type>(1));
22540  }
22541 
22542  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22543  }
22544 
22550  {
22551  return insert(pos, val);
22552  }
22553 
22579  {
22580  // insert only works for arrays
22582  {
22583  // check if iterator pos fits to this JSON value
22584  if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
22585  {
22586  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
22587  }
22588 
22589  // insert to array and return iterator
22590  return set_parents(insert_iterator(pos, cnt, val), static_cast<typename iterator::difference_type>(cnt));
22591  }
22592 
22593  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22594  }
22595 
22627  {
22628  // insert only works for arrays
22630  {
22631  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22632  }
22633 
22634  // check if iterator pos fits to this JSON value
22635  if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
22636  {
22637  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
22638  }
22639 
22640  // check if range iterators belong to the same JSON object
22641  if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22642  {
22643  JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
22644  }
22645 
22646  if (JSON_HEDLEY_UNLIKELY(first.m_object == this))
22647  {
22648  JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container", *this));
22649  }
22650 
22651  // insert to array and return iterator
22652  return set_parents(insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator), std::distance(first, last));
22653  }
22654 
22680  {
22681  // insert only works for arrays
22683  {
22684  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22685  }
22686 
22687  // check if iterator pos fits to this JSON value
22688  if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
22689  {
22690  JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
22691  }
22692 
22693  // insert to array and return iterator
22694  return set_parents(insert_iterator(pos, ilist.begin(), ilist.end()), static_cast<typename iterator::difference_type>(ilist.size()));
22695  }
22696 
22721  {
22722  // insert only works for objects
22724  {
22725  JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
22726  }
22727 
22728  // check if range iterators belong to the same JSON object
22729  if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22730  {
22731  JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
22732  }
22733 
22734  // passed iterators must belong to objects
22735  if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22736  {
22737  JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
22738  }
22739 
22740  m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22741  }
22742 
22763  {
22764  // implicitly convert null value to an empty object
22765  if (is_null())
22766  {
22767  m_type = value_t::object;
22768  m_value.object = create<object_t>();
22769  assert_invariant();
22770  }
22771 
22773  {
22774  JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
22775  }
22776  if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
22777  {
22778  JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this));
22779  }
22780 
22781  for (auto it = j.cbegin(); it != j.cend(); ++it)
22782  {
22783  m_value.object->operator[](it.key()) = it.value();
22784  }
22785  }
22786 
22814  {
22815  // implicitly convert null value to an empty object
22816  if (is_null())
22817  {
22818  m_type = value_t::object;
22819  m_value.object = create<object_t>();
22820  assert_invariant();
22821  }
22822 
22824  {
22825  JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
22826  }
22827 
22828  // check if range iterators belong to the same JSON object
22829  if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22830  {
22831  JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
22832  }
22833 
22834  // passed iterators must belong to objects
22835  if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
22836  || !last.m_object->is_object()))
22837  {
22838  JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
22839  }
22840 
22841  for (auto it = first; it != last; ++it)
22842  {
22843  m_value.object->operator[](it.key()) = it.value();
22844  }
22845  }
22846 
22864  void swap(reference other) noexcept (
22869  )
22870  {
22871  std::swap(m_type, other.m_type);
22872  std::swap(m_value, other.m_value);
22873 
22874  set_parents();
22875  other.set_parents();
22876  assert_invariant();
22877  }
22878 
22897  friend void swap(reference left, reference right) noexcept (
22902  )
22903  {
22904  left.swap(right);
22905  }
22906 
22927  void swap(array_t& other) // NOLINT(bugprone-exception-escape)
22928  {
22929  // swap only works for arrays
22931  {
22932  std::swap(*(m_value.array), other);
22933  }
22934  else
22935  {
22936  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
22937  }
22938  }
22939 
22960  void swap(object_t& other) // NOLINT(bugprone-exception-escape)
22961  {
22962  // swap only works for objects
22964  {
22965  std::swap(*(m_value.object), other);
22966  }
22967  else
22968  {
22969  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
22970  }
22971  }
22972 
22993  void swap(string_t& other) // NOLINT(bugprone-exception-escape)
22994  {
22995  // swap only works for strings
22997  {
22998  std::swap(*(m_value.string), other);
22999  }
23000  else
23001  {
23002  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
23003  }
23004  }
23005 
23026  void swap(binary_t& other) // NOLINT(bugprone-exception-escape)
23027  {
23028  // swap only works for strings
23030  {
23031  std::swap(*(m_value.binary), other);
23032  }
23033  else
23034  {
23035  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
23036  }
23037  }
23038 
23040  void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape)
23041  {
23042  // swap only works for strings
23044  {
23045  std::swap(*(m_value.binary), other);
23046  }
23047  else
23048  {
23049  JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
23050  }
23051  }
23052 
23054 
23055  public:
23057  // lexicographical comparison operators //
23059 
23062 
23118  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
23119  {
23120  const auto lhs_type = lhs.type();
23121  const auto rhs_type = rhs.type();
23122 
23123  if (lhs_type == rhs_type)
23124  {
23125  switch (lhs_type)
23126  {
23127  case value_t::array:
23128  return *lhs.m_value.array == *rhs.m_value.array;
23129 
23130  case value_t::object:
23131  return *lhs.m_value.object == *rhs.m_value.object;
23132 
23133  case value_t::null:
23134  return true;
23135 
23136  case value_t::string:
23137  return *lhs.m_value.string == *rhs.m_value.string;
23138 
23139  case value_t::boolean:
23140  return lhs.m_value.boolean == rhs.m_value.boolean;
23141 
23143  return lhs.m_value.number_integer == rhs.m_value.number_integer;
23144 
23146  return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
23147 
23148  case value_t::number_float:
23149  return lhs.m_value.number_float == rhs.m_value.number_float;
23150 
23151  case value_t::binary:
23152  return *lhs.m_value.binary == *rhs.m_value.binary;
23153 
23154  default:
23155  return false;
23156  }
23157  }
23158  else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23159  {
23160  return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
23161  }
23162  else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23163  {
23164  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
23165  }
23166  else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23167  {
23168  return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
23169  }
23170  else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23171  {
23172  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
23173  }
23174  else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23175  {
23176  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
23177  }
23178  else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23179  {
23180  return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23181  }
23182 
23183  return false;
23184  }
23185 
23190  template<typename ScalarType, typename std::enable_if<
23192  friend bool operator==(const_reference lhs, ScalarType rhs) noexcept
23193  {
23194  return lhs == basic_json(rhs);
23195  }
23196 
23201  template<typename ScalarType, typename std::enable_if<
23203  friend bool operator==(ScalarType lhs, const_reference rhs) noexcept
23204  {
23205  return basic_json(lhs) == rhs;
23206  }
23207 
23226  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
23227  {
23228  return !(lhs == rhs);
23229  }
23230 
23235  template<typename ScalarType, typename std::enable_if<
23237  friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept
23238  {
23239  return lhs != basic_json(rhs);
23240  }
23241 
23246  template<typename ScalarType, typename std::enable_if<
23248  friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept
23249  {
23250  return basic_json(lhs) != rhs;
23251  }
23252 
23279  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
23280  {
23281  const auto lhs_type = lhs.type();
23282  const auto rhs_type = rhs.type();
23283 
23284  if (lhs_type == rhs_type)
23285  {
23286  switch (lhs_type)
23287  {
23288  case value_t::array:
23289  // note parentheses are necessary, see
23290  // https://github.com/nlohmann/json/issues/1530
23291  return (*lhs.m_value.array) < (*rhs.m_value.array);
23292 
23293  case value_t::object:
23294  return (*lhs.m_value.object) < (*rhs.m_value.object);
23295 
23296  case value_t::null:
23297  return false;
23298 
23299  case value_t::string:
23300  return (*lhs.m_value.string) < (*rhs.m_value.string);
23301 
23302  case value_t::boolean:
23303  return (lhs.m_value.boolean) < (rhs.m_value.boolean);
23304 
23306  return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
23307 
23309  return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
23310 
23311  case value_t::number_float:
23312  return (lhs.m_value.number_float) < (rhs.m_value.number_float);
23313 
23314  case value_t::binary:
23315  return (*lhs.m_value.binary) < (*rhs.m_value.binary);
23316 
23317  default:
23318  return false;
23319  }
23320  }
23321  else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23322  {
23323  return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
23324  }
23325  else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23326  {
23327  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
23328  }
23329  else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23330  {
23331  return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
23332  }
23333  else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23334  {
23335  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
23336  }
23337  else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23338  {
23339  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23340  }
23341  else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23342  {
23343  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
23344  }
23345 
23346  // We only reach this line if we cannot compare values. In that case,
23347  // we compare types. Note we have to call the operator explicitly,
23348  // because MSVC has problems otherwise.
23349  return operator<(lhs_type, rhs_type);
23350  }
23351 
23356  template<typename ScalarType, typename std::enable_if<
23358  friend bool operator<(const_reference lhs, ScalarType rhs) noexcept
23359  {
23360  return lhs < basic_json(rhs);
23361  }
23362 
23367  template<typename ScalarType, typename std::enable_if<
23369  friend bool operator<(ScalarType lhs, const_reference rhs) noexcept
23370  {
23371  return basic_json(lhs) < rhs;
23372  }
23373 
23393  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
23394  {
23395  return !(rhs < lhs);
23396  }
23397 
23402  template<typename ScalarType, typename std::enable_if<
23404  friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept
23405  {
23406  return lhs <= basic_json(rhs);
23407  }
23408 
23413  template<typename ScalarType, typename std::enable_if<
23415  friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept
23416  {
23417  return basic_json(lhs) <= rhs;
23418  }
23419 
23439  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
23440  {
23441  return !(lhs <= rhs);
23442  }
23443 
23448  template<typename ScalarType, typename std::enable_if<
23450  friend bool operator>(const_reference lhs, ScalarType rhs) noexcept
23451  {
23452  return lhs > basic_json(rhs);
23453  }
23454 
23459  template<typename ScalarType, typename std::enable_if<
23461  friend bool operator>(ScalarType lhs, const_reference rhs) noexcept
23462  {
23463  return basic_json(lhs) > rhs;
23464  }
23465 
23485  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
23486  {
23487  return !(lhs < rhs);
23488  }
23489 
23494  template<typename ScalarType, typename std::enable_if<
23496  friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept
23497  {
23498  return lhs >= basic_json(rhs);
23499  }
23500 
23505  template<typename ScalarType, typename std::enable_if<
23507  friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept
23508  {
23509  return basic_json(lhs) >= rhs;
23510  }
23511 
23513 
23515  // serialization //
23517 
23520 
23552  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
23553  {
23554  // read width member and use it as indentation parameter if nonzero
23555  const bool pretty_print = o.width() > 0;
23556  const auto indentation = pretty_print ? o.width() : 0;
23557 
23558  // reset width to 0 for subsequent calls to this stream
23559  o.width(0);
23560 
23561  // do the actual serialization
23562  serializer s(detail::output_adapter<char>(o), o.fill());
23563  s.dump(j, pretty_print, false, static_cast<unsigned int>(indentation));
23564  return o;
23565  }
23566 
23575  JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&))
23576  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
23577  {
23578  return o << j;
23579  }
23580 
23582 
23583 
23585  // deserialization //
23587 
23590 
23642  template<typename InputType>
23644  static basic_json parse(InputType&& i,
23645  const parser_callback_t cb = nullptr,
23646  const bool allow_exceptions = true,
23647  const bool ignore_comments = false)
23648  {
23649  basic_json result;
23650  parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result);
23651  return result;
23652  }
23653 
23680  template<typename IteratorType>
23682  static basic_json parse(IteratorType first,
23683  IteratorType last,
23684  const parser_callback_t cb = nullptr,
23685  const bool allow_exceptions = true,
23686  const bool ignore_comments = false)
23687  {
23688  basic_json result;
23689  parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result);
23690  return result;
23691  }
23692 
23694  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
23695  static basic_json parse(detail::span_input_adapter&& i,
23696  const parser_callback_t cb = nullptr,
23697  const bool allow_exceptions = true,
23698  const bool ignore_comments = false)
23699  {
23700  basic_json result;
23701  parser(i.get(), cb, allow_exceptions, ignore_comments).parse(true, result);
23702  return result;
23703  }
23704 
23735  template<typename InputType>
23736  static bool accept(InputType&& i,
23737  const bool ignore_comments = false)
23738  {
23739  return parser(detail::input_adapter(std::forward<InputType>(i)), nullptr, false, ignore_comments).accept(true);
23740  }
23741 
23742  template<typename IteratorType>
23743  static bool accept(IteratorType first, IteratorType last,
23744  const bool ignore_comments = false)
23745  {
23746  return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true);
23747  }
23748 
23750  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
23751  static bool accept(detail::span_input_adapter&& i,
23752  const bool ignore_comments = false)
23753  {
23754  return parser(i.get(), nullptr, false, ignore_comments).accept(true);
23755  }
23756 
23797  template <typename InputType, typename SAX>
23799  static bool sax_parse(InputType&& i, SAX* sax,
23801  const bool strict = true,
23802  const bool ignore_comments = false)
23803  {
23804  auto ia = detail::input_adapter(std::forward<InputType>(i));
23805  return format == input_format_t::json
23806  ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
23807  : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23808  }
23809 
23810  template<class IteratorType, class SAX>
23812  static bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
23814  const bool strict = true,
23815  const bool ignore_comments = false)
23816  {
23817  auto ia = detail::input_adapter(std::move(first), std::move(last));
23818  return format == input_format_t::json
23819  ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
23820  : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23821  }
23822 
23823  template <typename SAX>
23824  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
23826  static bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
23828  const bool strict = true,
23829  const bool ignore_comments = false)
23830  {
23831  auto ia = i.get();
23832  return format == input_format_t::json
23833  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
23834  ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
23835  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
23836  : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23837  }
23838 
23847  JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&))
23848  friend std::istream& operator<<(basic_json& j, std::istream& i)
23849  {
23850  return operator>>(i, j);
23851  }
23852 
23878  friend std::istream& operator>>(std::istream& i, basic_json& j)
23879  {
23880  parser(detail::input_adapter(i)).parse(false, j);
23881  return i;
23882  }
23883 
23885 
23887  // convenience functions //
23889 
23922  const char* type_name() const noexcept
23923  {
23924  {
23925  switch (m_type)
23926  {
23927  case value_t::null:
23928  return "null";
23929  case value_t::object:
23930  return "object";
23931  case value_t::array:
23932  return "array";
23933  case value_t::string:
23934  return "string";
23935  case value_t::boolean:
23936  return "boolean";
23937  case value_t::binary:
23938  return "binary";
23939  case value_t::discarded:
23940  return "discarded";
23941  default:
23942  return "number";
23943  }
23944  }
23945  }
23946 
23947 
23950  // member variables //
23952 
23954  value_t m_type = value_t::null;
23955 
23958 
23959 #if JSON_DIAGNOSTICS
23961  basic_json* m_parent = nullptr;
23962 #endif
23963 
23965  // binary serialization/deserialization //
23967 
23970 
23971  public:
24066  static std::vector<uint8_t> to_cbor(const basic_json& j)
24067  {
24068  std::vector<uint8_t> result;
24069  to_cbor(j, result);
24070  return result;
24071  }
24072 
24074  {
24076  }
24077 
24079  {
24081  }
24082 
24161  static std::vector<uint8_t> to_msgpack(const basic_json& j)
24162  {
24163  std::vector<uint8_t> result;
24164  to_msgpack(j, result);
24165  return result;
24166  }
24167 
24169  {
24171  }
24172 
24174  {
24176  }
24177 
24264  static std::vector<uint8_t> to_ubjson(const basic_json& j,
24265  const bool use_size = false,
24266  const bool use_type = false)
24267  {
24268  std::vector<uint8_t> result;
24269  to_ubjson(j, result, use_size, use_type);
24270  return result;
24271  }
24272 
24274  const bool use_size = false, const bool use_type = false)
24275  {
24276  binary_writer<uint8_t>(o).write_ubjson(j, use_size, use_type);
24277  }
24278 
24280  const bool use_size = false, const bool use_type = false)
24281  {
24282  binary_writer<char>(o).write_ubjson(j, use_size, use_type);
24283  }
24284 
24285 
24342  static std::vector<uint8_t> to_bson(const basic_json& j)
24343  {
24344  std::vector<uint8_t> result;
24345  to_bson(j, result);
24346  return result;
24347  }
24348 
24358  {
24360  }
24361 
24366  {
24368  }
24369 
24370 
24473  template<typename InputType>
24475  static basic_json from_cbor(InputType&& i,
24476  const bool strict = true,
24477  const bool allow_exceptions = true,
24478  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24479  {
24480  basic_json result;
24481  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24482  auto ia = detail::input_adapter(std::forward<InputType>(i));
24483  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24484  return res ? result : basic_json(value_t::discarded);
24485  }
24486 
24490  template<typename IteratorType>
24492  static basic_json from_cbor(IteratorType first, IteratorType last,
24493  const bool strict = true,
24494  const bool allow_exceptions = true,
24495  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24496  {
24497  basic_json result;
24498  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24499  auto ia = detail::input_adapter(std::move(first), std::move(last));
24500  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24501  return res ? result : basic_json(value_t::discarded);
24502  }
24503 
24504  template<typename T>
24506  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24507  static basic_json from_cbor(const T* ptr, std::size_t len,
24508  const bool strict = true,
24509  const bool allow_exceptions = true,
24510  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24511  {
24512  return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
24513  }
24514 
24515 
24517  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24518  static basic_json from_cbor(detail::span_input_adapter&& i,
24519  const bool strict = true,
24520  const bool allow_exceptions = true,
24521  const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24522  {
24523  basic_json result;
24524  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24525  auto ia = i.get();
24526  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
24527  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24528  return res ? result : basic_json(value_t::discarded);
24529  }
24530 
24617  template<typename InputType>
24619  static basic_json from_msgpack(InputType&& i,
24620  const bool strict = true,
24621  const bool allow_exceptions = true)
24622  {
24623  basic_json result;
24624  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24625  auto ia = detail::input_adapter(std::forward<InputType>(i));
24626  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24627  return res ? result : basic_json(value_t::discarded);
24628  }
24629 
24633  template<typename IteratorType>
24635  static basic_json from_msgpack(IteratorType first, IteratorType last,
24636  const bool strict = true,
24637  const bool allow_exceptions = true)
24638  {
24639  basic_json result;
24640  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24641  auto ia = detail::input_adapter(std::move(first), std::move(last));
24642  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24643  return res ? result : basic_json(value_t::discarded);
24644  }
24645 
24646 
24647  template<typename T>
24649  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24650  static basic_json from_msgpack(const T* ptr, std::size_t len,
24651  const bool strict = true,
24652  const bool allow_exceptions = true)
24653  {
24654  return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
24655  }
24656 
24658  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24659  static basic_json from_msgpack(detail::span_input_adapter&& i,
24660  const bool strict = true,
24661  const bool allow_exceptions = true)
24662  {
24663  basic_json result;
24664  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24665  auto ia = i.get();
24666  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
24667  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24668  return res ? result : basic_json(value_t::discarded);
24669  }
24670 
24671 
24734  template<typename InputType>
24736  static basic_json from_ubjson(InputType&& i,
24737  const bool strict = true,
24738  const bool allow_exceptions = true)
24739  {
24740  basic_json result;
24741  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24742  auto ia = detail::input_adapter(std::forward<InputType>(i));
24743  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24744  return res ? result : basic_json(value_t::discarded);
24745  }
24746 
24750  template<typename IteratorType>
24752  static basic_json from_ubjson(IteratorType first, IteratorType last,
24753  const bool strict = true,
24754  const bool allow_exceptions = true)
24755  {
24756  basic_json result;
24757  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24758  auto ia = detail::input_adapter(std::move(first), std::move(last));
24759  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24760  return res ? result : basic_json(value_t::discarded);
24761  }
24762 
24763  template<typename T>
24765  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24766  static basic_json from_ubjson(const T* ptr, std::size_t len,
24767  const bool strict = true,
24768  const bool allow_exceptions = true)
24769  {
24770  return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
24771  }
24772 
24774  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24775  static basic_json from_ubjson(detail::span_input_adapter&& i,
24776  const bool strict = true,
24777  const bool allow_exceptions = true)
24778  {
24779  basic_json result;
24780  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24781  auto ia = i.get();
24782  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
24783  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24784  return res ? result : basic_json(value_t::discarded);
24785  }
24786 
24787 
24848  template<typename InputType>
24850  static basic_json from_bson(InputType&& i,
24851  const bool strict = true,
24852  const bool allow_exceptions = true)
24853  {
24854  basic_json result;
24855  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24856  auto ia = detail::input_adapter(std::forward<InputType>(i));
24857  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24858  return res ? result : basic_json(value_t::discarded);
24859  }
24860 
24864  template<typename IteratorType>
24866  static basic_json from_bson(IteratorType first, IteratorType last,
24867  const bool strict = true,
24868  const bool allow_exceptions = true)
24869  {
24870  basic_json result;
24871  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24872  auto ia = detail::input_adapter(std::move(first), std::move(last));
24873  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24874  return res ? result : basic_json(value_t::discarded);
24875  }
24876 
24877  template<typename T>
24879  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
24880  static basic_json from_bson(const T* ptr, std::size_t len,
24881  const bool strict = true,
24882  const bool allow_exceptions = true)
24883  {
24884  return from_bson(ptr, ptr + len, strict, allow_exceptions);
24885  }
24886 
24888  JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
24889  static basic_json from_bson(detail::span_input_adapter&& i,
24890  const bool strict = true,
24891  const bool allow_exceptions = true)
24892  {
24893  basic_json result;
24894  detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24895  auto ia = i.get();
24896  // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
24897  const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24898  return res ? result : basic_json(value_t::discarded);
24899  }
24901 
24903  // JSON Pointer support //
24905 
24908 
24943  {
24944  return ptr.get_unchecked(this);
24945  }
24946 
24971  {
24972  return ptr.get_unchecked(this);
24973  }
24974 
25014  {
25015  return ptr.get_checked(this);
25016  }
25017 
25056  const_reference at(const json_pointer& ptr) const
25057  {
25058  return ptr.get_checked(this);
25059  }
25060 
25084  {
25085  basic_json result(value_t::object);
25086  json_pointer::flatten("", *this, result);
25087  return result;
25088  }
25089 
25121  {
25122  return json_pointer::unflatten(*this);
25123  }
25124 
25126 
25128  // JSON Patch functions //
25130 
25133 
25181  basic_json patch(const basic_json& json_patch) const
25182  {
25183  // make a working copy to apply the patch to
25184  basic_json result = *this;
25185 
25186  // the valid JSON Patch operations
25187  enum class patch_operations {add, remove, replace, move, copy, test, invalid};
25188 
25189  const auto get_op = [](const std::string & op)
25190  {
25191  if (op == "add")
25192  {
25193  return patch_operations::add;
25194  }
25195  if (op == "remove")
25196  {
25197  return patch_operations::remove;
25198  }
25199  if (op == "replace")
25200  {
25201  return patch_operations::replace;
25202  }
25203  if (op == "move")
25204  {
25205  return patch_operations::move;
25206  }
25207  if (op == "copy")
25208  {
25209  return patch_operations::copy;
25210  }
25211  if (op == "test")
25212  {
25213  return patch_operations::test;
25214  }
25215 
25216  return patch_operations::invalid;
25217  };
25218 
25219  // wrapper for "add" operation; add value at ptr
25220  const auto operation_add = [&result](json_pointer & ptr, basic_json val)
25221  {
25222  // adding to the root of the target document means replacing it
25223  if (ptr.empty())
25224  {
25225  result = val;
25226  return;
25227  }
25228 
25229  // make sure the top element of the pointer exists
25230  json_pointer top_pointer = ptr.top();
25231  if (top_pointer != ptr)
25232  {
25233  result.at(top_pointer);
25234  }
25235 
25236  // get reference to parent of JSON pointer ptr
25237  const auto last_path = ptr.back();
25238  ptr.pop_back();
25239  basic_json& parent = result[ptr];
25240 
25241  switch (parent.m_type)
25242  {
25243  case value_t::null:
25244  case value_t::object:
25245  {
25246  // use operator[] to add value
25247  parent[last_path] = val;
25248  break;
25249  }
25250 
25251  case value_t::array:
25252  {
25253  if (last_path == "-")
25254  {
25255  // special case: append to back
25256  parent.push_back(val);
25257  }
25258  else
25259  {
25260  const auto idx = json_pointer::array_index(last_path);
25261  if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
25262  {
25263  // avoid undefined behavior
25264  JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", parent));
25265  }
25266 
25267  // default case: insert add offset
25268  parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
25269  }
25270  break;
25271  }
25272 
25273  // if there exists a parent it cannot be primitive
25274  default: // LCOV_EXCL_LINE
25275  JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
25276  }
25277  };
25278 
25279  // wrapper for "remove" operation; remove value at ptr
25280  const auto operation_remove = [this, &result](json_pointer & ptr)
25281  {
25282  // get reference to parent of JSON pointer ptr
25283  const auto last_path = ptr.back();
25284  ptr.pop_back();
25285  basic_json& parent = result.at(ptr);
25286 
25287  // remove child
25288  if (parent.is_object())
25289  {
25290  // perform range check
25291  auto it = parent.find(last_path);
25292  if (JSON_HEDLEY_LIKELY(it != parent.end()))
25293  {
25294  parent.erase(it);
25295  }
25296  else
25297  {
25298  JSON_THROW(out_of_range::create(403, "key '" + last_path + "' not found", *this));
25299  }
25300  }
25301  else if (parent.is_array())
25302  {
25303  // note erase performs range check
25304  parent.erase(json_pointer::array_index(last_path));
25305  }
25306  };
25307 
25308  // type check: top level value must be an array
25309  if (JSON_HEDLEY_UNLIKELY(!json_patch.is_array()))
25310  {
25311  JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", json_patch));
25312  }
25313 
25314  // iterate and apply the operations
25315  for (const auto& val : json_patch)
25316  {
25317  // wrapper to get a value for an operation
25318  const auto get_value = [&val](const std::string & op,
25319  const std::string & member,
25320  bool string_type) -> basic_json &
25321  {
25322  // find value
25323  auto it = val.m_value.object->find(member);
25324 
25325  // context-sensitive error message
25326  const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
25327 
25328  // check if desired value is present
25329  if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
25330  {
25331  // NOLINTNEXTLINE(performance-inefficient-string-concatenation)
25332  JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'", val));
25333  }
25334 
25335  // check if result is of type string
25336  if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
25337  {
25338  // NOLINTNEXTLINE(performance-inefficient-string-concatenation)
25339  JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'", val));
25340  }
25341 
25342  // no error: return value
25343  return it->second;
25344  };
25345 
25346  // type check: every element of the array must be an object
25347  if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
25348  {
25349  JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", val));
25350  }
25351 
25352  // collect mandatory members
25353  const auto op = get_value("op", "op", true).template get<std::string>();
25354  const auto path = get_value(op, "path", true).template get<std::string>();
25355  json_pointer ptr(path);
25356 
25357  switch (get_op(op))
25358  {
25359  case patch_operations::add:
25360  {
25361  operation_add(ptr, get_value("add", "value", false));
25362  break;
25363  }
25364 
25365  case patch_operations::remove:
25366  {
25367  operation_remove(ptr);
25368  break;
25369  }
25370 
25371  case patch_operations::replace:
25372  {
25373  // the "path" location must exist - use at()
25374  result.at(ptr) = get_value("replace", "value", false);
25375  break;
25376  }
25377 
25378  case patch_operations::move:
25379  {
25380  const auto from_path = get_value("move", "from", true).template get<std::string>();
25381  json_pointer from_ptr(from_path);
25382 
25383  // the "from" location must exist - use at()
25384  basic_json v = result.at(from_ptr);
25385 
25386  // The move operation is functionally identical to a
25387  // "remove" operation on the "from" location, followed
25388  // immediately by an "add" operation at the target
25389  // location with the value that was just removed.
25390  operation_remove(from_ptr);
25391  operation_add(ptr, v);
25392  break;
25393  }
25394 
25395  case patch_operations::copy:
25396  {
25397  const auto from_path = get_value("copy", "from", true).template get<std::string>();
25398  const json_pointer from_ptr(from_path);
25399 
25400  // the "from" location must exist - use at()
25401  basic_json v = result.at(from_ptr);
25402 
25403  // The copy is functionally identical to an "add"
25404  // operation at the target location using the value
25405  // specified in the "from" member.
25406  operation_add(ptr, v);
25407  break;
25408  }
25409 
25410  case patch_operations::test:
25411  {
25412  bool success = false;
25413  JSON_TRY
25414  {
25415  // check if "value" matches the one at "path"
25416  // the "path" location must exist - use at()
25417  success = (result.at(ptr) == get_value("test", "value", false));
25418  }
25420  {
25421  // ignore out of range errors: success remains false
25422  }
25423 
25424  // throw an exception if test fails
25425  if (JSON_HEDLEY_UNLIKELY(!success))
25426  {
25427  JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump(), val));
25428  }
25429 
25430  break;
25431  }
25432 
25433  default:
25434  {
25435  // op must be "add", "remove", "replace", "move", "copy", or
25436  // "test"
25437  JSON_THROW(parse_error::create(105, 0, "operation value '" + op + "' is invalid", val));
25438  }
25439  }
25440  }
25441 
25442  return result;
25443  }
25444 
25479  static basic_json diff(const basic_json& source, const basic_json& target,
25480  const std::string& path = "")
25481  {
25482  // the patch
25483  basic_json result(value_t::array);
25484 
25485  // if the values are the same, return empty patch
25486  if (source == target)
25487  {
25488  return result;
25489  }
25490 
25491  if (source.type() != target.type())
25492  {
25493  // different types: replace value
25494  result.push_back(
25495  {
25496  {"op", "replace"}, {"path", path}, {"value", target}
25497  });
25498  return result;
25499  }
25500 
25501  switch (source.type())
25502  {
25503  case value_t::array:
25504  {
25505  // first pass: traverse common elements
25506  std::size_t i = 0;
25507  while (i < source.size() && i < target.size())
25508  {
25509  // recursive call to compare array values at index i
25510  auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i));
25511  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
25512  ++i;
25513  }
25514 
25515  // i now reached the end of at least one array
25516  // in a second pass, traverse the remaining elements
25517 
25518  // remove my remaining elements
25519  const auto end_index = static_cast<difference_type>(result.size());
25520  while (i < source.size())
25521  {
25522  // add operations in reverse order to avoid invalid
25523  // indices
25524  result.insert(result.begin() + end_index, object(
25525  {
25526  {"op", "remove"},
25527  {"path", path + "/" + std::to_string(i)}
25528  }));
25529  ++i;
25530  }
25531 
25532  // add other remaining elements
25533  while (i < target.size())
25534  {
25535  result.push_back(
25536  {
25537  {"op", "add"},
25538  {"path", path + "/-"},
25539  {"value", target[i]}
25540  });
25541  ++i;
25542  }
25543 
25544  break;
25545  }
25546 
25547  case value_t::object:
25548  {
25549  // first pass: traverse this object's elements
25550  for (auto it = source.cbegin(); it != source.cend(); ++it)
25551  {
25552  // escape the key name to be used in a JSON patch
25553  const auto path_key = path + "/" + detail::escape(it.key());
25554 
25555  if (target.find(it.key()) != target.end())
25556  {
25557  // recursive call to compare object values at key it
25558  auto temp_diff = diff(it.value(), target[it.key()], path_key);
25559  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
25560  }
25561  else
25562  {
25563  // found a key that is not in o -> remove it
25564  result.push_back(object(
25565  {
25566  {"op", "remove"}, {"path", path_key}
25567  }));
25568  }
25569  }
25570 
25571  // second pass: traverse other object's elements
25572  for (auto it = target.cbegin(); it != target.cend(); ++it)
25573  {
25574  if (source.find(it.key()) == source.end())
25575  {
25576  // found a key that is not in this -> add it
25577  const auto path_key = path + "/" + detail::escape(it.key());
25578  result.push_back(
25579  {
25580  {"op", "add"}, {"path", path_key},
25581  {"value", it.value()}
25582  });
25583  }
25584  }
25585 
25586  break;
25587  }
25588 
25589  default:
25590  {
25591  // both primitive type: replace value
25592  result.push_back(
25593  {
25594  {"op", "replace"}, {"path", path}, {"value", target}
25595  });
25596  break;
25597  }
25598  }
25599 
25600  return result;
25601  }
25602 
25604 
25606  // JSON Merge Patch functions //
25608 
25611 
25654  void merge_patch(const basic_json& apply_patch)
25655  {
25656  if (apply_patch.is_object())
25657  {
25658  if (!is_object())
25659  {
25660  *this = object();
25661  }
25662  for (auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
25663  {
25664  if (it.value().is_null())
25665  {
25666  erase(it.key());
25667  }
25668  else
25669  {
25670  operator[](it.key()).merge_patch(it.value());
25671  }
25672  }
25673  }
25674  else
25675  {
25676  *this = apply_patch;
25677  }
25678  }
25679 
25681 };
25682 
25693 std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j)
25694 {
25695  return j.dump();
25696 }
25697 } // namespace nlohmann
25698 
25700 // nonmember support //
25702 
25703 // specialization of std::swap, and std::hash
25704 namespace std
25705 {
25706 
25708 template<>
25710 {
25716  std::size_t operator()(const nlohmann::json& j) const
25717  {
25718  return nlohmann::detail::hash(j);
25719  }
25720 };
25721 
25725 template<>
25727 {
25733  nlohmann::detail::value_t rhs) const noexcept
25734  {
25735  return nlohmann::detail::operator<(lhs, rhs);
25736  }
25737 };
25738 
25739 // C++20 prohibit function specialization in the std namespace.
25740 #ifndef JSON_HAS_CPP_20
25741 
25747 template<>
25748 inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name)
25749  is_nothrow_move_constructible<nlohmann::json>::value&& // NOLINT(misc-redundant-expression)
25751  )
25752 {
25753  j1.swap(j2);
25754 }
25755 
25756 #endif
25757 
25758 } // namespace std
25759 
25774 inline nlohmann::json operator""_json(const char* s, std::size_t n)
25775 {
25776  return nlohmann::json::parse(s, s + n);
25777 }
25778 
25793 inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n)
25794 {
25795  return nlohmann::json::json_pointer(std::string(s, n));
25796 }
25797 
25798 // #include <nlohmann/detail/macro_unscope.hpp>
25799 
25800 
25801 // restore GCC/clang diagnostic settings
25802 #if defined(__clang__)
25803  #pragma GCC diagnostic pop
25804 #endif
25805 
25806 // clean up
25807 #undef JSON_ASSERT
25808 #undef JSON_INTERNAL_CATCH
25809 #undef JSON_CATCH
25810 #undef JSON_THROW
25811 #undef JSON_TRY
25812 #undef JSON_PRIVATE_UNLESS_TESTED
25813 #undef JSON_HAS_CPP_14
25814 #undef JSON_HAS_CPP_17
25815 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
25816 #undef NLOHMANN_BASIC_JSON_TPL
25817 #undef JSON_EXPLICIT
25818 
25819 // #include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
25820 
25821 
25822 #undef JSON_HEDLEY_ALWAYS_INLINE
25823 #undef JSON_HEDLEY_ARM_VERSION
25824 #undef JSON_HEDLEY_ARM_VERSION_CHECK
25825 #undef JSON_HEDLEY_ARRAY_PARAM
25826 #undef JSON_HEDLEY_ASSUME
25827 #undef JSON_HEDLEY_BEGIN_C_DECLS
25828 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
25829 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
25830 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
25831 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
25832 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
25833 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
25834 #undef JSON_HEDLEY_CLANG_HAS_WARNING
25835 #undef JSON_HEDLEY_COMPCERT_VERSION
25836 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
25837 #undef JSON_HEDLEY_CONCAT
25838 #undef JSON_HEDLEY_CONCAT3
25839 #undef JSON_HEDLEY_CONCAT3_EX
25840 #undef JSON_HEDLEY_CONCAT_EX
25841 #undef JSON_HEDLEY_CONST
25842 #undef JSON_HEDLEY_CONSTEXPR
25843 #undef JSON_HEDLEY_CONST_CAST
25844 #undef JSON_HEDLEY_CPP_CAST
25845 #undef JSON_HEDLEY_CRAY_VERSION
25846 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
25847 #undef JSON_HEDLEY_C_DECL
25848 #undef JSON_HEDLEY_DEPRECATED
25849 #undef JSON_HEDLEY_DEPRECATED_FOR
25850 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
25851 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
25852 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
25853 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
25854 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
25855 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
25856 #undef JSON_HEDLEY_DIAGNOSTIC_POP
25857 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
25858 #undef JSON_HEDLEY_DMC_VERSION
25859 #undef JSON_HEDLEY_DMC_VERSION_CHECK
25860 #undef JSON_HEDLEY_EMPTY_BASES
25861 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
25862 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
25863 #undef JSON_HEDLEY_END_C_DECLS
25864 #undef JSON_HEDLEY_FLAGS
25865 #undef JSON_HEDLEY_FLAGS_CAST
25866 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
25867 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
25868 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
25869 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
25870 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
25871 #undef JSON_HEDLEY_GCC_HAS_FEATURE
25872 #undef JSON_HEDLEY_GCC_HAS_WARNING
25873 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
25874 #undef JSON_HEDLEY_GCC_VERSION
25875 #undef JSON_HEDLEY_GCC_VERSION_CHECK
25876 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
25877 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
25878 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
25879 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
25880 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
25881 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
25882 #undef JSON_HEDLEY_GNUC_HAS_WARNING
25883 #undef JSON_HEDLEY_GNUC_VERSION
25884 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
25885 #undef JSON_HEDLEY_HAS_ATTRIBUTE
25886 #undef JSON_HEDLEY_HAS_BUILTIN
25887 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
25888 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
25889 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
25890 #undef JSON_HEDLEY_HAS_EXTENSION
25891 #undef JSON_HEDLEY_HAS_FEATURE
25892 #undef JSON_HEDLEY_HAS_WARNING
25893 #undef JSON_HEDLEY_IAR_VERSION
25894 #undef JSON_HEDLEY_IAR_VERSION_CHECK
25895 #undef JSON_HEDLEY_IBM_VERSION
25896 #undef JSON_HEDLEY_IBM_VERSION_CHECK
25897 #undef JSON_HEDLEY_IMPORT
25898 #undef JSON_HEDLEY_INLINE
25899 #undef JSON_HEDLEY_INTEL_CL_VERSION
25900 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
25901 #undef JSON_HEDLEY_INTEL_VERSION
25902 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
25903 #undef JSON_HEDLEY_IS_CONSTANT
25904 #undef JSON_HEDLEY_IS_CONSTEXPR_
25905 #undef JSON_HEDLEY_LIKELY
25906 #undef JSON_HEDLEY_MALLOC
25907 #undef JSON_HEDLEY_MCST_LCC_VERSION
25908 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
25909 #undef JSON_HEDLEY_MESSAGE
25910 #undef JSON_HEDLEY_MSVC_VERSION
25911 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
25912 #undef JSON_HEDLEY_NEVER_INLINE
25913 #undef JSON_HEDLEY_NON_NULL
25914 #undef JSON_HEDLEY_NO_ESCAPE
25915 #undef JSON_HEDLEY_NO_RETURN
25916 #undef JSON_HEDLEY_NO_THROW
25917 #undef JSON_HEDLEY_NULL
25918 #undef JSON_HEDLEY_PELLES_VERSION
25919 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
25920 #undef JSON_HEDLEY_PGI_VERSION
25921 #undef JSON_HEDLEY_PGI_VERSION_CHECK
25922 #undef JSON_HEDLEY_PREDICT
25923 #undef JSON_HEDLEY_PRINTF_FORMAT
25924 #undef JSON_HEDLEY_PRIVATE
25925 #undef JSON_HEDLEY_PUBLIC
25926 #undef JSON_HEDLEY_PURE
25927 #undef JSON_HEDLEY_REINTERPRET_CAST
25928 #undef JSON_HEDLEY_REQUIRE
25929 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
25930 #undef JSON_HEDLEY_REQUIRE_MSG
25931 #undef JSON_HEDLEY_RESTRICT
25932 #undef JSON_HEDLEY_RETURNS_NON_NULL
25933 #undef JSON_HEDLEY_SENTINEL
25934 #undef JSON_HEDLEY_STATIC_ASSERT
25935 #undef JSON_HEDLEY_STATIC_CAST
25936 #undef JSON_HEDLEY_STRINGIFY
25937 #undef JSON_HEDLEY_STRINGIFY_EX
25938 #undef JSON_HEDLEY_SUNPRO_VERSION
25939 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
25940 #undef JSON_HEDLEY_TINYC_VERSION
25941 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
25942 #undef JSON_HEDLEY_TI_ARMCL_VERSION
25943 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
25944 #undef JSON_HEDLEY_TI_CL2000_VERSION
25945 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
25946 #undef JSON_HEDLEY_TI_CL430_VERSION
25947 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
25948 #undef JSON_HEDLEY_TI_CL6X_VERSION
25949 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
25950 #undef JSON_HEDLEY_TI_CL7X_VERSION
25951 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
25952 #undef JSON_HEDLEY_TI_CLPRU_VERSION
25953 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
25954 #undef JSON_HEDLEY_TI_VERSION
25955 #undef JSON_HEDLEY_TI_VERSION_CHECK
25956 #undef JSON_HEDLEY_UNAVAILABLE
25957 #undef JSON_HEDLEY_UNLIKELY
25958 #undef JSON_HEDLEY_UNPREDICTABLE
25959 #undef JSON_HEDLEY_UNREACHABLE
25960 #undef JSON_HEDLEY_UNREACHABLE_RETURN
25961 #undef JSON_HEDLEY_VERSION
25962 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
25963 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
25964 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
25965 #undef JSON_HEDLEY_VERSION_ENCODE
25966 #undef JSON_HEDLEY_WARNING
25967 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
25968 #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
25969 #undef JSON_HEDLEY_FALL_THROUGH
25970 
25971 
25972 
25973 #endif // INCLUDE_NLOHMANN_JSON_HPP_
#define NLOHMANN_BASIC_JSON_TPL_DECLARATION
Definition: json.hpp:2330
#define JSON_HEDLEY_CONST
Definition: json.hpp:1667
#define JSON_HEDLEY_DIAGNOSTIC_PUSH
Definition: json.hpp:951
#define JSON_HEDLEY_WARN_UNUSED_RESULT
Definition: json.hpp:1297
#define JSON_PRIVATE_UNLESS_TESTED
Definition: json.hpp:2293
#define NLOHMANN_JSON_VERSION_PATCH
Definition: json.hpp:35
#define JSON_HEDLEY_LIKELY(expr)
Definition: json.hpp:1562
#define JSON_HEDLEY_NON_NULL(...)
Definition: json.hpp:1455
#define JSON_INTERNAL_CATCH(exception)
Definition: json.hpp:2260
#define JSON_HEDLEY_RETURNS_NON_NULL
Definition: json.hpp:1896
#define JSON_CATCH(exception)
Definition: json.hpp:2259
#define JSON_ASSERT(x)
Definition: json.hpp:2286
#define JSON_THROW(exception)
Definition: json.hpp:2257
#define NLOHMANN_JSON_VERSION_MAJOR
Definition: json.hpp:33
#define NLOHMANN_BASIC_JSON_TPL
Definition: json.hpp:2339
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: json.hpp:1563
#define JSON_TRY
Definition: json.hpp:2258
#define NLOHMANN_JSON_VERSION_MINOR
Definition: json.hpp:34
#define JSON_HEDLEY_DIAGNOSTIC_POP
Definition: json.hpp:952
#define JSON_EXPLICIT
Definition: json.hpp:2503
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
Definition: json.hpp:1245
#define JSON_HEDLEY_PURE
Definition: json.hpp:1636
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:25318
basic_json<> json
default specialization
Definition: json.hpp:3554
ArrayType
Definition: Xml.h:25
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:585
namespace for Niels Lohmann
Definition: json.hpp:20203
JSON_PRIVATE_UNLESS_TESTED const_reference rhs
Definition: json.hpp:23791
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:22357
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: json.hpp:13528
void set_end() noexcept
set iterator to a defined past the end
Definition: json.hpp:13522
constexpr difference_type get_value() const noexcept
Definition: json.hpp:13510
void set_begin() noexcept
set iterator to a defined beginning
Definition: json.hpp:13516
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
Definition: json.hpp:14616
a class to store JSON values
Definition: json.hpp:17064
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init, std::uint8_t subtype)
explicitly create a binary array (with subtype)
Definition: json.hpp:18713
constexpr auto get() const noexcept -> decltype(std::declval< const basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition: json.hpp:20120
void insert(const_iterator first, const_iterator last)
inserts elements
Definition: json.hpp:22720
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
Definition: json.hpp:18276
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
Definition: json.hpp:21396
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.hpp:21681
number_unsigned_t number_unsigned
number (unsigned integer)
Definition: json.hpp:17876
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.hpp:24970
basic_json get() const
get special-case overload
Definition: json.hpp:19829
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.hpp:24942
friend bool operator==(const_reference lhs, ScalarType rhs) noexcept
comparison: equal
Definition: json.hpp:23192
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:20779
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition: json.hpp:19522
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:17598
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.hpp:23118
NLOHMANN_BASIC_JSON_TPL basic_json_t
workaround type for MSVC
Definition: json.hpp:17085
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:23799
constexpr const number_integer_t * get_impl_ptr(const number_integer_t *) const noexcept
get a pointer to the value (integer number)
Definition: json.hpp:19741
ReferenceType get_ref()
get a reference value (implicit)
Definition: json.hpp:20154
static JSON_HEDLEY_WARN_UNUSED_RESULT 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:23644
reference emplace_back(Args &&... args)
add an object to an array
Definition: json.hpp:22404
const_iterator find(KeyT &&key) const
find an element in a JSON object
Definition: json.hpp:21329
basic_json(const value_t v)
create an empty value with a given type
Definition: json.hpp:18317
static void to_ubjson(const basic_json &j, detail::output_adapter< uint8_t > o, const bool use_size=false, const bool use_type=false)
Definition: json.hpp:24273
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:19154
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition: json.hpp:22065
static JSON_HEDLEY_WARN_UNUSED_RESULT 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:25479
void erase(const size_type idx)
remove element from a JSON array given an index
Definition: json.hpp:21259
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.hpp:21710
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition: json.hpp:20435
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
wrapper to access iterator member functions in range-based for
Definition: json.hpp:21774
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition: json.hpp:20384
iterator begin() noexcept
returns an iterator to the first element
Definition: json.hpp:21466
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition: json.hpp:18896
friend bool operator==(ScalarType lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.hpp:23203
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:24264
json_value(object_t &&value)
constructor for rvalue objects
Definition: json.hpp:17980
boolean_t * get_impl_ptr(boolean_t *) noexcept
get a pointer to the value (boolean)
Definition: json.hpp:19723
basic_json(const JsonRef &ref)
Definition: json.hpp:18999
static void to_cbor(const basic_json &j, detail::output_adapter< uint8_t > o)
Definition: json.hpp:24073
string_t * get_impl_ptr(string_t *) noexcept
get a pointer to the value (string)
Definition: json.hpp:19711
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition: json.hpp:18759
json_value(number_float_t v) noexcept
constructor for numbers (floating-point)
Definition: json.hpp:17889
const_reverse_iterator rend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.hpp:21652
void assert_invariant(bool check_parents=true) const noexcept
checks the class invariants
Definition: json.hpp:18131
json_value(string_t &&value)
constructor for rvalue strings
Definition: json.hpp:17968
const_iterator cend() const noexcept
returns a const iterator to one past the last element
Definition: json.hpp:21577
json_value(number_integer_t v) noexcept
constructor for numbers (integer)
Definition: json.hpp:17885
reference back()
access the last element
Definition: json.hpp:20949
static bool accept(InputType &&i, const bool ignore_comments=false)
check if the input is valid JSON
Definition: json.hpp:23736
StringType string_t
a type for a string
Definition: json.hpp:17500
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:21994
void push_back(const basic_json &val)
add an object to an array
Definition: json.hpp:22249
friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
Definition: json.hpp:23576
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition: json.hpp:17241
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition: json.hpp:20851
void update(const_reference j)
updates a JSON object from another object, overwriting existing keys
Definition: json.hpp:22762
constexpr const binary_t * get_impl_ptr(const binary_t *) const noexcept
get a pointer to the value (binary)
Definition: json.hpp:19777
std::size_t size_type
a type to represent container sizes
Definition: json.hpp:17184
array_t * get_impl_ptr(array_t *) noexcept
get a pointer to the value (array)
Definition: json.hpp:19699
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition: json.hpp:17182
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
Definition: json.hpp:18656
reference operator[](const typename object_t::key_type &key)
access specified object element
Definition: json.hpp:20572
number_float_t * get_impl_ptr(number_float_t *) noexcept
get a pointer to the value (floating-point number)
Definition: json.hpp:19759
json_value(number_unsigned_t v) noexcept
constructor for numbers (unsigned)
Definition: json.hpp:17887
reference operator+=(basic_json &&val)
add an object to an array
Definition: json.hpp:22239
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition: json.hpp:18451
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition: json.hpp:17192
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
Create a JSON value from an input in BSON format.
Definition: json.hpp:24866
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition: json.hpp:17190
static JSON_HEDLEY_WARN_UNUSED_RESULT 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:24475
BooleanType boolean_t
a type for a boolean
Definition: json.hpp:17526
void push_back(initializer_list_t init)
add an object to an object
Definition: json.hpp:22356
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition: json.hpp:23922
boolean_t get_impl(boolean_t *) const
get a boolean (explicit)
Definition: json.hpp:19676
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:19252
static bool accept(IteratorType first, IteratorType last, const bool ignore_comments=false)
Definition: json.hpp:23743
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition: json.hpp:21016
friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept
comparison: not equal
Definition: json.hpp:23237
static JSON_HEDLEY_WARN_UNUSED_RESULT 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:24850
constexpr bool is_structured() const noexcept
return whether type is structured
Definition: json.hpp:19363
friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.hpp:23415
const_iterator begin() const noexcept
returns a const iterator to the first element
Definition: json.hpp:21476
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition: json.hpp:21864
friend bool operator<(const_reference lhs, ScalarType rhs) noexcept
comparison: less than
Definition: json.hpp:23358
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:20286
reference front()
access the first element
Definition: json.hpp:20905
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition: json.hpp:19336
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition: json.hpp:19494
static void to_cbor(const basic_json &j, detail::output_adapter< char > o)
Definition: json.hpp:24078
void swap(object_t &other)
exchanges the values
Definition: json.hpp:22960
constexpr bool is_object() const noexcept
return whether value is an object
Definition: json.hpp:19544
const_reference front() const
access the first element
Definition: json.hpp:20913
binary_t * get_impl_ptr(binary_t *) noexcept
get a pointer to the value (binary)
Definition: json.hpp:19771
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.hpp:19305
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:17737
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition: json.hpp:17199
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.hpp:23393
bool empty() const noexcept
checks whether the container is empty.
Definition: json.hpp:21921
constexpr const number_unsigned_t * get_impl_ptr(const number_unsigned_t *) const noexcept
get a pointer to the value (unsigned number)
Definition: json.hpp:19753
friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
serialize to stream
Definition: json.hpp:23552
json_value(value_t t)
constructor for empty values of a given type
Definition: json.hpp:17891
basic_json(const basic_json &other)
copy constructor
Definition: json.hpp:19026
constexpr const boolean_t * get_impl_ptr(const boolean_t *) const noexcept
get a pointer to the value (boolean)
Definition: json.hpp:19729
~basic_json() noexcept
destructor
Definition: json.hpp:19188
BasicJsonType get() const
get special-case overload
Definition: json.hpp:19852
basic_json(basic_json &&other) noexcept
move constructor
Definition: json.hpp:19116
static void to_bson(const basic_json &j, detail::output_adapter< uint8_t > o)
Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the ...
Definition: json.hpp:24357
friend bool operator>(ScalarType lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.hpp:23461
static void to_ubjson(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
Definition: json.hpp:24279
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.hpp:23226
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts elements
Definition: json.hpp:22578
friend bool operator<(ScalarType lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.hpp:23369
json_value m_value
the value of the current element
Definition: json.hpp:23957
boolean_t boolean
boolean
Definition: json.hpp:17872
void swap(typename binary_t::container_type &other)
exchanges the values
Definition: json.hpp:23040
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:23485
constexpr const object_t * get_impl_ptr(const object_t *) const noexcept
get a pointer to the value (object)
Definition: json.hpp:19693
void swap(array_t &other)
exchanges the values
Definition: json.hpp:22927
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition: json.hpp:21644
json_value(const string_t &value)
constructor for strings
Definition: json.hpp:17962
json_value(const binary_t &value)
constructor for binary arrays (internal type)
Definition: json.hpp:18010
ReferenceType get_ref() const
get a reference value (implicit)
Definition: json.hpp:20167
json_value(const array_t &value)
constructor for arrays
Definition: json.hpp:17986
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts elements
Definition: json.hpp:22626
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition: json.hpp:20108
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.hpp:25056
const_iterator end() const noexcept
returns a const iterator to one past the last element
Definition: json.hpp:21547
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition: json.hpp:25654
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition: json.hpp:20060
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements
Definition: json.hpp:22679
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition: json.hpp:17447
Array get_to(T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v)))
Definition: json.hpp:20023
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.hpp:23439
json_value(const object_t &value)
constructor for objects
Definition: json.hpp:17974
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition: json.hpp:21129
object_t * get_impl_ptr(object_t *) noexcept
get a pointer to the value (object)
Definition: json.hpp:19687
json_value(typename binary_t::container_type &&value)
constructor for rvalue binary arrays
Definition: json.hpp:18004
json_value(boolean_t v) noexcept
constructor for booleans
Definition: json.hpp:17883
ValueType get() const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), std::declval< ValueType & >())))
get a value (explicit)
Definition: json.hpp:19902
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition: json.hpp:19407
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition: json.hpp:21856
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:21537
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:22864
void clear() noexcept
clears the contents
Definition: json.hpp:22136
friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:23507
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition: json.hpp:24635
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition: json.hpp:19610
static std::vector< uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition: json.hpp:24161
binary_t * binary
binary (stored with pointer to save storage)
Definition: json.hpp:17870
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition: json.hpp:18803
constexpr const number_float_t * get_impl_ptr(const number_float_t *) const noexcept
get a pointer to the value (floating-point number)
Definition: json.hpp:19765
iterator insert(const_iterator pos, basic_json &&val)
inserts element
Definition: json.hpp:22549
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
Definition: json.hpp:24752
reference operator[](size_type idx)
access specified array element
Definition: json.hpp:20481
friend bool operator>(const_reference lhs, ScalarType rhs) noexcept
comparison: greater than
Definition: json.hpp:23450
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the ...
Definition: json.hpp:24365
void update(const_iterator first, const_iterator last)
updates a JSON object from another object, overwriting existing keys
Definition: json.hpp:22813
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.hpp:25013
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:19999
void swap(binary_t &other)
exchanges the values
Definition: json.hpp:23026
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:24342
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition: json.hpp:17201
static JSON_HEDLEY_WARN_UNUSED_RESULT 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:24736
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition: json.hpp:17126
static void to_msgpack(const basic_json &j, detail::output_adapter< uint8_t > o)
Definition: json.hpp:24168
friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.hpp:23248
static ::nlohmann::detail::parser< basic_json, InputAdapterType > parser(InputAdapterType adapter, detail::parser_callback_t< basic_json >cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
Definition: json.hpp:17092
number_unsigned_t * get_impl_ptr(number_unsigned_t *) noexcept
get a pointer to the value (unsigned number)
Definition: json.hpp:19747
const_reverse_iterator rbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.hpp:21615
binary_t & get_binary()
Definition: json.hpp:20228
void swap(string_t &other)
exchanges the values
Definition: json.hpp:22993
const_reference back() const
access the last element
Definition: json.hpp:20959
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.hpp:23279
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition: json.hpp:23878
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array (without subtype)
Definition: json.hpp:18703
constexpr bool is_string() const noexcept
return whether value is a string
Definition: json.hpp:19588
number_integer_t * get_impl_ptr(number_integer_t *) noexcept
get a pointer to the value (integer number)
Definition: json.hpp:19735
constexpr bool is_array() const noexcept
return whether value is an array
Definition: json.hpp:19566
iterator insert_iterator(const_iterator pos, Args &&... args)
Definition: json.hpp:22489
basic_json flatten() const
return flattened JSON value
Definition: json.hpp:25083
friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:23496
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:22213
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(IteratorType first, IteratorType last, 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:24492
size_type count(KeyT &&key) const
returns the number of occurrences of a key in a JSON object
Definition: json.hpp:21363
json_value(const typename binary_t::container_type &value)
constructor for binary arrays
Definition: json.hpp:17998
const binary_t & get_binary() const
Definition: json.hpp:20239
json_value()=default
default constructor (for null values)
constexpr bool is_number() const noexcept
return whether value is a number
Definition: json.hpp:19437
number_float_t number_float
number (floating-point)
Definition: json.hpp:17878
std::less< StringType > object_comparator_t
Definition: json.hpp:17311
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:17868
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition: json.hpp:22457
reference operator+=(initializer_list_t init)
add an object to an object
Definition: json.hpp:22374
::nlohmann::detail::output_adapter_t< CharType > output_adapter_t
Definition: json.hpp:17114
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition: json.hpp:19466
static JSON_HEDLEY_RETURNS_NON_NULL T * create(Args &&... args)
helper for exception-safe object creation
Definition: json.hpp:17816
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition: json.hpp:17134
constexpr const array_t * get_impl_ptr(const array_t *) const noexcept
get a pointer to the value (array)
Definition: json.hpp:19705
detail::value_t value_t
Definition: json.hpp:17124
ValueType & get_to(ValueType &v) const
Definition: json.hpp:20012
json_value(binary_t &&value)
constructor for rvalue binary arrays (internal type)
Definition: json.hpp:18016
static void to_msgpack(const basic_json &j, detail::output_adapter< char > o)
Definition: json.hpp:24173
const_reference operator[](const typename object_t::key_type &key) const
read-only access specified object element
Definition: json.hpp:20621
iterator set_parents(iterator it, typename iterator::difference_type count)
Definition: json.hpp:18182
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init, std::uint8_t subtype)
explicitly create a binary array (with subtype)
Definition: json.hpp:18693
iterator find(KeyT &&key)
find an element in a JSON object
Definition: json.hpp:21312
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition: json.hpp:18341
const_reference operator[](size_type idx) const
access specified array element
Definition: json.hpp:20534
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:17866
AllocatorType< basic_json > allocator_type
the allocator type
Definition: json.hpp:17187
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition: json.hpp:17808
JSONSerializer< T, SFINAE > json_serializer
Definition: json.hpp:17128
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition: json.hpp:22300
ValueType get() const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >())))
get a value (explicit); special case
Definition: json.hpp:19953
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(IteratorType first, IteratorType last, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a pair of character iterators
Definition: json.hpp:23682
number_integer_t number_integer
number (integer)
Definition: json.hpp:17874
constexpr const string_t * get_impl_ptr(const string_t *) const noexcept
get a pointer to the value (string)
Definition: json.hpp:19717
static std::vector< uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition: json.hpp:24066
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition: json.hpp:21427
static JSON_HEDLEY_WARN_UNUSED_RESULT 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:24619
void destroy(value_t t) noexcept
Definition: json.hpp:18021
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
Definition: json.hpp:25181
string_t value(const typename object_t::key_type &key, const char *default_value) const
overload for a default value of type const char*
Definition: json.hpp:20801
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:18413
void set_parents()
Definition: json.hpp:18153
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition: json.hpp:25120
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition: json.hpp:17669
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition: json.hpp:22325
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition: json.hpp:21506
friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept
comparison: less than or equal
Definition: json.hpp:23404
json_value(array_t &&value)
constructor for rvalue arrays
Definition: json.hpp:17992
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:18575
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition: json.hpp:20333
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:22527
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition: json.hpp:19637
constexpr bool is_null() const noexcept
return whether value is null
Definition: json.hpp:19385
reference set_parent(reference j)
Definition: json.hpp:18195
friend void swap(reference left, reference right) 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:22897
ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > >> object_t
a type for an object
Definition: json.hpp:17401
reference operator+=(const basic_json &val)
add an object to an array
Definition: json.hpp:22274
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition: json.hpp:21224
static ReferenceType get_ref_impl(ThisType &obj)
helper function to implement get_ref()
Definition: json.hpp:19794
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition: json.hpp:18830
static allocator_type get_allocator()
returns the allocator associated with the container
Definition: json.hpp:17209
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:20073
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition: json.hpp:21607
an internal type for a backed binary type
Definition: json.hpp:4803
BinaryType container_type
the type of the underlying container
Definition: json.hpp:4806
void set_subtype(std::uint8_t subtype_) noexcept
sets the binary subtype
Definition: json.hpp:4861
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition: json.hpp:4812
bool m_has_subtype
Definition: json.hpp:4941
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition: json.hpp:4816
bool operator!=(const byte_container_with_subtype &rhs) const
Definition: json.hpp:4838
void clear_subtype() noexcept
clears the binary subtype
Definition: json.hpp:4933
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition: json.hpp:4808
byte_container_with_subtype(const container_type &b, std::uint8_t subtype_) noexcept(noexcept(container_type(b)))
Definition: json.hpp:4820
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition: json.hpp:4909
byte_container_with_subtype(container_type &&b, std::uint8_t subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition: json.hpp:4826
constexpr std::uint8_t subtype() const noexcept
return the binary subtype
Definition: json.hpp:4888
std::uint8_t m_subtype
Definition: json.hpp:4940
bool operator==(const byte_container_with_subtype &rhs) const
Definition: json.hpp:4832
deserialization of CBOR, MessagePack, and UBJSON values
Definition: json.hpp:8109
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:8111
bool get_msgpack_array(const std::size_t len)
Definition: json.hpp:9754
bool get_bson_string(const NumberType len, string_t &result)
Parses a zero-terminated string of length len from the BSON input.
Definition: json.hpp:8262
bool parse_bson_element_internal(const char_int_type element_type, const std::size_t element_type_parse_position)
Read a BSON document element of the given element_type.
Definition: json.hpp:8309
bool parse_bson_array()
Reads an array from the BSON input and passes it to the SAX-parser.
Definition: json.hpp:8425
char_int_type get_ignore_noop()
Definition: json.hpp:10313
bool get_ubjson_high_precision_number()
Definition: json.hpp:10242
binary_reader(InputAdapterType &&adapter) noexcept
create a binary reader
Definition: json.hpp:8125
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:8110
bool get_bson_cstr(string_t &result)
Parses a C-style string from the BSON input.
Definition: json.hpp:8232
binary_reader & operator=(const binary_reader &)=delete
bool get_cbor_array(const std::size_t len, const cbor_tag_handler_t tag_handler)
Definition: json.hpp:9090
bool get_msgpack_binary(binary_t &result)
reads a MessagePack byte array
Definition: json.hpp:9643
bool get_cbor_object(const std::size_t len, const cbor_tag_handler_t tag_handler)
Definition: json.hpp:9128
bool get_ubjson_string(string_t &result, const bool get_char=true)
reads a UBJSON string
Definition: json.hpp:9832
SAX json_sax_t
Definition: json.hpp:8115
bool parse_bson_element_list(const bool is_array)
Read a BSON element list (as specified in the BSON-spec)
Definition: json.hpp:8387
bool parse_cbor_internal(const bool get_char, const cbor_tag_handler_t tag_handler)
Definition: json.hpp:8455
bool get_string(const input_format_t format, const NumberType len, string_t &result)
create a string by reading characters from the input
Definition: json.hpp:10381
bool get_cbor_string(string_t &result)
reads a CBOR string
Definition: json.hpp:8901
InputAdapterType ia
input adapter
Definition: json.hpp:10497
bool get_binary(const input_format_t format, const NumberType len, binary_t &result)
create a byte array by reading bytes from the input
Definition: json.hpp:10414
bool parse_ubjson_internal(const bool get_char=true)
Definition: json.hpp:9813
bool unexpect_eof(const input_format_t format, const char *context) const
Definition: json.hpp:10438
bool get_ubjson_size_type(std::pair< std::size_t, char_int_type > &result)
determine the type and size for a container
Definition: json.hpp:9963
std::string get_token_string() const
Definition: json.hpp:10451
bool get_ubjson_value(const char_int_type prefix)
Definition: json.hpp:10004
typename BasicJsonType::string_t string_t
Definition: json.hpp:8113
bool get_msgpack_object(const std::size_t len)
Definition: json.hpp:9776
bool get_bson_binary(const NumberType len, binary_t &result)
Parses a byte array input of length len from the BSON input.
Definition: json.hpp:8283
std::string exception_message(const input_format_t format, const std::string &detail, const std::string &context) const
Definition: json.hpp:10464
std::size_t chars_read
the number of characters read
Definition: json.hpp:10503
typename std::char_traits< char_type >::int_type char_int_type
Definition: json.hpp:8117
binary_reader(const binary_reader &)=delete
char_int_type current
the current character
Definition: json.hpp:10500
bool sax_parse(const input_format_t format, json_sax_t *sax_, const bool strict=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
Definition: json.hpp:8146
json_sax_t * sax
the SAX parser
Definition: json.hpp:10509
bool get_ubjson_size_value(std::size_t &result)
Definition: json.hpp:9886
typename InputAdapterType::char_type char_type
Definition: json.hpp:8116
bool parse_bson_internal()
Reads in a BSON-object and passes it to the SAX-parser.
Definition: json.hpp:8207
bool get_number(const input_format_t format, NumberType &result)
Definition: json.hpp:10338
bool get_cbor_binary(binary_t &result)
reads a CBOR byte array
Definition: json.hpp:8996
binary_reader(binary_reader &&)=default
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:8114
char_int_type get()
get next character from the input
Definition: json.hpp:10304
binary_reader & operator=(binary_reader &&)=default
const bool is_little_endian
whether we can assume little endianess
Definition: json.hpp:10506
bool get_msgpack_string(string_t &result)
reads a MessagePack string
Definition: json.hpp:9561
bool get_ubjson_object()
Definition: json.hpp:10167
bool parse_msgpack_internal()
Definition: json.hpp:9181
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:8112
bool get_ubjson_array()
Definition: json.hpp:10105
serialization to CBOR and MessagePack values
Definition: json.hpp:13132
void write_bson_array(const string_t &name, const typename BasicJsonType::array_t &value)
Writes a BSON element with key name and array value.
Definition: json.hpp:14177
void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix)
Definition: json.hpp:14366
void write_ubjson(const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true)
Definition: json.hpp:13801
static std::size_t calc_bson_entry_header_size(const string_t &name, const BasicJsonType &j)
Definition: json.hpp:14008
static constexpr CharType get_ubjson_float_prefix(double)
Definition: json.hpp:14591
void write_bson_entry_header(const string_t &name, const std::uint8_t element_type)
Writes the given element_type and name to the output adapter.
Definition: json.hpp:14022
static std::size_t calc_bson_element_size(const string_t &name, const BasicJsonType &j)
Calculates the size necessary to serialize the JSON value j with its name.
Definition: json.hpp:14211
void write_bson_double(const string_t &name, const double value)
Writes a BSON element with key name and double value value.
Definition: json.hpp:14044
void write_bson_object(const typename BasicJsonType::object_t &value)
Definition: json.hpp:14319
typename BasicJsonType::string_t string_t
Definition: json.hpp:13133
static constexpr CharType get_cbor_float_prefix(float)
Definition: json.hpp:14335
static constexpr CharType to_char_type(InputCharType x) noexcept
Definition: json.hpp:14684
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:13134
binary_writer(output_adapter_t< CharType > adapter)
create a binary writer
Definition: json.hpp:13143
static constexpr CharType get_msgpack_float_prefix(double)
Definition: json.hpp:14354
CharType ubjson_prefix(const BasicJsonType &j) const noexcept
determine the type prefix of container values
Definition: json.hpp:14506
void write_bson_integer(const string_t &name, const std::int64_t value)
Writes a BSON element with key name and integer value.
Definition: json.hpp:14094
static CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:14662
void write_bson_string(const string_t &name, const string_t &value)
Writes a BSON element with key name and string value value.
Definition: json.hpp:14062
void write_bson_object_entry(const string_t &name, const typename BasicJsonType::object_t &value)
Writes a BSON element with key name and object value.
Definition: json.hpp:14144
static constexpr CharType get_ubjson_float_prefix(float)
Definition: json.hpp:14586
void write_number(const NumberType n)
Definition: json.hpp:14612
void write_bson_element(const string_t &name, const BasicJsonType &j)
Serializes the JSON value j to BSON and associates it with the key name.
Definition: json.hpp:14258
void write_bson_binary(const string_t &name, const binary_t &value)
Writes a BSON element with key name and binary value value.
Definition: json.hpp:14196
void write_bson_null(const string_t &name)
Writes a BSON element with key name and null value.
Definition: json.hpp:14076
static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t &value)
Definition: json.hpp:14169
void write_bson(const BasicJsonType &j)
Definition: json.hpp:13152
void write_cbor(const BasicJsonType &j)
Definition: json.hpp:13172
static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept
Definition: json.hpp:14112
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:14655
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:13135
void write_bson_unsigned(const string_t &name, const BasicJsonType &j)
Writes a BSON element with key name and unsigned value.
Definition: json.hpp:14122
static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t &value)
Calculates the size of the BSON serialization of the given JSON-object j.
Definition: json.hpp:14304
static constexpr CharType get_msgpack_float_prefix(float)
Definition: json.hpp:14349
void write_bson_boolean(const string_t &name, const bool value)
Writes a BSON element with key name and boolean value value.
Definition: json.hpp:14034
void write_msgpack(const BasicJsonType &j)
Definition: json.hpp:13477
void write_compact_float(const number_float_t n, detail::input_format_t format)
Definition: json.hpp:14628
static std::size_t calc_bson_string_size(const string_t &value)
Definition: json.hpp:14054
static std::size_t calc_bson_integer_size(const std::int64_t value)
Definition: json.hpp:14084
static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t &value)
Definition: json.hpp:14154
static constexpr CharType get_cbor_float_prefix(double)
Definition: json.hpp:14340
general exception of the basic_json class
Definition: json.hpp:2637
const char * what() const noexcept override
returns the explanatory string
Definition: json.hpp:2640
const int id
the id of the exception
Definition: json.hpp:2646
static std::string diagnostics(const BasicJsonType &leaf_element)
Definition: json.hpp:2658
static std::string name(const std::string &ename, int id_)
Definition: json.hpp:2652
std::runtime_error m
an exception object as storage for error messages
Definition: json.hpp:2715
Definition: json.hpp:5130
std::FILE * m_file
the file pointer to read from
Definition: json.hpp:5153
std::char_traits< char >::int_type get_character() noexcept
Definition: json.hpp:5146
file_input_adapter(const file_input_adapter &)=delete
file_input_adapter(file_input_adapter &&) noexcept=default
char char_type
Definition: json.hpp:5132
input_stream_adapter(input_stream_adapter &&rhs) noexcept
Definition: json.hpp:5190
~input_stream_adapter()
Definition: json.hpp:5171
input_stream_adapter & operator=(input_stream_adapter &&)=delete
input_stream_adapter(const input_stream_adapter &)=delete
std::istream * is
the associated input stream
Definition: json.hpp:5213
char char_type
Definition: json.hpp:5169
std::streambuf * sb
Definition: json.hpp:5214
std::char_traits< char >::int_type get_character()
Definition: json.hpp:5200
input_stream_adapter & operator=(input_stream_adapter &)=delete
input_stream_adapter(std::istream &i)
Definition: json.hpp:5181
exception indicating errors with iterators
Definition: json.hpp:2852
static invalid_iterator create(int id_, const std::string &what_arg, const BasicJsonType &context)
Definition: json.hpp:2855
invalid_iterator(int id_, const char *what_arg)
Definition: json.hpp:2863
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition: json.hpp:11218
bool operator<(const iter_impl &other) const
comparison: smaller
Definition: json.hpp:11619
iter_impl operator-(difference_type i) const
subtract from iterator
Definition: json.hpp:11733
const object_t::key_type & key() const
return the key of an object iterator
Definition: json.hpp:11796
bool operator!=(const IterImpl &other) const
comparison: not equal
Definition: json.hpp:11610
iter_impl const operator--(int)
post-decrement (it–)
Definition: json.hpp:11538
void set_end() noexcept
set the iterator past the last value
Definition: json.hpp:11393
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition: json.hpp:11245
iter_impl & operator+=(difference_type i)
add to iterator
Definition: json.hpp:11673
difference_type operator-(const iter_impl &other) const
return difference
Definition: json.hpp:11744
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type reference
defines a reference to the type iterated over (value_type)
Definition: json.hpp:11254
reference operator*() const
return a reference to the value pointed to by the iterator
Definition: json.hpp:11424
iter_impl(iter_impl &&) noexcept=default
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition: json.hpp:11664
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type pointer
defines a pointer to the type iterated over (value_type)
Definition: json.hpp:11249
pointer operator->() const
dereference the iterator
Definition: json.hpp:11461
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition: json.hpp:11344
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition: json.hpp:11309
iter_impl const operator++(int)
post-increment (it++)
Definition: json.hpp:11495
iter_impl & operator--()
pre-decrement (–it)
Definition: json.hpp:11549
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition: json.hpp:11334
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:11821
iter_impl operator+(difference_type i) const
add to iterator
Definition: json.hpp:11711
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition: json.hpp:11722
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition: json.hpp:11319
bool operator==(const IterImpl &other) const
comparison: equal
Definition: json.hpp:11582
bool operator>(const iter_impl &other) const
comparison: greater than
Definition: json.hpp:11655
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition: json.hpp:11243
reference value() const
return the value of an iterator
Definition: json.hpp:11812
typename BasicJsonType::object_t object_t
Definition: json.hpp:11227
friend other_iter_impl
allow basic_json to access private members
Definition: json.hpp:11222
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition: json.hpp:11702
iter_impl & operator++()
pre-increment (++it)
Definition: json.hpp:11506
friend BasicJsonType
Definition: json.hpp:11223
reference operator[](difference_type n) const
access to successor
Definition: json.hpp:11765
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition: json.hpp:11646
std::bidirectional_iterator_tag iterator_category
Definition: json.hpp:11240
typename BasicJsonType::array_t array_t
Definition: json.hpp:11228
IteratorType anchor
the iterator
Definition: json.hpp:4212
iteration_proxy_value & operator*()
dereference operator (needed for range-based for)
Definition: json.hpp:4228
std::input_iterator_tag iterator_category
Definition: json.hpp:4207
typename std::remove_cv< typename std::remove_reference< decltype(std::declval< IteratorType >().key()) >::type >::type string_type
Definition: json.hpp:4208
const string_type empty_str
an empty string (to return a reference for primitive values)
Definition: json.hpp:4220
iteration_proxy_value(IteratorType it) noexcept
Definition: json.hpp:4223
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition: json.hpp:4249
std::size_t array_index_last
last stringified array index
Definition: json.hpp:4216
string_type array_index_str
a string representation of the array index
Definition: json.hpp:4218
IteratorType::reference value() const
return value of the iterator
Definition: json.hpp:4283
std::size_t array_index
an index for arrays (used to create key names)
Definition: json.hpp:4214
std::ptrdiff_t difference_type
Definition: json.hpp:4203
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition: json.hpp:4234
const string_type & key() const
return key of the iterator
Definition: json.hpp:4255
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition: json.hpp:4243
proxy class for the items() function
Definition: json.hpp:4291
iteration_proxy_value< IteratorType > begin() noexcept
return iterator begin (needed for range-based for)
Definition: json.hpp:4302
IteratorType::reference container
the container to iterate
Definition: json.hpp:4294
iteration_proxy_value< IteratorType > end() noexcept
return iterator end (needed for range-based for)
Definition: json.hpp:4308
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition: json.hpp:4298
std::char_traits< char_type >::int_type get_character()
Definition: json.hpp:5229
typename std::iterator_traits< IteratorType >::value_type char_type
Definition: json.hpp:5223
IteratorType end
Definition: json.hpp:5243
IteratorType current
Definition: json.hpp:5242
iterator_input_adapter(IteratorType first, IteratorType last)
Definition: json.hpp:5225
bool empty() const
Definition: json.hpp:5248
Definition: json.hpp:12906
value_type const * value_ref
Definition: json.hpp:12957
json_ref(json_ref &&) noexcept=default
value_type owned_value
Definition: json.hpp:12956
BasicJsonType value_type
Definition: json.hpp:12908
json_ref(Args &&... args)
Definition: json.hpp:12925
json_ref(const value_type &value)
Definition: json.hpp:12914
value_type const & operator*() const
Definition: json.hpp:12945
value_type const * operator->() const
Definition: json.hpp:12950
json_ref(std::initializer_list< json_ref > init)
Definition: json.hpp:12918
json_ref(value_type &&value)
Definition: json.hpp:12910
value_type moved_or_copied() const
Definition: json.hpp:12936
a template for a reverse iterator class
Definition: json.hpp:11863
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition: json.hpp:11872
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition: json.hpp:11897
json_reverse_iterator & operator++()
pre-increment (++it)
Definition: json.hpp:11885
json_reverse_iterator const operator--(int)
post-decrement (it–)
Definition: json.hpp:11891
typename Base::reference reference
the reference type for the pointed-to element
Definition: json.hpp:11869
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition: json.hpp:11903
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition: json.hpp:11915
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition: json.hpp:11867
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition: json.hpp:11876
reference operator[](difference_type n) const
access to successor
Definition: json.hpp:11927
std::ptrdiff_t difference_type
Definition: json.hpp:11865
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition: json.hpp:11921
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition: json.hpp:11909
json_reverse_iterator const operator++(int)
post-increment (it++)
Definition: json.hpp:11879
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition: json.hpp:11933
reference value() const
return the value of an iterator
Definition: json.hpp:11940
Definition: json.hpp:6212
bool end_array()
Definition: json.hpp:6275
typename BasicJsonType::string_t string_t
Definition: json.hpp:6217
bool binary(binary_t &)
Definition: json.hpp:6250
bool boolean(bool)
Definition: json.hpp:6225
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:6214
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:6216
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:6218
bool key(string_t &)
Definition: json.hpp:6260
bool start_object(std::size_t=std::size_t(-1))
Definition: json.hpp:6255
bool start_array(std::size_t=std::size_t(-1))
Definition: json.hpp:6270
bool end_object()
Definition: json.hpp:6265
bool parse_error(std::size_t, const std::string &, const detail::exception &)
Definition: json.hpp:6280
bool number_integer(number_integer_t)
Definition: json.hpp:6230
bool string(string_t &)
Definition: json.hpp:6245
bool number_unsigned(number_unsigned_t)
Definition: json.hpp:6235
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:6215
bool number_float(number_float_t, const string_t &)
Definition: json.hpp:6240
typename BasicJsonType::string_t string_t
Definition: json.hpp:5910
bool start_object(std::size_t len)
Definition: json.hpp:5972
bool key(string_t &val)
Definition: json.hpp:5990
constexpr bool is_errored() const
Definition: json.hpp:6105
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:5908
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:5907
typename BasicJsonType::parser_callback_t parser_callback_t
Definition: json.hpp:5912
bool start_array(std::size_t len)
Definition: json.hpp:6043
json_sax_dom_callback_parser(const json_sax_dom_callback_parser &)=delete
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:5911
json_sax_dom_callback_parser & operator=(const json_sax_dom_callback_parser &)=delete
json_sax_dom_callback_parser & operator=(json_sax_dom_callback_parser &&)=default
bool binary(binary_t &val)
Definition: json.hpp:5966
bool number_integer(number_integer_t val)
Definition: json.hpp:5942
BasicJsonType & root
the parsed JSON value
Definition: json.hpp:6191
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:6127
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:5909
bool end_array()
Definition: json.hpp:6060
typename BasicJsonType::parse_event_t parse_event_t
Definition: json.hpp:5913
bool boolean(bool val)
Definition: json.hpp:5936
bool number_unsigned(number_unsigned_t val)
Definition: json.hpp:5948
bool string(string_t &val)
Definition: json.hpp:5960
bool number_float(number_float_t val, const string_t &)
Definition: json.hpp:5954
bool end_object()
Definition: json.hpp:6007
json_sax_dom_callback_parser(json_sax_dom_callback_parser &&)=default
bool parse_error(std::size_t, const std::string &, const Exception &ex)
Definition: json.hpp:6093
json_sax_dom_callback_parser(BasicJsonType &r, const parser_callback_t cb, const bool allow_exceptions_=true)
Definition: json.hpp:5915
SAX implementation to create a JSON value from SAX events.
Definition: json.hpp:5731
bool start_array(std::size_t len)
Definition: json.hpp:5823
json_sax_dom_parser(const json_sax_dom_parser &)=delete
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:5737
bool number_unsigned(number_unsigned_t val)
Definition: json.hpp:5773
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:5733
bool boolean(bool val)
Definition: json.hpp:5761
bool parse_error(std::size_t, const std::string &, const Exception &ex)
Definition: json.hpp:5843
bool string(string_t &val)
Definition: json.hpp:5785
bool end_object()
Definition: json.hpp:5816
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:5734
json_sax_dom_parser & operator=(const json_sax_dom_parser &)=delete
bool start_object(std::size_t len)
Definition: json.hpp:5797
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:5869
bool binary(binary_t &val)
Definition: json.hpp:5791
constexpr bool is_errored() const
Definition: json.hpp:5855
bool key(string_t &val)
Definition: json.hpp:5809
json_sax_dom_parser(json_sax_dom_parser &&)=default
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:5735
BasicJsonType & root
the parsed JSON value
Definition: json.hpp:5892
bool number_float(number_float_t val, const string_t &)
Definition: json.hpp:5779
bool end_array()
Definition: json.hpp:5835
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true)
Definition: json.hpp:5744
typename BasicJsonType::string_t string_t
Definition: json.hpp:5736
bool number_integer(number_integer_t val)
Definition: json.hpp:5767
json_sax_dom_parser & operator=(json_sax_dom_parser &&)=default
Definition: json.hpp:6319
token_type
token types for the parser
Definition: json.hpp:6323
@ value_float
an floating point number – use get_number_float() for actual value
@ begin_array
the character for array begin [
@ value_string
a string – use get_string() for actual value
@ end_array
the character for array end ]
@ uninitialized
indicating the scanner is uninitialized
@ parse_error
indicating a parse error
@ value_integer
a signed integer – use get_number_integer() for actual value
@ value_separator
the value separator ,
@ end_object
the character for object end }
@ begin_object
the character for object begin {
@ value_unsigned
an unsigned integer – use get_number_unsigned() for actual value
@ end_of_input
indicating the end of the input buffer
@ literal_or_value
a literal or the begin of a value (only for diagnostics)
JSON_HEDLEY_RETURNS_NON_NULL static JSON_HEDLEY_CONST const char * token_type_name(const token_type t) noexcept
return name of values of type token_type (only used for errors)
Definition: json.hpp:6346
lexical analysis
Definition: json.hpp:6396
number_float_t value_float
Definition: json.hpp:7909
const bool ignore_comments
whether comments should be ignored (true) or signaled as errors (false)
Definition: json.hpp:7886
lexer & operator=(lexer &&)=default
void add(char_int_type c)
add a character to token_buffer
Definition: json.hpp:7685
void reset() noexcept
reset token_buffer; current character is beginning of token
Definition: json.hpp:7604
token_type scan()
Definition: json.hpp:7793
bool next_unget
whether the next get() call should just return current
Definition: json.hpp:7892
char_int_type current
the current character
Definition: json.hpp:7889
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:6399
void skip_whitespace()
Definition: json.hpp:7784
typename std::char_traits< char_type >::int_type char_int_type
Definition: json.hpp:6402
static JSON_HEDLEY_PURE char get_decimal_point() noexcept
return the locale-dependent decimal point
Definition: json.hpp:6427
number_integer_t value_integer
Definition: json.hpp:7907
InputAdapterType ia
input adapter
Definition: json.hpp:7883
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:6397
static void strtof(float &f, const char *str, char **endptr) noexcept
Definition: json.hpp:7196
const char_int_type decimal_point_char
the decimal point
Definition: json.hpp:7912
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
Definition: json.hpp:7714
bool skip_bom()
skip the UTF-8 byte order mark
Definition: json.hpp:7770
const char * error_message
a description of occurred lexer errors
Definition: json.hpp:7904
lexer(InputAdapterType &&adapter, bool ignore_comments_=false) noexcept
Definition: json.hpp:6407
position_t position
the start position of the current token
Definition: json.hpp:7895
constexpr position_t get_position() const noexcept
return position of last read token
Definition: json.hpp:7724
std::vector< char_type > token_string
raw input token string (for error messages)
Definition: json.hpp:7898
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition: json.hpp:7696
constexpr JSON_HEDLEY_RETURNS_NON_NULL const char * get_error_message() const noexcept
return syntax error message
Definition: json.hpp:7757
typename lexer_base< BasicJsonType >::token_type token_type
Definition: json.hpp:6405
typename InputAdapterType::char_type char_type
Definition: json.hpp:6401
char_int_type get()
Definition: json.hpp:7621
token_type scan_number()
scan a number literal
Definition: json.hpp:7253
void unget()
unget current character (read it again on next get)
Definition: json.hpp:7658
token_type scan_string()
scan a string literal
Definition: json.hpp:6538
lexer(const lexer &)=delete
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition: json.hpp:7702
string_t token_buffer
buffer for variable-length tokens (numbers, strings)
Definition: json.hpp:7901
token_type scan_literal(const char_type *literal_text, const std::size_t length, token_type return_type)
Definition: json.hpp:7584
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition: json.hpp:7708
int get_codepoint()
get codepoint from 4 hex characters following \u
Definition: json.hpp:6453
std::string get_token_string() const
Definition: json.hpp:7732
number_unsigned_t value_unsigned
Definition: json.hpp:7908
lexer(lexer &&)=default
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:6398
bool next_byte_in_range(std::initializer_list< char_int_type > ranges)
check if the next byte(s) are inside a given range
Definition: json.hpp:6501
lexer & operator=(lexer &)=delete
typename BasicJsonType::string_t string_t
Definition: json.hpp:6400
bool scan_comment()
scan a comment
Definition: json.hpp:7128
exception indicating other library errors
Definition: json.hpp:2994
static other_error create(int id_, const std::string &what_arg, const BasicJsonType &context)
Definition: json.hpp:2997
other_error(int id_, const char *what_arg)
Definition: json.hpp:3005
exception indicating access out of the defined range
Definition: json.hpp:2955
static out_of_range create(int id_, const std::string &what_arg, const BasicJsonType &context)
Definition: json.hpp:2958
out_of_range(int id_, const char *what_arg)
Definition: json.hpp:2966
Definition: json.hpp:13096
output_adapter(std::vector< CharType > &vec)
Definition: json.hpp:13098
output_adapter(std::basic_ostream< CharType > &s)
Definition: json.hpp:13101
output_adapter(StringType &s)
Definition: json.hpp:13104
output adapter for output streams
Definition: json.hpp:13049
void write_character(CharType c) override
Definition: json.hpp:13055
std::basic_ostream< CharType > & stream
Definition: json.hpp:13067
output_stream_adapter(std::basic_ostream< CharType > &s) noexcept
Definition: json.hpp:13051
output adapter for basic_string
Definition: json.hpp:13073
void write_character(CharType c) override
Definition: json.hpp:13079
StringType & str
Definition: json.hpp:13091
output_string_adapter(StringType &s) noexcept
Definition: json.hpp:13075
output adapter for byte vectors
Definition: json.hpp:13025
std::vector< CharType > & v
Definition: json.hpp:13043
output_vector_adapter(std::vector< CharType > &vec) noexcept
Definition: json.hpp:13027
void write_character(CharType c) override
Definition: json.hpp:13031
exception indicating a parse error
Definition: json.hpp:2764
parse_error(int id_, std::size_t byte_, const char *what_arg)
Definition: json.hpp:2804
static parse_error create(int id_, std::size_t byte_, const std::string &what_arg, const BasicJsonType &context)
Definition: json.hpp:2784
const std::size_t byte
byte index of the parse error
Definition: json.hpp:2801
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, const BasicJsonType &context)
create a parse error exception
Definition: json.hpp:2776
static std::string position_string(const position_t &pos)
Definition: json.hpp:2807
syntax analysis
Definition: json.hpp:10578
lexer_t m_lexer
the lexer
Definition: json.hpp:11011
bool sax_parse(SAX *sax, const bool strict=true)
Definition: json.hpp:10678
token_type get_token()
get next token from lexer
Definition: json.hpp:10971
token_type last_token
the type of the last read token
Definition: json.hpp:11009
parser(InputAdapterType &&adapter, const parser_callback_t< BasicJsonType > cb=nullptr, const bool allow_exceptions_=true, const bool skip_comments=false)
a parser reading from an input adapter
Definition: json.hpp:10588
bool accept(const bool strict=true)
public accept interface
Definition: json.hpp:10670
typename BasicJsonType::string_t string_t
Definition: json.hpp:10582
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:10580
typename lexer_t::token_type token_type
Definition: json.hpp:10584
bool sax_parse_internal(SAX *sax)
Definition: json.hpp:10697
const parser_callback_t< BasicJsonType > callback
callback function
Definition: json.hpp:11007
void parse(const bool strict, BasicJsonType &result)
public parser interface
Definition: json.hpp:10610
std::string exception_message(const token_type expected, const std::string &context)
Definition: json.hpp:10976
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:10581
const bool allow_exceptions
whether to throw exceptions in case of errors
Definition: json.hpp:11013
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:10579
Definition: json.hpp:11045
primitive_iterator_t operator+(difference_type n) noexcept
Definition: json.hpp:11095
primitive_iterator_t & operator-=(difference_type n) noexcept
Definition: json.hpp:11139
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition: json.hpp:11080
constexpr friend bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:11090
constexpr friend difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:11102
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: json.hpp:11074
void set_begin() noexcept
set iterator to a defined beginning
Definition: json.hpp:11062
primitive_iterator_t const operator++(int) noexcept
Definition: json.hpp:11113
static constexpr difference_type end_value
Definition: json.hpp:11049
primitive_iterator_t & operator--() noexcept
Definition: json.hpp:11120
primitive_iterator_t & operator++() noexcept
Definition: json.hpp:11107
void set_end() noexcept
set iterator to a defined past the end
Definition: json.hpp:11068
constexpr difference_type get_value() const noexcept
Definition: json.hpp:11056
primitive_iterator_t & operator+=(difference_type n) noexcept
Definition: json.hpp:11133
primitive_iterator_t const operator--(int) noexcept
Definition: json.hpp:11126
std::ptrdiff_t difference_type
Definition: json.hpp:11047
constexpr friend bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:11085
static constexpr difference_type begin_value
Definition: json.hpp:11048
Definition: json.hpp:15853
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition: json.hpp:16763
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:15857
const std::lconv * loc
the locale
Definition: json.hpp:16748
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition: json.hpp:16745
static constexpr std::uint8_t UTF8_ACCEPT
Definition: json.hpp:15859
serializer(serializer &&)=delete
const char decimal_point
the locale's decimal point character
Definition: json.hpp:16752
std::uint8_t state
Definition: json.hpp:16195
std::size_t bytes
Definition: json.hpp:16196
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:15855
serializer & operator=(const serializer &)=delete
const char thousands_sep
the locale's thousand separator character
Definition: json.hpp:16750
std::size_t undumped_chars
Definition: json.hpp:16200
static constexpr std::uint8_t UTF8_REJECT
Definition: json.hpp:15860
void dump(const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
Definition: json.hpp:15908
const char indent_char
the indentation character
Definition: json.hpp:16758
std::size_t bytes_after_last_accept
Definition: json.hpp:16199
std::array< char, 512 > string_buffer
string buffer
Definition: json.hpp:16755
typename BasicJsonType::binary_t::value_type binary_char_t
Definition: json.hpp:15858
JSON_PRIVATE_UNLESS_TESTED const bool ensure_ascii
Definition: json.hpp:16193
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition: json.hpp:15868
serializer & operator=(serializer &&)=delete
typename BasicJsonType::string_t string_t
Definition: json.hpp:15854
serializer(const serializer &)=delete
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:15856
string_t indent_string
the indentation string
Definition: json.hpp:16760
Definition: json.hpp:5545
span_input_adapter(CharT b, std::size_t l)
Definition: json.hpp:5553
contiguous_bytes_input_adapter ia
Definition: json.hpp:5569
contiguous_bytes_input_adapter && get()
Definition: json.hpp:5563
span_input_adapter(IteratorType first, IteratorType last)
Definition: json.hpp:5560
exception indicating executing a member function with a wrong type
Definition: json.hpp:2907
static type_error create(int id_, const std::string &what_arg, const BasicJsonType &context)
Definition: json.hpp:2910
type_error(int id_, const char *what_arg)
Definition: json.hpp:2918
void fill_buffer()
Definition: json.hpp:5409
std::size_t utf8_bytes_index
index to the utf8_codes array for the next valid byte
Definition: json.hpp:5418
std::char_traits< char >::int_type get_character() noexcept
Definition: json.hpp:5388
BaseInputAdapter base_adapter
Definition: json.hpp:5406
char char_type
Definition: json.hpp:5383
std::size_t utf8_bytes_filled
number of valid bytes in the utf8_codes array
Definition: json.hpp:5420
wide_string_input_adapter(BaseInputAdapter base)
Definition: json.hpp:5385
std::array< std::char_traits< char >::int_type, 4 > utf8_bytes
a buffer for UTF-8 bytes
Definition: json.hpp:5415
JSON Pointer.
Definition: json.hpp:11975
std::vector< std::string > reference_tokens
the reference tokens
Definition: json.hpp:12887
JSON_PRIVATE_UNLESS_TESTED JSON pointer has no BasicJsonType()))
const std::string & back() const
return last reference token
Definition: json.hpp:12226
BasicJsonType & get_checked(BasicJsonType *ptr) const
Definition: json.hpp:12485
std::string to_string() const
return a string representation of the JSON pointer
Definition: json.hpp:12020
friend bool operator==(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for equality
Definition: json.hpp:12863
result reference_tokens
Definition: json.hpp:12341
void pop_back()
remove last reference token
Definition: json.hpp:12202
const BasicJsonType & get_checked(const BasicJsonType *ptr) const
Definition: json.hpp:12574
BasicJsonType & get_unchecked(BasicJsonType *ptr) const
return a reference to the pointed to value
Definition: json.hpp:12426
BasicJsonType & get_and_create(BasicJsonType &j) const
create and return a reference to the pointed to value
Definition: json.hpp:12354
bool empty() const noexcept
return whether pointer points to the root document
Definition: json.hpp:12273
friend bool operator!=(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for inequality
Definition: json.hpp:12880
void push_back(const std::string &token)
append an unescaped token at the end of the reference pointer
Definition: json.hpp:12248
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition: json.hpp:12052
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition: json.hpp:12098
json_pointer(const std::string &s="")
create JSON pointer
Definition: json.hpp:12002
return result
Definition: json.hpp:12342
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:12118
bool contains(const BasicJsonType *ptr) const
Definition: json.hpp:12614
static BasicJsonType unflatten(const BasicJsonType &value)
Definition: json.hpp:12825
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:12139
static void flatten(const std::string &reference_string, const BasicJsonType &value, BasicJsonType &result)
Definition: json.hpp:12762
json_pointer & operator/=(std::string token)
append an unescaped reference token at the end of this JSON pointer
Definition: json.hpp:12076
void push_back(std::string &&token)
append an unescaped token at the end of the reference pointer
Definition: json.hpp:12254
const BasicJsonType & get_unchecked(const BasicJsonType *ptr) const
return a const reference to the pointed to value
Definition: json.hpp:12534
static std::vector< std::string > split(const std::string &reference_string)
split the string input to reference tokens
Definition: json.hpp:12694
static BasicJsonType::size_type array_index(const std::string &s)
Definition: json.hpp:12289
json_pointer result
Definition: json.hpp:12340
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:12159
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition: json.hpp:12177
Concept for allocating, resizing and freeing memory block.
decltype(get< N >(std::declval< ::nlohmann::detail::iteration_proxy_value< IteratorType > >())) type
Definition: json.hpp:5695
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2117
v1d & operator+=(v1d &a, cv1d &b)
Definition: Tools.cpp:29
v1d operator-(v1d a, double &b)
Definition: Tools.cpp:17
@ pos
Definition: Typedefs.h:19
v1d operator+(v1d a, double b)
Definition: Tools.cpp:13
uint d
int N
std::string decode(std::string const &encoded_string)
Definition: base64.hpp:89
type
The type the bitset is encoded with.
Definition: bitset.hpp:44
C const & container(std::queue< T, C > const &queue)
Allows access to the protected container in queue.
Definition: queue.hpp:48
CEREAL_SIZE_TYPE size_type
The size type used by cereal.
Definition: helpers.hpp:61
detail namespace with internal helper functions
Definition: json.hpp:260
typename std::enable_if< B, T >::type enable_if_t
Definition: json.hpp:3225
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
Definition: json.hpp:15537
Target reinterpret_bits(const Source source)
Definition: json.hpp:14757
boundaries compute_boundaries(FloatType value)
Definition: json.hpp:14898
int find_largest_pow10(const std::uint32_t n, std::uint32_t &pow10)
Definition: json.hpp:15201
constexpr int kGamma
Definition: json.hpp:15021
void grisu2_round(char *buf, int len, std::uint64_t dist, std::uint64_t delta, std::uint64_t rest, std::uint64_t ten_k)
Definition: json.hpp:15255
void grisu2_digit_gen(char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
Definition: json.hpp:15296
JSON_HEDLEY_RETURNS_NON_NULL char * format_buffer(char *buf, int len, int decimal_exponent, int min_exp, int max_exp)
prettify v = buf * 10^decimal_exponent
Definition: json.hpp:15689
constexpr int kAlpha
Definition: json.hpp:15020
JSON_HEDLEY_RETURNS_NON_NULL char * append_exponent(char *buf, int e)
appends a decimal representation of e to buf
Definition: json.hpp:15637
cached_power get_cached_power_for_binary_exponent(int e)
Definition: json.hpp:15037
typename std::enable_if< B, T >::type enable_if_t
Definition: json.hpp:3042
typename T::reference reference_t
Definition: json.hpp:3454
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition: json.hpp:144
static void unescape(std::string &s)
string unescaping as described in RFC 6901 (Sect. 4)
Definition: json.hpp:2559
decltype(T::from_json(std::declval< Args >()...)) from_json_function
Definition: json.hpp:3466
void to_json(BasicJsonType &j, T b) noexcept
Definition: json.hpp:4580
value_t
the JSON type enumeration
Definition: json.hpp:118
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)
void from_json(const BasicJsonType &j, typename std::nullptr_t &n)
Definition: json.hpp:3785
make_index_sequence< sizeof...(Ts)> index_sequence_for
Definition: json.hpp:3146
decltype(std::declval< T & >().parse_error(std::declval< std::size_t >(), std::declval< const std::string & >(), std::declval< const Exception & >())) parse_error_function_t
Definition: json.hpp:7983
typename T::pointer pointer_t
Definition: json.hpp:3451
decltype(std::declval< T & >().string(std::declval< String & >())) string_function_t
Definition: json.hpp:7956
void from_json_tuple_impl(const BasicJsonType &j, Tuple &t, index_sequence< Idx... >)
Definition: json.hpp:4091
std::function< bool(int, parse_event_t, BasicJsonType &)> parser_callback_t
Definition: json.hpp:10569
parse_event_t
Definition: json.hpp:10552
@ value
the parser finished reading a JSON value
@ key
the parser read a key of a value in an object
@ array_end
the parser read ] and finished processing a JSON array
@ array_start
the parser read [ and started to process a JSON array
@ object_start
the parser read { and started to process a JSON object
@ object_end
the parser read } and finished processing a JSON object
typename T::difference_type difference_type_t
Definition: json.hpp:3448
typename detector< nonesuch, void, Op, Args... >::type detected_t
Definition: json.hpp:3293
void int_to_string(string_type &target, std::size_t value)
Definition: json.hpp:4194
void from_json_array_impl(const BasicJsonType &j, typename BasicJsonType::array_t &arr, priority_tag< 3 >)
Definition: json.hpp:3933
integer_sequence< size_t, Ints... > index_sequence
Definition: json.hpp:3084
decltype(std::declval< T & >().key(std::declval< String & >())) key_function_t
Definition: json.hpp:7968
decltype(std::declval< T & >().boolean(std::declval< bool >())) boolean_function_t
Definition: json.hpp:7940
decltype(std::declval< T & >().binary(std::declval< Binary & >())) binary_function_t
Definition: json.hpp:7960
decltype(std::declval< T & >().number_integer(std::declval< Integer >())) number_integer_function_t
Definition: json.hpp:7944
void to_json_tuple_impl(BasicJsonType &j, const Tuple &t, index_sequence< Idx... >)
Definition: json.hpp:4703
std::is_convertible< detected_t< Op, Args... >, To > is_detected_convertible
Definition: json.hpp:3306
typename std::remove_cv< typename std::remove_reference< T >::type >::type uncvref_t
Definition: json.hpp:3028
cbor_tag_handler_t
how to treat CBOR tags
Definition: json.hpp:8082
@ error
throw a parse_error exception in case of a tag
error_handler_t
how to treat decoding errors
Definition: json.hpp:15845
@ strict
throw a type_error exception in case of invalid UTF-8
@ ignore
ignore invalid UTF-8 sequences
@ replace
replace invalid UTF-8 sequences with U+FFFD
decltype(std::declval< T & >().start_object(std::declval< std::size_t >())) start_object_function_t
Definition: json.hpp:7964
typename T::key_type key_type_t
Definition: json.hpp:3442
std::size_t combine(std::size_t seed, std::size_t h) noexcept
Definition: json.hpp:4968
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition: json.hpp:4986
JSON_HEDLEY_RETURNS_NON_NULL char * to_chars(char *first, const char *last, FloatType value)
generates a decimal representation of the floating-point number value in [first, last).
Definition: json.hpp:15774
typename utility_internal::Gen< T, N >::type make_integer_sequence
Definition: json.hpp:3130
decltype(std::declval< T & >().number_unsigned(std::declval< Unsigned >())) number_unsigned_function_t
Definition: json.hpp:7948
std::is_same< Expected, detected_t< Op, Args... > > is_detected_exact
Definition: json.hpp:3302
typename detected_or< Default, Op, Args... >::type detected_or_t
Definition: json.hpp:3299
decltype(std::declval< T & >().start_array(std::declval< std::size_t >())) start_array_function_t
Definition: json.hpp:7975
void get_arithmetic_value(const BasicJsonType &j, ArithmeticType &val)
Definition: json.hpp:3799
typename detector< nonesuch, void, Op, Args... >::value_t is_detected
Definition: json.hpp:3290
typename make_void< Ts... >::type void_t
Definition: json.hpp:3193
make_integer_sequence< size_t, N > make_index_sequence
Definition: json.hpp:3138
std::shared_ptr< output_adapter_protocol< CharType > > output_adapter_t
a type to simplify interfaces
Definition: json.hpp:13020
typename T::mapped_type mapped_type_t
Definition: json.hpp:3439
std::string escape(std::string s)
string escaping as described in RFC 6901 (Sect. 4)
Definition: json.hpp:2545
typename T::iterator iterator_t
Definition: json.hpp:3460
input_format_t
the supported input formats
Definition: json.hpp:5119
void to_json(BasicJsonType &j, const T &b)
Definition: json.hpp:4697
decltype(std::declval< T >().template get< U >()) get_template_function
Definition: json.hpp:3469
decltype(input_adapter(std::declval< const char * >(), std::declval< const char * >())) contiguous_bytes_input_adapter
Definition: json.hpp:5518
decltype(std::declval< T & >().null()) null_function_t
Definition: json.hpp:7936
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Definition: json.hpp:4317
void replace_substring(std::string &s, const std::string &f, const std::string &t)
replace all occurrences of a substring by another string
Definition: json.hpp:2527
iterator_input_adapter_factory< IteratorType >::adapter_type input_adapter(IteratorType first, IteratorType last)
Definition: json.hpp:5463
typename T::iterator_category iterator_category_t
Definition: json.hpp:3457
static bool little_endianess(int num=1) noexcept
determine system byte order
Definition: json.hpp:8094
decltype(std::declval< T & >().number_float(std::declval< Float >(), std::declval< const String & >())) number_float_function_t
Definition: json.hpp:7952
decltype(std::declval< T & >().end_array()) end_array_function_t
Definition: json.hpp:7978
void from_json(const BasicJsonType &j, std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > &m)
Definition: json.hpp:4125
decltype(std::declval< T & >().end_object()) end_object_function_t
Definition: json.hpp:7971
decltype(T::to_json(std::declval< Args >()...)) to_json_function
Definition: json.hpp:3463
typename T::value_type value_type_t
Definition: json.hpp:3445
namespace for Niels Lohmann
Definition: json.hpp:86
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:25693
std::basic_string< PUGIXML_CHAR, std::char_traits< PUGIXML_CHAR >, std::allocator< PUGIXML_CHAR > > string_t
Definition: pugixml.hpp:141
Definition: json.hpp:5678
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.hpp:25399
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1181
const CharType(& source)[N]
Definition: pointer.h:1204
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
PUGI_IMPL_FN void reverse(I begin, I end)
Definition: pugixml.cpp:7615
PUGI_IMPL_FN bool is_little_endian()
Definition: pugixml.cpp:1931
signed short int16_t
Definition: stdint.h:122
unsigned short uint16_t
Definition: stdint.h:125
signed __int64 int64_t
Definition: stdint.h:135
unsigned int uint32_t
Definition: stdint.h:126
signed int int32_t
Definition: stdint.h:123
unsigned char uint8_t
Definition: stdint.h:124
unsigned __int64 uint64_t
Definition: stdint.h:136
signed char int8_t
Definition: stdint.h:121
namespace for Niels Lohmann
Definition: json.hpp:6181
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:13619
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:13621
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:13617
Definition: pugixml.cpp:7582
default JSONSerializer template argument
Definition: json.hpp:4740
static auto to_json(BasicJsonType &j, ValueType &&val) noexcept(noexcept(::nlohmann::to_json(j, std::forward< ValueType >(val)))) -> decltype(::nlohmann::to_json(j, std::forward< ValueType >(val)), void())
convert any value type to a JSON value
Definition: json.hpp:4768
static auto from_json(BasicJsonType &&j, ValueType &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:4751
Definition: json.hpp:3764
Definition: json.hpp:3763
Definition: json.hpp:3277
Default type
Definition: json.hpp:3279
std::false_type value_t
Definition: json.hpp:3278
Definition: json.hpp:14885
diyfp plus
Definition: json.hpp:14888
diyfp w
Definition: json.hpp:14886
diyfp minus
Definition: json.hpp:14887
std::uint64_t f
Definition: json.hpp:15025
int k
Definition: json.hpp:15027
int e
Definition: json.hpp:15026
Definition: json.hpp:14767
static constexpr int kPrecision
Definition: json.hpp:14768
static diyfp normalize(diyfp x) noexcept
normalize x such that the significand is >= 2^(q-1)
Definition: json.hpp:14856
static diyfp normalize_to(const diyfp &x, const int target_exponent) noexcept
normalize x such that the result has the exponent E
Definition: json.hpp:14873
static diyfp mul(const diyfp &x, const diyfp &y) noexcept
returns x * y
Definition: json.hpp:14791
constexpr diyfp(std::uint64_t f_, int e_) noexcept
Definition: json.hpp:14773
int e
Definition: json.hpp:14771
std::uint64_t f
Definition: json.hpp:14770
static diyfp sub(const diyfp &x, const diyfp &y) noexcept
returns x - y
Definition: json.hpp:14779
static void construct(BasicJsonType &j, const CompatibleArrayType &arr)
Definition: json.hpp:4499
static void construct(BasicJsonType &j, const std::valarray< T > &arr)
Definition: json.hpp:4525
static void construct(BasicJsonType &j, const std::vector< bool > &arr)
Definition: json.hpp:4510
static void construct(BasicJsonType &j, typename BasicJsonType::array_t &&arr)
Definition: json.hpp:4488
static void construct(BasicJsonType &j, const typename BasicJsonType::array_t &arr)
Definition: json.hpp:4479
static void construct(BasicJsonType &j, const typename BasicJsonType::binary_t &b)
Definition: json.hpp:4423
static void construct(BasicJsonType &j, typename BasicJsonType::binary_t &&b)
Definition: json.hpp:4431
static void construct(BasicJsonType &j, typename BasicJsonType::boolean_t b) noexcept
Definition: json.hpp:4381
static void construct(BasicJsonType &j, typename BasicJsonType::number_float_t val) noexcept
Definition: json.hpp:4443
static void construct(BasicJsonType &j, typename BasicJsonType::number_integer_t val) noexcept
Definition: json.hpp:4467
static void construct(BasicJsonType &j, typename BasicJsonType::number_unsigned_t val) noexcept
Definition: json.hpp:4455
static void construct(BasicJsonType &j, typename BasicJsonType::object_t &&obj)
Definition: json.hpp:4552
static void construct(BasicJsonType &j, const typename BasicJsonType::object_t &obj)
Definition: json.hpp:4543
static void construct(BasicJsonType &j, const CompatibleObjectType &obj)
Definition: json.hpp:4562
static void construct(BasicJsonType &j, typename BasicJsonType::string_t &&s)
Definition: json.hpp:4401
static void construct(BasicJsonType &j, const CompatibleStringType &str)
Definition: json.hpp:4411
static void construct(BasicJsonType &j, const typename BasicJsonType::string_t &s)
Definition: json.hpp:4393
Definition: json.hpp:4143
auto operator()(const BasicJsonType &j, T &val) const noexcept(noexcept(from_json(j, val))) -> decltype(from_json(j, val), void())
Definition: json.hpp:4145
typename BasicJsonType::template json_serializer< T, void > serializer
Definition: json.hpp:3489
Definition: json.hpp:3473
typename BasicJsonType::template json_serializer< T, void > serializer
Definition: json.hpp:3504
typename BasicJsonType::template json_serializer< T, void > serializer
Definition: json.hpp:3519
Definition: json.hpp:3514
Definition: json.hpp:3070
T value_type
Definition: json.hpp:3071
static constexpr std::size_t size() noexcept
Definition: json.hpp:3072
an iterator value
Definition: json.hpp:11160
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:11166
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:11164
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:11162
Definition: json.hpp:3416
Definition: json.hpp:3760
Definition: json.hpp:3554
Definition: json.hpp:3481
static constexpr bool value
Definition: json.hpp:3482
typename std::iterator_traits< T >::value_type value_type
Definition: json.hpp:5440
Definition: json.hpp:3532
Definition: json.hpp:3429
typename BasicJsonType::string_t string_t
Definition: json.hpp:8026
typename BasicJsonType::exception exception_t
Definition: json.hpp:8028
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:8023
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:8025
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:8027
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:8024
Definition: json.hpp:7987
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:7994
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:7993
typename BasicJsonType::exception exception_t
Definition: json.hpp:7997
static constexpr bool value
Definition: json.hpp:8000
typename BasicJsonType::number_integer_t number_integer_t
Definition: json.hpp:7992
typename BasicJsonType::string_t string_t
Definition: json.hpp:7995
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:7996
typename std::iterator_traits< iterator_type >::value_type char_type
Definition: json.hpp:5451
typename std::iterator_traits< iterator_type >::value_type char_type
Definition: json.hpp:5428
static adapter_type create(IteratorType first, IteratorType last)
Definition: json.hpp:5431
iterator_input_adapter< iterator_type > adapter_type
Definition: json.hpp:5429
IteratorType iterator_type
Definition: json.hpp:5427
std::random_access_iterator_tag iterator_category
Definition: json.hpp:3236
Definition: json.hpp:3224
Definition: json.hpp:3205
Definition: json.hpp:3190
void type
Definition: json.hpp:3191
Definition: json.hpp:3263
nonesuch(nonesuch const &)=delete
void operator=(nonesuch &&)=delete
nonesuch(nonesuch const &&)=delete
void operator=(nonesuch const &)=delete
abstract output adapter interface
Definition: json.hpp:13006
virtual void write_characters(const CharType *s, std::size_t length)=0
virtual void write_character(CharType c)=0
output_adapter_protocol(output_adapter_protocol &&) noexcept=default
output_adapter_protocol(const output_adapter_protocol &)=default
struct to capture the start position of the current token
Definition: json.hpp:2579
std::size_t lines_read
the number of lines read
Definition: json.hpp:2585
std::size_t chars_read_current_line
the number of characters read in the current line
Definition: json.hpp:2583
std::size_t chars_read_total
the total number of characters read
Definition: json.hpp:2581
Definition: json.hpp:3154
Definition: json.hpp:3153
Definition: json.hpp:3159
static constexpr T value
Definition: json.hpp:3160
Definition: json.hpp:4715
auto operator()(BasicJsonType &j, T &&val) const noexcept(noexcept(to_json(j, std::forward< T >(val)))) -> decltype(to_json(j, std::forward< T >(val)), void())
Definition: json.hpp:4717
typename Extend< typename Gen< T, N/2 >::type, N/2, N % 2 >::type type
Definition: json.hpp:3111
static void fill_buffer(BaseInputAdapter &input, std::array< std::char_traits< char >::int_type, 4 > &utf8_bytes, size_t &utf8_bytes_index, size_t &utf8_bytes_filled)
Definition: json.hpp:5320
static void fill_buffer(BaseInputAdapter &input, std::array< std::char_traits< char >::int_type, 4 > &utf8_bytes, size_t &utf8_bytes_index, size_t &utf8_bytes_filled)
Definition: json.hpp:5262
SAX interface.
Definition: json.hpp:5600
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:5601
typename BasicJsonType::binary_t binary_t
Definition: json.hpp:5605
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:5602
virtual bool binary(binary_t &val)=0
a binary string was read
typename BasicJsonType::number_float_t number_float_t
Definition: json.hpp:5603
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:5604
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
Definition: json.hpp:16795
std::pair< iterator, bool > insert(const value_type &value)
Definition: json.hpp:16936
ordered_map(std::initializer_list< T > init, const Allocator &alloc=Allocator())
Definition: json.hpp:16810
std::vector< std::pair< const Key, T >, Allocator > Container
Definition: json.hpp:16798
T mapped_type
Definition: json.hpp:16797
iterator find(const Key &key)
Definition: json.hpp:16907
iterator erase(iterator pos)
Definition: json.hpp:16881
void insert(InputIt first, InputIt last)
Definition: json.hpp:16954
std::pair< iterator, bool > emplace(const key_type &key, T &&t)
Definition: json.hpp:16813
const_iterator find(const Key &key) const
Definition: json.hpp:16919
std::pair< iterator, bool > insert(value_type &&value)
Definition: json.hpp:16931
Key key_type
Definition: json.hpp:16796
size_type erase(const Key &key)
Definition: json.hpp:16862
const T & operator[](const Key &key) const
Definition: json.hpp:16831
ordered_map(const Allocator &alloc=Allocator())
Definition: json.hpp:16806
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:16951
const T & at(const Key &key) const
Definition: json.hpp:16849
ordered_map(It first, It last, const Allocator &alloc=Allocator())
Definition: json.hpp:16808
T & at(const Key &key)
Definition: json.hpp:16836
T & operator[](const Key &key)
Definition: json.hpp:16826
size_type count(const Key &key) const
Definition: json.hpp:16895
std::size_t operator()(const nlohmann::json &j) const
return a hash value for a JSON object
Definition: json.hpp:25716
bool operator()(nlohmann::detail::value_t lhs, nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition: json.hpp:25732
#define const
Definition: zconf.h:233