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 9
35 #define NLOHMANN_JSON_VERSION_PATCH 1
40 #include <initializer_list>
59 #include <forward_list>
64 #include <type_traits>
65 #include <unordered_map>
89 std::size_t chars_read_total = 0;
91 std::size_t chars_read_current_line = 0;
93 std::size_t lines_read = 0;
96 constexpr
operator size_t()
const
98 return chars_read_total;
122 #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 13)
123 #if defined(JSON_HEDLEY_VERSION)
124 #undef JSON_HEDLEY_VERSION
126 #define JSON_HEDLEY_VERSION 13
128 #if defined(JSON_HEDLEY_STRINGIFY_EX)
129 #undef JSON_HEDLEY_STRINGIFY_EX
131 #define JSON_HEDLEY_STRINGIFY_EX(x) #x
133 #if defined(JSON_HEDLEY_STRINGIFY)
134 #undef JSON_HEDLEY_STRINGIFY
136 #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
138 #if defined(JSON_HEDLEY_CONCAT_EX)
139 #undef JSON_HEDLEY_CONCAT_EX
141 #define JSON_HEDLEY_CONCAT_EX(a,b) a##b
143 #if defined(JSON_HEDLEY_CONCAT)
144 #undef JSON_HEDLEY_CONCAT
146 #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
148 #if defined(JSON_HEDLEY_CONCAT3_EX)
149 #undef JSON_HEDLEY_CONCAT3_EX
151 #define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
153 #if defined(JSON_HEDLEY_CONCAT3)
154 #undef JSON_HEDLEY_CONCAT3
156 #define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
158 #if defined(JSON_HEDLEY_VERSION_ENCODE)
159 #undef JSON_HEDLEY_VERSION_ENCODE
161 #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
163 #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
164 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
166 #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
168 #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
169 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
171 #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
173 #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
174 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
176 #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
178 #if defined(JSON_HEDLEY_GNUC_VERSION)
179 #undef JSON_HEDLEY_GNUC_VERSION
181 #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
182 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
183 #elif defined(__GNUC__)
184 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
187 #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
188 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
190 #if defined(JSON_HEDLEY_GNUC_VERSION)
191 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
193 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
196 #if defined(JSON_HEDLEY_MSVC_VERSION)
197 #undef JSON_HEDLEY_MSVC_VERSION
199 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000)
200 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
201 #elif defined(_MSC_FULL_VER)
202 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
203 #elif defined(_MSC_VER)
204 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
207 #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
208 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
210 #if !defined(_MSC_VER)
211 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
212 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
213 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
214 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
215 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
217 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
220 #if defined(JSON_HEDLEY_INTEL_VERSION)
221 #undef JSON_HEDLEY_INTEL_VERSION
223 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE)
224 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
225 #elif defined(__INTEL_COMPILER)
226 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
229 #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
230 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
232 #if defined(JSON_HEDLEY_INTEL_VERSION)
233 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
235 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
238 #if defined(JSON_HEDLEY_PGI_VERSION)
239 #undef JSON_HEDLEY_PGI_VERSION
241 #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
242 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
245 #if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
246 #undef JSON_HEDLEY_PGI_VERSION_CHECK
248 #if defined(JSON_HEDLEY_PGI_VERSION)
249 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
251 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
254 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
255 #undef JSON_HEDLEY_SUNPRO_VERSION
257 #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
258 #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)
259 #elif defined(__SUNPRO_C)
260 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
261 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
262 #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)
263 #elif defined(__SUNPRO_CC)
264 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
267 #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
268 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
270 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
271 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
273 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
276 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
277 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
279 #if defined(__EMSCRIPTEN__)
280 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
283 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
284 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
286 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
287 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
289 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
292 #if defined(JSON_HEDLEY_ARM_VERSION)
293 #undef JSON_HEDLEY_ARM_VERSION
295 #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
296 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
297 #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
298 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
301 #if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
302 #undef JSON_HEDLEY_ARM_VERSION_CHECK
304 #if defined(JSON_HEDLEY_ARM_VERSION)
305 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
307 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
310 #if defined(JSON_HEDLEY_IBM_VERSION)
311 #undef JSON_HEDLEY_IBM_VERSION
313 #if defined(__ibmxl__)
314 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
315 #elif defined(__xlC__) && defined(__xlC_ver__)
316 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
317 #elif defined(__xlC__)
318 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
321 #if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
322 #undef JSON_HEDLEY_IBM_VERSION_CHECK
324 #if defined(JSON_HEDLEY_IBM_VERSION)
325 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
327 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
330 #if defined(JSON_HEDLEY_TI_VERSION)
331 #undef JSON_HEDLEY_TI_VERSION
334 defined(__TI_COMPILER_VERSION__) && \
336 defined(__TMS470__) || defined(__TI_ARM__) || \
337 defined(__MSP430__) || \
338 defined(__TMS320C2000__) \
340 #if (__TI_COMPILER_VERSION__ >= 16000000)
341 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
345 #if defined(JSON_HEDLEY_TI_VERSION_CHECK)
346 #undef JSON_HEDLEY_TI_VERSION_CHECK
348 #if defined(JSON_HEDLEY_TI_VERSION)
349 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
351 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
354 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
355 #undef JSON_HEDLEY_TI_CL2000_VERSION
357 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
358 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
361 #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
362 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
364 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
365 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
367 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
370 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
371 #undef JSON_HEDLEY_TI_CL430_VERSION
373 #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
374 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
377 #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
378 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
380 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
381 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
383 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
386 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
387 #undef JSON_HEDLEY_TI_ARMCL_VERSION
389 #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
390 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
393 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
394 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
396 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
397 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
399 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
402 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
403 #undef JSON_HEDLEY_TI_CL6X_VERSION
405 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
406 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
409 #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
410 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
412 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
413 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
415 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
418 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
419 #undef JSON_HEDLEY_TI_CL7X_VERSION
421 #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
422 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
425 #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
426 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
428 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
429 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
431 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
434 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
435 #undef JSON_HEDLEY_TI_CLPRU_VERSION
437 #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
438 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
441 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
442 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
444 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
445 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
447 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
450 #if defined(JSON_HEDLEY_CRAY_VERSION)
451 #undef JSON_HEDLEY_CRAY_VERSION
454 #if defined(_RELEASE_PATCHLEVEL)
455 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
457 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
461 #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
462 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
464 #if defined(JSON_HEDLEY_CRAY_VERSION)
465 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
467 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
470 #if defined(JSON_HEDLEY_IAR_VERSION)
471 #undef JSON_HEDLEY_IAR_VERSION
473 #if defined(__IAR_SYSTEMS_ICC__)
475 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
477 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(VER / 100, __VER__ % 100, 0)
481 #if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
482 #undef JSON_HEDLEY_IAR_VERSION_CHECK
484 #if defined(JSON_HEDLEY_IAR_VERSION)
485 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
487 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
490 #if defined(JSON_HEDLEY_TINYC_VERSION)
491 #undef JSON_HEDLEY_TINYC_VERSION
493 #if defined(__TINYC__)
494 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
497 #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
498 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
500 #if defined(JSON_HEDLEY_TINYC_VERSION)
501 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
503 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
506 #if defined(JSON_HEDLEY_DMC_VERSION)
507 #undef JSON_HEDLEY_DMC_VERSION
510 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
513 #if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
514 #undef JSON_HEDLEY_DMC_VERSION_CHECK
516 #if defined(JSON_HEDLEY_DMC_VERSION)
517 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
519 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
522 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
523 #undef JSON_HEDLEY_COMPCERT_VERSION
525 #if defined(__COMPCERT_VERSION__)
526 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
529 #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
530 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
532 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
533 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
535 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
538 #if defined(JSON_HEDLEY_PELLES_VERSION)
539 #undef JSON_HEDLEY_PELLES_VERSION
541 #if defined(__POCC__)
542 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
545 #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
546 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
548 #if defined(JSON_HEDLEY_PELLES_VERSION)
549 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
551 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
554 #if defined(JSON_HEDLEY_GCC_VERSION)
555 #undef JSON_HEDLEY_GCC_VERSION
558 defined(JSON_HEDLEY_GNUC_VERSION) && \
559 !defined(__clang__) && \
560 !defined(JSON_HEDLEY_INTEL_VERSION) && \
561 !defined(JSON_HEDLEY_PGI_VERSION) && \
562 !defined(JSON_HEDLEY_ARM_VERSION) && \
563 !defined(JSON_HEDLEY_TI_VERSION) && \
564 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
565 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
566 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
567 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
568 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
569 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
570 !defined(__COMPCERT__)
571 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
574 #if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
575 #undef JSON_HEDLEY_GCC_VERSION_CHECK
577 #if defined(JSON_HEDLEY_GCC_VERSION)
578 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
580 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
583 #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
584 #undef JSON_HEDLEY_HAS_ATTRIBUTE
586 #if defined(__has_attribute)
587 #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
589 #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
592 #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
593 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
595 #if defined(__has_attribute)
596 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute)
598 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
601 #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
602 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
604 #if defined(__has_attribute)
605 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute)
607 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
610 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
611 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
614 defined(__has_cpp_attribute) && \
615 defined(__cplusplus) && \
616 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
617 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
619 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
622 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
623 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
625 #if !defined(__cplusplus) || !defined(__has_cpp_attribute)
626 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
628 !defined(JSON_HEDLEY_PGI_VERSION) && \
629 !defined(JSON_HEDLEY_IAR_VERSION) && \
630 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
631 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
632 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
634 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
637 #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
638 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
640 #if defined(__has_cpp_attribute) && defined(__cplusplus)
641 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
643 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
646 #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
647 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
649 #if defined(__has_cpp_attribute) && defined(__cplusplus)
650 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
652 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
655 #if defined(JSON_HEDLEY_HAS_BUILTIN)
656 #undef JSON_HEDLEY_HAS_BUILTIN
658 #if defined(__has_builtin)
659 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
661 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
664 #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
665 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
667 #if defined(__has_builtin)
668 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
670 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
673 #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
674 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
676 #if defined(__has_builtin)
677 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
679 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
682 #if defined(JSON_HEDLEY_HAS_FEATURE)
683 #undef JSON_HEDLEY_HAS_FEATURE
685 #if defined(__has_feature)
686 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
688 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
691 #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
692 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
694 #if defined(__has_feature)
695 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
697 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
700 #if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
701 #undef JSON_HEDLEY_GCC_HAS_FEATURE
703 #if defined(__has_feature)
704 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
706 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
709 #if defined(JSON_HEDLEY_HAS_EXTENSION)
710 #undef JSON_HEDLEY_HAS_EXTENSION
712 #if defined(__has_extension)
713 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
715 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
718 #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
719 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
721 #if defined(__has_extension)
722 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
724 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
727 #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
728 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
730 #if defined(__has_extension)
731 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
733 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
736 #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
737 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
739 #if defined(__has_declspec_attribute)
740 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
742 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
745 #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
746 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
748 #if defined(__has_declspec_attribute)
749 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
751 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
754 #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
755 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
757 #if defined(__has_declspec_attribute)
758 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
760 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
763 #if defined(JSON_HEDLEY_HAS_WARNING)
764 #undef JSON_HEDLEY_HAS_WARNING
766 #if defined(__has_warning)
767 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
769 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
772 #if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
773 #undef JSON_HEDLEY_GNUC_HAS_WARNING
775 #if defined(__has_warning)
776 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
778 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
781 #if defined(JSON_HEDLEY_GCC_HAS_WARNING)
782 #undef JSON_HEDLEY_GCC_HAS_WARNING
784 #if defined(__has_warning)
785 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
787 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
792 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
793 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
795 #if defined(__cplusplus)
796 # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
797 # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
798 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
799 JSON_HEDLEY_DIAGNOSTIC_PUSH \
800 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
801 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
803 JSON_HEDLEY_DIAGNOSTIC_POP
805 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
806 JSON_HEDLEY_DIAGNOSTIC_PUSH \
807 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
809 JSON_HEDLEY_DIAGNOSTIC_POP
813 #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
814 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
817 #if defined(JSON_HEDLEY_CONST_CAST)
818 #undef JSON_HEDLEY_CONST_CAST
820 #if defined(__cplusplus)
821 # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
823 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
824 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
825 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
826 # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
827 JSON_HEDLEY_DIAGNOSTIC_PUSH \
828 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
830 JSON_HEDLEY_DIAGNOSTIC_POP \
833 # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
836 #if defined(JSON_HEDLEY_REINTERPRET_CAST)
837 #undef JSON_HEDLEY_REINTERPRET_CAST
839 #if defined(__cplusplus)
840 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
842 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
845 #if defined(JSON_HEDLEY_STATIC_CAST)
846 #undef JSON_HEDLEY_STATIC_CAST
848 #if defined(__cplusplus)
849 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
851 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
854 #if defined(JSON_HEDLEY_CPP_CAST)
855 #undef JSON_HEDLEY_CPP_CAST
857 #if defined(__cplusplus)
858 # if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
859 # define JSON_HEDLEY_CPP_CAST(T, expr) \
860 JSON_HEDLEY_DIAGNOSTIC_PUSH \
861 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
863 JSON_HEDLEY_DIAGNOSTIC_POP
864 # elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
865 # define JSON_HEDLEY_CPP_CAST(T, expr) \
866 JSON_HEDLEY_DIAGNOSTIC_PUSH \
867 _Pragma("diag_suppress=Pe137") \
868 JSON_HEDLEY_DIAGNOSTIC_POP \
870 # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
873 # define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
877 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
878 defined(__clang__) || \
879 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
880 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
881 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
882 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
883 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
884 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
885 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
886 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
887 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
888 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
889 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
890 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
891 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
892 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
893 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
894 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
895 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
896 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
897 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
899 #define JSON_HEDLEY_PRAGMA(value)
902 #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
903 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
905 #if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
906 #undef JSON_HEDLEY_DIAGNOSTIC_POP
908 #if defined(__clang__)
909 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
910 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
911 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
912 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
913 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
914 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
915 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
916 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
917 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
918 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
919 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
920 #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
921 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
922 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
924 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
925 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
926 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
927 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
928 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
929 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
930 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
931 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
932 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
933 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
934 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
936 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
937 #define JSON_HEDLEY_DIAGNOSTIC_POP
940 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
941 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
943 #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
944 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
945 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
946 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
947 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
948 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
949 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
950 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
951 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
952 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
954 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
955 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
956 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
957 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
958 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
959 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
960 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
961 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
962 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
963 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
964 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
965 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
966 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
967 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
968 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
969 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
970 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
971 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
972 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
973 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
975 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
978 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
979 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
981 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
982 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
983 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
984 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
985 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
986 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
987 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
988 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
989 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
990 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
992 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
993 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
994 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
995 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
996 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
997 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
998 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
999 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1000 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1002 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1005 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1006 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1008 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1009 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1010 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1011 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1012 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1013 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1014 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1015 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1016 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1017 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1018 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1019 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1021 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1022 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1023 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1024 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1025 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1026 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1028 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1031 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1032 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1034 #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1035 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1036 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1037 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1038 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1039 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1041 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1044 #if defined(JSON_HEDLEY_DEPRECATED)
1045 #undef JSON_HEDLEY_DEPRECATED
1047 #if defined(JSON_HEDLEY_DEPRECATED_FOR)
1048 #undef JSON_HEDLEY_DEPRECATED_FOR
1050 #if JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0)
1051 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1052 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1053 #elif defined(__cplusplus) && (__cplusplus >= 201402L)
1054 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1055 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1057 JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) || \
1058 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1059 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1060 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1061 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1062 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1063 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1064 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1065 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1066 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1067 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1068 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1069 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1071 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1072 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1073 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1074 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1075 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1076 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1077 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1078 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1079 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1080 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1081 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1082 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1083 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1084 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1085 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1086 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1088 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1089 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0)
1090 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1091 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1092 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1093 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1094 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1096 #define JSON_HEDLEY_DEPRECATED(since)
1097 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1100 #if defined(JSON_HEDLEY_UNAVAILABLE)
1101 #undef JSON_HEDLEY_UNAVAILABLE
1104 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1105 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1106 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1107 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1109 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1118 #if (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1119 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1120 #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1121 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1122 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1123 #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1125 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1126 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1127 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1128 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1129 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1130 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1131 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1132 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1133 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1134 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1135 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1136 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1137 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1138 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1139 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1140 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1141 #define __attribute__((__warn_unused_result__))
1142 #define _MSG(msg) __attribute__((__warn_unused_result__))
1143 #elif defined(_Check_return_)
1144 #define _Check_return_
1145 #define _MSG(msg) _Check_return_
1151 #if defined(JSON_HEDLEY_SENTINEL)
1152 #undef JSON_HEDLEY_SENTINEL
1155 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1156 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1157 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1158 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0)
1159 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1161 #define JSON_HEDLEY_SENTINEL(position)
1164 #if defined(JSON_HEDLEY_NO_RETURN)
1165 #undef JSON_HEDLEY_NO_RETURN
1167 #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1168 #define JSON_HEDLEY_NO_RETURN __noreturn
1169 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1170 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1171 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1172 #define JSON_HEDLEY_NO_RETURN _Noreturn
1173 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1174 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1176 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1177 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1178 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1179 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1180 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1181 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1182 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1183 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1184 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1185 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1186 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1187 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1188 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1189 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1190 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1191 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1192 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1193 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1194 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1195 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
1196 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1197 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1198 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1199 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1200 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1201 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1202 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1204 #define JSON_HEDLEY_NO_RETURN
1207 #if defined(JSON_HEDLEY_NO_ESCAPE)
1208 #undef JSON_HEDLEY_NO_ESCAPE
1210 #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1211 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1213 #define JSON_HEDLEY_NO_ESCAPE
1216 #if defined(JSON_HEDLEY_UNREACHABLE)
1217 #undef JSON_HEDLEY_UNREACHABLE
1219 #if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1220 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1222 #if defined(JSON_HEDLEY_ASSUME)
1223 #undef JSON_HEDLEY_ASSUME
1226 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1227 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1228 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1229 #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1230 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1232 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1233 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1234 #if defined(__cplusplus)
1235 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1237 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1241 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1242 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1243 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1244 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1245 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5)
1246 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1247 #elif defined(JSON_HEDLEY_ASSUME)
1248 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1250 #if !defined(JSON_HEDLEY_ASSUME)
1251 #if defined(JSON_HEDLEY_UNREACHABLE)
1252 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1254 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1257 #if defined(JSON_HEDLEY_UNREACHABLE)
1259 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1260 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1261 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1263 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1266 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1268 #if !defined(JSON_HEDLEY_UNREACHABLE)
1269 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1272 JSON_HEDLEY_DIAGNOSTIC_PUSH
1273 #if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1274 #pragma clang diagnostic ignored "-Wpedantic"
1276 #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1277 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1279 #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1280 #if defined(__clang__)
1281 #pragma clang diagnostic ignored "-Wvariadic-macros"
1282 #elif defined(JSON_HEDLEY_GCC_VERSION)
1283 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1286 #if defined(JSON_HEDLEY_NON_NULL)
1287 #undef JSON_HEDLEY_NON_NULL
1290 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1291 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1292 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1293 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1294 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1296 #define JSON_HEDLEY_NON_NULL(...)
1298 JSON_HEDLEY_DIAGNOSTIC_POP
1300 #if defined(JSON_HEDLEY_PRINTF_FORMAT)
1301 #undef JSON_HEDLEY_PRINTF_FORMAT
1303 #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1304 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1305 #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1306 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1308 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1309 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1310 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1311 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1312 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1313 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1314 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1315 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1316 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1317 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1318 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1319 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1320 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1321 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1322 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1323 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1324 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1325 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1326 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1328 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1331 #if defined(JSON_HEDLEY_CONSTEXPR)
1332 #undef JSON_HEDLEY_CONSTEXPR
1334 #if defined(__cplusplus)
1335 #if __cplusplus >= 201103L
1336 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1339 #if !defined(JSON_HEDLEY_CONSTEXPR)
1340 #define JSON_HEDLEY_CONSTEXPR
1343 #if defined(JSON_HEDLEY_PREDICT)
1344 #undef JSON_HEDLEY_PREDICT
1346 #if defined(JSON_HEDLEY_LIKELY)
1347 #undef JSON_HEDLEY_LIKELY
1349 #if defined(JSON_HEDLEY_UNLIKELY)
1350 #undef JSON_HEDLEY_UNLIKELY
1352 #if defined(JSON_HEDLEY_UNPREDICTABLE)
1353 #undef JSON_HEDLEY_UNPREDICTABLE
1355 #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1356 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1359 JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) || \
1360 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0)
1361 # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1362 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1363 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1364 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1365 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1367 JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) || \
1368 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1369 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1370 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1371 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1372 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1373 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1374 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1375 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1376 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1377 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1378 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1379 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1380 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1381 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0)
1382 # define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1383 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1384 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1386 double hedley_probability_ = (probability); \
1387 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1389 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1391 double hedley_probability_ = (probability); \
1392 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1394 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1395 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1397 # define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1398 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1399 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1400 # define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1401 # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1403 #if !defined(JSON_HEDLEY_UNPREDICTABLE)
1404 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1407 #if defined(JSON_HEDLEY_MALLOC)
1408 #undef JSON_HEDLEY_MALLOC
1411 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1412 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1413 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1414 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1415 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1416 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1417 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1418 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1419 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1420 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1421 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1422 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1423 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1424 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1425 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1426 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1427 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1428 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1429 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1430 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1431 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0)
1432 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1434 #define JSON_HEDLEY_MALLOC
1437 #if defined(JSON_HEDLEY_PURE)
1438 #undef JSON_HEDLEY_PURE
1441 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1442 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1443 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1444 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1445 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1446 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1447 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1448 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1449 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1450 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1451 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1452 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1453 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1454 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1455 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1456 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1457 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1458 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1459 # define JSON_HEDLEY_PURE __attribute__((__pure__))
1460 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1461 # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1462 #elif defined(__cplusplus) && \
1464 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1465 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1466 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1468 # define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1470 # define JSON_HEDLEY_PURE
1473 #if defined(JSON_HEDLEY_CONST)
1474 #undef JSON_HEDLEY_CONST
1477 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1478 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1479 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1480 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1481 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1482 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1483 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1484 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1485 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1486 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1487 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1488 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1489 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1490 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1491 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1492 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1493 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1494 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1495 #define JSON_HEDLEY_CONST __attribute__((__const__))
1497 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1498 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1500 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1503 #if defined(JSON_HEDLEY_RESTRICT)
1504 #undef JSON_HEDLEY_RESTRICT
1506 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1507 #define JSON_HEDLEY_RESTRICT restrict
1509 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1510 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1511 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1512 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1513 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1514 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1515 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1516 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1517 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1518 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1519 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1520 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1522 #define JSON_HEDLEY_RESTRICT __restrict
1523 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1524 #define JSON_HEDLEY_RESTRICT _Restrict
1526 #define JSON_HEDLEY_RESTRICT
1529 #if defined(JSON_HEDLEY_INLINE)
1530 #undef JSON_HEDLEY_INLINE
1533 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1534 (defined(__cplusplus) && (__cplusplus >= 199711L))
1535 #define JSON_HEDLEY_INLINE inline
1537 defined(JSON_HEDLEY_GCC_VERSION) || \
1538 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1539 #define JSON_HEDLEY_INLINE __inline__
1541 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1542 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1543 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1544 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1545 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1546 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1547 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1548 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1549 #define JSON_HEDLEY_INLINE __inline
1551 #define JSON_HEDLEY_INLINE
1554 #if defined(JSON_HEDLEY_ALWAYS_INLINE)
1555 #undef JSON_HEDLEY_ALWAYS_INLINE
1558 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1559 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1560 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1561 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1562 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1563 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1564 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1565 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1566 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1567 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1568 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1569 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1570 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1571 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1572 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1573 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1574 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1575 # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1576 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0)
1577 # define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1578 #elif defined(__cplusplus) && \
1580 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1581 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1582 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1583 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1584 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1585 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1587 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1588 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1589 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1591 # define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1594 #if defined(JSON_HEDLEY_NEVER_INLINE)
1595 #undef JSON_HEDLEY_NEVER_INLINE
1598 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1599 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1600 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1601 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1602 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1603 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1604 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1605 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1606 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1607 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1608 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1609 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1610 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1611 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1612 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1613 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1614 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1615 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1616 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
1617 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1618 #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1619 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1620 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1621 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1622 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1623 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1624 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1625 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1626 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1627 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1629 #define JSON_HEDLEY_NEVER_INLINE
1632 #if defined(JSON_HEDLEY_PRIVATE)
1633 #undef JSON_HEDLEY_PRIVATE
1635 #if defined(JSON_HEDLEY_PUBLIC)
1636 #undef JSON_HEDLEY_PUBLIC
1638 #if defined(JSON_HEDLEY_IMPORT)
1639 #undef JSON_HEDLEY_IMPORT
1641 #if defined(_WIN32) || defined(__CYGWIN__)
1642 # define JSON_HEDLEY_PRIVATE
1643 # define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1644 # define JSON_HEDLEY_IMPORT __declspec(dllimport)
1647 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1648 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1649 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1650 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1651 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1652 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1654 defined(__TI_EABI__) && \
1656 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1657 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1660 # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1661 # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1663 # define JSON_HEDLEY_PRIVATE
1664 # define JSON_HEDLEY_PUBLIC
1666 # define JSON_HEDLEY_IMPORT extern
1669 #if defined(JSON_HEDLEY_NO_THROW)
1670 #undef JSON_HEDLEY_NO_THROW
1673 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1674 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1675 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1676 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1678 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1679 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1680 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1682 #define JSON_HEDLEY_NO_THROW
1685 #if defined(JSON_HEDLEY_FALL_THROUGH)
1686 #undef JSON_HEDLEY_FALL_THROUGH
1689 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
1690 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0)
1691 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1692 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1693 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1694 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1695 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1696 #elif defined(__fallthrough)
1697 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1699 #define JSON_HEDLEY_FALL_THROUGH
1706 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1707 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
1708 #define __attribute__((__returns_nonnull__))
1709 #elif defined(_Ret_notnull_)
1710 #define _Ret_notnull_
1715 #if defined(JSON_HEDLEY_ARRAY_PARAM)
1716 #undef JSON_HEDLEY_ARRAY_PARAM
1719 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1720 !defined(__STDC_NO_VLA__) && \
1721 !defined(__cplusplus) && \
1722 !defined(JSON_HEDLEY_PGI_VERSION) && \
1723 !defined(JSON_HEDLEY_TINYC_VERSION)
1724 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1726 #define JSON_HEDLEY_ARRAY_PARAM(name)
1729 #if defined(JSON_HEDLEY_IS_CONSTANT)
1730 #undef JSON_HEDLEY_IS_CONSTANT
1732 #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1733 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1737 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1738 #undef JSON_HEDLEY_IS_CONSTEXPR_
1741 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1742 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1743 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1744 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1745 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1746 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1747 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1748 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1749 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0)
1750 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1752 #if !defined(__cplusplus)
1754 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1755 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1756 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1757 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1758 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1759 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1760 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1761 #if defined(__INTPTR_TYPE__)
1762 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1765 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1769 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
1770 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
1771 !defined(JSON_HEDLEY_PGI_VERSION) && \
1772 !defined(JSON_HEDLEY_IAR_VERSION)) || \
1773 JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \
1774 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1775 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1776 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1777 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1778 #if defined(__INTPTR_TYPE__)
1779 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1782 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1785 defined(JSON_HEDLEY_GCC_VERSION) || \
1786 defined(JSON_HEDLEY_INTEL_VERSION) || \
1787 defined(JSON_HEDLEY_TINYC_VERSION) || \
1788 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
1789 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
1790 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
1791 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
1792 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
1793 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
1795 # define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1799 ((void*) ((expr) * 0L) ) : \
1800 ((struct { char v[sizeof(void) * 2]; } *) 1) \
1806 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1807 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1808 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1810 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
1812 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1813 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
1815 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
1818 #if defined(JSON_HEDLEY_BEGIN_C_DECLS)
1819 #undef JSON_HEDLEY_BEGIN_C_DECLS
1821 #if defined(JSON_HEDLEY_END_C_DECLS)
1822 #undef JSON_HEDLEY_END_C_DECLS
1824 #if defined(JSON_HEDLEY_C_DECL)
1825 #undef JSON_HEDLEY_C_DECL
1827 #if defined(__cplusplus)
1828 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
1829 #define JSON_HEDLEY_END_C_DECLS }
1830 #define JSON_HEDLEY_C_DECL extern "C"
1832 #define JSON_HEDLEY_BEGIN_C_DECLS
1833 #define JSON_HEDLEY_END_C_DECLS
1834 #define JSON_HEDLEY_C_DECL
1837 #if defined(JSON_HEDLEY_STATIC_ASSERT)
1838 #undef JSON_HEDLEY_STATIC_ASSERT
1841 !defined(__cplusplus) && ( \
1842 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
1843 JSON_HEDLEY_HAS_FEATURE(c_static_assert) || \
1844 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
1845 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1846 defined(_Static_assert) \
1848 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
1850 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
1851 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0)
1852 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
1854 # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
1857 #if defined(JSON_HEDLEY_NULL)
1858 #undef JSON_HEDLEY_NULL
1860 #if defined(__cplusplus)
1861 #if __cplusplus >= 201103L
1862 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
1864 #define JSON_HEDLEY_NULL NULL
1866 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
1869 #define JSON_HEDLEY_NULL NULL
1871 #define JSON_HEDLEY_NULL ((void*) 0)
1874 #if defined(JSON_HEDLEY_MESSAGE)
1875 #undef JSON_HEDLEY_MESSAGE
1877 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1878 # define JSON_HEDLEY_MESSAGE(msg) \
1879 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1880 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
1881 JSON_HEDLEY_PRAGMA(message msg) \
1882 JSON_HEDLEY_DIAGNOSTIC_POP
1884 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
1885 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1886 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
1887 #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
1888 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
1889 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1890 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
1891 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
1892 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
1894 # define JSON_HEDLEY_MESSAGE(msg)
1897 #if defined(JSON_HEDLEY_WARNING)
1898 #undef JSON_HEDLEY_WARNING
1900 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1901 # define JSON_HEDLEY_WARNING(msg) \
1902 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1903 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
1904 JSON_HEDLEY_PRAGMA(clang warning msg) \
1905 JSON_HEDLEY_DIAGNOSTIC_POP
1907 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
1908 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
1909 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1910 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
1911 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1912 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
1914 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
1917 #if defined(JSON_HEDLEY_REQUIRE)
1918 #undef JSON_HEDLEY_REQUIRE
1920 #if defined(JSON_HEDLEY_REQUIRE_MSG)
1921 #undef JSON_HEDLEY_REQUIRE_MSG
1923 #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
1924 # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
1925 # define JSON_HEDLEY_REQUIRE(expr) \
1926 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1927 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
1928 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
1929 JSON_HEDLEY_DIAGNOSTIC_POP
1930 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
1931 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1932 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
1933 __attribute__((diagnose_if(!(expr), msg, "error"))) \
1934 JSON_HEDLEY_DIAGNOSTIC_POP
1936 # define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
1937 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
1940 # define JSON_HEDLEY_REQUIRE(expr)
1941 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
1944 #if defined(JSON_HEDLEY_FLAGS)
1945 #undef JSON_HEDLEY_FLAGS
1947 #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum)
1948 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
1951 #if defined(JSON_HEDLEY_FLAGS_CAST)
1952 #undef JSON_HEDLEY_FLAGS_CAST
1954 #if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
1955 # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
1956 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1957 _Pragma("warning(disable:188)") \
1959 JSON_HEDLEY_DIAGNOSTIC_POP \
1962 # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
1965 #if defined(JSON_HEDLEY_EMPTY_BASES)
1966 #undef JSON_HEDLEY_EMPTY_BASES
1968 #if JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)
1969 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
1971 #define JSON_HEDLEY_EMPTY_BASES
1976 #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
1977 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
1979 #if defined(__clang__)
1980 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
1982 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1985 #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
1986 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
1988 #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
1990 #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
1991 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
1993 #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
1995 #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
1996 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
1998 #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2000 #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2001 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2003 #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2005 #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2006 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2008 #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2010 #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2011 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2013 #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2015 #if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2016 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2018 #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2027 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2028 #if defined(__clang__)
2029 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2030 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2032 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2033 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2034 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2040 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2041 #define JSON_HAS_CPP_20
2042 #define JSON_HAS_CPP_17
2043 #define JSON_HAS_CPP_14
2044 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
2045 #define JSON_HAS_CPP_17
2046 #define JSON_HAS_CPP_14
2047 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2048 #define JSON_HAS_CPP_14
2052 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
2053 #pragma GCC diagnostic push
2054 #pragma GCC diagnostic ignored "-Wfloat-equal"
2058 #if defined(__clang__)
2059 #pragma GCC diagnostic push
2060 #pragma GCC diagnostic ignored "-Wdocumentation"
2064 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2065 #define JSON_THROW(exception) throw exception
2066 #define JSON_TRY try
2067 #define JSON_CATCH(exception) catch(exception)
2068 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2071 #define JSON_THROW(exception) std::abort()
2072 #define JSON_TRY if(true)
2073 #define JSON_CATCH(exception) if(false)
2074 #define JSON_INTERNAL_CATCH(exception) if(false)
2078 #if defined(JSON_THROW_USER)
2080 #define JSON_THROW JSON_THROW_USER
2082 #if defined(JSON_TRY_USER)
2084 #define JSON_TRY JSON_TRY_USER
2086 #if defined(JSON_CATCH_USER)
2088 #define JSON_CATCH JSON_CATCH_USER
2089 #undef JSON_INTERNAL_CATCH
2090 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2092 #if defined(JSON_INTERNAL_CATCH_USER)
2093 #undef JSON_INTERNAL_CATCH
2094 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2098 #if !defined(JSON_ASSERT)
2100 #define JSON_ASSERT(x) assert(x)
2104 #if defined(JSON_TESTS_PRIVATE)
2105 #define JSON_PRIVATE_UNLESS_TESTED public
2107 #define JSON_PRIVATE_UNLESS_TESTED private
2115 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2116 template<typename BasicJsonType> \
2117 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2119 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2120 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2121 auto it = std::find_if(std::begin(m), std::end(m), \
2122 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2124 return ej_pair.first == e; \
2126 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2128 template<typename BasicJsonType> \
2129 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2131 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2132 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2133 auto it = std::find_if(std::begin(m), std::end(m), \
2134 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2136 return ej_pair.second == j; \
2138 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2144 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2145 template<template<typename, typename, typename...> class ObjectType, \
2146 template<typename, typename...> class ArrayType, \
2147 class StringType, class BooleanType, class NumberIntegerType, \
2148 class NumberUnsignedType, class NumberFloatType, \
2149 template<typename> class AllocatorType, \
2150 template<typename, typename = void> class JSONSerializer, \
2153 #define NLOHMANN_BASIC_JSON_TPL \
2154 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2155 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2156 AllocatorType, JSONSerializer, BinaryType>
2160 #define NLOHMANN_JSON_EXPAND( x ) x
2161 #define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME
2162 #define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2163 NLOHMANN_JSON_PASTE64, \
2164 NLOHMANN_JSON_PASTE63, \
2165 NLOHMANN_JSON_PASTE62, \
2166 NLOHMANN_JSON_PASTE61, \
2167 NLOHMANN_JSON_PASTE60, \
2168 NLOHMANN_JSON_PASTE59, \
2169 NLOHMANN_JSON_PASTE58, \
2170 NLOHMANN_JSON_PASTE57, \
2171 NLOHMANN_JSON_PASTE56, \
2172 NLOHMANN_JSON_PASTE55, \
2173 NLOHMANN_JSON_PASTE54, \
2174 NLOHMANN_JSON_PASTE53, \
2175 NLOHMANN_JSON_PASTE52, \
2176 NLOHMANN_JSON_PASTE51, \
2177 NLOHMANN_JSON_PASTE50, \
2178 NLOHMANN_JSON_PASTE49, \
2179 NLOHMANN_JSON_PASTE48, \
2180 NLOHMANN_JSON_PASTE47, \
2181 NLOHMANN_JSON_PASTE46, \
2182 NLOHMANN_JSON_PASTE45, \
2183 NLOHMANN_JSON_PASTE44, \
2184 NLOHMANN_JSON_PASTE43, \
2185 NLOHMANN_JSON_PASTE42, \
2186 NLOHMANN_JSON_PASTE41, \
2187 NLOHMANN_JSON_PASTE40, \
2188 NLOHMANN_JSON_PASTE39, \
2189 NLOHMANN_JSON_PASTE38, \
2190 NLOHMANN_JSON_PASTE37, \
2191 NLOHMANN_JSON_PASTE36, \
2192 NLOHMANN_JSON_PASTE35, \
2193 NLOHMANN_JSON_PASTE34, \
2194 NLOHMANN_JSON_PASTE33, \
2195 NLOHMANN_JSON_PASTE32, \
2196 NLOHMANN_JSON_PASTE31, \
2197 NLOHMANN_JSON_PASTE30, \
2198 NLOHMANN_JSON_PASTE29, \
2199 NLOHMANN_JSON_PASTE28, \
2200 NLOHMANN_JSON_PASTE27, \
2201 NLOHMANN_JSON_PASTE26, \
2202 NLOHMANN_JSON_PASTE25, \
2203 NLOHMANN_JSON_PASTE24, \
2204 NLOHMANN_JSON_PASTE23, \
2205 NLOHMANN_JSON_PASTE22, \
2206 NLOHMANN_JSON_PASTE21, \
2207 NLOHMANN_JSON_PASTE20, \
2208 NLOHMANN_JSON_PASTE19, \
2209 NLOHMANN_JSON_PASTE18, \
2210 NLOHMANN_JSON_PASTE17, \
2211 NLOHMANN_JSON_PASTE16, \
2212 NLOHMANN_JSON_PASTE15, \
2213 NLOHMANN_JSON_PASTE14, \
2214 NLOHMANN_JSON_PASTE13, \
2215 NLOHMANN_JSON_PASTE12, \
2216 NLOHMANN_JSON_PASTE11, \
2217 NLOHMANN_JSON_PASTE10, \
2218 NLOHMANN_JSON_PASTE9, \
2219 NLOHMANN_JSON_PASTE8, \
2220 NLOHMANN_JSON_PASTE7, \
2221 NLOHMANN_JSON_PASTE6, \
2222 NLOHMANN_JSON_PASTE5, \
2223 NLOHMANN_JSON_PASTE4, \
2224 NLOHMANN_JSON_PASTE3, \
2225 NLOHMANN_JSON_PASTE2, \
2226 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2227 #define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2228 #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2229 #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2230 #define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2231 #define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2232 #define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6)
2233 #define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
2234 #define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8)
2235 #define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9)
2236 #define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)
2237 #define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)
2238 #define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
2239 #define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
2240 #define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
2241 #define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)
2242 #define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)
2243 #define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
2244 #define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
2245 #define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
2246 #define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)
2247 #define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)
2248 #define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)
2249 #define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23)
2250 #define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24)
2251 #define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25)
2252 #define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26)
2253 #define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27)
2254 #define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28)
2255 #define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29)
2256 #define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30)
2257 #define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31)
2258 #define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32)
2259 #define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33)
2260 #define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34)
2261 #define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35)
2262 #define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36)
2263 #define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37)
2264 #define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38)
2265 #define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39)
2266 #define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40)
2267 #define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)
2268 #define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42)
2269 #define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43)
2270 #define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44)
2271 #define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45)
2272 #define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46)
2273 #define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47)
2274 #define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48)
2275 #define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49)
2276 #define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50)
2277 #define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51)
2278 #define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52)
2279 #define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53)
2280 #define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54)
2281 #define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55)
2282 #define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56)
2283 #define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57)
2284 #define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58)
2285 #define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59)
2286 #define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60)
2287 #define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61)
2288 #define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62)
2289 #define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)
2291 #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2292 #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2299 #define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2300 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2301 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2308 #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2309 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2310 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2312 #ifndef JSON_USE_IMPLICIT_CONVERSIONS
2313 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2316 #if JSON_USE_IMPLICIT_CONVERSIONS
2317 #define JSON_EXPLICIT
2319 #define JSON_EXPLICIT explicit
2359 class exception :
public std::exception
2364 const char* what() const noexcept
override
2373 JSON_HEDLEY_NON_NULL(3)
2374 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
2376 static std::string name(
const std::string& ename,
int id_)
2378 return "[json.exception." + ename +
"." + std::to_string(id_) +
"] ";
2383 std::runtime_error m;
2431 class parse_error :
public exception
2443 static parse_error create(
int id_,
const position_t& pos,
const std::string& what_arg)
2445 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2446 position_string(pos) +
": " + what_arg;
2447 return parse_error(id_, pos.chars_read_total, w.c_str());
2450 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg)
2452 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2453 (byte_ != 0 ? (
" at byte " + std::to_string(byte_)) :
"") +
2455 return parse_error(id_, byte_, w.c_str());
2467 const std::size_t byte;
2470 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
2471 : exception(id_, what_arg), byte(byte_) {}
2473 static std::string position_string(
const position_t& pos)
2475 return " at line " + std::to_string(pos.lines_read + 1) +
2476 ", column " + std::to_string(pos.chars_read_current_line);
2517 class invalid_iterator :
public exception
2520 static invalid_iterator create(
int id_,
const std::string& what_arg)
2522 std::string w = exception::name(
"invalid_iterator", id_) + what_arg;
2523 return invalid_iterator(id_, w.c_str());
2527 JSON_HEDLEY_NON_NULL(3)
2528 invalid_iterator(
int id_, const
char* what_arg)
2529 : exception(id_, what_arg) {}
2571 class type_error :
public exception
2574 static type_error create(
int id_,
const std::string& what_arg)
2576 std::string w = exception::name(
"type_error", id_) + what_arg;
2577 return type_error(id_, w.c_str());
2581 JSON_HEDLEY_NON_NULL(3)
2582 type_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
2618 class out_of_range :
public exception
2621 static out_of_range create(
int id_,
const std::string& what_arg)
2623 std::string w = exception::name(
"out_of_range", id_) + what_arg;
2624 return out_of_range(id_, w.c_str());
2628 JSON_HEDLEY_NON_NULL(3)
2629 out_of_range(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
2656 class other_error :
public exception
2659 static other_error create(
int id_,
const std::string& what_arg)
2661 std::string w = exception::name(
"other_error", id_) + what_arg;
2662 return other_error(id_, w.c_str());
2666 JSON_HEDLEY_NON_NULL(3)
2667 other_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
2678 #include <type_traits>
2685 template<
bool B,
typename T =
void>
2686 using enable_if_t =
typename std::enable_if<B, T>::type;
2688 template<
typename T>
2689 using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
2693 template<std::size_t... Ints>
2694 struct index_sequence
2696 using type = index_sequence;
2697 using value_type = std::size_t;
2698 static constexpr std::size_t size() noexcept
2700 return sizeof...(Ints);
2704 template<
class Sequence1,
class Sequence2>
2705 struct merge_and_renumber;
2707 template<std::size_t... I1, std::size_t... I2>
2708 struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>>
2709 : index_sequence < I1..., (sizeof...(I1) + I2)... > {};
2711 template<std::
size_t N>
2712 struct make_index_sequence
2713 : merge_and_renumber < typename make_index_sequence < N / 2 >::type,
2714 typename make_index_sequence < N - N / 2 >::type > {};
2716 template<>
struct make_index_sequence<0> : index_sequence<> {};
2717 template<>
struct make_index_sequence<1> : index_sequence<0> {};
2719 template<
typename... Ts>
2720 using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
2723 template<
unsigned N>
struct priority_tag : priority_tag < N - 1 > {};
2724 template<>
struct priority_tag<0> {};
2727 template<
typename T>
2730 static constexpr T value{};
2733 template<
typename T>
2734 constexpr T static_const<T>::value;
2742 #include <type_traits>
2757 template<
typename ...Ts>
struct make_void
2761 template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
2772 template<
typename It,
typename =
void>
2773 struct iterator_types {};
2775 template<
typename It>
2776 struct iterator_types <
2778 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
2779 typename It::reference, typename It::iterator_category >>
2781 using difference_type =
typename It::difference_type;
2782 using value_type =
typename It::value_type;
2783 using pointer =
typename It::pointer;
2784 using reference =
typename It::reference;
2785 using iterator_category =
typename It::iterator_category;
2790 template<
typename T,
typename =
void>
2791 struct iterator_traits
2795 template<
typename T>
2796 struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
2801 template<
typename T>
2802 struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
2804 using iterator_category = std::random_access_iterator_tag;
2805 using value_type = T;
2806 using difference_type = ptrdiff_t;
2808 using reference = T&;
2820 #include <type_traits>
2832 nonesuch() =
delete;
2833 ~nonesuch() =
delete;
2834 nonesuch(nonesuch
const&) =
delete;
2835 nonesuch(nonesuch
const&&) =
delete;
2836 void operator=(nonesuch
const&) =
delete;
2837 void operator=(nonesuch&&) =
delete;
2840 template<
class Default,
2842 template<
class...>
class Op,
2846 using value_t = std::false_type;
2847 using type = Default;
2850 template<
class Default,
template<
class...>
class Op,
class... Args>
2851 struct detector<Default, void_t<Op<Args...>>, Op, Args...>
2853 using value_t = std::true_type;
2854 using type = Op<Args...>;
2857 template<
template<
class...>
class Op,
class... Args>
2858 using is_detected =
typename detector<nonesuch, void, Op, Args...>::value_t;
2860 template<
template<
class...>
class Op,
class... Args>
2861 using detected_t =
typename detector<nonesuch, void, Op, Args...>::type;
2863 template<
class Default,
template<
class...>
class Op,
class... Args>
2864 using detected_or = detector<Default, void, Op, Args...>;
2866 template<
class Default,
template<
class...>
class Op,
class... Args>
2867 using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
2869 template<
class Expected,
template<
class...>
class Op,
class... Args>
2870 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
2872 template<
class To,
template<
class...>
class Op,
class... Args>
2873 using is_detected_convertible =
2874 std::is_convertible<detected_t<Op, Args...>, To>;
2879 #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
2880 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
2902 template<
typename T =
void,
typename SFINAE =
void>
2903 struct adl_serializer;
2905 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
2907 template<
typename U,
typename... Args>
class ArrayType = std::vector,
2908 class StringType = std::string,
class BooleanType = bool,
2909 class NumberIntegerType = std::int64_t,
2910 class NumberUnsignedType = std::uint64_t,
2911 class NumberFloatType = double,
2912 template<
typename U>
class AllocatorType = std::allocator,
2913 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
2915 class BinaryType = std::vector<std::uint8_t>>
2929 template<
typename BasicJsonType>
2942 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
2956 #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
2984 template<
typename>
struct is_basic_json : std::false_type {};
2986 NLOHMANN_BASIC_JSON_TPL_DECLARATION
2987 struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
2997 struct is_json_ref : std::false_type {};
2999 template<
typename T>
3000 struct is_json_ref<json_ref<T>> : std::true_type {};
3006 template<
typename T>
3007 using mapped_type_t =
typename T::mapped_type;
3009 template<
typename T>
3010 using key_type_t =
typename T::key_type;
3012 template<
typename T>
3013 using value_type_t =
typename T::value_type;
3015 template<
typename T>
3016 using difference_type_t =
typename T::difference_type;
3018 template<
typename T>
3019 using pointer_t =
typename T::pointer;
3021 template<
typename T>
3022 using reference_t =
typename T::reference;
3024 template<
typename T>
3025 using iterator_category_t =
typename T::iterator_category;
3027 template<
typename T>
3028 using iterator_t =
typename T::iterator;
3030 template<
typename T,
typename... Args>
3031 using to_json_function = decltype(T::to_json(std::declval<Args>()...));
3033 template<
typename T,
typename... Args>
3034 using from_json_function = decltype(T::from_json(std::declval<Args>()...));
3036 template<
typename T,
typename U>
3037 using get_template_function = decltype(std::declval<T>().
template get<U>());
3040 template<
typename BasicJsonType,
typename T,
typename =
void>
3041 struct has_from_json : std::false_type {};
3047 template <
typename BasicJsonType,
typename T>
3050 static constexpr
bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3053 template<
typename BasicJsonType,
typename T>
3054 struct has_from_json < BasicJsonType, T,
3055 enable_if_t < !is_basic_json<T>::value >>
3057 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3059 static constexpr
bool value =
3060 is_detected_exact<void, from_json_function, serializer,
3061 const BasicJsonType&, T&>::value;
3066 template<
typename BasicJsonType,
typename T,
typename =
void>
3067 struct has_non_default_from_json : std::false_type {};
3069 template<
typename BasicJsonType,
typename T>
3070 struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3072 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3074 static constexpr
bool value =
3075 is_detected_exact<T, from_json_function, serializer,
3076 const BasicJsonType&>::value;
3081 template<
typename BasicJsonType,
typename T,
typename =
void>
3082 struct has_to_json : std::false_type {};
3084 template<
typename BasicJsonType,
typename T>
3085 struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3087 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3089 static constexpr
bool value =
3090 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3099 template<
typename T,
typename =
void>
3100 struct is_iterator_traits : std::false_type {};
3102 template<
typename T>
3103 struct is_iterator_traits<iterator_traits<T>>
3106 using traits = iterator_traits<T>;
3109 static constexpr
auto value =
3110 is_detected<value_type_t, traits>::value &&
3111 is_detected<difference_type_t, traits>::value &&
3112 is_detected<pointer_t, traits>::value &&
3113 is_detected<iterator_category_t, traits>::value &&
3114 is_detected<reference_t, traits>::value;
3119 template<
typename T,
typename =
void>
3120 struct is_complete_type : std::false_type {};
3122 template<
typename T>
3123 struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3125 template<
typename BasicJsonType,
typename CompatibleObjectType,
3127 struct is_compatible_object_type_impl : std::false_type {};
3129 template<
typename BasicJsonType,
typename CompatibleObjectType>
3130 struct is_compatible_object_type_impl <
3131 BasicJsonType, CompatibleObjectType,
3132 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3133 is_detected<key_type_t, CompatibleObjectType>::value >>
3136 using object_t =
typename BasicJsonType::object_t;
3139 static constexpr
bool value =
3140 std::is_constructible<
typename object_t::key_type,
3141 typename CompatibleObjectType::key_type>::value &&
3142 std::is_constructible<
typename object_t::mapped_type,
3143 typename CompatibleObjectType::mapped_type>::value;
3146 template<
typename BasicJsonType,
typename CompatibleObjectType>
3147 struct is_compatible_object_type
3148 : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
3150 template<
typename BasicJsonType,
typename ConstructibleObjectType,
3152 struct is_constructible_object_type_impl : std::false_type {};
3154 template<
typename BasicJsonType,
typename ConstructibleObjectType>
3155 struct is_constructible_object_type_impl <
3156 BasicJsonType, ConstructibleObjectType,
3157 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3158 is_detected<key_type_t, ConstructibleObjectType>::value >>
3160 using object_t =
typename BasicJsonType::object_t;
3162 static constexpr
bool value =
3163 (std::is_default_constructible<ConstructibleObjectType>::value &&
3164 (std::is_move_assignable<ConstructibleObjectType>::value ||
3165 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3166 (std::is_constructible<
typename ConstructibleObjectType::key_type,
3167 typename object_t::key_type>::value &&
3169 typename object_t::mapped_type,
3170 typename ConstructibleObjectType::mapped_type >::value)) ||
3171 (has_from_json<BasicJsonType,
3172 typename ConstructibleObjectType::mapped_type>::value ||
3173 has_non_default_from_json <
3175 typename ConstructibleObjectType::mapped_type >::value);
3178 template<
typename BasicJsonType,
typename ConstructibleObjectType>
3179 struct is_constructible_object_type
3180 : is_constructible_object_type_impl<BasicJsonType,
3181 ConstructibleObjectType> {};
3183 template<
typename BasicJsonType,
typename CompatibleStringType,
3185 struct is_compatible_string_type_impl : std::false_type {};
3187 template<
typename BasicJsonType,
typename CompatibleStringType>
3188 struct is_compatible_string_type_impl <
3189 BasicJsonType, CompatibleStringType,
3190 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3191 value_type_t, CompatibleStringType>::value >>
3193 static constexpr
auto value =
3194 std::is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
3197 template<
typename BasicJsonType,
typename ConstructibleStringType>
3198 struct is_compatible_string_type
3199 : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3201 template<
typename BasicJsonType,
typename ConstructibleStringType,
3203 struct is_constructible_string_type_impl : std::false_type {};
3205 template<
typename BasicJsonType,
typename ConstructibleStringType>
3206 struct is_constructible_string_type_impl <
3207 BasicJsonType, ConstructibleStringType,
3208 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3209 value_type_t, ConstructibleStringType>::value >>
3211 static constexpr
auto value =
3212 std::is_constructible<ConstructibleStringType,
3213 typename BasicJsonType::string_t>::value;
3216 template<
typename BasicJsonType,
typename ConstructibleStringType>
3217 struct is_constructible_string_type
3218 : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3220 template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3221 struct is_compatible_array_type_impl : std::false_type {};
3223 template<
typename BasicJsonType,
typename CompatibleArrayType>
3224 struct is_compatible_array_type_impl <
3225 BasicJsonType, CompatibleArrayType,
3226 enable_if_t < is_detected<value_type_t, CompatibleArrayType>::value&&
3227 is_detected<iterator_t, CompatibleArrayType>::value&&
3231 !is_iterator_traits <
3232 iterator_traits<CompatibleArrayType >>::value >>
3234 static constexpr
bool value =
3235 std::is_constructible<BasicJsonType,
3236 typename CompatibleArrayType::value_type>::value;
3239 template<
typename BasicJsonType,
typename CompatibleArrayType>
3240 struct is_compatible_array_type
3241 : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
3243 template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3244 struct is_constructible_array_type_impl : std::false_type {};
3246 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3247 struct is_constructible_array_type_impl <
3248 BasicJsonType, ConstructibleArrayType,
3249 enable_if_t<std::is_same<ConstructibleArrayType,
3250 typename BasicJsonType::value_type>::value >>
3251 : std::true_type {};
3253 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3254 struct is_constructible_array_type_impl <
3255 BasicJsonType, ConstructibleArrayType,
3256 enable_if_t < !std::is_same<ConstructibleArrayType,
3257 typename BasicJsonType::value_type>::value&&
3258 std::is_default_constructible<ConstructibleArrayType>::value&&
3259 (std::is_move_assignable<ConstructibleArrayType>::value ||
3260 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3261 is_detected<value_type_t, ConstructibleArrayType>::value&&
3262 is_detected<iterator_t, ConstructibleArrayType>::value&&
3264 detected_t<value_type_t, ConstructibleArrayType >>::value >>
3266 static constexpr
bool value =
3272 !is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value &&
3274 (std::is_same<
typename ConstructibleArrayType::value_type,
3275 typename BasicJsonType::array_t::value_type>::value ||
3276 has_from_json<BasicJsonType,
3277 typename ConstructibleArrayType::value_type>::value ||
3278 has_non_default_from_json <
3279 BasicJsonType,
typename ConstructibleArrayType::value_type >::value);
3282 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3283 struct is_constructible_array_type
3284 : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
3286 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3288 struct is_compatible_integer_type_impl : std::false_type {};
3290 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3291 struct is_compatible_integer_type_impl <
3292 RealIntegerType, CompatibleNumberIntegerType,
3293 enable_if_t < std::is_integral<RealIntegerType>::value&&
3294 std::is_integral<CompatibleNumberIntegerType>::value&&
3295 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3298 using RealLimits = std::numeric_limits<RealIntegerType>;
3299 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3301 static constexpr
auto value =
3302 std::is_constructible<RealIntegerType,
3303 CompatibleNumberIntegerType>::value &&
3304 CompatibleLimits::is_integer &&
3305 RealLimits::is_signed == CompatibleLimits::is_signed;
3308 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3309 struct is_compatible_integer_type
3310 : is_compatible_integer_type_impl<RealIntegerType,
3311 CompatibleNumberIntegerType> {};
3313 template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3314 struct is_compatible_type_impl: std::false_type {};
3316 template<
typename BasicJsonType,
typename CompatibleType>
3317 struct is_compatible_type_impl <
3318 BasicJsonType, CompatibleType,
3319 enable_if_t<is_complete_type<CompatibleType>::value >>
3321 static constexpr
bool value =
3322 has_to_json<BasicJsonType, CompatibleType>::value;
3325 template<
typename BasicJsonType,
typename CompatibleType>
3326 struct is_compatible_type
3327 : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
3330 template<
class...>
struct conjunction : std::true_type { };
3331 template<
class B1>
struct conjunction<B1> : B1 { };
3332 template<
class B1,
class... Bn>
3333 struct conjunction<B1, Bn...>
3334 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3336 template<
typename T1,
typename T2>
3337 struct is_constructible_tuple : std::false_type {};
3339 template<
typename T1,
typename... Args>
3340 struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<std::is_constructible<T1, Args>...> {};
3384 enum class value_t : std::uint8_t
3411 inline bool operator<(
const value_t lhs,
const value_t rhs) noexcept
3413 static constexpr std::array<std::uint8_t, 9> order = {{
3420 const auto l_index =
static_cast<std::size_t
>(lhs);
3421 const auto r_index =
static_cast<std::size_t
>(rhs);
3422 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
3432 template<
typename BasicJsonType>
3433 void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
3435 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3437 JSON_THROW(type_error::create(302,
"type must be null, but is " + std::string(j.type_name())));
3443 template <
typename BasicJsonType,
typename ArithmeticType,
3444 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
3445 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3447 void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
3449 switch (
static_cast<value_t
>(j))
3451 case value_t::number_unsigned:
3453 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3456 case value_t::number_integer:
3458 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3461 case value_t::number_float:
3463 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3468 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name())));
3472 template<
typename BasicJsonType>
3473 void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
3475 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
3477 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(j.type_name())));
3479 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
3482 template<
typename BasicJsonType>
3483 void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
3485 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3487 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name())));
3489 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3493 typename BasicJsonType,
typename ConstructibleStringType,
3495 is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&&
3496 !std::is_same<
typename BasicJsonType::string_t,
3497 ConstructibleStringType>::value,
3499 void from_json(
const BasicJsonType& j, ConstructibleStringType& s)
3501 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3503 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name())));
3506 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3509 template<
typename BasicJsonType>
3510 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
3512 get_arithmetic_value(j, val);
3515 template<
typename BasicJsonType>
3516 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
3518 get_arithmetic_value(j, val);
3521 template<
typename BasicJsonType>
3522 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
3524 get_arithmetic_value(j, val);
3527 template<
typename BasicJsonType,
typename EnumType,
3528 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
3529 void from_json(
const BasicJsonType& j, EnumType& e)
3531 typename std::underlying_type<EnumType>::type val;
3532 get_arithmetic_value(j, val);
3533 e =
static_cast<EnumType
>(val);
3537 template<
typename BasicJsonType,
typename T,
typename Allocator,
3538 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
3539 void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
3541 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3543 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name())));
3546 std::transform(j.rbegin(), j.rend(),
3547 std::front_inserter(l), [](
const BasicJsonType & i)
3549 return i.template get<T>();
3554 template<
typename BasicJsonType,
typename T,
3555 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
3556 void from_json(
const BasicJsonType& j, std::valarray<T>& l)
3558 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3560 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name())));
3563 std::transform(j.begin(), j.end(), std::begin(l),
3564 [](
const BasicJsonType & elem)
3566 return elem.template get<T>();
3570 template<
typename BasicJsonType,
typename T, std::
size_t N>
3571 auto from_json(
const BasicJsonType& j, T (&arr)[N])
3572 -> decltype(j.template get<T>(),
void())
3574 for (std::size_t i = 0; i < N; ++i)
3576 arr[i] = j.at(i).template get<T>();
3580 template<
typename BasicJsonType>
3581 void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
3583 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
3586 template<
typename BasicJsonType,
typename T, std::
size_t N>
3587 auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
3589 -> decltype(j.template get<T>(),
void())
3591 for (std::size_t i = 0; i < N; ++i)
3593 arr[i] = j.at(i).template get<T>();
3597 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3598 auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
3600 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
3601 j.template get<typename ConstructibleArrayType::value_type>(),
3606 ConstructibleArrayType ret;
3607 ret.reserve(j.size());
3608 std::transform(j.begin(), j.end(),
3609 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
3613 return i.template get<typename ConstructibleArrayType::value_type>();
3615 arr = std::move(ret);
3618 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3619 void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
3624 ConstructibleArrayType ret;
3626 j.begin(), j.end(), std::inserter(ret, end(ret)),
3627 [](
const BasicJsonType & i)
3631 return i.template get<typename ConstructibleArrayType::value_type>();
3633 arr = std::move(ret);
3636 template <
typename BasicJsonType,
typename ConstructibleArrayType,
3638 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
3639 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
3640 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
3641 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
3642 !is_basic_json<ConstructibleArrayType>::value,
3644 auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
3645 -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
3646 j.template get<typename ConstructibleArrayType::value_type>(),
3649 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3651 JSON_THROW(type_error::create(302,
"type must be array, but is " +
3652 std::string(j.type_name())));
3655 from_json_array_impl(j, arr, priority_tag<3> {});
3658 template<
typename BasicJsonType>
3659 void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
3661 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
3663 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(j.type_name())));
3666 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
3669 template<
typename BasicJsonType,
typename ConstructibleObjectType,
3670 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
3671 void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
3673 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
3675 JSON_THROW(type_error::create(302,
"type must be object, but is " + std::string(j.type_name())));
3678 ConstructibleObjectType ret;
3679 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
3680 using value_type =
typename ConstructibleObjectType::value_type;
3682 inner_object->begin(), inner_object->end(),
3683 std::inserter(ret, ret.begin()),
3684 [](
typename BasicJsonType::object_t::value_type
const & p)
3686 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
3688 obj = std::move(ret);
3695 template <
typename BasicJsonType,
typename ArithmeticType,
3697 std::is_arithmetic<ArithmeticType>::value&&
3698 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
3699 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
3700 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
3701 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3703 void from_json(
const BasicJsonType& j, ArithmeticType& val)
3705 switch (
static_cast<value_t
>(j))
3707 case value_t::number_unsigned:
3709 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3712 case value_t::number_integer:
3714 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3717 case value_t::number_float:
3719 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3722 case value_t::boolean:
3724 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
3729 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name())));
3733 template<
typename BasicJsonType,
typename A1,
typename A2>
3734 void from_json(
const BasicJsonType& j, std::pair<A1, A2>& p)
3736 p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
3739 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
3740 void from_json_tuple_impl(
const BasicJsonType& j, Tuple& t, index_sequence<Idx...> )
3742 t = std::make_tuple(j.at(Idx).template get<
typename std::tuple_element<Idx, Tuple>::type>()...);
3745 template<
typename BasicJsonType,
typename... Args>
3746 void from_json(
const BasicJsonType& j, std::tuple<Args...>& t)
3748 from_json_tuple_impl(j, t, index_sequence_for<Args...> {});
3751 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
3752 typename = enable_if_t < !std::is_constructible <
3753 typename BasicJsonType::string_t, Key >::value >>
3754 void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
3756 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3758 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name())));
3761 for (
const auto& p : j)
3763 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
3765 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name())));
3767 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
3771 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
3772 typename = enable_if_t < !std::is_constructible <
3773 typename BasicJsonType::string_t, Key >::value >>
3774 void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
3776 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3778 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name())));
3781 for (
const auto& p : j)
3783 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
3785 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name())));
3787 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
3793 template<
typename BasicJsonType,
typename T>
3794 auto operator()(
const BasicJsonType& j, T& val)
const
3808 constexpr
const auto&
from_json = detail::static_const<detail::from_json_fn>::value;
3815 #include <algorithm>
3819 #include <type_traits>
3841 template<
typename string_type>
3842 void int_to_string( string_type& target, std::size_t value )
3845 using std::to_string;
3848 template<
typename IteratorType>
class iteration_proxy_value
3851 using difference_type = std::ptrdiff_t;
3852 using value_type = iteration_proxy_value;
3853 using pointer = value_type * ;
3854 using reference = value_type & ;
3855 using iterator_category = std::input_iterator_tag;
3856 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
3860 IteratorType anchor;
3862 std::size_t array_index = 0;
3864 mutable std::size_t array_index_last = 0;
3866 mutable string_type array_index_str =
"0";
3868 const string_type empty_str =
"";
3871 explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {}
3874 iteration_proxy_value& operator*()
3880 iteration_proxy_value& operator++()
3889 bool operator==(
const iteration_proxy_value& o)
const
3891 return anchor == o.anchor;
3895 bool operator!=(
const iteration_proxy_value& o)
const
3897 return anchor != o.anchor;
3901 const string_type& key()
const
3903 JSON_ASSERT(anchor.m_object !=
nullptr);
3905 switch (anchor.m_object->type())
3908 case value_t::array:
3910 if (array_index != array_index_last)
3912 int_to_string( array_index_str, array_index );
3913 array_index_last = array_index;
3915 return array_index_str;
3919 case value_t::object:
3920 return anchor.key();
3929 typename IteratorType::reference value()
const
3931 return anchor.value();
3936 template<
typename IteratorType>
class iteration_proxy
3940 typename IteratorType::reference container;
3944 explicit iteration_proxy(
typename IteratorType::reference cont) noexcept
3945 : container(cont) {}
3948 iteration_proxy_value<IteratorType> begin() noexcept
3950 return iteration_proxy_value<IteratorType>(container.begin());
3954 iteration_proxy_value<IteratorType> end() noexcept
3956 return iteration_proxy_value<IteratorType>(container.end());
3962 template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
3963 auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
3970 template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
3971 auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
3984 #if defined(__clang__)
3986 #pragma clang diagnostic push
3987 #pragma clang diagnostic ignored "-Wmismatched-tags"
3989 template<
typename IteratorType>
3990 class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
3991 :
public std::integral_constant<std::size_t, 2> {};
3993 template<std::
size_t N,
typename IteratorType>
3994 class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
3997 using type = decltype(
3998 get<N>(std::declval <
3999 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
4001 #if defined(__clang__)
4002 #pragma clang diagnostic pop
4021 template<value_t>
struct external_constructor;
4024 struct external_constructor<value_t::boolean>
4026 template<
typename BasicJsonType>
4027 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b) noexcept
4029 j.m_type = value_t::boolean;
4031 j.assert_invariant();
4036 struct external_constructor<value_t::string>
4038 template<
typename BasicJsonType>
4039 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
4041 j.m_type = value_t::string;
4043 j.assert_invariant();
4046 template<
typename BasicJsonType>
4047 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4049 j.m_type = value_t::string;
4050 j.m_value = std::move(s);
4051 j.assert_invariant();
4054 template <
typename BasicJsonType,
typename CompatibleStringType,
4055 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
4057 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
4059 j.m_type = value_t::string;
4060 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
4061 j.assert_invariant();
4066 struct external_constructor<value_t::binary>
4068 template<
typename BasicJsonType>
4069 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
4071 j.m_type = value_t::binary;
4072 typename BasicJsonType::binary_t value{b};
4074 j.assert_invariant();
4077 template<
typename BasicJsonType>
4078 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
4080 j.m_type = value_t::binary;
4081 typename BasicJsonType::binary_t value{std::move(b)};
4083 j.assert_invariant();
4088 struct external_constructor<value_t::number_float>
4090 template<
typename BasicJsonType>
4091 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val) noexcept
4093 j.m_type = value_t::number_float;
4095 j.assert_invariant();
4100 struct external_constructor<value_t::number_unsigned>
4102 template<
typename BasicJsonType>
4103 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val) noexcept
4105 j.m_type = value_t::number_unsigned;
4107 j.assert_invariant();
4112 struct external_constructor<value_t::number_integer>
4114 template<
typename BasicJsonType>
4115 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val) noexcept
4117 j.m_type = value_t::number_integer;
4119 j.assert_invariant();
4124 struct external_constructor<value_t::array>
4126 template<
typename BasicJsonType>
4127 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
4129 j.m_type = value_t::array;
4131 j.assert_invariant();
4134 template<
typename BasicJsonType>
4135 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4137 j.m_type = value_t::array;
4138 j.m_value = std::move(arr);
4139 j.assert_invariant();
4142 template <
typename BasicJsonType,
typename CompatibleArrayType,
4143 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
4145 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
4149 j.m_type = value_t::array;
4150 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
4151 j.assert_invariant();
4154 template<
typename BasicJsonType>
4155 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
4157 j.m_type = value_t::array;
4158 j.m_value = value_t::array;
4159 j.m_value.array->reserve(arr.size());
4160 for (
const bool x : arr)
4162 j.m_value.array->push_back(x);
4164 j.assert_invariant();
4167 template<
typename BasicJsonType,
typename T,
4168 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4169 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
4171 j.m_type = value_t::array;
4172 j.m_value = value_t::array;
4173 j.m_value.array->resize(arr.size());
4176 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
4178 j.assert_invariant();
4183 struct external_constructor<value_t::object>
4185 template<
typename BasicJsonType>
4186 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
4188 j.m_type = value_t::object;
4190 j.assert_invariant();
4193 template<
typename BasicJsonType>
4194 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4196 j.m_type = value_t::object;
4197 j.m_value = std::move(obj);
4198 j.assert_invariant();
4201 template <
typename BasicJsonType,
typename CompatibleObjectType,
4202 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
4203 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
4208 j.m_type = value_t::object;
4209 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
4210 j.assert_invariant();
4218 template<
typename BasicJsonType,
typename T,
4219 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
4220 void to_json(BasicJsonType& j, T b) noexcept
4222 external_constructor<value_t::boolean>::construct(j, b);
4225 template<
typename BasicJsonType,
typename CompatibleString,
4226 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
4227 void to_json(BasicJsonType& j,
const CompatibleString& s)
4229 external_constructor<value_t::string>::construct(j, s);
4232 template<
typename BasicJsonType>
4233 void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4235 external_constructor<value_t::string>::construct(j, std::move(s));
4238 template<
typename BasicJsonType,
typename FloatType,
4239 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
4240 void to_json(BasicJsonType& j, FloatType val) noexcept
4242 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
4245 template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
4246 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
4247 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
4249 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
4252 template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
4253 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
4254 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
4256 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
4259 template<
typename BasicJsonType,
typename EnumType,
4260 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4261 void to_json(BasicJsonType& j, EnumType e) noexcept
4263 using underlying_type =
typename std::underlying_type<EnumType>::type;
4264 external_constructor<value_t::number_integer>::construct(j,
static_cast<underlying_type
>(e));
4267 template<
typename BasicJsonType>
4268 void to_json(BasicJsonType& j,
const std::vector<bool>& e)
4270 external_constructor<value_t::array>::construct(j, e);
4273 template <
typename BasicJsonType,
typename CompatibleArrayType,
4274 enable_if_t < is_compatible_array_type<BasicJsonType,
4275 CompatibleArrayType>::value&&
4276 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
4277 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
4278 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
4279 !is_basic_json<CompatibleArrayType>::value,
4281 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
4283 external_constructor<value_t::array>::construct(j, arr);
4286 template<
typename BasicJsonType>
4287 void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
4289 external_constructor<value_t::binary>::construct(j, bin);
4292 template<
typename BasicJsonType,
typename T,
4293 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4294 void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
4296 external_constructor<value_t::array>::construct(j, std::move(arr));
4299 template<
typename BasicJsonType>
4300 void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4302 external_constructor<value_t::array>::construct(j, std::move(arr));
4305 template <
typename BasicJsonType,
typename CompatibleObjectType,
4306 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
4307 void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
4309 external_constructor<value_t::object>::construct(j, obj);
4312 template<
typename BasicJsonType>
4313 void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4315 external_constructor<value_t::object>::construct(j, std::move(obj));
4319 typename BasicJsonType,
typename T, std::size_t N,
4320 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
4321 const T(&)[N]>::value,
4323 void to_json(BasicJsonType& j,
const T(&arr)[N])
4325 external_constructor<value_t::array>::construct(j, arr);
4328 template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
4329 void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
4331 j = { p.first, p.second };
4335 template<
typename BasicJsonType,
typename T,
4336 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
4337 void to_json(BasicJsonType& j,
const T& b)
4339 j = { {b.key(), b.value()} };
4342 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
4343 void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
4345 j = { std::get<Idx>(t)... };
4348 template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
4349 void to_json(BasicJsonType& j,
const T& t)
4351 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
4356 template<
typename BasicJsonType,
typename T>
4357 auto operator()(BasicJsonType& j, T&& val)
const noexcept(noexcept(
to_json(j, std::forward<T>(val))))
4358 -> decltype(
to_json(j, std::forward<T>(val)),
void())
4360 return to_json(j, std::forward<T>(val));
4368 constexpr
const auto&
to_json = detail::static_const<detail::to_json_fn>::value;
4376 template<
typename,
typename>
4388 template<
typename BasicJsonType,
typename ValueType>
4389 static auto from_json(BasicJsonType&& j, ValueType& val) noexcept(
4390 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
4391 -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
4393 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
4405 template<
typename BasicJsonType,
typename ValueType>
4406 static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
4407 noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
4408 -> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)),
void())
4410 ::nlohmann::to_json(j, std::forward<ValueType>(val));
4439 template<
typename BinaryType>
4461 , m_has_subtype(true)
4467 , m_has_subtype(true)
4472 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
4473 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
4478 return !(rhs == *
this);
4502 m_has_subtype =
true;
4549 return m_has_subtype;
4574 m_has_subtype =
false;
4578 std::uint8_t m_subtype = 0;
4579 bool m_has_subtype =
false;
4594 #include <functional>
4602 inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
4604 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
4619 template<
typename BasicJsonType>
4620 std::size_t hash(
const BasicJsonType& j)
4622 using string_t =
typename BasicJsonType::string_t;
4623 using number_integer_t =
typename BasicJsonType::number_integer_t;
4624 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
4625 using number_float_t =
typename BasicJsonType::number_float_t;
4627 const auto type =
static_cast<std::size_t
>(j.type());
4630 case BasicJsonType::value_t::null:
4631 case BasicJsonType::value_t::discarded:
4633 return combine(type, 0);
4636 case BasicJsonType::value_t::object:
4638 auto seed = combine(type, j.size());
4639 for (
const auto& element : j.items())
4641 const auto h = std::hash<string_t> {}(element.key());
4642 seed = combine(seed, h);
4643 seed = combine(seed, hash(element.value()));
4648 case BasicJsonType::value_t::array:
4650 auto seed = combine(type, j.size());
4651 for (
const auto& element : j)
4653 seed = combine(seed, hash(element));
4658 case BasicJsonType::value_t::string:
4660 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
4661 return combine(type, h);
4664 case BasicJsonType::value_t::boolean:
4666 const auto h = std::hash<bool> {}(j.template get<bool>());
4667 return combine(type, h);
4670 case BasicJsonType::value_t::number_integer:
4672 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
4673 return combine(type, h);
4676 case BasicJsonType::value_t::number_unsigned:
4678 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
4679 return combine(type, h);
4682 case BasicJsonType::value_t::number_float:
4684 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
4685 return combine(type, h);
4688 case BasicJsonType::value_t::binary:
4690 auto seed = combine(type, j.get_binary().size());
4691 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
4692 seed = combine(seed, h);
4693 seed = combine(seed, j.get_binary().subtype());
4694 for (
const auto byte : j.get_binary())
4696 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
4713 #include <algorithm>
4739 #include <type_traits>
4752 enum class input_format_t {
json, cbor, msgpack, ubjson, bson };
4762 class file_input_adapter
4765 using char_type = char;
4767 JSON_HEDLEY_NON_NULL(2)
4768 explicit file_input_adapter(std::FILE* f) noexcept
4773 file_input_adapter(
const file_input_adapter&) =
delete;
4774 file_input_adapter(file_input_adapter&&) =
default;
4775 file_input_adapter& operator=(
const file_input_adapter&) =
delete;
4776 file_input_adapter& operator=(file_input_adapter&&) =
delete;
4778 std::char_traits<char>::int_type get_character() noexcept
4780 return std::fgetc(m_file);
4798 class input_stream_adapter
4801 using char_type = char;
4803 ~input_stream_adapter()
4809 is->clear(is->rdstate() & std::ios::eofbit);
4813 explicit input_stream_adapter(std::istream& i)
4814 : is(&i), sb(i.rdbuf())
4818 input_stream_adapter(
const input_stream_adapter&) =
delete;
4819 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
4820 input_stream_adapter& operator=(input_stream_adapter&& rhs) =
delete;
4822 input_stream_adapter(input_stream_adapter&& rhs) noexcept : is(rhs.is), sb(rhs.sb)
4831 std::char_traits<char>::int_type get_character()
4833 auto res = sb->sbumpc();
4835 if (JSON_HEDLEY_UNLIKELY(res == EOF))
4837 is->clear(is->rdstate() | std::ios::eofbit);
4844 std::istream* is =
nullptr;
4845 std::streambuf* sb =
nullptr;
4850 template<
typename IteratorType>
4851 class iterator_input_adapter
4854 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
4856 iterator_input_adapter(IteratorType first, IteratorType last)
4857 : current(std::move(first)), end(std::move(last)) {}
4859 typename std::char_traits<char_type>::int_type get_character()
4861 if (JSON_HEDLEY_LIKELY(current != end))
4863 auto result = std::char_traits<char_type>::to_int_type(*current);
4864 std::advance(current, 1);
4869 return std::char_traits<char_type>::eof();
4874 IteratorType current;
4877 template<
typename BaseInputAdapter,
size_t T>
4878 friend struct wide_string_input_helper;
4882 return current == end;
4888 template<
typename BaseInputAdapter,
size_t T>
4889 struct wide_string_input_helper;
4891 template<
typename BaseInputAdapter>
4892 struct wide_string_input_helper<BaseInputAdapter, 4>
4895 static void fill_buffer(BaseInputAdapter& input,
4896 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
4897 size_t& utf8_bytes_index,
4898 size_t& utf8_bytes_filled)
4900 utf8_bytes_index = 0;
4902 if (JSON_HEDLEY_UNLIKELY(input.empty()))
4904 utf8_bytes[0] = std::char_traits<char>::eof();
4905 utf8_bytes_filled = 1;
4910 const auto wc = input.get_character();
4915 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4916 utf8_bytes_filled = 1;
4918 else if (wc <= 0x7FF)
4920 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
4921 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
4922 utf8_bytes_filled = 2;
4924 else if (wc <= 0xFFFF)
4926 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
4927 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
4928 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
4929 utf8_bytes_filled = 3;
4931 else if (wc <= 0x10FFFF)
4933 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
4934 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
4935 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
4936 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
4937 utf8_bytes_filled = 4;
4942 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4943 utf8_bytes_filled = 1;
4949 template<
typename BaseInputAdapter>
4950 struct wide_string_input_helper<BaseInputAdapter, 2>
4953 static void fill_buffer(BaseInputAdapter& input,
4954 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
4955 size_t& utf8_bytes_index,
4956 size_t& utf8_bytes_filled)
4958 utf8_bytes_index = 0;
4960 if (JSON_HEDLEY_UNLIKELY(input.empty()))
4962 utf8_bytes[0] = std::char_traits<char>::eof();
4963 utf8_bytes_filled = 1;
4968 const auto wc = input.get_character();
4973 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4974 utf8_bytes_filled = 1;
4976 else if (wc <= 0x7FF)
4978 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
4979 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
4980 utf8_bytes_filled = 2;
4982 else if (0xD800 > wc || wc >= 0xE000)
4984 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
4985 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
4986 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
4987 utf8_bytes_filled = 3;
4991 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
4993 const auto wc2 =
static_cast<unsigned int>(input.get_character());
4994 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
4995 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
4996 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
4997 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
4998 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
4999 utf8_bytes_filled = 4;
5003 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5004 utf8_bytes_filled = 1;
5012 template<
typename BaseInputAdapter,
typename W
ideCharType>
5013 class wide_string_input_adapter
5016 using char_type = char;
5018 wide_string_input_adapter(BaseInputAdapter base)
5019 : base_adapter(base) {}
5021 typename std::char_traits<char>::int_type get_character() noexcept
5024 if (utf8_bytes_index == utf8_bytes_filled)
5026 fill_buffer<sizeof(WideCharType)>();
5028 JSON_ASSERT(utf8_bytes_filled > 0);
5029 JSON_ASSERT(utf8_bytes_index == 0);
5033 JSON_ASSERT(utf8_bytes_filled > 0);
5034 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
5035 return utf8_bytes[utf8_bytes_index++];
5039 BaseInputAdapter base_adapter;
5044 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
5048 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
5051 std::size_t utf8_bytes_index = 0;
5053 std::size_t utf8_bytes_filled = 0;
5057 template<
typename IteratorType,
typename Enable =
void>
5058 struct iterator_input_adapter_factory
5060 using iterator_type = IteratorType;
5061 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5062 using adapter_type = iterator_input_adapter<iterator_type>;
5064 static adapter_type create(IteratorType first, IteratorType last)
5066 return adapter_type(std::move(first), std::move(last));
5070 template<
typename T>
5071 struct is_iterator_of_multibyte
5073 using value_type =
typename std::iterator_traits<T>::value_type;
5076 value =
sizeof(value_type) > 1
5080 template<
typename IteratorType>
5081 struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
5083 using iterator_type = IteratorType;
5084 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5085 using base_adapter_type = iterator_input_adapter<iterator_type>;
5086 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
5088 static adapter_type create(IteratorType first, IteratorType last)
5090 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
5095 template<
typename IteratorType>
5096 typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
5098 using factory_type = iterator_input_adapter_factory<IteratorType>;
5099 return factory_type::create(first, last);
5103 template<
typename ContainerType>
5104 auto input_adapter(
const ContainerType& container) -> decltype(input_adapter(begin(container), end(container)))
5110 return input_adapter(begin(container), end(container));
5114 inline file_input_adapter input_adapter(std::FILE* file)
5116 return file_input_adapter(file);
5119 inline input_stream_adapter input_adapter(std::istream& stream)
5121 return input_stream_adapter(stream);
5124 inline input_stream_adapter input_adapter(std::istream&& stream)
5126 return input_stream_adapter(stream);
5129 using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
5132 template <
typename CharT,
5133 typename std::enable_if <
5134 std::is_pointer<CharT>::value&&
5135 !std::is_array<CharT>::value&&
5136 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5137 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5139 contiguous_bytes_input_adapter input_adapter(CharT b)
5141 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
5142 const auto* ptr =
reinterpret_cast<const char*
>(b);
5143 return input_adapter(ptr, ptr + length);
5146 template<
typename T, std::
size_t N>
5147 auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N))
5149 return input_adapter(array, array + N);
5155 class span_input_adapter
5158 template <
typename CharT,
5159 typename std::enable_if <
5160 std::is_pointer<CharT>::value&&
5161 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5162 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5164 span_input_adapter(CharT b, std::size_t l)
5165 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
5167 template<
class IteratorType,
5168 typename std::enable_if<
5169 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
5171 span_input_adapter(IteratorType first, IteratorType last)
5172 : ia(input_adapter(first, last)) {}
5174 contiguous_bytes_input_adapter&& get()
5176 return std::move(ia);
5180 contiguous_bytes_input_adapter ia;
5209 template<
typename BasicJsonType>
5222 virtual bool null() = 0;
5313 const std::string& last_token,
5314 const detail::exception& ex) = 0;
5335 template<
typename BasicJsonType>
5336 class json_sax_dom_parser
5339 using number_integer_t =
typename BasicJsonType::number_integer_t;
5340 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5341 using number_float_t =
typename BasicJsonType::number_float_t;
5342 using string_t =
typename BasicJsonType::string_t;
5343 using binary_t =
typename BasicJsonType::binary_t;
5350 explicit json_sax_dom_parser(BasicJsonType& r,
const bool allow_exceptions_ =
true)
5351 : root(r), allow_exceptions(allow_exceptions_)
5355 json_sax_dom_parser(
const json_sax_dom_parser&) =
delete;
5356 json_sax_dom_parser(json_sax_dom_parser&&) =
default;
5357 json_sax_dom_parser& operator=(
const json_sax_dom_parser&) =
delete;
5358 json_sax_dom_parser& operator=(json_sax_dom_parser&&) =
default;
5359 ~json_sax_dom_parser() =
default;
5363 handle_value(
nullptr);
5367 bool boolean(
bool val)
5373 bool number_integer(number_integer_t val)
5379 bool number_unsigned(number_unsigned_t val)
5385 bool number_float(number_float_t val,
const string_t& )
5391 bool string(string_t& val)
5397 bool binary(binary_t& val)
5399 handle_value(std::move(val));
5403 bool start_object(std::size_t len)
5405 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
5407 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5409 JSON_THROW(out_of_range::create(408,
5410 "excessive object size: " + std::to_string(len)));
5416 bool key(string_t& val)
5419 object_element = &(ref_stack.back()->m_value.object->operator[](val));
5425 ref_stack.pop_back();
5429 bool start_array(std::size_t len)
5431 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
5433 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5435 JSON_THROW(out_of_range::create(408,
5436 "excessive array size: " + std::to_string(len)));
5444 ref_stack.pop_back();
5448 template<
class Exception>
5449 bool parse_error(std::size_t ,
const std::string& ,
5450 const Exception& ex)
5453 static_cast<void>(ex);
5454 if (allow_exceptions)
5461 constexpr
bool is_errored()
const
5473 template<
typename Value>
5475 BasicJsonType* handle_value(Value&& v)
5477 if (ref_stack.empty())
5479 root = BasicJsonType(std::forward<Value>(v));
5483 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
5485 if (ref_stack.back()->is_array())
5487 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
5488 return &(ref_stack.back()->m_value.array->back());
5491 JSON_ASSERT(ref_stack.back()->is_object());
5492 JSON_ASSERT(object_element);
5493 *object_element = BasicJsonType(std::forward<Value>(v));
5494 return object_element;
5498 BasicJsonType& root;
5500 std::vector<BasicJsonType*> ref_stack {};
5502 BasicJsonType* object_element =
nullptr;
5504 bool errored =
false;
5506 const bool allow_exceptions =
true;
5509 template<
typename BasicJsonType>
5510 class json_sax_dom_callback_parser
5513 using number_integer_t =
typename BasicJsonType::number_integer_t;
5514 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5515 using number_float_t =
typename BasicJsonType::number_float_t;
5516 using string_t =
typename BasicJsonType::string_t;
5517 using binary_t =
typename BasicJsonType::binary_t;
5518 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
5519 using parse_event_t =
typename BasicJsonType::parse_event_t;
5521 json_sax_dom_callback_parser(BasicJsonType& r,
5522 const parser_callback_t cb,
5523 const bool allow_exceptions_ =
true)
5524 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
5526 keep_stack.push_back(
true);
5530 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
5531 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
default;
5532 json_sax_dom_callback_parser& operator=(
const json_sax_dom_callback_parser&) =
delete;
5533 json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) =
default;
5534 ~json_sax_dom_callback_parser() =
default;
5538 handle_value(
nullptr);
5542 bool boolean(
bool val)
5548 bool number_integer(number_integer_t val)
5554 bool number_unsigned(number_unsigned_t val)
5560 bool number_float(number_float_t val,
const string_t& )
5566 bool string(string_t& val)
5572 bool binary(binary_t& val)
5574 handle_value(std::move(val));
5578 bool start_object(std::size_t len)
5581 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
5582 keep_stack.push_back(keep);
5584 auto val = handle_value(BasicJsonType::value_t::object,
true);
5585 ref_stack.push_back(val.second);
5588 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5590 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len)));
5596 bool key(string_t& val)
5598 BasicJsonType k = BasicJsonType(val);
5601 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
5602 key_keep_stack.push_back(keep);
5605 if (keep && ref_stack.back())
5607 object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
5615 if (ref_stack.back() && !callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
5618 *ref_stack.back() = discarded;
5621 JSON_ASSERT(!ref_stack.empty());
5622 JSON_ASSERT(!keep_stack.empty());
5623 ref_stack.pop_back();
5624 keep_stack.pop_back();
5626 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
5629 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
5631 if (it->is_discarded())
5633 ref_stack.back()->erase(it);
5642 bool start_array(std::size_t len)
5644 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
5645 keep_stack.push_back(keep);
5647 auto val = handle_value(BasicJsonType::value_t::array,
true);
5648 ref_stack.push_back(val.second);
5651 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5653 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len)));
5663 if (ref_stack.back())
5665 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
5669 *ref_stack.back() = discarded;
5673 JSON_ASSERT(!ref_stack.empty());
5674 JSON_ASSERT(!keep_stack.empty());
5675 ref_stack.pop_back();
5676 keep_stack.pop_back();
5679 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
5681 ref_stack.back()->m_value.array->pop_back();
5687 template<
class Exception>
5688 bool parse_error(std::size_t ,
const std::string& ,
5689 const Exception& ex)
5692 static_cast<void>(ex);
5693 if (allow_exceptions)
5700 constexpr
bool is_errored()
const
5721 template<
typename Value>
5722 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
5724 JSON_ASSERT(!keep_stack.empty());
5728 if (!keep_stack.back())
5730 return {
false,
nullptr};
5734 auto value = BasicJsonType(std::forward<Value>(v));
5737 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
5742 return {
false,
nullptr};
5745 if (ref_stack.empty())
5747 root = std::move(value);
5748 return {
true, &root};
5753 if (!ref_stack.back())
5755 return {
false,
nullptr};
5759 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
5762 if (ref_stack.back()->is_array())
5764 ref_stack.back()->m_value.array->push_back(std::move(value));
5765 return {
true, &(ref_stack.back()->m_value.array->back())};
5769 JSON_ASSERT(ref_stack.back()->is_object());
5771 JSON_ASSERT(!key_keep_stack.empty());
5772 const bool store_element = key_keep_stack.back();
5773 key_keep_stack.pop_back();
5777 return {
false,
nullptr};
5780 JSON_ASSERT(object_element);
5781 *object_element = std::move(value);
5782 return {
true, object_element};
5786 BasicJsonType& root;
5788 std::vector<BasicJsonType*> ref_stack {};
5790 std::vector<bool> keep_stack {};
5792 std::vector<bool> key_keep_stack {};
5794 BasicJsonType* object_element =
nullptr;
5796 bool errored =
false;
5798 const parser_callback_t callback =
nullptr;
5800 const bool allow_exceptions =
true;
5802 BasicJsonType discarded = BasicJsonType::value_t::discarded;
5805 template<
typename BasicJsonType>
5806 class json_sax_acceptor
5809 using number_integer_t =
typename BasicJsonType::number_integer_t;
5810 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5811 using number_float_t =
typename BasicJsonType::number_float_t;
5812 using string_t =
typename BasicJsonType::string_t;
5813 using binary_t =
typename BasicJsonType::binary_t;
5825 bool number_integer(number_integer_t )
5830 bool number_unsigned(number_unsigned_t )
5835 bool number_float(number_float_t ,
const string_t& )
5840 bool string(string_t& )
5845 bool binary(binary_t& )
5850 bool start_object(std::size_t = std::size_t(-1))
5855 bool key(string_t& )
5865 bool start_array(std::size_t = std::size_t(-1))
5875 bool parse_error(std::size_t ,
const std::string& ,
const detail::exception& )
5892 #include <initializer_list>
5912 template<
typename BasicJsonType>
5917 enum class token_type
5941 static const char* token_type_name(
const token_type t) noexcept
5945 case token_type::uninitialized:
5946 return "<uninitialized>";
5947 case token_type::literal_true:
5948 return "true literal";
5949 case token_type::literal_false:
5950 return "false literal";
5951 case token_type::literal_null:
5952 return "null literal";
5953 case token_type::value_string:
5954 return "string literal";
5955 case token_type::value_unsigned:
5956 case token_type::value_integer:
5957 case token_type::value_float:
5958 return "number literal";
5959 case token_type::begin_array:
5961 case token_type::begin_object:
5963 case token_type::end_array:
5965 case token_type::end_object:
5967 case token_type::name_separator:
5969 case token_type::value_separator:
5971 case token_type::parse_error:
5972 return "<parse error>";
5973 case token_type::end_of_input:
5974 return "end of input";
5975 case token_type::literal_or_value:
5976 return "'[', '{', or a literal";
5979 return "unknown token";
5989 template<
typename BasicJsonType,
typename InputAdapterType>
5990 class lexer :
public lexer_base<BasicJsonType>
5992 using number_integer_t =
typename BasicJsonType::number_integer_t;
5993 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5994 using number_float_t =
typename BasicJsonType::number_float_t;
5995 using string_t =
typename BasicJsonType::string_t;
5996 using char_type =
typename InputAdapterType::char_type;
5997 using char_int_type =
typename std::char_traits<char_type>::int_type;
6000 using token_type =
typename lexer_base<BasicJsonType>::token_type;
6002 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false)
6003 : ia(std::move(adapter))
6004 , ignore_comments(ignore_comments_)
6005 , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
6009 lexer(
const lexer&) =
delete;
6010 lexer(lexer&&) =
default;
6011 lexer& operator=(lexer&) =
delete;
6012 lexer& operator=(lexer&&) =
default;
6022 static char get_decimal_point() noexcept
6024 const auto* loc = localeconv();
6025 JSON_ASSERT(loc !=
nullptr);
6026 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
6051 JSON_ASSERT(current ==
'u');
6054 const auto factors = { 12u, 8u, 4u, 0u };
6055 for (
const auto factor : factors)
6059 if (current >=
'0' && current <=
'9')
6061 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
6063 else if (current >=
'A' && current <=
'F')
6065 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
6067 else if (current >=
'a' && current <=
'f')
6069 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
6077 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6096 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
6098 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
6101 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
6104 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
6110 error_message =
"invalid string: ill-formed UTF-8 byte";
6133 token_type scan_string()
6139 JSON_ASSERT(current ==
'\"');
6147 case std::char_traits<char_type>::eof():
6149 error_message =
"invalid string: missing closing quote";
6150 return token_type::parse_error;
6156 return token_type::value_string;
6200 const int codepoint1 = get_codepoint();
6201 int codepoint = codepoint1;
6203 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
6205 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6206 return token_type::parse_error;
6210 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
6213 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
6215 const int codepoint2 = get_codepoint();
6217 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
6219 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6220 return token_type::parse_error;
6224 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
6227 codepoint =
static_cast<int>(
6229 (
static_cast<unsigned int>(codepoint1) << 10u)
6231 +
static_cast<unsigned int>(codepoint2)
6239 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6240 return token_type::parse_error;
6245 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6246 return token_type::parse_error;
6251 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
6253 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
6254 return token_type::parse_error;
6259 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
6262 if (codepoint < 0x80)
6265 add(
static_cast<char_int_type
>(codepoint));
6267 else if (codepoint <= 0x7FF)
6270 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
6271 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6273 else if (codepoint <= 0xFFFF)
6276 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
6277 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6278 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6283 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
6284 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
6285 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6286 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6294 error_message =
"invalid string: forbidden character after backslash";
6295 return token_type::parse_error;
6304 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
6305 return token_type::parse_error;
6310 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
6311 return token_type::parse_error;
6316 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
6317 return token_type::parse_error;
6322 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
6323 return token_type::parse_error;
6328 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
6329 return token_type::parse_error;
6334 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
6335 return token_type::parse_error;
6340 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
6341 return token_type::parse_error;
6346 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
6347 return token_type::parse_error;
6352 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
6353 return token_type::parse_error;
6358 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
6359 return token_type::parse_error;
6364 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
6365 return token_type::parse_error;
6370 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
6371 return token_type::parse_error;
6376 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
6377 return token_type::parse_error;
6382 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
6383 return token_type::parse_error;
6388 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
6389 return token_type::parse_error;
6394 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
6395 return token_type::parse_error;
6400 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
6401 return token_type::parse_error;
6406 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
6407 return token_type::parse_error;
6412 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
6413 return token_type::parse_error;
6418 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
6419 return token_type::parse_error;
6424 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
6425 return token_type::parse_error;
6430 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
6431 return token_type::parse_error;
6436 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
6437 return token_type::parse_error;
6442 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
6443 return token_type::parse_error;
6448 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
6449 return token_type::parse_error;
6454 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
6455 return token_type::parse_error;
6460 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
6461 return token_type::parse_error;
6466 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
6467 return token_type::parse_error;
6472 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
6473 return token_type::parse_error;
6478 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
6479 return token_type::parse_error;
6484 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
6485 return token_type::parse_error;
6490 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
6491 return token_type::parse_error;
6626 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
6628 return token_type::parse_error;
6636 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
6638 return token_type::parse_error;
6660 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
6662 return token_type::parse_error;
6670 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
6672 return token_type::parse_error;
6680 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
6682 return token_type::parse_error;
6692 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
6694 return token_type::parse_error;
6702 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
6704 return token_type::parse_error;
6712 error_message =
"invalid string: ill-formed UTF-8 byte";
6713 return token_type::parse_error;
6736 case std::char_traits<char_type>::eof():
6753 case std::char_traits<char_type>::eof():
6756 error_message =
"invalid comment; missing closing '*/'";
6784 error_message =
"invalid comment; expecting '/' or '*' after '/'";
6790 JSON_HEDLEY_NON_NULL(2)
6791 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
6793 f = std::strtof(str, endptr);
6796 JSON_HEDLEY_NON_NULL(2)
6797 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
6799 f = std::strtod(str, endptr);
6802 JSON_HEDLEY_NON_NULL(2)
6803 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
6805 f = std::strtold(str, endptr);
6848 token_type scan_number()
6855 token_type number_type = token_type::value_unsigned;
6863 goto scan_number_minus;
6869 goto scan_number_zero;
6883 goto scan_number_any1;
6893 number_type = token_type::value_integer;
6899 goto scan_number_zero;
6913 goto scan_number_any1;
6918 error_message =
"invalid number; expected digit after '-'";
6919 return token_type::parse_error;
6929 add(decimal_point_char);
6930 goto scan_number_decimal1;
6937 goto scan_number_exponent;
6941 goto scan_number_done;
6960 goto scan_number_any1;
6965 add(decimal_point_char);
6966 goto scan_number_decimal1;
6973 goto scan_number_exponent;
6977 goto scan_number_done;
6980 scan_number_decimal1:
6982 number_type = token_type::value_float;
6997 goto scan_number_decimal2;
7002 error_message =
"invalid number; expected digit after '.'";
7003 return token_type::parse_error;
7007 scan_number_decimal2:
7023 goto scan_number_decimal2;
7030 goto scan_number_exponent;
7034 goto scan_number_done;
7037 scan_number_exponent:
7039 number_type = token_type::value_float;
7046 goto scan_number_sign;
7061 goto scan_number_any2;
7067 "invalid number; expected '+', '-', or digit after exponent";
7068 return token_type::parse_error;
7088 goto scan_number_any2;
7093 error_message =
"invalid number; expected digit after exponent sign";
7094 return token_type::parse_error;
7114 goto scan_number_any2;
7118 goto scan_number_done;
7126 char* endptr =
nullptr;
7130 if (number_type == token_type::value_unsigned)
7132 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
7135 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7139 value_unsigned =
static_cast<number_unsigned_t
>(x);
7140 if (value_unsigned == x)
7142 return token_type::value_unsigned;
7146 else if (number_type == token_type::value_integer)
7148 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
7151 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7155 value_integer =
static_cast<number_integer_t
>(x);
7156 if (value_integer == x)
7158 return token_type::value_integer;
7165 strtof(value_float, token_buffer.data(), &endptr);
7168 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7170 return token_type::value_float;
7178 JSON_HEDLEY_NON_NULL(2)
7179 token_type scan_literal(const char_type* literal_text, const std::
size_t length,
7180 token_type return_type)
7182 JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
7183 for (std::size_t i = 1; i < length; ++i)
7185 if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
7187 error_message =
"invalid literal";
7188 return token_type::parse_error;
7199 void reset() noexcept
7201 token_buffer.clear();
7202 token_string.clear();
7203 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7218 ++position.chars_read_total;
7219 ++position.chars_read_current_line;
7228 current = ia.get_character();
7231 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7233 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7236 if (current ==
'\n')
7238 ++position.lines_read;
7239 position.chars_read_current_line = 0;
7257 --position.chars_read_total;
7260 if (position.chars_read_current_line == 0)
7262 if (position.lines_read > 0)
7264 --position.lines_read;
7269 --position.chars_read_current_line;
7272 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7274 JSON_ASSERT(!token_string.empty());
7275 token_string.pop_back();
7280 void add(char_int_type c)
7282 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
7291 constexpr number_integer_t get_number_integer() const noexcept
7293 return value_integer;
7297 constexpr number_unsigned_t get_number_unsigned() const noexcept
7299 return value_unsigned;
7303 constexpr number_float_t get_number_float() const noexcept
7309 string_t& get_string()
7311 return token_buffer;
7319 constexpr position_t get_position() const noexcept
7327 std::string get_token_string()
const
7331 for (
const auto c : token_string)
7333 if (
static_cast<unsigned char>(c) <=
'\x1F')
7336 std::array<char, 9> cs{{}};
7337 (std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c));
7338 result += cs.data();
7343 result.push_back(
static_cast<std::string::value_type
>(c));
7352 constexpr
const char* get_error_message() const noexcept
7354 return error_message;
7370 return get() == 0xBB && get() == 0xBF;
7379 void skip_whitespace()
7385 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
7391 if (position.chars_read_total == 0 && !skip_bom())
7393 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
7394 return token_type::parse_error;
7401 while (ignore_comments && current ==
'/')
7403 if (!scan_comment())
7405 return token_type::parse_error;
7416 return token_type::begin_array;
7418 return token_type::end_array;
7420 return token_type::begin_object;
7422 return token_type::end_object;
7424 return token_type::name_separator;
7426 return token_type::value_separator;
7431 std::array<char_type, 4> true_literal = {{
't',
'r',
'u',
'e'}};
7432 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
7436 std::array<char_type, 5> false_literal = {{
'f',
'a',
'l',
's',
'e'}};
7437 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
7441 std::array<char_type, 4> null_literal = {{
'n',
'u',
'l',
'l'}};
7442 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
7447 return scan_string();
7461 return scan_number();
7466 case std::char_traits<char_type>::eof():
7467 return token_type::end_of_input;
7471 error_message =
"invalid literal";
7472 return token_type::parse_error;
7478 InputAdapterType ia;
7481 const bool ignore_comments =
false;
7484 char_int_type current = std::char_traits<char_type>::eof();
7487 bool next_unget =
false;
7490 position_t position {};
7493 std::vector<char_type> token_string {};
7496 string_t token_buffer {};
7499 const char* error_message =
"";
7502 number_integer_t value_integer = 0;
7503 number_unsigned_t value_unsigned = 0;
7504 number_float_t value_float = 0;
7507 const char_int_type decimal_point_char =
'.';
7530 template<
typename T>
7531 using null_function_t = decltype(std::declval<T&>().
null());
7533 template<
typename T>
7534 using boolean_function_t =
7535 decltype(std::declval<T&>().
boolean(std::declval<bool>()));
7537 template<
typename T,
typename Integer>
7538 using number_integer_function_t =
7539 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
7541 template<
typename T,
typename Un
signed>
7542 using number_unsigned_function_t =
7543 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
7545 template<
typename T,
typename Float,
typename String>
7546 using number_float_function_t = decltype(std::declval<T&>().number_float(
7547 std::declval<Float>(), std::declval<const String&>()));
7549 template<
typename T,
typename String>
7550 using string_function_t =
7551 decltype(std::declval<T&>().
string(std::declval<String&>()));
7553 template<
typename T,
typename Binary>
7554 using binary_function_t =
7555 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
7557 template<
typename T>
7558 using start_object_function_t =
7559 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
7561 template<
typename T,
typename String>
7562 using key_function_t =
7563 decltype(std::declval<T&>().key(std::declval<String&>()));
7565 template<
typename T>
7566 using end_object_function_t = decltype(std::declval<T&>().end_object());
7568 template<
typename T>
7569 using start_array_function_t =
7570 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
7572 template<
typename T>
7573 using end_array_function_t = decltype(std::declval<T&>().end_array());
7575 template<
typename T,
typename Exception>
7576 using parse_error_function_t = decltype(std::declval<T&>().parse_error(
7577 std::declval<std::size_t>(), std::declval<const std::string&>(),
7578 std::declval<const Exception&>()));
7580 template<
typename SAX,
typename BasicJsonType>
7584 static_assert(is_basic_json<BasicJsonType>::value,
7585 "BasicJsonType must be of type basic_json<...>");
7587 using number_integer_t =
typename BasicJsonType::number_integer_t;
7588 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7589 using number_float_t =
typename BasicJsonType::number_float_t;
7590 using string_t =
typename BasicJsonType::string_t;
7591 using binary_t =
typename BasicJsonType::binary_t;
7592 using exception_t =
typename BasicJsonType::exception;
7595 static constexpr
bool value =
7596 is_detected_exact<bool, null_function_t, SAX>::value &&
7597 is_detected_exact<bool, boolean_function_t, SAX>::value &&
7598 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
7599 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
7600 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
7601 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
7602 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
7603 is_detected_exact<bool, start_object_function_t, SAX>::value &&
7604 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
7605 is_detected_exact<bool, end_object_function_t, SAX>::value &&
7606 is_detected_exact<bool, start_array_function_t, SAX>::value &&
7607 is_detected_exact<bool, end_array_function_t, SAX>::value &&
7608 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
7611 template<
typename SAX,
typename BasicJsonType>
7612 struct is_sax_static_asserts
7615 static_assert(is_basic_json<BasicJsonType>::value,
7616 "BasicJsonType must be of type basic_json<...>");
7618 using number_integer_t =
typename BasicJsonType::number_integer_t;
7619 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7620 using number_float_t =
typename BasicJsonType::number_float_t;
7621 using string_t =
typename BasicJsonType::string_t;
7622 using binary_t =
typename BasicJsonType::binary_t;
7623 using exception_t =
typename BasicJsonType::exception;
7626 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
7627 "Missing/invalid function: bool null()");
7628 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
7629 "Missing/invalid function: bool boolean(bool)");
7630 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
7631 "Missing/invalid function: bool boolean(bool)");
7633 is_detected_exact<
bool, number_integer_function_t, SAX,
7634 number_integer_t>::value,
7635 "Missing/invalid function: bool number_integer(number_integer_t)");
7637 is_detected_exact<
bool, number_unsigned_function_t, SAX,
7638 number_unsigned_t>::value,
7639 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
7640 static_assert(is_detected_exact<
bool, number_float_function_t, SAX,
7641 number_float_t, string_t>::value,
7642 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
7644 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
7645 "Missing/invalid function: bool string(string_t&)");
7647 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
7648 "Missing/invalid function: bool binary(binary_t&)");
7649 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
7650 "Missing/invalid function: bool start_object(std::size_t)");
7651 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
7652 "Missing/invalid function: bool key(string_t&)");
7653 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
7654 "Missing/invalid function: bool end_object()");
7655 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
7656 "Missing/invalid function: bool start_array(std::size_t)");
7657 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
7658 "Missing/invalid function: bool end_array()");
7660 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
7661 "Missing/invalid function: bool parse_error(std::size_t, const "
7662 "std::string&, const exception&)");
7676 enum class cbor_tag_handler_t
7689 static inline bool little_endianess(
int num = 1) noexcept
7691 return *
reinterpret_cast<char*
>(&num) == 1;
7702 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
7705 using number_integer_t =
typename BasicJsonType::number_integer_t;
7706 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7707 using number_float_t =
typename BasicJsonType::number_float_t;
7708 using string_t =
typename BasicJsonType::string_t;
7709 using binary_t =
typename BasicJsonType::binary_t;
7710 using json_sax_t = SAX;
7711 using char_type =
typename InputAdapterType::char_type;
7712 using char_int_type =
typename std::char_traits<char_type>::int_type;
7720 explicit binary_reader(InputAdapterType&& adapter) : ia(std::move(adapter))
7722 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
7726 binary_reader(
const binary_reader&) =
delete;
7727 binary_reader(binary_reader&&) =
default;
7728 binary_reader& operator=(
const binary_reader&) =
delete;
7729 binary_reader& operator=(binary_reader&&) =
default;
7730 ~binary_reader() =
default;
7740 JSON_HEDLEY_NON_NULL(3)
7741 bool sax_parse(const input_format_t format,
7743 const
bool strict = true,
7744 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
7747 bool result =
false;
7751 case input_format_t::bson:
7752 result = parse_bson_internal();
7755 case input_format_t::cbor:
7756 result = parse_cbor_internal(
true, tag_handler);
7759 case input_format_t::msgpack:
7760 result = parse_msgpack_internal();
7763 case input_format_t::ubjson:
7764 result = parse_ubjson_internal();
7772 if (result && strict)
7774 if (format == input_format_t::ubjson)
7783 if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
7785 return sax->parse_error(chars_read, get_token_string(),
7786 parse_error::create(110, chars_read, exception_message(format,
"expected end of input; last byte: 0x" + get_token_string(),
"value")));
7802 bool parse_bson_internal()
7804 std::int32_t document_size{};
7805 get_number<std::int32_t, true>(input_format_t::bson, document_size);
7807 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
7812 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
7817 return sax->end_object();
7827 bool get_bson_cstr(string_t& result)
7829 auto out = std::back_inserter(result);
7833 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
7837 if (current == 0x00)
7841 *out++ =
static_cast<typename string_t::value_type
>(current);
7856 template<
typename NumberType>
7857 bool get_bson_string(
const NumberType len, string_t& result)
7859 if (JSON_HEDLEY_UNLIKELY(len < 1))
7861 auto last_token = get_token_string();
7862 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")));
7865 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != std::char_traits<char_type>::eof();
7877 template<
typename NumberType>
7878 bool get_bson_binary(
const NumberType len, binary_t& result)
7880 if (JSON_HEDLEY_UNLIKELY(len < 0))
7882 auto last_token = get_token_string();
7883 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson,
"byte array length cannot be negative, is " + std::to_string(len),
"binary")));
7887 std::uint8_t subtype{};
7888 get_number<std::uint8_t>(input_format_t::bson, subtype);
7889 result.set_subtype(subtype);
7891 return get_binary(input_format_t::bson, len, result);
7904 bool parse_bson_element_internal(
const char_int_type element_type,
7905 const std::size_t element_type_parse_position)
7907 switch (element_type)
7912 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
7919 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
7924 return parse_bson_internal();
7929 return parse_bson_array();
7936 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
7941 return sax->boolean(get() != 0);
7951 std::int32_t value{};
7952 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
7957 std::int64_t value{};
7958 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
7963 std::array<char, 3> cr{{}};
7964 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type));
7965 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())));
7982 bool parse_bson_element_list(
const bool is_array)
7986 while (
auto element_type = get())
7988 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
7993 const std::size_t element_type_parse_position = chars_read;
7994 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
7999 if (!is_array && !sax->key(key))
8004 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
8020 bool parse_bson_array()
8022 std::int32_t document_size{};
8023 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8025 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
8030 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
8035 return sax->end_array();
8050 bool parse_cbor_internal(
const bool get_char,
8051 const cbor_tag_handler_t tag_handler)
8053 switch (get_char ? get() : current)
8056 case std::char_traits<char_type>::eof():
8057 return unexpect_eof(input_format_t::cbor,
"value");
8084 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
8088 std::uint8_t number{};
8089 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8094 std::uint16_t number{};
8095 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8100 std::uint32_t number{};
8101 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8106 std::uint64_t number{};
8107 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8135 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
8139 std::uint8_t number{};
8140 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8145 std::uint16_t number{};
8146 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8151 std::uint32_t number{};
8152 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8157 std::uint64_t number{};
8158 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
8159 -
static_cast<number_integer_t
>(number));
8194 return get_cbor_binary(b) && sax->binary(b);
8229 return get_cbor_string(s) && sax->string(s);
8257 return get_cbor_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8262 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8267 std::uint16_t len{};
8268 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8273 std::uint32_t len{};
8274 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8279 std::uint64_t len{};
8280 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8284 return get_cbor_array(std::size_t(-1), tag_handler);
8311 return get_cbor_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8316 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8321 std::uint16_t len{};
8322 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8327 std::uint32_t len{};
8328 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8333 std::uint64_t len{};
8334 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8338 return get_cbor_object(std::size_t(-1), tag_handler);
8360 switch (tag_handler)
8362 case cbor_tag_handler_t::error:
8364 auto last_token = get_token_string();
8365 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")));
8368 case cbor_tag_handler_t::ignore:
8375 get_number(input_format_t::cbor, len);
8380 std::uint16_t len{};
8381 get_number(input_format_t::cbor, len);
8386 std::uint32_t len{};
8387 get_number(input_format_t::cbor, len);
8392 std::uint64_t len{};
8393 get_number(input_format_t::cbor, len);
8399 return parse_cbor_internal(
true, tag_handler);
8409 return sax->boolean(
false);
8412 return sax->boolean(
true);
8419 const auto byte1_raw = get();
8420 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
8424 const auto byte2_raw = get();
8425 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
8430 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
8431 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
8441 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
8442 const double val = [&half]
8444 const int exp = (half >> 10u) & 0x1Fu;
8445 const unsigned int mant = half & 0x3FFu;
8446 JSON_ASSERT(0 <= exp&& exp <= 32);
8447 JSON_ASSERT(mant <= 1024);
8451 return std::ldexp(mant, -24);
8454 ? std::numeric_limits<double>::infinity()
8455 : std::numeric_limits<double>::quiet_NaN();
8457 return std::ldexp(mant + 1024, exp - 25);
8460 return sax->number_float((half & 0x8000u) != 0
8461 ?
static_cast<number_float_t
>(-val)
8462 :
static_cast<number_float_t
>(val),
"");
8468 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
8474 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
8479 auto last_token = get_token_string();
8480 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")));
8496 bool get_cbor_string(string_t& result)
8498 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
8531 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
8537 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8542 std::uint16_t len{};
8543 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8548 std::uint32_t len{};
8549 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8554 std::uint64_t len{};
8555 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8560 while (get() != 0xFF)
8563 if (!get_cbor_string(chunk))
8567 result.append(chunk);
8574 auto last_token = get_token_string();
8575 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")));
8591 bool get_cbor_binary(binary_t& result)
8593 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
8626 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
8632 return get_number(input_format_t::cbor, len) &&
8633 get_binary(input_format_t::cbor, len, result);
8638 std::uint16_t len{};
8639 return get_number(input_format_t::cbor, len) &&
8640 get_binary(input_format_t::cbor, len, result);
8645 std::uint32_t len{};
8646 return get_number(input_format_t::cbor, len) &&
8647 get_binary(input_format_t::cbor, len, result);
8652 std::uint64_t len{};
8653 return get_number(input_format_t::cbor, len) &&
8654 get_binary(input_format_t::cbor, len, result);
8659 while (get() != 0xFF)
8662 if (!get_cbor_binary(chunk))
8666 result.insert(result.end(), chunk.begin(), chunk.end());
8673 auto last_token = get_token_string();
8674 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor,
"expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x" + last_token,
"binary")));
8685 bool get_cbor_array(
const std::size_t len,
8686 const cbor_tag_handler_t tag_handler)
8688 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
8693 if (len != std::size_t(-1))
8695 for (std::size_t i = 0; i < len; ++i)
8697 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
8705 while (get() != 0xFF)
8707 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
8714 return sax->end_array();
8723 bool get_cbor_object(
const std::size_t len,
8724 const cbor_tag_handler_t tag_handler)
8726 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
8732 if (len != std::size_t(-1))
8734 for (std::size_t i = 0; i < len; ++i)
8737 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
8742 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
8751 while (get() != 0xFF)
8753 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
8758 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
8766 return sax->end_object();
8776 bool parse_msgpack_internal()
8781 case std::char_traits<char_type>::eof():
8782 return unexpect_eof(input_format_t::msgpack,
"value");
8913 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
8932 return get_msgpack_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
8951 return get_msgpack_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
8991 return get_msgpack_string(s) && sax->string(s);
8998 return sax->boolean(
false);
9001 return sax->boolean(
true);
9016 return get_msgpack_binary(b) && sax->binary(b);
9022 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9028 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9033 std::uint8_t number{};
9034 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9039 std::uint16_t number{};
9040 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9045 std::uint32_t number{};
9046 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9051 std::uint64_t number{};
9052 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9057 std::int8_t number{};
9058 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9063 std::int16_t number{};
9064 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9069 std::int32_t number{};
9070 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9075 std::int64_t number{};
9076 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9081 std::uint16_t len{};
9082 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9087 std::uint32_t len{};
9088 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9093 std::uint16_t len{};
9094 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9099 std::uint32_t len{};
9100 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9136 return sax->number_integer(
static_cast<std::int8_t
>(current));
9140 auto last_token = get_token_string();
9141 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")));
9156 bool get_msgpack_string(string_t& result)
9158 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
9199 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
9205 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9210 std::uint16_t len{};
9211 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9216 std::uint32_t len{};
9217 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9222 auto last_token = get_token_string();
9223 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")));
9238 bool get_msgpack_binary(binary_t& result)
9241 auto assign_and_return_true = [&result](std::int8_t subtype)
9243 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
9252 return get_number(input_format_t::msgpack, len) &&
9253 get_binary(input_format_t::msgpack, len, result);
9258 std::uint16_t len{};
9259 return get_number(input_format_t::msgpack, len) &&
9260 get_binary(input_format_t::msgpack, len, result);
9265 std::uint32_t len{};
9266 return get_number(input_format_t::msgpack, len) &&
9267 get_binary(input_format_t::msgpack, len, result);
9273 std::int8_t subtype{};
9274 return get_number(input_format_t::msgpack, len) &&
9275 get_number(input_format_t::msgpack, subtype) &&
9276 get_binary(input_format_t::msgpack, len, result) &&
9277 assign_and_return_true(subtype);
9282 std::uint16_t len{};
9283 std::int8_t subtype{};
9284 return get_number(input_format_t::msgpack, len) &&
9285 get_number(input_format_t::msgpack, subtype) &&
9286 get_binary(input_format_t::msgpack, len, result) &&
9287 assign_and_return_true(subtype);
9292 std::uint32_t len{};
9293 std::int8_t subtype{};
9294 return get_number(input_format_t::msgpack, len) &&
9295 get_number(input_format_t::msgpack, subtype) &&
9296 get_binary(input_format_t::msgpack, len, result) &&
9297 assign_and_return_true(subtype);
9302 std::int8_t subtype{};
9303 return get_number(input_format_t::msgpack, subtype) &&
9304 get_binary(input_format_t::msgpack, 1, result) &&
9305 assign_and_return_true(subtype);
9310 std::int8_t subtype{};
9311 return get_number(input_format_t::msgpack, subtype) &&
9312 get_binary(input_format_t::msgpack, 2, result) &&
9313 assign_and_return_true(subtype);
9318 std::int8_t subtype{};
9319 return get_number(input_format_t::msgpack, subtype) &&
9320 get_binary(input_format_t::msgpack, 4, result) &&
9321 assign_and_return_true(subtype);
9326 std::int8_t subtype{};
9327 return get_number(input_format_t::msgpack, subtype) &&
9328 get_binary(input_format_t::msgpack, 8, result) &&
9329 assign_and_return_true(subtype);
9334 std::int8_t subtype{};
9335 return get_number(input_format_t::msgpack, subtype) &&
9336 get_binary(input_format_t::msgpack, 16, result) &&
9337 assign_and_return_true(subtype);
9349 bool get_msgpack_array(
const std::size_t len)
9351 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9356 for (std::size_t i = 0; i < len; ++i)
9358 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
9364 return sax->end_array();
9371 bool get_msgpack_object(
const std::size_t len)
9373 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9379 for (std::size_t i = 0; i < len; ++i)
9382 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
9387 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
9394 return sax->end_object();
9408 bool parse_ubjson_internal(
const bool get_char =
true)
9410 return get_ubjson_value(get_char ? get_ignore_noop() : current);
9427 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
9434 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
9444 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9450 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9456 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9462 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9468 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9472 auto last_token = get_token_string();
9473 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")));
9481 bool get_ubjson_size_value(std::size_t& result)
9483 switch (get_ignore_noop())
9487 std::uint8_t number{};
9488 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9492 result =
static_cast<std::size_t
>(number);
9498 std::int8_t number{};
9499 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9503 result =
static_cast<std::size_t
>(number);
9509 std::int16_t number{};
9510 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9514 result =
static_cast<std::size_t
>(number);
9520 std::int32_t number{};
9521 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9525 result =
static_cast<std::size_t
>(number);
9531 std::int64_t number{};
9532 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9536 result =
static_cast<std::size_t
>(number);
9542 auto last_token = get_token_string();
9543 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")));
9558 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result)
9560 result.first = string_t::npos;
9567 result.second = get();
9568 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"type")))
9574 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
9576 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
9580 auto last_token = get_token_string();
9581 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")));
9584 return get_ubjson_size_value(result.first);
9589 return get_ubjson_size_value(result.first);
9599 bool get_ubjson_value(
const char_int_type prefix)
9603 case std::char_traits<char_type>::eof():
9604 return unexpect_eof(input_format_t::ubjson,
"value");
9607 return sax->boolean(
true);
9609 return sax->boolean(
false);
9616 std::uint8_t number{};
9617 return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number);
9622 std::int8_t number{};
9623 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
9628 std::int16_t number{};
9629 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
9634 std::int32_t number{};
9635 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
9640 std::int64_t number{};
9641 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
9647 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9653 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9658 return get_ubjson_high_precision_number();
9664 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"char")))
9668 if (JSON_HEDLEY_UNLIKELY(current > 127))
9670 auto last_token = get_token_string();
9671 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")));
9673 string_t s(1,
static_cast<typename string_t::value_type
>(current));
9674 return sax->string(s);
9680 return get_ubjson_string(s) && sax->string(s);
9684 return get_ubjson_array();
9687 return get_ubjson_object();
9691 auto last_token = get_token_string();
9692 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")));
9700 bool get_ubjson_array()
9702 std::pair<std::size_t, char_int_type> size_and_type;
9703 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
9708 if (size_and_type.first != string_t::npos)
9710 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
9715 if (size_and_type.second != 0)
9717 if (size_and_type.second !=
'N')
9719 for (std::size_t i = 0; i < size_and_type.first; ++i)
9721 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
9730 for (std::size_t i = 0; i < size_and_type.first; ++i)
9732 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
9741 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
9746 while (current !=
']')
9748 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
9756 return sax->end_array();
9762 bool get_ubjson_object()
9764 std::pair<std::size_t, char_int_type> size_and_type;
9765 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
9771 if (size_and_type.first != string_t::npos)
9773 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
9778 if (size_and_type.second != 0)
9780 for (std::size_t i = 0; i < size_and_type.first; ++i)
9782 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
9786 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
9795 for (std::size_t i = 0; i < size_and_type.first; ++i)
9797 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
9801 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
9811 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
9816 while (current !=
'}')
9818 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
9822 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
9831 return sax->end_object();
9837 bool get_ubjson_high_precision_number()
9841 auto res = get_ubjson_size_value(size);
9842 if (JSON_HEDLEY_UNLIKELY(!res))
9848 std::vector<char> number_vector;
9849 for (std::size_t i = 0; i < size; ++i)
9852 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"number")))
9856 number_vector.push_back(
static_cast<char>(current));
9860 auto number_ia = detail::input_adapter(std::forward<decltype(number_vector)>(number_vector));
9861 auto number_lexer = detail::lexer<BasicJsonType, decltype(number_ia)>(std::move(number_ia),
false);
9862 const auto result_number = number_lexer.scan();
9863 const auto number_string = number_lexer.get_token_string();
9864 const auto result_remainder = number_lexer.scan();
9866 using token_type =
typename detail::lexer_base<BasicJsonType>::token_type;
9868 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
9870 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson,
"invalid number text: " + number_lexer.get_token_string(),
"high-precision number")));
9873 switch (result_number)
9875 case token_type::value_integer:
9876 return sax->number_integer(number_lexer.get_number_integer());
9877 case token_type::value_unsigned:
9878 return sax->number_unsigned(number_lexer.get_number_unsigned());
9879 case token_type::value_float:
9880 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
9882 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson,
"invalid number text: " + number_lexer.get_token_string(),
"high-precision number")));
9902 return current = ia.get_character();
9908 char_int_type get_ignore_noop()
9914 while (current ==
'N');
9932 template<
typename NumberType,
bool InputIsLittleEndian = false>
9933 bool get_number(
const input_format_t format, NumberType& result)
9936 std::array<std::uint8_t,
sizeof(NumberType)> vec;
9937 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
9940 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number")))
9946 if (is_little_endian != InputIsLittleEndian)
9948 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
9952 vec[i] =
static_cast<std::uint8_t
>(current);
9957 std::memcpy(&result, vec.data(),
sizeof(NumberType));
9975 template<
typename NumberType>
9976 bool get_string(
const input_format_t format,
9977 const NumberType len,
9980 bool success =
true;
9981 for (NumberType i = 0; i < len; i++)
9984 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
9989 result.push_back(
static_cast<typename string_t::value_type
>(current));
10008 template<
typename NumberType>
10009 bool get_binary(
const input_format_t format,
10010 const NumberType len,
10013 bool success =
true;
10014 for (NumberType i = 0; i < len; i++)
10017 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
10022 result.push_back(
static_cast<std::uint8_t
>(current));
10032 JSON_HEDLEY_NON_NULL(3)
10033 bool unexpect_eof(const input_format_t format, const
char* context)
const
10035 if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
10037 return sax->parse_error(chars_read,
"<end of file>",
10038 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context)));
10046 std::string get_token_string()
const
10048 std::array<char, 3> cr{{}};
10049 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current));
10050 return std::string{cr.data()};
10059 std::string exception_message(
const input_format_t format,
10060 const std::string& detail,
10061 const std::string& context)
const
10063 std::string error_msg =
"syntax error while parsing ";
10067 case input_format_t::cbor:
10068 error_msg +=
"CBOR";
10071 case input_format_t::msgpack:
10072 error_msg +=
"MessagePack";
10075 case input_format_t::ubjson:
10076 error_msg +=
"UBJSON";
10079 case input_format_t::bson:
10080 error_msg +=
"BSON";
10084 JSON_ASSERT(
false);
10087 return error_msg +
" " + context +
": " + detail;
10092 InputAdapterType ia;
10095 char_int_type current = std::char_traits<char_type>::eof();
10098 std::size_t chars_read = 0;
10101 const bool is_little_endian = little_endianess();
10104 json_sax_t* sax =
nullptr;
10118 #include <functional>
10146 enum class parse_event_t : uint8_t
10162 template<
typename BasicJsonType>
10163 using parser_callback_t =
10164 std::function<bool(
int depth, parse_event_t event, BasicJsonType& parsed)>;
10171 template<
typename BasicJsonType,
typename InputAdapterType>
10174 using number_integer_t =
typename BasicJsonType::number_integer_t;
10175 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
10176 using number_float_t =
typename BasicJsonType::number_float_t;
10177 using string_t =
typename BasicJsonType::string_t;
10178 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
10179 using token_type =
typename lexer_t::token_type;
10183 explicit parser(InputAdapterType&& adapter,
10184 const parser_callback_t<BasicJsonType> cb =
nullptr,
10185 const bool allow_exceptions_ =
true,
10186 const bool skip_comments =
false)
10188 , m_lexer(std::move(adapter), skip_comments)
10189 , allow_exceptions(allow_exceptions_)
10205 void parse(
const bool strict, BasicJsonType& result)
10209 json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
10210 sax_parse_internal(&sdp);
10211 result.assert_invariant();
10214 if (strict && (get_token() != token_type::end_of_input))
10216 sdp.parse_error(m_lexer.get_position(),
10217 m_lexer.get_token_string(),
10218 parse_error::create(101, m_lexer.get_position(),
10219 exception_message(token_type::end_of_input,
"value")));
10223 if (sdp.is_errored())
10225 result = value_t::discarded;
10231 if (result.is_discarded())
10238 json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
10239 sax_parse_internal(&sdp);
10240 result.assert_invariant();
10243 if (strict && (get_token() != token_type::end_of_input))
10245 sdp.parse_error(m_lexer.get_position(),
10246 m_lexer.get_token_string(),
10247 parse_error::create(101, m_lexer.get_position(),
10248 exception_message(token_type::end_of_input,
"value")));
10252 if (sdp.is_errored())
10254 result = value_t::discarded;
10266 bool accept(
const bool strict =
true)
10268 json_sax_acceptor<BasicJsonType> sax_acceptor;
10269 return sax_parse(&sax_acceptor, strict);
10272 template<
typename SAX>
10273 JSON_HEDLEY_NON_NULL(2)
10274 bool sax_parse(SAX* sax, const
bool strict = true)
10276 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
10277 const bool result = sax_parse_internal(sax);
10280 if (result && strict && (get_token() != token_type::end_of_input))
10282 return sax->parse_error(m_lexer.get_position(),
10283 m_lexer.get_token_string(),
10284 parse_error::create(101, m_lexer.get_position(),
10285 exception_message(token_type::end_of_input,
"value")));
10292 template<
typename SAX>
10293 JSON_HEDLEY_NON_NULL(2)
10294 bool sax_parse_internal(SAX* sax)
10298 std::vector<bool> states;
10300 bool skip_to_state_evaluation =
false;
10304 if (!skip_to_state_evaluation)
10307 switch (last_token)
10309 case token_type::begin_object:
10311 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10317 if (get_token() == token_type::end_object)
10319 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
10327 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
10329 return sax->parse_error(m_lexer.get_position(),
10330 m_lexer.get_token_string(),
10331 parse_error::create(101, m_lexer.get_position(),
10332 exception_message(token_type::value_string,
"object key")));
10334 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
10340 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
10342 return sax->parse_error(m_lexer.get_position(),
10343 m_lexer.get_token_string(),
10344 parse_error::create(101, m_lexer.get_position(),
10345 exception_message(token_type::name_separator,
"object separator")));
10349 states.push_back(
false);
10356 case token_type::begin_array:
10358 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10364 if (get_token() == token_type::end_array)
10366 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
10374 states.push_back(
true);
10380 case token_type::value_float:
10382 const auto res = m_lexer.get_number_float();
10384 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
10386 return sax->parse_error(m_lexer.get_position(),
10387 m_lexer.get_token_string(),
10388 out_of_range::create(406,
"number overflow parsing '" + m_lexer.get_token_string() +
"'"));
10391 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
10399 case token_type::literal_false:
10401 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
10408 case token_type::literal_null:
10410 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
10417 case token_type::literal_true:
10419 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
10426 case token_type::value_integer:
10428 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
10435 case token_type::value_string:
10437 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
10444 case token_type::value_unsigned:
10446 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
10453 case token_type::parse_error:
10456 return sax->parse_error(m_lexer.get_position(),
10457 m_lexer.get_token_string(),
10458 parse_error::create(101, m_lexer.get_position(),
10459 exception_message(token_type::uninitialized,
"value")));
10464 return sax->parse_error(m_lexer.get_position(),
10465 m_lexer.get_token_string(),
10466 parse_error::create(101, m_lexer.get_position(),
10467 exception_message(token_type::literal_or_value,
"value")));
10473 skip_to_state_evaluation =
false;
10477 if (states.empty())
10486 if (get_token() == token_type::value_separator)
10494 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
10496 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
10505 JSON_ASSERT(!states.empty());
10507 skip_to_state_evaluation =
true;
10511 return sax->parse_error(m_lexer.get_position(),
10512 m_lexer.get_token_string(),
10513 parse_error::create(101, m_lexer.get_position(),
10514 exception_message(token_type::end_array,
"array")));
10519 if (get_token() == token_type::value_separator)
10522 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
10524 return sax->parse_error(m_lexer.get_position(),
10525 m_lexer.get_token_string(),
10526 parse_error::create(101, m_lexer.get_position(),
10527 exception_message(token_type::value_string,
"object key")));
10530 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
10536 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
10538 return sax->parse_error(m_lexer.get_position(),
10539 m_lexer.get_token_string(),
10540 parse_error::create(101, m_lexer.get_position(),
10541 exception_message(token_type::name_separator,
"object separator")));
10550 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
10552 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
10561 JSON_ASSERT(!states.empty());
10563 skip_to_state_evaluation =
true;
10567 return sax->parse_error(m_lexer.get_position(),
10568 m_lexer.get_token_string(),
10569 parse_error::create(101, m_lexer.get_position(),
10570 exception_message(token_type::end_object,
"object")));
10576 token_type get_token()
10578 return last_token = m_lexer.scan();
10581 std::string exception_message(
const token_type expected,
const std::string& context)
10583 std::string error_msg =
"syntax error ";
10585 if (!context.empty())
10587 error_msg +=
"while parsing " + context +
" ";
10592 if (last_token == token_type::parse_error)
10594 error_msg += std::string(m_lexer.get_error_message()) +
"; last read: '" +
10595 m_lexer.get_token_string() +
"'";
10599 error_msg +=
"unexpected " + std::string(lexer_t::token_type_name(last_token));
10602 if (expected != token_type::uninitialized)
10604 error_msg +=
"; expected " + std::string(lexer_t::token_type_name(expected));
10612 const parser_callback_t<BasicJsonType> callback =
nullptr;
10614 token_type last_token = token_type::uninitialized;
10618 const bool allow_exceptions =
true;
10645 class primitive_iterator_t
10648 using difference_type = std::ptrdiff_t;
10649 static constexpr difference_type begin_value = 0;
10650 static constexpr difference_type end_value = begin_value + 1;
10652 JSON_PRIVATE_UNLESS_TESTED:
10654 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
10657 constexpr difference_type get_value() const noexcept
10663 void set_begin() noexcept
10665 m_it = begin_value;
10669 void set_end() noexcept
10675 constexpr
bool is_begin() const noexcept
10677 return m_it == begin_value;
10681 constexpr
bool is_end() const noexcept
10683 return m_it == end_value;
10686 friend constexpr
bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
10688 return lhs.m_it == rhs.m_it;
10691 friend constexpr
bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
10693 return lhs.m_it < rhs.m_it;
10696 primitive_iterator_t operator+(difference_type n) noexcept
10698 auto result = *
this;
10703 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
10705 return lhs.m_it - rhs.m_it;
10708 primitive_iterator_t& operator++() noexcept
10714 primitive_iterator_t
const operator++(
int) noexcept
10716 auto result = *
this;
10721 primitive_iterator_t& operator--() noexcept
10727 primitive_iterator_t
const operator--(
int) noexcept
10729 auto result = *
this;
10734 primitive_iterator_t& operator+=(difference_type n) noexcept
10740 primitive_iterator_t& operator-=(difference_type n) noexcept
10760 template<
typename BasicJsonType>
struct internal_iterator
10763 typename BasicJsonType::object_t::iterator object_iterator {};
10765 typename BasicJsonType::array_t::iterator array_iterator {};
10767 primitive_iterator_t primitive_iterator {};
10775 #include <iterator>
10776 #include <type_traits>
10798 template<
typename IteratorType>
class iteration_proxy;
10799 template<
typename IteratorType>
class iteration_proxy_value;
10817 template<
typename BasicJsonType>
10821 friend iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value,
typename std::remove_const<BasicJsonType>::type,
const BasicJsonType>::type>;
10822 friend BasicJsonType;
10823 friend iteration_proxy<iter_impl>;
10824 friend iteration_proxy_value<iter_impl>;
10826 using object_t =
typename BasicJsonType::object_t;
10827 using array_t =
typename BasicJsonType::array_t;
10829 static_assert(is_basic_json<
typename std::remove_const<BasicJsonType>::type>::value,
10830 "iter_impl only accepts (const) basic_json");
10839 using iterator_category = std::bidirectional_iterator_tag;
10842 using value_type =
typename BasicJsonType::value_type;
10844 using difference_type =
typename BasicJsonType::difference_type;
10846 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
10847 typename BasicJsonType::const_pointer,
10848 typename BasicJsonType::pointer>::type;
10851 typename std::conditional<std::is_const<BasicJsonType>::value,
10852 typename BasicJsonType::const_reference,
10853 typename BasicJsonType::reference>::type;
10856 iter_impl() =
default;
10864 explicit iter_impl(pointer
object) noexcept : m_object(
object)
10866 JSON_ASSERT(m_object !=
nullptr);
10868 switch (m_object->m_type)
10870 case value_t::object:
10872 m_it.object_iterator =
typename object_t::iterator();
10876 case value_t::array:
10878 m_it.array_iterator =
typename array_t::iterator();
10884 m_it.primitive_iterator = primitive_iterator_t();
10906 iter_impl(
const iter_impl<const BasicJsonType>& other) noexcept
10907 : m_object(other.m_object), m_it(other.m_it)
10916 iter_impl& operator=(
const iter_impl<const BasicJsonType>& other) noexcept
10918 m_object = other.m_object;
10928 iter_impl(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
10929 : m_object(other.m_object), m_it(other.m_it)
10938 iter_impl& operator=(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
10940 m_object = other.m_object;
10945 JSON_PRIVATE_UNLESS_TESTED:
10950 void set_begin() noexcept
10952 JSON_ASSERT(m_object !=
nullptr);
10954 switch (m_object->m_type)
10956 case value_t::object:
10958 m_it.object_iterator = m_object->m_value.object->begin();
10962 case value_t::array:
10964 m_it.array_iterator = m_object->m_value.array->begin();
10968 case value_t::null:
10971 m_it.primitive_iterator.set_end();
10977 m_it.primitive_iterator.set_begin();
10987 void set_end() noexcept
10989 JSON_ASSERT(m_object !=
nullptr);
10991 switch (m_object->m_type)
10993 case value_t::object:
10995 m_it.object_iterator = m_object->m_value.object->end();
10999 case value_t::array:
11001 m_it.array_iterator = m_object->m_value.array->end();
11007 m_it.primitive_iterator.set_end();
11018 reference operator*()
const
11020 JSON_ASSERT(m_object !=
nullptr);
11022 switch (m_object->m_type)
11024 case value_t::object:
11026 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11027 return m_it.object_iterator->second;
11030 case value_t::array:
11032 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11033 return *m_it.array_iterator;
11036 case value_t::null:
11037 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
11041 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11046 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
11055 pointer operator->()
const
11057 JSON_ASSERT(m_object !=
nullptr);
11059 switch (m_object->m_type)
11061 case value_t::object:
11063 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11064 return &(m_it.object_iterator->second);
11067 case value_t::array:
11069 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11070 return &*m_it.array_iterator;
11075 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11080 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
11089 iter_impl
const operator++(
int)
11091 auto result = *
this;
11100 iter_impl& operator++()
11102 JSON_ASSERT(m_object !=
nullptr);
11104 switch (m_object->m_type)
11106 case value_t::object:
11108 std::advance(m_it.object_iterator, 1);
11112 case value_t::array:
11114 std::advance(m_it.array_iterator, 1);
11120 ++m_it.primitive_iterator;
11132 iter_impl
const operator--(
int)
11134 auto result = *
this;
11143 iter_impl& operator--()
11145 JSON_ASSERT(m_object !=
nullptr);
11147 switch (m_object->m_type)
11149 case value_t::object:
11151 std::advance(m_it.object_iterator, -1);
11155 case value_t::array:
11157 std::advance(m_it.array_iterator, -1);
11163 --m_it.primitive_iterator;
11175 bool operator==(
const iter_impl& other)
const
11178 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11180 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
11183 JSON_ASSERT(m_object !=
nullptr);
11185 switch (m_object->m_type)
11187 case value_t::object:
11188 return (m_it.object_iterator == other.m_it.object_iterator);
11190 case value_t::array:
11191 return (m_it.array_iterator == other.m_it.array_iterator);
11194 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
11202 bool operator!=(
const iter_impl& other)
const
11204 return !operator==(other);
11211 bool operator<(
const iter_impl& other)
const
11214 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11216 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
11219 JSON_ASSERT(m_object !=
nullptr);
11221 switch (m_object->m_type)
11223 case value_t::object:
11224 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
11226 case value_t::array:
11227 return (m_it.array_iterator < other.m_it.array_iterator);
11230 return (m_it.primitive_iterator < other.m_it.primitive_iterator);
11238 bool operator<=(
const iter_impl& other)
const
11240 return !other.operator < (*this);
11247 bool operator>(
const iter_impl& other)
const
11249 return !operator<=(other);
11256 bool operator>=(
const iter_impl& other)
const
11258 return !operator<(other);
11265 iter_impl& operator+=(difference_type i)
11267 JSON_ASSERT(m_object !=
nullptr);
11269 switch (m_object->m_type)
11271 case value_t::object:
11272 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
11274 case value_t::array:
11276 std::advance(m_it.array_iterator, i);
11282 m_it.primitive_iterator += i;
11294 iter_impl& operator-=(difference_type i)
11296 return operator+=(-i);
11303 iter_impl operator+(difference_type i)
const
11305 auto result = *
this;
11314 friend iter_impl operator+(difference_type i,
const iter_impl& it)
11325 iter_impl operator-(difference_type i)
const
11327 auto result = *
this;
11336 difference_type operator-(
const iter_impl& other)
const
11338 JSON_ASSERT(m_object !=
nullptr);
11340 switch (m_object->m_type)
11342 case value_t::object:
11343 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
11345 case value_t::array:
11346 return m_it.array_iterator - other.m_it.array_iterator;
11349 return m_it.primitive_iterator - other.m_it.primitive_iterator;
11357 reference operator[](difference_type n)
const
11359 JSON_ASSERT(m_object !=
nullptr);
11361 switch (m_object->m_type)
11363 case value_t::object:
11364 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
11366 case value_t::array:
11367 return *std::next(m_it.array_iterator, n);
11369 case value_t::null:
11370 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
11374 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
11379 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
11388 const typename object_t::key_type& key()
const
11390 JSON_ASSERT(m_object !=
nullptr);
11392 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
11394 return m_it.object_iterator->first;
11397 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators"));
11404 reference value()
const
11406 return operator*();
11409 JSON_PRIVATE_UNLESS_TESTED:
11411 pointer m_object =
nullptr;
11413 internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
11424 #include <iterator>
11453 template<
typename Base>
11454 class json_reverse_iterator :
public std::reverse_iterator<Base>
11457 using difference_type = std::ptrdiff_t;
11459 using base_iterator = std::reverse_iterator<Base>;
11461 using reference =
typename Base::reference;
11464 explicit json_reverse_iterator(
const typename base_iterator::iterator_type& it) noexcept
11465 : base_iterator(it) {}
11468 explicit json_reverse_iterator(
const base_iterator& it) noexcept : base_iterator(it) {}
11471 json_reverse_iterator
const operator++(
int)
11473 return static_cast<json_reverse_iterator
>(base_iterator::operator++(1));
11477 json_reverse_iterator& operator++()
11479 return static_cast<json_reverse_iterator&
>(base_iterator::operator++());
11483 json_reverse_iterator
const operator--(
int)
11485 return static_cast<json_reverse_iterator
>(base_iterator::operator--(1));
11489 json_reverse_iterator& operator--()
11491 return static_cast<json_reverse_iterator&
>(base_iterator::operator--());
11495 json_reverse_iterator& operator+=(difference_type i)
11497 return static_cast<json_reverse_iterator&
>(base_iterator::operator+=(i));
11501 json_reverse_iterator operator+(difference_type i)
const
11503 return static_cast<json_reverse_iterator
>(base_iterator::operator+(i));
11507 json_reverse_iterator operator-(difference_type i)
const
11509 return static_cast<json_reverse_iterator
>(base_iterator::operator-(i));
11513 difference_type operator-(
const json_reverse_iterator& other)
const
11515 return base_iterator(*
this) - base_iterator(other);
11519 reference operator[](difference_type n)
const
11521 return *(this->operator+(n));
11525 auto key() const -> decltype(std::declval<Base>().key())
11527 auto it = --this->base();
11532 reference value()
const
11534 auto it = --this->base();
11535 return it.operator * ();
11546 #include <algorithm>
11563 template<
typename BasicJsonType>
11567 NLOHMANN_BASIC_JSON_TPL_DECLARATION
11593 : reference_tokens(split(s))
11612 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
11614 [](
const std::string & a,
const std::string & b)
11616 return a +
"/" + escape(b);
11621 operator std::string()
const
11644 reference_tokens.insert(reference_tokens.end(),
11645 ptr.reference_tokens.begin(),
11646 ptr.reference_tokens.end());
11690 return *
this /= std::to_string(array_idx);
11794 if (JSON_HEDLEY_UNLIKELY(
empty()))
11796 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
11799 reference_tokens.pop_back();
11818 if (JSON_HEDLEY_UNLIKELY(
empty()))
11820 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
11823 return reference_tokens.back();
11840 reference_tokens.push_back(token);
11846 reference_tokens.push_back(std::move(token));
11865 return reference_tokens.empty();
11879 static typename BasicJsonType::size_type array_index(
const std::string& s)
11881 using size_type =
typename BasicJsonType::size_type;
11884 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
11886 JSON_THROW(detail::parse_error::create(106, 0,
11887 "array index '" + s +
11888 "' must not begin with '0'"));
11892 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
11894 JSON_THROW(detail::parse_error::create(109, 0,
"array index '" + s +
"' is not a number"));
11897 std::size_t processed_chars = 0;
11898 unsigned long long res = 0;
11901 res = std::stoull(s, &processed_chars);
11903 JSON_CATCH(std::out_of_range&)
11905 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'"));
11909 if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
11911 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'"));
11916 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
11918 JSON_THROW(detail::out_of_range::create(410,
"array index " + s +
" exceeds size_type"));
11921 return static_cast<size_type
>(res);
11924 JSON_PRIVATE_UNLESS_TESTED:
11927 if (JSON_HEDLEY_UNLIKELY(
empty()))
11929 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
11933 result.reference_tokens = {reference_tokens[0]};
11946 BasicJsonType& get_and_create(BasicJsonType& j)
const
11952 for (
const auto& reference_token : reference_tokens)
11954 switch (result->type())
11956 case detail::value_t::null:
11958 if (reference_token ==
"0")
11961 result = &result->operator[](0);
11966 result = &result->operator[](reference_token);
11971 case detail::value_t::object:
11974 result = &result->operator[](reference_token);
11978 case detail::value_t::array:
11981 result = &result->operator[](array_index(reference_token));
11992 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten"));
12018 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
12020 for (
const auto& reference_token : reference_tokens)
12023 if (ptr->is_null())
12027 std::all_of(reference_token.begin(), reference_token.end(),
12028 [](
const unsigned char x)
12030 return std::isdigit(x);
12034 *ptr = (nums || reference_token ==
"-")
12035 ? detail::value_t::array
12036 : detail::value_t::object;
12039 switch (ptr->type())
12041 case detail::value_t::object:
12044 ptr = &ptr->operator[](reference_token);
12048 case detail::value_t::array:
12050 if (reference_token ==
"-")
12053 ptr = &ptr->operator[](ptr->m_value.array->size());
12058 ptr = &ptr->operator[](array_index(reference_token));
12064 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'"));
12077 BasicJsonType& get_checked(BasicJsonType* ptr)
const
12079 for (
const auto& reference_token : reference_tokens)
12081 switch (ptr->type())
12083 case detail::value_t::object:
12086 ptr = &ptr->at(reference_token);
12090 case detail::value_t::array:
12092 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12095 JSON_THROW(detail::out_of_range::create(402,
12096 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12097 ") is out of range"));
12101 ptr = &ptr->at(array_index(reference_token));
12106 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'"));
12126 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
12128 for (
const auto& reference_token : reference_tokens)
12130 switch (ptr->type())
12132 case detail::value_t::object:
12135 ptr = &ptr->operator[](reference_token);
12139 case detail::value_t::array:
12141 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12144 JSON_THROW(detail::out_of_range::create(402,
12145 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12146 ") is out of range"));
12150 ptr = &ptr->operator[](array_index(reference_token));
12155 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'"));
12168 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
12170 for (
const auto& reference_token : reference_tokens)
12172 switch (ptr->type())
12174 case detail::value_t::object:
12177 ptr = &ptr->at(reference_token);
12181 case detail::value_t::array:
12183 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12186 JSON_THROW(detail::out_of_range::create(402,
12187 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12188 ") is out of range"));
12192 ptr = &ptr->at(array_index(reference_token));
12197 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'"));
12208 bool contains(
const BasicJsonType* ptr)
const
12210 for (
const auto& reference_token : reference_tokens)
12212 switch (ptr->type())
12214 case detail::value_t::object:
12216 if (!ptr->contains(reference_token))
12222 ptr = &ptr->operator[](reference_token);
12226 case detail::value_t::array:
12228 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12233 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
12238 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
12240 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
12245 for (std::size_t i = 1; i < reference_token.size(); i++)
12247 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
12255 const auto idx = array_index(reference_token);
12256 if (idx >= ptr->size())
12262 ptr = &ptr->operator[](idx);
12288 static std::vector<std::string> split(
const std::string& reference_string)
12290 std::vector<std::string> result;
12293 if (reference_string.empty())
12299 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
12301 JSON_THROW(detail::parse_error::create(107, 1,
12302 "JSON pointer must be empty or begin with '/' - was: '" +
12303 reference_string +
"'"));
12311 std::size_t slash = reference_string.find_first_of(
'/', 1),
12318 start = (slash == std::string::npos) ? 0 : slash + 1,
12320 slash = reference_string.find_first_of(
'/', start))
12324 auto reference_token = reference_string.substr(start, slash - start);
12327 for (std::size_t pos = reference_token.find_first_of(
'~');
12328 pos != std::string::npos;
12329 pos = reference_token.find_first_of(
'~', pos + 1))
12331 JSON_ASSERT(reference_token[pos] ==
'~');
12334 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
12335 (reference_token[pos + 1] !=
'0' &&
12336 reference_token[pos + 1] !=
'1')))
12338 JSON_THROW(detail::parse_error::create(108, 0,
"escape character '~' must be followed with '0' or '1'"));
12343 unescape(reference_token);
12344 result.push_back(reference_token);
12363 static void replace_substring(std::string& s,
const std::string& f,
12364 const std::string& t)
12366 JSON_ASSERT(!f.empty());
12367 for (
auto pos = s.find(f);
12368 pos != std::string::npos;
12369 s.replace(pos, f.size(), t),
12370 pos = s.find(f, pos + t.size()))
12374 JSON_PRIVATE_UNLESS_TESTED:
12376 static std::string escape(std::string s)
12378 replace_substring(s,
"~",
"~0");
12379 replace_substring(s,
"/",
"~1");
12384 static void unescape(std::string& s)
12386 replace_substring(s,
"~1",
"/");
12387 replace_substring(s,
"~0",
"~");
12398 static void flatten(
const std::string& reference_string,
12399 const BasicJsonType& value,
12400 BasicJsonType& result)
12402 switch (value.type())
12404 case detail::value_t::array:
12406 if (value.m_value.array->empty())
12409 result[reference_string] =
nullptr;
12414 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
12416 flatten(reference_string +
"/" + std::to_string(i),
12417 value.m_value.array->operator[](i), result);
12423 case detail::value_t::object:
12425 if (value.m_value.object->empty())
12428 result[reference_string] =
nullptr;
12433 for (
const auto& element : *value.m_value.object)
12435 flatten(reference_string +
"/" + escape(element.first), element.second, result);
12444 result[reference_string] = value;
12460 static BasicJsonType
12461 unflatten(
const BasicJsonType& value)
12463 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
12465 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened"));
12468 BasicJsonType result;
12471 for (
const auto& element : *value.m_value.object)
12473 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
12475 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive"));
12482 json_pointer(element.first).get_and_create(result) = element.second;
12502 return lhs.reference_tokens == rhs.reference_tokens;
12519 return !(lhs == rhs);
12523 std::vector<std::string> reference_tokens;
12530 #include <initializer_list>
12540 template<
typename BasicJsonType>
12544 using value_type = BasicJsonType;
12546 json_ref(value_type&& value)
12547 : owned_value(std::move(value))
12548 , value_ref(&owned_value)
12552 json_ref(
const value_type& value)
12553 : value_ref(const_cast<value_type*>(&value))
12557 json_ref(std::initializer_list<json_ref> init)
12558 : owned_value(init)
12559 , value_ref(&owned_value)
12565 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
12566 json_ref(Args && ... args)
12567 : owned_value(std::forward<Args>(args)...)
12568 , value_ref(&owned_value)
12573 json_ref(json_ref&&) =
default;
12574 json_ref(
const json_ref&) =
delete;
12575 json_ref& operator=(
const json_ref&) =
delete;
12576 json_ref& operator=(json_ref&&) =
delete;
12577 ~json_ref() =
default;
12579 value_type moved_or_copied()
const
12583 return std::move(*value_ref);
12588 value_type
const& operator*()
const
12590 return *
static_cast<value_type const*
>(value_ref);
12593 value_type
const* operator->()
const
12595 return static_cast<value_type const*
>(value_ref);
12599 mutable value_type owned_value =
nullptr;
12600 value_type* value_ref =
nullptr;
12601 const bool is_rvalue =
true;
12615 #include <algorithm>
12630 #include <algorithm>
12633 #include <iterator>
12646 template<
typename CharType>
struct output_adapter_protocol
12648 virtual void write_character(CharType c) = 0;
12649 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
12650 virtual ~output_adapter_protocol() =
default;
12654 template<
typename CharType>
12655 using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
12658 template<
typename CharType>
12659 class output_vector_adapter :
public output_adapter_protocol<CharType>
12662 explicit output_vector_adapter(std::vector<CharType>& vec) noexcept
12666 void write_character(CharType c)
override
12671 JSON_HEDLEY_NON_NULL(2)
12672 void write_characters(const CharType* s, std::
size_t length)
override
12674 std::copy(s, s + length, std::back_inserter(v));
12678 std::vector<CharType>& v;
12682 template<
typename CharType>
12683 class output_stream_adapter :
public output_adapter_protocol<CharType>
12686 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
12690 void write_character(CharType c)
override
12695 JSON_HEDLEY_NON_NULL(2)
12696 void write_characters(const CharType* s, std::
size_t length)
override
12698 stream.write(s,
static_cast<std::streamsize
>(length));
12702 std::basic_ostream<CharType>& stream;
12706 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
12707 class output_string_adapter :
public output_adapter_protocol<CharType>
12710 explicit output_string_adapter(StringType& s) noexcept
12714 void write_character(CharType c)
override
12719 JSON_HEDLEY_NON_NULL(2)
12720 void write_characters(const CharType* s, std::
size_t length)
override
12722 str.append(s, length);
12729 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
12730 class output_adapter
12733 output_adapter(std::vector<CharType>& vec)
12734 : oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {}
12736 output_adapter(std::basic_ostream<CharType>& s)
12737 : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
12739 output_adapter(StringType& s)
12740 : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
12742 operator output_adapter_t<CharType>()
12748 output_adapter_t<CharType> oa =
nullptr;
12765 template<
typename BasicJsonType,
typename CharType>
12766 class binary_writer
12768 using string_t =
typename BasicJsonType::string_t;
12769 using binary_t =
typename BasicJsonType::binary_t;
12770 using number_float_t =
typename BasicJsonType::number_float_t;
12778 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter)
12787 void write_bson(
const BasicJsonType& j)
12791 case value_t::object:
12793 write_bson_object(*j.m_value.object);
12799 JSON_THROW(type_error::create(317,
"to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name())));
12807 void write_cbor(
const BasicJsonType& j)
12811 case value_t::null:
12813 oa->write_character(to_char_type(0xF6));
12817 case value_t::boolean:
12819 oa->write_character(j.m_value.boolean
12820 ? to_char_type(0xF5)
12821 : to_char_type(0xF4));
12825 case value_t::number_integer:
12827 if (j.m_value.number_integer >= 0)
12832 if (j.m_value.number_integer <= 0x17)
12834 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
12836 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
12838 oa->write_character(to_char_type(0x18));
12839 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
12841 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
12843 oa->write_character(to_char_type(0x19));
12844 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
12846 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
12848 oa->write_character(to_char_type(0x1A));
12849 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
12853 oa->write_character(to_char_type(0x1B));
12854 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
12861 const auto positive_number = -1 - j.m_value.number_integer;
12862 if (j.m_value.number_integer >= -24)
12864 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
12866 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
12868 oa->write_character(to_char_type(0x38));
12869 write_number(
static_cast<std::uint8_t
>(positive_number));
12871 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
12873 oa->write_character(to_char_type(0x39));
12874 write_number(
static_cast<std::uint16_t
>(positive_number));
12876 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
12878 oa->write_character(to_char_type(0x3A));
12879 write_number(
static_cast<std::uint32_t
>(positive_number));
12883 oa->write_character(to_char_type(0x3B));
12884 write_number(
static_cast<std::uint64_t
>(positive_number));
12890 case value_t::number_unsigned:
12892 if (j.m_value.number_unsigned <= 0x17)
12894 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
12896 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
12898 oa->write_character(to_char_type(0x18));
12899 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
12901 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
12903 oa->write_character(to_char_type(0x19));
12904 write_number(
static_cast<std::uint16_t
>(j.m_value.number_unsigned));
12906 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
12908 oa->write_character(to_char_type(0x1A));
12909 write_number(
static_cast<std::uint32_t
>(j.m_value.number_unsigned));
12913 oa->write_character(to_char_type(0x1B));
12914 write_number(
static_cast<std::uint64_t
>(j.m_value.number_unsigned));
12919 case value_t::number_float:
12921 if (std::isnan(j.m_value.number_float))
12924 oa->write_character(to_char_type(0xF9));
12925 oa->write_character(to_char_type(0x7E));
12926 oa->write_character(to_char_type(0x00));
12928 else if (std::isinf(j.m_value.number_float))
12931 oa->write_character(to_char_type(0xf9));
12932 oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
12933 oa->write_character(to_char_type(0x00));
12937 write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
12942 case value_t::string:
12945 const auto N = j.m_value.string->size();
12948 write_number(
static_cast<std::uint8_t
>(0x60 + N));
12950 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
12952 oa->write_character(to_char_type(0x78));
12953 write_number(
static_cast<std::uint8_t
>(N));
12955 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
12957 oa->write_character(to_char_type(0x79));
12958 write_number(
static_cast<std::uint16_t
>(N));
12960 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
12962 oa->write_character(to_char_type(0x7A));
12963 write_number(
static_cast<std::uint32_t
>(N));
12966 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
12968 oa->write_character(to_char_type(0x7B));
12969 write_number(
static_cast<std::uint64_t
>(N));
12974 oa->write_characters(
12975 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
12976 j.m_value.string->size());
12980 case value_t::array:
12983 const auto N = j.m_value.array->size();
12986 write_number(
static_cast<std::uint8_t
>(0x80 + N));
12988 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
12990 oa->write_character(to_char_type(0x98));
12991 write_number(
static_cast<std::uint8_t
>(N));
12993 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
12995 oa->write_character(to_char_type(0x99));
12996 write_number(
static_cast<std::uint16_t
>(N));
12998 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13000 oa->write_character(to_char_type(0x9A));
13001 write_number(
static_cast<std::uint32_t
>(N));
13004 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13006 oa->write_character(to_char_type(0x9B));
13007 write_number(
static_cast<std::uint64_t
>(N));
13012 for (
const auto& el : *j.m_value.array)
13019 case value_t::binary:
13021 if (j.m_value.binary->has_subtype())
13023 write_number(
static_cast<std::uint8_t
>(0xd8));
13024 write_number(j.m_value.binary->subtype());
13028 const auto N = j.m_value.binary->size();
13031 write_number(
static_cast<std::uint8_t
>(0x40 + N));
13033 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13035 oa->write_character(to_char_type(0x58));
13036 write_number(
static_cast<std::uint8_t
>(N));
13038 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13040 oa->write_character(to_char_type(0x59));
13041 write_number(
static_cast<std::uint16_t
>(N));
13043 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13045 oa->write_character(to_char_type(0x5A));
13046 write_number(
static_cast<std::uint32_t
>(N));
13049 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13051 oa->write_character(to_char_type(0x5B));
13052 write_number(
static_cast<std::uint64_t
>(N));
13057 oa->write_characters(
13058 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13064 case value_t::object:
13067 const auto N = j.m_value.object->size();
13070 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
13072 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13074 oa->write_character(to_char_type(0xB8));
13075 write_number(
static_cast<std::uint8_t
>(N));
13077 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13079 oa->write_character(to_char_type(0xB9));
13080 write_number(
static_cast<std::uint16_t
>(N));
13082 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13084 oa->write_character(to_char_type(0xBA));
13085 write_number(
static_cast<std::uint32_t
>(N));
13088 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13090 oa->write_character(to_char_type(0xBB));
13091 write_number(
static_cast<std::uint64_t
>(N));
13096 for (
const auto& el : *j.m_value.object)
13098 write_cbor(el.first);
13099 write_cbor(el.second);
13112 void write_msgpack(
const BasicJsonType& j)
13116 case value_t::null:
13118 oa->write_character(to_char_type(0xC0));
13122 case value_t::boolean:
13124 oa->write_character(j.m_value.boolean
13125 ? to_char_type(0xC3)
13126 : to_char_type(0xC2));
13130 case value_t::number_integer:
13132 if (j.m_value.number_integer >= 0)
13137 if (j.m_value.number_unsigned < 128)
13140 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13142 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13145 oa->write_character(to_char_type(0xCC));
13146 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13148 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13151 oa->write_character(to_char_type(0xCD));
13152 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13154 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13157 oa->write_character(to_char_type(0xCE));
13158 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13160 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13163 oa->write_character(to_char_type(0xCF));
13164 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13169 if (j.m_value.number_integer >= -32)
13172 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
13174 else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
13175 j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
13178 oa->write_character(to_char_type(0xD0));
13179 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
13181 else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
13182 j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
13185 oa->write_character(to_char_type(0xD1));
13186 write_number(
static_cast<std::int16_t
>(j.m_value.number_integer));
13188 else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
13189 j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
13192 oa->write_character(to_char_type(0xD2));
13193 write_number(
static_cast<std::int32_t
>(j.m_value.number_integer));
13195 else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
13196 j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
13199 oa->write_character(to_char_type(0xD3));
13200 write_number(
static_cast<std::int64_t
>(j.m_value.number_integer));
13206 case value_t::number_unsigned:
13208 if (j.m_value.number_unsigned < 128)
13211 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13213 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13216 oa->write_character(to_char_type(0xCC));
13217 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13219 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13222 oa->write_character(to_char_type(0xCD));
13223 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13225 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13228 oa->write_character(to_char_type(0xCE));
13229 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13231 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13234 oa->write_character(to_char_type(0xCF));
13235 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13240 case value_t::number_float:
13242 write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
13246 case value_t::string:
13249 const auto N = j.m_value.string->size();
13253 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
13255 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13258 oa->write_character(to_char_type(0xD9));
13259 write_number(
static_cast<std::uint8_t
>(N));
13261 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13264 oa->write_character(to_char_type(0xDA));
13265 write_number(
static_cast<std::uint16_t
>(N));
13267 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13270 oa->write_character(to_char_type(0xDB));
13271 write_number(
static_cast<std::uint32_t
>(N));
13275 oa->write_characters(
13276 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13277 j.m_value.string->size());
13281 case value_t::array:
13284 const auto N = j.m_value.array->size();
13288 write_number(
static_cast<std::uint8_t
>(0x90 | N));
13290 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13293 oa->write_character(to_char_type(0xDC));
13294 write_number(
static_cast<std::uint16_t
>(N));
13296 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13299 oa->write_character(to_char_type(0xDD));
13300 write_number(
static_cast<std::uint32_t
>(N));
13304 for (
const auto& el : *j.m_value.array)
13311 case value_t::binary:
13315 const bool use_ext = j.m_value.binary->has_subtype();
13318 const auto N = j.m_value.binary->size();
13319 if (N <= (std::numeric_limits<std::uint8_t>::max)())
13321 std::uint8_t output_type{};
13328 output_type = 0xD4;
13331 output_type = 0xD5;
13334 output_type = 0xD6;
13337 output_type = 0xD7;
13340 output_type = 0xD8;
13343 output_type = 0xC7;
13351 output_type = 0xC4;
13355 oa->write_character(to_char_type(output_type));
13358 write_number(
static_cast<std::uint8_t
>(N));
13361 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13363 std::uint8_t output_type = use_ext
13367 oa->write_character(to_char_type(output_type));
13368 write_number(
static_cast<std::uint16_t
>(N));
13370 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13372 std::uint8_t output_type = use_ext
13376 oa->write_character(to_char_type(output_type));
13377 write_number(
static_cast<std::uint32_t
>(N));
13383 write_number(
static_cast<std::int8_t
>(j.m_value.binary->subtype()));
13387 oa->write_characters(
13388 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13394 case value_t::object:
13397 const auto N = j.m_value.object->size();
13401 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
13403 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13406 oa->write_character(to_char_type(0xDE));
13407 write_number(
static_cast<std::uint16_t
>(N));
13409 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13412 oa->write_character(to_char_type(0xDF));
13413 write_number(
static_cast<std::uint32_t
>(N));
13417 for (
const auto& el : *j.m_value.object)
13419 write_msgpack(el.first);
13420 write_msgpack(el.second);
13436 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
13437 const bool use_type,
const bool add_prefix =
true)
13441 case value_t::null:
13445 oa->write_character(to_char_type(
'Z'));
13450 case value_t::boolean:
13454 oa->write_character(j.m_value.boolean
13455 ? to_char_type(
'T')
13456 : to_char_type(
'F'));
13461 case value_t::number_integer:
13463 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
13467 case value_t::number_unsigned:
13469 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
13473 case value_t::number_float:
13475 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
13479 case value_t::string:
13483 oa->write_character(to_char_type(
'S'));
13485 write_number_with_ubjson_prefix(j.m_value.string->size(),
true);
13486 oa->write_characters(
13487 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13488 j.m_value.string->size());
13492 case value_t::array:
13496 oa->write_character(to_char_type(
'['));
13499 bool prefix_required =
true;
13500 if (use_type && !j.m_value.array->empty())
13502 JSON_ASSERT(use_count);
13503 const CharType first_prefix = ubjson_prefix(j.front());
13504 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
13505 [
this, first_prefix](
const BasicJsonType & v)
13507 return ubjson_prefix(v) == first_prefix;
13512 prefix_required =
false;
13513 oa->write_character(to_char_type(
'$'));
13514 oa->write_character(first_prefix);
13520 oa->write_character(to_char_type(
'#'));
13521 write_number_with_ubjson_prefix(j.m_value.array->size(),
true);
13524 for (
const auto& el : *j.m_value.array)
13526 write_ubjson(el, use_count, use_type, prefix_required);
13531 oa->write_character(to_char_type(
']'));
13537 case value_t::binary:
13541 oa->write_character(to_char_type(
'['));
13544 if (use_type && !j.m_value.binary->empty())
13546 JSON_ASSERT(use_count);
13547 oa->write_character(to_char_type(
'$'));
13548 oa->write_character(
'U');
13553 oa->write_character(to_char_type(
'#'));
13554 write_number_with_ubjson_prefix(j.m_value.binary->size(),
true);
13559 oa->write_characters(
13560 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13561 j.m_value.binary->size());
13565 for (
size_t i = 0; i < j.m_value.binary->size(); ++i)
13567 oa->write_character(to_char_type(
'U'));
13568 oa->write_character(j.m_value.binary->data()[i]);
13574 oa->write_character(to_char_type(
']'));
13580 case value_t::object:
13584 oa->write_character(to_char_type(
'{'));
13587 bool prefix_required =
true;
13588 if (use_type && !j.m_value.object->empty())
13590 JSON_ASSERT(use_count);
13591 const CharType first_prefix = ubjson_prefix(j.front());
13592 const bool same_prefix = std::all_of(j.begin(), j.end(),
13593 [
this, first_prefix](
const BasicJsonType & v)
13595 return ubjson_prefix(v) == first_prefix;
13600 prefix_required =
false;
13601 oa->write_character(to_char_type(
'$'));
13602 oa->write_character(first_prefix);
13608 oa->write_character(to_char_type(
'#'));
13609 write_number_with_ubjson_prefix(j.m_value.object->size(),
true);
13612 for (
const auto& el : *j.m_value.object)
13614 write_number_with_ubjson_prefix(el.first.size(),
true);
13615 oa->write_characters(
13616 reinterpret_cast<const CharType*
>(el.first.c_str()),
13618 write_ubjson(el.second, use_count, use_type, prefix_required);
13623 oa->write_character(to_char_type(
'}'));
13643 static std::size_t calc_bson_entry_header_size(
const string_t& name)
13645 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
13646 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
13648 JSON_THROW(out_of_range::create(409,
13649 "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) +
")"));
13652 return 1ul + name.size() + 1u;
13658 void write_bson_entry_header(
const string_t& name,
13659 const std::uint8_t element_type)
13661 oa->write_character(to_char_type(element_type));
13662 oa->write_characters(
13663 reinterpret_cast<const CharType*
>(name.c_str()),
13670 void write_bson_boolean(
const string_t& name,
13673 write_bson_entry_header(name, 0x08);
13674 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
13680 void write_bson_double(
const string_t& name,
13681 const double value)
13683 write_bson_entry_header(name, 0x01);
13684 write_number<double, true>(value);
13690 static std::size_t calc_bson_string_size(
const string_t& value)
13692 return sizeof(std::int32_t) + value.size() + 1ul;
13698 void write_bson_string(
const string_t& name,
13699 const string_t& value)
13701 write_bson_entry_header(name, 0x02);
13703 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size() + 1ul));
13704 oa->write_characters(
13705 reinterpret_cast<const CharType*
>(value.c_str()),
13712 void write_bson_null(
const string_t& name)
13714 write_bson_entry_header(name, 0x0A);
13720 static std::size_t calc_bson_integer_size(
const std::int64_t value)
13722 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
13723 ?
sizeof(std::int32_t)
13724 :
sizeof(std::int64_t);
13730 void write_bson_integer(
const string_t& name,
13731 const std::int64_t value)
13733 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
13735 write_bson_entry_header(name, 0x10);
13736 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value));
13740 write_bson_entry_header(name, 0x12);
13741 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(value));
13748 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value) noexcept
13750 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
13751 ?
sizeof(std::int32_t)
13752 :
sizeof(std::int64_t);
13758 void write_bson_unsigned(
const string_t& name,
13759 const std::uint64_t value)
13761 if (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
13763 write_bson_entry_header(name, 0x10 );
13764 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value));
13766 else if (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
13768 write_bson_entry_header(name, 0x12 );
13769 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(value));
13773 JSON_THROW(out_of_range::create(407,
"integer number " + std::to_string(value) +
" cannot be represented by BSON as it does not fit int64"));
13780 void write_bson_object_entry(
const string_t& name,
13781 const typename BasicJsonType::object_t& value)
13783 write_bson_entry_header(name, 0x03);
13784 write_bson_object(value);
13790 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
13792 std::size_t array_index = 0ul;
13794 const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), std::size_t(0), [&array_index](std::size_t result,
const typename BasicJsonType::array_t::value_type & el)
13796 return result + calc_bson_element_size(std::to_string(array_index++), el);
13799 return sizeof(std::int32_t) + embedded_document_size + 1ul;
13805 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
13807 return sizeof(std::int32_t) + value.size() + 1ul;
13813 void write_bson_array(
const string_t& name,
13814 const typename BasicJsonType::array_t& value)
13816 write_bson_entry_header(name, 0x04);
13817 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_array_size(value)));
13819 std::size_t array_index = 0ul;
13821 for (
const auto& el : value)
13823 write_bson_element(std::to_string(array_index++), el);
13826 oa->write_character(to_char_type(0x00));
13832 void write_bson_binary(
const string_t& name,
13833 const binary_t& value)
13835 write_bson_entry_header(name, 0x05);
13837 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size()));
13838 write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00));
13840 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
13847 static std::size_t calc_bson_element_size(
const string_t& name,
13848 const BasicJsonType& j)
13850 const auto header_size = calc_bson_entry_header_size(name);
13853 case value_t::object:
13854 return header_size + calc_bson_object_size(*j.m_value.object);
13856 case value_t::array:
13857 return header_size + calc_bson_array_size(*j.m_value.array);
13859 case value_t::binary:
13860 return header_size + calc_bson_binary_size(*j.m_value.binary);
13862 case value_t::boolean:
13863 return header_size + 1ul;
13865 case value_t::number_float:
13866 return header_size + 8ul;
13868 case value_t::number_integer:
13869 return header_size + calc_bson_integer_size(j.m_value.number_integer);
13871 case value_t::number_unsigned:
13872 return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
13874 case value_t::string:
13875 return header_size + calc_bson_string_size(*j.m_value.string);
13877 case value_t::null:
13878 return header_size + 0ul;
13882 JSON_ASSERT(
false);
13895 void write_bson_element(
const string_t& name,
13896 const BasicJsonType& j)
13900 case value_t::object:
13901 return write_bson_object_entry(name, *j.m_value.object);
13903 case value_t::array:
13904 return write_bson_array(name, *j.m_value.array);
13906 case value_t::binary:
13907 return write_bson_binary(name, *j.m_value.binary);
13909 case value_t::boolean:
13910 return write_bson_boolean(name, j.m_value.boolean);
13912 case value_t::number_float:
13913 return write_bson_double(name, j.m_value.number_float);
13915 case value_t::number_integer:
13916 return write_bson_integer(name, j.m_value.number_integer);
13918 case value_t::number_unsigned:
13919 return write_bson_unsigned(name, j.m_value.number_unsigned);
13921 case value_t::string:
13922 return write_bson_string(name, *j.m_value.string);
13924 case value_t::null:
13925 return write_bson_null(name);
13929 JSON_ASSERT(
false);
13941 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
13943 std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
13944 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
13946 return result += calc_bson_element_size(el.first, el.second);
13949 return sizeof(std::int32_t) + document_size + 1ul;
13956 void write_bson_object(
const typename BasicJsonType::object_t& value)
13958 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_object_size(value)));
13960 for (
const auto& el : value)
13962 write_bson_element(el.first, el.second);
13965 oa->write_character(to_char_type(0x00));
13972 static constexpr CharType get_cbor_float_prefix(
float )
13974 return to_char_type(0xFA);
13977 static constexpr CharType get_cbor_float_prefix(
double )
13979 return to_char_type(0xFB);
13986 static constexpr CharType get_msgpack_float_prefix(
float )
13988 return to_char_type(0xCA);
13991 static constexpr CharType get_msgpack_float_prefix(
double )
13993 return to_char_type(0xCB);
14001 template<
typename NumberType,
typename std::enable_if<
14002 std::is_floating_point<NumberType>::value,
int>::type = 0>
14003 void write_number_with_ubjson_prefix(
const NumberType n,
14004 const bool add_prefix)
14008 oa->write_character(get_ubjson_float_prefix(n));
14014 template<
typename NumberType,
typename std::enable_if<
14015 std::is_unsigned<NumberType>::value,
int>::type = 0>
14016 void write_number_with_ubjson_prefix(
const NumberType n,
14017 const bool add_prefix)
14019 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
14023 oa->write_character(to_char_type(
'i'));
14025 write_number(
static_cast<std::uint8_t
>(n));
14027 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
14031 oa->write_character(to_char_type(
'U'));
14033 write_number(
static_cast<std::uint8_t
>(n));
14035 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
14039 oa->write_character(to_char_type(
'I'));
14041 write_number(
static_cast<std::int16_t
>(n));
14043 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14047 oa->write_character(to_char_type(
'l'));
14049 write_number(
static_cast<std::int32_t
>(n));
14051 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14055 oa->write_character(to_char_type(
'L'));
14057 write_number(
static_cast<std::int64_t
>(n));
14063 oa->write_character(to_char_type(
'H'));
14066 const auto number = BasicJsonType(n).dump();
14067 write_number_with_ubjson_prefix(number.size(),
true);
14068 for (std::size_t i = 0; i < number.size(); ++i)
14070 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
14076 template <
typename NumberType,
typename std::enable_if <
14077 std::is_signed<NumberType>::value&&
14078 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
14079 void write_number_with_ubjson_prefix(
const NumberType n,
14080 const bool add_prefix)
14082 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
14086 oa->write_character(to_char_type(
'i'));
14088 write_number(
static_cast<std::int8_t
>(n));
14090 else if (
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::max)()))
14094 oa->write_character(to_char_type(
'U'));
14096 write_number(
static_cast<std::uint8_t
>(n));
14098 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
14102 oa->write_character(to_char_type(
'I'));
14104 write_number(
static_cast<std::int16_t
>(n));
14106 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
14110 oa->write_character(to_char_type(
'l'));
14112 write_number(
static_cast<std::int32_t
>(n));
14114 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
14118 oa->write_character(to_char_type(
'L'));
14120 write_number(
static_cast<std::int64_t
>(n));
14127 oa->write_character(to_char_type(
'H'));
14130 const auto number = BasicJsonType(n).dump();
14131 write_number_with_ubjson_prefix(number.size(),
true);
14132 for (std::size_t i = 0; i < number.size(); ++i)
14134 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
14143 CharType ubjson_prefix(
const BasicJsonType& j)
const noexcept
14147 case value_t::null:
14150 case value_t::boolean:
14151 return j.m_value.boolean ?
'T' :
'F';
14153 case value_t::number_integer:
14155 if ((std::numeric_limits<std::int8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
14159 if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
14163 if ((std::numeric_limits<std::int16_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
14167 if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
14171 if ((std::numeric_limits<std::int64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
14179 case value_t::number_unsigned:
14181 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
14185 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
14189 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
14193 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14197 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14205 case value_t::number_float:
14206 return get_ubjson_float_prefix(j.m_value.number_float);
14208 case value_t::string:
14211 case value_t::array:
14212 case value_t::binary:
14215 case value_t::object:
14223 static constexpr CharType get_ubjson_float_prefix(
float )
14228 static constexpr CharType get_ubjson_float_prefix(
double )
14248 template<
typename NumberType,
bool OutputIsLittleEndian = false>
14249 void write_number(
const NumberType n)
14252 std::array<CharType,
sizeof(NumberType)> vec;
14253 std::memcpy(vec.data(), &n,
sizeof(NumberType));
14256 if (is_little_endian != OutputIsLittleEndian)
14259 std::reverse(vec.begin(), vec.end());
14262 oa->write_characters(vec.data(),
sizeof(NumberType));
14265 void write_compact_float(
const number_float_t n, detail::input_format_t format)
14267 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
14268 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
14269 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
14271 oa->write_character(format == detail::input_format_t::cbor
14272 ? get_cbor_float_prefix(
static_cast<float>(n))
14273 : get_msgpack_float_prefix(
static_cast<float>(n)));
14274 write_number(
static_cast<float>(n));
14278 oa->write_character(format == detail::input_format_t::cbor
14279 ? get_cbor_float_prefix(n)
14280 : get_msgpack_float_prefix(n));
14290 template <
typename C = CharType,
14291 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
14292 static constexpr CharType to_char_type(std::uint8_t x) noexcept
14294 return *
reinterpret_cast<char*
>(&x);
14297 template <
typename C = CharType,
14298 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
14299 static CharType to_char_type(std::uint8_t x) noexcept
14301 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
14302 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
14304 std::memcpy(&result, &x,
sizeof(x));
14308 template<
typename C = CharType,
14309 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
14310 static constexpr CharType to_char_type(std::uint8_t x) noexcept
14315 template <
typename InputCharType,
typename C = CharType,
14317 std::is_signed<C>::value &&
14318 std::is_signed<char>::value &&
14319 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
14321 static constexpr CharType to_char_type(InputCharType x) noexcept
14328 const bool is_little_endian = little_endianess();
14331 output_adapter_t<CharType> oa =
nullptr;
14341 #include <algorithm>
14350 #include <type_traits>
14361 #include <type_traits>
14390 namespace dtoa_impl
14393 template<
typename Target,
typename Source>
14394 Target reinterpret_bits(
const Source source)
14396 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
14399 std::memcpy(&target, &source,
sizeof(Source));
14405 static constexpr
int kPrecision = 64;
14407 std::uint64_t f = 0;
14410 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
14416 static diyfp sub(
const diyfp& x,
const diyfp& y) noexcept
14418 JSON_ASSERT(x.e == y.e);
14419 JSON_ASSERT(x.f >= y.f);
14421 return {x.f - y.f, x.e};
14428 static diyfp mul(
const diyfp& x,
const diyfp& y) noexcept
14430 static_assert(kPrecision == 64,
"internal error");
14455 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
14456 const std::uint64_t u_hi = x.f >> 32u;
14457 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
14458 const std::uint64_t v_hi = y.f >> 32u;
14460 const std::uint64_t p0 = u_lo * v_lo;
14461 const std::uint64_t p1 = u_lo * v_hi;
14462 const std::uint64_t p2 = u_hi * v_lo;
14463 const std::uint64_t p3 = u_hi * v_hi;
14465 const std::uint64_t p0_hi = p0 >> 32u;
14466 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
14467 const std::uint64_t p1_hi = p1 >> 32u;
14468 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
14469 const std::uint64_t p2_hi = p2 >> 32u;
14471 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
14482 Q += std::uint64_t{1} << (64u - 32u - 1u);
14484 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
14486 return {h, x.e + y.e + 64};
14493 static diyfp normalize(diyfp x) noexcept
14495 JSON_ASSERT(x.f != 0);
14497 while ((x.f >> 63u) == 0)
14510 static diyfp normalize_to(
const diyfp& x,
const int target_exponent) noexcept
14512 const int delta = x.e - target_exponent;
14514 JSON_ASSERT(delta >= 0);
14515 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
14517 return {x.f << delta, target_exponent};
14534 template<
typename FloatType>
14535 boundaries compute_boundaries(FloatType value)
14537 JSON_ASSERT(std::isfinite(value));
14538 JSON_ASSERT(value > 0);
14547 static_assert(std::numeric_limits<FloatType>::is_iec559,
14548 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
14550 constexpr
int kPrecision = std::numeric_limits<FloatType>::digits;
14551 constexpr
int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
14552 constexpr
int kMinExp = 1 - kBias;
14553 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
14555 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
14557 const std::uint64_t bits = reinterpret_bits<bits_type>(value);
14558 const std::uint64_t E = bits >> (kPrecision - 1);
14559 const std::uint64_t F = bits & (kHiddenBit - 1);
14561 const bool is_denormal = E == 0;
14562 const diyfp v = is_denormal
14563 ? diyfp(F, kMinExp)
14564 : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
14587 const bool lower_boundary_is_closer = F == 0 && E > 1;
14588 const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
14589 const diyfp m_minus = lower_boundary_is_closer
14590 ? diyfp(4 * v.f - 1, v.e - 2)
14591 : diyfp(2 * v.f - 1, v.e - 1);
14594 const diyfp w_plus = diyfp::normalize(m_plus);
14597 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
14599 return {diyfp::normalize(v), w_minus, w_plus};
14657 constexpr
int kAlpha = -60;
14658 constexpr
int kGamma = -32;
14660 struct cached_power
14674 inline cached_power get_cached_power_for_binary_exponent(
int e)
14726 constexpr
int kCachedPowersMinDecExp = -300;
14727 constexpr
int kCachedPowersDecStep = 8;
14729 static constexpr std::array<cached_power, 79> kCachedPowers =
14732 { 0xAB70FE17C79AC6CA, -1060, -300 },
14733 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
14734 { 0xBE5691EF416BD60C, -1007, -284 },
14735 { 0x8DD01FAD907FFC3C, -980, -276 },
14736 { 0xD3515C2831559A83, -954, -268 },
14737 { 0x9D71AC8FADA6C9B5, -927, -260 },
14738 { 0xEA9C227723EE8BCB, -901, -252 },
14739 { 0xAECC49914078536D, -874, -244 },
14740 { 0x823C12795DB6CE57, -847, -236 },
14741 { 0xC21094364DFB5637, -821, -228 },
14742 { 0x9096EA6F3848984F, -794, -220 },
14743 { 0xD77485CB25823AC7, -768, -212 },
14744 { 0xA086CFCD97BF97F4, -741, -204 },
14745 { 0xEF340A98172AACE5, -715, -196 },
14746 { 0xB23867FB2A35B28E, -688, -188 },
14747 { 0x84C8D4DFD2C63F3B, -661, -180 },
14748 { 0xC5DD44271AD3CDBA, -635, -172 },
14749 { 0x936B9FCEBB25C996, -608, -164 },
14750 { 0xDBAC6C247D62A584, -582, -156 },
14751 { 0xA3AB66580D5FDAF6, -555, -148 },
14752 { 0xF3E2F893DEC3F126, -529, -140 },
14753 { 0xB5B5ADA8AAFF80B8, -502, -132 },
14754 { 0x87625F056C7C4A8B, -475, -124 },
14755 { 0xC9BCFF6034C13053, -449, -116 },
14756 { 0x964E858C91BA2655, -422, -108 },
14757 { 0xDFF9772470297EBD, -396, -100 },
14758 { 0xA6DFBD9FB8E5B88F, -369, -92 },
14759 { 0xF8A95FCF88747D94, -343, -84 },
14760 { 0xB94470938FA89BCF, -316, -76 },
14761 { 0x8A08F0F8BF0F156B, -289, -68 },
14762 { 0xCDB02555653131B6, -263, -60 },
14763 { 0x993FE2C6D07B7FAC, -236, -52 },
14764 { 0xE45C10C42A2B3B06, -210, -44 },
14765 { 0xAA242499697392D3, -183, -36 },
14766 { 0xFD87B5F28300CA0E, -157, -28 },
14767 { 0xBCE5086492111AEB, -130, -20 },
14768 { 0x8CBCCC096F5088CC, -103, -12 },
14769 { 0xD1B71758E219652C, -77, -4 },
14770 { 0x9C40000000000000, -50, 4 },
14771 { 0xE8D4A51000000000, -24, 12 },
14772 { 0xAD78EBC5AC620000, 3, 20 },
14773 { 0x813F3978F8940984, 30, 28 },
14774 { 0xC097CE7BC90715B3, 56, 36 },
14775 { 0x8F7E32CE7BEA5C70, 83, 44 },
14776 { 0xD5D238A4ABE98068, 109, 52 },
14777 { 0x9F4F2726179A2245, 136, 60 },
14778 { 0xED63A231D4C4FB27, 162, 68 },
14779 { 0xB0DE65388CC8ADA8, 189, 76 },
14780 { 0x83C7088E1AAB65DB, 216, 84 },
14781 { 0xC45D1DF942711D9A, 242, 92 },
14782 { 0x924D692CA61BE758, 269, 100 },
14783 { 0xDA01EE641A708DEA, 295, 108 },
14784 { 0xA26DA3999AEF774A, 322, 116 },
14785 { 0xF209787BB47D6B85, 348, 124 },
14786 { 0xB454E4A179DD1877, 375, 132 },
14787 { 0x865B86925B9BC5C2, 402, 140 },
14788 { 0xC83553C5C8965D3D, 428, 148 },
14789 { 0x952AB45CFA97A0B3, 455, 156 },
14790 { 0xDE469FBD99A05FE3, 481, 164 },
14791 { 0xA59BC234DB398C25, 508, 172 },
14792 { 0xF6C69A72A3989F5C, 534, 180 },
14793 { 0xB7DCBF5354E9BECE, 561, 188 },
14794 { 0x88FCF317F22241E2, 588, 196 },
14795 { 0xCC20CE9BD35C78A5, 614, 204 },
14796 { 0x98165AF37B2153DF, 641, 212 },
14797 { 0xE2A0B5DC971F303A, 667, 220 },
14798 { 0xA8D9D1535CE3B396, 694, 228 },
14799 { 0xFB9B7CD9A4A7443C, 720, 236 },
14800 { 0xBB764C4CA7A44410, 747, 244 },
14801 { 0x8BAB8EEFB6409C1A, 774, 252 },
14802 { 0xD01FEF10A657842C, 800, 260 },
14803 { 0x9B10A4E5E9913129, 827, 268 },
14804 { 0xE7109BFBA19C0C9D, 853, 276 },
14805 { 0xAC2820D9623BF429, 880, 284 },
14806 { 0x80444B5E7AA7CF85, 907, 292 },
14807 { 0xBF21E44003ACDD2D, 933, 300 },
14808 { 0x8E679C2F5E44FF8F, 960, 308 },
14809 { 0xD433179D9C8CB841, 986, 316 },
14810 { 0x9E19DB92B4E31BA9, 1013, 324 },
14818 JSON_ASSERT(e >= -1500);
14819 JSON_ASSERT(e <= 1500);
14820 const int f = kAlpha - e - 1;
14821 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
14823 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
14824 JSON_ASSERT(index >= 0);
14825 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
14827 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
14828 JSON_ASSERT(kAlpha <= cached.e + e + 64);
14829 JSON_ASSERT(kGamma >= cached.e + e + 64);
14838 inline int find_largest_pow10(
const std::uint32_t n, std::uint32_t& pow10)
14841 if (n >= 1000000000)
14843 pow10 = 1000000000;
14847 else if (n >= 100000000)
14852 else if (n >= 10000000)
14857 else if (n >= 1000000)
14862 else if (n >= 100000)
14867 else if (n >= 10000)
14872 else if (n >= 1000)
14894 inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
14895 std::uint64_t rest, std::uint64_t ten_k)
14897 JSON_ASSERT(len >= 1);
14898 JSON_ASSERT(dist <= delta);
14899 JSON_ASSERT(rest <= delta);
14900 JSON_ASSERT(ten_k > 0);
14922 && delta - rest >= ten_k
14923 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
14925 JSON_ASSERT(buf[len - 1] !=
'0');
14935 inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
14936 diyfp M_minus, diyfp w, diyfp M_plus)
14938 static_assert(kAlpha >= -60,
"internal error");
14939 static_assert(kGamma <= -32,
"internal error");
14953 JSON_ASSERT(M_plus.e >= kAlpha);
14954 JSON_ASSERT(M_plus.e <= kGamma);
14956 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
14957 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
14966 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
14968 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
14969 std::uint64_t p2 = M_plus.f & (one.f - 1);
14975 JSON_ASSERT(p1 > 0);
14977 std::uint32_t pow10;
14978 const int k = find_largest_pow10(p1, pow10);
15005 const std::uint32_t d = p1 / pow10;
15006 const std::uint32_t r = p1 % pow10;
15011 JSON_ASSERT(d <= 9);
15012 buffer[length++] =
static_cast<char>(
'0' + d);
15031 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
15036 decimal_exponent += n;
15047 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
15048 grisu2_round(buffer, length, dist, delta, rest, ten_n);
15098 JSON_ASSERT(p2 > delta);
15109 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
15111 const std::uint64_t d = p2 >> -one.e;
15112 const std::uint64_t r = p2 & (one.f - 1);
15118 JSON_ASSERT(d <= 9);
15119 buffer[length++] =
static_cast<char>(
'0' + d);
15144 decimal_exponent -= m;
15152 const std::uint64_t ten_m = one.f;
15153 grisu2_round(buffer, length, dist, delta, p2, ten_m);
15175 JSON_HEDLEY_NON_NULL(1)
15176 inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
15177 diyfp m_minus, diyfp v, diyfp m_plus)
15179 JSON_ASSERT(m_plus.e == m_minus.e);
15180 JSON_ASSERT(m_plus.e == v.e);
15191 const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
15193 const diyfp c_minus_k(cached.f, cached.e);
15196 const diyfp w = diyfp::mul(v, c_minus_k);
15197 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
15198 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
15221 const diyfp M_minus(w_minus.f + 1, w_minus.e);
15222 const diyfp M_plus (w_plus.f - 1, w_plus.e );
15224 decimal_exponent = -cached.k;
15226 grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
15234 template<
typename FloatType>
15235 JSON_HEDLEY_NON_NULL(1)
15236 void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
15238 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
15239 "internal error: not enough precision");
15241 JSON_ASSERT(std::isfinite(value));
15242 JSON_ASSERT(value > 0);
15261 const boundaries w = compute_boundaries(
static_cast<double>(value));
15263 const boundaries w = compute_boundaries(value);
15266 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
15274 JSON_HEDLEY_NON_NULL(1)
15276 inline
char* append_exponent(
char* buf,
int e)
15278 JSON_ASSERT(e > -1000);
15279 JSON_ASSERT(e < 1000);
15291 auto k =
static_cast<std::uint32_t
>(e);
15297 *buf++ =
static_cast<char>(
'0' + k);
15301 *buf++ =
static_cast<char>(
'0' + k / 10);
15303 *buf++ =
static_cast<char>(
'0' + k);
15307 *buf++ =
static_cast<char>(
'0' + k / 100);
15309 *buf++ =
static_cast<char>(
'0' + k / 10);
15311 *buf++ =
static_cast<char>(
'0' + k);
15326 JSON_HEDLEY_NON_NULL(1)
15328 inline
char* format_buffer(
char* buf,
int len,
int decimal_exponent,
15329 int min_exp,
int max_exp)
15331 JSON_ASSERT(min_exp < 0);
15332 JSON_ASSERT(max_exp > 0);
15335 const int n = len + decimal_exponent;
15341 if (k <= n && n <= max_exp)
15346 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
15350 return buf + (
static_cast<size_t>(n) + 2);
15353 if (0 < n && n <= max_exp)
15358 JSON_ASSERT(k > n);
15360 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
15362 return buf + (
static_cast<size_t>(k) + 1U);
15365 if (min_exp < n && n <= 0)
15370 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
15373 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
15374 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
15389 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
15391 buf += 1 +
static_cast<size_t>(k);
15395 return append_exponent(buf, n - 1);
15410 template<
typename FloatType>
15411 JSON_HEDLEY_NON_NULL(1, 2)
15413 char* to_chars(
char* first, const
char* last, FloatType value)
15415 static_cast<void>(last);
15416 JSON_ASSERT(std::isfinite(value));
15419 if (std::signbit(value))
15434 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
15441 int decimal_exponent = 0;
15442 dtoa_impl::grisu2(first, len, decimal_exponent, value);
15444 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
15447 constexpr
int kMinExp = -4;
15449 constexpr
int kMaxExp = std::numeric_limits<FloatType>::digits10;
15451 JSON_ASSERT(last - first >= kMaxExp + 2);
15452 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
15453 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
15455 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
15483 enum class error_handler_t
15490 template<
typename BasicJsonType>
15493 using string_t =
typename BasicJsonType::string_t;
15494 using number_float_t =
typename BasicJsonType::number_float_t;
15495 using number_integer_t =
typename BasicJsonType::number_integer_t;
15496 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
15497 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
15498 static constexpr std::uint8_t UTF8_ACCEPT = 0;
15499 static constexpr std::uint8_t UTF8_REJECT = 1;
15507 serializer(output_adapter_t<char> s,
const char ichar,
15508 error_handler_t error_handler_ = error_handler_t::strict)
15510 , loc(std::localeconv())
15511 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
15512 , decimal_point(loc->decimal_point == nullptr ?
'\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
15513 , indent_char(ichar)
15514 , indent_string(512, indent_char)
15515 , error_handler(error_handler_)
15519 serializer(
const serializer&) =
delete;
15520 serializer& operator=(
const serializer&) =
delete;
15521 serializer(serializer&&) =
delete;
15522 serializer& operator=(serializer&&) =
delete;
15523 ~serializer() =
default;
15547 void dump(
const BasicJsonType& val,
15548 const bool pretty_print,
15549 const bool ensure_ascii,
15550 const unsigned int indent_step,
15551 const unsigned int current_indent = 0)
15553 switch (val.m_type)
15555 case value_t::object:
15557 if (val.m_value.object->empty())
15559 o->write_characters(
"{}", 2);
15565 o->write_characters(
"{\n", 2);
15568 const auto new_indent = current_indent + indent_step;
15569 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15571 indent_string.resize(indent_string.size() * 2,
' ');
15575 auto i = val.m_value.object->cbegin();
15576 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
15578 o->write_characters(indent_string.c_str(), new_indent);
15579 o->write_character(
'\"');
15580 dump_escaped(i->first, ensure_ascii);
15581 o->write_characters(
"\": ", 3);
15582 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
15583 o->write_characters(
",\n", 2);
15587 JSON_ASSERT(i != val.m_value.object->cend());
15588 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
15589 o->write_characters(indent_string.c_str(), new_indent);
15590 o->write_character(
'\"');
15591 dump_escaped(i->first, ensure_ascii);
15592 o->write_characters(
"\": ", 3);
15593 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
15595 o->write_character(
'\n');
15596 o->write_characters(indent_string.c_str(), current_indent);
15597 o->write_character(
'}');
15601 o->write_character(
'{');
15604 auto i = val.m_value.object->cbegin();
15605 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
15607 o->write_character(
'\"');
15608 dump_escaped(i->first, ensure_ascii);
15609 o->write_characters(
"\":", 2);
15610 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
15611 o->write_character(
',');
15615 JSON_ASSERT(i != val.m_value.object->cend());
15616 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
15617 o->write_character(
'\"');
15618 dump_escaped(i->first, ensure_ascii);
15619 o->write_characters(
"\":", 2);
15620 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
15622 o->write_character(
'}');
15628 case value_t::array:
15630 if (val.m_value.array->empty())
15632 o->write_characters(
"[]", 2);
15638 o->write_characters(
"[\n", 2);
15641 const auto new_indent = current_indent + indent_step;
15642 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15644 indent_string.resize(indent_string.size() * 2,
' ');
15648 for (
auto i = val.m_value.array->cbegin();
15649 i != val.m_value.array->cend() - 1; ++i)
15651 o->write_characters(indent_string.c_str(), new_indent);
15652 dump(*i,
true, ensure_ascii, indent_step, new_indent);
15653 o->write_characters(
",\n", 2);
15657 JSON_ASSERT(!val.m_value.array->empty());
15658 o->write_characters(indent_string.c_str(), new_indent);
15659 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
15661 o->write_character(
'\n');
15662 o->write_characters(indent_string.c_str(), current_indent);
15663 o->write_character(
']');
15667 o->write_character(
'[');
15670 for (
auto i = val.m_value.array->cbegin();
15671 i != val.m_value.array->cend() - 1; ++i)
15673 dump(*i,
false, ensure_ascii, indent_step, current_indent);
15674 o->write_character(
',');
15678 JSON_ASSERT(!val.m_value.array->empty());
15679 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
15681 o->write_character(
']');
15687 case value_t::string:
15689 o->write_character(
'\"');
15690 dump_escaped(*val.m_value.string, ensure_ascii);
15691 o->write_character(
'\"');
15695 case value_t::binary:
15699 o->write_characters(
"{\n", 2);
15702 const auto new_indent = current_indent + indent_step;
15703 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15705 indent_string.resize(indent_string.size() * 2,
' ');
15708 o->write_characters(indent_string.c_str(), new_indent);
15710 o->write_characters(
"\"bytes\": [", 10);
15712 if (!val.m_value.binary->empty())
15714 for (
auto i = val.m_value.binary->cbegin();
15715 i != val.m_value.binary->cend() - 1; ++i)
15718 o->write_characters(
", ", 2);
15720 dump_integer(val.m_value.binary->back());
15723 o->write_characters(
"],\n", 3);
15724 o->write_characters(indent_string.c_str(), new_indent);
15726 o->write_characters(
"\"subtype\": ", 11);
15727 if (val.m_value.binary->has_subtype())
15729 dump_integer(val.m_value.binary->subtype());
15733 o->write_characters(
"null", 4);
15735 o->write_character(
'\n');
15736 o->write_characters(indent_string.c_str(), current_indent);
15737 o->write_character(
'}');
15741 o->write_characters(
"{\"bytes\":[", 10);
15743 if (!val.m_value.binary->empty())
15745 for (
auto i = val.m_value.binary->cbegin();
15746 i != val.m_value.binary->cend() - 1; ++i)
15749 o->write_character(
',');
15751 dump_integer(val.m_value.binary->back());
15754 o->write_characters(
"],\"subtype\":", 12);
15755 if (val.m_value.binary->has_subtype())
15757 dump_integer(val.m_value.binary->subtype());
15758 o->write_character(
'}');
15762 o->write_characters(
"null}", 5);
15768 case value_t::boolean:
15770 if (val.m_value.boolean)
15772 o->write_characters(
"true", 4);
15776 o->write_characters(
"false", 5);
15781 case value_t::number_integer:
15783 dump_integer(val.m_value.number_integer);
15787 case value_t::number_unsigned:
15789 dump_integer(val.m_value.number_unsigned);
15793 case value_t::number_float:
15795 dump_float(val.m_value.number_float);
15799 case value_t::discarded:
15801 o->write_characters(
"<discarded>", 11);
15805 case value_t::null:
15807 o->write_characters(
"null", 4);
15812 JSON_ASSERT(
false);
15816 JSON_PRIVATE_UNLESS_TESTED:
15831 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
15833 std::uint32_t codepoint;
15834 std::uint8_t state = UTF8_ACCEPT;
15835 std::size_t bytes = 0;
15838 std::size_t bytes_after_last_accept = 0;
15839 std::size_t undumped_chars = 0;
15841 for (std::size_t i = 0; i < s.size(); ++i)
15843 const auto byte =
static_cast<uint8_t
>(s[i]);
15845 switch (decode(state, codepoint,
byte))
15853 string_buffer[bytes++] =
'\\';
15854 string_buffer[bytes++] =
'b';
15860 string_buffer[bytes++] =
'\\';
15861 string_buffer[bytes++] =
't';
15867 string_buffer[bytes++] =
'\\';
15868 string_buffer[bytes++] =
'n';
15874 string_buffer[bytes++] =
'\\';
15875 string_buffer[bytes++] =
'f';
15881 string_buffer[bytes++] =
'\\';
15882 string_buffer[bytes++] =
'r';
15888 string_buffer[bytes++] =
'\\';
15889 string_buffer[bytes++] =
'\"';
15895 string_buffer[bytes++] =
'\\';
15896 string_buffer[bytes++] =
'\\';
15904 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
15906 if (codepoint <= 0xFFFF)
15908 (std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
15909 static_cast<std::uint16_t
>(codepoint));
15914 (std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
15915 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
15916 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu)));
15924 string_buffer[bytes++] = s[i];
15933 if (string_buffer.size() - bytes < 13)
15935 o->write_characters(string_buffer.data(), bytes);
15940 bytes_after_last_accept = bytes;
15941 undumped_chars = 0;
15947 switch (error_handler)
15949 case error_handler_t::strict:
15951 std::string sn(3,
'\0');
15952 (std::snprintf)(&sn[0], sn.size(),
"%.2X", byte);
15953 JSON_THROW(type_error::create(316,
"invalid UTF-8 byte at index " + std::to_string(i) +
": 0x" + sn));
15956 case error_handler_t::ignore:
15957 case error_handler_t::replace:
15963 if (undumped_chars > 0)
15970 bytes = bytes_after_last_accept;
15972 if (error_handler == error_handler_t::replace)
15977 string_buffer[bytes++] =
'\\';
15978 string_buffer[bytes++] =
'u';
15979 string_buffer[bytes++] =
'f';
15980 string_buffer[bytes++] =
'f';
15981 string_buffer[bytes++] =
'f';
15982 string_buffer[bytes++] =
'd';
15986 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
15987 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
15988 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
15994 if (string_buffer.size() - bytes < 13)
15996 o->write_characters(string_buffer.data(), bytes);
16000 bytes_after_last_accept = bytes;
16003 undumped_chars = 0;
16006 state = UTF8_ACCEPT;
16011 JSON_ASSERT(
false);
16021 string_buffer[bytes++] = s[i];
16030 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
16035 o->write_characters(string_buffer.data(), bytes);
16041 switch (error_handler)
16043 case error_handler_t::strict:
16045 std::string sn(3,
'\0');
16046 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
static_cast<std::uint8_t
>(s.back()));
16047 JSON_THROW(type_error::create(316,
"incomplete UTF-8 string; last byte: 0x" + sn));
16050 case error_handler_t::ignore:
16053 o->write_characters(string_buffer.data(), bytes_after_last_accept);
16057 case error_handler_t::replace:
16060 o->write_characters(string_buffer.data(), bytes_after_last_accept);
16064 o->write_characters(
"\\ufffd", 6);
16068 o->write_characters(
"\xEF\xBF\xBD", 3);
16074 JSON_ASSERT(
false);
16088 inline unsigned int count_digits(number_unsigned_t x) noexcept
16090 unsigned int n_digits = 1;
16099 return n_digits + 1;
16103 return n_digits + 2;
16107 return n_digits + 3;
16123 template <
typename NumberType, detail::enable_if_t <
16124 std::is_same<NumberType, number_unsigned_t>::value ||
16125 std::is_same<NumberType, number_integer_t>::value ||
16126 std::is_same<NumberType, binary_char_t>::value,
16128 void dump_integer(NumberType x)
16130 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
16133 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
16134 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
16135 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
16136 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
16137 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
16138 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
16139 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
16140 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
16141 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
16142 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
16149 o->write_character(
'0');
16154 auto buffer_ptr = number_buffer.begin();
16156 const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0);
16157 number_unsigned_t abs_value;
16159 unsigned int n_chars;
16164 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
16167 n_chars = 1 + count_digits(abs_value);
16171 abs_value =
static_cast<number_unsigned_t
>(x);
16172 n_chars = count_digits(abs_value);
16176 JSON_ASSERT(n_chars < number_buffer.size() - 1);
16180 buffer_ptr += n_chars;
16184 while (abs_value >= 100)
16186 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
16188 *(--buffer_ptr) = digits_to_99[digits_index][1];
16189 *(--buffer_ptr) = digits_to_99[digits_index][0];
16192 if (abs_value >= 10)
16194 const auto digits_index =
static_cast<unsigned>(abs_value);
16195 *(--buffer_ptr) = digits_to_99[digits_index][1];
16196 *(--buffer_ptr) = digits_to_99[digits_index][0];
16200 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
16203 o->write_characters(number_buffer.data(), n_chars);
16214 void dump_float(number_float_t x)
16217 if (!std::isfinite(x))
16219 o->write_characters(
"null", 4);
16228 static constexpr
bool is_ieee_single_or_double
16229 = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
16230 (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
16232 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
16235 void dump_float(number_float_t x, std::true_type )
16237 char* begin = number_buffer.data();
16238 char* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
16240 o->write_characters(begin,
static_cast<size_t>(end - begin));
16243 void dump_float(number_float_t x, std::false_type )
16246 static constexpr
auto d = std::numeric_limits<number_float_t>::max_digits10;
16249 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
16252 JSON_ASSERT(len > 0);
16254 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
16257 if (thousands_sep !=
'\0')
16259 const auto end = std::remove(number_buffer.begin(),
16260 number_buffer.begin() + len, thousands_sep);
16261 std::fill(end, number_buffer.end(),
'\0');
16262 JSON_ASSERT((end - number_buffer.begin()) <= len);
16263 len = (end - number_buffer.begin());
16267 if (decimal_point !=
'\0' && decimal_point !=
'.')
16269 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
16270 if (dec_pos != number_buffer.end())
16276 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
16279 const bool value_is_int_like =
16280 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
16283 return c ==
'.' || c ==
'e';
16286 if (value_is_int_like)
16288 o->write_characters(
".0", 2);
16313 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte) noexcept
16315 static const std::array<std::uint8_t, 400> utf8d =
16318 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,
16319 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,
16320 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,
16321 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,
16322 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,
16323 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,
16324 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,
16325 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
16326 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
16327 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
16328 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,
16329 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,
16330 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,
16331 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
16335 const std::uint8_t type = utf8d[byte];
16337 codep = (state != UTF8_ACCEPT)
16338 ? (
byte & 0x3fu) | (codep << 6u)
16339 : (0xFFu >> type) & (byte);
16341 std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
16342 JSON_ASSERT(index < 400);
16343 state = utf8d[index];
16352 number_unsigned_t remove_sign(number_unsigned_t x)
16354 JSON_ASSERT(
false);
16367 inline number_unsigned_t remove_sign(number_integer_t x) noexcept
16369 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
16370 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
16375 output_adapter_t<char> o =
nullptr;
16378 std::array<char, 64> number_buffer{{}};
16381 const std::lconv* loc =
nullptr;
16383 const char thousands_sep =
'\0';
16385 const char decimal_point =
'\0';
16388 std::array<char, 512> string_buffer{{}};
16391 const char indent_char;
16393 string_t indent_string;
16396 const error_handler_t error_handler;
16408 #include <functional>
16421 template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
16422 class Allocator = std::allocator<std::pair<const Key, T>>>
16427 using Container = std::vector<std::pair<const Key, T>, Allocator>;
16428 using typename Container::iterator;
16429 using typename Container::const_iterator;
16430 using typename Container::size_type;
16431 using typename Container::value_type;
16436 template <
class It>
16439 ordered_map(std::initializer_list<T> init,
const Allocator& alloc = Allocator() )
16444 for (
auto it = this->begin(); it != this->end(); ++it)
16446 if (it->first == key)
16448 return {it,
false};
16451 Container::emplace_back(key, t);
16452 return {--this->end(),
true};
16457 return emplace(key, T{}).first->second;
16467 for (
auto it = this->begin(); it != this->end(); ++it)
16469 if (it->first == key)
16475 JSON_THROW(std::out_of_range(
"key not found"));
16478 const T&
at(
const Key& key)
const
16480 for (
auto it = this->begin(); it != this->end(); ++it)
16482 if (it->first == key)
16488 JSON_THROW(std::out_of_range(
"key not found"));
16493 for (
auto it = this->begin(); it != this->end(); ++it)
16495 if (it->first == key)
16498 for (
auto next = it; ++next != this->end(); ++it)
16501 new (&*it) value_type{std::move(*next)};
16503 Container::pop_back();
16515 for (
auto next = it; ++next != this->end(); ++it)
16518 new (&*it) value_type{std::move(*next)};
16520 Container::pop_back();
16526 for (
auto it = this->begin(); it != this->end(); ++it)
16528 if (it->first == key)
16538 for (
auto it = this->begin(); it != this->end(); ++it)
16540 if (it->first == key)
16545 return Container::end();
16548 const_iterator
find(
const Key& key)
const
16550 for (
auto it = this->begin(); it != this->end(); ++it)
16552 if (it->first == key)
16557 return Container::end();
16560 std::pair<iterator, bool>
insert( value_type&& value )
16562 return emplace(value.first, std::move(value.second));
16565 std::pair<iterator, bool>
insert(
const value_type& value )
16567 for (
auto it = this->begin(); it != this->end(); ++it)
16569 if (it->first == value.first)
16571 return {it,
false};
16574 Container::push_back(value);
16575 return {--this->end(),
true};
16674 NLOHMANN_BASIC_JSON_TPL_DECLARATION
16679 friend ::nlohmann::json_pointer<basic_json>;
16681 template<
typename BasicJsonType,
typename InputType>
16682 friend class ::nlohmann::detail::parser;
16683 friend ::nlohmann::detail::serializer<basic_json>;
16684 template<
typename BasicJsonType>
16685 friend class ::nlohmann::detail::iter_impl;
16686 template<
typename BasicJsonType,
typename CharType>
16687 friend class ::nlohmann::detail::binary_writer;
16688 template<
typename BasicJsonType,
typename InputType,
typename SAX>
16689 friend class ::nlohmann::detail::binary_reader;
16690 template<
typename BasicJsonType>
16691 friend class ::nlohmann::detail::json_sax_dom_parser;
16692 template<
typename BasicJsonType>
16693 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
16696 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
16698 JSON_PRIVATE_UNLESS_TESTED:
16700 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
16702 template<
typename InputAdapterType>
16703 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
16704 InputAdapterType adapter,
16705 detail::parser_callback_t<basic_json>cb =
nullptr,
16706 const bool allow_exceptions =
true,
16707 const bool ignore_comments =
false
16710 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
16711 std::move(cb), allow_exceptions, ignore_comments);
16715 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
16716 template<
typename BasicJsonType>
16717 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
16718 template<
typename BasicJsonType>
16719 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
16720 template<
typename Iterator>
16721 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
16722 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
16724 template<
typename CharType>
16725 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
16727 template<
typename InputType>
16728 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
16729 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
16731 JSON_PRIVATE_UNLESS_TESTED:
16732 using serializer = ::nlohmann::detail::serializer<basic_json>;
16735 using value_t = detail::value_t;
16738 template<
typename T,
typename SFINAE>
16741 using error_handler_t = detail::error_handler_t;
16743 using cbor_tag_handler_t = detail::cbor_tag_handler_t;
16747 using input_format_t = detail::input_format_t;
16801 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
16803 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
16856 result[
"copyright"] =
"(C) 2013-2020 Niels Lohmann";
16857 result[
"name"] =
"JSON for Modern C++";
16858 result[
"url"] =
"https://github.com/nlohmann/json";
16859 result[
"version"][
"string"] =
16860 std::to_string(NLOHMANN_JSON_VERSION_MAJOR) +
"." +
16861 std::to_string(NLOHMANN_JSON_VERSION_MINOR) +
"." +
16862 std::to_string(NLOHMANN_JSON_VERSION_PATCH);
16863 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
16864 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
16865 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
16868 result[
"platform"] =
"win32";
16869 #elif defined __linux__
16870 result[
"platform"] =
"linux";
16871 #elif defined __APPLE__
16872 result[
"platform"] =
"apple";
16873 #elif defined __unix__
16874 result[
"platform"] =
"unix";
16876 result[
"platform"] =
"unknown";
16879 #if defined(__ICC) || defined(__INTEL_COMPILER)
16880 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
16881 #elif defined(__clang__)
16882 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
16883 #elif defined(__GNUC__) || defined(__GNUG__)
16884 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." + std::to_string(__GNUC_PATCHLEVEL__)}};
16885 #elif defined(__HP_cc) || defined(__HP_aCC)
16886 result[
"compiler"] =
"hp"
16887 #elif defined(__IBMCPP__)
16888 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
16889 #elif defined(_MSC_VER)
16890 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
16891 #elif defined(__PGI)
16892 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
16893 #elif defined(__SUNPRO_CC)
16894 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
16896 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
16900 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
16902 result[
"compiler"][
"c++"] =
"unknown";
16917 #if defined(JSON_HAS_CPP_14)
17011 AllocatorType<std::pair<
const StringType,
17058 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
17425 template<
typename T,
typename... Args>
17427 static T* create(Args&& ... args)
17429 AllocatorType<T> alloc;
17430 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
17432 auto deleter = [&](T *
object)
17434 AllocatorTraits::deallocate(alloc,
object, 1);
17436 std::unique_ptr<T, decltype(deleter)>
object(AllocatorTraits::allocate(alloc, 1), deleter);
17437 AllocatorTraits::construct(alloc,
object.
get(), std::forward<Args>(args)...);
17438 JSON_ASSERT(
object !=
nullptr);
17439 return object.release();
17446 JSON_PRIVATE_UNLESS_TESTED:
17492 json_value() =
default;
17494 json_value(
boolean_t v) noexcept : boolean(v) {}
17506 case value_t::object:
17508 object = create<object_t>();
17512 case value_t::array:
17514 array = create<array_t>();
17518 case value_t::string:
17520 string = create<string_t>(
"");
17524 case value_t::binary:
17526 binary = create<binary_t>();
17530 case value_t::boolean:
17536 case value_t::number_integer:
17542 case value_t::number_unsigned:
17548 case value_t::number_float:
17554 case value_t::null:
17563 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
17565 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.9.1"));
17575 string = create<string_t>(
value);
17581 string = create<string_t>(std::move(
value));
17587 object = create<object_t>(
value);
17593 object = create<object_t>(std::move(
value));
17599 array = create<array_t>(
value);
17605 array = create<array_t>(std::move(
value));
17611 binary = create<binary_t>(
value);
17617 binary = create<binary_t>(std::move(
value));
17623 binary = create<binary_t>(
value);
17629 binary = create<binary_t>(std::move(
value));
17632 void destroy(
value_t t) noexcept
17635 std::vector<basic_json> stack;
17638 if (t == value_t::array)
17640 stack.reserve(array->size());
17641 std::move(array->begin(), array->end(), std::back_inserter(stack));
17643 else if (t == value_t::object)
17646 for (
auto&& it : *
object)
17648 stack.push_back(std::move(it.second));
17652 while (!stack.empty())
17655 basic_json current_item(std::move(stack.back()));
17660 if (current_item.is_array())
17662 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(),
17663 std::back_inserter(stack));
17665 current_item.m_value.array->clear();
17667 else if (current_item.is_object())
17669 for (
auto&& it : *current_item.m_value.object)
17671 stack.push_back(std::move(it.second));
17674 current_item.m_value.object->clear();
17683 case value_t::object:
17685 AllocatorType<object_t> alloc;
17686 std::allocator_traits<decltype(alloc)>::destroy(alloc,
object);
17687 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
object, 1);
17691 case value_t::array:
17693 AllocatorType<array_t> alloc;
17694 std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
17695 std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
17699 case value_t::string:
17701 AllocatorType<string_t> alloc;
17702 std::allocator_traits<decltype(alloc)>::destroy(alloc,
string);
17703 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
string, 1);
17707 case value_t::binary:
17709 AllocatorType<binary_t> alloc;
17710 std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
17711 std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
17733 void assert_invariant() const noexcept
17735 JSON_ASSERT(m_type != value_t::object ||
m_value.object !=
nullptr);
17736 JSON_ASSERT(m_type != value_t::array ||
m_value.array !=
nullptr);
17737 JSON_ASSERT(m_type != value_t::string ||
m_value.string !=
nullptr);
17738 JSON_ASSERT(m_type != value_t::binary ||
m_value.binary !=
nullptr);
17761 using parse_event_t = detail::parse_event_t;
17856 assert_invariant();
17880 assert_invariant();
17946 template <
typename CompatibleType,
17947 typename U = detail::uncvref_t<CompatibleType>,
17948 detail::enable_if_t <
17949 !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value,
int > = 0 >
17951 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
17952 std::forward<CompatibleType>(val))))
17954 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
17955 assert_invariant();
17984 template <
typename BasicJsonType,
17985 detail::enable_if_t <
17986 detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value,
int > = 0 >
17989 using other_boolean_t =
typename BasicJsonType::boolean_t;
17990 using other_number_float_t =
typename BasicJsonType::number_float_t;
17991 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
17992 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
17993 using other_string_t =
typename BasicJsonType::string_t;
17994 using other_object_t =
typename BasicJsonType::object_t;
17995 using other_array_t =
typename BasicJsonType::array_t;
17996 using other_binary_t =
typename BasicJsonType::binary_t;
17998 switch (val.type())
18000 case value_t::boolean:
18001 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
18003 case value_t::number_float:
18004 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
18006 case value_t::number_integer:
18007 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
18009 case value_t::number_unsigned:
18010 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
18012 case value_t::string:
18013 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
18015 case value_t::object:
18016 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
18018 case value_t::array:
18019 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
18021 case value_t::binary:
18022 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
18024 case value_t::null:
18027 case value_t::discarded:
18028 m_type = value_t::discarded;
18031 JSON_ASSERT(
false);
18033 assert_invariant();
18111 bool type_deduction =
true,
18112 value_t manual_type = value_t::array)
18116 bool is_an_object = std::all_of(init.begin(), init.end(),
18117 [](
const detail::json_ref<basic_json>& element_ref)
18119 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
18123 if (!type_deduction)
18126 if (manual_type == value_t::array)
18128 is_an_object =
false;
18132 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
18134 JSON_THROW(type_error::create(301,
"cannot create object from initializer list"));
18141 m_type = value_t::object;
18144 std::for_each(init.begin(), init.end(), [
this](
const detail::json_ref<basic_json>& element_ref)
18146 auto element = element_ref.moved_or_copied();
18147 m_value.object->emplace(
18148 std::move(*((*element.m_value.array)[0].m_value.string)),
18149 std::move((*element.m_value.array)[1]));
18155 m_type = value_t::array;
18156 m_value.array = create<array_t>(init.begin(), init.end());
18159 assert_invariant();
18193 res.m_type = value_t::binary;
18194 res.m_value = init;
18230 res.m_type = value_t::binary;
18231 res.m_value =
binary_t(init, subtype);
18240 res.m_type = value_t::binary;
18241 res.m_value = std::move(init);
18250 res.m_type = value_t::binary;
18251 res.m_value =
binary_t(std::move(init), subtype);
18295 return basic_json(init,
false, value_t::array);
18339 return basic_json(init,
false, value_t::object);
18365 : m_type(value_t::array)
18367 m_value.array = create<array_t>(cnt, val);
18368 assert_invariant();
18426 template <
class InputIT,
typename std::enable_if <
18427 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
18428 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
18431 JSON_ASSERT(first.m_object !=
nullptr);
18432 JSON_ASSERT(last.m_object !=
nullptr);
18435 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
18437 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible"));
18441 m_type = first.m_object->m_type;
18446 case value_t::boolean:
18447 case value_t::number_float:
18448 case value_t::number_integer:
18449 case value_t::number_unsigned:
18450 case value_t::string:
18452 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
18453 || !last.m_it.primitive_iterator.is_end()))
18455 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
18466 case value_t::number_integer:
18468 m_value.number_integer = first.m_object->m_value.number_integer;
18472 case value_t::number_unsigned:
18474 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
18478 case value_t::number_float:
18480 m_value.number_float = first.m_object->m_value.number_float;
18484 case value_t::boolean:
18486 m_value.boolean = first.m_object->m_value.boolean;
18490 case value_t::string:
18492 m_value = *first.m_object->m_value.string;
18496 case value_t::object:
18498 m_value.object = create<object_t>(first.m_it.object_iterator,
18499 last.m_it.object_iterator);
18503 case value_t::array:
18505 m_value.array = create<array_t>(first.m_it.array_iterator,
18506 last.m_it.array_iterator);
18510 case value_t::binary:
18512 m_value = *first.m_object->m_value.binary;
18517 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " +
18518 std::string(first.m_object->type_name())));
18521 assert_invariant();
18529 template<
typename JsonRef,
18530 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
18531 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
18560 : m_type(other.m_type)
18563 other.assert_invariant();
18567 case value_t::object:
18573 case value_t::array:
18579 case value_t::string:
18585 case value_t::boolean:
18591 case value_t::number_integer:
18597 case value_t::number_unsigned:
18603 case value_t::number_float:
18609 case value_t::binary:
18619 assert_invariant();
18649 : m_type(std::move(other.m_type)),
18650 m_value(std::move(other.m_value))
18653 other.assert_invariant();
18656 other.m_type = value_t::null;
18657 other.m_value = {};
18659 assert_invariant();
18686 std::is_nothrow_move_constructible<value_t>::value&&
18687 std::is_nothrow_move_assignable<value_t>::value&&
18688 std::is_nothrow_move_constructible<json_value>::value&&
18689 std::is_nothrow_move_assignable<json_value>::value
18693 other.assert_invariant();
18696 swap(m_type, other.m_type);
18699 assert_invariant();
18720 assert_invariant();
18783 const char indent_char =
' ',
18784 const bool ensure_ascii =
false,
18785 const error_handler_t error_handler = error_handler_t::strict)
const
18788 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
18792 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
18796 s.dump(*
this,
false, ensure_ascii, 0);
18835 constexpr value_t
type() const noexcept
18917 return m_type == value_t::null;
18939 return m_type == value_t::boolean;
18998 return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
19026 return m_type == value_t::number_unsigned;
19054 return m_type == value_t::number_float;
19076 return m_type == value_t::object;
19098 return m_type == value_t::array;
19120 return m_type == value_t::string;
19142 return m_type == value_t::binary;
19169 return m_type == value_t::discarded;
19213 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(
type_name())));
19235 constexpr
const array_t* get_impl_ptr(
const array_t* )
const noexcept
19323 template<
typename ReferenceType,
typename ThisType>
19324 static ReferenceType get_ref_impl(ThisType& obj)
19327 auto ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
19329 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
19334 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name())));
19356 template<
typename BasicJsonType, detail::enable_if_t<
19357 std::is_same<typename std::remove_const<BasicJsonType>::type, basic_json_t>
::value,
19379 template <
typename BasicJsonType, detail::enable_if_t <
19380 !std::is_same<BasicJsonType, basic_json>::value&&
19381 detail::is_basic_json<BasicJsonType>::value,
int > = 0 >
19426 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
19427 detail::enable_if_t <
19428 !detail::is_basic_json<ValueType>::value &&
19429 detail::has_from_json<basic_json_t, ValueType>::value &&
19430 !detail::has_non_default_from_json<basic_json_t, ValueType>::value,
19432 ValueType
get() const noexcept(noexcept(
19433 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
19438 static_assert(!std::is_reference<ValueTypeCV>::value,
19439 "get() cannot be used with reference types, you might want to use get_ref()");
19440 static_assert(std::is_default_constructible<ValueType>::value,
19441 "types must be DefaultConstructible when used with get()");
19444 JSONSerializer<ValueType>::from_json(*
this, ret);
19479 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
19480 detail::enable_if_t < !std::is_same<basic_json_t, ValueType>::value &&
19481 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
19483 ValueType
get() const noexcept(noexcept(
19484 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
19486 static_assert(!std::is_reference<ValueTypeCV>::value,
19487 "get() cannot be used with reference types, you might want to use get_ref()");
19488 return JSONSerializer<ValueType>::from_json(*
this);
19524 template <
typename ValueType,
19525 detail::enable_if_t <
19526 !detail::is_basic_json<ValueType>::value&&
19527 detail::has_from_json<basic_json_t, ValueType>::value,
19529 ValueType &
get_to(ValueType& v)
const noexcept(noexcept(
19530 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
19532 JSONSerializer<ValueType>::from_json(*
this, v);
19538 template<
typename ValueType,
19539 detail::enable_if_t <
19540 detail::is_basic_json<ValueType>::value,
19549 typename T, std::size_t N,
19550 typename Array = T (&)[N],
19551 detail::enable_if_t <
19552 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
19554 noexcept(noexcept(JSONSerializer<Array>::from_json(
19555 std::declval<const basic_json_t&>(), v)))
19557 JSONSerializer<Array>::from_json(*
this, v);
19588 template<
typename PointerType,
typename std::enable_if<
19589 std::is_pointer<PointerType>::value,
int>
::type = 0>
19590 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
19593 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
19600 template <
typename PointerType,
typename std::enable_if <
19601 std::is_pointer<PointerType>::value&&
19602 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int >
::type = 0 >
19603 constexpr
auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
19606 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
19636 template<
typename PointerType,
typename std::enable_if<
19637 std::is_pointer<PointerType>::value,
int>
::type = 0>
19638 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template
get_ptr<PointerType>())
19641 return get_ptr<PointerType>();
19648 template<
typename PointerType,
typename std::enable_if<
19649 std::is_pointer<PointerType>::value,
int>
::type = 0>
19650 constexpr
auto get() const noexcept -> decltype(std::declval<const basic_json_t&>().template
get_ptr<PointerType>())
19653 return get_ptr<PointerType>();
19682 template<
typename ReferenceType,
typename std::enable_if<
19683 std::is_reference<ReferenceType>::value,
int>
::type = 0>
19687 return get_ref_impl<ReferenceType>(*
this);
19694 template <
typename ReferenceType,
typename std::enable_if <
19695 std::is_reference<ReferenceType>::value&&
19696 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int >
::type = 0 >
19700 return get_ref_impl<ReferenceType>(*
this);
19732 template <
typename ValueType,
typename std::enable_if <
19733 !std::is_pointer<ValueType>::value&&
19734 !std::is_same<ValueType, detail::json_ref<basic_json>>
::value&&
19735 !std::is_same<ValueType, typename string_t::value_type>::value&&
19736 !detail::is_basic_json<ValueType>::value
19737 && !std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>
::value
19738 #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
19739 && !std::is_same<ValueType, typename std::string_view>::value
19741 && detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
19743 JSON_EXPLICIT
operator ValueType()
const
19746 return get<ValueType>();
19762 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name())));
19765 return *get_ptr<binary_t*>();
19773 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name())));
19776 return *get_ptr<const binary_t*>();
19819 if (JSON_HEDLEY_LIKELY(
is_array()))
19823 return m_value.array->at(idx);
19825 JSON_CATCH (std::out_of_range&)
19828 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range"));
19833 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name())));
19866 if (JSON_HEDLEY_LIKELY(
is_array()))
19870 return m_value.array->at(idx);
19872 JSON_CATCH (std::out_of_range&)
19875 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range"));
19880 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name())));
19914 reference at(
const typename object_t::key_type& key)
19921 return m_value.object->at(key);
19923 JSON_CATCH (std::out_of_range&)
19926 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found"));
19931 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name())));
19972 return m_value.object->at(key);
19974 JSON_CATCH (std::out_of_range&)
19977 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found"));
19982 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name())));
20016 m_type = value_t::array;
20017 m_value.array = create<array_t>();
20018 assert_invariant();
20022 if (JSON_HEDLEY_LIKELY(
is_array()))
20025 if (idx >=
m_value.array->size())
20028 idx -
m_value.array->size() + 1,
20032 return m_value.array->operator[](idx);
20035 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name())));
20060 if (JSON_HEDLEY_LIKELY(
is_array()))
20062 return m_value.array->operator[](idx);
20065 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name())));
20100 m_type = value_t::object;
20101 m_value.object = create<object_t>();
20102 assert_invariant();
20108 return m_value.object->operator[](key);
20111 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name())));
20149 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
20150 return m_value.object->find(key)->second;
20153 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name())));
20183 template<
typename T>
20184 JSON_HEDLEY_NON_NULL(2)
20190 m_type = value_t::object;
20192 assert_invariant();
20198 return m_value.object->operator[](key);
20201 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name())));
20234 template<
typename T>
20235 JSON_HEDLEY_NON_NULL(2)
20241 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
20242 return m_value.object->find(key)->second;
20245 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name())));
20299 template <
class ValueType,
typename std::enable_if <
20300 detail::is_getable<basic_json_t, ValueType>::value
20301 && !std::is_same<value_t, ValueType>::value,
int >
::type = 0 >
20302 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
20308 const auto it =
find(key);
20311 return it->template get<ValueType>();
20314 return default_value;
20317 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name())));
20324 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const
20372 template<
class ValueType,
typename std::enable_if<
20373 detail::is_getable<basic_json_t, ValueType>::value,
int>
::type = 0>
20382 return ptr.get_checked(
this).template get<ValueType>();
20386 return default_value;
20390 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name())));
20397 JSON_HEDLEY_NON_NULL(3)
20535 template <
class IteratorType,
typename std::enable_if <
20536 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
20537 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
20539 IteratorType
erase(IteratorType pos)
20542 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
20544 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
20547 IteratorType result =
end();
20551 case value_t::boolean:
20552 case value_t::number_float:
20553 case value_t::number_integer:
20554 case value_t::number_unsigned:
20555 case value_t::string:
20556 case value_t::binary:
20558 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
20560 JSON_THROW(invalid_iterator::create(205,
"iterator out of range"));
20565 AllocatorType<string_t> alloc;
20566 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
20567 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
20572 AllocatorType<binary_t> alloc;
20573 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
20574 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
20578 m_type = value_t::null;
20579 assert_invariant();
20583 case value_t::object:
20585 result.m_it.object_iterator =
m_value.object->erase(pos.m_it.object_iterator);
20589 case value_t::array:
20591 result.m_it.array_iterator =
m_value.array->erase(pos.m_it.array_iterator);
20596 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name())));
20648 template <
class IteratorType,
typename std::enable_if <
20649 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
20650 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
20652 IteratorType
erase(IteratorType first, IteratorType last)
20655 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
20657 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value"));
20660 IteratorType result =
end();
20664 case value_t::boolean:
20665 case value_t::number_float:
20666 case value_t::number_integer:
20667 case value_t::number_unsigned:
20668 case value_t::string:
20669 case value_t::binary:
20671 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
20672 || !last.m_it.primitive_iterator.is_end()))
20674 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
20679 AllocatorType<string_t> alloc;
20680 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
20681 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
20686 AllocatorType<binary_t> alloc;
20687 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
20688 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
20692 m_type = value_t::null;
20693 assert_invariant();
20697 case value_t::object:
20699 result.m_it.object_iterator =
m_value.object->erase(first.m_it.object_iterator,
20700 last.m_it.object_iterator);
20704 case value_t::array:
20706 result.m_it.array_iterator =
m_value.array->erase(first.m_it.array_iterator,
20707 last.m_it.array_iterator);
20712 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name())));
20752 return m_value.object->erase(key);
20755 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name())));
20785 if (JSON_HEDLEY_LIKELY(
is_array()))
20787 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
20789 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range"));
20796 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name())));
20834 template<
typename KeyT>
20837 auto result =
end();
20841 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
20851 template<
typename KeyT>
20854 auto result =
cend();
20858 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
20885 template<
typename KeyT>
20917 template <
typename KeyT,
typename std::enable_if <
20952 return ptr.contains(
this);
20992 result.set_begin();
21032 result.set_begin();
21296 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
21299 return ref.items();
21305 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
21308 return ref.items();
21379 iteration_proxy<iterator>
items() noexcept
21381 return iteration_proxy<iterator>(*
this);
21387 iteration_proxy<const_iterator>
items() const noexcept
21389 return iteration_proxy<const_iterator>(*
this);
21444 bool empty() const noexcept
21448 case value_t::null:
21454 case value_t::array:
21457 return m_value.array->empty();
21460 case value_t::object:
21463 return m_value.object->empty();
21521 case value_t::null:
21527 case value_t::array:
21530 return m_value.array->size();
21533 case value_t::object:
21536 return m_value.object->size();
21592 case value_t::array:
21595 return m_value.array->max_size();
21598 case value_t::object:
21601 return m_value.object->max_size();
21659 void clear() noexcept
21663 case value_t::number_integer:
21669 case value_t::number_unsigned:
21675 case value_t::number_float:
21681 case value_t::boolean:
21687 case value_t::string:
21693 case value_t::binary:
21699 case value_t::array:
21705 case value_t::object:
21741 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name())));
21747 m_type = value_t::array;
21749 assert_invariant();
21753 m_value.array->push_back(std::move(val));
21776 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name())));
21782 m_type = value_t::array;
21784 assert_invariant();
21788 m_value.array->push_back(val);
21821 void push_back(
const typename object_t::value_type& val)
21826 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name())));
21832 m_type = value_t::object;
21834 assert_invariant();
21878 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
21880 basic_json&& key = init.begin()->moved_or_copied();
21881 push_back(
typename object_t::value_type(
21882 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
21923 template<
class... Args>
21929 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(
type_name())));
21935 m_type = value_t::array;
21937 assert_invariant();
21941 #ifdef JSON_HAS_CPP_17
21942 return m_value.array->emplace_back(std::forward<Args>(args)...);
21944 m_value.array->emplace_back(std::forward<Args>(args)...);
21945 return m_value.array->back();
21976 template<
class... Args>
21977 std::pair<iterator, bool>
emplace(Args&& ... args)
21982 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(
type_name())));
21988 m_type = value_t::object;
21990 assert_invariant();
21994 auto res =
m_value.object->emplace(std::forward<Args>(args)...);
21997 it.m_it.object_iterator = res.first;
22000 return {it, res.second};
22006 template<
typename... Args>
22010 JSON_ASSERT(
m_value.array !=
nullptr);
22012 auto insert_pos = std::distance(
m_value.array->begin(), pos.m_it.array_iterator);
22013 m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22014 result.m_it.array_iterator =
m_value.array->begin() + insert_pos;
22048 if (JSON_HEDLEY_LIKELY(
is_array()))
22051 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22053 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
22060 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
22069 return insert(pos, val);
22099 if (JSON_HEDLEY_LIKELY(
is_array()))
22102 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22104 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
22111 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
22147 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
22149 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
22153 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22155 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
22159 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22161 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
22164 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
22166 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container"));
22170 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
22200 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
22202 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
22206 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22208 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
22241 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
22243 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name())));
22247 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22249 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
22253 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22255 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects"));
22258 m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22285 m_type = value_t::object;
22286 m_value.object = create<object_t>();
22287 assert_invariant();
22292 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name())));
22294 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
22296 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.type_name())));
22299 for (
auto it = j.cbegin(); it != j.cend(); ++it)
22301 m_value.object->operator[](it.key()) = it.value();
22336 m_type = value_t::object;
22337 m_value.object = create<object_t>();
22338 assert_invariant();
22343 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name())));
22347 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22349 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
22353 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
22354 || !last.m_object->is_object()))
22356 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects"));
22359 for (
auto it = first; it != last; ++it)
22361 m_value.object->operator[](it.key()) = it.value();
22383 std::is_nothrow_move_constructible<value_t>::value&&
22384 std::is_nothrow_move_assignable<value_t>::value&&
22385 std::is_nothrow_move_constructible<json_value>::value&&
22386 std::is_nothrow_move_assignable<json_value>::value
22389 std::swap(m_type, other.m_type);
22390 std::swap(
m_value, other.m_value);
22391 assert_invariant();
22413 std::is_nothrow_move_constructible<value_t>::value&&
22414 std::is_nothrow_move_assignable<value_t>::value&&
22415 std::is_nothrow_move_constructible<json_value>::value&&
22416 std::is_nothrow_move_assignable<json_value>::value
22445 if (JSON_HEDLEY_LIKELY(
is_array()))
22447 std::swap(*(
m_value.array), other);
22451 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name())));
22480 std::swap(*(
m_value.object), other);
22484 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name())));
22513 std::swap(*(
m_value.string), other);
22517 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name())));
22546 std::swap(*(
m_value.binary), other);
22550 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name())));
22560 std::swap(*(
m_value.binary), other);
22564 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name())));
22635 const auto lhs_type = lhs.type();
22636 const auto rhs_type = rhs.type();
22638 if (lhs_type == rhs_type)
22642 case value_t::array:
22643 return *lhs.m_value.array == *rhs.m_value.array;
22645 case value_t::object:
22646 return *lhs.m_value.object == *rhs.m_value.object;
22648 case value_t::null:
22651 case value_t::string:
22652 return *lhs.m_value.string == *rhs.m_value.string;
22654 case value_t::boolean:
22655 return lhs.m_value.boolean == rhs.m_value.boolean;
22657 case value_t::number_integer:
22658 return lhs.m_value.number_integer == rhs.m_value.number_integer;
22660 case value_t::number_unsigned:
22661 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
22663 case value_t::number_float:
22664 return lhs.m_value.number_float == rhs.m_value.number_float;
22666 case value_t::binary:
22667 return *lhs.m_value.binary == *rhs.m_value.binary;
22673 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
22675 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
22677 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
22679 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
22681 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
22683 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
22685 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
22687 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
22689 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
22691 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
22693 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
22695 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
22705 template<
typename ScalarType,
typename std::enable_if<
22706 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22716 template<
typename ScalarType,
typename std::enable_if<
22717 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22743 return !(lhs == rhs);
22750 template<
typename ScalarType,
typename std::enable_if<
22751 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22761 template<
typename ScalarType,
typename std::enable_if<
22762 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22796 const auto lhs_type = lhs.type();
22797 const auto rhs_type = rhs.type();
22799 if (lhs_type == rhs_type)
22803 case value_t::array:
22806 return (*lhs.m_value.array) < (*rhs.m_value.array);
22808 case value_t::object:
22809 return (*lhs.m_value.object) < (*rhs.m_value.object);
22811 case value_t::null:
22814 case value_t::string:
22815 return (*lhs.m_value.string) < (*rhs.m_value.string);
22817 case value_t::boolean:
22818 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
22820 case value_t::number_integer:
22821 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
22823 case value_t::number_unsigned:
22824 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
22826 case value_t::number_float:
22827 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
22829 case value_t::binary:
22830 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
22836 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
22838 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
22840 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
22842 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
22844 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
22846 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
22848 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
22850 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
22852 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
22854 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
22856 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
22858 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
22871 template<
typename ScalarType,
typename std::enable_if<
22872 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22882 template<
typename ScalarType,
typename std::enable_if<
22883 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22910 return !(rhs < lhs);
22917 template<
typename ScalarType,
typename std::enable_if<
22918 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22928 template<
typename ScalarType,
typename std::enable_if<
22929 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22956 return !(lhs <= rhs);
22963 template<
typename ScalarType,
typename std::enable_if<
22964 std::is_scalar<ScalarType>::value,
int>
::type = 0>
22974 template<
typename ScalarType,
typename std::enable_if<
22975 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23002 return !(lhs < rhs);
23009 template<
typename ScalarType,
typename std::enable_if<
23010 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23020 template<
typename ScalarType,
typename std::enable_if<
23021 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23070 const bool pretty_print = o.width() > 0;
23071 const auto indentation = pretty_print ? o.width() : 0;
23077 serializer s(detail::output_adapter<char>(o), o.fill());
23078 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
23090 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
23157 template<
typename InputType>
23161 const bool allow_exceptions =
true,
23162 const bool ignore_comments =
false)
23165 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23195 template<
typename IteratorType>
23200 const bool allow_exceptions =
true,
23201 const bool ignore_comments =
false)
23204 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23209 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
parse(ptr, ptr + len))
23212 const bool allow_exceptions =
true,
23213 const bool ignore_comments =
false)
23216 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
23250 template<
typename InputType>
23251 static bool accept(InputType&& i,
23252 const bool ignore_comments =
false)
23254 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
23257 template<
typename IteratorType>
23258 static bool accept(IteratorType first, IteratorType last,
23259 const bool ignore_comments =
false)
23261 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
23265 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
accept(ptr, ptr + len))
23266 static bool accept(detail::span_input_adapter&& i,
23267 const bool ignore_comments =
false)
23269 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
23312 template <
typename InputType,
typename SAX>
23313 JSON_HEDLEY_NON_NULL(2)
23314 static
bool sax_parse(InputType&& i, SAX* sax,
23316 const
bool strict = true,
23317 const
bool ignore_comments = false)
23319 auto ia = detail::input_adapter(std::forward<InputType>(i));
23320 return format == input_format_t::json
23321 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23322 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23325 template<
class IteratorType,
class SAX>
23326 JSON_HEDLEY_NON_NULL(3)
23327 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
23328 input_format_t format = input_format_t::
json,
23329 const
bool strict = true,
23330 const
bool ignore_comments = false)
23332 auto ia = detail::input_adapter(std::move(first), std::move(last));
23333 return format == input_format_t::json
23334 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23335 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23338 template <
typename SAX>
23339 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
sax_parse(ptr, ptr + len, ...))
23340 JSON_HEDLEY_NON_NULL(2)
23341 static
bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
23342 input_format_t format = input_format_t::
json,
23343 const
bool strict = true,
23344 const
bool ignore_comments = false)
23347 return format == input_format_t::json
23348 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23349 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23360 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
23393 parser(detail::input_adapter(i)).parse(
false, j);
23440 case value_t::null:
23442 case value_t::object:
23444 case value_t::array:
23446 case value_t::string:
23448 case value_t::boolean:
23450 case value_t::binary:
23452 case value_t::discarded:
23453 return "discarded";
23461 JSON_PRIVATE_UNLESS_TESTED:
23467 value_t m_type = value_t::null;
23576 std::vector<uint8_t> result;
23583 binary_writer<uint8_t>(o).write_cbor(j);
23588 binary_writer<char>(o).write_cbor(j);
23671 std::vector<uint8_t> result;
23678 binary_writer<uint8_t>(o).write_msgpack(j);
23683 binary_writer<char>(o).write_msgpack(j);
23773 const bool use_size =
false,
23774 const bool use_type =
false)
23776 std::vector<uint8_t> result;
23777 to_ubjson(j, result, use_size, use_type);
23782 const bool use_size =
false,
const bool use_type =
false)
23784 binary_writer<uint8_t>(o).write_ubjson(j, use_size, use_type);
23788 const bool use_size =
false,
const bool use_type =
false)
23790 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
23852 std::vector<uint8_t> result;
23867 binary_writer<uint8_t>(o).write_bson(j);
23875 binary_writer<char>(o).write_bson(j);
23981 template<
typename InputType>
23984 const bool strict =
true,
23985 const bool allow_exceptions =
true,
23989 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
23990 auto ia = detail::input_adapter(std::forward<InputType>(i));
23991 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23992 return res ? result :
basic_json(value_t::discarded);
23998 template<
typename IteratorType>
24001 const bool strict =
true,
24002 const bool allow_exceptions =
true,
24006 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24007 auto ia = detail::input_adapter(std::move(first), std::move(last));
24008 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24009 return res ? result :
basic_json(value_t::discarded);
24012 template<
typename T>
24014 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
24016 const bool strict =
true,
24017 const bool allow_exceptions =
true,
24020 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
24027 const bool strict =
true,
24028 const bool allow_exceptions =
true,
24029 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24032 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24034 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24035 return res ? result :
basic_json(value_t::discarded);
24124 template<
typename InputType>
24127 const bool strict =
true,
24128 const bool allow_exceptions =
true)
24131 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24132 auto ia = detail::input_adapter(std::forward<InputType>(i));
24133 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24134 return res ? result :
basic_json(value_t::discarded);
24140 template<
typename IteratorType>
24143 const bool strict =
true,
24144 const bool allow_exceptions =
true)
24147 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24148 auto ia = detail::input_adapter(std::move(first), std::move(last));
24149 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24150 return res ? result :
basic_json(value_t::discarded);
24154 template<
typename T>
24156 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
24158 const bool strict =
true,
24159 const bool allow_exceptions =
true)
24161 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
24165 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
24167 const bool strict =
true,
24168 const bool allow_exceptions =
true)
24171 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24173 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24174 return res ? result :
basic_json(value_t::discarded);
24240 template<
typename InputType>
24243 const bool strict =
true,
24244 const bool allow_exceptions =
true)
24247 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24248 auto ia = detail::input_adapter(std::forward<InputType>(i));
24249 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24250 return res ? result :
basic_json(value_t::discarded);
24256 template<
typename IteratorType>
24259 const bool strict =
true,
24260 const bool allow_exceptions =
true)
24263 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24264 auto ia = detail::input_adapter(std::move(first), std::move(last));
24265 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24266 return res ? result :
basic_json(value_t::discarded);
24269 template<
typename T>
24271 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
24273 const bool strict =
true,
24274 const bool allow_exceptions =
true)
24276 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
24280 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
24282 const bool strict =
true,
24283 const bool allow_exceptions =
true)
24286 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24288 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24289 return res ? result :
basic_json(value_t::discarded);
24353 template<
typename InputType>
24356 const bool strict =
true,
24357 const bool allow_exceptions =
true)
24360 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24361 auto ia = detail::input_adapter(std::forward<InputType>(i));
24362 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24363 return res ? result :
basic_json(value_t::discarded);
24369 template<
typename IteratorType>
24372 const bool strict =
true,
24373 const bool allow_exceptions =
true)
24376 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24377 auto ia = detail::input_adapter(std::move(first), std::move(last));
24378 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24379 return res ? result :
basic_json(value_t::discarded);
24382 template<
typename T>
24384 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
24386 const bool strict =
true,
24387 const bool allow_exceptions =
true)
24389 return from_bson(ptr, ptr + len, strict, allow_exceptions);
24393 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
24395 const bool strict =
true,
24396 const bool allow_exceptions =
true)
24399 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24401 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24402 return res ? result :
basic_json(value_t::discarded);
24448 return ptr.get_unchecked(
this);
24476 return ptr.get_unchecked(
this);
24519 return ptr.get_checked(
this);
24562 return ptr.get_checked(
this);
24590 json_pointer::flatten(
"", *
this, result);
24626 return json_pointer::unflatten(*
this);
24691 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
24693 const auto get_op = [](
const std::string & op)
24697 return patch_operations::add;
24699 if (op ==
"remove")
24701 return patch_operations::remove;
24703 if (op ==
"replace")
24705 return patch_operations::replace;
24709 return patch_operations::move;
24713 return patch_operations::copy;
24717 return patch_operations::test;
24720 return patch_operations::invalid;
24735 if (top_pointer != ptr)
24737 result.
at(top_pointer);
24741 const auto last_path = ptr.
back();
24745 switch (parent.m_type)
24747 case value_t::null:
24748 case value_t::object:
24751 parent[last_path] = val;
24755 case value_t::array:
24757 if (last_path ==
"-")
24764 const auto idx = json_pointer::array_index(last_path);
24765 if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
24768 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range"));
24772 parent.insert(parent.begin() +
static_cast<difference_type>(idx), val);
24779 JSON_ASSERT(
false);
24784 const auto operation_remove = [&result](
json_pointer & ptr)
24787 const auto last_path = ptr.back();
24792 if (parent.is_object())
24795 auto it = parent.
find(last_path);
24796 if (JSON_HEDLEY_LIKELY(it != parent.end()))
24802 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found"));
24805 else if (parent.is_array())
24808 parent.erase(json_pointer::array_index(last_path));
24813 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
24815 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects"));
24819 for (
const auto& val : json_patch)
24822 const auto get_value = [&val](
const std::string & op,
24823 const std::string & member,
24827 auto it = val.m_value.object->find(member);
24830 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
24833 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
24835 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'"));
24839 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
24841 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'"));
24849 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
24851 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects"));
24855 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
24856 const auto path = get_value(op,
"path",
true).template get<std::string>();
24859 switch (get_op(op))
24861 case patch_operations::add:
24863 operation_add(ptr, get_value(
"add",
"value",
false));
24867 case patch_operations::remove:
24869 operation_remove(ptr);
24873 case patch_operations::replace:
24876 result.
at(ptr) = get_value(
"replace",
"value",
false);
24880 case patch_operations::move:
24882 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
24892 operation_remove(from_ptr);
24893 operation_add(ptr, v);
24897 case patch_operations::copy:
24899 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
24908 operation_add(ptr, v);
24912 case patch_operations::test:
24914 bool success =
false;
24919 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
24927 if (JSON_HEDLEY_UNLIKELY(!success))
24929 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump()));
24939 JSON_THROW(parse_error::create(105, 0,
"operation value '" + op +
"' is invalid"));
24982 const std::string& path =
"")
24988 if (source == target)
24993 if (source.type() != target.type())
24998 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25003 switch (source.type())
25005 case value_t::array:
25009 while (i < source.size() && i < target.size())
25012 auto temp_diff =
diff(source[i], target[i], path +
"/" + std::to_string(i));
25013 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25022 while (i < source.size())
25029 {
"path", path +
"/" + std::to_string(i)}
25035 while (i < target.size())
25040 {
"path", path +
"/-"},
25041 {
"value", target[i]}
25049 case value_t::object:
25052 for (
auto it = source.cbegin(); it != source.cend(); ++it)
25055 const auto key = json_pointer::escape(it.key());
25057 if (target.find(it.key()) != target.end())
25060 auto temp_diff =
diff(it.value(), target[it.key()], path +
"/" + key);
25061 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25068 {
"op",
"remove"}, {
"path", path +
"/" + key}
25074 for (
auto it = target.cbegin(); it != target.cend(); ++it)
25076 if (source.find(it.key()) == source.end())
25079 const auto key = json_pointer::escape(it.key());
25082 {
"op",
"add"}, {
"path", path +
"/" + key},
25083 {
"value", it.value()}
25096 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25158 if (apply_patch.is_object())
25164 for (
auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
25166 if (it.value().is_null())
25178 *
this = apply_patch;
25194 NLOHMANN_BASIC_JSON_TPL_DECLARATION
25195 std::string
to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
25220 return nlohmann::detail::hash(j);
25228 struct less<::nlohmann::detail::value_t>
25234 bool operator()(nlohmann::detail::value_t lhs,
25235 nlohmann::detail::value_t rhs)
const noexcept
25237 return nlohmann::detail::operator<(lhs, rhs);
25242 #ifndef JSON_HAS_CPP_20
25251 is_nothrow_move_constructible<nlohmann::json>::value&&
25252 is_nothrow_move_assignable<nlohmann::json>::value
25275 JSON_HEDLEY_NON_NULL(1)
25276 inline
nlohmann::json operator "" _json(const
char* s, std::
size_t n)
25294 JSON_HEDLEY_NON_NULL(1)
25295 inline
nlohmann::json::json_pointer operator "" _json_pointer(const
char* s, std::
size_t n)
25304 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
25305 #pragma GCC diagnostic pop
25307 #if defined(__clang__)
25308 #pragma GCC diagnostic pop
25313 #undef JSON_INTERNAL_CATCH
25317 #undef JSON_PRIVATE_UNLESS_TESTED
25318 #undef JSON_HAS_CPP_14
25319 #undef JSON_HAS_CPP_17
25320 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
25321 #undef NLOHMANN_BASIC_JSON_TPL
25322 #undef JSON_EXPLICIT
25325 #undef JSON_HEDLEY_ALWAYS_INLINE
25326 #undef JSON_HEDLEY_ARM_VERSION
25327 #undef JSON_HEDLEY_ARM_VERSION_CHECK
25328 #undef JSON_HEDLEY_ARRAY_PARAM
25329 #undef JSON_HEDLEY_ASSUME
25330 #undef JSON_HEDLEY_BEGIN_C_DECLS
25331 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
25332 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
25333 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
25334 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
25335 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
25336 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
25337 #undef JSON_HEDLEY_CLANG_HAS_WARNING
25338 #undef JSON_HEDLEY_COMPCERT_VERSION
25339 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
25340 #undef JSON_HEDLEY_CONCAT
25341 #undef JSON_HEDLEY_CONCAT3
25342 #undef JSON_HEDLEY_CONCAT3_EX
25343 #undef JSON_HEDLEY_CONCAT_EX
25344 #undef JSON_HEDLEY_CONST
25345 #undef JSON_HEDLEY_CONSTEXPR
25346 #undef JSON_HEDLEY_CONST_CAST
25347 #undef JSON_HEDLEY_CPP_CAST
25348 #undef JSON_HEDLEY_CRAY_VERSION
25349 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
25350 #undef JSON_HEDLEY_C_DECL
25351 #undef JSON_HEDLEY_DEPRECATED
25352 #undef JSON_HEDLEY_DEPRECATED_FOR
25353 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
25354 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
25355 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
25356 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
25357 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
25358 #undef JSON_HEDLEY_DIAGNOSTIC_POP
25359 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
25360 #undef JSON_HEDLEY_DMC_VERSION
25361 #undef JSON_HEDLEY_DMC_VERSION_CHECK
25362 #undef JSON_HEDLEY_EMPTY_BASES
25363 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
25364 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
25365 #undef JSON_HEDLEY_END_C_DECLS
25366 #undef JSON_HEDLEY_FLAGS
25367 #undef JSON_HEDLEY_FLAGS_CAST
25368 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
25369 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
25370 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
25371 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
25372 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
25373 #undef JSON_HEDLEY_GCC_HAS_FEATURE
25374 #undef JSON_HEDLEY_GCC_HAS_WARNING
25375 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
25376 #undef JSON_HEDLEY_GCC_VERSION
25377 #undef JSON_HEDLEY_GCC_VERSION_CHECK
25378 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
25379 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
25380 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
25381 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
25382 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
25383 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
25384 #undef JSON_HEDLEY_GNUC_HAS_WARNING
25385 #undef JSON_HEDLEY_GNUC_VERSION
25386 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
25387 #undef JSON_HEDLEY_HAS_ATTRIBUTE
25388 #undef JSON_HEDLEY_HAS_BUILTIN
25389 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
25390 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
25391 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
25392 #undef JSON_HEDLEY_HAS_EXTENSION
25393 #undef JSON_HEDLEY_HAS_FEATURE
25394 #undef JSON_HEDLEY_HAS_WARNING
25395 #undef JSON_HEDLEY_IAR_VERSION
25396 #undef JSON_HEDLEY_IAR_VERSION_CHECK
25397 #undef JSON_HEDLEY_IBM_VERSION
25398 #undef JSON_HEDLEY_IBM_VERSION_CHECK
25399 #undef JSON_HEDLEY_IMPORT
25400 #undef JSON_HEDLEY_INLINE
25401 #undef JSON_HEDLEY_INTEL_VERSION
25402 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
25403 #undef JSON_HEDLEY_IS_CONSTANT
25404 #undef JSON_HEDLEY_IS_CONSTEXPR_
25405 #undef JSON_HEDLEY_LIKELY
25406 #undef JSON_HEDLEY_MALLOC
25407 #undef JSON_HEDLEY_MESSAGE
25408 #undef JSON_HEDLEY_MSVC_VERSION
25409 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
25410 #undef JSON_HEDLEY_NEVER_INLINE
25411 #undef JSON_HEDLEY_NON_NULL
25412 #undef JSON_HEDLEY_NO_ESCAPE
25413 #undef JSON_HEDLEY_NO_RETURN
25414 #undef JSON_HEDLEY_NO_THROW
25415 #undef JSON_HEDLEY_NULL
25416 #undef JSON_HEDLEY_PELLES_VERSION
25417 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
25418 #undef JSON_HEDLEY_PGI_VERSION
25419 #undef JSON_HEDLEY_PGI_VERSION_CHECK
25420 #undef JSON_HEDLEY_PREDICT
25421 #undef JSON_HEDLEY_PRINTF_FORMAT
25422 #undef JSON_HEDLEY_PRIVATE
25423 #undef JSON_HEDLEY_PUBLIC
25424 #undef JSON_HEDLEY_PURE
25425 #undef JSON_HEDLEY_REINTERPRET_CAST
25426 #undef JSON_HEDLEY_REQUIRE
25427 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
25428 #undef JSON_HEDLEY_REQUIRE_MSG
25429 #undef JSON_HEDLEY_RESTRICT
25431 #undef JSON_HEDLEY_SENTINEL
25432 #undef JSON_HEDLEY_STATIC_ASSERT
25433 #undef JSON_HEDLEY_STATIC_CAST
25434 #undef JSON_HEDLEY_STRINGIFY
25435 #undef JSON_HEDLEY_STRINGIFY_EX
25436 #undef JSON_HEDLEY_SUNPRO_VERSION
25437 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
25438 #undef JSON_HEDLEY_TINYC_VERSION
25439 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
25440 #undef JSON_HEDLEY_TI_ARMCL_VERSION
25441 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
25442 #undef JSON_HEDLEY_TI_CL2000_VERSION
25443 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
25444 #undef JSON_HEDLEY_TI_CL430_VERSION
25445 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
25446 #undef JSON_HEDLEY_TI_CL6X_VERSION
25447 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
25448 #undef JSON_HEDLEY_TI_CL7X_VERSION
25449 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
25450 #undef JSON_HEDLEY_TI_CLPRU_VERSION
25451 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
25452 #undef JSON_HEDLEY_TI_VERSION
25453 #undef JSON_HEDLEY_TI_VERSION_CHECK
25454 #undef JSON_HEDLEY_UNAVAILABLE
25455 #undef JSON_HEDLEY_UNLIKELY
25456 #undef JSON_HEDLEY_UNPREDICTABLE
25457 #undef JSON_HEDLEY_UNREACHABLE
25458 #undef JSON_HEDLEY_UNREACHABLE_RETURN
25459 #undef JSON_HEDLEY_VERSION
25460 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
25461 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
25462 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
25463 #undef JSON_HEDLEY_VERSION_ENCODE
25464 #undef JSON_HEDLEY_WARNING
25467 #undef JSON_HEDLEY_FALL_THROUGH
25471 #endif // INCLUDE_NLOHMANN_JSON_HPP_