30#ifndef INCLUDE_NLOHMANN_JSON_HPP_
31#define INCLUDE_NLOHMANN_JSON_HPP_
33#define NLOHMANN_JSON_VERSION_MAJOR 3
34#define NLOHMANN_JSON_VERSION_MINOR 7
35#define NLOHMANN_JSON_VERSION_PATCH 3
42#include <initializer_list>
62#include <forward_list>
68#include <unordered_map>
99 constexpr operator size_t()
const
125#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 11)
126#if defined(JSON_HEDLEY_VERSION)
127 #undef JSON_HEDLEY_VERSION
129#define JSON_HEDLEY_VERSION 11
131#if defined(JSON_HEDLEY_STRINGIFY_EX)
132 #undef JSON_HEDLEY_STRINGIFY_EX
134#define JSON_HEDLEY_STRINGIFY_EX(x) #x
136#if defined(JSON_HEDLEY_STRINGIFY)
137 #undef JSON_HEDLEY_STRINGIFY
139#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
141#if defined(JSON_HEDLEY_CONCAT_EX)
142 #undef JSON_HEDLEY_CONCAT_EX
144#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
146#if defined(JSON_HEDLEY_CONCAT)
147 #undef JSON_HEDLEY_CONCAT
149#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
151#if defined(JSON_HEDLEY_VERSION_ENCODE)
152 #undef JSON_HEDLEY_VERSION_ENCODE
154#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
156#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
157 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
159#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
161#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
162 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
164#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
166#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
167 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
169#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
171#if defined(JSON_HEDLEY_GNUC_VERSION)
172 #undef JSON_HEDLEY_GNUC_VERSION
174#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
175 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
176#elif defined(__GNUC__)
177 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
180#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
181 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
183#if defined(JSON_HEDLEY_GNUC_VERSION)
184 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
186 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
189#if defined(JSON_HEDLEY_MSVC_VERSION)
190 #undef JSON_HEDLEY_MSVC_VERSION
192#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000)
193 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
194#elif defined(_MSC_FULL_VER)
195 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
196#elif defined(_MSC_VER)
197 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
200#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
201 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
203#if !defined(_MSC_VER)
204 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
205#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
206 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
207#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
208 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
210 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
213#if defined(JSON_HEDLEY_INTEL_VERSION)
214 #undef JSON_HEDLEY_INTEL_VERSION
216#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE)
217 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
218#elif defined(__INTEL_COMPILER)
219 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
222#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
223 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
225#if defined(JSON_HEDLEY_INTEL_VERSION)
226 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
228 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
231#if defined(JSON_HEDLEY_PGI_VERSION)
232 #undef JSON_HEDLEY_PGI_VERSION
234#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
235 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
238#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
239 #undef JSON_HEDLEY_PGI_VERSION_CHECK
241#if defined(JSON_HEDLEY_PGI_VERSION)
242 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
244 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
247#if defined(JSON_HEDLEY_SUNPRO_VERSION)
248 #undef JSON_HEDLEY_SUNPRO_VERSION
250#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
251 #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)
252#elif defined(__SUNPRO_C)
253 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
254#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
255 #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)
256#elif defined(__SUNPRO_CC)
257 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
260#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
261 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
263#if defined(JSON_HEDLEY_SUNPRO_VERSION)
264 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
266 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
269#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
270 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
272#if defined(__EMSCRIPTEN__)
273 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
276#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
277 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
279#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
280 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
282 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
285#if defined(JSON_HEDLEY_ARM_VERSION)
286 #undef JSON_HEDLEY_ARM_VERSION
288#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
289 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
290#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
291 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
294#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
295 #undef JSON_HEDLEY_ARM_VERSION_CHECK
297#if defined(JSON_HEDLEY_ARM_VERSION)
298 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
300 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
303#if defined(JSON_HEDLEY_IBM_VERSION)
304 #undef JSON_HEDLEY_IBM_VERSION
306#if defined(__ibmxl__)
307 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
308#elif defined(__xlC__) && defined(__xlC_ver__)
309 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
310#elif defined(__xlC__)
311 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
314#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
315 #undef JSON_HEDLEY_IBM_VERSION_CHECK
317#if defined(JSON_HEDLEY_IBM_VERSION)
318 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
320 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
323#if defined(JSON_HEDLEY_TI_VERSION)
324 #undef JSON_HEDLEY_TI_VERSION
326#if defined(__TI_COMPILER_VERSION__)
327 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
330#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
331 #undef JSON_HEDLEY_TI_VERSION_CHECK
333#if defined(JSON_HEDLEY_TI_VERSION)
334 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
336 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
339#if defined(JSON_HEDLEY_CRAY_VERSION)
340 #undef JSON_HEDLEY_CRAY_VERSION
343 #if defined(_RELEASE_PATCHLEVEL)
344 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
346 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
350#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
351 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
353#if defined(JSON_HEDLEY_CRAY_VERSION)
354 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
356 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
359#if defined(JSON_HEDLEY_IAR_VERSION)
360 #undef JSON_HEDLEY_IAR_VERSION
362#if defined(__IAR_SYSTEMS_ICC__)
364 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
366 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(VER / 100, __VER__ % 100, 0)
370#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
371 #undef JSON_HEDLEY_IAR_VERSION_CHECK
373#if defined(JSON_HEDLEY_IAR_VERSION)
374 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
376 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
379#if defined(JSON_HEDLEY_TINYC_VERSION)
380 #undef JSON_HEDLEY_TINYC_VERSION
382#if defined(__TINYC__)
383 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
386#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
387 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
389#if defined(JSON_HEDLEY_TINYC_VERSION)
390 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
392 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
395#if defined(JSON_HEDLEY_DMC_VERSION)
396 #undef JSON_HEDLEY_DMC_VERSION
399 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
402#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
403 #undef JSON_HEDLEY_DMC_VERSION_CHECK
405#if defined(JSON_HEDLEY_DMC_VERSION)
406 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
408 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
411#if defined(JSON_HEDLEY_COMPCERT_VERSION)
412 #undef JSON_HEDLEY_COMPCERT_VERSION
414#if defined(__COMPCERT_VERSION__)
415 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
418#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
419 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
421#if defined(JSON_HEDLEY_COMPCERT_VERSION)
422 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
424 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
427#if defined(JSON_HEDLEY_PELLES_VERSION)
428 #undef JSON_HEDLEY_PELLES_VERSION
431 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
434#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
435 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
437#if defined(JSON_HEDLEY_PELLES_VERSION)
438 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
440 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
443#if defined(JSON_HEDLEY_GCC_VERSION)
444 #undef JSON_HEDLEY_GCC_VERSION
447 defined(JSON_HEDLEY_GNUC_VERSION) && \
448 !defined(__clang__) && \
449 !defined(JSON_HEDLEY_INTEL_VERSION) && \
450 !defined(JSON_HEDLEY_PGI_VERSION) && \
451 !defined(JSON_HEDLEY_ARM_VERSION) && \
452 !defined(JSON_HEDLEY_TI_VERSION) && \
453 !defined(__COMPCERT__)
454 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
457#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
458 #undef JSON_HEDLEY_GCC_VERSION_CHECK
460#if defined(JSON_HEDLEY_GCC_VERSION)
461 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
463 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
466#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
467 #undef JSON_HEDLEY_HAS_ATTRIBUTE
469#if defined(__has_attribute)
470 #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
472 #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
475#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
476 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
478#if defined(__has_attribute)
479 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute)
481 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
484#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
485 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
487#if defined(__has_attribute)
488 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute)
490 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
493#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
494 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
497 defined(__has_cpp_attribute) && \
498 defined(__cplusplus) && \
499 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
500 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
502 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
505#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
506 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
508#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
509 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
511 !defined(JSON_HEDLEY_PGI_VERSION) && \
512 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
513 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
514 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
516 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
519#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
520 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
522#if defined(__has_cpp_attribute) && defined(__cplusplus)
523 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
525 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
528#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
529 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
531#if defined(__has_cpp_attribute) && defined(__cplusplus)
532 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
534 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
537#if defined(JSON_HEDLEY_HAS_BUILTIN)
538 #undef JSON_HEDLEY_HAS_BUILTIN
540#if defined(__has_builtin)
541 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
543 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
546#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
547 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
549#if defined(__has_builtin)
550 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
552 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
555#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
556 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
558#if defined(__has_builtin)
559 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
561 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
564#if defined(JSON_HEDLEY_HAS_FEATURE)
565 #undef JSON_HEDLEY_HAS_FEATURE
567#if defined(__has_feature)
568 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
570 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
573#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
574 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
576#if defined(__has_feature)
577 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
579 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
582#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
583 #undef JSON_HEDLEY_GCC_HAS_FEATURE
585#if defined(__has_feature)
586 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
588 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
591#if defined(JSON_HEDLEY_HAS_EXTENSION)
592 #undef JSON_HEDLEY_HAS_EXTENSION
594#if defined(__has_extension)
595 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
597 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
600#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
601 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
603#if defined(__has_extension)
604 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
606 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
609#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
610 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
612#if defined(__has_extension)
613 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
615 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
618#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
619 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
621#if defined(__has_declspec_attribute)
622 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
624 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
627#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
628 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
630#if defined(__has_declspec_attribute)
631 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
633 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
636#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
637 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
639#if defined(__has_declspec_attribute)
640 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
642 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
645#if defined(JSON_HEDLEY_HAS_WARNING)
646 #undef JSON_HEDLEY_HAS_WARNING
648#if defined(__has_warning)
649 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
651 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
654#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
655 #undef JSON_HEDLEY_GNUC_HAS_WARNING
657#if defined(__has_warning)
658 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
660 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
663#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
664 #undef JSON_HEDLEY_GCC_HAS_WARNING
666#if defined(__has_warning)
667 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
669 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
674#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
675 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
677#if defined(__cplusplus) && JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
678# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
679 JSON_HEDLEY_DIAGNOSTIC_PUSH \
680 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
682 JSON_HEDLEY_DIAGNOSTIC_POP
684# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
688 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
689 defined(__clang__) || \
690 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
691 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
692 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
693 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
694 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
695 JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) || \
696 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
697 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
698 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
699 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
700 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
701#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
702 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
704 #define JSON_HEDLEY_PRAGMA(value)
707#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
708 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
710#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
711 #undef JSON_HEDLEY_DIAGNOSTIC_POP
713#if defined(__clang__)
714 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
715 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
716#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
717 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
718 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
719#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
720 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
721 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
722#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
723 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
724 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
725#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
726 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
727 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
728#elif JSON_HEDLEY_TI_VERSION_CHECK(8,1,0)
729 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
730 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
731#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
732 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
733 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
735 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
736 #define JSON_HEDLEY_DIAGNOSTIC_POP
739#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
740 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
742#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
743 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
744#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
745 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
746#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
747 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
748#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
749 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
750#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
751 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
752#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
753 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
754#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
755 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
756#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
757 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
758#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
759 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
760#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
761 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
763 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
766#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
767 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
769#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
770 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
771#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
772 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
773#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
774 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
775#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
776 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
777#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
778 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
779#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
780 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
781#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
782 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
784 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
787#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
788 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
790#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
791 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
792#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
793 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
794#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
795 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
796#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
797 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
798#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
799 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
800#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
801 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
802#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
803 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
805 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
808#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
809 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
811#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
812 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
813#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
814 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
815#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
816 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
818 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
821#if defined(JSON_HEDLEY_DEPRECATED)
822 #undef JSON_HEDLEY_DEPRECATED
824#if defined(JSON_HEDLEY_DEPRECATED_FOR)
825 #undef JSON_HEDLEY_DEPRECATED_FOR
827#if defined(__cplusplus) && (__cplusplus >= 201402L)
828 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
829 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
831 JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) || \
832 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
833 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
834 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
835 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
836 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
837 JSON_HEDLEY_TI_VERSION_CHECK(8,3,0)
838 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
839 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
841 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
842 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
843 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
844 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
845 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
846 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
847 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
848#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0)
849 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
850 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
852 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
853 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0)
854 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
855 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
856#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
857 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
858 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
860 #define JSON_HEDLEY_DEPRECATED(since)
861 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
864#if defined(JSON_HEDLEY_UNAVAILABLE)
865 #undef JSON_HEDLEY_UNAVAILABLE
868 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
869 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
870 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
871 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
873 #define JSON_HEDLEY_UNAVAILABLE(available_since)
876#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
877 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
879#if defined(__cplusplus) && (__cplusplus >= 201703L)
880 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
882 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
883 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
884 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
885 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
886 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
887 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
888 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
889 #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
890#elif defined(_Check_return_)
891 #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
893 #define JSON_HEDLEY_WARN_UNUSED_RESULT
896#if defined(JSON_HEDLEY_SENTINEL)
897 #undef JSON_HEDLEY_SENTINEL
900 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
901 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
902 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
903 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0)
904 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
906 #define JSON_HEDLEY_SENTINEL(position)
909#if defined(JSON_HEDLEY_NO_RETURN)
910 #undef JSON_HEDLEY_NO_RETURN
912#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
913 #define JSON_HEDLEY_NO_RETURN __noreturn
914#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
915 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
916#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
917 #define JSON_HEDLEY_NO_RETURN _Noreturn
918#elif defined(__cplusplus) && (__cplusplus >= 201103L)
919 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
921 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
922 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
923 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
924 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
925 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
926 JSON_HEDLEY_TI_VERSION_CHECK(18,0,0) || \
927 (JSON_HEDLEY_TI_VERSION_CHECK(17,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
928 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
929#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
930 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
931#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
932 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
933#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
934 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
935#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
936 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
937#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
938 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
940 #define JSON_HEDLEY_NO_RETURN
943#if defined(JSON_HEDLEY_NO_ESCAPE)
944 #undef JSON_HEDLEY_NO_ESCAPE
946#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
947 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
949 #define JSON_HEDLEY_NO_ESCAPE
952#if defined(JSON_HEDLEY_UNREACHABLE)
953 #undef JSON_HEDLEY_UNREACHABLE
955#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
956 #undef JSON_HEDLEY_UNREACHABLE_RETURN
959 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
960 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
961 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
962 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5)
963 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
964#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
965 #define JSON_HEDLEY_UNREACHABLE() __assume(0)
966#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0)
967 #if defined(__cplusplus)
968 #define JSON_HEDLEY_UNREACHABLE() std::_nassert(0)
970 #define JSON_HEDLEY_UNREACHABLE() _nassert(0)
972 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value
973#elif defined(EXIT_FAILURE)
974 #define JSON_HEDLEY_UNREACHABLE() abort()
976 #define JSON_HEDLEY_UNREACHABLE()
977 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value
979#if !defined(JSON_HEDLEY_UNREACHABLE_RETURN)
980 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
983#if defined(JSON_HEDLEY_ASSUME)
984 #undef JSON_HEDLEY_ASSUME
987 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
988 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
989 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
990#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
991 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
992#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0)
993 #if defined(__cplusplus)
994 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
996 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
999 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && !defined(JSON_HEDLEY_ARM_VERSION)) || \
1000 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1001 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1002 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5)
1003 #define JSON_HEDLEY_ASSUME(expr) ((void) ((expr) ? 1 : (__builtin_unreachable(), 1)))
1005 #define JSON_HEDLEY_ASSUME(expr) ((void) (expr))
1008JSON_HEDLEY_DIAGNOSTIC_PUSH
1009#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1010 #pragma clang diagnostic ignored "-Wpedantic"
1012#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1013 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1015#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1016 #if defined(__clang__)
1017 #pragma clang diagnostic ignored "-Wvariadic-macros"
1018 #elif defined(JSON_HEDLEY_GCC_VERSION)
1019 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1022#if defined(JSON_HEDLEY_NON_NULL)
1023 #undef JSON_HEDLEY_NON_NULL
1026 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1027 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1028 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1029 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1030 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1032 #define JSON_HEDLEY_NON_NULL(...)
1034JSON_HEDLEY_DIAGNOSTIC_POP
1036#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1037 #undef JSON_HEDLEY_PRINTF_FORMAT
1039#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1040 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1041#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1042 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1044 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1045 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1046 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1047 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1048 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1049 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
1050 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1051 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1052#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1053 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1055 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1058#if defined(JSON_HEDLEY_CONSTEXPR)
1059 #undef JSON_HEDLEY_CONSTEXPR
1061#if defined(__cplusplus)
1062 #if __cplusplus >= 201103L
1063 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1066#if !defined(JSON_HEDLEY_CONSTEXPR)
1067 #define JSON_HEDLEY_CONSTEXPR
1070#if defined(JSON_HEDLEY_PREDICT)
1071 #undef JSON_HEDLEY_PREDICT
1073#if defined(JSON_HEDLEY_LIKELY)
1074 #undef JSON_HEDLEY_LIKELY
1076#if defined(JSON_HEDLEY_UNLIKELY)
1077 #undef JSON_HEDLEY_UNLIKELY
1079#if defined(JSON_HEDLEY_UNPREDICTABLE)
1080 #undef JSON_HEDLEY_UNPREDICTABLE
1082#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1083 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable(!!(expr))
1086 JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) || \
1087 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0)
1088# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability(expr, value, probability)
1089# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1, probability)
1090# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0, probability)
1091# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1092# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1093#if !defined(JSON_HEDLEY_BUILTIN_UNPREDICTABLE)
1094 #define JSON_HEDLEY_BUILTIN_UNPREDICTABLE(expr) __builtin_expect_with_probability(!!(expr), 1, 0.5)
1097 JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) || \
1098 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1099 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1100 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1101 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1102 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1103 JSON_HEDLEY_TI_VERSION_CHECK(6,1,0) || \
1104 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27)
1105# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1106 (((probability) >= 0.9) ? __builtin_expect(!!(expr), (expected)) : (((void) (expected)), !!(expr)))
1107# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1109 JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability); \
1110 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1112# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1114 JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability); \
1115 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1117# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1118# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1120# define JSON_HEDLEY_PREDICT(expr, expected, probability) (((void) (expected)), !!(expr))
1121# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1122# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1123# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1124# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1126#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1127 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1130#if defined(JSON_HEDLEY_MALLOC)
1131 #undef JSON_HEDLEY_MALLOC
1134 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1135 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1136 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1137 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1138 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1139 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1140 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
1141 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1142 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1143#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1144 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1145#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0)
1146 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1148 #define JSON_HEDLEY_MALLOC
1151#if defined(JSON_HEDLEY_PURE)
1152 #undef JSON_HEDLEY_PURE
1155 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1156 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1157 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1158 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1159 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1160 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1161 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
1162 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1163 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1164 #define JSON_HEDLEY_PURE __attribute__((__pure__))
1165#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1166 #define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1167#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1168 #define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1170 #define JSON_HEDLEY_PURE
1173#if defined(JSON_HEDLEY_CONST)
1174 #undef JSON_HEDLEY_CONST
1177 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1178 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1179 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1180 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1181 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1182 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1183 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
1184 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1185 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1186 #define JSON_HEDLEY_CONST __attribute__((__const__))
1188 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1189 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1191 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1194#if defined(JSON_HEDLEY_RESTRICT)
1195 #undef JSON_HEDLEY_RESTRICT
1197#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1198 #define JSON_HEDLEY_RESTRICT restrict
1200 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1201 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1202 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1203 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1204 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1205 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1206 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
1207 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1208 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1210 #define JSON_HEDLEY_RESTRICT __restrict
1211#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1212 #define JSON_HEDLEY_RESTRICT _Restrict
1214 #define JSON_HEDLEY_RESTRICT
1217#if defined(JSON_HEDLEY_INLINE)
1218 #undef JSON_HEDLEY_INLINE
1221 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1222 (defined(__cplusplus) && (__cplusplus >= 199711L))
1223 #define JSON_HEDLEY_INLINE inline
1225 defined(JSON_HEDLEY_GCC_VERSION) || \
1226 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1227 #define JSON_HEDLEY_INLINE __inline__
1229 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1230 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1231 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
1232 #define JSON_HEDLEY_INLINE __inline
1234 #define JSON_HEDLEY_INLINE
1237#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1238 #undef JSON_HEDLEY_ALWAYS_INLINE
1241 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1242 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1243 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1244 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1245 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1246 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1247 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
1248 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1249 #define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1250#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0)
1251 #define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1252#elif JSON_HEDLEY_TI_VERSION_CHECK(7,0,0) && defined(__cplusplus)
1253 #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1254#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1255 #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1257 #define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1260#if defined(JSON_HEDLEY_NEVER_INLINE)
1261 #undef JSON_HEDLEY_NEVER_INLINE
1264 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1265 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1266 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1267 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1268 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1269 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1270 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
1271 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1272 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1273#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
1274 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1275#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1276 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1277#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1278 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1279#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1280 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1281#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1282 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1283#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1284 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1286 #define JSON_HEDLEY_NEVER_INLINE
1289#if defined(JSON_HEDLEY_PRIVATE)
1290 #undef JSON_HEDLEY_PRIVATE
1292#if defined(JSON_HEDLEY_PUBLIC)
1293 #undef JSON_HEDLEY_PUBLIC
1295#if defined(JSON_HEDLEY_IMPORT)
1296 #undef JSON_HEDLEY_IMPORT
1298#if defined(_WIN32) || defined(__CYGWIN__)
1299 #define JSON_HEDLEY_PRIVATE
1300 #define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1301 #define JSON_HEDLEY_IMPORT __declspec(dllimport)
1304 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1305 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1306 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1307 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1308 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1309 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1310 JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
1311 (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_EABI__) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1312 #define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1313 #define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1315 #define JSON_HEDLEY_PRIVATE
1316 #define JSON_HEDLEY_PUBLIC
1318 #define JSON_HEDLEY_IMPORT extern
1321#if defined(JSON_HEDLEY_NO_THROW)
1322 #undef JSON_HEDLEY_NO_THROW
1325 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1326 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1327 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1328 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1330 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1331 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1332 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1334 #define JSON_HEDLEY_NO_THROW
1337#if defined(JSON_HEDLEY_FALL_THROUGH)
1338 #undef JSON_HEDLEY_FALL_THROUGH
1340#if JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(fallthrough,7,0,0) && !defined(JSON_HEDLEY_PGI_VERSION)
1341 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1342#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1343 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1344#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1345 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1346#elif defined(__fallthrough)
1347 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1349 #define JSON_HEDLEY_FALL_THROUGH
1352#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
1353 #undef JSON_HEDLEY_RETURNS_NON_NULL
1356 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1357 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
1358 #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
1359#elif defined(_Ret_notnull_)
1360 #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
1362 #define JSON_HEDLEY_RETURNS_NON_NULL
1365#if defined(JSON_HEDLEY_ARRAY_PARAM)
1366 #undef JSON_HEDLEY_ARRAY_PARAM
1369 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1370 !defined(__STDC_NO_VLA__) && \
1371 !defined(__cplusplus) && \
1372 !defined(JSON_HEDLEY_PGI_VERSION) && \
1373 !defined(JSON_HEDLEY_TINYC_VERSION)
1374 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1376 #define JSON_HEDLEY_ARRAY_PARAM(name)
1379#if defined(JSON_HEDLEY_IS_CONSTANT)
1380 #undef JSON_HEDLEY_IS_CONSTANT
1382#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1383 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1387#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1388 #undef JSON_HEDLEY_IS_CONSTEXPR_
1391 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1392 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1393 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1394 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1395 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1396 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1397 JSON_HEDLEY_TI_VERSION_CHECK(6,1,0) || \
1398 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1399 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0)
1400 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1402#if !defined(__cplusplus)
1404 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1405 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1406 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1407 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1408 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1409 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1410 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1411#if defined(__INTPTR_TYPE__)
1412 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1415 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1418 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(JSON_HEDLEY_SUNPRO_VERSION) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1419 JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \
1420 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1421 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1422 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1423 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1424#if defined(__INTPTR_TYPE__)
1425 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1428 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1431 defined(JSON_HEDLEY_GCC_VERSION) || \
1432 defined(JSON_HEDLEY_INTEL_VERSION) || \
1433 defined(JSON_HEDLEY_TINYC_VERSION) || \
1434 defined(JSON_HEDLEY_TI_VERSION) || \
1436# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1440 ((void*) ((expr) * 0L) ) : \
1441((struct { char v[sizeof(void) * 2]; } *) 1) \
1447#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1448 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1449 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1451 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
1453 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1454 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
1456 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
1459#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
1460 #undef JSON_HEDLEY_BEGIN_C_DECLS
1462#if defined(JSON_HEDLEY_END_C_DECLS)
1463 #undef JSON_HEDLEY_END_C_DECLS
1465#if defined(JSON_HEDLEY_C_DECL)
1466 #undef JSON_HEDLEY_C_DECL
1468#if defined(__cplusplus)
1469 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
1470 #define JSON_HEDLEY_END_C_DECLS }
1471 #define JSON_HEDLEY_C_DECL extern "C"
1473 #define JSON_HEDLEY_BEGIN_C_DECLS
1474 #define JSON_HEDLEY_END_C_DECLS
1475 #define JSON_HEDLEY_C_DECL
1478#if defined(JSON_HEDLEY_STATIC_ASSERT)
1479 #undef JSON_HEDLEY_STATIC_ASSERT
1482 !defined(__cplusplus) && ( \
1483 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
1484 JSON_HEDLEY_HAS_FEATURE(c_static_assert) || \
1485 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
1486 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1487 defined(_Static_assert) \
1489# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
1491 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
1492 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
1493 (defined(__cplusplus) && JSON_HEDLEY_TI_VERSION_CHECK(8,3,0))
1494# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
1496# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
1499#if defined(JSON_HEDLEY_CONST_CAST)
1500 #undef JSON_HEDLEY_CONST_CAST
1502#if defined(__cplusplus)
1503# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1505 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1506 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1507 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1508# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1509 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1510 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1512 JSON_HEDLEY_DIAGNOSTIC_POP \
1515# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1518#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1519 #undef JSON_HEDLEY_REINTERPRET_CAST
1521#if defined(__cplusplus)
1522 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1524 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (*((T*) &(expr)))
1527#if defined(JSON_HEDLEY_STATIC_CAST)
1528 #undef JSON_HEDLEY_STATIC_CAST
1530#if defined(__cplusplus)
1531 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1533 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1536#if defined(JSON_HEDLEY_CPP_CAST)
1537 #undef JSON_HEDLEY_CPP_CAST
1539#if defined(__cplusplus)
1540 #define JSON_HEDLEY_CPP_CAST(T, expr) static_cast<T>(expr)
1542 #define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1545#if defined(JSON_HEDLEY_NULL)
1546 #undef JSON_HEDLEY_NULL
1548#if defined(__cplusplus)
1549 #if __cplusplus >= 201103L
1550 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
1552 #define JSON_HEDLEY_NULL NULL
1554 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
1557 #define JSON_HEDLEY_NULL NULL
1559 #define JSON_HEDLEY_NULL ((void*) 0)
1562#if defined(JSON_HEDLEY_MESSAGE)
1563 #undef JSON_HEDLEY_MESSAGE
1565#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1566# define JSON_HEDLEY_MESSAGE(msg) \
1567 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1568 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
1569 JSON_HEDLEY_PRAGMA(message msg) \
1570 JSON_HEDLEY_DIAGNOSTIC_POP
1572 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
1573 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1574# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
1575#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
1576# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
1577#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1578# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
1579#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
1580# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
1582# define JSON_HEDLEY_MESSAGE(msg)
1585#if defined(JSON_HEDLEY_WARNING)
1586 #undef JSON_HEDLEY_WARNING
1588#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1589# define JSON_HEDLEY_WARNING(msg) \
1590 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1591 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
1592 JSON_HEDLEY_PRAGMA(clang warning msg) \
1593 JSON_HEDLEY_DIAGNOSTIC_POP
1595 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
1596 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0)
1597# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
1598#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1599# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
1601# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
1604#if defined(JSON_HEDLEY_REQUIRE)
1605 #undef JSON_HEDLEY_REQUIRE
1607#if defined(JSON_HEDLEY_REQUIRE_MSG)
1608 #undef JSON_HEDLEY_REQUIRE_MSG
1610#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
1611# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
1612# define JSON_HEDLEY_REQUIRE(expr) \
1613 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1614 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
1615 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
1616 JSON_HEDLEY_DIAGNOSTIC_POP
1617# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
1618 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1619 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
1620 __attribute__((diagnose_if(!(expr), msg, "error"))) \
1621 JSON_HEDLEY_DIAGNOSTIC_POP
1623# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
1624# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
1627# define JSON_HEDLEY_REQUIRE(expr)
1628# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
1631#if defined(JSON_HEDLEY_FLAGS)
1632 #undef JSON_HEDLEY_FLAGS
1634#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum)
1635 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
1638#if defined(JSON_HEDLEY_FLAGS_CAST)
1639 #undef JSON_HEDLEY_FLAGS_CAST
1641#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
1642# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
1643 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1644 _Pragma("warning(disable:188)") \
1646 JSON_HEDLEY_DIAGNOSTIC_POP \
1649# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
1652#if defined(JSON_HEDLEY_EMPTY_BASES)
1653 #undef JSON_HEDLEY_EMPTY_BASES
1655#if JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)
1656 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
1658 #define JSON_HEDLEY_EMPTY_BASES
1663#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
1664 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
1666#if defined(__clang__)
1667 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
1669 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1672#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
1673 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
1675#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
1677#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
1678 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
1680#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
1682#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
1683 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
1685#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
1687#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
1688 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
1690#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
1692#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
1693 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
1695#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
1697#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
1698 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
1700#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
1702#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
1703 #undef JSON_HEDLEY_CLANG_HAS_WARNING
1705#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
1714#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
1715 #if defined(__clang__)
1716 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
1717 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
1719 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
1720 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
1721 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
1727#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
1728 #define JSON_HAS_CPP_17
1729 #define JSON_HAS_CPP_14
1730#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
1731 #define JSON_HAS_CPP_14
1735#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
1736 #pragma GCC diagnostic push
1737 #pragma GCC diagnostic ignored "-Wfloat-equal"
1741#if defined(__clang__)
1742 #pragma GCC diagnostic push
1743 #pragma GCC diagnostic ignored "-Wdocumentation"
1747#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
1748 #define JSON_THROW(exception) throw exception
1749 #define JSON_TRY try
1750 #define JSON_CATCH(exception) catch(exception)
1751 #define JSON_INTERNAL_CATCH(exception) catch(exception)
1754 #define JSON_THROW(exception) std::abort()
1755 #define JSON_TRY if(true)
1756 #define JSON_CATCH(exception) if(false)
1757 #define JSON_INTERNAL_CATCH(exception) if(false)
1761#if defined(JSON_THROW_USER)
1763 #define JSON_THROW JSON_THROW_USER
1765#if defined(JSON_TRY_USER)
1767 #define JSON_TRY JSON_TRY_USER
1769#if defined(JSON_CATCH_USER)
1771 #define JSON_CATCH JSON_CATCH_USER
1772 #undef JSON_INTERNAL_CATCH
1773 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
1775#if defined(JSON_INTERNAL_CATCH_USER)
1776 #undef JSON_INTERNAL_CATCH
1777 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
1785#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
1786 template<typename BasicJsonType> \
1787 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
1789 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
1790 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
1791 auto it = std::find_if(std::begin(m), std::end(m), \
1792 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
1794 return ej_pair.first == e; \
1796 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
1798 template<typename BasicJsonType> \
1799 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
1801 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
1802 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
1803 auto it = std::find_if(std::begin(m), std::end(m), \
1804 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
1806 return ej_pair.second == j; \
1808 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
1814#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
1815 template<template<typename, typename, typename...> class ObjectType, \
1816 template<typename, typename...> class ArrayType, \
1817 class StringType, class BooleanType, class NumberIntegerType, \
1818 class NumberUnsignedType, class NumberFloatType, \
1819 template<typename> class AllocatorType, \
1820 template<typename, typename = void> class JSONSerializer>
1822#define NLOHMANN_BASIC_JSON_TPL \
1823 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
1824 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
1825 AllocatorType, JSONSerializer>
1864class exception :
public std::exception
1868 JSON_HEDLEY_RETURNS_NON_NULL
1869 const char*
what() const noexcept
override
1878 JSON_HEDLEY_NON_NULL(3)
1879 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
1881 static std::string name(
const std::string& ename,
int id_)
1883 return "[json.exception." + ename +
"." + std::to_string(id_) +
"] ";
1888 std::runtime_error m;
1935class parse_error :
public exception
1949 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
1950 position_string(pos) +
": " + what_arg;
1954 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg)
1956 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
1957 (byte_ != 0 ? (
" at byte " + std::to_string(byte_)) :
"") +
1974 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
1975 : exception(id_, what_arg),
byte(byte_) {}
1977 static std::string position_string(
const position_t& pos)
1979 return " at line " + std::to_string(pos.
lines_read + 1) +
2021class invalid_iterator :
public exception
2024 static invalid_iterator create(
int id_,
const std::string& what_arg)
2026 std::string w = exception::name(
"invalid_iterator", id_) + what_arg;
2027 return invalid_iterator(id_, w.c_str());
2031 JSON_HEDLEY_NON_NULL(3)
2032 invalid_iterator(
int id_,
const char* what_arg)
2033 : exception(id_, what_arg) {}
2075class type_error :
public exception
2078 static type_error create(
int id_,
const std::string& what_arg)
2080 std::string w = exception::name(
"type_error", id_) + what_arg;
2081 return type_error(id_, w.c_str());
2085 JSON_HEDLEY_NON_NULL(3)
2086 type_error(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
2122class out_of_range :
public exception
2125 static out_of_range create(
int id_,
const std::string& what_arg)
2127 std::string w = exception::name(
"out_of_range", id_) + what_arg;
2128 return out_of_range(id_, w.c_str());
2132 JSON_HEDLEY_NON_NULL(3)
2133 out_of_range(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
2160class other_error :
public exception
2163 static other_error create(
int id_,
const std::string& what_arg)
2165 std::string w = exception::name(
"other_error", id_) + what_arg;
2166 return other_error(id_, w.c_str());
2170 JSON_HEDLEY_NON_NULL(3)
2171 other_error(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
2183#include <type_traits>
2190template<
bool B,
typename T =
void>
2191using enable_if_t =
typename std::enable_if<B, T>::type;
2194using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
2198template<std::size_t... Ints>
2202 using value_type = std::size_t;
2203 static constexpr std::size_t size()
noexcept
2205 return sizeof...(Ints);
2209template<
class Sequence1,
class Sequence2>
2212template<std::size_t... I1, std::size_t... I2>
2216template<std::
size_t N>
2219 typename make_index_sequence < N - N / 2 >::type > {};
2224template<
typename... Ts>
2235 static constexpr T value{};
2239constexpr T static_const<T>::value;
2248#include <type_traits>
2267template <
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
2278template <
typename It,
typename =
void>
2281template <
typename It>
2284 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
2285 typename It::reference, typename It::iterator_category >>
2287 using difference_type =
typename It::difference_type;
2288 using value_type =
typename It::value_type;
2289 using pointer =
typename It::pointer;
2290 using reference =
typename It::reference;
2291 using iterator_category =
typename It::iterator_category;
2296template <
typename T,
typename =
void>
2301template <
typename T>
2307template <
typename T>
2310 using iterator_category = std::random_access_iterator_tag;
2311 using value_type = T;
2312 using difference_type = ptrdiff_t;
2314 using reference = T&;
2326#include <type_traits>
2338 nonesuch() =
delete;
2339 ~nonesuch() =
delete;
2340 nonesuch(nonesuch
const&) =
delete;
2341 nonesuch(nonesuch
const&&) =
delete;
2342 void operator=(nonesuch
const&) =
delete;
2343 void operator=(nonesuch&&) =
delete;
2346template <
class Default,
2348 template <
class...>
class Op,
2352 using value_t = std::false_type;
2353 using type = Default;
2356template <
class Default,
template <
class...>
class Op,
class... Args>
2357struct detector<Default, void_t<Op<Args...>>, Op, Args...>
2359 using value_t = std::true_type;
2360 using type = Op<Args...>;
2363template <
template <
class...>
class Op,
class... Args>
2366template <
template <
class...>
class Op,
class... Args>
2369template <
class Default,
template <
class...>
class Op,
class... Args>
2370using detected_or =
detector<Default, void, Op, Args...>;
2372template <
class Default,
template <
class...>
class Op,
class... Args>
2373using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
2375template <
class Expected,
template <
class...>
class Op,
class... Args>
2376using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
2378template <
class To,
template <
class...>
class Op,
class... Args>
2379using is_detected_convertible =
2380 std::is_convertible<detected_t<Op, Args...>, To>;
2385#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
2386#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
2408template<
typename T =
void,
typename SFINAE =
void>
2409struct adl_serializer;
2411template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
2413 template<
typename U,
typename... Args>
class ArrayType = std::vector,
2414 class StringType = std::string,
class BooleanType = bool,
2415 class NumberIntegerType = std::int64_t,
2416 class NumberUnsignedType = std::uint64_t,
2417 class NumberFloatType = double,
2418 template<
typename U>
class AllocatorType = std::allocator,
2419 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
2434template<
typename BasicJsonType>
2478NLOHMANN_BASIC_JSON_TPL_DECLARATION
2485template <
typename T>
2486using mapped_type_t =
typename T::mapped_type;
2488template <
typename T>
2489using key_type_t =
typename T::key_type;
2491template <
typename T>
2492using value_type_t =
typename T::value_type;
2494template <
typename T>
2495using difference_type_t =
typename T::difference_type;
2497template <
typename T>
2498using pointer_t =
typename T::pointer;
2500template <
typename T>
2501using reference_t =
typename T::reference;
2503template <
typename T>
2504using iterator_category_t =
typename T::iterator_category;
2506template <
typename T>
2507using iterator_t =
typename T::iterator;
2509template <
typename T,
typename... Args>
2510using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
2512template <
typename T,
typename... Args>
2513using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
2515template <
typename T,
typename U>
2516using get_template_function =
decltype(std::declval<T>().template get<U>());
2519template <
typename BasicJsonType,
typename T,
typename =
void>
2522template <
typename BasicJsonType,
typename T>
2526 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
2528 static constexpr bool value =
2529 is_detected_exact<void, from_json_function, serializer,
2530 const BasicJsonType&, T&>::value;
2535template <
typename BasicJsonType,
typename T,
typename =
void>
2538template<
typename BasicJsonType,
typename T>
2541 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
2543 static constexpr bool value =
2544 is_detected_exact<T, from_json_function, serializer,
2545 const BasicJsonType&>::value;
2550template <
typename BasicJsonType,
typename T,
typename =
void>
2553template <
typename BasicJsonType,
typename T>
2556 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
2558 static constexpr bool value =
2559 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
2568template <
typename T,
typename =
void>
2571template <
typename T>
2578 static constexpr auto value =
2579 is_detected<value_type_t, traits>::value &&
2580 is_detected<difference_type_t, traits>::value &&
2581 is_detected<pointer_t, traits>::value &&
2582 is_detected<iterator_category_t, traits>::value &&
2583 is_detected<reference_t, traits>::value;
2588template <
typename T,
typename =
void>
2591template <
typename T>
2594template <
typename BasicJsonType,
typename CompatibleObjectType,
2598template <
typename BasicJsonType,
typename CompatibleObjectType>
2600 BasicJsonType, CompatibleObjectType,
2601 enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value and
2602 is_detected<key_type_t, CompatibleObjectType>::value >>
2605 using object_t =
typename BasicJsonType::object_t;
2608 static constexpr bool value =
2609 std::is_constructible<
typename object_t::key_type,
2610 typename CompatibleObjectType::key_type>::value and
2611 std::is_constructible<
typename object_t::mapped_type,
2612 typename CompatibleObjectType::mapped_type>::value;
2615template <
typename BasicJsonType,
typename CompatibleObjectType>
2619template <
typename BasicJsonType,
typename ConstructibleObjectType,
2623template <
typename BasicJsonType,
typename ConstructibleObjectType>
2625 BasicJsonType, ConstructibleObjectType,
2626 enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value and
2627 is_detected<key_type_t, ConstructibleObjectType>::value >>
2629 using object_t =
typename BasicJsonType::object_t;
2631 static constexpr bool value =
2632 (std::is_default_constructible<ConstructibleObjectType>::value and
2633 (std::is_move_assignable<ConstructibleObjectType>::value or
2634 std::is_copy_assignable<ConstructibleObjectType>::value) and
2635 (std::is_constructible<
typename ConstructibleObjectType::key_type,
2636 typename object_t::key_type>::value and
2638 typename object_t::mapped_type,
2639 typename ConstructibleObjectType::mapped_type >::value)) or
2641 typename ConstructibleObjectType::mapped_type>::value or
2644 typename ConstructibleObjectType::mapped_type >::value);
2647template <
typename BasicJsonType,
typename ConstructibleObjectType>
2650 ConstructibleObjectType> {};
2652template <
typename BasicJsonType,
typename CompatibleStringType,
2656template <
typename BasicJsonType,
typename CompatibleStringType>
2658 BasicJsonType, CompatibleStringType,
2659 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
2660 value_type_t, CompatibleStringType>::value >>
2662 static constexpr auto value =
2663 std::is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
2666template <
typename BasicJsonType,
typename ConstructibleStringType>
2670template <
typename BasicJsonType,
typename ConstructibleStringType,
2674template <
typename BasicJsonType,
typename ConstructibleStringType>
2676 BasicJsonType, ConstructibleStringType,
2677 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
2678 value_type_t, ConstructibleStringType>::value >>
2680 static constexpr auto value =
2681 std::is_constructible<ConstructibleStringType,
2682 typename BasicJsonType::string_t>::value;
2685template <
typename BasicJsonType,
typename ConstructibleStringType>
2689template <
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
2692template <
typename BasicJsonType,
typename CompatibleArrayType>
2694 BasicJsonType, CompatibleArrayType,
2695 enable_if_t<is_detected<value_type_t, CompatibleArrayType>::value and
2696 is_detected<iterator_t, CompatibleArrayType>::value and
2701 iterator_traits<CompatibleArrayType>>::value >>
2703 static constexpr bool value =
2704 std::is_constructible<BasicJsonType,
2705 typename CompatibleArrayType::value_type>::value;
2708template <
typename BasicJsonType,
typename CompatibleArrayType>
2712template <
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
2715template <
typename BasicJsonType,
typename ConstructibleArrayType>
2717 BasicJsonType, ConstructibleArrayType,
2718 enable_if_t<std::is_same<ConstructibleArrayType,
2719 typename BasicJsonType::value_type>::value >>
2720 : std::true_type {};
2722template <
typename BasicJsonType,
typename ConstructibleArrayType>
2724 BasicJsonType, ConstructibleArrayType,
2725 enable_if_t<not std::is_same<ConstructibleArrayType,
2726 typename BasicJsonType::value_type>::value and
2727 std::is_default_constructible<ConstructibleArrayType>::value and
2728(std::is_move_assignable<ConstructibleArrayType>::value or
2729 std::is_copy_assignable<ConstructibleArrayType>::value) and
2730is_detected<value_type_t, ConstructibleArrayType>::value and
2731is_detected<iterator_t, ConstructibleArrayType>::value and
2733detected_t<value_type_t, ConstructibleArrayType>>::value >>
2735 static constexpr bool value =
2743 (std::is_same<
typename ConstructibleArrayType::value_type,
2744 typename BasicJsonType::array_t::value_type>::value or
2746 typename ConstructibleArrayType::value_type>::value or
2748 BasicJsonType,
typename ConstructibleArrayType::value_type >::value);
2751template <
typename BasicJsonType,
typename ConstructibleArrayType>
2755template <
typename RealIntegerType,
typename CompatibleNumberIntegerType,
2759template <
typename RealIntegerType,
typename CompatibleNumberIntegerType>
2761 RealIntegerType, CompatibleNumberIntegerType,
2762 enable_if_t<std::is_integral<RealIntegerType>::value and
2763 std::is_integral<CompatibleNumberIntegerType>::value and
2764 not std::is_same<bool, CompatibleNumberIntegerType>::value >>
2767 using RealLimits = std::numeric_limits<RealIntegerType>;
2768 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
2770 static constexpr auto value =
2771 std::is_constructible<RealIntegerType,
2772 CompatibleNumberIntegerType>::value and
2773 CompatibleLimits::is_integer and
2774 RealLimits::is_signed == CompatibleLimits::is_signed;
2777template <
typename RealIntegerType,
typename CompatibleNumberIntegerType>
2780 CompatibleNumberIntegerType> {};
2782template <
typename BasicJsonType,
typename CompatibleType,
typename =
void>
2785template <
typename BasicJsonType,
typename CompatibleType>
2787 BasicJsonType, CompatibleType,
2790 static constexpr bool value =
2794template <
typename BasicJsonType,
typename CompatibleType>
2801template<
class B1,
class... Bn>
2803: std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
2805template <
typename T1,
typename T2>
2808template <
typename T1,
typename... Args>
2879 static constexpr std::array<std::uint8_t, 8> order = {{
2885 const auto l_index =
static_cast<std::size_t
>(lhs);
2886 const auto r_index =
static_cast<std::size_t
>(rhs);
2887 return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index];
2897template<
typename BasicJsonType>
2898void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
2900 if (JSON_HEDLEY_UNLIKELY(not j.is_null()))
2902 JSON_THROW(type_error::create(302,
"type must be null, but is " + std::string(j.type_name())));
2908template<
typename BasicJsonType,
typename ArithmeticType,
2909 enable_if_t<std::is_arithmetic<ArithmeticType>::value and
2910 not std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
2912void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
2914 switch (
static_cast<value_t>(j))
2918 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
2923 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
2928 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
2933 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name())));
2937template<
typename BasicJsonType>
2938void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
2940 if (JSON_HEDLEY_UNLIKELY(not j.is_boolean()))
2942 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(j.type_name())));
2944 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
2947template<
typename BasicJsonType>
2948void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
2950 if (JSON_HEDLEY_UNLIKELY(not j.is_string()))
2952 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name())));
2954 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
2958 typename BasicJsonType,
typename ConstructibleStringType,
2961 not std::is_same<
typename BasicJsonType::string_t,
2962 ConstructibleStringType>::value,
2964void from_json(
const BasicJsonType& j, ConstructibleStringType& s)
2966 if (JSON_HEDLEY_UNLIKELY(not j.is_string()))
2968 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name())));
2971 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
2974template<
typename BasicJsonType>
2975void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
2977 get_arithmetic_value(j, val);
2980template<
typename BasicJsonType>
2981void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
2983 get_arithmetic_value(j, val);
2986template<
typename BasicJsonType>
2987void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
2989 get_arithmetic_value(j, val);
2992template<
typename BasicJsonType,
typename EnumType,
2993 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
2994void from_json(
const BasicJsonType& j, EnumType& e)
2996 typename std::underlying_type<EnumType>::type val;
2997 get_arithmetic_value(j, val);
2998 e =
static_cast<EnumType
>(val);
3002template<
typename BasicJsonType,
typename T,
typename Allocator,
3003 enable_if_t<std::is_convertible<BasicJsonType, T>::value,
int> = 0>
3004void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
3006 if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
3008 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name())));
3011 std::transform(j.rbegin(), j.rend(),
3012 std::front_inserter(l), [](
const BasicJsonType & i)
3014 return i.template get<T>();
3019template<
typename BasicJsonType,
typename T,
3020 enable_if_t<std::is_convertible<BasicJsonType, T>::value,
int> = 0>
3021void from_json(
const BasicJsonType& j, std::valarray<T>& l)
3023 if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
3025 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name())));
3028 std::copy(j.begin(), j.end(), std::begin(l));
3031template <
typename BasicJsonType,
typename T, std::
size_t N>
3032auto from_json(
const BasicJsonType& j, T (&arr)[N])
3033->
decltype(j.template get<T>(), void())
3035 for (std::size_t i = 0; i < N; ++i)
3037 arr[i] = j.at(i).template get<T>();
3041template<
typename BasicJsonType>
3042void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr,
priority_tag<3> )
3044 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
3047template <
typename BasicJsonType,
typename T, std::
size_t N>
3048auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
3050->
decltype(j.template get<T>(), void())
3052 for (std::size_t i = 0; i < N; ++i)
3054 arr[i] = j.at(i).template get<T>();
3058template<
typename BasicJsonType,
typename ConstructibleArrayType>
3059auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
priority_tag<1> )
3061 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
3062 j.template get<typename ConstructibleArrayType::value_type>(),
3067 ConstructibleArrayType ret;
3068 ret.reserve(j.size());
3069 std::transform(j.begin(), j.end(),
3070 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
3074 return i.template get<typename ConstructibleArrayType::value_type>();
3076 arr = std::move(ret);
3079template <
typename BasicJsonType,
typename ConstructibleArrayType>
3080void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
3085 ConstructibleArrayType ret;
3087 j.begin(), j.end(), std::inserter(ret, end(ret)),
3088 [](
const BasicJsonType & i)
3092 return i.template get<typename ConstructibleArrayType::value_type>();
3094 arr = std::move(ret);
3097template <
typename BasicJsonType,
typename ConstructibleArrayType,
3105auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
3107j.template get<typename ConstructibleArrayType::value_type>(),
3110 if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
3112 JSON_THROW(type_error::create(302,
"type must be array, but is " +
3113 std::string(j.type_name())));
3119template<
typename BasicJsonType,
typename ConstructibleObjectType,
3120 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
3121void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
3123 if (JSON_HEDLEY_UNLIKELY(not j.is_object()))
3125 JSON_THROW(type_error::create(302,
"type must be object, but is " + std::string(j.type_name())));
3128 ConstructibleObjectType ret;
3129 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
3130 using value_type =
typename ConstructibleObjectType::value_type;
3132 inner_object->begin(), inner_object->end(),
3133 std::inserter(ret, ret.begin()),
3134 [](
typename BasicJsonType::object_t::value_type
const & p)
3136 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
3138 obj = std::move(ret);
3145template<
typename BasicJsonType,
typename ArithmeticType,
3147 std::is_arithmetic<ArithmeticType>::value and
3148 not std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value and
3149 not std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value and
3150 not std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value and
3151 not std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3153void from_json(
const BasicJsonType& j, ArithmeticType& val)
3155 switch (
static_cast<value_t>(j))
3159 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3164 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3169 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3174 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
3179 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name())));
3183template<
typename BasicJsonType,
typename A1,
typename A2>
3184void from_json(
const BasicJsonType& j, std::pair<A1, A2>& p)
3186 p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
3189template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
3192 t = std::make_tuple(j.at(Idx).template get<
typename std::tuple_element<Idx, Tuple>::type>()...);
3195template<
typename BasicJsonType,
typename... Args>
3196void from_json(
const BasicJsonType& j, std::tuple<Args...>& t)
3198 from_json_tuple_impl(j, t, index_sequence_for<Args...> {});
3201template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
3202 typename = enable_if_t<not std::is_constructible<
3203 typename BasicJsonType::string_t, Key>::value>>
3204void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
3206 if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
3208 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name())));
3211 for (
const auto& p : j)
3213 if (JSON_HEDLEY_UNLIKELY(not p.is_array()))
3215 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name())));
3217 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
3221template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
3222 typename = enable_if_t<not std::is_constructible<
3223 typename BasicJsonType::string_t, Key>::value>>
3224void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
3226 if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
3228 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name())));
3231 for (
const auto& p : j)
3233 if (JSON_HEDLEY_UNLIKELY(not p.is_array()))
3235 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name())));
3237 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
3243 template<
typename BasicJsonType,
typename T>
3244 auto operator()(
const BasicJsonType& j, T& val)
const
3245 noexcept(
noexcept(from_json(j, val)))
3246 ->
decltype(from_json(j, val),
void())
3248 return from_json(j, val);
3258constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
3270#include <type_traits>
3292template<
typename string_type>
3293void int_to_string( string_type& target, std::size_t value )
3295 target = std::to_string(value);
3297template <
typename IteratorType>
class iteration_proxy_value
3300 using difference_type = std::ptrdiff_t;
3301 using value_type = iteration_proxy_value;
3302 using pointer = value_type * ;
3303 using reference = value_type & ;
3304 using iterator_category = std::input_iterator_tag;
3305 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
3309 IteratorType anchor;
3311 std::size_t array_index = 0;
3313 mutable std::size_t array_index_last = 0;
3315 mutable string_type array_index_str =
"0";
3317 const string_type empty_str =
"";
3320 explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {}
3340 return anchor == o.anchor;
3346 return anchor != o.anchor;
3350 const string_type&
key()
const
3352 assert(anchor.m_object !=
nullptr);
3354 switch (anchor.m_object->type())
3359 if (array_index != array_index_last)
3361 int_to_string( array_index_str, array_index );
3362 array_index_last = array_index;
3364 return array_index_str;
3369 return anchor.key();
3378 typename IteratorType::reference
value()
const
3380 return anchor.value();
3389 typename IteratorType::reference container;
3394 : container(cont) {}
3411template <std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
3419template <std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
3433#if defined(__clang__)
3435 #pragma clang diagnostic push
3436 #pragma clang diagnostic ignored "-Wmismatched-tags"
3438template <
typename IteratorType>
3440 :
public std::integral_constant<std::size_t, 2> {};
3442template <std::
size_t N,
typename IteratorType>
3446 using type =
decltype(
3447 get<N>(std::declval <
3450#if defined(__clang__)
3451 #pragma clang diagnostic pop
3475 template<
typename BasicJsonType>
3476 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
3480 j.assert_invariant();
3487 template<
typename BasicJsonType>
3488 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
3492 j.assert_invariant();
3495 template<
typename BasicJsonType>
3496 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
3499 j.m_value = std::move(s);
3500 j.assert_invariant();
3503 template<
typename BasicJsonType,
typename CompatibleStringType,
3504 enable_if_t<not std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
3506 static void construct(BasicJsonType& j,
const CompatibleStringType&
str)
3509 j.m_value.string = j.template create<typename BasicJsonType::string_t>(
str);
3510 j.assert_invariant();
3517 template<
typename BasicJsonType>
3518 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
3522 j.assert_invariant();
3529 template<
typename BasicJsonType>
3530 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
3534 j.assert_invariant();
3541 template<
typename BasicJsonType>
3542 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
3546 j.assert_invariant();
3553 template<
typename BasicJsonType>
3554 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
3558 j.assert_invariant();
3561 template<
typename BasicJsonType>
3562 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
3565 j.m_value = std::move(arr);
3566 j.assert_invariant();
3569 template<
typename BasicJsonType,
typename CompatibleArrayType,
3570 enable_if_t<not std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
3572 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
3577 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
3578 j.assert_invariant();
3581 template<
typename BasicJsonType>
3582 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
3586 j.m_value.array->reserve(arr.size());
3587 for (
const bool x : arr)
3589 j.m_value.array->push_back(x);
3591 j.assert_invariant();
3594 template<
typename BasicJsonType,
typename T,
3595 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
3596 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
3600 j.m_value.array->resize(arr.size());
3603 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
3605 j.assert_invariant();
3612 template<
typename BasicJsonType>
3613 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
3617 j.assert_invariant();
3620 template<
typename BasicJsonType>
3621 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
3624 j.m_value = std::move(obj);
3625 j.assert_invariant();
3628 template<
typename BasicJsonType,
typename CompatibleObjectType,
3629 enable_if_t<not std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int> = 0>
3630 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
3636 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
3637 j.assert_invariant();
3645template<
typename BasicJsonType,
typename T,
3646 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
3647void to_json(BasicJsonType& j, T b)
noexcept
3652template<
typename BasicJsonType,
typename CompatibleString,
3653 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
3654void to_json(BasicJsonType& j,
const CompatibleString& s)
3656 external_constructor<value_t::string>::construct(j, s);
3659template<
typename BasicJsonType>
3660void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
3662 external_constructor<value_t::string>::construct(j, std::move(s));
3665template<
typename BasicJsonType,
typename FloatType,
3666 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
3667void to_json(BasicJsonType& j, FloatType val)
noexcept
3672template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
3673 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
3674void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
3679template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
3680 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
3681void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
3686template<
typename BasicJsonType,
typename EnumType,
3687 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
3688void to_json(BasicJsonType& j, EnumType e)
noexcept
3690 using underlying_type =
typename std::underlying_type<EnumType>::type;
3694template<
typename BasicJsonType>
3695void to_json(BasicJsonType& j,
const std::vector<bool>& e)
3700template <
typename BasicJsonType,
typename CompatibleArrayType,
3702 CompatibleArrayType>::value and
3704 BasicJsonType, CompatibleArrayType>::value and
3708void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
3713template<
typename BasicJsonType,
typename T,
3714 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
3715void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
3720template<
typename BasicJsonType>
3721void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
3726template<
typename BasicJsonType,
typename CompatibleObjectType,
3728void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
3733template<
typename BasicJsonType>
3734void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
3740 typename BasicJsonType,
typename T, std::size_t N,
3741 enable_if_t<not std::is_constructible<
typename BasicJsonType::string_t,
3742 const T(&)[N]>::value,
3744void to_json(BasicJsonType& j,
const T(&arr)[N])
3749template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
3750void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
3752 j = { p.first, p.second };
3756template <
typename BasicJsonType,
typename T,
3757 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
3758void to_json(BasicJsonType& j,
const T& b)
3760 j = { {b.key(), b.value()} };
3763template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
3766 j = { std::get<Idx>(t)... };
3769template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
3770void to_json(BasicJsonType& j,
const T& t)
3777 template<
typename BasicJsonType,
typename T>
3778 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(to_json(j, std::forward<T>(val))))
3779 ->
decltype(to_json(j, std::forward<T>(val)),
void())
3781 return to_json(j, std::forward<T>(val));
3789constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
3797template<
typename,
typename>
3809 template<
typename BasicJsonType,
typename ValueType>
3810 static auto from_json(BasicJsonType&& j, ValueType& val)
noexcept(
3811 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
3812 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
3814 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
3826 template <
typename BasicJsonType,
typename ValueType>
3827 static auto to_json(BasicJsonType& j, ValueType&& val)
noexcept(
3828 noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
3829 ->
decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)),
void())
3831 ::nlohmann::to_json(j, std::forward<ValueType>(val));
3874#include <type_traits>
3921 JSON_HEDLEY_NON_NULL(2)
3922 explicit file_input_adapter(std::FILE* f) noexcept
3927 file_input_adapter(
const file_input_adapter&) =
delete;
3928 file_input_adapter(file_input_adapter&&) =
default;
3929 file_input_adapter& operator=(
const file_input_adapter&) =
delete;
3930 file_input_adapter& operator=(file_input_adapter&&) =
default;
3931 ~file_input_adapter()
override =
default;
3935 return std::fgetc(m_file);
3956 ~input_stream_adapter()
override
3960 is.clear(is.rdstate() & std::ios::eofbit);
3963 explicit input_stream_adapter(std::istream& i)
3964 : is(i), sb(*i.rdbuf())
3968 input_stream_adapter(
const input_stream_adapter&) =
delete;
3969 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
3970 input_stream_adapter(input_stream_adapter&&) =
delete;
3971 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
3978 auto res = sb.sbumpc();
3982 is.clear(is.rdstate() | std::ios::eofbit);
3997 input_buffer_adapter(
const char* b,
const std::size_t l) noexcept
3998 : cursor(b), limit(b ==
nullptr ?
nullptr : (b + l))
4002 input_buffer_adapter(
const input_buffer_adapter&) =
delete;
4003 input_buffer_adapter& operator=(input_buffer_adapter&) =
delete;
4004 input_buffer_adapter(input_buffer_adapter&&) =
delete;
4005 input_buffer_adapter& operator=(input_buffer_adapter&&) =
delete;
4006 ~input_buffer_adapter()
override =
default;
4010 if (JSON_HEDLEY_LIKELY(cursor < limit))
4012 assert(cursor !=
nullptr and limit !=
nullptr);
4013 return std::char_traits<char>::to_int_type(*(cursor++));
4016 return std::char_traits<char>::eof();
4023 const char*
const limit;
4026template<
typename W
ideStringType,
size_t T>
4030 static void fill_buffer(
const WideStringType&
str,
4031 size_t& current_wchar,
4032 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
4033 size_t& utf8_bytes_index,
4034 size_t& utf8_bytes_filled)
4036 utf8_bytes_index = 0;
4038 if (current_wchar ==
str.size())
4040 utf8_bytes[0] = std::char_traits<char>::eof();
4041 utf8_bytes_filled = 1;
4046 const auto wc =
static_cast<unsigned int>(
str[current_wchar++]);
4051 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4052 utf8_bytes_filled = 1;
4054 else if (wc <= 0x7FF)
4056 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((wc >> 6u) & 0x1Fu));
4057 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (wc & 0x3Fu));
4058 utf8_bytes_filled = 2;
4060 else if (wc <= 0xFFFF)
4062 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((wc >> 12u) & 0x0Fu));
4063 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((wc >> 6u) & 0x3Fu));
4064 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (wc & 0x3Fu));
4065 utf8_bytes_filled = 3;
4067 else if (wc <= 0x10FFFF)
4069 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((wc >> 18u) & 0x07u));
4070 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((wc >> 12u) & 0x3Fu));
4071 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((wc >> 6u) & 0x3Fu));
4072 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (wc & 0x3Fu));
4073 utf8_bytes_filled = 4;
4078 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4079 utf8_bytes_filled = 1;
4085template<
typename W
ideStringType>
4089 static void fill_buffer(
const WideStringType&
str,
4090 size_t& current_wchar,
4091 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
4092 size_t& utf8_bytes_index,
4093 size_t& utf8_bytes_filled)
4095 utf8_bytes_index = 0;
4097 if (current_wchar ==
str.size())
4099 utf8_bytes[0] = std::char_traits<char>::eof();
4100 utf8_bytes_filled = 1;
4105 const auto wc =
static_cast<unsigned int>(
str[current_wchar++]);
4110 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4111 utf8_bytes_filled = 1;
4113 else if (wc <= 0x7FF)
4115 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((wc >> 6u)));
4116 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (wc & 0x3Fu));
4117 utf8_bytes_filled = 2;
4119 else if (0xD800 > wc or wc >= 0xE000)
4121 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((wc >> 12u)));
4122 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((wc >> 6u) & 0x3Fu));
4123 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (wc & 0x3Fu));
4124 utf8_bytes_filled = 3;
4128 if (current_wchar <
str.size())
4130 const auto wc2 =
static_cast<unsigned int>(
str[current_wchar++]);
4131 const auto charcode = 0x10000u + (((wc & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
4132 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
4133 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
4134 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
4135 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
4136 utf8_bytes_filled = 4;
4142 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4143 utf8_bytes_filled = 1;
4150template<
typename W
ideStringType>
4154 explicit wide_string_input_adapter(
const WideStringType& w) noexcept
4161 if (utf8_bytes_index == utf8_bytes_filled)
4163 fill_buffer<sizeof(typename WideStringType::value_type)>();
4165 assert(utf8_bytes_filled > 0);
4166 assert(utf8_bytes_index == 0);
4170 assert(utf8_bytes_filled > 0);
4171 assert(utf8_bytes_index < utf8_bytes_filled);
4172 return utf8_bytes[utf8_bytes_index++];
4179 wide_string_input_helper<WideStringType, T>::fill_buffer(
str, current_wchar, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
4183 const WideStringType&
str;
4186 std::size_t current_wchar = 0;
4189 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
4192 std::size_t utf8_bytes_index = 0;
4194 std::size_t utf8_bytes_filled = 0;
4201 JSON_HEDLEY_NON_NULL(2)
4202 input_adapter(std::FILE* file)
4203 : ia(std::make_shared<file_input_adapter>(file)) {}
4215 input_adapter(
const std::u16string& ws)
4216 : ia(std::make_shared<wide_string_input_adapter<std::u16string>>(ws)) {}
4218 input_adapter(
const std::u32string& ws)
4219 : ia(std::make_shared<wide_string_input_adapter<std::u32string>>(ws)) {}
4222 template<
typename CharT,
4223 typename std::enable_if<
4224 std::is_pointer<CharT>::value and
4225 std::is_integral<typename std::remove_pointer<CharT>::type>::value and
4226 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
4234 template<
typename CharT,
4235 typename std::enable_if<
4236 std::is_pointer<CharT>::value and
4237 std::is_integral<typename std::remove_pointer<CharT>::type>::value and
4238 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
4241 : input_adapter(reinterpret_cast<const char*>(b),
4242 std::strlen(reinterpret_cast<const char*>(b))) {}
4245 template<
class IteratorType,
4246 typename std::enable_if<
4247 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
4254 const auto is_contiguous = std::accumulate(
4255 first, last, std::pair<bool, int>(
true, 0),
4256 [&first](std::pair<bool, int> res,
decltype(*first) val)
4258 res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
4261 assert(is_contiguous);
4267 "each element in the iterator range must have the size of 1 byte");
4269 const auto len =
static_cast<size_t>(std::distance(first, last));
4270 if (JSON_HEDLEY_LIKELY(len > 0))
4273 ia = std::make_shared<input_buffer_adapter>(
reinterpret_cast<const char*
>(&(*first)), len);
4278 ia = std::make_shared<input_buffer_adapter>(
nullptr, len);
4283 template<
class T, std::
size_t N>
4285 : input_adapter(std::begin(
array), std::end(
array)) {}
4288 template<
class ContiguousContainer,
typename
4289 std::enable_if<not std::is_pointer<ContiguousContainer>::value and
4290 std::is_base_of<std::random_access_iterator_tag, typename iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::value,
4293 : input_adapter(std::begin(c), std::end(c)) {}
4332template<
typename BasicJsonType>
4431 const std::string& last_token,
4453template<
typename BasicJsonType>
4457 using number_integer_t =
typename BasicJsonType::number_integer_t;
4458 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
4459 using number_float_t =
typename BasicJsonType::number_float_t;
4460 using string_t =
typename BasicJsonType::string_t;
4468 : root(r), allow_exceptions(allow_exceptions_)
4480 handle_value(
nullptr);
4502 bool number_float(number_float_t val,
const string_t& )
4508 bool string(string_t& val)
4514 bool start_object(std::size_t len)
4516 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
4518 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4520 JSON_THROW(out_of_range::create(408,
4521 "excessive object size: " + std::to_string(len)));
4527 bool key(string_t& val)
4530 object_element = &(ref_stack.back()->m_value.object->operator[](val));
4536 ref_stack.pop_back();
4540 bool start_array(std::size_t len)
4542 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
4544 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4546 JSON_THROW(out_of_range::create(408,
4547 "excessive array size: " + std::to_string(len)));
4555 ref_stack.pop_back();
4559 bool parse_error(std::size_t ,
const std::string& ,
4560 const detail::exception& ex)
4563 if (allow_exceptions)
4566 switch ((ex.id / 100) % 100)
4569 JSON_THROW(*
static_cast<const detail::parse_error*
>(&ex));
4571 JSON_THROW(*
static_cast<const detail::out_of_range*
>(&ex));
4574 JSON_THROW(*
static_cast<const detail::invalid_iterator*
>(&ex));
4576 JSON_THROW(*
static_cast<const detail::type_error*
>(&ex));
4578 JSON_THROW(*
static_cast<const detail::other_error*
>(&ex));
4587 constexpr bool is_errored()
const
4599 template<
typename Value>
4600 JSON_HEDLEY_RETURNS_NON_NULL
4601 BasicJsonType* handle_value(Value&& v)
4603 if (ref_stack.empty())
4605 root = BasicJsonType(std::forward<Value>(v));
4609 assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
4611 if (ref_stack.back()->is_array())
4613 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
4614 return &(ref_stack.back()->m_value.array->back());
4617 assert(ref_stack.back()->is_object());
4618 assert(object_element);
4619 *object_element = BasicJsonType(std::forward<Value>(v));
4620 return object_element;
4624 BasicJsonType& root;
4626 std::vector<BasicJsonType*> ref_stack {};
4628 BasicJsonType* object_element =
nullptr;
4630 bool errored =
false;
4632 const bool allow_exceptions =
true;
4635template<
typename BasicJsonType>
4636class json_sax_dom_callback_parser
4639 using number_integer_t =
typename BasicJsonType::number_integer_t;
4640 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
4641 using number_float_t =
typename BasicJsonType::number_float_t;
4642 using string_t =
typename BasicJsonType::string_t;
4643 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
4644 using parse_event_t =
typename BasicJsonType::parse_event_t;
4646 json_sax_dom_callback_parser(BasicJsonType& r,
4647 const parser_callback_t cb,
4648 const bool allow_exceptions_ =
true)
4649 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
4651 keep_stack.push_back(
true);
4655 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
4656 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
default;
4657 json_sax_dom_callback_parser& operator=(
const json_sax_dom_callback_parser&) =
delete;
4658 json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) =
default;
4659 ~json_sax_dom_callback_parser() =
default;
4663 handle_value(
nullptr);
4685 bool number_float(number_float_t val,
const string_t& )
4691 bool string(string_t& val)
4697 bool start_object(std::size_t len)
4700 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
4701 keep_stack.push_back(keep);
4703 auto val = handle_value(BasicJsonType::value_t::object,
true);
4704 ref_stack.push_back(val.second);
4707 if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4709 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len)));
4715 bool key(string_t& val)
4717 BasicJsonType k = BasicJsonType(val);
4720 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
4721 key_keep_stack.push_back(keep);
4724 if (keep and ref_stack.back())
4726 object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
4734 if (ref_stack.back() and not callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
4737 *ref_stack.back() = discarded;
4740 assert(not ref_stack.empty());
4741 assert(not keep_stack.empty());
4742 ref_stack.pop_back();
4743 keep_stack.pop_back();
4745 if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_object())
4748 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
4750 if (it->is_discarded())
4752 ref_stack.back()->erase(it);
4761 bool start_array(std::size_t len)
4763 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
4764 keep_stack.push_back(keep);
4766 auto val = handle_value(BasicJsonType::value_t::array,
true);
4767 ref_stack.push_back(val.second);
4770 if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4772 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len)));
4782 if (ref_stack.back())
4784 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
4788 *ref_stack.back() = discarded;
4792 assert(not ref_stack.empty());
4793 assert(not keep_stack.empty());
4794 ref_stack.pop_back();
4795 keep_stack.pop_back();
4798 if (not keep and not ref_stack.empty() and ref_stack.back()->is_array())
4800 ref_stack.back()->m_value.array->pop_back();
4806 bool parse_error(std::size_t ,
const std::string& ,
4810 if (allow_exceptions)
4813 switch ((ex.
id / 100) % 100)
4834 constexpr bool is_errored()
const
4855 template<
typename Value>
4856 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
4858 assert(not keep_stack.empty());
4862 if (not keep_stack.back())
4864 return {
false,
nullptr};
4868 auto value = BasicJsonType(std::forward<Value>(v));
4871 const bool keep = skip_callback or callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
4876 return {
false,
nullptr};
4879 if (ref_stack.empty())
4881 root = std::move(value);
4882 return {
true, &root};
4887 if (not ref_stack.back())
4889 return {
false,
nullptr};
4893 assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
4896 if (ref_stack.back()->is_array())
4898 ref_stack.back()->m_value.array->push_back(std::move(value));
4899 return {
true, &(ref_stack.back()->m_value.array->back())};
4903 assert(ref_stack.back()->is_object());
4905 assert(not key_keep_stack.empty());
4906 const bool store_element = key_keep_stack.back();
4907 key_keep_stack.pop_back();
4909 if (not store_element)
4911 return {
false,
nullptr};
4914 assert(object_element);
4915 *object_element = std::move(value);
4916 return {
true, object_element};
4920 BasicJsonType& root;
4922 std::vector<BasicJsonType*> ref_stack {};
4924 std::vector<bool> keep_stack {};
4926 std::vector<bool> key_keep_stack {};
4928 BasicJsonType* object_element =
nullptr;
4930 bool errored =
false;
4932 const parser_callback_t callback =
nullptr;
4934 const bool allow_exceptions =
true;
4936 BasicJsonType discarded = BasicJsonType::value_t::discarded;
4939template<
typename BasicJsonType>
4943 using number_integer_t =
typename BasicJsonType::number_integer_t;
4944 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
4945 using number_float_t =
typename BasicJsonType::number_float_t;
4946 using string_t =
typename BasicJsonType::string_t;
4978 bool start_object(std::size_t = std::size_t(-1))
4983 bool key(string_t& )
4993 bool start_array(std::size_t = std::size_t(-1))
5030template <
typename T>
5031using null_function_t =
decltype(std::declval<T&>().null());
5033template <
typename T>
5034using boolean_function_t =
5035 decltype(std::declval<T&>().boolean(std::declval<bool>()));
5037template <
typename T,
typename Integer>
5038using number_integer_function_t =
5039 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
5041template <
typename T,
typename Un
signed>
5042using number_unsigned_function_t =
5043 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
5045template <
typename T,
typename Float,
typename String>
5046using number_float_function_t =
decltype(std::declval<T&>().number_float(
5047 std::declval<Float>(), std::declval<const String&>()));
5049template <
typename T,
typename String>
5050using string_function_t =
5051 decltype(std::declval<T&>().string(std::declval<String&>()));
5053template <
typename T>
5054using start_object_function_t =
5055 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
5057template <
typename T,
typename String>
5058using key_function_t =
5059 decltype(std::declval<T&>().key(std::declval<String&>()));
5061template <
typename T>
5062using end_object_function_t =
decltype(std::declval<T&>().end_object());
5064template <
typename T>
5065using start_array_function_t =
5066 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
5068template <
typename T>
5069using end_array_function_t =
decltype(std::declval<T&>().end_array());
5071template <
typename T,
typename Exception>
5072using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
5073 std::declval<std::size_t>(), std::declval<const std::string&>(),
5074 std::declval<const Exception&>()));
5076template <
typename SAX,
typename BasicJsonType>
5081 "BasicJsonType must be of type basic_json<...>");
5083 using number_integer_t =
typename BasicJsonType::number_integer_t;
5084 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5085 using number_float_t =
typename BasicJsonType::number_float_t;
5086 using string_t =
typename BasicJsonType::string_t;
5087 using exception_t =
typename BasicJsonType::exception;
5090 static constexpr bool value =
5091 is_detected_exact<bool, null_function_t, SAX>::value &&
5092 is_detected_exact<bool, boolean_function_t, SAX>::value &&
5093 is_detected_exact<bool, number_integer_function_t, SAX,
5094 number_integer_t>::value &&
5095 is_detected_exact<bool, number_unsigned_function_t, SAX,
5096 number_unsigned_t>::value &&
5097 is_detected_exact<bool, number_float_function_t, SAX, number_float_t,
5099 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
5100 is_detected_exact<bool, start_object_function_t, SAX>::value &&
5101 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
5102 is_detected_exact<bool, end_object_function_t, SAX>::value &&
5103 is_detected_exact<bool, start_array_function_t, SAX>::value &&
5104 is_detected_exact<bool, end_array_function_t, SAX>::value &&
5105 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
5108template <
typename SAX,
typename BasicJsonType>
5113 "BasicJsonType must be of type basic_json<...>");
5115 using number_integer_t =
typename BasicJsonType::number_integer_t;
5116 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5117 using number_float_t =
typename BasicJsonType::number_float_t;
5118 using string_t =
typename BasicJsonType::string_t;
5119 using exception_t =
typename BasicJsonType::exception;
5122 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
5123 "Missing/invalid function: bool null()");
5124 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
5125 "Missing/invalid function: bool boolean(bool)");
5126 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
5127 "Missing/invalid function: bool boolean(bool)");
5129 is_detected_exact<bool, number_integer_function_t, SAX,
5130 number_integer_t>::value,
5131 "Missing/invalid function: bool number_integer(number_integer_t)");
5133 is_detected_exact<bool, number_unsigned_function_t, SAX,
5134 number_unsigned_t>::value,
5135 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
5136 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
5137 number_float_t, string_t>::value,
5138 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
5140 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
5141 "Missing/invalid function: bool string(string_t&)");
5142 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
5143 "Missing/invalid function: bool start_object(std::size_t)");
5144 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
5145 "Missing/invalid function: bool key(string_t&)");
5146 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
5147 "Missing/invalid function: bool end_object()");
5148 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
5149 "Missing/invalid function: bool start_array(std::size_t)");
5150 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
5151 "Missing/invalid function: bool end_array()");
5153 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
5154 "Missing/invalid function: bool parse_error(std::size_t, const "
5155 "std::string&, const exception&)");
5174template<
typename BasicJsonType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
5177 using number_integer_t =
typename BasicJsonType::number_integer_t;
5178 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5179 using number_float_t =
typename BasicJsonType::number_float_t;
5180 using string_t =
typename BasicJsonType::string_t;
5181 using json_sax_t = SAX;
5209 JSON_HEDLEY_NON_NULL(3)
5212 const
bool strict = true)
5215 bool result =
false;
5219 case input_format_t::bson:
5220 result = parse_bson_internal();
5223 case input_format_t::cbor:
5224 result = parse_cbor_internal();
5227 case input_format_t::msgpack:
5228 result = parse_msgpack_internal();
5231 case input_format_t::ubjson:
5232 result = parse_ubjson_internal();
5242 if (format == input_format_t::ubjson)
5251 if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char>::eof()))
5253 return sax->parse_error(chars_read, get_token_string(),
5254 parse_error::create(110, chars_read, exception_message(format,
"expected end of input; last byte: 0x" + get_token_string(),
"value")));
5270 return *
reinterpret_cast<char*
>(&num) == 1;
5282 bool parse_bson_internal()
5284 std::int32_t document_size;
5285 get_number<std::int32_t, true>(input_format_t::bson, document_size);
5287 if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
5292 if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_list(
false)))
5297 return sax->end_object();
5307 bool get_bson_cstr(string_t& result)
5309 auto out = std::back_inserter(result);
5313 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson,
"cstring")))
5317 if (current == 0x00)
5321 *out++ =
static_cast<char>(current);
5338 template<
typename NumberType>
5339 bool get_bson_string(
const NumberType len, string_t& result)
5341 if (JSON_HEDLEY_UNLIKELY(len < 1))
5343 auto last_token = get_token_string();
5344 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")));
5347 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) and get() != std::char_traits<char>::eof();
5360 bool parse_bson_element_internal(
const int element_type,
5361 const std::size_t element_type_parse_position)
5363 switch (element_type)
5368 return get_number<double, true>(input_format_t::bson, number) and sax->number_float(
static_cast<number_float_t
>(number),
"");
5375 return get_number<std::int32_t, true>(input_format_t::bson, len) and get_bson_string(len, value) and sax->string(value);
5380 return parse_bson_internal();
5385 return parse_bson_array();
5390 return sax->boolean(get() != 0);
5401 return get_number<std::int32_t, true>(input_format_t::bson, value) and sax->number_integer(value);
5407 return get_number<std::int64_t, true>(input_format_t::bson, value) and sax->number_integer(value);
5412 std::array<char, 3> cr{{}};
5413 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type));
5414 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())));
5431 bool parse_bson_element_list(
const bool is_array)
5434 while (
int element_type = get())
5436 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson,
"element list")))
5441 const std::size_t element_type_parse_position = chars_read;
5442 if (JSON_HEDLEY_UNLIKELY(not get_bson_cstr(key)))
5447 if (not is_array and not sax->key(key))
5452 if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
5468 bool parse_bson_array()
5470 std::int32_t document_size;
5471 get_number<std::int32_t, true>(input_format_t::bson, document_size);
5473 if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
5478 if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_list(
true)))
5483 return sax->end_array();
5497 bool parse_cbor_internal(
const bool get_char =
true)
5499 switch (get_char ? get() : current)
5502 case std::char_traits<char>::eof():
5530 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
5534 std::uint8_t number;
5535 return get_number(input_format_t::cbor, number) and sax->number_unsigned(number);
5540 std::uint16_t number;
5541 return get_number(input_format_t::cbor, number) and sax->number_unsigned(number);
5546 std::uint32_t number;
5547 return get_number(input_format_t::cbor, number) and sax->number_unsigned(number);
5552 std::uint64_t number;
5553 return get_number(input_format_t::cbor, number) and sax->number_unsigned(number);
5581 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
5585 std::uint8_t number;
5586 return get_number(input_format_t::cbor, number) and sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
5591 std::uint16_t number;
5592 return get_number(input_format_t::cbor, number) and sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
5597 std::uint32_t number;
5598 return get_number(input_format_t::cbor, number) and sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
5603 std::uint64_t number;
5604 return get_number(input_format_t::cbor, number) and sax->number_integer(
static_cast<number_integer_t
>(-1)
5605 -
static_cast<number_integer_t
>(number));
5640 return get_cbor_string(s) and sax->string(s);
5668 return get_cbor_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu));
5673 return get_number(input_format_t::cbor, len) and get_cbor_array(
static_cast<std::size_t
>(len));
5679 return get_number(input_format_t::cbor, len) and get_cbor_array(
static_cast<std::size_t
>(len));
5685 return get_number(input_format_t::cbor, len) and get_cbor_array(
static_cast<std::size_t
>(len));
5691 return get_number(input_format_t::cbor, len) and get_cbor_array(
static_cast<std::size_t
>(len));
5695 return get_cbor_array(std::size_t(-1));
5722 return get_cbor_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu));
5727 return get_number(input_format_t::cbor, len) and get_cbor_object(
static_cast<std::size_t
>(len));
5733 return get_number(input_format_t::cbor, len) and get_cbor_object(
static_cast<std::size_t
>(len));
5739 return get_number(input_format_t::cbor, len) and get_cbor_object(
static_cast<std::size_t
>(len));
5745 return get_number(input_format_t::cbor, len) and get_cbor_object(
static_cast<std::size_t
>(len));
5749 return get_cbor_object(std::size_t(-1));
5752 return sax->boolean(
false);
5755 return sax->boolean(
true);
5762 const int byte1_raw = get();
5763 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor,
"number")))
5767 const int byte2_raw = get();
5768 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor,
"number")))
5773 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
5774 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
5784 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
5785 const double val = [&half]
5787 const int exp = (half >> 10u) & 0x1Fu;
5788 const unsigned int mant = half & 0x3FFu;
5789 assert(0 <= exp and exp <= 32);
5790 assert(mant <= 1024);
5794 return std::ldexp(mant, -24);
5797 ? std::numeric_limits<double>::infinity()
5798 : std::numeric_limits<double>::quiet_NaN();
5800 return std::ldexp(mant + 1024, exp - 25);
5803 return sax->number_float((half & 0x8000u) != 0
5804 ?
static_cast<number_float_t
>(-val)
5805 :
static_cast<number_float_t
>(val),
"");
5811 return get_number(input_format_t::cbor, number) and sax->number_float(
static_cast<number_float_t
>(number),
"");
5817 return get_number(input_format_t::cbor, number) and sax->number_float(
static_cast<number_float_t
>(number),
"");
5822 auto last_token = get_token_string();
5823 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")));
5839 bool get_cbor_string(string_t& result)
5841 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor,
"string")))
5874 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
5880 return get_number(input_format_t::cbor, len) and get_string(input_format_t::cbor, len, result);
5886 return get_number(input_format_t::cbor, len) and get_string(input_format_t::cbor, len, result);
5892 return get_number(input_format_t::cbor, len) and get_string(input_format_t::cbor, len, result);
5898 return get_number(input_format_t::cbor, len) and get_string(input_format_t::cbor, len, result);
5903 while (get() != 0xFF)
5906 if (not get_cbor_string(chunk))
5910 result.append(chunk);
5917 auto last_token = get_token_string();
5918 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")));
5928 bool get_cbor_array(
const std::size_t len)
5930 if (JSON_HEDLEY_UNLIKELY(not sax->start_array(len)))
5935 if (len != std::size_t(-1))
5937 for (std::size_t i = 0; i < len; ++i)
5939 if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
5947 while (get() != 0xFF)
5949 if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal(
false)))
5956 return sax->end_array();
5964 bool get_cbor_object(
const std::size_t len)
5966 if (JSON_HEDLEY_UNLIKELY(not sax->start_object(len)))
5972 if (len != std::size_t(-1))
5974 for (std::size_t i = 0; i < len; ++i)
5977 if (JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
5982 if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
5991 while (get() != 0xFF)
5993 if (JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
5998 if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
6006 return sax->end_object();
6016 bool parse_msgpack_internal()
6021 case std::char_traits<char>::eof():
6153 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
6172 return get_msgpack_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
6191 return get_msgpack_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
6231 return get_msgpack_string(s) and sax->string(s);
6238 return sax->boolean(
false);
6241 return sax->boolean(
true);
6246 return get_number(input_format_t::msgpack, number) and sax->number_float(
static_cast<number_float_t
>(number),
"");
6252 return get_number(input_format_t::msgpack, number) and sax->number_float(
static_cast<number_float_t
>(number),
"");
6257 std::uint8_t number;
6258 return get_number(input_format_t::msgpack, number) and sax->number_unsigned(number);
6263 std::uint16_t number;
6264 return get_number(input_format_t::msgpack, number) and sax->number_unsigned(number);
6269 std::uint32_t number;
6270 return get_number(input_format_t::msgpack, number) and sax->number_unsigned(number);
6275 std::uint64_t number;
6276 return get_number(input_format_t::msgpack, number) and sax->number_unsigned(number);
6282 return get_number(input_format_t::msgpack, number) and sax->number_integer(number);
6287 std::int16_t number;
6288 return get_number(input_format_t::msgpack, number) and sax->number_integer(number);
6293 std::int32_t number;
6294 return get_number(input_format_t::msgpack, number) and sax->number_integer(number);
6299 std::int64_t number;
6300 return get_number(input_format_t::msgpack, number) and sax->number_integer(number);
6306 return get_number(input_format_t::msgpack, len) and get_msgpack_array(
static_cast<std::size_t
>(len));
6312 return get_number(input_format_t::msgpack, len) and get_msgpack_array(
static_cast<std::size_t
>(len));
6318 return get_number(input_format_t::msgpack, len) and get_msgpack_object(
static_cast<std::size_t
>(len));
6324 return get_number(input_format_t::msgpack, len) and get_msgpack_object(
static_cast<std::size_t
>(len));
6360 return sax->number_integer(
static_cast<std::int8_t
>(current));
6364 auto last_token = get_token_string();
6365 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")));
6380 bool get_msgpack_string(string_t& result)
6382 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::msgpack,
"string")))
6423 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
6429 return get_number(input_format_t::msgpack, len) and get_string(input_format_t::msgpack, len, result);
6435 return get_number(input_format_t::msgpack, len) and get_string(input_format_t::msgpack, len, result);
6441 return get_number(input_format_t::msgpack, len) and get_string(input_format_t::msgpack, len, result);
6446 auto last_token = get_token_string();
6447 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")));
6456 bool get_msgpack_array(
const std::size_t len)
6458 if (JSON_HEDLEY_UNLIKELY(not sax->start_array(len)))
6463 for (std::size_t i = 0; i < len; ++i)
6465 if (JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal()))
6471 return sax->end_array();
6478 bool get_msgpack_object(
const std::size_t len)
6480 if (JSON_HEDLEY_UNLIKELY(not sax->start_object(len)))
6486 for (std::size_t i = 0; i < len; ++i)
6489 if (JSON_HEDLEY_UNLIKELY(not get_msgpack_string(key) or not sax->key(key)))
6494 if (JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal()))
6501 return sax->end_object();
6515 bool parse_ubjson_internal(
const bool get_char =
true)
6517 return get_ubjson_value(get_char ? get_ignore_noop() : current);
6534 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
6541 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson,
"value")))
6551 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6557 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6563 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6569 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6575 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6579 auto last_token = get_token_string();
6580 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")));
6588 bool get_ubjson_size_value(std::size_t& result)
6590 switch (get_ignore_noop())
6594 std::uint8_t number;
6595 if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
6599 result =
static_cast<std::size_t
>(number);
6606 if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
6610 result =
static_cast<std::size_t
>(number);
6616 std::int16_t number;
6617 if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
6621 result =
static_cast<std::size_t
>(number);
6627 std::int32_t number;
6628 if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
6632 result =
static_cast<std::size_t
>(number);
6638 std::int64_t number;
6639 if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
6643 result =
static_cast<std::size_t
>(number);
6649 auto last_token = get_token_string();
6650 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")));
6665 bool get_ubjson_size_type(std::pair<std::size_t, int>& result)
6667 result.first = string_t::npos;
6674 result.second = get();
6675 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson,
"type")))
6681 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
6683 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson,
"value")))
6687 auto last_token = get_token_string();
6688 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")));
6691 return get_ubjson_size_value(result.first);
6696 return get_ubjson_size_value(result.first);
6706 bool get_ubjson_value(
const int prefix)
6710 case std::char_traits<char>::eof():
6714 return sax->boolean(
true);
6716 return sax->boolean(
false);
6723 std::uint8_t number;
6724 return get_number(input_format_t::ubjson, number) and sax->number_unsigned(number);
6730 return get_number(input_format_t::ubjson, number) and sax->number_integer(number);
6735 std::int16_t number;
6736 return get_number(input_format_t::ubjson, number) and sax->number_integer(number);
6741 std::int32_t number;
6742 return get_number(input_format_t::ubjson, number) and sax->number_integer(number);
6747 std::int64_t number;
6748 return get_number(input_format_t::ubjson, number) and sax->number_integer(number);
6754 return get_number(input_format_t::ubjson, number) and sax->number_float(
static_cast<number_float_t
>(number),
"");
6760 return get_number(input_format_t::ubjson, number) and sax->number_float(
static_cast<number_float_t
>(number),
"");
6766 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson,
"char")))
6770 if (JSON_HEDLEY_UNLIKELY(current > 127))
6772 auto last_token = get_token_string();
6773 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")));
6775 string_t s(1,
static_cast<char>(current));
6776 return sax->string(s);
6782 return get_ubjson_string(s) and sax->string(s);
6786 return get_ubjson_array();
6789 return get_ubjson_object();
6793 auto last_token = get_token_string();
6794 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")));
6802 bool get_ubjson_array()
6804 std::pair<std::size_t, int> size_and_type;
6805 if (JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
6810 if (size_and_type.first != string_t::npos)
6812 if (JSON_HEDLEY_UNLIKELY(not sax->start_array(size_and_type.first)))
6817 if (size_and_type.second != 0)
6819 if (size_and_type.second !=
'N')
6821 for (std::size_t i = 0; i < size_and_type.first; ++i)
6823 if (JSON_HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.second)))
6832 for (std::size_t i = 0; i < size_and_type.first; ++i)
6834 if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
6843 if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
6848 while (current !=
']')
6850 if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal(
false)))
6858 return sax->end_array();
6864 bool get_ubjson_object()
6866 std::pair<std::size_t, int> size_and_type;
6867 if (JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
6873 if (size_and_type.first != string_t::npos)
6875 if (JSON_HEDLEY_UNLIKELY(not sax->start_object(size_and_type.first)))
6880 if (size_and_type.second != 0)
6882 for (std::size_t i = 0; i < size_and_type.first; ++i)
6884 if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
6888 if (JSON_HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.second)))
6897 for (std::size_t i = 0; i < size_and_type.first; ++i)
6899 if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
6903 if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
6913 if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
6918 while (current !=
'}')
6920 if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key,
false) or not sax->key(key)))
6924 if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
6933 return sax->end_object();
6952 return current = ia->get_character();
6958 int get_ignore_noop()
6964 while (current ==
'N');
6982 template<
typename NumberType,
bool InputIsLittleEndian = false>
6986 std::array<std::uint8_t,
sizeof(NumberType)> vec;
6987 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
6990 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(format,
"number")))
6996 if (is_little_endian != InputIsLittleEndian)
6998 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
7002 vec[i] =
static_cast<std::uint8_t
>(current);
7007 std::memcpy(&result, vec.data(),
sizeof(NumberType));
7025 template<
typename NumberType>
7027 const NumberType len,
7030 bool success =
true;
7031 std::generate_n(std::back_inserter(result), len, [
this, &success, &format]()
7034 if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(format,
"string")))
7038 return static_cast<char>(current);
7048 JSON_HEDLEY_NON_NULL(3)
7049 bool unexpect_eof(const
input_format_t format, const
char* context)
const
7051 if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char>::eof()))
7053 return sax->parse_error(chars_read,
"<end of file>",
7054 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context)));
7062 std::string get_token_string()
const
7064 std::array<char, 3> cr{{}};
7065 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current));
7066 return std::string{cr.data()};
7076 const std::string& detail,
7077 const std::string& context)
const
7079 std::string error_msg =
"syntax error while parsing ";
7083 case input_format_t::cbor:
7084 error_msg +=
"CBOR";
7087 case input_format_t::msgpack:
7088 error_msg +=
"MessagePack";
7091 case input_format_t::ubjson:
7092 error_msg +=
"UBJSON";
7095 case input_format_t::bson:
7096 error_msg +=
"BSON";
7103 return error_msg +
" " + context +
": " + detail;
7111 int current = std::char_traits<char>::eof();
7114 std::size_t chars_read = 0;
7120 json_sax_t* sax =
nullptr;
7135#include <initializer_list>
7160template<
typename BasicJsonType>
7163 using number_integer_t =
typename BasicJsonType::number_integer_t;
7164 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7165 using number_float_t =
typename BasicJsonType::number_float_t;
7166 using string_t =
typename BasicJsonType::string_t;
7192 JSON_HEDLEY_RETURNS_NON_NULL
7199 return "<uninitialized>";
7201 return "true literal";
7203 return "false literal";
7205 return "null literal";
7207 return "string literal";
7211 return "number literal";
7225 return "<parse error>";
7227 return "end of input";
7229 return "'[', '{', or a literal";
7232 return "unknown token";
7238 : ia(std::move(adapter)), decimal_point_char(get_decimal_point()) {}
7241 lexer(
const lexer&) =
delete;
7242 lexer(lexer&&) =
delete;
7243 lexer& operator=(lexer&) =
delete;
7244 lexer& operator=(lexer&&) =
delete;
7254 static char get_decimal_point() noexcept
7256 const auto loc = localeconv();
7257 assert(loc !=
nullptr);
7258 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7283 assert(current ==
'u');
7286 const auto factors = { 12u, 8u, 4u, 0u };
7287 for (
const auto factor : factors)
7291 if (current >=
'0' and current <=
'9')
7293 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7295 else if (current >=
'A' and current <=
'F')
7297 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7299 else if (current >=
'a' and current <=
'f')
7301 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7309 assert(0x0000 <= codepoint and codepoint <= 0xFFFF);
7328 bool next_byte_in_range(std::initializer_list<int> ranges)
7330 assert(ranges.size() == 2 or ranges.size() == 4 or ranges.size() == 6);
7333 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7336 if (JSON_HEDLEY_LIKELY(*range <= current and current <= *(++range)))
7342 error_message =
"invalid string: ill-formed UTF-8 byte";
7371 assert(current ==
'\"');
7379 case std::char_traits<char>::eof():
7381 error_message =
"invalid string: missing closing quote";
7388 return token_type::value_string;
7432 const int codepoint1 = get_codepoint();
7433 int codepoint = codepoint1;
7435 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
7437 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7438 return token_type::parse_error;
7442 if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF)
7445 if (JSON_HEDLEY_LIKELY(get() ==
'\\' and get() ==
'u'))
7447 const int codepoint2 = get_codepoint();
7449 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
7451 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7452 return token_type::parse_error;
7456 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF))
7459 codepoint =
static_cast<int>(
7461 (
static_cast<unsigned int>(codepoint1) << 10u)
7463 +
static_cast<unsigned int>(codepoint2)
7471 error_message =
"invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF";
7472 return token_type::parse_error;
7477 error_message =
"invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF";
7478 return token_type::parse_error;
7483 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 and codepoint1 <= 0xDFFF))
7485 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7486 return token_type::parse_error;
7491 assert(0x00 <= codepoint and codepoint <= 0x10FFFF);
7494 if (codepoint < 0x80)
7499 else if (codepoint <= 0x7FF)
7502 add(
static_cast<int>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7503 add(
static_cast<int>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7505 else if (codepoint <= 0xFFFF)
7508 add(
static_cast<int>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7509 add(
static_cast<int>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7510 add(
static_cast<int>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7515 add(
static_cast<int>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7516 add(
static_cast<int>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7517 add(
static_cast<int>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7518 add(
static_cast<int>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7526 error_message =
"invalid string: forbidden character after backslash";
7527 return token_type::parse_error;
7536 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7537 return token_type::parse_error;
7542 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7543 return token_type::parse_error;
7548 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7549 return token_type::parse_error;
7554 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7555 return token_type::parse_error;
7560 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7561 return token_type::parse_error;
7566 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7567 return token_type::parse_error;
7572 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7573 return token_type::parse_error;
7578 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7579 return token_type::parse_error;
7584 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7585 return token_type::parse_error;
7590 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7591 return token_type::parse_error;
7596 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7597 return token_type::parse_error;
7602 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7603 return token_type::parse_error;
7608 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7609 return token_type::parse_error;
7614 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7615 return token_type::parse_error;
7620 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7621 return token_type::parse_error;
7626 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7627 return token_type::parse_error;
7632 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7633 return token_type::parse_error;
7638 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7639 return token_type::parse_error;
7644 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7645 return token_type::parse_error;
7650 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7651 return token_type::parse_error;
7656 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7657 return token_type::parse_error;
7662 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7663 return token_type::parse_error;
7668 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7669 return token_type::parse_error;
7674 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7675 return token_type::parse_error;
7680 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7681 return token_type::parse_error;
7686 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7687 return token_type::parse_error;
7692 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7693 return token_type::parse_error;
7698 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7699 return token_type::parse_error;
7704 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7705 return token_type::parse_error;
7710 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7711 return token_type::parse_error;
7716 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7717 return token_type::parse_error;
7722 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7723 return token_type::parse_error;
7858 if (JSON_HEDLEY_UNLIKELY(not next_byte_in_range({0x80, 0xBF})))
7860 return token_type::parse_error;
7868 if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7870 return token_type::parse_error;
7892 if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7894 return token_type::parse_error;
7902 if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7904 return token_type::parse_error;
7912 if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7914 return token_type::parse_error;
7924 if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7926 return token_type::parse_error;
7934 if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7936 return token_type::parse_error;
7944 error_message =
"invalid string: ill-formed UTF-8 byte";
7945 return token_type::parse_error;
7951 JSON_HEDLEY_NON_NULL(2)
7952 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
7954 f = std::strtof(str, endptr);
7957 JSON_HEDLEY_NON_NULL(2)
7958 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
7960 f = std::strtod(str, endptr);
7963 JSON_HEDLEY_NON_NULL(2)
7964 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
7966 f = std::strtold(str, endptr);
8009 token_type scan_number()
8016 token_type number_type = token_type::value_unsigned;
8024 goto scan_number_minus;
8030 goto scan_number_zero;
8044 goto scan_number_any1;
8054 number_type = token_type::value_integer;
8060 goto scan_number_zero;
8074 goto scan_number_any1;
8079 error_message =
"invalid number; expected digit after '-'";
8080 return token_type::parse_error;
8090 add(decimal_point_char);
8091 goto scan_number_decimal1;
8098 goto scan_number_exponent;
8102 goto scan_number_done;
8121 goto scan_number_any1;
8126 add(decimal_point_char);
8127 goto scan_number_decimal1;
8134 goto scan_number_exponent;
8138 goto scan_number_done;
8141scan_number_decimal1:
8143 number_type = token_type::value_float;
8158 goto scan_number_decimal2;
8163 error_message =
"invalid number; expected digit after '.'";
8164 return token_type::parse_error;
8168scan_number_decimal2:
8184 goto scan_number_decimal2;
8191 goto scan_number_exponent;
8195 goto scan_number_done;
8198scan_number_exponent:
8200 number_type = token_type::value_float;
8207 goto scan_number_sign;
8222 goto scan_number_any2;
8228 "invalid number; expected '+', '-', or digit after exponent";
8229 return token_type::parse_error;
8249 goto scan_number_any2;
8254 error_message =
"invalid number; expected digit after exponent sign";
8255 return token_type::parse_error;
8275 goto scan_number_any2;
8279 goto scan_number_done;
8287 char* endptr =
nullptr;
8291 if (number_type == token_type::value_unsigned)
8293 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8296 assert(endptr == token_buffer.data() + token_buffer.size());
8300 value_unsigned =
static_cast<number_unsigned_t
>(x);
8301 if (value_unsigned == x)
8303 return token_type::value_unsigned;
8307 else if (number_type == token_type::value_integer)
8309 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8312 assert(endptr == token_buffer.data() + token_buffer.size());
8316 value_integer =
static_cast<number_integer_t
>(x);
8317 if (value_integer == x)
8319 return token_type::value_integer;
8326 strtof(value_float, token_buffer.data(), &endptr);
8329 assert(endptr == token_buffer.data() + token_buffer.size());
8331 return token_type::value_float;
8339 JSON_HEDLEY_NON_NULL(2)
8340 token_type scan_literal(const
char* literal_text, const std::
size_t length,
8341 token_type return_type)
8343 assert(current == literal_text[0]);
8344 for (std::size_t i = 1; i < length; ++i)
8346 if (JSON_HEDLEY_UNLIKELY(get() != literal_text[i]))
8348 error_message =
"invalid literal";
8349 return token_type::parse_error;
8360 void reset() noexcept
8362 token_buffer.clear();
8363 token_string.clear();
8364 token_string.push_back(std::char_traits<char>::to_char_type(current));
8377 std::char_traits<char>::int_type get()
8379 ++position.chars_read_total;
8380 ++position.chars_read_current_line;
8389 current = ia->get_character();
8392 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char>::eof()))
8394 token_string.push_back(std::char_traits<char>::to_char_type(current));
8397 if (current ==
'\n')
8399 ++position.lines_read;
8400 position.chars_read_current_line = 0;
8418 --position.chars_read_total;
8421 if (position.chars_read_current_line == 0)
8423 if (position.lines_read > 0)
8425 --position.lines_read;
8430 --position.chars_read_current_line;
8433 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char>::eof()))
8435 assert(not token_string.empty());
8436 token_string.pop_back();
8443 token_buffer.push_back(std::char_traits<char>::to_char_type(c));
8454 return value_integer;
8460 return value_unsigned;
8472 return token_buffer;
8492 for (
const auto c : token_string)
8494 if (
'\x00' <= c and c <=
'\x1F')
8497 std::array<char, 9> cs{{}};
8498 (std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c));
8499 result += cs.data();
8504 result.push_back(c);
8512 JSON_HEDLEY_RETURNS_NON_NULL
8515 return error_message;
8531 return get() == 0xBB and get() == 0xBF;
8543 if (position.chars_read_total == 0 and not skip_bom())
8545 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8546 return token_type::parse_error;
8554 while (current ==
' ' or current ==
'\t' or current ==
'\n' or current ==
'\r');
8560 return token_type::begin_array;
8562 return token_type::end_array;
8564 return token_type::begin_object;
8566 return token_type::end_object;
8568 return token_type::name_separator;
8570 return token_type::value_separator;
8574 return scan_literal(
"true", 4, token_type::literal_true);
8576 return scan_literal(
"false", 5, token_type::literal_false);
8578 return scan_literal(
"null", 4, token_type::literal_null);
8582 return scan_string();
8596 return scan_number();
8601 case std::char_traits<char>::eof():
8602 return token_type::end_of_input;
8606 error_message =
"invalid literal";
8607 return token_type::parse_error;
8616 std::char_traits<char>::int_type current = std::char_traits<char>::eof();
8619 bool next_unget =
false;
8625 std::vector<char> token_string {};
8628 string_t token_buffer {};
8631 const char* error_message =
"";
8634 number_integer_t value_integer = 0;
8635 number_unsigned_t value_unsigned = 0;
8636 number_float_t value_float = 0;
8639 const char decimal_point_char =
'.';
8650#include <functional>
8683template<
typename BasicJsonType>
8686 using number_integer_t =
typename BasicJsonType::number_integer_t;
8687 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8688 using number_float_t =
typename BasicJsonType::number_float_t;
8689 using string_t =
typename BasicJsonType::string_t;
8710 using parser_callback_t =
8711 std::function<bool(
int depth,
parse_event_t event, BasicJsonType& parsed)>;
8715 const parser_callback_t cb =
nullptr,
8716 const bool allow_exceptions_ =
true)
8717 : callback(cb), m_lexer(std::move(adapter)), allow_exceptions(allow_exceptions_)
8738 sax_parse_internal(&sdp);
8739 result.assert_invariant();
8742 if (
strict and (get_token() != token_type::end_of_input))
8744 sdp.parse_error(m_lexer.get_position(),
8745 m_lexer.get_token_string(),
8747 exception_message(token_type::end_of_input,
"value")));
8751 if (sdp.is_errored())
8759 if (result.is_discarded())
8767 sax_parse_internal(&sdp);
8768 result.assert_invariant();
8771 if (
strict and (get_token() != token_type::end_of_input))
8773 sdp.parse_error(m_lexer.get_position(),
8774 m_lexer.get_token_string(),
8776 exception_message(token_type::end_of_input,
"value")));
8780 if (sdp.is_errored())
8797 return sax_parse(&sax_acceptor,
strict);
8800 template <
typename SAX>
8801 JSON_HEDLEY_NON_NULL(2)
8802 bool sax_parse(SAX* sax, const
bool strict = true)
8805 const bool result = sax_parse_internal(sax);
8808 if (result and
strict and (get_token() != token_type::end_of_input))
8813 exception_message(token_type::end_of_input,
"value")));
8820 template <
typename SAX>
8821 JSON_HEDLEY_NON_NULL(2)
8822 bool sax_parse_internal(SAX* sax)
8826 std::vector<bool> states;
8828 bool skip_to_state_evaluation =
false;
8832 if (not skip_to_state_evaluation)
8837 case token_type::begin_object:
8839 if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
8845 if (get_token() == token_type::end_object)
8847 if (JSON_HEDLEY_UNLIKELY(not sax->end_object()))
8855 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
8857 return sax->parse_error(m_lexer.get_position(),
8858 m_lexer.get_token_string(),
8860 exception_message(token_type::value_string,
"object key")));
8862 if (JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
8868 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
8870 return sax->parse_error(m_lexer.get_position(),
8871 m_lexer.get_token_string(),
8873 exception_message(token_type::name_separator,
"object separator")));
8877 states.push_back(
false);
8884 case token_type::begin_array:
8886 if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
8892 if (get_token() == token_type::end_array)
8894 if (JSON_HEDLEY_UNLIKELY(not sax->end_array()))
8902 states.push_back(
true);
8908 case token_type::value_float:
8910 const auto res = m_lexer.get_number_float();
8912 if (JSON_HEDLEY_UNLIKELY(not std::isfinite(res)))
8914 return sax->parse_error(m_lexer.get_position(),
8915 m_lexer.get_token_string(),
8916 out_of_range::create(406,
"number overflow parsing '" + m_lexer.get_token_string() +
"'"));
8919 if (JSON_HEDLEY_UNLIKELY(not sax->number_float(res, m_lexer.get_string())))
8927 case token_type::literal_false:
8929 if (JSON_HEDLEY_UNLIKELY(not sax->boolean(
false)))
8936 case token_type::literal_null:
8938 if (JSON_HEDLEY_UNLIKELY(not sax->null()))
8945 case token_type::literal_true:
8947 if (JSON_HEDLEY_UNLIKELY(not sax->boolean(
true)))
8954 case token_type::value_integer:
8956 if (JSON_HEDLEY_UNLIKELY(not sax->number_integer(m_lexer.get_number_integer())))
8963 case token_type::value_string:
8965 if (JSON_HEDLEY_UNLIKELY(not sax->string(m_lexer.get_string())))
8972 case token_type::value_unsigned:
8974 if (JSON_HEDLEY_UNLIKELY(not sax->number_unsigned(m_lexer.get_number_unsigned())))
8981 case token_type::parse_error:
8984 return sax->parse_error(m_lexer.get_position(),
8985 m_lexer.get_token_string(),
8987 exception_message(token_type::uninitialized,
"value")));
8992 return sax->parse_error(m_lexer.get_position(),
8993 m_lexer.get_token_string(),
8995 exception_message(token_type::literal_or_value,
"value")));
9001 skip_to_state_evaluation =
false;
9014 if (get_token() == token_type::value_separator)
9022 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
9024 if (JSON_HEDLEY_UNLIKELY(not sax->end_array()))
9033 assert(not states.empty());
9035 skip_to_state_evaluation =
true;
9039 return sax->parse_error(m_lexer.get_position(),
9040 m_lexer.get_token_string(),
9042 exception_message(token_type::end_array,
"array")));
9047 if (get_token() == token_type::value_separator)
9050 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
9052 return sax->parse_error(m_lexer.get_position(),
9053 m_lexer.get_token_string(),
9055 exception_message(token_type::value_string,
"object key")));
9058 if (JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
9064 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
9066 return sax->parse_error(m_lexer.get_position(),
9067 m_lexer.get_token_string(),
9069 exception_message(token_type::name_separator,
"object separator")));
9078 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
9080 if (JSON_HEDLEY_UNLIKELY(not sax->end_object()))
9089 assert(not states.empty());
9091 skip_to_state_evaluation =
true;
9095 return sax->parse_error(m_lexer.get_position(),
9096 m_lexer.get_token_string(),
9098 exception_message(token_type::end_object,
"object")));
9104 token_type get_token()
9106 return last_token = m_lexer.scan();
9109 std::string exception_message(
const token_type expected,
const std::string& context)
9111 std::string error_msg =
"syntax error ";
9113 if (not context.empty())
9115 error_msg +=
"while parsing " + context +
" ";
9120 if (last_token == token_type::parse_error)
9122 error_msg += std::string(m_lexer.get_error_message()) +
"; last read: '" +
9123 m_lexer.get_token_string() +
"'";
9130 if (expected != token_type::uninitialized)
9140 const parser_callback_t callback =
nullptr;
9142 token_type last_token = token_type::uninitialized;
9146 const bool allow_exceptions =
true;
9176 using difference_type = std::ptrdiff_t;
9177 static constexpr difference_type begin_value = 0;
9178 static constexpr difference_type end_value = begin_value + 1;
9181 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
9184 constexpr difference_type get_value()
const noexcept
9204 return m_it == begin_value;
9210 return m_it == end_value;
9215 return lhs.m_it == rhs.m_it;
9218 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
9220 return lhs.m_it < rhs.m_it;
9223 primitive_iterator_t operator+(difference_type n)
noexcept
9225 auto result = *
this;
9230 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
9232 return lhs.m_it - rhs.m_it;
9235 primitive_iterator_t& operator++() noexcept
9241 primitive_iterator_t
const operator++(
int)
noexcept
9243 auto result = *
this;
9248 primitive_iterator_t& operator--() noexcept
9254 primitive_iterator_t
const operator--(
int)
noexcept
9256 auto result = *
this;
9261 primitive_iterator_t& operator+=(difference_type n)
noexcept
9267 primitive_iterator_t& operator-=(difference_type n)
noexcept
9304#include <type_traits>
9345template<
typename BasicJsonType>
9350 friend BasicJsonType;
9354 using object_t =
typename BasicJsonType::object_t;
9355 using array_t =
typename BasicJsonType::array_t;
9358 "iter_impl only accepts (const) basic_json");
9374 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
9375 typename BasicJsonType::const_pointer,
9376 typename BasicJsonType::pointer>::type;
9379 typename std::conditional<std::is_const<BasicJsonType>::value,
9380 typename BasicJsonType::const_reference,
9381 typename BasicJsonType::reference>::type;
9394 assert(m_object !=
nullptr);
9396 switch (m_object->m_type)
9400 m_it.object_iterator =
typename object_t::iterator();
9406 m_it.array_iterator =
typename array_t::iterator();
9435 : m_object(other.m_object), m_it(other.m_it)
9446 m_object = other.m_object;
9457 : m_object(other.m_object), m_it(other.m_it)
9468 m_object = other.m_object;
9478 void set_begin() noexcept
9480 assert(m_object !=
nullptr);
9482 switch (m_object->m_type)
9486 m_it.object_iterator = m_object->m_value.object->begin();
9492 m_it.array_iterator = m_object->m_value.array->begin();
9499 m_it.primitive_iterator.set_end();
9505 m_it.primitive_iterator.set_begin();
9515 void set_end() noexcept
9517 assert(m_object !=
nullptr);
9519 switch (m_object->m_type)
9523 m_it.object_iterator = m_object->m_value.object->end();
9529 m_it.array_iterator = m_object->m_value.array->end();
9535 m_it.primitive_iterator.set_end();
9548 assert(m_object !=
nullptr);
9550 switch (m_object->m_type)
9554 assert(m_it.object_iterator != m_object->m_value.object->end());
9555 return m_it.object_iterator->second;
9560 assert(m_it.array_iterator != m_object->m_value.array->end());
9561 return *m_it.array_iterator;
9565 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
9569 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
9574 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
9585 assert(m_object !=
nullptr);
9587 switch (m_object->m_type)
9591 assert(m_it.object_iterator != m_object->m_value.object->end());
9592 return &(m_it.object_iterator->second);
9597 assert(m_it.array_iterator != m_object->m_value.array->end());
9598 return &*m_it.array_iterator;
9603 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
9608 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
9619 auto result = *
this;
9630 assert(m_object !=
nullptr);
9632 switch (m_object->m_type)
9636 std::advance(m_it.object_iterator, 1);
9642 std::advance(m_it.array_iterator, 1);
9648 ++m_it.primitive_iterator;
9662 auto result = *
this;
9673 assert(m_object !=
nullptr);
9675 switch (m_object->m_type)
9679 std::advance(m_it.object_iterator, -1);
9685 std::advance(m_it.array_iterator, -1);
9691 --m_it.primitive_iterator;
9706 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
9708 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
9711 assert(m_object !=
nullptr);
9713 switch (m_object->m_type)
9716 return (m_it.object_iterator == other.m_it.object_iterator);
9719 return (m_it.array_iterator == other.m_it.array_iterator);
9722 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
9742 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
9744 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
9747 assert(m_object !=
nullptr);
9749 switch (m_object->m_type)
9752 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
9755 return (m_it.array_iterator < other.m_it.array_iterator);
9758 return (m_it.primitive_iterator < other.m_it.primitive_iterator);
9768 return not other.operator < (*this);
9795 assert(m_object !=
nullptr);
9797 switch (m_object->m_type)
9800 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
9804 std::advance(m_it.array_iterator, i);
9810 m_it.primitive_iterator += i;
9833 auto result = *
this;
9855 auto result = *
this;
9866 assert(m_object !=
nullptr);
9868 switch (m_object->m_type)
9871 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
9874 return m_it.array_iterator - other.m_it.array_iterator;
9877 return m_it.primitive_iterator - other.m_it.primitive_iterator;
9887 assert(m_object !=
nullptr);
9889 switch (m_object->m_type)
9892 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
9895 return *std::next(m_it.array_iterator, n);
9898 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
9902 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
9907 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
9916 const typename object_t::key_type&
key()
const
9918 assert(m_object !=
nullptr);
9920 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
9922 return m_it.object_iterator->first;
9925 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators"));
9981template<
typename Base>
9985 using difference_type = std::ptrdiff_t;
10053 auto key() const -> decltype(std::declval<Base>().
key())
10055 auto it = --this->base();
10062 auto it = --this->base();
10063 return it.operator * ();
10074#include <algorithm>
10091template<
typename BasicJsonType>
10095 NLOHMANN_BASIC_JSON_TPL_DECLARATION
10096 friend class basic_json;
10121 : reference_tokens(split(s))
10140 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
10142 [](
const std::string & a,
const std::string & b)
10144 return a +
"/" + escape(b);
10149 operator std::string()
const
10172 reference_tokens.insert(reference_tokens.end(),
10173 ptr.reference_tokens.begin(),
10174 ptr.reference_tokens.end());
10218 return *
this /= std::to_string(array_index);
10322 if (JSON_HEDLEY_UNLIKELY(
empty()))
10324 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
10327 reference_tokens.pop_back();
10346 if (JSON_HEDLEY_UNLIKELY(
empty()))
10348 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
10351 return reference_tokens.back();
10368 reference_tokens.push_back(token);
10374 reference_tokens.push_back(std::move(token));
10393 return reference_tokens.empty();
10404 static int array_index(
const std::string& s)
10406 std::size_t processed_chars = 0;
10407 const int res = std::stoi(s, &processed_chars);
10410 if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
10412 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'"));
10420 if (JSON_HEDLEY_UNLIKELY(
empty()))
10422 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
10426 result.reference_tokens = {reference_tokens[0]};
10438 BasicJsonType& get_and_create(BasicJsonType& j)
const
10440 using size_type =
typename BasicJsonType::size_type;
10445 for (
const auto& reference_token : reference_tokens)
10447 switch (result->type())
10451 if (reference_token ==
"0")
10454 result = &result->operator[](0);
10459 result = &result->operator[](reference_token);
10467 result = &result->operator[](reference_token);
10476 result = &result->operator[](
static_cast<size_type
>(array_index(reference_token)));
10478 JSON_CATCH(std::invalid_argument&)
10492 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten"));
10518 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
10520 using size_type =
typename BasicJsonType::size_type;
10521 for (
const auto& reference_token : reference_tokens)
10524 if (ptr->is_null())
10528 std::all_of(reference_token.begin(), reference_token.end(),
10529 [](
const unsigned char x)
10531 return std::isdigit(x);
10535 *ptr = (nums or reference_token ==
"-")
10540 switch (ptr->type())
10545 ptr = &ptr->operator[](reference_token);
10552 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] ==
'0'))
10555 "array index '" + reference_token +
10556 "' must not begin with '0'"));
10559 if (reference_token ==
"-")
10562 ptr = &ptr->operator[](ptr->m_value.array->size());
10569 ptr = &ptr->operator[](
10570 static_cast<size_type
>(array_index(reference_token)));
10572 JSON_CATCH(std::invalid_argument&)
10581 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'"));
10594 BasicJsonType& get_checked(BasicJsonType* ptr)
const
10596 using size_type =
typename BasicJsonType::size_type;
10597 for (
const auto& reference_token : reference_tokens)
10599 switch (ptr->type())
10604 ptr = &ptr->at(reference_token);
10610 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
10613 JSON_THROW(detail::out_of_range::create(402,
10614 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
10615 ") is out of range"));
10619 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] ==
'0'))
10622 "array index '" + reference_token +
10623 "' must not begin with '0'"));
10629 ptr = &ptr->at(
static_cast<size_type
>(array_index(reference_token)));
10631 JSON_CATCH(std::invalid_argument&)
10639 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'"));
10659 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
10661 using size_type =
typename BasicJsonType::size_type;
10662 for (
const auto& reference_token : reference_tokens)
10664 switch (ptr->type())
10669 ptr = &ptr->operator[](reference_token);
10675 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
10678 JSON_THROW(detail::out_of_range::create(402,
10679 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
10680 ") is out of range"));
10684 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] ==
'0'))
10687 "array index '" + reference_token +
10688 "' must not begin with '0'"));
10694 ptr = &ptr->operator[](
10695 static_cast<size_type
>(array_index(reference_token)));
10697 JSON_CATCH(std::invalid_argument&)
10705 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'"));
10718 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
10720 using size_type =
typename BasicJsonType::size_type;
10721 for (
const auto& reference_token : reference_tokens)
10723 switch (ptr->type())
10728 ptr = &ptr->at(reference_token);
10734 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
10737 JSON_THROW(detail::out_of_range::create(402,
10738 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
10739 ") is out of range"));
10743 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] ==
'0'))
10746 "array index '" + reference_token +
10747 "' must not begin with '0'"));
10753 ptr = &ptr->at(
static_cast<size_type
>(array_index(reference_token)));
10755 JSON_CATCH(std::invalid_argument&)
10763 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'"));
10774 bool contains(
const BasicJsonType* ptr)
const
10776 using size_type =
typename BasicJsonType::size_type;
10777 for (
const auto& reference_token : reference_tokens)
10779 switch (ptr->type())
10783 if (not ptr->contains(reference_token))
10789 ptr = &ptr->operator[](reference_token);
10795 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
10802 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] ==
'0'))
10805 "array index '" + reference_token +
10806 "' must not begin with '0'"));
10811 const auto idx =
static_cast<size_type
>(array_index(reference_token));
10812 if (idx >= ptr->size())
10818 ptr = &ptr->operator[](idx);
10821 JSON_CATCH(std::invalid_argument&)
10850 static std::vector<std::string> split(
const std::string& reference_string)
10852 std::vector<std::string> result;
10855 if (reference_string.empty())
10861 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
10864 "JSON pointer must be empty or begin with '/' - was: '" +
10865 reference_string +
"'"));
10873 std::size_t slash = reference_string.find_first_of(
'/', 1),
10880 start = (slash == std::string::npos) ? 0 : slash + 1,
10882 slash = reference_string.find_first_of(
'/', start))
10886 auto reference_token = reference_string.substr(start, slash - start);
10889 for (std::size_t pos = reference_token.find_first_of(
'~');
10890 pos != std::string::npos;
10891 pos = reference_token.find_first_of(
'~', pos + 1))
10893 assert(reference_token[pos] ==
'~');
10896 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 or
10897 (reference_token[pos + 1] !=
'0' and
10898 reference_token[pos + 1] !=
'1')))
10905 unescape(reference_token);
10906 result.push_back(reference_token);
10925 static void replace_substring(std::string& s,
const std::string& f,
10926 const std::string& t)
10928 assert(not f.empty());
10929 for (
auto pos = s.find(f);
10930 pos != std::string::npos;
10931 s.replace(pos, f.size(), t),
10932 pos = s.find(f, pos + t.size()))
10937 static std::string escape(std::string s)
10939 replace_substring(s,
"~",
"~0");
10940 replace_substring(s,
"/",
"~1");
10945 static void unescape(std::string& s)
10947 replace_substring(s,
"~1",
"/");
10948 replace_substring(s,
"~0",
"~");
10958 static void flatten(
const std::string& reference_string,
10959 const BasicJsonType& value,
10960 BasicJsonType& result)
10962 switch (value.type())
10966 if (value.m_value.array->empty())
10969 result[reference_string] =
nullptr;
10974 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
10976 flatten(reference_string +
"/" + std::to_string(i),
10977 value.m_value.array->operator[](i), result);
10985 if (value.m_value.object->empty())
10988 result[reference_string] =
nullptr;
10993 for (
const auto& element : *value.m_value.object)
10995 flatten(reference_string +
"/" + escape(element.first), element.second, result);
11004 result[reference_string] = value;
11020 static BasicJsonType
11021 unflatten(
const BasicJsonType& value)
11023 if (JSON_HEDLEY_UNLIKELY(not value.is_object()))
11025 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened"));
11028 BasicJsonType result;
11031 for (
const auto& element : *value.m_value.object)
11033 if (JSON_HEDLEY_UNLIKELY(not element.second.is_primitive()))
11035 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive"));
11042 json_pointer(element.first).get_and_create(result) = element.second;
11062 return lhs.reference_tokens == rhs.reference_tokens;
11079 return not (lhs == rhs);
11083 std::vector<std::string> reference_tokens;
11090#include <initializer_list>
11100template<
typename BasicJsonType>
11104 using value_type = BasicJsonType;
11106 json_ref(value_type&& value)
11107 : owned_value(std::move(value)), value_ref(&owned_value), is_rvalue(
true)
11110 json_ref(
const value_type& value)
11111 : value_ref(
const_cast<value_type*
>(&value)), is_rvalue(
false)
11114 json_ref(std::initializer_list<json_ref> init)
11115 : owned_value(init), value_ref(&owned_value), is_rvalue(
true)
11120 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
11121 json_ref(Args && ... args)
11122 : owned_value(std::forward<Args>(args)...), value_ref(&owned_value),
11126 json_ref(json_ref&&) =
default;
11127 json_ref(
const json_ref&) =
delete;
11128 json_ref& operator=(
const json_ref&) =
delete;
11129 json_ref& operator=(json_ref&&) =
delete;
11130 ~json_ref() =
default;
11132 value_type moved_or_copied()
const
11136 return std::move(*value_ref);
11141 value_type
const& operator*()
const
11143 return *
static_cast<value_type const*
>(value_ref);
11146 value_type
const* operator->()
const
11148 return static_cast<value_type const*
>(value_ref);
11152 mutable value_type owned_value =
nullptr;
11153 value_type* value_ref =
nullptr;
11154 const bool is_rvalue;
11168#include <algorithm>
11182#include <algorithm>
11200 virtual void write_character(CharType c) = 0;
11201 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
11206template<
typename CharType>
11210template<
typename CharType>
11214 explicit output_vector_adapter(std::vector<CharType>& vec) noexcept
11218 void write_character(CharType c)
override
11223 JSON_HEDLEY_NON_NULL(2)
11224 void write_characters(
const CharType* s, std::size_t length)
override
11226 std::copy(s, s + length, std::back_inserter(v));
11230 std::vector<CharType>& v;
11234template<
typename CharType>
11238 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
11242 void write_character(CharType c)
override
11247 JSON_HEDLEY_NON_NULL(2)
11248 void write_characters(
const CharType* s, std::size_t length)
override
11250 stream.write(s,
static_cast<std::streamsize
>(length));
11254 std::basic_ostream<CharType>& stream;
11258template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
11262 explicit output_string_adapter(StringType& s) noexcept
11266 void write_character(CharType c)
override
11271 JSON_HEDLEY_NON_NULL(2)
11272 void write_characters(
const CharType* s, std::size_t length)
override
11274 str.append(s, length);
11281template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
11282class output_adapter
11285 output_adapter(std::vector<CharType>& vec)
11288 output_adapter(std::basic_ostream<CharType>& s)
11291 output_adapter(StringType& s)
11317template<
typename BasicJsonType,
typename CharType>
11320 using string_t =
typename BasicJsonType::string_t;
11343 write_bson_object(*j.m_value.object);
11349 JSON_THROW(type_error::create(317,
"to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name())));
11363 oa->write_character(to_char_type(0xF6));
11369 oa->write_character(j.m_value.boolean
11370 ? to_char_type(0xF5)
11371 : to_char_type(0xF4));
11377 if (j.m_value.number_integer >= 0)
11382 if (j.m_value.number_integer <= 0x17)
11384 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
11386 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
11388 oa->write_character(to_char_type(0x18));
11389 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
11391 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
11393 oa->write_character(to_char_type(0x19));
11394 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
11396 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
11398 oa->write_character(to_char_type(0x1A));
11399 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
11403 oa->write_character(to_char_type(0x1B));
11404 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
11411 const auto positive_number = -1 - j.m_value.number_integer;
11412 if (j.m_value.number_integer >= -24)
11414 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
11416 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
11418 oa->write_character(to_char_type(0x38));
11419 write_number(
static_cast<std::uint8_t
>(positive_number));
11421 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
11423 oa->write_character(to_char_type(0x39));
11424 write_number(
static_cast<std::uint16_t
>(positive_number));
11426 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
11428 oa->write_character(to_char_type(0x3A));
11429 write_number(
static_cast<std::uint32_t
>(positive_number));
11433 oa->write_character(to_char_type(0x3B));
11434 write_number(
static_cast<std::uint64_t
>(positive_number));
11442 if (j.m_value.number_unsigned <= 0x17)
11444 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
11446 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
11448 oa->write_character(to_char_type(0x18));
11449 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
11451 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
11453 oa->write_character(to_char_type(0x19));
11454 write_number(
static_cast<std::uint16_t
>(j.m_value.number_unsigned));
11456 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
11458 oa->write_character(to_char_type(0x1A));
11459 write_number(
static_cast<std::uint32_t
>(j.m_value.number_unsigned));
11463 oa->write_character(to_char_type(0x1B));
11464 write_number(
static_cast<std::uint64_t
>(j.m_value.number_unsigned));
11471 oa->write_character(get_cbor_float_prefix(j.m_value.number_float));
11472 write_number(j.m_value.number_float);
11479 const auto N = j.m_value.string->size();
11482 write_number(
static_cast<std::uint8_t
>(0x60 + N));
11484 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
11486 oa->write_character(to_char_type(0x78));
11487 write_number(
static_cast<std::uint8_t
>(N));
11489 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11491 oa->write_character(to_char_type(0x79));
11492 write_number(
static_cast<std::uint16_t
>(N));
11494 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11496 oa->write_character(to_char_type(0x7A));
11497 write_number(
static_cast<std::uint32_t
>(N));
11500 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
11502 oa->write_character(to_char_type(0x7B));
11503 write_number(
static_cast<std::uint64_t
>(N));
11508 oa->write_characters(
11509 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
11510 j.m_value.string->size());
11517 const auto N = j.m_value.array->size();
11520 write_number(
static_cast<std::uint8_t
>(0x80 + N));
11522 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
11524 oa->write_character(to_char_type(0x98));
11525 write_number(
static_cast<std::uint8_t
>(N));
11527 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11529 oa->write_character(to_char_type(0x99));
11530 write_number(
static_cast<std::uint16_t
>(N));
11532 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11534 oa->write_character(to_char_type(0x9A));
11535 write_number(
static_cast<std::uint32_t
>(N));
11538 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
11540 oa->write_character(to_char_type(0x9B));
11541 write_number(
static_cast<std::uint64_t
>(N));
11546 for (
const auto& el : *j.m_value.array)
11556 const auto N = j.m_value.object->size();
11559 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
11561 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
11563 oa->write_character(to_char_type(0xB8));
11564 write_number(
static_cast<std::uint8_t
>(N));
11566 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11568 oa->write_character(to_char_type(0xB9));
11569 write_number(
static_cast<std::uint16_t
>(N));
11571 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11573 oa->write_character(to_char_type(0xBA));
11574 write_number(
static_cast<std::uint32_t
>(N));
11577 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
11579 oa->write_character(to_char_type(0xBB));
11580 write_number(
static_cast<std::uint64_t
>(N));
11585 for (
const auto& el : *j.m_value.object)
11607 oa->write_character(to_char_type(0xC0));
11613 oa->write_character(j.m_value.boolean
11614 ? to_char_type(0xC3)
11615 : to_char_type(0xC2));
11621 if (j.m_value.number_integer >= 0)
11626 if (j.m_value.number_unsigned < 128)
11629 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
11631 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
11634 oa->write_character(to_char_type(0xCC));
11635 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
11637 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
11640 oa->write_character(to_char_type(0xCD));
11641 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
11643 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
11646 oa->write_character(to_char_type(0xCE));
11647 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
11649 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
11652 oa->write_character(to_char_type(0xCF));
11653 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
11658 if (j.m_value.number_integer >= -32)
11661 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
11663 else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() and
11664 j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
11667 oa->write_character(to_char_type(0xD0));
11668 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
11670 else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() and
11671 j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
11674 oa->write_character(to_char_type(0xD1));
11675 write_number(
static_cast<std::int16_t
>(j.m_value.number_integer));
11677 else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() and
11678 j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
11681 oa->write_character(to_char_type(0xD2));
11682 write_number(
static_cast<std::int32_t
>(j.m_value.number_integer));
11684 else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() and
11685 j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
11688 oa->write_character(to_char_type(0xD3));
11689 write_number(
static_cast<std::int64_t
>(j.m_value.number_integer));
11697 if (j.m_value.number_unsigned < 128)
11700 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
11702 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
11705 oa->write_character(to_char_type(0xCC));
11706 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
11708 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
11711 oa->write_character(to_char_type(0xCD));
11712 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
11714 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
11717 oa->write_character(to_char_type(0xCE));
11718 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
11720 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
11723 oa->write_character(to_char_type(0xCF));
11724 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
11731 oa->write_character(get_msgpack_float_prefix(j.m_value.number_float));
11732 write_number(j.m_value.number_float);
11739 const auto N = j.m_value.string->size();
11743 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
11745 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
11748 oa->write_character(to_char_type(0xD9));
11749 write_number(
static_cast<std::uint8_t
>(N));
11751 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11754 oa->write_character(to_char_type(0xDA));
11755 write_number(
static_cast<std::uint16_t
>(N));
11757 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11760 oa->write_character(to_char_type(0xDB));
11761 write_number(
static_cast<std::uint32_t
>(N));
11765 oa->write_characters(
11766 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
11767 j.m_value.string->size());
11774 const auto N = j.m_value.array->size();
11778 write_number(
static_cast<std::uint8_t
>(0x90 | N));
11780 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11783 oa->write_character(to_char_type(0xDC));
11784 write_number(
static_cast<std::uint16_t
>(N));
11786 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11789 oa->write_character(to_char_type(0xDD));
11790 write_number(
static_cast<std::uint32_t
>(N));
11794 for (
const auto& el : *j.m_value.array)
11804 const auto N = j.m_value.object->size();
11808 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
11810 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11813 oa->write_character(to_char_type(0xDE));
11814 write_number(
static_cast<std::uint16_t
>(N));
11816 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11819 oa->write_character(to_char_type(0xDF));
11820 write_number(
static_cast<std::uint32_t
>(N));
11824 for (
const auto& el : *j.m_value.object)
11844 const bool use_type,
const bool add_prefix =
true)
11852 oa->write_character(to_char_type(
'Z'));
11861 oa->write_character(j.m_value.boolean
11862 ? to_char_type(
'T')
11863 : to_char_type(
'F'));
11870 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
11876 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
11882 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
11890 oa->write_character(to_char_type(
'S'));
11892 write_number_with_ubjson_prefix(j.m_value.string->size(),
true);
11893 oa->write_characters(
11894 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
11895 j.m_value.string->size());
11903 oa->write_character(to_char_type(
'['));
11906 bool prefix_required =
true;
11907 if (use_type and not j.m_value.array->empty())
11910 const CharType first_prefix = ubjson_prefix(j.front());
11911 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
11912 [
this, first_prefix](
const BasicJsonType & v)
11914 return ubjson_prefix(v) == first_prefix;
11919 prefix_required =
false;
11920 oa->write_character(to_char_type(
'$'));
11921 oa->write_character(first_prefix);
11927 oa->write_character(to_char_type(
'#'));
11928 write_number_with_ubjson_prefix(j.m_value.array->size(),
true);
11931 for (
const auto& el : *j.m_value.array)
11933 write_ubjson(el, use_count, use_type, prefix_required);
11938 oa->write_character(to_char_type(
']'));
11948 oa->write_character(to_char_type(
'{'));
11951 bool prefix_required =
true;
11952 if (use_type and not j.m_value.object->empty())
11955 const CharType first_prefix = ubjson_prefix(j.front());
11956 const bool same_prefix = std::all_of(j.begin(), j.end(),
11957 [
this, first_prefix](
const BasicJsonType & v)
11959 return ubjson_prefix(v) == first_prefix;
11964 prefix_required =
false;
11965 oa->write_character(to_char_type(
'$'));
11966 oa->write_character(first_prefix);
11972 oa->write_character(to_char_type(
'#'));
11973 write_number_with_ubjson_prefix(j.m_value.object->size(),
true);
11976 for (
const auto& el : *j.m_value.object)
11978 write_number_with_ubjson_prefix(el.first.size(),
true);
11979 oa->write_characters(
11980 reinterpret_cast<const CharType*
>(el.first.c_str()),
11982 write_ubjson(el.second, use_count, use_type, prefix_required);
11987 oa->write_character(to_char_type(
'}'));
12007 static std::size_t calc_bson_entry_header_size(
const string_t& name)
12009 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
12010 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
12012 JSON_THROW(out_of_range::create(409,
12013 "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) +
")"));
12016 return 1ul + name.size() + 1u;
12022 void write_bson_entry_header(
const string_t& name,
12023 const std::uint8_t element_type)
12025 oa->write_character(to_char_type(element_type));
12026 oa->write_characters(
12027 reinterpret_cast<const CharType*
>(name.c_str()),
12034 void write_bson_boolean(
const string_t& name,
12037 write_bson_entry_header(name, 0x08);
12038 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
12044 void write_bson_double(
const string_t& name,
12045 const double value)
12047 write_bson_entry_header(name, 0x01);
12048 write_number<double, true>(value);
12054 static std::size_t calc_bson_string_size(
const string_t& value)
12056 return sizeof(std::int32_t) + value.size() + 1ul;
12062 void write_bson_string(
const string_t& name,
12063 const string_t& value)
12065 write_bson_entry_header(name, 0x02);
12067 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size() + 1ul));
12068 oa->write_characters(
12069 reinterpret_cast<const CharType*
>(value.c_str()),
12076 void write_bson_null(
const string_t& name)
12078 write_bson_entry_header(name, 0x0A);
12084 static std::size_t calc_bson_integer_size(
const std::int64_t value)
12086 return (std::numeric_limits<std::int32_t>::min)() <= value and value <= (std::numeric_limits<std::int32_t>::max)()
12087 ?
sizeof(std::int32_t)
12088 :
sizeof(std::int64_t);
12094 void write_bson_integer(
const string_t& name,
12095 const std::int64_t value)
12097 if ((std::numeric_limits<std::int32_t>::min)() <= value and value <= (std::numeric_limits<std::int32_t>::max)())
12099 write_bson_entry_header(name, 0x10);
12100 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value));
12104 write_bson_entry_header(name, 0x12);
12105 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(value));
12112 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
12114 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
12115 ?
sizeof(std::int32_t)
12116 : sizeof(std::int64_t);
12122 void write_bson_unsigned(
const string_t& name,
12123 const std::uint64_t value)
12125 if (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
12127 write_bson_entry_header(name, 0x10 );
12128 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value));
12130 else if (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
12132 write_bson_entry_header(name, 0x12 );
12133 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(value));
12137 JSON_THROW(out_of_range::create(407,
"integer number " + std::to_string(value) +
" cannot be represented by BSON as it does not fit int64"));
12144 void write_bson_object_entry(
const string_t& name,
12145 const typename BasicJsonType::object_t& value)
12147 write_bson_entry_header(name, 0x03);
12148 write_bson_object(value);
12154 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
12156 std::size_t array_index = 0ul;
12158 const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), 0ul, [&array_index](std::size_t result,
const typename BasicJsonType::array_t::value_type & el)
12160 return result + calc_bson_element_size(std::to_string(array_index++), el);
12163 return sizeof(std::int32_t) + embedded_document_size + 1ul;
12169 void write_bson_array(
const string_t& name,
12170 const typename BasicJsonType::array_t& value)
12172 write_bson_entry_header(name, 0x04);
12173 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_array_size(value)));
12175 std::size_t array_index = 0ul;
12177 for (
const auto& el : value)
12179 write_bson_element(std::to_string(array_index++), el);
12182 oa->write_character(to_char_type(0x00));
12189 static std::size_t calc_bson_element_size(
const string_t& name,
12190 const BasicJsonType& j)
12192 const auto header_size = calc_bson_entry_header_size(name);
12196 return header_size + calc_bson_object_size(*j.m_value.object);
12199 return header_size + calc_bson_array_size(*j.m_value.array);
12202 return header_size + 1ul;
12205 return header_size + 8ul;
12208 return header_size + calc_bson_integer_size(j.m_value.number_integer);
12211 return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
12214 return header_size + calc_bson_string_size(*j.m_value.string);
12217 return header_size + 0ul;
12234 void write_bson_element(
const string_t& name,
12235 const BasicJsonType& j)
12240 return write_bson_object_entry(name, *j.m_value.object);
12243 return write_bson_array(name, *j.m_value.array);
12246 return write_bson_boolean(name, j.m_value.boolean);
12249 return write_bson_double(name, j.m_value.number_float);
12252 return write_bson_integer(name, j.m_value.number_integer);
12255 return write_bson_unsigned(name, j.m_value.number_unsigned);
12258 return write_bson_string(name, *j.m_value.string);
12261 return write_bson_null(name);
12277 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
12279 std::size_t document_size = std::accumulate(value.begin(), value.end(), 0ul,
12280 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
12282 return result += calc_bson_element_size(el.first, el.second);
12285 return sizeof(std::int32_t) + document_size + 1ul;
12292 void write_bson_object(
const typename BasicJsonType::object_t& value)
12294 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_object_size(value)));
12296 for (
const auto& el : value)
12298 write_bson_element(el.first, el.second);
12301 oa->write_character(to_char_type(0x00));
12308 static constexpr CharType get_cbor_float_prefix(
float )
12310 return to_char_type(0xFA);
12313 static constexpr CharType get_cbor_float_prefix(
double )
12315 return to_char_type(0xFB);
12322 static constexpr CharType get_msgpack_float_prefix(
float )
12324 return to_char_type(0xCA);
12327 static constexpr CharType get_msgpack_float_prefix(
double )
12329 return to_char_type(0xCB);
12337 template<
typename NumberType,
typename std::enable_if<
12338 std::is_floating_point<NumberType>::value,
int>::type = 0>
12339 void write_number_with_ubjson_prefix(
const NumberType n,
12340 const bool add_prefix)
12344 oa->write_character(get_ubjson_float_prefix(n));
12350 template<
typename NumberType,
typename std::enable_if<
12351 std::is_unsigned<NumberType>::value,
int>::type = 0>
12352 void write_number_with_ubjson_prefix(
const NumberType n,
12353 const bool add_prefix)
12355 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
12359 oa->write_character(to_char_type(
'i'));
12361 write_number(
static_cast<std::uint8_t
>(n));
12363 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
12367 oa->write_character(to_char_type(
'U'));
12369 write_number(
static_cast<std::uint8_t
>(n));
12371 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
12375 oa->write_character(to_char_type(
'I'));
12377 write_number(
static_cast<std::int16_t
>(n));
12379 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
12383 oa->write_character(to_char_type(
'l'));
12385 write_number(
static_cast<std::int32_t
>(n));
12387 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
12391 oa->write_character(to_char_type(
'L'));
12393 write_number(
static_cast<std::int64_t
>(n));
12397 JSON_THROW(out_of_range::create(407,
"integer number " + std::to_string(n) +
" cannot be represented by UBJSON as it does not fit int64"));
12402 template<
typename NumberType,
typename std::enable_if<
12403 std::is_signed<NumberType>::value and
12404 not std::is_floating_point<NumberType>::value,
int>::type = 0>
12405 void write_number_with_ubjson_prefix(
const NumberType n,
12406 const bool add_prefix)
12408 if ((std::numeric_limits<std::int8_t>::min)() <= n and n <= (std::numeric_limits<std::int8_t>::max)())
12412 oa->write_character(to_char_type(
'i'));
12414 write_number(
static_cast<std::int8_t
>(n));
12416 else if (
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::min)()) <= n and n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::max)()))
12420 oa->write_character(to_char_type(
'U'));
12422 write_number(
static_cast<std::uint8_t
>(n));
12424 else if ((std::numeric_limits<std::int16_t>::min)() <= n and n <= (std::numeric_limits<std::int16_t>::max)())
12428 oa->write_character(to_char_type(
'I'));
12430 write_number(
static_cast<std::int16_t
>(n));
12432 else if ((std::numeric_limits<std::int32_t>::min)() <= n and n <= (std::numeric_limits<std::int32_t>::max)())
12436 oa->write_character(to_char_type(
'l'));
12438 write_number(
static_cast<std::int32_t
>(n));
12440 else if ((std::numeric_limits<std::int64_t>::min)() <= n and n <= (std::numeric_limits<std::int64_t>::max)())
12444 oa->write_character(to_char_type(
'L'));
12446 write_number(
static_cast<std::int64_t
>(n));
12451 JSON_THROW(out_of_range::create(407,
"integer number " + std::to_string(n) +
" cannot be represented by UBJSON as it does not fit int64"));
12465 CharType ubjson_prefix(
const BasicJsonType& j)
const noexcept
12473 return j.m_value.boolean ?
'T' :
'F';
12477 if ((std::numeric_limits<std::int8_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
12481 if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
12485 if ((std::numeric_limits<std::int16_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
12489 if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
12499 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
12503 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
12507 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
12511 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
12520 return get_ubjson_float_prefix(j.m_value.number_float);
12536 static constexpr CharType get_ubjson_float_prefix(
float )
12541 static constexpr CharType get_ubjson_float_prefix(
double )
12561 template<
typename NumberType,
bool OutputIsLittleEndian = false>
12562 void write_number(
const NumberType n)
12565 std::array<CharType,
sizeof(NumberType)> vec;
12566 std::memcpy(vec.data(), &n,
sizeof(NumberType));
12569 if (is_little_endian != OutputIsLittleEndian)
12572 std::reverse(vec.begin(), vec.end());
12575 oa->write_characters(vec.data(),
sizeof(NumberType));
12583 template <
typename C = CharType,
12584 enable_if_t < std::is_signed<C>::value and std::is_signed<char>::value > * =
nullptr >
12585 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
12587 return *
reinterpret_cast<char*
>(&x);
12590 template <
typename C = CharType,
12591 enable_if_t < std::is_signed<C>::value and std::is_unsigned<char>::value > * =
nullptr >
12592 static CharType to_char_type(std::uint8_t x)
noexcept
12594 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
12595 static_assert(std::is_pod<CharType>::value,
"CharType must be POD");
12597 std::memcpy(&result, &x,
sizeof(x));
12601 template<
typename C = CharType,
12602 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
12603 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
12608 template <
typename InputCharType,
typename C = CharType,
12610 std::is_signed<C>::value and
12611 std::is_signed<char>::value and
12612 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
12614 static constexpr CharType to_char_type(InputCharType x)
noexcept
12634#include <algorithm>
12645#include <type_traits>
12658#include <type_traits>
12689template <
typename Target,
typename Source>
12690Target reinterpret_bits(
const Source source)
12692 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
12695 std::memcpy(&target, &source,
sizeof(Source));
12701 static constexpr int kPrecision = 64;
12703 std::uint64_t f = 0;
12706 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
12712 static diyfp
sub(
const diyfp& x,
const diyfp& y)
noexcept
12714 assert(x.e == y.e);
12715 assert(x.f >= y.f);
12717 return {x.f - y.f, x.e};
12724 static diyfp
mul(
const diyfp& x,
const diyfp& y)
noexcept
12726 static_assert(kPrecision == 64,
"internal error");
12751 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
12752 const std::uint64_t u_hi = x.f >> 32u;
12753 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
12754 const std::uint64_t v_hi = y.f >> 32u;
12756 const std::uint64_t p0 = u_lo * v_lo;
12757 const std::uint64_t p1 = u_lo * v_hi;
12758 const std::uint64_t p2 = u_hi * v_lo;
12759 const std::uint64_t p3 = u_hi * v_hi;
12761 const std::uint64_t p0_hi = p0 >> 32u;
12762 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
12763 const std::uint64_t p1_hi = p1 >> 32u;
12764 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
12765 const std::uint64_t p2_hi = p2 >> 32u;
12767 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
12778 Q += std::uint64_t{1} << (64u - 32u - 1u);
12780 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
12782 return {h, x.e + y.e + 64};
12793 while ((x.f >> 63u) == 0)
12808 const int delta = x.e - target_exponent;
12810 assert(delta >= 0);
12811 assert(((x.f << delta) >> delta) == x.f);
12813 return {x.f << delta, target_exponent};
12830template <
typename FloatType>
12833 assert(std::isfinite(value));
12843 static_assert(std::numeric_limits<FloatType>::is_iec559,
12844 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
12846 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
12847 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
12848 constexpr int kMinExp = 1 - kBias;
12849 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
12851 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
12853 const std::uint64_t bits = reinterpret_bits<bits_type>(value);
12854 const std::uint64_t E = bits >> (kPrecision - 1);
12855 const std::uint64_t F = bits & (kHiddenBit - 1);
12857 const bool is_denormal = E == 0;
12858 const diyfp v = is_denormal
12859 ?
diyfp(F, kMinExp)
12860 :
diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
12883 const bool lower_boundary_is_closer = F == 0 and E > 1;
12884 const diyfp m_plus =
diyfp(2 * v.f + 1, v.e - 1);
12885 const diyfp m_minus = lower_boundary_is_closer
12886 ?
diyfp(4 * v.f - 1, v.e - 2)
12887 :
diyfp(2 * v.f - 1, v.e - 1);
12953constexpr int kAlpha = -60;
12954constexpr int kGamma = -32;
13022 constexpr int kCachedPowersMinDecExp = -300;
13023 constexpr int kCachedPowersDecStep = 8;
13025 static constexpr std::array<cached_power, 79> kCachedPowers =
13028 { 0xAB70FE17C79AC6CA, -1060, -300 },
13029 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
13030 { 0xBE5691EF416BD60C, -1007, -284 },
13031 { 0x8DD01FAD907FFC3C, -980, -276 },
13032 { 0xD3515C2831559A83, -954, -268 },
13033 { 0x9D71AC8FADA6C9B5, -927, -260 },
13034 { 0xEA9C227723EE8BCB, -901, -252 },
13035 { 0xAECC49914078536D, -874, -244 },
13036 { 0x823C12795DB6CE57, -847, -236 },
13037 { 0xC21094364DFB5637, -821, -228 },
13038 { 0x9096EA6F3848984F, -794, -220 },
13039 { 0xD77485CB25823AC7, -768, -212 },
13040 { 0xA086CFCD97BF97F4, -741, -204 },
13041 { 0xEF340A98172AACE5, -715, -196 },
13042 { 0xB23867FB2A35B28E, -688, -188 },
13043 { 0x84C8D4DFD2C63F3B, -661, -180 },
13044 { 0xC5DD44271AD3CDBA, -635, -172 },
13045 { 0x936B9FCEBB25C996, -608, -164 },
13046 { 0xDBAC6C247D62A584, -582, -156 },
13047 { 0xA3AB66580D5FDAF6, -555, -148 },
13048 { 0xF3E2F893DEC3F126, -529, -140 },
13049 { 0xB5B5ADA8AAFF80B8, -502, -132 },
13050 { 0x87625F056C7C4A8B, -475, -124 },
13051 { 0xC9BCFF6034C13053, -449, -116 },
13052 { 0x964E858C91BA2655, -422, -108 },
13053 { 0xDFF9772470297EBD, -396, -100 },
13054 { 0xA6DFBD9FB8E5B88F, -369, -92 },
13055 { 0xF8A95FCF88747D94, -343, -84 },
13056 { 0xB94470938FA89BCF, -316, -76 },
13057 { 0x8A08F0F8BF0F156B, -289, -68 },
13058 { 0xCDB02555653131B6, -263, -60 },
13059 { 0x993FE2C6D07B7FAC, -236, -52 },
13060 { 0xE45C10C42A2B3B06, -210, -44 },
13061 { 0xAA242499697392D3, -183, -36 },
13062 { 0xFD87B5F28300CA0E, -157, -28 },
13063 { 0xBCE5086492111AEB, -130, -20 },
13064 { 0x8CBCCC096F5088CC, -103, -12 },
13065 { 0xD1B71758E219652C, -77, -4 },
13066 { 0x9C40000000000000, -50, 4 },
13067 { 0xE8D4A51000000000, -24, 12 },
13068 { 0xAD78EBC5AC620000, 3, 20 },
13069 { 0x813F3978F8940984, 30, 28 },
13070 { 0xC097CE7BC90715B3, 56, 36 },
13071 { 0x8F7E32CE7BEA5C70, 83, 44 },
13072 { 0xD5D238A4ABE98068, 109, 52 },
13073 { 0x9F4F2726179A2245, 136, 60 },
13074 { 0xED63A231D4C4FB27, 162, 68 },
13075 { 0xB0DE65388CC8ADA8, 189, 76 },
13076 { 0x83C7088E1AAB65DB, 216, 84 },
13077 { 0xC45D1DF942711D9A, 242, 92 },
13078 { 0x924D692CA61BE758, 269, 100 },
13079 { 0xDA01EE641A708DEA, 295, 108 },
13080 { 0xA26DA3999AEF774A, 322, 116 },
13081 { 0xF209787BB47D6B85, 348, 124 },
13082 { 0xB454E4A179DD1877, 375, 132 },
13083 { 0x865B86925B9BC5C2, 402, 140 },
13084 { 0xC83553C5C8965D3D, 428, 148 },
13085 { 0x952AB45CFA97A0B3, 455, 156 },
13086 { 0xDE469FBD99A05FE3, 481, 164 },
13087 { 0xA59BC234DB398C25, 508, 172 },
13088 { 0xF6C69A72A3989F5C, 534, 180 },
13089 { 0xB7DCBF5354E9BECE, 561, 188 },
13090 { 0x88FCF317F22241E2, 588, 196 },
13091 { 0xCC20CE9BD35C78A5, 614, 204 },
13092 { 0x98165AF37B2153DF, 641, 212 },
13093 { 0xE2A0B5DC971F303A, 667, 220 },
13094 { 0xA8D9D1535CE3B396, 694, 228 },
13095 { 0xFB9B7CD9A4A7443C, 720, 236 },
13096 { 0xBB764C4CA7A44410, 747, 244 },
13097 { 0x8BAB8EEFB6409C1A, 774, 252 },
13098 { 0xD01FEF10A657842C, 800, 260 },
13099 { 0x9B10A4E5E9913129, 827, 268 },
13100 { 0xE7109BFBA19C0C9D, 853, 276 },
13101 { 0xAC2820D9623BF429, 880, 284 },
13102 { 0x80444B5E7AA7CF85, 907, 292 },
13103 { 0xBF21E44003ACDD2D, 933, 300 },
13104 { 0x8E679C2F5E44FF8F, 960, 308 },
13105 { 0xD433179D9C8CB841, 986, 316 },
13106 { 0x9E19DB92B4E31BA9, 1013, 324 },
13114 assert(e >= -1500);
13116 const int f = kAlpha - e - 1;
13117 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
13119 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
13120 assert(index >= 0);
13121 assert(
static_cast<std::size_t
>(index) < kCachedPowers.size());
13123 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
13124 assert(kAlpha <= cached.e + e + 64);
13125 assert(kGamma >= cached.e + e + 64);
13137 if (n >= 1000000000)
13139 pow10 = 1000000000;
13143 else if (n >= 100000000)
13148 else if (n >= 10000000)
13153 else if (n >= 1000000)
13158 else if (n >= 100000)
13163 else if (n >= 10000)
13168 else if (n >= 1000)
13190inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
13191 std::uint64_t rest, std::uint64_t ten_k)
13194 assert(dist <= delta);
13195 assert(rest <= delta);
13218 and delta - rest >= ten_k
13219 and (rest + ten_k < dist or dist - rest > rest + ten_k - dist))
13221 assert(buf[len - 1] !=
'0');
13234 static_assert(kAlpha >= -60,
"internal error");
13235 static_assert(kGamma <= -32,
"internal error");
13249 assert(M_plus.e >= kAlpha);
13250 assert(M_plus.e <= kGamma);
13252 std::uint64_t delta =
diyfp::sub(M_plus, M_minus).f;
13253 std::uint64_t dist =
diyfp::sub(M_plus, w ).f;
13262 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
13264 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
13265 std::uint64_t p2 = M_plus.f & (one.f - 1);
13273 std::uint32_t pow10;
13301 const std::uint32_t d = p1 / pow10;
13302 const std::uint32_t r = p1 % pow10;
13308 buffer[length++] =
static_cast<char>(
'0' + d);
13327 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
13332 decimal_exponent += n;
13343 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
13344 grisu2_round(buffer, length, dist, delta, rest, ten_n);
13394 assert(p2 > delta);
13405 assert(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
13407 const std::uint64_t d = p2 >> -one.e;
13408 const std::uint64_t r = p2 & (one.f - 1);
13415 buffer[length++] =
static_cast<char>(
'0' + d);
13440 decimal_exponent -= m;
13448 const std::uint64_t ten_m = one.f;
13449 grisu2_round(buffer, length, dist, delta, p2, ten_m);
13471JSON_HEDLEY_NON_NULL(1)
13472inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
13475 assert(m_plus.e == m_minus.e);
13476 assert(m_plus.e == v.e);
13489 const diyfp c_minus_k(cached.f, cached.e);
13517 const diyfp M_minus(w_minus.f + 1, w_minus.e);
13518 const diyfp M_plus (w_plus.f - 1, w_plus.e );
13520 decimal_exponent = -cached.k;
13530template <
typename FloatType>
13531JSON_HEDLEY_NON_NULL(1)
13532void
grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
13534 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
13535 "internal error: not enough precision");
13537 assert(std::isfinite(value));
13562 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
13570JSON_HEDLEY_NON_NULL(1)
13571JSON_HEDLEY_RETURNS_NON_NULL
13587 auto k =
static_cast<std::uint32_t
>(e);
13593 *buf++ =
static_cast<char>(
'0' + k);
13597 *buf++ =
static_cast<char>(
'0' + k / 10);
13599 *buf++ =
static_cast<char>(
'0' + k);
13603 *buf++ =
static_cast<char>(
'0' + k / 100);
13605 *buf++ =
static_cast<char>(
'0' + k / 10);
13607 *buf++ =
static_cast<char>(
'0' + k);
13622JSON_HEDLEY_NON_NULL(1)
13623JSON_HEDLEY_RETURNS_NON_NULL
13625 int min_exp,
int max_exp)
13627 assert(min_exp < 0);
13628 assert(max_exp > 0);
13631 const int n = len + decimal_exponent;
13637 if (k <= n and n <= max_exp)
13642 std::memset(buf + k,
'0',
static_cast<size_t>(n - k));
13646 return buf + (n + 2);
13649 if (0 < n and n <= max_exp)
13656 std::memmove(buf + (n + 1), buf + n,
static_cast<size_t>(k - n));
13658 return buf + (k + 1);
13661 if (min_exp < n and n <= 0)
13666 std::memmove(buf + (2 + -n), buf,
static_cast<size_t>(k));
13669 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
13670 return buf + (2 + (-n) + k);
13685 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k - 1));
13706template <
typename FloatType>
13707JSON_HEDLEY_NON_NULL(1, 2)
13708JSON_HEDLEY_RETURNS_NON_NULL
13709char*
to_chars(
char* first, const
char* last, FloatType value)
13711 static_cast<void>(last);
13712 assert(std::isfinite(value));
13715 if (std::signbit(value))
13730 assert(last - first >= std::numeric_limits<FloatType>::max_digits10);
13737 int decimal_exponent = 0;
13740 assert(len <= std::numeric_limits<FloatType>::max_digits10);
13743 constexpr int kMinExp = -4;
13745 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
13747 assert(last - first >= kMaxExp + 2);
13748 assert(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
13749 assert(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
13786template<
typename BasicJsonType>
13789 using string_t =
typename BasicJsonType::string_t;
13790 using number_float_t =
typename BasicJsonType::number_float_t;
13791 using number_integer_t =
typename BasicJsonType::number_integer_t;
13792 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
13793 static constexpr std::uint8_t UTF8_ACCEPT = 0;
13794 static constexpr std::uint8_t UTF8_REJECT = 1;
13805 , loc(std::localeconv())
13806 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : * (loc->thousands_sep))
13807 , decimal_point(loc->decimal_point == nullptr ?
'\0' : * (loc->decimal_point))
13808 , indent_char(ichar)
13809 , indent_string(512, indent_char)
13810 , error_handler(error_handler_)
13837 void dump(
const BasicJsonType& val,
const bool pretty_print,
13838 const bool ensure_ascii,
13839 const unsigned int indent_step,
13840 const unsigned int current_indent = 0)
13842 switch (val.m_type)
13846 if (val.m_value.object->empty())
13848 o->write_characters(
"{}", 2);
13854 o->write_characters(
"{\n", 2);
13857 const auto new_indent = current_indent + indent_step;
13858 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
13860 indent_string.resize(indent_string.size() * 2,
' ');
13864 auto i = val.m_value.object->cbegin();
13865 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
13867 o->write_characters(indent_string.c_str(), new_indent);
13868 o->write_character(
'\"');
13869 dump_escaped(i->first, ensure_ascii);
13870 o->write_characters(
"\": ", 3);
13871 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
13872 o->write_characters(
",\n", 2);
13876 assert(i != val.m_value.object->cend());
13877 assert(std::next(i) == val.m_value.object->cend());
13878 o->write_characters(indent_string.c_str(), new_indent);
13879 o->write_character(
'\"');
13880 dump_escaped(i->first, ensure_ascii);
13881 o->write_characters(
"\": ", 3);
13882 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
13884 o->write_character(
'\n');
13885 o->write_characters(indent_string.c_str(), current_indent);
13886 o->write_character(
'}');
13890 o->write_character(
'{');
13893 auto i = val.m_value.object->cbegin();
13894 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
13896 o->write_character(
'\"');
13897 dump_escaped(i->first, ensure_ascii);
13898 o->write_characters(
"\":", 2);
13899 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
13900 o->write_character(
',');
13904 assert(i != val.m_value.object->cend());
13905 assert(std::next(i) == val.m_value.object->cend());
13906 o->write_character(
'\"');
13907 dump_escaped(i->first, ensure_ascii);
13908 o->write_characters(
"\":", 2);
13909 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
13911 o->write_character(
'}');
13919 if (val.m_value.array->empty())
13921 o->write_characters(
"[]", 2);
13927 o->write_characters(
"[\n", 2);
13930 const auto new_indent = current_indent + indent_step;
13931 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
13933 indent_string.resize(indent_string.size() * 2,
' ');
13937 for (
auto i = val.m_value.array->cbegin();
13938 i != val.m_value.array->cend() - 1; ++i)
13940 o->write_characters(indent_string.c_str(), new_indent);
13941 dump(*i,
true, ensure_ascii, indent_step, new_indent);
13942 o->write_characters(
",\n", 2);
13946 assert(not val.m_value.array->empty());
13947 o->write_characters(indent_string.c_str(), new_indent);
13948 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
13950 o->write_character(
'\n');
13951 o->write_characters(indent_string.c_str(), current_indent);
13952 o->write_character(
']');
13956 o->write_character(
'[');
13959 for (
auto i = val.m_value.array->cbegin();
13960 i != val.m_value.array->cend() - 1; ++i)
13962 dump(*i,
false, ensure_ascii, indent_step, current_indent);
13963 o->write_character(
',');
13967 assert(not val.m_value.array->empty());
13968 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
13970 o->write_character(
']');
13978 o->write_character(
'\"');
13979 dump_escaped(*val.m_value.string, ensure_ascii);
13980 o->write_character(
'\"');
13986 if (val.m_value.boolean)
13988 o->write_characters(
"true", 4);
13992 o->write_characters(
"false", 5);
13999 dump_integer(val.m_value.number_integer);
14005 dump_integer(val.m_value.number_unsigned);
14011 dump_float(val.m_value.number_float);
14017 o->write_characters(
"<discarded>", 11);
14023 o->write_characters(
"null", 4);
14047 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
14049 std::uint32_t codepoint;
14050 std::uint8_t
state = UTF8_ACCEPT;
14051 std::size_t bytes = 0;
14054 std::size_t bytes_after_last_accept = 0;
14055 std::size_t undumped_chars = 0;
14057 for (std::size_t i = 0; i < s.size(); ++i)
14059 const auto byte =
static_cast<uint8_t
>(s[i]);
14061 switch (decode(
state, codepoint,
byte))
14069 string_buffer[bytes++] =
'\\';
14070 string_buffer[bytes++] =
'b';
14076 string_buffer[bytes++] =
'\\';
14077 string_buffer[bytes++] =
't';
14083 string_buffer[bytes++] =
'\\';
14084 string_buffer[bytes++] =
'n';
14090 string_buffer[bytes++] =
'\\';
14091 string_buffer[bytes++] =
'f';
14097 string_buffer[bytes++] =
'\\';
14098 string_buffer[bytes++] =
'r';
14104 string_buffer[bytes++] =
'\\';
14105 string_buffer[bytes++] =
'\"';
14111 string_buffer[bytes++] =
'\\';
14112 string_buffer[bytes++] =
'\\';
14120 if ((codepoint <= 0x1F) or (ensure_ascii and (codepoint >= 0x7F)))
14122 if (codepoint <= 0xFFFF)
14124 (std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
14125 static_cast<std::uint16_t
>(codepoint));
14130 (std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
14131 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
14132 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu)));
14140 string_buffer[bytes++] = s[i];
14149 if (string_buffer.size() - bytes < 13)
14151 o->write_characters(string_buffer.data(), bytes);
14156 bytes_after_last_accept = bytes;
14157 undumped_chars = 0;
14163 switch (error_handler)
14167 std::string sn(3,
'\0');
14168 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
byte);
14169 JSON_THROW(type_error::create(316,
"invalid UTF-8 byte at index " + std::to_string(i) +
": 0x" + sn));
14179 if (undumped_chars > 0)
14186 bytes = bytes_after_last_accept;
14193 string_buffer[bytes++] =
'\\';
14194 string_buffer[bytes++] =
'u';
14195 string_buffer[bytes++] =
'f';
14196 string_buffer[bytes++] =
'f';
14197 string_buffer[bytes++] =
'f';
14198 string_buffer[bytes++] =
'd';
14202 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
14203 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
14204 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
14210 if (string_buffer.size() - bytes < 13)
14212 o->write_characters(string_buffer.data(), bytes);
14216 bytes_after_last_accept = bytes;
14219 undumped_chars = 0;
14222 state = UTF8_ACCEPT;
14234 if (not ensure_ascii)
14237 string_buffer[bytes++] = s[i];
14246 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
14251 o->write_characters(string_buffer.data(), bytes);
14257 switch (error_handler)
14261 std::string sn(3,
'\0');
14262 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
static_cast<std::uint8_t
>(s.back()));
14263 JSON_THROW(type_error::create(316,
"incomplete UTF-8 string; last byte: 0x" + sn));
14269 o->write_characters(string_buffer.data(), bytes_after_last_accept);
14276 o->write_characters(string_buffer.data(), bytes_after_last_accept);
14280 o->write_characters(
"\\ufffd", 6);
14284 o->write_characters(
"\xEF\xBF\xBD", 3);
14303 inline unsigned int count_digits(number_unsigned_t x)
noexcept
14305 unsigned int n_digits = 1;
14314 return n_digits + 1;
14318 return n_digits + 2;
14322 return n_digits + 3;
14338 template<
typename NumberType, detail::enable_if_t<
14339 std::is_same<NumberType, number_unsigned_t>::value or
14340 std::is_same<NumberType, number_integer_t>::value,
14342 void dump_integer(NumberType x)
14344 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
14347 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
14348 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
14349 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
14350 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
14351 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
14352 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
14353 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
14354 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
14355 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
14356 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
14363 o->write_character(
'0');
14368 auto buffer_ptr = number_buffer.begin();
14370 const bool is_negative = std::is_same<NumberType, number_integer_t>::value and not(x >= 0);
14371 number_unsigned_t abs_value;
14373 unsigned int n_chars;
14378 abs_value = remove_sign(x);
14381 n_chars = 1 + count_digits(abs_value);
14385 abs_value =
static_cast<number_unsigned_t
>(x);
14386 n_chars = count_digits(abs_value);
14390 assert(n_chars < number_buffer.size() - 1);
14394 buffer_ptr += n_chars;
14398 while (abs_value >= 100)
14400 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
14402 *(--buffer_ptr) = digits_to_99[digits_index][1];
14403 *(--buffer_ptr) = digits_to_99[digits_index][0];
14406 if (abs_value >= 10)
14408 const auto digits_index =
static_cast<unsigned>(abs_value);
14409 *(--buffer_ptr) = digits_to_99[digits_index][1];
14410 *(--buffer_ptr) = digits_to_99[digits_index][0];
14414 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
14417 o->write_characters(number_buffer.data(), n_chars);
14428 void dump_float(number_float_t x)
14431 if (not std::isfinite(x))
14433 o->write_characters(
"null", 4);
14442 static constexpr bool is_ieee_single_or_double
14443 = (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 24 and std::numeric_limits<number_float_t>::max_exponent == 128) or
14444 (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 53 and std::numeric_limits<number_float_t>::max_exponent == 1024);
14446 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
14449 void dump_float(number_float_t x, std::true_type )
14451 char* begin = number_buffer.data();
14454 o->write_characters(begin,
static_cast<size_t>(end - begin));
14457 void dump_float(number_float_t x, std::false_type )
14460 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
14463 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
14468 assert(
static_cast<std::size_t
>(len) < number_buffer.size());
14471 if (thousands_sep !=
'\0')
14473 const auto end = std::remove(number_buffer.begin(),
14474 number_buffer.begin() + len, thousands_sep);
14475 std::fill(end, number_buffer.end(),
'\0');
14476 assert((end - number_buffer.begin()) <= len);
14477 len = (end - number_buffer.begin());
14481 if (decimal_point !=
'\0' and decimal_point !=
'.')
14483 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
14484 if (dec_pos != number_buffer.end())
14490 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
14493 const bool value_is_int_like =
14494 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
14497 return c ==
'.' or c ==
'e';
14500 if (value_is_int_like)
14502 o->write_characters(
".0", 2);
14527 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
14529 static const std::array<std::uint8_t, 400> utf8d =
14532 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,
14533 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,
14534 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,
14535 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,
14536 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,
14537 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,
14538 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,
14539 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
14540 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
14541 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
14542 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,
14543 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,
14544 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,
14545 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
14549 const std::uint8_t type = utf8d[byte];
14551 codep = (state != UTF8_ACCEPT)
14552 ? (
byte & 0x3fu) | (codep << 6u)
14553 : (0xFFu >> type) & (byte);
14555 state = utf8d[256u + state * 16u + type];
14564 number_unsigned_t remove_sign(number_unsigned_t x)
14579 inline number_unsigned_t remove_sign(number_integer_t x)
noexcept
14581 assert(x < 0 and x < (std::numeric_limits<number_integer_t>::max)());
14582 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
14590 std::array<char, 64> number_buffer{{}};
14593 const std::lconv* loc =
nullptr;
14595 const char thousands_sep =
'\0';
14597 const char decimal_point =
'\0';
14600 std::array<char, 512> string_buffer{{}};
14603 const char indent_char;
14605 string_t indent_string;
14707NLOHMANN_BASIC_JSON_TPL_DECLARATION
14712 friend ::nlohmann::json_pointer<basic_json>;
14713 friend ::nlohmann::detail::parser<basic_json>;
14714 friend ::nlohmann::detail::serializer<basic_json>;
14715 template<
typename BasicJsonType>
14716 friend class ::nlohmann::detail::iter_impl;
14717 template<
typename BasicJsonType,
typename CharType>
14718 friend class ::nlohmann::detail::binary_writer;
14719 template<
typename BasicJsonType,
typename SAX>
14720 friend class ::nlohmann::detail::binary_reader;
14721 template<
typename BasicJsonType>
14722 friend class ::nlohmann::detail::json_sax_dom_parser;
14723 template<
typename BasicJsonType>
14724 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
14727 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
14734 template<
typename BasicJsonType>
14736 template<
typename BasicJsonType>
14738 template<
typename Iterator>
14742 template<
typename CharType>
14754 template<
typename T,
typename SFINAE>
14755 using json_serializer = JSONSerializer<T, SFINAE>;
14815 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
14817 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
14865 JSON_HEDLEY_WARN_UNUSED_RESULT
14870 result[
"copyright"] =
"(C) 2013-2017 Niels Lohmann";
14871 result[
"name"] =
"JSON for Modern C++";
14872 result[
"url"] =
"https://github.com/nlohmann/json";
14873 result[
"version"][
"string"] =
14874 std::to_string(NLOHMANN_JSON_VERSION_MAJOR) +
"." +
14875 std::to_string(NLOHMANN_JSON_VERSION_MINOR) +
"." +
14876 std::to_string(NLOHMANN_JSON_VERSION_PATCH);
14877 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
14878 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
14879 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
14882 result[
"platform"] =
"win32";
14883#elif defined __linux__
14884 result[
"platform"] =
"linux";
14885#elif defined __APPLE__
14886 result[
"platform"] =
"apple";
14887#elif defined __unix__
14888 result[
"platform"] =
"unix";
14890 result[
"platform"] =
"unknown";
14893#if defined(__ICC) || defined(__INTEL_COMPILER)
14894 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
14895#elif defined(__clang__)
14896 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
14897#elif defined(__GNUC__) || defined(__GNUG__)
14898 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." + std::to_string(__GNUC_PATCHLEVEL__)}};
14899#elif defined(__HP_cc) || defined(__HP_aCC)
14900 result[
"compiler"] =
"hp"
14901#elif defined(__IBMCPP__)
14902 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
14903#elif defined(_MSC_VER)
14904 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
14905#elif defined(__PGI)
14906 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
14907#elif defined(__SUNPRO_CC)
14908 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
14910 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
14914 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
14916 result[
"compiler"][
"c++"] =
"unknown";
14931#if defined(JSON_HAS_CPP_14)
14934 using object_comparator_t = std::less<>;
14936 using object_comparator_t = std::less<StringType>;
15024 object_comparator_t,
15025 AllocatorType<std::pair<
const StringType,
15072 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
15369 template<
typename T,
typename... Args>
15370 JSON_HEDLEY_RETURNS_NON_NULL
15371 static T* create(Args&& ... args)
15373 AllocatorType<T> alloc;
15374 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
15376 auto deleter = [&](T *
object)
15378 AllocatorTraits::deallocate(alloc,
object, 1);
15380 std::unique_ptr<T,
decltype(deleter)>
object(AllocatorTraits::allocate(alloc, 1), deleter);
15381 AllocatorTraits::construct(alloc,
object.
get(), std::forward<Args>(args)...);
15382 assert(
object !=
nullptr);
15383 return object.release();
15432 json_value() =
default;
15434 json_value(
boolean_t v) noexcept : boolean(v) {}
15442 json_value(value_t t)
15446 case value_t::object:
15448 object = create<object_t>();
15452 case value_t::array:
15454 array = create<array_t>();
15458 case value_t::string:
15460 string = create<string_t>(
"");
15464 case value_t::boolean:
15470 case value_t::number_integer:
15476 case value_t::number_unsigned:
15482 case value_t::number_float:
15488 case value_t::null:
15497 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
15499 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.7.3"));
15509 string = create<string_t>(
value);
15515 string = create<string_t>(std::move(
value));
15521 object = create<object_t>(
value);
15527 object = create<object_t>(std::move(
value));
15533 array = create<array_t>(
value);
15539 array = create<array_t>(std::move(
value));
15542 void destroy(value_t t)
noexcept
15545 std::vector<basic_json> stack;
15548 if (t == value_t::array)
15550 stack.reserve(array->size());
15551 std::move(array->begin(), array->end(), std::back_inserter(stack));
15553 else if (t == value_t::object)
15555 stack.reserve(object->size());
15556 for (
auto&& it : *
object)
15558 stack.push_back(std::move(it.second));
15562 while (not stack.empty())
15565 basic_json current_item(std::move(stack.back()));
15570 if (current_item.is_array())
15572 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(),
15573 std::back_inserter(stack));
15575 current_item.m_value.array->clear();
15577 else if (current_item.is_object())
15579 for (
auto&& it : *current_item.m_value.object)
15581 stack.push_back(std::move(it.second));
15584 current_item.m_value.object->clear();
15593 case value_t::object:
15595 AllocatorType<object_t> alloc;
15596 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
15597 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
15601 case value_t::array:
15603 AllocatorType<array_t> alloc;
15604 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
15605 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
15609 case value_t::string:
15611 AllocatorType<string_t> alloc;
15612 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
15613 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
15634 void assert_invariant() const noexcept
15636 assert(m_type != value_t::object or m_value.object !=
nullptr);
15637 assert(m_type != value_t::array or m_value.array !=
nullptr);
15638 assert(m_type != value_t::string or m_value.string !=
nullptr);
15753 : m_type(v), m_value(v)
15755 assert_invariant();
15779 assert_invariant();
15839 template <
typename CompatibleType,
15840 typename U = detail::uncvref_t<CompatibleType>,
15841 detail::enable_if_t<
15844 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
15845 std::forward<CompatibleType>(val))))
15847 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
15848 assert_invariant();
15877 template <
typename BasicJsonType,
15878 detail::enable_if_t<
15882 using other_boolean_t =
typename BasicJsonType::boolean_t;
15883 using other_number_float_t =
typename BasicJsonType::number_float_t;
15884 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
15885 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
15886 using other_string_t =
typename BasicJsonType::string_t;
15887 using other_object_t =
typename BasicJsonType::object_t;
15888 using other_array_t =
typename BasicJsonType::array_t;
15890 switch (val.type())
15892 case value_t::boolean:
15895 case value_t::number_float:
15898 case value_t::number_integer:
15901 case value_t::number_unsigned:
15904 case value_t::string:
15907 case value_t::object:
15910 case value_t::array:
15913 case value_t::null:
15916 case value_t::discarded:
15917 m_type = value_t::discarded;
15922 assert_invariant();
16000 bool type_deduction =
true,
16001 value_t manual_type = value_t::array)
16005 bool is_an_object = std::all_of(init.begin(), init.end(),
16008 return element_ref->is_array() and element_ref->size() == 2 and (*element_ref)[0].is_string();
16012 if (not type_deduction)
16015 if (manual_type == value_t::array)
16017 is_an_object =
false;
16021 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object and not is_an_object))
16023 JSON_THROW(type_error::create(301,
"cannot create object from initializer list"));
16030 m_type = value_t::object;
16031 m_value = value_t::object;
16035 auto element = element_ref.moved_or_copied();
16036 m_value.object->emplace(
16037 std::move(*((*element.m_value.array)[0].m_value.string)),
16038 std::move((*element.m_value.array)[1]));
16044 m_type = value_t::array;
16045 m_value.array = create<array_t>(init.begin(), init.end());
16048 assert_invariant();
16088 JSON_HEDLEY_WARN_UNUSED_RESULT
16091 return basic_json(init,
false, value_t::array);
16132 JSON_HEDLEY_WARN_UNUSED_RESULT
16135 return basic_json(init,
false, value_t::object);
16161 : m_type(value_t::
array)
16163 m_value.array = create<array_t>(cnt, val);
16164 assert_invariant();
16222 template<
class InputIT,
typename std::enable_if<
16223 std::is_same<InputIT, typename basic_json_t::iterator>::value or
16224 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int>
::type = 0>
16227 assert(first.m_object !=
nullptr);
16228 assert(last.m_object !=
nullptr);
16231 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
16233 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible"));
16237 m_type = first.m_object->m_type;
16242 case value_t::boolean:
16243 case value_t::number_float:
16244 case value_t::number_integer:
16245 case value_t::number_unsigned:
16246 case value_t::string:
16248 if (JSON_HEDLEY_UNLIKELY(not first.m_it.primitive_iterator.is_begin()
16249 or not last.m_it.primitive_iterator.is_end()))
16251 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
16262 case value_t::number_integer:
16264 m_value.number_integer = first.m_object->m_value.number_integer;
16268 case value_t::number_unsigned:
16270 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
16274 case value_t::number_float:
16276 m_value.number_float = first.m_object->m_value.number_float;
16280 case value_t::boolean:
16282 m_value.boolean = first.m_object->m_value.boolean;
16286 case value_t::string:
16288 m_value = *first.m_object->m_value.string;
16292 case value_t::object:
16294 m_value.object = create<object_t>(first.m_it.object_iterator,
16295 last.m_it.object_iterator);
16299 case value_t::array:
16301 m_value.array = create<array_t>(first.m_it.array_iterator,
16302 last.m_it.array_iterator);
16307 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " +
16308 std::string(first.m_object->type_name())));
16311 assert_invariant();
16350 : m_type(other.m_type)
16353 other.assert_invariant();
16357 case value_t::object:
16359 m_value = *other.m_value.object;
16363 case value_t::array:
16365 m_value = *other.m_value.array;
16369 case value_t::string:
16371 m_value = *other.m_value.string;
16375 case value_t::boolean:
16377 m_value = other.m_value.boolean;
16381 case value_t::number_integer:
16383 m_value = other.m_value.number_integer;
16387 case value_t::number_unsigned:
16389 m_value = other.m_value.number_unsigned;
16393 case value_t::number_float:
16395 m_value = other.m_value.number_float;
16403 assert_invariant();
16433 : m_type(std::move(other.m_type)),
16434 m_value(std::move(other.m_value))
16437 other.assert_invariant();
16440 other.m_type = value_t::null;
16441 other.m_value = {};
16443 assert_invariant();
16470 std::is_nothrow_move_constructible<value_t>::value and
16471 std::is_nothrow_move_assignable<value_t>::value and
16472 std::is_nothrow_move_constructible<json_value>::value and
16473 std::is_nothrow_move_assignable<json_value>::value
16477 other.assert_invariant();
16480 swap(m_type, other.m_type);
16481 swap(m_value, other.m_value);
16483 assert_invariant();
16504 assert_invariant();
16505 m_value.destroy(m_type);
16561 const char indent_char =
' ',
16562 const bool ensure_ascii =
false,
16570 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
16574 s.dump(*
this,
false, ensure_ascii, 0);
16612 constexpr value_t
type() const noexcept
16693 return m_type == value_t::null;
16715 return m_type == value_t::boolean;
16774 return m_type == value_t::number_integer or m_type == value_t::number_unsigned;
16802 return m_type == value_t::number_unsigned;
16830 return m_type == value_t::number_float;
16852 return m_type == value_t::object;
16874 return m_type == value_t::array;
16896 return m_type == value_t::string;
16923 return m_type == value_t::discarded;
16947 constexpr operator value_t() const noexcept
16964 return m_value.boolean;
16967 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(
type_name())));
16973 return is_object() ? m_value.object :
nullptr;
16979 return is_object() ? m_value.object :
nullptr;
16985 return is_array() ? m_value.array :
nullptr;
16989 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
16991 return is_array() ? m_value.array :
nullptr;
16997 return is_string() ? m_value.string :
nullptr;
17003 return is_string() ? m_value.string :
nullptr;
17009 return is_boolean() ? &m_value.boolean :
nullptr;
17015 return is_boolean() ? &m_value.boolean :
nullptr;
17065 template<
typename ReferenceType,
typename ThisType>
17066 static ReferenceType get_ref_impl(ThisType& obj)
17071 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
17076 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name())));
17098 template<
typename BasicJsonType, detail::enable_if_t<
17099 std::is_same<typename std::remove_const<BasicJsonType>::type, basic_json_t>
::value,
17121 template<
typename BasicJsonType, detail::enable_if_t<
17122 not std::is_same<BasicJsonType, basic_json>::value and
17168 template<
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
17169 detail::enable_if_t <
17170 not detail::is_basic_json<ValueType>::value and
17171 detail::has_from_json<basic_json_t, ValueType>::value and
17172 not detail::has_non_default_from_json<basic_json_t, ValueType>::value,
17174 ValueType
get() const noexcept(noexcept(
17175 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
17180 static_assert(not std::is_reference<ValueTypeCV>::value,
17181 "get() cannot be used with reference types, you might want to use get_ref()");
17182 static_assert(std::is_default_constructible<ValueType>::value,
17183 "types must be DefaultConstructible when used with get()");
17186 JSONSerializer<ValueType>::from_json(*
this, ret);
17221 template<
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
17222 detail::enable_if_t<not std::is_same<basic_json_t, ValueType>::value and
17223 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
17225 ValueType
get() const noexcept(noexcept(
17226 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
17228 static_assert(not std::is_reference<ValueTypeCV>::value,
17229 "get() cannot be used with reference types, you might want to use get_ref()");
17230 return JSONSerializer<ValueType>::from_json(*
this);
17266 template<
typename ValueType,
17267 detail::enable_if_t <
17271 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
17272 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
17274 JSONSerializer<ValueType>::from_json(*
this, v);
17279 typename T, std::size_t N,
17280 typename Array = T (&)[N],
17281 detail::enable_if_t <
17283 Array
get_to(T (&v)[N])
const
17284 noexcept(
noexcept(JSONSerializer<Array>::from_json(
17285 std::declval<const basic_json_t&>(), v)))
17287 JSONSerializer<Array>::from_json(*
this, v);
17318 template<
typename PointerType,
typename std::enable_if<
17319 std::is_pointer<PointerType>::value,
int>
::type = 0>
17320 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
17323 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
17330 template<
typename PointerType,
typename std::enable_if<
17331 std::is_pointer<PointerType>::value and
17332 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int>
::type = 0>
17333 constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
17336 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
17366 template<
typename PointerType,
typename std::enable_if<
17367 std::is_pointer<PointerType>::value,
int>
::type = 0>
17368 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template
get_ptr<PointerType>())
17378 template<
typename PointerType,
typename std::enable_if<
17379 std::is_pointer<PointerType>::value,
int>
::type = 0>
17380 constexpr auto get() const noexcept -> decltype(std::declval<const basic_json_t&>().template
get_ptr<PointerType>())
17412 template<
typename ReferenceType,
typename std::enable_if<
17413 std::is_reference<ReferenceType>::value,
int>
::type = 0>
17417 return get_ref_impl<ReferenceType>(*
this);
17424 template<
typename ReferenceType,
typename std::enable_if<
17425 std::is_reference<ReferenceType>::value and
17426 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int>
::type = 0>
17430 return get_ref_impl<ReferenceType>(*
this);
17462 template <
typename ValueType,
typename std::enable_if <
17463 not std::is_pointer<ValueType>::value and
17464 not std::is_same<ValueType, detail::json_ref<basic_json>>
::value and
17465 not std::is_same<ValueType, typename string_t::value_type>::value and
17469 and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>
::value
17470#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) and _MSC_VER <= 1914))
17471 and not std::is_same<ValueType, typename std::string_view>::value
17474 and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
17476 operator ValueType()
const
17522 if (JSON_HEDLEY_LIKELY(
is_array()))
17526 return m_value.array->at(idx);
17528 JSON_CATCH (std::out_of_range&)
17531 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range"));
17536 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name())));
17569 if (JSON_HEDLEY_LIKELY(
is_array()))
17573 return m_value.array->at(idx);
17575 JSON_CATCH (std::out_of_range&)
17578 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range"));
17583 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name())));
17624 return m_value.object->at(key);
17626 JSON_CATCH (std::out_of_range&)
17629 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found"));
17634 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name())));
17675 return m_value.object->at(key);
17677 JSON_CATCH (std::out_of_range&)
17680 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found"));
17685 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name())));
17719 m_type = value_t::array;
17720 m_value.array = create<array_t>();
17721 assert_invariant();
17725 if (JSON_HEDLEY_LIKELY(
is_array()))
17728 if (idx >= m_value.array->size())
17730 m_value.array->insert(m_value.array->end(),
17731 idx - m_value.array->size() + 1,
17735 return m_value.array->operator[](idx);
17738 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name())));
17763 if (JSON_HEDLEY_LIKELY(
is_array()))
17765 return m_value.array->operator[](idx);
17768 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name())));
17803 m_type = value_t::object;
17804 m_value.object = create<object_t>();
17805 assert_invariant();
17811 return m_value.object->operator[](key);
17814 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name())));
17852 assert(m_value.object->find(key) != m_value.object->end());
17853 return m_value.object->find(key)->second;
17856 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name())));
17886 template<
typename T>
17887 JSON_HEDLEY_NON_NULL(2)
17893 m_type = value_t::object;
17894 m_value = value_t::object;
17895 assert_invariant();
17901 return m_value.object->operator[](key);
17904 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name())));
17937 template<
typename T>
17938 JSON_HEDLEY_NON_NULL(2)
17944 assert(m_value.object->find(key) != m_value.object->end());
17945 return m_value.object->find(key)->second;
17948 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name())));
18001 template<
class ValueType,
typename std::enable_if<
18002 std::is_convertible<basic_json_t, ValueType>::value,
int>
::type = 0>
18003 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
18009 const auto it =
find(key);
18015 return default_value;
18018 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name())));
18025 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const
18073 template<
class ValueType,
typename std::enable_if<
18074 std::is_convertible<basic_json_t, ValueType>::value,
int>
::type = 0>
18083 return ptr.get_checked(
this);
18087 return default_value;
18091 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name())));
18098 JSON_HEDLEY_NON_NULL(3)
18236 template<
class IteratorType,
typename std::enable_if<
18237 std::is_same<IteratorType, typename basic_json_t::iterator>::value or
18238 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int>
::type
18243 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
18245 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
18248 IteratorType result =
end();
18252 case value_t::boolean:
18253 case value_t::number_float:
18254 case value_t::number_integer:
18255 case value_t::number_unsigned:
18256 case value_t::string:
18258 if (JSON_HEDLEY_UNLIKELY(not pos.m_it.primitive_iterator.is_begin()))
18260 JSON_THROW(invalid_iterator::create(205,
"iterator out of range"));
18265 AllocatorType<string_t> alloc;
18266 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_value.string);
18267 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_value.string, 1);
18268 m_value.string =
nullptr;
18271 m_type = value_t::null;
18272 assert_invariant();
18276 case value_t::object:
18278 result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
18282 case value_t::array:
18284 result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
18289 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name())));
18341 template<
class IteratorType,
typename std::enable_if<
18342 std::is_same<IteratorType, typename basic_json_t::iterator>::value or
18343 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int>
::type
18345 IteratorType
erase(IteratorType first, IteratorType last)
18348 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object or
this != last.m_object))
18350 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value"));
18353 IteratorType result =
end();
18357 case value_t::boolean:
18358 case value_t::number_float:
18359 case value_t::number_integer:
18360 case value_t::number_unsigned:
18361 case value_t::string:
18363 if (JSON_HEDLEY_LIKELY(not first.m_it.primitive_iterator.is_begin()
18364 or not last.m_it.primitive_iterator.is_end()))
18366 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
18371 AllocatorType<string_t> alloc;
18372 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_value.string);
18373 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_value.string, 1);
18374 m_value.string =
nullptr;
18377 m_type = value_t::null;
18378 assert_invariant();
18382 case value_t::object:
18384 result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
18385 last.m_it.object_iterator);
18389 case value_t::array:
18391 result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
18392 last.m_it.array_iterator);
18397 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name())));
18437 return m_value.object->erase(key);
18440 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name())));
18470 if (JSON_HEDLEY_LIKELY(
is_array()))
18472 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
18474 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range"));
18477 m_value.array->erase(m_value.array->begin() +
static_cast<difference_type>(idx));
18481 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name())));
18519 template<
typename KeyT>
18522 auto result =
end();
18526 result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
18536 template<
typename KeyT>
18539 auto result =
cend();
18543 result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
18570 template<
typename KeyT>
18574 return is_object() ? m_value.object->count(std::forward<KeyT>(key)) : 0;
18602 template<
typename KeyT,
typename std::enable_if<
18606 return is_object() and m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
18637 return ptr.contains(
this);
18677 result.set_begin();
18717 result.set_begin();
18981 JSON_HEDLEY_DEPRECATED(3.1.0)
18984 return ref.items();
18990 JSON_HEDLEY_DEPRECATED(3.1.0)
18993 return ref.items();
19061 return iteration_proxy<iterator>(*
this);
19067 iteration_proxy<const_iterator>
items() const noexcept
19069 return iteration_proxy<const_iterator>(*
this);
19127 case value_t::null:
19133 case value_t::array:
19136 return m_value.array->empty();
19139 case value_t::object:
19142 return m_value.object->empty();
19199 case value_t::null:
19205 case value_t::array:
19208 return m_value.array->size();
19211 case value_t::object:
19214 return m_value.object->size();
19269 case value_t::array:
19272 return m_value.array->max_size();
19275 case value_t::object:
19278 return m_value.object->max_size();
19339 case value_t::number_integer:
19341 m_value.number_integer = 0;
19345 case value_t::number_unsigned:
19347 m_value.number_unsigned = 0;
19351 case value_t::number_float:
19353 m_value.number_float = 0.0;
19357 case value_t::boolean:
19359 m_value.boolean =
false;
19363 case value_t::string:
19365 m_value.string->clear();
19369 case value_t::array:
19371 m_value.array->clear();
19375 case value_t::object:
19377 m_value.object->clear();
19411 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name())));
19417 m_type = value_t::array;
19418 m_value = value_t::array;
19419 assert_invariant();
19423 m_value.array->push_back(std::move(val));
19426 val.m_type = value_t::null;
19448 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name())));
19454 m_type = value_t::array;
19455 m_value = value_t::array;
19456 assert_invariant();
19460 m_value.array->push_back(val);
19498 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name())));
19504 m_type = value_t::object;
19505 m_value = value_t::object;
19506 assert_invariant();
19510 m_value.object->insert(val);
19550 if (
is_object() and init.size() == 2 and (*init.begin())->is_string())
19552 basic_json&& key = init.begin()->moved_or_copied();
19553 push_back(
typename object_t::value_type(
19554 std::move(key.
get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
19595 template<
class... Args>
19601 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(
type_name())));
19607 m_type = value_t::array;
19608 m_value = value_t::array;
19609 assert_invariant();
19613#ifdef JSON_HAS_CPP_17
19648 template<
class... Args>
19654 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(
type_name())));
19660 m_type = value_t::object;
19661 m_value = value_t::object;
19662 assert_invariant();
19666 auto res = m_value.object->emplace(std::forward<Args>(args)...);
19669 it.m_it.object_iterator = res.first;
19672 return {it, res.second};
19678 template<
typename... Args>
19682 assert(m_value.array !=
nullptr);
19684 auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
19685 m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
19686 result.m_it.array_iterator = m_value.array->begin() + insert_pos;
19720 if (JSON_HEDLEY_LIKELY(
is_array()))
19723 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
19725 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
19732 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
19741 return insert(pos, val);
19771 if (JSON_HEDLEY_LIKELY(
is_array()))
19774 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
19776 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
19783 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
19819 if (JSON_HEDLEY_UNLIKELY(not
is_array()))
19821 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
19825 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
19827 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
19831 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
19833 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
19836 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
19838 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container"));
19842 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
19872 if (JSON_HEDLEY_UNLIKELY(not
is_array()))
19874 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
19878 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
19880 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
19913 if (JSON_HEDLEY_UNLIKELY(not
is_object()))
19915 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
19919 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
19921 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
19925 if (JSON_HEDLEY_UNLIKELY(not first.m_object->is_object()))
19927 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects"));
19930 m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
19957 m_type = value_t::object;
19958 m_value.object = create<object_t>();
19959 assert_invariant();
19962 if (JSON_HEDLEY_UNLIKELY(not
is_object()))
19964 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name())));
19966 if (JSON_HEDLEY_UNLIKELY(not j.
is_object()))
19968 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.
type_name())));
19971 for (
auto it = j.
cbegin(); it != j.
cend(); ++it)
19973 m_value.object->operator[](it.key()) = it.value();
20008 m_type = value_t::object;
20009 m_value.object = create<object_t>();
20010 assert_invariant();
20013 if (JSON_HEDLEY_UNLIKELY(not
is_object()))
20015 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name())));
20019 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
20021 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
20025 if (JSON_HEDLEY_UNLIKELY(not first.m_object->is_object()
20026 or not last.m_object->is_object()))
20028 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects"));
20031 for (
auto it = first; it != last; ++it)
20033 m_value.object->operator[](it.key()) = it.value();
20055 std::is_nothrow_move_constructible<value_t>::value and
20056 std::is_nothrow_move_assignable<value_t>::value and
20057 std::is_nothrow_move_constructible<json_value>::value and
20058 std::is_nothrow_move_assignable<json_value>::value
20061 std::swap(m_type, other.m_type);
20062 std::swap(m_value, other.m_value);
20063 assert_invariant();
20089 if (JSON_HEDLEY_LIKELY(
is_array()))
20091 std::swap(*(m_value.array), other);
20095 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name())));
20124 std::swap(*(m_value.object), other);
20128 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name())));
20157 std::swap(*(m_value.string), other);
20161 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name())));
20216 const auto lhs_type = lhs.type();
20217 const auto rhs_type = rhs.type();
20219 if (lhs_type == rhs_type)
20223 case value_t::array:
20224 return *lhs.m_value.array == *rhs.m_value.array;
20226 case value_t::object:
20227 return *lhs.m_value.object == *rhs.m_value.object;
20229 case value_t::null:
20232 case value_t::string:
20233 return *lhs.m_value.string == *rhs.m_value.string;
20235 case value_t::boolean:
20236 return lhs.m_value.boolean == rhs.m_value.boolean;
20238 case value_t::number_integer:
20239 return lhs.m_value.number_integer == rhs.m_value.number_integer;
20241 case value_t::number_unsigned:
20242 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
20244 case value_t::number_float:
20245 return lhs.m_value.number_float == rhs.m_value.number_float;
20251 else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
20253 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
20255 else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
20257 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
20259 else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
20261 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
20263 else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
20265 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
20267 else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
20269 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
20271 else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
20273 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
20283 template<
typename ScalarType,
typename std::enable_if<
20284 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20294 template<
typename ScalarType,
typename std::enable_if<
20295 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20321 return not (lhs == rhs);
20328 template<
typename ScalarType,
typename std::enable_if<
20329 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20339 template<
typename ScalarType,
typename std::enable_if<
20340 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20374 const auto lhs_type = lhs.type();
20375 const auto rhs_type = rhs.type();
20377 if (lhs_type == rhs_type)
20381 case value_t::array:
20384 return (*lhs.m_value.array) < (*rhs.m_value.array);
20386 case value_t::object:
20387 return (*lhs.m_value.object) < (*rhs.m_value.object);
20389 case value_t::null:
20392 case value_t::string:
20393 return (*lhs.m_value.string) < (*rhs.m_value.string);
20395 case value_t::boolean:
20396 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
20398 case value_t::number_integer:
20399 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
20401 case value_t::number_unsigned:
20402 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
20404 case value_t::number_float:
20405 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
20411 else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
20413 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
20415 else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
20417 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
20419 else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
20421 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
20423 else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
20425 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
20427 else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
20429 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
20431 else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
20433 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
20446 template<
typename ScalarType,
typename std::enable_if<
20447 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20457 template<
typename ScalarType,
typename std::enable_if<
20458 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20485 return not (rhs < lhs);
20492 template<
typename ScalarType,
typename std::enable_if<
20493 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20503 template<
typename ScalarType,
typename std::enable_if<
20504 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20531 return not (lhs <= rhs);
20538 template<
typename ScalarType,
typename std::enable_if<
20539 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20549 template<
typename ScalarType,
typename std::enable_if<
20550 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20577 return not (lhs < rhs);
20584 template<
typename ScalarType,
typename std::enable_if<
20585 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20595 template<
typename ScalarType,
typename std::enable_if<
20596 std::is_scalar<ScalarType>::value,
int>
::type = 0>
20645 const bool pretty_print = o.width() > 0;
20646 const auto indentation = pretty_print ? o.width() : 0;
20653 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
20665 JSON_HEDLEY_DEPRECATED(3.0.0)
20666 friend std::ostream& operator>>(const
basic_json& j, std::ostream& o)
20744 JSON_HEDLEY_WARN_UNUSED_RESULT
20747 const bool allow_exceptions =
true)
20750 parser(i, cb, allow_exceptions).parse(
true, result);
20756 return parser(i).
accept(
true);
20812 template <
typename SAX>
20813 JSON_HEDLEY_NON_NULL(2)
20815 input_format_t format = input_format_t::
json,
20816 const
bool strict = true)
20819 return format == input_format_t::json
20820 ? parser(std::move(i)).sax_parse(sax, strict)
20873 template<
class IteratorType,
typename std::enable_if<
20875 std::random_access_iterator_tag,
20876 typename std::iterator_traits<IteratorType>::iterator_category>
::value,
int>
::type = 0>
20879 const bool allow_exceptions =
true)
20886 template<
class IteratorType,
typename std::enable_if<
20888 std::random_access_iterator_tag,
20889 typename std::iterator_traits<IteratorType>::iterator_category>
::value,
int>
::type = 0>
20890 static bool accept(IteratorType first, IteratorType last)
20895 template<
class IteratorType,
class SAX,
typename std::enable_if<
20897 std::random_access_iterator_tag,
20898 typename std::iterator_traits<IteratorType>::iterator_category>
::value,
int>
::type = 0>
20899 JSON_HEDLEY_NON_NULL(3)
20900 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax)
20902 return parser(detail::input_adapter(first, last)).sax_parse(sax);
20913 JSON_HEDLEY_DEPRECATED(3.0.0)
20986 JSON_HEDLEY_RETURNS_NON_NULL
20992 case value_t::null:
20994 case value_t::object:
20996 case value_t::array:
20998 case value_t::string:
21000 case value_t::boolean:
21002 case value_t::discarded:
21003 return "discarded";
21017 value_t m_type = value_t::null;
21020 json_value m_value = {};
21120 std::vector<uint8_t> result;
21127 binary_writer<uint8_t>(o).write_cbor(j);
21132 binary_writer<char>(o).write_cbor(j);
21216 std::vector<uint8_t> result;
21223 binary_writer<uint8_t>(o).write_msgpack(j);
21228 binary_writer<char>(o).write_msgpack(j);
21312 const bool use_size =
false,
21313 const bool use_type =
false)
21315 std::vector<uint8_t> result;
21316 to_ubjson(j, result, use_size, use_type);
21321 const bool use_size =
false,
const bool use_type =
false)
21323 binary_writer<uint8_t>(o).write_ubjson(j, use_size, use_type);
21327 const bool use_size =
false,
const bool use_type =
false)
21329 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
21390 std::vector<uint8_t> result;
21405 binary_writer<uint8_t>(o).write_bson(j);
21413 binary_writer<char>(o).write_bson(j);
21516 JSON_HEDLEY_WARN_UNUSED_RESULT
21518 const bool strict =
true,
21519 const bool allow_exceptions =
true)
21523 const bool res = binary_reader(
detail::input_adapter(i)).sax_parse(input_format_t::cbor, &sdp, strict);
21524 return res ? result :
basic_json(value_t::discarded);
21530 template<
typename A1,
typename A2,
21531 detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value,
int> = 0>
21532 JSON_HEDLEY_WARN_UNUSED_RESULT
21534 const bool strict =
true,
21535 const bool allow_exceptions =
true)
21539 const bool res = binary_reader(
detail::input_adapter(std::forward<A1>(a1), std::forward<A2>(a2))).sax_parse(input_format_t::cbor, &sdp, strict);
21540 return res ? result :
basic_json(value_t::discarded);
21625 JSON_HEDLEY_WARN_UNUSED_RESULT
21627 const bool strict =
true,
21628 const bool allow_exceptions =
true)
21632 const bool res = binary_reader(
detail::input_adapter(i)).sax_parse(input_format_t::msgpack, &sdp, strict);
21633 return res ? result :
basic_json(value_t::discarded);
21639 template<
typename A1,
typename A2,
21640 detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value,
int> = 0>
21641 JSON_HEDLEY_WARN_UNUSED_RESULT
21643 const bool strict =
true,
21644 const bool allow_exceptions =
true)
21648 const bool res = binary_reader(
detail::input_adapter(std::forward<A1>(a1), std::forward<A2>(a2))).sax_parse(input_format_t::msgpack, &sdp, strict);
21649 return res ? result :
basic_json(value_t::discarded);
21713 JSON_HEDLEY_WARN_UNUSED_RESULT
21715 const bool strict =
true,
21716 const bool allow_exceptions =
true)
21720 const bool res = binary_reader(
detail::input_adapter(i)).sax_parse(input_format_t::ubjson, &sdp, strict);
21721 return res ? result :
basic_json(value_t::discarded);
21727 template<
typename A1,
typename A2,
21728 detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value,
int> = 0>
21729 JSON_HEDLEY_WARN_UNUSED_RESULT
21731 const bool strict =
true,
21732 const bool allow_exceptions =
true)
21736 const bool res = binary_reader(
detail::input_adapter(std::forward<A1>(a1), std::forward<A2>(a2))).sax_parse(input_format_t::ubjson, &sdp, strict);
21737 return res ? result :
basic_json(value_t::discarded);
21800 JSON_HEDLEY_WARN_UNUSED_RESULT
21802 const bool strict =
true,
21803 const bool allow_exceptions =
true)
21807 const bool res = binary_reader(
detail::input_adapter(i)).sax_parse(input_format_t::bson, &sdp, strict);
21808 return res ? result :
basic_json(value_t::discarded);
21814 template<
typename A1,
typename A2,
21815 detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value,
int> = 0>
21816 JSON_HEDLEY_WARN_UNUSED_RESULT
21818 const bool strict =
true,
21819 const bool allow_exceptions =
true)
21823 const bool res = binary_reader(
detail::input_adapter(std::forward<A1>(a1), std::forward<A2>(a2))).sax_parse(input_format_t::bson, &sdp, strict);
21824 return res ? result :
basic_json(value_t::discarded);
21873 return ptr.get_unchecked(
this);
21901 return ptr.get_unchecked(
this);
21944 return ptr.get_checked(
this);
21987 return ptr.get_checked(
this);
22015 json_pointer::flatten(
"", *
this, result);
22051 return json_pointer::unflatten(*
this);
22116 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
22118 const auto get_op = [](
const std::string & op)
22122 return patch_operations::add;
22124 if (op ==
"remove")
22126 return patch_operations::remove;
22128 if (op ==
"replace")
22130 return patch_operations::replace;
22134 return patch_operations::move;
22138 return patch_operations::copy;
22142 return patch_operations::test;
22145 return patch_operations::invalid;
22160 if (top_pointer != ptr)
22162 result.
at(top_pointer);
22166 const auto last_path = ptr.
back();
22170 switch (parent.m_type)
22172 case value_t::null:
22173 case value_t::object:
22176 parent[last_path] = val;
22180 case value_t::array:
22182 if (last_path ==
"-")
22189 const auto idx = json_pointer::array_index(last_path);
22190 if (JSON_HEDLEY_UNLIKELY(
static_cast<size_type>(idx) > parent.
size()))
22193 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range"));
22209 const auto operation_remove = [&result](
json_pointer & ptr)
22212 const auto last_path = ptr.
back();
22220 auto it = parent.
find(last_path);
22221 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
22227 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found"));
22233 parent.
erase(
static_cast<size_type>(json_pointer::array_index(last_path)));
22238 if (JSON_HEDLEY_UNLIKELY(not json_patch.
is_array()))
22244 for (
const auto& val : json_patch)
22247 const auto get_value = [&val](
const std::string & op,
22248 const std::string & member,
22252 auto it = val.m_value.object->find(member);
22255 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
22258 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
22260 JSON_THROW(
parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'"));
22264 if (JSON_HEDLEY_UNLIKELY(string_type and not it->second.is_string()))
22266 JSON_THROW(
parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'"));
22274 if (JSON_HEDLEY_UNLIKELY(not val.is_object()))
22280 const std::string op = get_value(
"op",
"op",
true);
22281 const std::string path = get_value(op,
"path",
true);
22284 switch (get_op(op))
22286 case patch_operations::add:
22288 operation_add(ptr, get_value(
"add",
"value",
false));
22292 case patch_operations::remove:
22294 operation_remove(ptr);
22298 case patch_operations::replace:
22301 result.
at(ptr) = get_value(
"replace",
"value",
false);
22305 case patch_operations::move:
22307 const std::string from_path = get_value(
"move",
"from",
true);
22317 operation_remove(from_ptr);
22318 operation_add(ptr, v);
22322 case patch_operations::copy:
22324 const std::string from_path = get_value(
"copy",
"from",
true);
22333 operation_add(ptr, v);
22337 case patch_operations::test:
22339 bool success =
false;
22344 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
22352 if (JSON_HEDLEY_UNLIKELY(not success))
22354 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump()));
22405 JSON_HEDLEY_WARN_UNUSED_RESULT
22407 const std::string& path =
"")
22413 if (source == target)
22418 if (source.
type() != target.
type())
22423 {
"op",
"replace"}, {
"path", path}, {
"value", target}
22428 switch (source.
type())
22430 case value_t::array:
22434 while (i < source.
size() and i < target.
size())
22437 auto temp_diff =
diff(source[i], target[i], path +
"/" + std::to_string(i));
22438 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
22447 while (i < source.
size())
22451 result.
insert(result.
begin() + end_index,
object(
22454 {
"path", path +
"/" + std::to_string(i)}
22460 while (i < target.
size())
22465 {
"path", path +
"/" + std::to_string(i)},
22466 {
"value", target[i]}
22474 case value_t::object:
22477 for (
auto it = source.
cbegin(); it != source.
cend(); ++it)
22480 const auto key = json_pointer::escape(it.key());
22482 if (target.
find(it.key()) != target.
end())
22485 auto temp_diff =
diff(it.value(), target[it.key()], path +
"/" + key);
22486 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
22493 {
"op",
"remove"}, {
"path", path +
"/" + key}
22499 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
22501 if (source.
find(it.key()) == source.
end())
22504 const auto key = json_pointer::escape(it.key());
22507 {
"op",
"add"}, {
"path", path +
"/" + key},
22508 {
"value", it.value()}
22521 {
"op",
"replace"}, {
"path", path}, {
"value", target}
22589 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
22591 if (it.value().is_null())
22597 operator[](it.key()).merge_patch(it.value());
22603 *
this = apply_patch;
22619NLOHMANN_BASIC_JSON_TPL_DECLARATION
22646 const auto& h = hash<nlohmann::json::string_t>();
22647 return h(j.
dump());
22675 is_nothrow_move_constructible<nlohmann::json>::value and
22676 is_nothrow_move_assignable<nlohmann::json>::value
22697JSON_HEDLEY_NON_NULL(1)
22698inline
nlohmann::json operator
"" _json(const
char* s, std::
size_t n)
22716JSON_HEDLEY_NON_NULL(1)
22717inline
nlohmann::json::json_pointer operator
"" _json_pointer(const
char* s, std::
size_t n)
22726#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
22727 #pragma GCC diagnostic pop
22729#if defined(__clang__)
22730 #pragma GCC diagnostic pop
22734#undef JSON_INTERNAL_CATCH
22738#undef JSON_HAS_CPP_14
22739#undef JSON_HAS_CPP_17
22740#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
22741#undef NLOHMANN_BASIC_JSON_TPL
22744#undef JSON_HEDLEY_ALWAYS_INLINE
22745#undef JSON_HEDLEY_ARM_VERSION
22746#undef JSON_HEDLEY_ARM_VERSION_CHECK
22747#undef JSON_HEDLEY_ARRAY_PARAM
22748#undef JSON_HEDLEY_ASSUME
22749#undef JSON_HEDLEY_BEGIN_C_DECLS
22750#undef JSON_HEDLEY_C_DECL
22751#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
22752#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
22753#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
22754#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
22755#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
22756#undef JSON_HEDLEY_CLANG_HAS_FEATURE
22757#undef JSON_HEDLEY_CLANG_HAS_WARNING
22758#undef JSON_HEDLEY_COMPCERT_VERSION
22759#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
22760#undef JSON_HEDLEY_CONCAT
22761#undef JSON_HEDLEY_CONCAT_EX
22762#undef JSON_HEDLEY_CONST
22763#undef JSON_HEDLEY_CONST_CAST
22764#undef JSON_HEDLEY_CONSTEXPR
22765#undef JSON_HEDLEY_CPP_CAST
22766#undef JSON_HEDLEY_CRAY_VERSION
22767#undef JSON_HEDLEY_CRAY_VERSION_CHECK
22768#undef JSON_HEDLEY_DEPRECATED
22769#undef JSON_HEDLEY_DEPRECATED_FOR
22770#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
22771#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
22772#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
22773#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
22774#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
22775#undef JSON_HEDLEY_DIAGNOSTIC_POP
22776#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
22777#undef JSON_HEDLEY_DMC_VERSION
22778#undef JSON_HEDLEY_DMC_VERSION_CHECK
22779#undef JSON_HEDLEY_EMPTY_BASES
22780#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
22781#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
22782#undef JSON_HEDLEY_END_C_DECLS
22783#undef JSON_HEDLEY_FALL_THROUGH
22784#undef JSON_HEDLEY_FLAGS
22785#undef JSON_HEDLEY_FLAGS_CAST
22786#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
22787#undef JSON_HEDLEY_GCC_HAS_BUILTIN
22788#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
22789#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
22790#undef JSON_HEDLEY_GCC_HAS_EXTENSION
22791#undef JSON_HEDLEY_GCC_HAS_FEATURE
22792#undef JSON_HEDLEY_GCC_HAS_WARNING
22793#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
22794#undef JSON_HEDLEY_GCC_VERSION
22795#undef JSON_HEDLEY_GCC_VERSION_CHECK
22796#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
22797#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
22798#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
22799#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
22800#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
22801#undef JSON_HEDLEY_GNUC_HAS_FEATURE
22802#undef JSON_HEDLEY_GNUC_HAS_WARNING
22803#undef JSON_HEDLEY_GNUC_VERSION
22804#undef JSON_HEDLEY_GNUC_VERSION_CHECK
22805#undef JSON_HEDLEY_HAS_ATTRIBUTE
22806#undef JSON_HEDLEY_HAS_BUILTIN
22807#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
22808#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
22809#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
22810#undef JSON_HEDLEY_HAS_EXTENSION
22811#undef JSON_HEDLEY_HAS_FEATURE
22812#undef JSON_HEDLEY_HAS_WARNING
22813#undef JSON_HEDLEY_IAR_VERSION
22814#undef JSON_HEDLEY_IAR_VERSION_CHECK
22815#undef JSON_HEDLEY_IBM_VERSION
22816#undef JSON_HEDLEY_IBM_VERSION_CHECK
22817#undef JSON_HEDLEY_IMPORT
22818#undef JSON_HEDLEY_INLINE
22819#undef JSON_HEDLEY_INTEL_VERSION
22820#undef JSON_HEDLEY_INTEL_VERSION_CHECK
22821#undef JSON_HEDLEY_IS_CONSTANT
22822#undef JSON_HEDLEY_IS_CONSTEXPR_
22823#undef JSON_HEDLEY_LIKELY
22824#undef JSON_HEDLEY_MALLOC
22825#undef JSON_HEDLEY_MESSAGE
22826#undef JSON_HEDLEY_MSVC_VERSION
22827#undef JSON_HEDLEY_MSVC_VERSION_CHECK
22828#undef JSON_HEDLEY_NEVER_INLINE
22829#undef JSON_HEDLEY_NO_ESCAPE
22830#undef JSON_HEDLEY_NON_NULL
22831#undef JSON_HEDLEY_NO_RETURN
22832#undef JSON_HEDLEY_NO_THROW
22833#undef JSON_HEDLEY_NULL
22834#undef JSON_HEDLEY_PELLES_VERSION
22835#undef JSON_HEDLEY_PELLES_VERSION_CHECK
22836#undef JSON_HEDLEY_PGI_VERSION
22837#undef JSON_HEDLEY_PGI_VERSION_CHECK
22838#undef JSON_HEDLEY_PREDICT
22839#undef JSON_HEDLEY_PRINTF_FORMAT
22840#undef JSON_HEDLEY_PRIVATE
22841#undef JSON_HEDLEY_PUBLIC
22842#undef JSON_HEDLEY_PURE
22843#undef JSON_HEDLEY_REINTERPRET_CAST
22844#undef JSON_HEDLEY_REQUIRE
22845#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
22846#undef JSON_HEDLEY_REQUIRE_MSG
22847#undef JSON_HEDLEY_RESTRICT
22848#undef JSON_HEDLEY_RETURNS_NON_NULL
22849#undef JSON_HEDLEY_SENTINEL
22850#undef JSON_HEDLEY_STATIC_ASSERT
22851#undef JSON_HEDLEY_STATIC_CAST
22852#undef JSON_HEDLEY_STRINGIFY
22853#undef JSON_HEDLEY_STRINGIFY_EX
22854#undef JSON_HEDLEY_SUNPRO_VERSION
22855#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
22856#undef JSON_HEDLEY_TINYC_VERSION
22857#undef JSON_HEDLEY_TINYC_VERSION_CHECK
22858#undef JSON_HEDLEY_TI_VERSION
22859#undef JSON_HEDLEY_TI_VERSION_CHECK
22860#undef JSON_HEDLEY_UNAVAILABLE
22861#undef JSON_HEDLEY_UNLIKELY
22862#undef JSON_HEDLEY_UNPREDICTABLE
22863#undef JSON_HEDLEY_UNREACHABLE
22864#undef JSON_HEDLEY_UNREACHABLE_RETURN
22865#undef JSON_HEDLEY_VERSION
22866#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
22867#undef JSON_HEDLEY_VERSION_DECODE_MINOR
22868#undef JSON_HEDLEY_VERSION_DECODE_REVISION
22869#undef JSON_HEDLEY_VERSION_ENCODE
22870#undef JSON_HEDLEY_WARNING
22871#undef JSON_HEDLEY_WARN_UNUSED_RESULT
a class to store JSON values
Definition json.hpp:14709
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(A1 &&a1, A2 &&a2, const bool strict=true, const bool allow_exceptions=true)
Create a JSON value from an input in BSON format.
Definition json.hpp:21817
reference back()
access the last element
Definition json.hpp:18173
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition json.hpp:19717
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(A1 &&a1, A2 &&a2, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition json.hpp:21642
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(detail::input_adapter &&i, const bool strict=true, const bool allow_exceptions=true)
Create a JSON value from an input in BSON format.
Definition json.hpp:21801
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.hpp:18240
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition json.hpp:14820
size_type count(KeyT &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:18571
iterator begin() noexcept
returns an iterator to the first element
Definition json.hpp:18674
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(detail::input_adapter &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition json.hpp:21626
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
comparison: equal
Definition json.hpp:20214
friend bool operator>(const ScalarType lhs, const_reference rhs) noexcept
comparison: greater than
Definition json.hpp:20551
iterator end() noexcept
returns an iterator to one past the last element
Definition json.hpp:18745
bool empty() const noexcept
checks whether the container is empty.
Definition json.hpp:19123
void insert(const_iterator first, const_iterator last)
inserts elements
Definition json.hpp:19910
void push_back(initializer_list_t init)
add an object to an object
Definition json.hpp:19548
const_iterator end() const noexcept
returns a const iterator to one past the last element
Definition json.hpp:18755
void update(const_reference j)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:19952
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(detail::input_adapter &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in CBOR format
Definition json.hpp:21517
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition json.hpp:18889
iterator insert(const_iterator pos, basic_json &&val)
inserts element
Definition json.hpp:19739
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(detail::input_adapter &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
Definition json.hpp:21714
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:18815
reference operator[](const typename object_t::key_type &key)
access specified object element
Definition json.hpp:17798
size_type size() const noexcept
returns the number of elements
Definition json.hpp:19195
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(detail::input_adapter &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true)
deserialize from a compatible input
Definition json.hpp:20745
void update(const_iterator first, const_iterator last)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:20003
detail::out_of_range out_of_range
exception indicating access out of the defined range
Definition json.hpp:14782
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.hpp:16612
basic_json value_type
the type of elements in a basic_json container
Definition json.hpp:14799
constexpr bool is_number() const noexcept
return whether value is a number
Definition json.hpp:16743
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.hpp:19265
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.hpp:18432
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts elements
Definition json.hpp:19768
BasicJsonType get() const
get special-case overload
Definition json.hpp:17124
iterator insert_iterator(const_iterator pos, Args &&... args)
Definition json.hpp:19679
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.hpp:16133
detail::other_error other_error
exception indicating other library errors
Definition json.hpp:14784
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition json.hpp:16828
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:17271
std::size_t size_type
a type to represent container sizes
Definition json.hpp:14809
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:19067
reference front()
access the first element
Definition json.hpp:18129
detail::type_error type_error
exception indicating executing a member function with a wrong type
Definition json.hpp:14780
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts elements
Definition json.hpp:19816
const value_type & const_reference
the type of an element const reference
Definition json.hpp:14804
friend bool operator>(const_reference lhs, const ScalarType rhs) noexcept
comparison: greater than
Definition json.hpp:20540
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition json.hpp:14822
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:21311
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:17368
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(A1 &&a1, A2 &&a2, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
Definition json.hpp:21730
const_reference front() const
access the first element
Definition json.hpp:18137
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.hpp:18345
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition json.hpp:15072
BooleanType boolean_t
a type for a boolean
Definition json.hpp:15151
const_iterator begin() const noexcept
returns a const iterator to the first element
Definition json.hpp:18684
const_reverse_iterator rend() const noexcept
returns a const reverse iterator to one before the first
Definition json.hpp:18860
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:16560
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(A1 &&a1, A2 &&a2, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in CBOR format
Definition json.hpp:21533
const_reverse_iterator rbegin() const noexcept
returns a const reverse iterator to the last element
Definition json.hpp:18823
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:21403
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.hpp:19649
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition json.hpp:20987
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition json.hpp:18918
friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
serialize to stream
Definition json.hpp:20642
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition json.hpp:20483
friend bool operator>=(const ScalarType lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition json.hpp:20597
StringType string_t
a type for a string
Definition json.hpp:15125
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.hpp:16642
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:17333
void swap(array_t &other)
exchanges the values
Definition json.hpp:20086
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition json.hpp:14759
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:18075
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.hpp:14866
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition json.hpp:14753
friend bool operator>=(const_reference lhs, const ScalarType rhs) noexcept
comparison: greater than or equal
Definition json.hpp:20586
constexpr bool is_string() const noexcept
return whether value is a string
Definition json.hpp:16894
basic_json get() const
get special-case overload
Definition json.hpp:17101
ValueType get() const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >())))
get a value (explicit); special case
Definition json.hpp:17225
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
Definition json.hpp:20319
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition json.hpp:14826
reference at(size_type idx)
access specified array element with bounds checking
Definition json.hpp:17519
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:21985
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition json.hpp:20575
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.hpp:22049
static std::vector< uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.hpp:21214
basic_json(CompatibleType &&val) noexcept(noexcept(JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value
Definition json.hpp:15843
friend bool operator<(const_reference lhs, const ScalarType rhs) noexcept
comparison: less than
Definition json.hpp:20448
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.hpp:22581
friend bool operator<=(const_reference lhs, const ScalarType rhs) noexcept
comparison: less than or equal
Definition json.hpp:20494
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
Definition json.hpp:22110
const_reference back() const
access the last element
Definition json.hpp:18183
static std::vector< uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:21118
AllocatorType< basic_json > allocator_type
the allocator type
Definition json.hpp:14812
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
Definition json.hpp:20529
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.hpp:18467
NumberFloatType number_float_t
a type for a number (floating-point)
Definition json.hpp:15362
iterator find(KeyT &&key)
find an element in a JSON object
Definition json.hpp:18520
static bool sax_parse(detail::input_adapter &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true)
generate SAX events
Definition json.hpp:20814
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.hpp:16089
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:21942
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.hpp:20054
const_iterator cend() const noexcept
returns a const iterator to one past the last element
Definition json.hpp:18785
constexpr bool is_null() const noexcept
return whether value is null
Definition json.hpp:16691
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
Definition json.hpp:18604
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.hpp:17617
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition json.hpp:16713
NumberIntegerType number_integer_t
a type for a number (integer)
Definition json.hpp:15223
basic_json & operator=(basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value)
copy assignment
Definition json.hpp:16469
basic_json(basic_json &&other) noexcept
move constructor
Definition json.hpp:16432
detail::exception exception
general exception of the basic_json class
Definition json.hpp:14774
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:22406
const_reference operator[](size_type idx) const
access specified array element
Definition json.hpp:17760
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:21899
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.hpp:16669
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.hpp:15880
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements
Definition json.hpp:19869
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:17174
json_sax< basic_json > json_sax_t
SAX interface type, see nlohmann::json_sax.
Definition json.hpp:14763
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.hpp:16921
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
Definition json.hpp:20372
typename parser::parse_event_t parse_event_t
parser event types
Definition json.hpp:15661
friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept
comparison: not equal
Definition json.hpp:20341
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.hpp:17566
const_reference operator[](const typename object_t::key_type &key) const
read-only access specified object element
Definition json.hpp:17847
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.hpp:18635
static basic_json parse(IteratorType first, IteratorType last, const parser_callback_t cb=nullptr, const bool allow_exceptions=true)
deserialize from an iterator range with contiguous storage
Definition json.hpp:20877
void push_back(const basic_json &val)
add an object to an array
Definition json.hpp:19443
typename parser::parser_callback_t parser_callback_t
per-element parser callback type
Definition json.hpp:15712
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:15999
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.hpp:16160
basic_json flatten() const
return flattened JSON value
Definition json.hpp:22012
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition json.hpp:15294
~basic_json() noexcept
destructor
Definition json.hpp:16502
friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept
comparison: equal
Definition json.hpp:20285
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition json.hpp:16772
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.hpp:16800
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.hpp:16225
friend bool operator<(const ScalarType lhs, const_reference rhs) noexcept
comparison: less than
Definition json.hpp:20459
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:17320
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:19517
reference emplace_back(Args &&... args)
add an object to an array
Definition json.hpp:19596
friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
Definition json.hpp:20666
void clear() noexcept
clears the contents
Definition json.hpp:19335
detail::invalid_iterator invalid_iterator
exception indicating errors with iterators
Definition json.hpp:14778
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition json.hpp:14824
void swap(object_t &other)
exchanges the values
Definition json.hpp:20119
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.hpp:17427
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:21871
value_type & reference
the type of an element reference
Definition json.hpp:14802
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.hpp:18852
reference operator[](size_type idx)
access specified array element
Definition json.hpp:17714
void push_back(basic_json &&val)
add an object to an array
Definition json.hpp:19406
ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
Definition json.hpp:15022
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.hpp:17668
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:18025
constexpr auto get() const noexcept -> decltype(std::declval< const basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:17380
friend bool operator<=(const ScalarType lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition json.hpp:20505
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition json.hpp:18714
void swap(string_t &other)
exchanges the values
Definition json.hpp:20152
reference operator+=(const basic_json &val)
add an object to an array
Definition json.hpp:19467
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:18003
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:19493
detail::error_handler_t error_handler_t
how to treat decoding errors
Definition json.hpp:14757
const_iterator find(KeyT &&key) const
find an element in a JSON object
Definition json.hpp:18537
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.hpp:15776
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition json.hpp:20944
reference operator+=(basic_json &&val)
add an object to an array
Definition json.hpp:19433
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:21388
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:21411
basic_json(const value_t v)
create an empty value with a given type
Definition json.hpp:15752
friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept
comparison: equal
Definition json.hpp:20296
constexpr bool is_array() const noexcept
return whether value is an array
Definition json.hpp:16872
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition json.hpp:14815
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:19059
detail::parse_error parse_error
exception indicating a parse error
Definition json.hpp:14776
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.hpp:19566
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.hpp:14834
basic_json(const basic_json &other)
copy constructor
Definition json.hpp:16349
constexpr bool is_object() const noexcept
return whether value is an object
Definition json.hpp:16850
ReferenceType get_ref()
get a reference value (implicit)
Definition json.hpp:17414
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
wrapper to access iterator member functions in range-based for
Definition json.hpp:18982
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition json.hpp:14807
friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept
comparison: not equal
Definition json.hpp:20330
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition json.hpp:14817
deserialization of CBOR, MessagePack, and UBJSON values
Definition json.hpp:5176
static constexpr bool little_endianess(int num=1) noexcept
determine system byte order
Definition json.hpp:5268
bool sax_parse(const input_format_t format, json_sax_t *sax_, const bool strict=true)
Definition json.hpp:5210
binary_reader(input_adapter_t adapter)
create a binary reader
Definition json.hpp:5189
serialization to CBOR and MessagePack values
Definition json.hpp:11319
void write_ubjson(const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true)
Definition json.hpp:11843
binary_writer(output_adapter_t< CharType > adapter)
create a binary writer
Definition json.hpp:11328
void write_bson(const BasicJsonType &j)
Definition json.hpp:11337
void write_cbor(const BasicJsonType &j)
Definition json.hpp:11357
void write_msgpack(const BasicJsonType &j)
Definition json.hpp:11601
general exception of the basic_json class
Definition json.hpp:1865
const int id
the id of the exception
Definition json.hpp:1875
JSON_HEDLEY_RETURNS_NON_NULL const char * what() const noexcept override
returns the explanatory string
Definition json.hpp:1869
exception indicating errors with iterators
Definition json.hpp:2022
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition json.hpp:9347
bool operator<(const iter_impl &other) const
comparison: smaller
Definition json.hpp:9739
iter_impl operator-(difference_type i) const
subtract from iterator
Definition json.hpp:9853
iter_impl const operator--(int)
post-decrement (it–)
Definition json.hpp:9660
bool operator==(const iter_impl &other) const
comparison: equal
Definition json.hpp:9703
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition json.hpp:9372
iter_impl()=default
default constructor
iter_impl & operator--()
pre-decrement (–it)
Definition json.hpp:9671
difference_type operator-(const iter_impl &other) const
return difference
Definition json.hpp:9864
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition json.hpp:9444
reference operator*() const
return a reference to the value pointed to by the iterator
Definition json.hpp:9546
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition json.hpp:9784
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition json.hpp:9466
pointer operator->() const
dereference the iterator
Definition json.hpp:9583
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition json.hpp:9434
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:9378
iter_impl const operator++(int)
post-increment (it++)
Definition json.hpp:9617
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition json.hpp:9456
iter_impl(pointer object) noexcept
constructor for a given JSON instance
Definition json.hpp:9392
iter_impl operator+(difference_type i) const
add to iterator
Definition json.hpp:9831
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition json.hpp:9842
const object_t::key_type & key() const
return the key of an object iterator
Definition json.hpp:9916
bool operator>(const iter_impl &other) const
comparison: greater than
Definition json.hpp:9775
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition json.hpp:9370
reference value() const
return the value of an iterator
Definition json.hpp:9932
iter_impl & operator++()
pre-increment (++it)
Definition json.hpp:9628
reference operator[](difference_type n) const
access to successor
Definition json.hpp:9885
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition json.hpp:9766
std::bidirectional_iterator_tag iterator_category
Definition json.hpp:9367
iter_impl & operator+=(difference_type i)
add to iterator
Definition json.hpp:9793
bool operator!=(const iter_impl &other) const
comparison: not equal
Definition json.hpp:9730
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:9374
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition json.hpp:9822
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition json.hpp:3344
IteratorType::reference value() const
return value of the iterator
Definition json.hpp:3378
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition json.hpp:3329
iteration_proxy_value & operator*()
dereference operator (needed for range-based for)
Definition json.hpp:3323
const string_type & key() const
return key of the iterator
Definition json.hpp:3350
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition json.hpp:3338
proxy class for the items() function
Definition json.hpp:3386
iteration_proxy_value< IteratorType > begin() noexcept
return iterator begin (needed for range-based for)
Definition json.hpp:3397
iteration_proxy_value< IteratorType > end() noexcept
return iterator end (needed for range-based for)
Definition json.hpp:3403
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition json.hpp:3393
Definition json.hpp:11102
a template for a reverse iterator class
Definition json.hpp:9983
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition json.hpp:9992
json_reverse_iterator const operator--(int)
post-decrement (it–)
Definition json.hpp:10011
typename Base::reference reference
the reference type for the pointed-to element
Definition json.hpp:9989
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition json.hpp:10035
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition json.hpp:10023
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition json.hpp:9987
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition json.hpp:9996
reference operator[](difference_type n) const
access to successor
Definition json.hpp:10047
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition json.hpp:10041
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition json.hpp:10029
json_reverse_iterator const operator++(int)
post-increment (it++)
Definition json.hpp:9999
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition json.hpp:10053
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition json.hpp:10017
reference value() const
return the value of an iterator
Definition json.hpp:10060
json_reverse_iterator & operator++()
pre-increment (++it)
Definition json.hpp:10005
SAX implementation to create a JSON value from SAX events.
Definition json.hpp:4455
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true)
Definition json.hpp:4467
lexical analysis
Definition json.hpp:7162
token_type
token types for the parser
Definition json.hpp:7171
@ value_float
an floating point number – use get_number_float() for actual value
Definition json.hpp:7179
@ begin_array
the character for array begin [
Definition json.hpp:7180
@ value_string
a string – use get_string() for actual value
Definition json.hpp:7176
@ end_array
the character for array end ]
Definition json.hpp:7182
@ uninitialized
indicating the scanner is uninitialized
Definition json.hpp:7172
@ parse_error
indicating a parse error
Definition json.hpp:7186
@ value_integer
a signed integer – use get_number_integer() for actual value
Definition json.hpp:7178
@ value_separator
the value separator ,
Definition json.hpp:7185
@ end_object
the character for object end }
Definition json.hpp:7183
@ literal_true
the true literal
Definition json.hpp:7173
@ begin_object
the character for object begin {
Definition json.hpp:7181
@ value_unsigned
an unsigned integer – use get_number_unsigned() for actual value
Definition json.hpp:7177
@ literal_null
the null literal
Definition json.hpp:7175
@ end_of_input
indicating the end of the input buffer
Definition json.hpp:7187
@ name_separator
the name separator :
Definition json.hpp:7184
@ literal_or_value
a literal or the begin of a value (only for diagnostics)
Definition json.hpp:7188
@ literal_false
the false literal
Definition json.hpp:7174
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
Definition json.hpp:8470
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:7194
std::string get_token_string() const
Definition json.hpp:8488
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition json.hpp:8458
bool skip_bom()
skip the UTF-8 byte order mark
Definition json.hpp:8526
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
Definition json.hpp:8513
constexpr position_t get_position() const noexcept
return position of last read token
Definition json.hpp:8480
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition json.hpp:8464
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition json.hpp:8452
exception indicating other library errors
Definition json.hpp:2161
exception indicating access out of the defined range
Definition json.hpp:2123
Definition json.hpp:11283
output adapter for output streams
Definition json.hpp:11236
output adapter for basic_string
Definition json.hpp:11260
output adapter for byte vectors
Definition json.hpp:11212
exception indicating a parse error
Definition json.hpp:1936
static parse_error create(int id_, const position_t &pos, const std::string &what_arg)
create a parse error exception
Definition json.hpp:1947
const std::size_t byte
byte index of the parse error
Definition json.hpp:1971
syntax analysis
Definition json.hpp:8685
void parse(const bool strict, BasicJsonType &result)
public parser interface
Definition json.hpp:8733
parser(detail::input_adapter_t &&adapter, const parser_callback_t cb=nullptr, const bool allow_exceptions_=true)
a parser reading from an input adapter
Definition json.hpp:8714
bool accept(const bool strict=true)
public accept interface
Definition json.hpp:8794
parse_event_t
Definition json.hpp:8695
@ value
the parser finished reading a JSON value
Definition json.hpp:8707
@ key
the parser read a key of a value in an object
Definition json.hpp:8705
@ array_end
the parser read ] and finished processing a JSON array
Definition json.hpp:8703
@ array_start
the parser read [ and started to process a JSON array
Definition json.hpp:8701
@ object_start
the parser read { and started to process a JSON object
Definition json.hpp:8697
@ object_end
the parser read } and finished processing a JSON object
Definition json.hpp:8699
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition json.hpp:9208
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition json.hpp:9202
void set_begin() noexcept
set iterator to a defined beginning
Definition json.hpp:9190
void set_end() noexcept
set iterator to a defined past the end
Definition json.hpp:9196
Definition json.hpp:13788
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:13837
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition json.hpp:13802
exception indicating executing a member function with a wrong type
Definition json.hpp:2076
JSON Pointer.
Definition json.hpp:10093
json_pointer & operator/=(std::string token)
append an unescaped reference token at the end of this JSON pointer
Definition json.hpp:10194
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition json.hpp:10170
std::string to_string() const
return a string representation of the JSON pointer
Definition json.hpp:10138
friend bool operator==(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for equality
Definition json.hpp:11059
void pop_back()
remove last reference token
Definition json.hpp:10320
const std::string & back() const
return last reference token
Definition json.hpp:10344
bool empty() const noexcept
return whether pointer points to the root document
Definition json.hpp:10391
friend bool operator!=(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for inequality
Definition json.hpp:11076
void push_back(const std::string &token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:10366
json_pointer(const std::string &s="")
create JSON pointer
Definition json.hpp:10120
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:10236
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:10257
friend json_pointer operator/(const json_pointer &ptr, std::size_t array_index)
create a new JSON pointer by appending the array-index-token at the end of the JSON pointer
Definition json.hpp:10277
void push_back(std::string &&token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:10372
json_pointer & operator/=(std::size_t array_index)
append an array index at the end of this JSON pointer
Definition json.hpp:10216
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition json.hpp:10295
implements the Grisu2 algorithm for binary to decimal floating-point conversion.
Definition json.hpp:12687
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
Definition json.hpp:13472
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:13624
boundaries compute_boundaries(FloatType value)
Definition json.hpp:12831
int find_largest_pow10(const std::uint32_t n, std::uint32_t &pow10)
Definition json.hpp:13134
JSON_HEDLEY_RETURNS_NON_NULL char * append_exponent(char *buf, int e)
appends a decimal representation of e to buf
Definition json.hpp:13572
void grisu2_digit_gen(char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
Definition json.hpp:13231
cached_power get_cached_power_for_binary_exponent(int e)
Definition json.hpp:12970
detail namespace with internal helper functions
Definition json.hpp:87
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.hpp:2877
value_t
the JSON type enumeration
Definition json.hpp:2855
@ null
null value
Definition json.hpp:2856
@ number_integer
number value (signed integer)
Definition json.hpp:2861
@ boolean
boolean value
Definition json.hpp:2860
@ discarded
discarded by the the parser callback function
Definition json.hpp:2864
@ object
object (unordered set of name/value pairs)
Definition json.hpp:2857
@ string
string value
Definition json.hpp:2859
@ number_float
number value (floating-point)
Definition json.hpp:2863
@ number_unsigned
number value (unsigned integer)
Definition json.hpp:2862
@ array
array (ordered collection of values)
Definition json.hpp:2858
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:13709
std::shared_ptr< input_adapter_protocol > input_adapter_t
a type to simplify interfaces
Definition json.hpp:3912
error_handler_t
how to treat decoding errors
Definition json.hpp:13780
@ strict
throw a type_error exception in case of invalid UTF-8
Definition json.hpp:13781
@ ignore
ignore invalid UTF-8 sequences
Definition json.hpp:13783
@ replace
replace invalid UTF-8 sequences with U+FFFD
Definition json.hpp:13782
input_format_t
the supported input formats
Definition json.hpp:3887
std::shared_ptr< output_adapter_protocol< CharType > > output_adapter_t
a type to simplify interfaces
Definition json.hpp:11207
namespace for Niels Lohmann
Definition json.hpp:85
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:22620
basic_json<> json
default JSON class
Definition json.hpp:2445
default JSONSerializer template argument
Definition json.hpp:3799
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:3827
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:3810
Definition json.hpp:12818
Definition json.hpp:12957
Definition json.hpp:12700
static diyfp normalize(diyfp x) noexcept
normalize x such that the significand is >= 2^(q-1)
Definition json.hpp:12789
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:12806
static diyfp mul(const diyfp &x, const diyfp &y) noexcept
returns x * y
Definition json.hpp:12724
static diyfp sub(const diyfp &x, const diyfp &y) noexcept
returns x - y
Definition json.hpp:12712
an iterator value
Definition json.hpp:9288
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition json.hpp:9292
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition json.hpp:9290
abstract output adapter interface
Definition json.hpp:11199
struct to capture the start position of the current token
Definition json.hpp:90
std::size_t lines_read
the number of lines read
Definition json.hpp:96
std::size_t chars_read_current_line
the number of characters read in the current line
Definition json.hpp:94
std::size_t chars_read_total
the total number of characters read
Definition json.hpp:92
SAX interface.
Definition json.hpp:4334
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
virtual bool null()=0
a null value was read
typename BasicJsonType::number_integer_t number_integer_t
type for (signed) integers
Definition json.hpp:4336
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
type for unsigned integers
Definition json.hpp:4338
typename BasicJsonType::number_float_t number_float_t
type for floating-point numbers
Definition json.hpp:4340
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
virtual bool boolean(bool val)=0
a boolean value was read
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
type for strings
Definition json.hpp:4342
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
std::size_t operator()(const nlohmann::json &j) const
return a hash value for a JSON object
Definition json.hpp:22643
bool operator()(nlohmann::detail::value_t lhs, nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.hpp:22661