30 #ifndef INCLUDE_NLOHMANN_JSON_HPP_
31 #define INCLUDE_NLOHMANN_JSON_HPP_
33 #define NLOHMANN_JSON_VERSION_MAJOR 3
34 #define NLOHMANN_JSON_VERSION_MINOR 7
35 #define NLOHMANN_JSON_VERSION_PATCH 3
42 #include <initializer_list>
62 #include <forward_list>
67 #include <type_traits>
68 #include <unordered_map>
99 constexpr
operator size_t()
const
125 #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 13)
126 #if defined(JSON_HEDLEY_VERSION)
127 #undef JSON_HEDLEY_VERSION
129 #define JSON_HEDLEY_VERSION 13
131 #if defined(JSON_HEDLEY_STRINGIFY_EX)
132 #undef JSON_HEDLEY_STRINGIFY_EX
134 #define JSON_HEDLEY_STRINGIFY_EX(x) #x
136 #if defined(JSON_HEDLEY_STRINGIFY)
137 #undef JSON_HEDLEY_STRINGIFY
139 #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
141 #if defined(JSON_HEDLEY_CONCAT_EX)
142 #undef JSON_HEDLEY_CONCAT_EX
144 #define JSON_HEDLEY_CONCAT_EX(a,b) a##b
146 #if defined(JSON_HEDLEY_CONCAT)
147 #undef JSON_HEDLEY_CONCAT
149 #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
151 #if defined(JSON_HEDLEY_CONCAT3_EX)
152 #undef JSON_HEDLEY_CONCAT3_EX
154 #define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
156 #if defined(JSON_HEDLEY_CONCAT3)
157 #undef JSON_HEDLEY_CONCAT3
159 #define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
161 #if defined(JSON_HEDLEY_VERSION_ENCODE)
162 #undef JSON_HEDLEY_VERSION_ENCODE
164 #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
166 #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
167 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
169 #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
171 #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
172 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
174 #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
176 #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
177 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
179 #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
181 #if defined(JSON_HEDLEY_GNUC_VERSION)
182 #undef JSON_HEDLEY_GNUC_VERSION
184 #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
185 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
186 #elif defined(__GNUC__)
187 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
190 #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
191 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
193 #if defined(JSON_HEDLEY_GNUC_VERSION)
194 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
196 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
199 #if defined(JSON_HEDLEY_MSVC_VERSION)
200 #undef JSON_HEDLEY_MSVC_VERSION
202 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000)
203 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
204 #elif defined(_MSC_FULL_VER)
205 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
206 #elif defined(_MSC_VER)
207 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
210 #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
211 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
213 #if !defined(_MSC_VER)
214 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
215 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
216 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
217 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
218 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
220 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
223 #if defined(JSON_HEDLEY_INTEL_VERSION)
224 #undef JSON_HEDLEY_INTEL_VERSION
226 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE)
227 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
228 #elif defined(__INTEL_COMPILER)
229 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
232 #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
233 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
235 #if defined(JSON_HEDLEY_INTEL_VERSION)
236 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
238 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
241 #if defined(JSON_HEDLEY_PGI_VERSION)
242 #undef JSON_HEDLEY_PGI_VERSION
244 #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
245 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
248 #if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
249 #undef JSON_HEDLEY_PGI_VERSION_CHECK
251 #if defined(JSON_HEDLEY_PGI_VERSION)
252 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
254 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
257 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
258 #undef JSON_HEDLEY_SUNPRO_VERSION
260 #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
261 #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)
262 #elif defined(__SUNPRO_C)
263 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
264 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
265 #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)
266 #elif defined(__SUNPRO_CC)
267 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
270 #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
271 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
273 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
274 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
276 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
279 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
280 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
282 #if defined(__EMSCRIPTEN__)
283 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
286 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
287 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
289 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
290 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
292 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
295 #if defined(JSON_HEDLEY_ARM_VERSION)
296 #undef JSON_HEDLEY_ARM_VERSION
298 #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
299 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
300 #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
301 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
304 #if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
305 #undef JSON_HEDLEY_ARM_VERSION_CHECK
307 #if defined(JSON_HEDLEY_ARM_VERSION)
308 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
310 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
313 #if defined(JSON_HEDLEY_IBM_VERSION)
314 #undef JSON_HEDLEY_IBM_VERSION
316 #if defined(__ibmxl__)
317 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
318 #elif defined(__xlC__) && defined(__xlC_ver__)
319 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
320 #elif defined(__xlC__)
321 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
324 #if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
325 #undef JSON_HEDLEY_IBM_VERSION_CHECK
327 #if defined(JSON_HEDLEY_IBM_VERSION)
328 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
330 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
333 #if defined(JSON_HEDLEY_TI_VERSION)
334 #undef JSON_HEDLEY_TI_VERSION
337 defined(__TI_COMPILER_VERSION__) && \
339 defined(__TMS470__) || defined(__TI_ARM__) || \
340 defined(__MSP430__) || \
341 defined(__TMS320C2000__) \
343 #if (__TI_COMPILER_VERSION__ >= 16000000)
344 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
348 #if defined(JSON_HEDLEY_TI_VERSION_CHECK)
349 #undef JSON_HEDLEY_TI_VERSION_CHECK
351 #if defined(JSON_HEDLEY_TI_VERSION)
352 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
354 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
357 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
358 #undef JSON_HEDLEY_TI_CL2000_VERSION
360 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
361 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
364 #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
365 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
367 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
368 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
370 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
373 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
374 #undef JSON_HEDLEY_TI_CL430_VERSION
376 #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
377 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
380 #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
381 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
383 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
384 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
386 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
389 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
390 #undef JSON_HEDLEY_TI_ARMCL_VERSION
392 #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
393 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
396 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
397 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
399 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
400 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
402 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
405 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
406 #undef JSON_HEDLEY_TI_CL6X_VERSION
408 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
409 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
412 #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
413 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
415 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
416 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
418 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
421 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
422 #undef JSON_HEDLEY_TI_CL7X_VERSION
424 #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
425 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
428 #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
429 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
431 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
432 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
434 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
437 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
438 #undef JSON_HEDLEY_TI_CLPRU_VERSION
440 #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
441 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
444 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
445 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
447 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
448 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
450 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
453 #if defined(JSON_HEDLEY_CRAY_VERSION)
454 #undef JSON_HEDLEY_CRAY_VERSION
457 #if defined(_RELEASE_PATCHLEVEL)
458 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
460 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
464 #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
465 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
467 #if defined(JSON_HEDLEY_CRAY_VERSION)
468 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
470 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
473 #if defined(JSON_HEDLEY_IAR_VERSION)
474 #undef JSON_HEDLEY_IAR_VERSION
476 #if defined(__IAR_SYSTEMS_ICC__)
478 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
480 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(VER / 100, __VER__ % 100, 0)
484 #if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
485 #undef JSON_HEDLEY_IAR_VERSION_CHECK
487 #if defined(JSON_HEDLEY_IAR_VERSION)
488 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
490 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
493 #if defined(JSON_HEDLEY_TINYC_VERSION)
494 #undef JSON_HEDLEY_TINYC_VERSION
496 #if defined(__TINYC__)
497 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
500 #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
501 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
503 #if defined(JSON_HEDLEY_TINYC_VERSION)
504 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
506 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
509 #if defined(JSON_HEDLEY_DMC_VERSION)
510 #undef JSON_HEDLEY_DMC_VERSION
513 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
516 #if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
517 #undef JSON_HEDLEY_DMC_VERSION_CHECK
519 #if defined(JSON_HEDLEY_DMC_VERSION)
520 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
522 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
525 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
526 #undef JSON_HEDLEY_COMPCERT_VERSION
528 #if defined(__COMPCERT_VERSION__)
529 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
532 #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
533 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
535 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
536 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
538 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
541 #if defined(JSON_HEDLEY_PELLES_VERSION)
542 #undef JSON_HEDLEY_PELLES_VERSION
544 #if defined(__POCC__)
545 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
548 #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
549 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
551 #if defined(JSON_HEDLEY_PELLES_VERSION)
552 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
554 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
557 #if defined(JSON_HEDLEY_GCC_VERSION)
558 #undef JSON_HEDLEY_GCC_VERSION
561 defined(JSON_HEDLEY_GNUC_VERSION) && \
562 !defined(__clang__) && \
563 !defined(JSON_HEDLEY_INTEL_VERSION) && \
564 !defined(JSON_HEDLEY_PGI_VERSION) && \
565 !defined(JSON_HEDLEY_ARM_VERSION) && \
566 !defined(JSON_HEDLEY_TI_VERSION) && \
567 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
568 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
569 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
570 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
571 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
572 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
573 !defined(__COMPCERT__)
574 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
577 #if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
578 #undef JSON_HEDLEY_GCC_VERSION_CHECK
580 #if defined(JSON_HEDLEY_GCC_VERSION)
581 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
583 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
586 #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
587 #undef JSON_HEDLEY_HAS_ATTRIBUTE
589 #if defined(__has_attribute)
590 #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
592 #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
595 #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
596 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
598 #if defined(__has_attribute)
599 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute)
601 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
604 #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
605 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
607 #if defined(__has_attribute)
608 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute)
610 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
613 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
614 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
617 defined(__has_cpp_attribute) && \
618 defined(__cplusplus) && \
619 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
620 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
622 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
625 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
626 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
628 #if !defined(__cplusplus) || !defined(__has_cpp_attribute)
629 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
631 !defined(JSON_HEDLEY_PGI_VERSION) && \
632 !defined(JSON_HEDLEY_IAR_VERSION) && \
633 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
634 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
635 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
637 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
640 #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
641 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
643 #if defined(__has_cpp_attribute) && defined(__cplusplus)
644 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
646 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
649 #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
650 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
652 #if defined(__has_cpp_attribute) && defined(__cplusplus)
653 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
655 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
658 #if defined(JSON_HEDLEY_HAS_BUILTIN)
659 #undef JSON_HEDLEY_HAS_BUILTIN
661 #if defined(__has_builtin)
662 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
664 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
667 #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
668 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
670 #if defined(__has_builtin)
671 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
673 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
676 #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
677 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
679 #if defined(__has_builtin)
680 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
682 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
685 #if defined(JSON_HEDLEY_HAS_FEATURE)
686 #undef JSON_HEDLEY_HAS_FEATURE
688 #if defined(__has_feature)
689 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
691 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
694 #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
695 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
697 #if defined(__has_feature)
698 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
700 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
703 #if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
704 #undef JSON_HEDLEY_GCC_HAS_FEATURE
706 #if defined(__has_feature)
707 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
709 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
712 #if defined(JSON_HEDLEY_HAS_EXTENSION)
713 #undef JSON_HEDLEY_HAS_EXTENSION
715 #if defined(__has_extension)
716 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
718 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
721 #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
722 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
724 #if defined(__has_extension)
725 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
727 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
730 #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
731 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
733 #if defined(__has_extension)
734 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
736 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
739 #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
740 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
742 #if defined(__has_declspec_attribute)
743 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
745 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
748 #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
749 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
751 #if defined(__has_declspec_attribute)
752 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
754 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
757 #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
758 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
760 #if defined(__has_declspec_attribute)
761 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
763 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
766 #if defined(JSON_HEDLEY_HAS_WARNING)
767 #undef JSON_HEDLEY_HAS_WARNING
769 #if defined(__has_warning)
770 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
772 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
775 #if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
776 #undef JSON_HEDLEY_GNUC_HAS_WARNING
778 #if defined(__has_warning)
779 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
781 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
784 #if defined(JSON_HEDLEY_GCC_HAS_WARNING)
785 #undef JSON_HEDLEY_GCC_HAS_WARNING
787 #if defined(__has_warning)
788 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
790 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
795 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
796 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
798 #if defined(__cplusplus)
799 # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
800 # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
801 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
802 JSON_HEDLEY_DIAGNOSTIC_PUSH \
803 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
804 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
806 JSON_HEDLEY_DIAGNOSTIC_POP
808 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
809 JSON_HEDLEY_DIAGNOSTIC_PUSH \
810 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
812 JSON_HEDLEY_DIAGNOSTIC_POP
816 #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
817 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
820 #if defined(JSON_HEDLEY_CONST_CAST)
821 #undef JSON_HEDLEY_CONST_CAST
823 #if defined(__cplusplus)
824 # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
826 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
827 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
828 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
829 # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
830 JSON_HEDLEY_DIAGNOSTIC_PUSH \
831 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
833 JSON_HEDLEY_DIAGNOSTIC_POP \
836 # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
839 #if defined(JSON_HEDLEY_REINTERPRET_CAST)
840 #undef JSON_HEDLEY_REINTERPRET_CAST
842 #if defined(__cplusplus)
843 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
845 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
848 #if defined(JSON_HEDLEY_STATIC_CAST)
849 #undef JSON_HEDLEY_STATIC_CAST
851 #if defined(__cplusplus)
852 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
854 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
857 #if defined(JSON_HEDLEY_CPP_CAST)
858 #undef JSON_HEDLEY_CPP_CAST
860 #if defined(__cplusplus)
861 # if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
862 # define JSON_HEDLEY_CPP_CAST(T, expr) \
863 JSON_HEDLEY_DIAGNOSTIC_PUSH \
864 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
866 JSON_HEDLEY_DIAGNOSTIC_POP
867 # elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
868 # define JSON_HEDLEY_CPP_CAST(T, expr) \
869 JSON_HEDLEY_DIAGNOSTIC_PUSH \
870 _Pragma("diag_suppress=Pe137") \
871 JSON_HEDLEY_DIAGNOSTIC_POP \
873 # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
876 # define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
880 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
881 defined(__clang__) || \
882 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
883 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
884 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
885 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
886 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
887 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
888 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
889 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
890 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
891 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
892 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
893 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
894 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
895 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
896 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
897 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
898 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
899 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
900 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
902 #define JSON_HEDLEY_PRAGMA(value)
905 #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
906 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
908 #if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
909 #undef JSON_HEDLEY_DIAGNOSTIC_POP
911 #if defined(__clang__)
912 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
913 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
914 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
915 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
916 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
917 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
918 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
919 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
920 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
921 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
922 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
923 #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
924 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
925 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
927 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
928 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
929 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
930 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
931 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
932 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
933 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
934 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
935 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
936 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
937 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
939 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
940 #define JSON_HEDLEY_DIAGNOSTIC_POP
943 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
944 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
946 #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
947 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
948 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
949 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
950 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
951 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
952 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
953 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
954 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
955 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
957 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
958 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
959 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
960 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
961 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
962 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
963 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
964 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
965 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
966 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
967 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
968 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
969 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
970 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
971 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
972 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
973 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
974 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
975 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
976 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
978 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
981 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
982 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
984 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
985 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
986 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
987 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
988 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
989 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
990 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
991 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
992 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
993 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
995 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
996 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
997 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
998 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
999 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1000 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1001 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1002 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1003 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1005 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1008 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1009 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1011 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1012 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1013 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1014 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1015 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1016 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1017 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1018 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1019 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1020 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1021 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1022 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1024 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1025 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1026 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1027 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1028 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1029 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1031 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1034 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1035 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1037 #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1038 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1039 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1040 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1041 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1042 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1044 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1047 #if defined(JSON_HEDLEY_DEPRECATED)
1048 #undef JSON_HEDLEY_DEPRECATED
1050 #if defined(JSON_HEDLEY_DEPRECATED_FOR)
1051 #undef JSON_HEDLEY_DEPRECATED_FOR
1053 #if JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0)
1054 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1055 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1056 #elif defined(__cplusplus) && (__cplusplus >= 201402L)
1057 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1058 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1060 JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) || \
1061 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1062 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1063 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1064 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1065 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1066 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1067 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1068 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1069 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1070 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1071 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1072 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1074 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1075 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1076 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1077 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1078 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1079 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1080 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1081 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1082 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1083 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1084 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1085 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1086 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1087 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1088 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1089 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1091 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1092 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0)
1093 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1094 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1095 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1096 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1097 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1099 #define JSON_HEDLEY_DEPRECATED(since)
1100 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1103 #if defined(JSON_HEDLEY_UNAVAILABLE)
1104 #undef JSON_HEDLEY_UNAVAILABLE
1107 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1108 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1109 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1110 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1112 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1115 #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1116 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
1118 #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1119 #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1121 #if (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1122 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1123 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1124 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1125 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1126 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1128 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1129 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1130 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1131 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1132 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1133 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1134 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1135 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1136 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1137 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1138 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1139 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1140 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1141 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1142 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1143 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1144 #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1145 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1146 #elif defined(_Check_return_)
1147 #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1148 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1150 #define JSON_HEDLEY_WARN_UNUSED_RESULT
1151 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1154 #if defined(JSON_HEDLEY_SENTINEL)
1155 #undef JSON_HEDLEY_SENTINEL
1158 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1159 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1160 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1161 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0)
1162 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1164 #define JSON_HEDLEY_SENTINEL(position)
1167 #if defined(JSON_HEDLEY_NO_RETURN)
1168 #undef JSON_HEDLEY_NO_RETURN
1170 #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1171 #define JSON_HEDLEY_NO_RETURN __noreturn
1172 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1173 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1174 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1175 #define JSON_HEDLEY_NO_RETURN _Noreturn
1176 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1177 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1179 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1180 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1181 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1182 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1183 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1184 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1185 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1186 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1187 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1188 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1189 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1190 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1191 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1192 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1193 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1194 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1195 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1196 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1197 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1198 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
1199 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1200 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1201 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1202 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1203 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1204 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1205 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1207 #define JSON_HEDLEY_NO_RETURN
1210 #if defined(JSON_HEDLEY_NO_ESCAPE)
1211 #undef JSON_HEDLEY_NO_ESCAPE
1213 #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1214 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1216 #define JSON_HEDLEY_NO_ESCAPE
1219 #if defined(JSON_HEDLEY_UNREACHABLE)
1220 #undef JSON_HEDLEY_UNREACHABLE
1222 #if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1223 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1225 #if defined(JSON_HEDLEY_ASSUME)
1226 #undef JSON_HEDLEY_ASSUME
1229 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1230 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1231 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1232 #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1233 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1235 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1236 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1237 #if defined(__cplusplus)
1238 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1240 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1244 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1245 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1246 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1247 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1248 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5)
1249 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1250 #elif defined(JSON_HEDLEY_ASSUME)
1251 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1253 #if !defined(JSON_HEDLEY_ASSUME)
1254 #if defined(JSON_HEDLEY_UNREACHABLE)
1255 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1257 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1260 #if defined(JSON_HEDLEY_UNREACHABLE)
1262 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1263 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1264 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1266 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1269 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1271 #if !defined(JSON_HEDLEY_UNREACHABLE)
1272 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1276 #if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1277 #pragma clang diagnostic ignored "-Wpedantic"
1279 #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1280 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1282 #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1283 #if defined(__clang__)
1284 #pragma clang diagnostic ignored "-Wvariadic-macros"
1285 #elif defined(JSON_HEDLEY_GCC_VERSION)
1286 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1289 #if defined(JSON_HEDLEY_NON_NULL)
1290 #undef JSON_HEDLEY_NON_NULL
1293 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1294 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1295 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1296 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1297 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1299 #define JSON_HEDLEY_NON_NULL(...)
1303 #if defined(JSON_HEDLEY_PRINTF_FORMAT)
1304 #undef JSON_HEDLEY_PRINTF_FORMAT
1306 #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1307 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1308 #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1309 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1311 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1312 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1313 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1314 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1315 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1316 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1317 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1318 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1319 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1320 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1321 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1322 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1323 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1324 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1325 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1326 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1327 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1328 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1329 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1331 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1334 #if defined(JSON_HEDLEY_CONSTEXPR)
1335 #undef JSON_HEDLEY_CONSTEXPR
1337 #if defined(__cplusplus)
1338 #if __cplusplus >= 201103L
1339 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1342 #if !defined(JSON_HEDLEY_CONSTEXPR)
1343 #define JSON_HEDLEY_CONSTEXPR
1346 #if defined(JSON_HEDLEY_PREDICT)
1347 #undef JSON_HEDLEY_PREDICT
1349 #if defined(JSON_HEDLEY_LIKELY)
1350 #undef JSON_HEDLEY_LIKELY
1352 #if defined(JSON_HEDLEY_UNLIKELY)
1353 #undef JSON_HEDLEY_UNLIKELY
1355 #if defined(JSON_HEDLEY_UNPREDICTABLE)
1356 #undef JSON_HEDLEY_UNPREDICTABLE
1358 #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1359 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1362 JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) || \
1363 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0)
1364 # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1365 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1366 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1367 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1368 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1370 JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) || \
1371 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1372 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1373 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1374 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1375 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1376 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1377 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1378 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1379 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1380 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1381 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1382 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1383 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1384 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0)
1385 # define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1386 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1387 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1389 double hedley_probability_ = (probability); \
1390 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1392 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1394 double hedley_probability_ = (probability); \
1395 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1397 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1398 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1400 # define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1401 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1402 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1403 # define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1404 # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1406 #if !defined(JSON_HEDLEY_UNPREDICTABLE)
1407 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1410 #if defined(JSON_HEDLEY_MALLOC)
1411 #undef JSON_HEDLEY_MALLOC
1414 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1415 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1416 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1417 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1418 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1419 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1420 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1421 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1422 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1423 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1424 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1425 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1426 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1427 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1428 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1429 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1430 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1431 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1432 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1433 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1434 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0)
1435 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1437 #define JSON_HEDLEY_MALLOC
1440 #if defined(JSON_HEDLEY_PURE)
1441 #undef JSON_HEDLEY_PURE
1444 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1445 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1446 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1447 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1448 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1449 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1450 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1451 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1452 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1453 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1454 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1455 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1456 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1457 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1458 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1459 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1460 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1461 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1462 # define JSON_HEDLEY_PURE __attribute__((__pure__))
1463 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1464 # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1465 #elif defined(__cplusplus) && \
1467 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1468 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1469 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1471 # define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1473 # define JSON_HEDLEY_PURE
1476 #if defined(JSON_HEDLEY_CONST)
1477 #undef JSON_HEDLEY_CONST
1480 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1481 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1482 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1483 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1484 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1485 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1486 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1487 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1488 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1489 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1490 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1491 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1492 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1493 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1494 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1495 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1496 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1497 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1498 #define JSON_HEDLEY_CONST __attribute__((__const__))
1500 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1501 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1503 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1506 #if defined(JSON_HEDLEY_RESTRICT)
1507 #undef JSON_HEDLEY_RESTRICT
1509 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1510 #define JSON_HEDLEY_RESTRICT restrict
1512 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1513 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1514 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1515 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1516 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1517 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1518 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1519 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1520 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1521 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1522 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1523 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1525 #define JSON_HEDLEY_RESTRICT __restrict
1526 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1527 #define JSON_HEDLEY_RESTRICT _Restrict
1529 #define JSON_HEDLEY_RESTRICT
1532 #if defined(JSON_HEDLEY_INLINE)
1533 #undef JSON_HEDLEY_INLINE
1536 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1537 (defined(__cplusplus) && (__cplusplus >= 199711L))
1538 #define JSON_HEDLEY_INLINE inline
1540 defined(JSON_HEDLEY_GCC_VERSION) || \
1541 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1542 #define JSON_HEDLEY_INLINE __inline__
1544 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1545 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1546 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1547 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1548 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1549 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1550 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1551 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1552 #define JSON_HEDLEY_INLINE __inline
1554 #define JSON_HEDLEY_INLINE
1557 #if defined(JSON_HEDLEY_ALWAYS_INLINE)
1558 #undef JSON_HEDLEY_ALWAYS_INLINE
1561 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1562 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1563 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1564 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1565 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1566 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1567 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1568 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1569 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1570 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1571 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1572 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1573 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1574 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1575 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1576 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1577 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1578 # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1579 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0)
1580 # define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1581 #elif defined(__cplusplus) && \
1583 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1584 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1585 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1586 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1587 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1588 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1590 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1591 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1592 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1594 # define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1597 #if defined(JSON_HEDLEY_NEVER_INLINE)
1598 #undef JSON_HEDLEY_NEVER_INLINE
1601 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1602 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1603 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1604 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1605 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1606 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1607 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1608 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1609 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1610 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1611 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1612 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1613 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1614 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1615 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1616 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1617 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1618 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1619 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
1620 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1621 #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1622 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1623 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1624 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1625 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1626 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1627 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1628 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1629 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1630 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1632 #define JSON_HEDLEY_NEVER_INLINE
1635 #if defined(JSON_HEDLEY_PRIVATE)
1636 #undef JSON_HEDLEY_PRIVATE
1638 #if defined(JSON_HEDLEY_PUBLIC)
1639 #undef JSON_HEDLEY_PUBLIC
1641 #if defined(JSON_HEDLEY_IMPORT)
1642 #undef JSON_HEDLEY_IMPORT
1644 #if defined(_WIN32) || defined(__CYGWIN__)
1645 # define JSON_HEDLEY_PRIVATE
1646 # define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1647 # define JSON_HEDLEY_IMPORT __declspec(dllimport)
1650 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1651 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1652 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1653 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1654 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1655 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1657 defined(__TI_EABI__) && \
1659 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1660 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1663 # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1664 # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1666 # define JSON_HEDLEY_PRIVATE
1667 # define JSON_HEDLEY_PUBLIC
1669 # define JSON_HEDLEY_IMPORT extern
1672 #if defined(JSON_HEDLEY_NO_THROW)
1673 #undef JSON_HEDLEY_NO_THROW
1676 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1677 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1678 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1679 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1681 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1682 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1683 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1685 #define JSON_HEDLEY_NO_THROW
1688 #if defined(JSON_HEDLEY_FALL_THROUGH)
1689 #undef JSON_HEDLEY_FALL_THROUGH
1692 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
1693 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0)
1694 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1695 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1696 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1697 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1698 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1699 #elif defined(__fallthrough)
1700 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1702 #define JSON_HEDLEY_FALL_THROUGH
1705 #if defined(JSON_HEDLEY_RETURNS_NON_NULL)
1706 #undef JSON_HEDLEY_RETURNS_NON_NULL
1709 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1710 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
1711 #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
1712 #elif defined(_Ret_notnull_)
1713 #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
1715 #define JSON_HEDLEY_RETURNS_NON_NULL
1718 #if defined(JSON_HEDLEY_ARRAY_PARAM)
1719 #undef JSON_HEDLEY_ARRAY_PARAM
1722 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1723 !defined(__STDC_NO_VLA__) && \
1724 !defined(__cplusplus) && \
1725 !defined(JSON_HEDLEY_PGI_VERSION) && \
1726 !defined(JSON_HEDLEY_TINYC_VERSION)
1727 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1729 #define JSON_HEDLEY_ARRAY_PARAM(name)
1732 #if defined(JSON_HEDLEY_IS_CONSTANT)
1733 #undef JSON_HEDLEY_IS_CONSTANT
1735 #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1736 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1740 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1741 #undef JSON_HEDLEY_IS_CONSTEXPR_
1744 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1745 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1746 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1747 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1748 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1749 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1750 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1751 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1752 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0)
1753 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1755 #if !defined(__cplusplus)
1757 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1758 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1759 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1760 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1761 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1762 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1763 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1764 #if defined(__INTPTR_TYPE__)
1765 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1768 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1772 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
1773 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
1774 !defined(JSON_HEDLEY_PGI_VERSION) && \
1775 !defined(JSON_HEDLEY_IAR_VERSION)) || \
1776 JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \
1777 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1778 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1779 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1780 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1781 #if defined(__INTPTR_TYPE__)
1782 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1785 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1788 defined(JSON_HEDLEY_GCC_VERSION) || \
1789 defined(JSON_HEDLEY_INTEL_VERSION) || \
1790 defined(JSON_HEDLEY_TINYC_VERSION) || \
1791 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
1792 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
1793 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
1794 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
1795 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
1796 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
1798 # define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1802 ((void*) ((expr) * 0L) ) : \
1803 ((struct { char v[sizeof(void) * 2]; } *) 1) \
1809 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1810 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1811 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1813 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
1815 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1816 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
1818 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
1821 #if defined(JSON_HEDLEY_BEGIN_C_DECLS)
1822 #undef JSON_HEDLEY_BEGIN_C_DECLS
1824 #if defined(JSON_HEDLEY_END_C_DECLS)
1825 #undef JSON_HEDLEY_END_C_DECLS
1827 #if defined(JSON_HEDLEY_C_DECL)
1828 #undef JSON_HEDLEY_C_DECL
1830 #if defined(__cplusplus)
1831 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
1832 #define JSON_HEDLEY_END_C_DECLS }
1833 #define JSON_HEDLEY_C_DECL extern "C"
1835 #define JSON_HEDLEY_BEGIN_C_DECLS
1836 #define JSON_HEDLEY_END_C_DECLS
1837 #define JSON_HEDLEY_C_DECL
1840 #if defined(JSON_HEDLEY_STATIC_ASSERT)
1841 #undef JSON_HEDLEY_STATIC_ASSERT
1844 !defined(__cplusplus) && ( \
1845 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
1846 JSON_HEDLEY_HAS_FEATURE(c_static_assert) || \
1847 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
1848 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1849 defined(_Static_assert) \
1851 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
1853 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
1854 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0)
1855 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
1857 # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
1860 #if defined(JSON_HEDLEY_NULL)
1861 #undef JSON_HEDLEY_NULL
1863 #if defined(__cplusplus)
1864 #if __cplusplus >= 201103L
1865 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
1867 #define JSON_HEDLEY_NULL NULL
1869 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
1872 #define JSON_HEDLEY_NULL NULL
1874 #define JSON_HEDLEY_NULL ((void*) 0)
1877 #if defined(JSON_HEDLEY_MESSAGE)
1878 #undef JSON_HEDLEY_MESSAGE
1880 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1881 # define JSON_HEDLEY_MESSAGE(msg) \
1882 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1883 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
1884 JSON_HEDLEY_PRAGMA(message msg) \
1885 JSON_HEDLEY_DIAGNOSTIC_POP
1887 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
1888 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1889 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
1890 #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
1891 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
1892 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1893 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
1894 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
1895 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
1897 # define JSON_HEDLEY_MESSAGE(msg)
1900 #if defined(JSON_HEDLEY_WARNING)
1901 #undef JSON_HEDLEY_WARNING
1903 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1904 # define JSON_HEDLEY_WARNING(msg) \
1905 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1906 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
1907 JSON_HEDLEY_PRAGMA(clang warning msg) \
1908 JSON_HEDLEY_DIAGNOSTIC_POP
1910 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
1911 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
1912 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1913 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
1914 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1915 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
1917 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
1920 #if defined(JSON_HEDLEY_REQUIRE)
1921 #undef JSON_HEDLEY_REQUIRE
1923 #if defined(JSON_HEDLEY_REQUIRE_MSG)
1924 #undef JSON_HEDLEY_REQUIRE_MSG
1926 #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
1927 # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
1928 # define JSON_HEDLEY_REQUIRE(expr) \
1929 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1930 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
1931 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
1932 JSON_HEDLEY_DIAGNOSTIC_POP
1933 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
1934 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1935 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
1936 __attribute__((diagnose_if(!(expr), msg, "error"))) \
1937 JSON_HEDLEY_DIAGNOSTIC_POP
1939 # define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
1940 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
1943 # define JSON_HEDLEY_REQUIRE(expr)
1944 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
1947 #if defined(JSON_HEDLEY_FLAGS)
1948 #undef JSON_HEDLEY_FLAGS
1950 #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum)
1951 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
1954 #if defined(JSON_HEDLEY_FLAGS_CAST)
1955 #undef JSON_HEDLEY_FLAGS_CAST
1957 #if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
1958 # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
1959 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1960 _Pragma("warning(disable:188)") \
1962 JSON_HEDLEY_DIAGNOSTIC_POP \
1965 # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
1968 #if defined(JSON_HEDLEY_EMPTY_BASES)
1969 #undef JSON_HEDLEY_EMPTY_BASES
1971 #if JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)
1972 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
1974 #define JSON_HEDLEY_EMPTY_BASES
1979 #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
1980 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
1982 #if defined(__clang__)
1983 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
1985 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1988 #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
1989 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
1991 #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
1993 #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
1994 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
1996 #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
1998 #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
1999 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2001 #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2003 #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2004 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2006 #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2008 #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2009 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2011 #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2013 #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2014 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2016 #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2018 #if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2019 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2021 #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2030 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2031 #if defined(__clang__)
2032 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2033 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2035 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2036 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2037 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2043 #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
2044 #define JSON_HAS_CPP_17
2045 #define JSON_HAS_CPP_14
2046 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2047 #define JSON_HAS_CPP_14
2051 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
2052 #pragma GCC diagnostic push
2053 #pragma GCC diagnostic ignored "-Wfloat-equal"
2057 #if defined(__clang__)
2058 #pragma GCC diagnostic push
2059 #pragma GCC diagnostic ignored "-Wdocumentation"
2063 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2064 #define JSON_THROW(exception) throw exception
2065 #define JSON_TRY try
2066 #define JSON_CATCH(exception) catch(exception)
2067 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2070 #define JSON_THROW(exception) std::abort()
2071 #define JSON_TRY if(true)
2072 #define JSON_CATCH(exception) if(false)
2073 #define JSON_INTERNAL_CATCH(exception) if(false)
2077 #if defined(JSON_THROW_USER)
2079 #define JSON_THROW JSON_THROW_USER
2081 #if defined(JSON_TRY_USER)
2083 #define JSON_TRY JSON_TRY_USER
2085 #if defined(JSON_CATCH_USER)
2087 #define JSON_CATCH JSON_CATCH_USER
2088 #undef JSON_INTERNAL_CATCH
2089 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2091 #if defined(JSON_INTERNAL_CATCH_USER)
2092 #undef JSON_INTERNAL_CATCH
2093 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2101 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2102 template<typename BasicJsonType> \
2103 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2105 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2106 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2107 auto it = std::find_if(std::begin(m), std::end(m), \
2108 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2110 return ej_pair.first == e; \
2112 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2114 template<typename BasicJsonType> \
2115 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2117 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2118 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2119 auto it = std::find_if(std::begin(m), std::end(m), \
2120 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2122 return ej_pair.second == j; \
2124 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2130 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2131 template<template<typename, typename, typename...> class ObjectType, \
2132 template<typename, typename...> class ArrayType, \
2133 class StringType, class BooleanType, class NumberIntegerType, \
2134 class NumberUnsignedType, class NumberFloatType, \
2135 template<typename> class AllocatorType, \
2136 template<typename, typename = void> class JSONSerializer>
2138 #define NLOHMANN_BASIC_JSON_TPL \
2139 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2140 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2141 AllocatorType, JSONSerializer>
2185 const char*
what() const noexcept
override
2195 exception(
int id_, const
char* what_arg) :
id(id_),
m(what_arg) {}
2197 static std::string
name(
const std::string& ename,
int id_)
2199 return "[json.exception." + ename +
"." +
std::to_string(id_) +
"] ";
2204 std::runtime_error
m;
2499 #include <type_traits>
2506 template<
bool B,
typename T =
void>
2509 template<
typename T>
2510 using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
2514 template<std::size_t... Ints>
2519 static constexpr std::size_t
size() noexcept
2521 return sizeof...(Ints);
2525 template<
class Sequence1,
class Sequence2>
2528 template<std::size_t... I1, std::size_t... I2>
2532 template<std::
size_t N>
2535 typename make_index_sequence < N - N / 2 >::type > {};
2540 template<
typename... Ts>
2548 template<
typename T>
2554 template<
typename T>
2564 #include <type_traits>
2594 template <
typename It,
typename =
void>
2597 template <
typename It>
2601 typename It::reference, typename It::iterator_category >>
2612 template <
typename T,
typename =
void>
2617 template <
typename T>
2623 template <
typename T>
2642 #include <type_traits>
2662 template <
class Default,
2664 template <
class...>
class Op,
2672 template <
class Default,
template <
class...>
class Op,
class... Args>
2679 template <
template <
class...>
class Op,
class... Args>
2682 template <
template <
class...>
class Op,
class... Args>
2685 template <
class Default,
template <
class...>
class Op,
class... Args>
2688 template <
class Default,
template <
class...>
class Op,
class... Args>
2691 template <
class Expected,
template <
class...>
class Op,
class... Args>
2694 template <
class To,
template <
class...>
class Op,
class... Args>
2701 #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
2702 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
2724 template<
typename T =
void,
typename SFINAE =
void>
2727 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
2729 template<
typename U,
typename... Args>
class ArrayType =
std::vector,
2730 class StringType = std::string,
class BooleanType = bool,
2731 class NumberIntegerType = std::int64_t,
2732 class NumberUnsignedType = std::uint64_t,
2733 class NumberFloatType = double,
2734 template<
typename U>
class AllocatorType = std::allocator,
2735 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
2750 template<
typename BasicJsonType>
2764 #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
2807 template <
typename T>
2814 template <
typename T>
2817 template <
typename T>
2820 template <
typename T>
2823 template <
typename T>
2826 template <
typename T>
2829 template <
typename T>
2832 template <
typename T>
2835 template <
typename T>
2838 template <
typename T,
typename... Args>
2841 template <
typename T,
typename... Args>
2844 template <
typename T,
typename U>
2848 template <
typename BasicJsonType,
typename T,
typename =
void>
2851 template <
typename BasicJsonType,
typename T>
2855 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
2864 template <
typename BasicJsonType,
typename T,
typename =
void>
2867 template<
typename BasicJsonType,
typename T>
2870 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
2879 template <
typename BasicJsonType,
typename T,
typename =
void>
2882 template <
typename BasicJsonType,
typename T>
2885 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
2897 template <
typename T,
typename =
void>
2900 template <
typename T>
2917 template <
typename T,
typename =
void>
2920 template <
typename T>
2923 template <
typename BasicJsonType,
typename CompatibleObjectType,
2927 template <
typename BasicJsonType,
typename CompatibleObjectType>
2929 BasicJsonType, CompatibleObjectType,
2938 std::is_constructible<
typename object_t::key_type,
2939 typename CompatibleObjectType::key_type>
::value and
2940 std::is_constructible<
typename object_t::mapped_type,
2941 typename CompatibleObjectType::mapped_type>
::value;
2944 template <
typename BasicJsonType,
typename CompatibleObjectType>
2948 template <
typename BasicJsonType,
typename ConstructibleObjectType,
2952 template <
typename BasicJsonType,
typename ConstructibleObjectType>
2954 BasicJsonType, ConstructibleObjectType,
2964 (std::is_constructible<
typename ConstructibleObjectType::key_type,
2965 typename object_t::key_type>::
value and
2967 typename object_t::mapped_type,
2968 typename ConstructibleObjectType::mapped_type >::
value)) or
2970 typename ConstructibleObjectType::mapped_type>::
value or
2973 typename ConstructibleObjectType::mapped_type >::
value);
2976 template <
typename BasicJsonType,
typename ConstructibleObjectType>
2979 ConstructibleObjectType> {};
2981 template <
typename BasicJsonType,
typename CompatibleStringType,
2985 template <
typename BasicJsonType,
typename CompatibleStringType>
2987 BasicJsonType, CompatibleStringType,
2995 template <
typename BasicJsonType,
typename ConstructibleStringType>
2999 template <
typename BasicJsonType,
typename ConstructibleStringType,
3003 template <
typename BasicJsonType,
typename ConstructibleStringType>
3005 BasicJsonType, ConstructibleStringType,
3010 std::is_constructible<ConstructibleStringType,
3011 typename BasicJsonType::string_t>
::value;
3014 template <
typename BasicJsonType,
typename ConstructibleStringType>
3018 template <
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3021 template <
typename BasicJsonType,
typename CompatibleArrayType>
3023 BasicJsonType, CompatibleArrayType,
3030 iterator_traits<CompatibleArrayType>>
::value >>
3033 std::is_constructible<BasicJsonType,
3037 template <
typename BasicJsonType,
typename CompatibleArrayType>
3041 template <
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3044 template <
typename BasicJsonType,
typename ConstructibleArrayType>
3046 BasicJsonType, ConstructibleArrayType,
3048 typename BasicJsonType::value_type>
::value >>
3049 : std::true_type {};
3051 template <
typename BasicJsonType,
typename ConstructibleArrayType>
3053 BasicJsonType, ConstructibleArrayType,
3054 enable_if_t<not std::is_same<ConstructibleArrayType,
3055 typename BasicJsonType::value_type>
::value and
3056 std::is_default_constructible<ConstructibleArrayType>
::value and
3057 (std::is_move_assignable<ConstructibleArrayType>::value or
3058 std::is_copy_assignable<ConstructibleArrayType>::value) and
3062 detected_t<value_type_t, ConstructibleArrayType>>
::value >>
3080 template <
typename BasicJsonType,
typename ConstructibleArrayType>
3084 template <
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3088 template <
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3090 RealIntegerType, CompatibleNumberIntegerType,
3092 std::is_integral<CompatibleNumberIntegerType>
::value and
3093 not std::is_same<bool, CompatibleNumberIntegerType>
::value >>
3100 std::is_constructible<RealIntegerType,
3101 CompatibleNumberIntegerType>
::value and
3102 CompatibleLimits::is_integer and
3103 RealLimits::is_signed == CompatibleLimits::is_signed;
3106 template <
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3109 CompatibleNumberIntegerType> {};
3111 template <
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3114 template <
typename BasicJsonType,
typename CompatibleType>
3116 BasicJsonType, CompatibleType,
3123 template <
typename BasicJsonType,
typename CompatibleType>
3130 template<
class B1,
class... Bn>
3132 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3134 template <
typename T1,
typename T2>
3137 template <
typename T1,
typename... Args>
3208 static constexpr std::array<std::uint8_t, 8> order = {{
3214 const auto l_index =
static_cast<std::size_t
>(lhs);
3215 const auto r_index =
static_cast<std::size_t
>(rhs);
3216 return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index];
3226 template<
typename BasicJsonType>
3227 void from_json(
const BasicJsonType& j,
typename std::nullptr_t&
n)
3237 template<
typename BasicJsonType,
typename ArithmeticType,
3243 switch (static_cast<value_t>(j))
3245 case value_t::number_unsigned:
3247 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3250 case value_t::number_integer:
3252 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3255 case value_t::number_float:
3257 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3266 template<
typename BasicJsonType>
3267 void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
3273 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
3276 template<
typename BasicJsonType>
3277 void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t&
s)
3283 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3287 typename BasicJsonType,
typename ConstructibleStringType,
3290 not std::is_same<
typename BasicJsonType::string_t,
3291 ConstructibleStringType>
::value,
3293 void from_json(
const BasicJsonType& j, ConstructibleStringType&
s)
3300 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3303 template<
typename BasicJsonType>
3304 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
3309 template<
typename BasicJsonType>
3310 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
3315 template<
typename BasicJsonType>
3316 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
3321 template<
typename BasicJsonType,
typename EnumType,
3325 typename std::underlying_type<EnumType>::type val;
3327 e =
static_cast<EnumType
>(val);
3331 template<
typename BasicJsonType,
typename T,
typename Allocator,
3333 void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
3341 std::front_inserter(l), [](
const BasicJsonType & i)
3343 return i.template get<T>();
3348 template<
typename BasicJsonType,
typename T,
3357 std::copy(j.begin(), j.end(), std::begin(l));
3360 template <
typename BasicJsonType,
typename T, std::
size_t N>
3362 -> decltype(j.template get<T>(),
void())
3364 for (std::size_t i = 0; i <
N; ++i)
3366 arr[i] = j.at(i).template get<T>();
3370 template<
typename BasicJsonType>
3373 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
3376 template <
typename BasicJsonType,
typename T, std::
size_t N>
3379 -> decltype(j.template get<T>(),
void())
3381 for (std::size_t i = 0; i <
N; ++i)
3383 arr[i] = j.at(i).template get<T>();
3387 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3390 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
3391 j.template get<typename ConstructibleArrayType::value_type>(),
3396 ConstructibleArrayType ret;
3397 ret.reserve(j.size());
3399 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
3403 return i.template get<typename ConstructibleArrayType::value_type>();
3405 arr = std::move(ret);
3408 template <
typename BasicJsonType,
typename ConstructibleArrayType>
3414 ConstructibleArrayType ret;
3416 j.begin(), j.end(), std::inserter(ret, end(ret)),
3417 [](
const BasicJsonType & i)
3421 return i.template get<typename ConstructibleArrayType::value_type>();
3423 arr = std::move(ret);
3426 template <
typename BasicJsonType,
typename ConstructibleArrayType,
3434 auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
3436 j.template get<typename ConstructibleArrayType::value_type>(),
3442 std::string(j.type_name())));
3448 template<
typename BasicJsonType,
typename ConstructibleObjectType,
3450 void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
3457 ConstructibleObjectType ret;
3458 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
3461 inner_object->begin(), inner_object->end(),
3462 std::inserter(ret, ret.begin()),
3465 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
3467 obj = std::move(ret);
3474 template<
typename BasicJsonType,
typename ArithmeticType,
3484 switch (static_cast<value_t>(j))
3486 case value_t::number_unsigned:
3488 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3491 case value_t::number_integer:
3493 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3496 case value_t::number_float:
3498 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3501 case value_t::boolean:
3503 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
3512 template<
typename BasicJsonType,
typename A1,
typename A2>
3515 p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
3518 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
3521 t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...);
3524 template<
typename BasicJsonType,
typename... Args>
3530 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
3532 typename BasicJsonType::string_t, Key>
::value>>
3533 void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>&
m)
3540 for (
const auto& p : j)
3546 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
3550 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
3552 typename BasicJsonType::string_t, Key>
::value>>
3553 void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>&
m)
3560 for (
const auto& p : j)
3566 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
3572 template<
typename BasicJsonType,
typename T>
3594 #include <algorithm>
3599 #include <type_traits>
3621 template<
typename string_type>
3634 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
3640 std::size_t array_index = 0;
3642 mutable std::size_t array_index_last = 0;
3669 return anchor == o.
anchor;
3675 return anchor != o.
anchor;
3681 assert(anchor.m_object !=
nullptr);
3683 switch (anchor.m_object->type())
3686 case value_t::array:
3688 if (array_index != array_index_last)
3691 array_index_last = array_index;
3693 return array_index_str;
3697 case value_t::object:
3698 return anchor.key();
3707 typename IteratorType::reference
value()
const
3709 return anchor.value();
3723 : container(cont) {}
3740 template <std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
3748 template <std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
3762 #if defined(__clang__)
3764 #pragma clang diagnostic push
3765 #pragma clang diagnostic ignored "-Wmismatched-tags"
3767 template <
typename IteratorType>
3769 :
public std::integral_constant<std::size_t, 2> {};
3771 template <std::
size_t N,
typename IteratorType>
3775 using type = decltype(
3776 get<N>(std::declval <
3779 #if defined(__clang__)
3780 #pragma clang diagnostic pop
3804 template<
typename BasicJsonType>
3805 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b) noexcept
3807 j.m_type = value_t::boolean;
3809 j.assert_invariant();
3816 template<
typename BasicJsonType>
3817 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t&
s)
3819 j.m_type = value_t::string;
3821 j.assert_invariant();
3824 template<
typename BasicJsonType>
3825 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&&
s)
3827 j.m_type = value_t::string;
3828 j.m_value = std::move(
s);
3829 j.assert_invariant();
3832 template<
typename BasicJsonType,
typename CompatibleStringType,
3835 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
3837 j.m_type = value_t::string;
3838 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
3839 j.assert_invariant();
3846 template<
typename BasicJsonType>
3847 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val) noexcept
3849 j.m_type = value_t::number_float;
3851 j.assert_invariant();
3858 template<
typename BasicJsonType>
3859 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val) noexcept
3861 j.m_type = value_t::number_unsigned;
3863 j.assert_invariant();
3870 template<
typename BasicJsonType>
3871 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val) noexcept
3873 j.m_type = value_t::number_integer;
3875 j.assert_invariant();
3882 template<
typename BasicJsonType>
3883 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
3885 j.m_type = value_t::array;
3887 j.assert_invariant();
3890 template<
typename BasicJsonType>
3891 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
3893 j.m_type = value_t::array;
3894 j.m_value = std::move(arr);
3895 j.assert_invariant();
3898 template<
typename BasicJsonType,
typename CompatibleArrayType,
3901 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
3905 j.m_type = value_t::array;
3906 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
3907 j.assert_invariant();
3910 template<
typename BasicJsonType>
3911 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
3913 j.m_type = value_t::array;
3914 j.m_value = value_t::array;
3915 j.m_value.array->reserve(arr.size());
3916 for (
const bool x : arr)
3918 j.m_value.array->push_back(
x);
3920 j.assert_invariant();
3923 template<
typename BasicJsonType,
typename T,
3925 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
3927 j.m_type = value_t::array;
3928 j.m_value = value_t::array;
3929 j.m_value.array->resize(arr.size());
3932 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
3934 j.assert_invariant();
3941 template<
typename BasicJsonType>
3942 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
3944 j.m_type = value_t::object;
3946 j.assert_invariant();
3949 template<
typename BasicJsonType>
3950 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
3952 j.m_type = value_t::object;
3953 j.m_value = std::move(obj);
3954 j.assert_invariant();
3957 template<
typename BasicJsonType,
typename CompatibleObjectType,
3959 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
3964 j.m_type = value_t::object;
3965 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
3966 j.assert_invariant();
3974 template<
typename BasicJsonType,
typename T,
3981 template<
typename BasicJsonType,
typename CompatibleString,
3983 void to_json(BasicJsonType& j,
const CompatibleString&
s)
3988 template<
typename BasicJsonType>
3989 void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&&
s)
3994 template<
typename BasicJsonType,
typename FloatType,
3996 void to_json(BasicJsonType& j, FloatType val) noexcept
4001 template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
4003 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
4008 template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
4010 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
4015 template<
typename BasicJsonType,
typename EnumType,
4019 using underlying_type =
typename std::underlying_type<EnumType>::type;
4023 template<
typename BasicJsonType>
4024 void to_json(BasicJsonType& j,
const std::vector<bool>&
e)
4029 template <
typename BasicJsonType,
typename CompatibleArrayType,
4030 enable_if_t<is_compatible_array_type<BasicJsonType,
4031 CompatibleArrayType>
::value and
4032 not is_compatible_object_type<
4033 BasicJsonType, CompatibleArrayType>
::value and
4037 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
4042 template<
typename BasicJsonType,
typename T,
4044 void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
4049 template<
typename BasicJsonType>
4050 void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4055 template<
typename BasicJsonType,
typename CompatibleObjectType,
4057 void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
4062 template<
typename BasicJsonType>
4063 void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4069 typename BasicJsonType,
typename T, std::size_t
N,
4070 enable_if_t<not std::is_constructible<
typename BasicJsonType::string_t,
4079 void to_json(BasicJsonType& j,
const std::pair<T1, T2>&
p)
4081 j = { p.first, p.second };
4085 template <
typename BasicJsonType,
typename T,
4086 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>
::value,
int> = 0>
4089 j = { {b.key(), b.value()} };
4092 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
4095 j = { std::get<Idx>(
t)... };
4099 void to_json(BasicJsonType& j,
const T& t)
4106 template<
typename BasicJsonType,
typename T>
4107 auto operator()(BasicJsonType& j,
T&& val) const noexcept(noexcept(
to_json(j, std::
forward<
T>(val))))
4110 return to_json(j, std::forward<T>(val));
4126 template<
typename,
typename>
4138 template<
typename BasicJsonType,
typename ValueType>
4139 static auto from_json(BasicJsonType&& j, ValueType& val) noexcept(
4155 template <
typename BasicJsonType,
typename ValueType>
4156 static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
4158 -> decltype(::nlohmann::
to_json(j, std::
forward<ValueType>(val)),
void())
4175 #include <algorithm>
4203 #include <type_traits>
4236 virtual std::char_traits<char>::int_type get_character() = 0;
4262 std::char_traits<char>::int_type get_character() noexcept
override
4264 return std::fgetc(m_file);
4289 is.clear(is.rdstate() & std::ios::eofbit);
4293 : is(i), sb(*i.rdbuf())
4305 std::char_traits<char>::int_type get_character()
override
4307 auto res = sb.sbumpc();
4311 is.clear(is.rdstate() | std::ios::eofbit);
4327 : cursor(b), limit(b ==
nullptr ?
nullptr : (b + l))
4337 std::char_traits<char>::int_type get_character() noexcept
override
4341 assert(cursor !=
nullptr and limit !=
nullptr);
4342 return std::char_traits<char>::to_int_type(*(cursor++));
4345 return std::char_traits<char>::eof();
4355 template<
typename W
ideStringType,
size_t T>
4359 static void fill_buffer(
const WideStringType& str,
4360 size_t& current_wchar,
4361 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
4362 size_t& utf8_bytes_index,
4363 size_t& utf8_bytes_filled)
4365 utf8_bytes_index = 0;
4367 if (current_wchar == str.size())
4369 utf8_bytes[0] = std::char_traits<char>::eof();
4370 utf8_bytes_filled = 1;
4375 const auto wc =
static_cast<unsigned int>(str[current_wchar++]);
4380 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4381 utf8_bytes_filled = 1;
4383 else if (wc <= 0x7FF)
4385 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0
u | ((wc >> 6
u) & 0x1Fu));
4386 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | (wc & 0x3F
u));
4387 utf8_bytes_filled = 2;
4389 else if (wc <= 0xFFFF)
4391 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0
u | ((wc >> 12
u) & 0x0Fu));
4392 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | ((wc >> 6
u) & 0x3Fu));
4393 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | (wc & 0x3F
u));
4394 utf8_bytes_filled = 3;
4396 else if (wc <= 0x10FFFF)
4398 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0
u | ((wc >> 18
u) & 0x07u));
4399 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | ((wc >> 12
u) & 0x3Fu));
4400 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | ((wc >> 6
u) & 0x3Fu));
4401 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | (wc & 0x3F
u));
4402 utf8_bytes_filled = 4;
4407 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4408 utf8_bytes_filled = 1;
4414 template<
typename W
ideStringType>
4418 static void fill_buffer(
const WideStringType& str,
4419 size_t& current_wchar,
4420 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
4421 size_t& utf8_bytes_index,
4422 size_t& utf8_bytes_filled)
4424 utf8_bytes_index = 0;
4426 if (current_wchar == str.size())
4428 utf8_bytes[0] = std::char_traits<char>::eof();
4429 utf8_bytes_filled = 1;
4434 const auto wc =
static_cast<unsigned int>(str[current_wchar++]);
4439 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4440 utf8_bytes_filled = 1;
4442 else if (wc <= 0x7FF)
4444 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0
u | ((wc >> 6
u)));
4445 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | (wc & 0x3F
u));
4446 utf8_bytes_filled = 2;
4448 else if (0xD800 > wc or wc >= 0xE000)
4450 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0
u | ((wc >> 12
u)));
4451 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | ((wc >> 6
u) & 0x3Fu));
4452 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | (wc & 0x3F
u));
4453 utf8_bytes_filled = 3;
4457 if (current_wchar < str.size())
4459 const auto wc2 =
static_cast<unsigned int>(str[current_wchar++]);
4460 const auto charcode = 0x10000
u + (((wc & 0x3FF
u) << 10
u) | (wc2 & 0x3FF
u));
4461 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0
u | (charcode >> 18
u));
4462 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | ((charcode >> 12
u) & 0x3Fu));
4463 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | ((charcode >> 6
u) & 0x3Fu));
4464 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80
u | (charcode & 0x3F
u));
4465 utf8_bytes_filled = 4;
4471 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
4472 utf8_bytes_filled = 1;
4479 template<
typename W
ideStringType>
4487 std::char_traits<char>::int_type get_character() noexcept
override
4490 if (utf8_bytes_index == utf8_bytes_filled)
4492 fill_buffer<sizeof(typename WideStringType::value_type)>();
4494 assert(utf8_bytes_filled > 0);
4495 assert(utf8_bytes_index == 0);
4499 assert(utf8_bytes_filled > 0);
4500 assert(utf8_bytes_index < utf8_bytes_filled);
4501 return utf8_bytes[utf8_bytes_index++];
4515 std::size_t current_wchar = 0;
4518 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
4521 std::size_t utf8_bytes_index = 0;
4523 std::size_t utf8_bytes_filled = 0;
4551 template<
typename CharT,
4552 typename std::enable_if<
4554 std::is_integral<typename std::remove_pointer<CharT>::type>
::value and
4555 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
4558 : ia(std::make_shared<input_buffer_adapter>(reinterpret_cast<const char*>(b), l)) {}
4563 template<
typename CharT,
4564 typename std::enable_if<
4566 std::is_integral<typename std::remove_pointer<CharT>::type>
::value and
4567 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
4571 std::strlen(reinterpret_cast<const char*>(b))) {}
4574 template<
class IteratorType,
4575 typename std::enable_if<
4576 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>
::value,
4583 const auto is_contiguous = std::accumulate(
4584 first, last, std::pair<bool, int>(
true, 0),
4585 [&first](std::pair<bool, int> res, decltype(*first) val)
4587 res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
4590 assert(is_contiguous);
4596 "each element in the iterator range must have the size of 1 byte");
4598 const auto len =
static_cast<size_t>(std::distance(first, last));
4602 ia = std::make_shared<input_buffer_adapter>(
reinterpret_cast<const char*
>(&(*first)), len);
4607 ia = std::make_shared<input_buffer_adapter>(
nullptr, len);
4612 template<
class T, std::
size_t N>
4617 template<
class ContiguousContainer,
typename
4619 std::is_base_of<std::random_access_iterator_tag, typename iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::
value,
4661 template<
typename BasicJsonType>
4677 virtual bool null() = 0;
4684 virtual bool boolean(
bool val) = 0;
4714 virtual bool string(
string_t& val) = 0;
4722 virtual bool start_object(std::size_t elements) = 0;
4730 virtual bool key(
string_t& val) = 0;
4736 virtual bool end_object() = 0;
4744 virtual bool start_array(std::size_t elements) = 0;
4750 virtual bool end_array() = 0;
4759 virtual bool parse_error(std::size_t
position,
4760 const std::string& last_token,
4782 template<
typename BasicJsonType>
4797 : root(r), allow_exceptions(allow_exceptions_)
4809 handle_value(
nullptr);
4813 bool boolean(
bool val)
4843 bool start_object(std::size_t len)
4845 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
4859 object_element = &(ref_stack.back()->m_value.object->operator[](val));
4865 ref_stack.pop_back();
4869 bool start_array(std::size_t len)
4871 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
4884 ref_stack.pop_back();
4892 if (allow_exceptions)
4895 switch ((ex.
id / 100) % 100)
4898 JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
4900 JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
4903 JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex));
4905 JSON_THROW(*static_cast<const detail::type_error*>(&ex));
4907 JSON_THROW(*static_cast<const detail::other_error*>(&ex));
4916 constexpr
bool is_errored()
const
4928 template<
typename Value>
4930 BasicJsonType* handle_value(Value&&
v)
4932 if (ref_stack.empty())
4934 root = BasicJsonType(std::forward<Value>(
v));
4938 assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
4940 if (ref_stack.back()->is_array())
4942 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(
v));
4943 return &(ref_stack.back()->m_value.array->back());
4946 assert(ref_stack.back()->is_object());
4947 assert(object_element);
4948 *object_element = BasicJsonType(std::forward<Value>(
v));
4949 return object_element;
4955 std::vector<BasicJsonType*> ref_stack {};
4957 BasicJsonType* object_element =
nullptr;
4959 bool errored =
false;
4961 const bool allow_exceptions =
true;
4964 template<
typename BasicJsonType>
4977 const bool allow_exceptions_ =
true)
4978 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
4980 keep_stack.push_back(
true);
4992 handle_value(
nullptr);
4996 bool boolean(
bool val)
5026 bool start_object(std::size_t len)
5029 const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
5030 keep_stack.push_back(keep);
5032 auto val = handle_value(BasicJsonType::value_t::object,
true);
5033 ref_stack.push_back(val.second);
5036 if (ref_stack.back() and
JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
5046 BasicJsonType
k = BasicJsonType(val);
5049 const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);
5050 key_keep_stack.push_back(keep);
5053 if (keep and ref_stack.back())
5055 object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
5063 if (ref_stack.back() and not callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
5066 *ref_stack.back() = discarded;
5069 assert(not ref_stack.empty());
5070 assert(not keep_stack.empty());
5071 ref_stack.pop_back();
5072 keep_stack.pop_back();
5074 if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_object())
5077 for (
auto it = ref_stack.back()->begin();
it != ref_stack.back()->end(); ++
it)
5079 if (
it->is_discarded())
5081 ref_stack.back()->erase(
it);
5090 bool start_array(std::size_t len)
5092 const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
5093 keep_stack.push_back(keep);
5095 auto val = handle_value(BasicJsonType::value_t::array,
true);
5096 ref_stack.push_back(val.second);
5099 if (ref_stack.back() and
JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
5111 if (ref_stack.back())
5113 keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
5117 *ref_stack.back() = discarded;
5121 assert(not ref_stack.empty());
5122 assert(not keep_stack.empty());
5123 ref_stack.pop_back();
5124 keep_stack.pop_back();
5127 if (not keep and not ref_stack.empty() and ref_stack.back()->is_array())
5129 ref_stack.back()->m_value.array->pop_back();
5139 if (allow_exceptions)
5142 switch ((ex.
id / 100) % 100)
5145 JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
5147 JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
5150 JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex));
5152 JSON_THROW(*static_cast<const detail::type_error*>(&ex));
5154 JSON_THROW(*static_cast<const detail::other_error*>(&ex));
5163 constexpr
bool is_errored()
const
5184 template<
typename Value>
5185 std::pair<bool, BasicJsonType*> handle_value(Value&&
v,
const bool skip_callback =
false)
5187 assert(not keep_stack.empty());
5191 if (not keep_stack.back())
5193 return {
false,
nullptr};
5197 auto value = BasicJsonType(std::forward<Value>(
v));
5205 return {
false,
nullptr};
5208 if (ref_stack.empty())
5210 root = std::move(
value);
5211 return {
true, &root};
5216 if (not ref_stack.back())
5218 return {
false,
nullptr};
5222 assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
5225 if (ref_stack.back()->is_array())
5227 ref_stack.back()->m_value.array->push_back(std::move(
value));
5228 return {
true, &(ref_stack.back()->m_value.array->back())};
5232 assert(ref_stack.back()->is_object());
5234 assert(not key_keep_stack.empty());
5235 const bool store_element = key_keep_stack.back();
5236 key_keep_stack.pop_back();
5238 if (not store_element)
5240 return {
false,
nullptr};
5243 assert(object_element);
5244 *object_element = std::move(
value);
5245 return {
true, object_element};
5251 std::vector<BasicJsonType*> ref_stack {};
5253 std::vector<bool> keep_stack {};
5255 std::vector<bool> key_keep_stack {};
5257 BasicJsonType* object_element =
nullptr;
5259 bool errored =
false;
5263 const bool allow_exceptions =
true;
5265 BasicJsonType discarded = BasicJsonType::value_t::discarded;
5268 template<
typename BasicJsonType>
5307 bool start_object(std::size_t = std::size_t(-1))
5322 bool start_array(std::size_t = std::size_t(-1))
5359 template <
typename T>
5362 template <
typename T>
5364 decltype(std::declval<T&>().
boolean(std::declval<bool>()));
5366 template <
typename T,
typename Integer>
5368 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
5370 template <
typename T,
typename Un
signed>
5372 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
5374 template <
typename T,
typename Float,
typename String>
5376 std::declval<Float>(), std::declval<const String&>()));
5378 template <
typename T,
typename String>
5380 decltype(std::declval<T&>().
string(std::declval<String&>()));
5382 template <
typename T>
5384 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
5386 template <
typename T,
typename String>
5388 decltype(std::declval<T&>().key(std::declval<String&>()));
5390 template <
typename T>
5393 template <
typename T>
5395 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
5397 template <
typename T>
5400 template <
typename T,
typename Exception>
5402 std::declval<std::size_t>(), std::declval<const std::string&>(),
5403 std::declval<const Exception&>()));
5405 template <
typename SAX,
typename BasicJsonType>
5410 "BasicJsonType must be of type basic_json<...>");
5437 template <
typename SAX,
typename BasicJsonType>
5442 "BasicJsonType must be of type basic_json<...>");
5452 "Missing/invalid function: bool null()");
5454 "Missing/invalid function: bool boolean(bool)");
5456 "Missing/invalid function: bool boolean(bool)");
5460 "Missing/invalid function: bool number_integer(number_integer_t)");
5464 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
5467 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
5470 "Missing/invalid function: bool string(string_t&)");
5472 "Missing/invalid function: bool start_object(std::size_t)");
5474 "Missing/invalid function: bool key(string_t&)");
5476 "Missing/invalid function: bool end_object()");
5478 "Missing/invalid function: bool start_array(std::size_t)");
5480 "Missing/invalid function: bool end_array()");
5483 "Missing/invalid function: bool parse_error(std::size_t, const "
5484 "std::string&, const exception&)");
5503 template<
typename BasicJsonType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
5541 const
bool strict =
true)
5544 bool result =
false;
5548 case input_format_t::bson:
5549 result = parse_bson_internal();
5552 case input_format_t::cbor:
5553 result = parse_cbor_internal();
5556 case input_format_t::msgpack:
5557 result = parse_msgpack_internal();
5560 case input_format_t::ubjson:
5561 result = parse_ubjson_internal();
5569 if (result and strict)
5571 if (format == input_format_t::ubjson)
5582 return sax->parse_error(chars_read, get_token_string(),
5583 parse_error::create(110, chars_read, exception_message(format,
"expected end of input; last byte: 0x" + get_token_string(),
"value")));
5597 static constexpr
bool little_endianess(
int num = 1) noexcept
5599 return *
reinterpret_cast<char*
>(&
num) == 1;
5611 bool parse_bson_internal()
5613 std::int32_t document_size;
5614 get_number<std::int32_t, true>(input_format_t::bson, document_size);
5626 return sax->end_object();
5638 auto out = std::back_inserter(result);
5646 if (current == 0x00)
5650 *out++ =
static_cast<char>(current);
5667 template<
typename NumberType>
5668 bool get_bson_string(
const NumberType len,
string_t& result)
5672 auto last_token = get_token_string();
5673 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")));
5676 return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) and
get() != std::char_traits<char>::eof();
5689 bool parse_bson_element_internal(
const int element_type,
5690 const std::size_t element_type_parse_position)
5692 switch (element_type)
5697 return get_number<double, true>(input_format_t::bson, number) and sax->number_float(static_cast<number_float_t>(number),
"");
5704 return get_number<std::int32_t, true>(input_format_t::bson, len) and get_bson_string(len, value) and sax->string(value);
5709 return parse_bson_internal();
5714 return parse_bson_array();
5719 return sax->boolean(
get() != 0);
5730 return get_number<std::int32_t, true>(input_format_t::bson,
value) and sax->number_integer(value);
5736 return get_number<std::int64_t, true>(input_format_t::bson,
value) and sax->number_integer(value);
5741 std::array<char, 3> cr{{}};
5742 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type));
5743 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())));
5760 bool parse_bson_element_list(
const bool is_array)
5763 while (
int element_type =
get())
5770 const std::size_t element_type_parse_position = chars_read;
5776 if (not is_array and not sax->key(key))
5781 if (
JSON_HEDLEY_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
5797 bool parse_bson_array()
5799 std::int32_t document_size;
5800 get_number<std::int32_t, true>(input_format_t::bson, document_size);
5812 return sax->end_array();
5826 bool parse_cbor_internal(
const bool get_char =
true)
5828 switch (get_char ?
get() : current)
5831 case std::char_traits<char>::eof():
5832 return unexpect_eof(input_format_t::cbor,
"value");
5859 return sax->number_unsigned(static_cast<number_unsigned_t>(current));
5864 return get_number(input_format_t::cbor, number) and sax->number_unsigned(number);
5870 return get_number(input_format_t::cbor, number) and sax->number_unsigned(number);
5876 return get_number(input_format_t::cbor, number) and sax->number_unsigned(number);
5881 std::uint64_t number;
5882 return get_number(input_format_t::cbor, number) and sax->number_unsigned(number);
5910 return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current));
5915 return get_number(input_format_t::cbor, number) and sax->number_integer(static_cast<number_integer_t>(-1) - number);
5921 return get_number(input_format_t::cbor, number) and sax->number_integer(static_cast<number_integer_t>(-1) - number);
5927 return get_number(input_format_t::cbor, number) and sax->number_integer(static_cast<number_integer_t>(-1) - number);
5932 std::uint64_t number;
5933 return get_number(input_format_t::cbor, number) and sax->number_integer(static_cast<number_integer_t>(-1)
5934 - static_cast<number_integer_t>(number));
5969 return get_cbor_string(s) and sax->string(s);
5997 return get_cbor_array(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu));
6002 return get_number(input_format_t::cbor, len) and get_cbor_array(static_cast<std::size_t>(len));
6008 return get_number(input_format_t::cbor, len) and get_cbor_array(static_cast<std::size_t>(len));
6014 return get_number(input_format_t::cbor, len) and get_cbor_array(static_cast<std::size_t>(len));
6020 return get_number(input_format_t::cbor, len) and get_cbor_array(static_cast<std::size_t>(len));
6024 return get_cbor_array(std::size_t(-1));
6051 return get_cbor_object(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu));
6056 return get_number(input_format_t::cbor, len) and get_cbor_object(static_cast<std::size_t>(len));
6062 return get_number(input_format_t::cbor, len) and get_cbor_object(static_cast<std::size_t>(len));
6068 return get_number(input_format_t::cbor, len) and get_cbor_object(static_cast<std::size_t>(len));
6074 return get_number(input_format_t::cbor, len) and get_cbor_object(static_cast<std::size_t>(len));
6078 return get_cbor_object(std::size_t(-1));
6081 return sax->boolean(
false);
6084 return sax->boolean(
true);
6091 const int byte1_raw =
get();
6096 const int byte2_raw =
get();
6102 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
6103 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
6113 const auto half =
static_cast<unsigned int>((byte1 << 8
u) + byte2);
6114 const double val = [&
half]
6116 const int exp = (
half >> 10
u) & 0x1Fu;
6117 const unsigned int mant =
half & 0x3FF
u;
6118 assert(0 <= exp and exp <= 32);
6119 assert(mant <= 1024);
6123 return std::ldexp(mant, -24);
6126 ? std::numeric_limits<double>::infinity()
6127 : std::numeric_limits<double>::quiet_NaN();
6129 return std::ldexp(mant + 1024, exp - 25);
6132 return sax->number_float((
half & 0x8000u) != 0
6133 ? static_cast<number_float_t>(-val)
6134 : static_cast<number_float_t>(val),
"");
6140 return get_number(input_format_t::cbor, number) and sax->number_float(static_cast<number_float_t>(number),
"");
6146 return get_number(input_format_t::cbor, number) and sax->number_float(static_cast<number_float_t>(number),
"");
6151 auto last_token = get_token_string();
6152 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")));
6203 return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
6209 return get_number(input_format_t::cbor, len) and get_string(input_format_t::cbor, len, result);
6215 return get_number(input_format_t::cbor, len) and get_string(input_format_t::cbor, len, result);
6221 return get_number(input_format_t::cbor, len) and get_string(input_format_t::cbor, len, result);
6227 return get_number(input_format_t::cbor, len) and get_string(input_format_t::cbor, len, result);
6232 while (
get() != 0xFF)
6235 if (not get_cbor_string(chunk))
6239 result.append(chunk);
6246 auto last_token = get_token_string();
6247 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")));
6257 bool get_cbor_array(
const std::size_t len)
6264 if (len != std::size_t(-1))
6266 for (std::size_t i = 0; i < len; ++i)
6276 while (
get() != 0xFF)
6285 return sax->end_array();
6293 bool get_cbor_object(
const std::size_t len)
6301 if (len != std::size_t(-1))
6303 for (std::size_t i = 0; i < len; ++i)
6320 while (
get() != 0xFF)
6335 return sax->end_object();
6345 bool parse_msgpack_internal()
6350 case std::char_traits<char>::eof():
6351 return unexpect_eof(input_format_t::msgpack,
"value");
6482 return sax->number_unsigned(static_cast<number_unsigned_t>(current));
6501 return get_msgpack_object(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
6520 return get_msgpack_array(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
6560 return get_msgpack_string(s) and sax->string(s);
6567 return sax->boolean(
false);
6570 return sax->boolean(
true);
6575 return get_number(input_format_t::msgpack, number) and sax->number_float(static_cast<number_float_t>(number),
"");
6581 return get_number(input_format_t::msgpack, number) and sax->number_float(static_cast<number_float_t>(number),
"");
6587 return get_number(input_format_t::msgpack, number) and sax->number_unsigned(number);
6593 return get_number(input_format_t::msgpack, number) and sax->number_unsigned(number);
6599 return get_number(input_format_t::msgpack, number) and sax->number_unsigned(number);
6604 std::uint64_t number;
6605 return get_number(input_format_t::msgpack, number) and sax->number_unsigned(number);
6611 return get_number(input_format_t::msgpack, number) and sax->number_integer(number);
6616 std::int16_t number;
6617 return get_number(input_format_t::msgpack, number) and sax->number_integer(number);
6622 std::int32_t number;
6623 return get_number(input_format_t::msgpack, number) and sax->number_integer(number);
6628 std::int64_t number;
6629 return get_number(input_format_t::msgpack, number) and sax->number_integer(number);
6635 return get_number(input_format_t::msgpack, len) and get_msgpack_array(static_cast<std::size_t>(len));
6641 return get_number(input_format_t::msgpack, len) and get_msgpack_array(static_cast<std::size_t>(len));
6647 return get_number(input_format_t::msgpack, len) and get_msgpack_object(static_cast<std::size_t>(len));
6653 return get_number(input_format_t::msgpack, len) and get_msgpack_object(static_cast<std::size_t>(len));
6689 return sax->number_integer(static_cast<std::int8_t>(current));
6693 auto last_token = get_token_string();
6694 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")));
6752 return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result);
6758 return get_number(input_format_t::msgpack, len) and get_string(input_format_t::msgpack, len, result);
6764 return get_number(input_format_t::msgpack, len) and get_string(input_format_t::msgpack, len, result);
6770 return get_number(input_format_t::msgpack, len) and get_string(input_format_t::msgpack, len, result);
6775 auto last_token = get_token_string();
6776 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")));
6785 bool get_msgpack_array(
const std::size_t len)
6792 for (std::size_t i = 0; i < len; ++i)
6800 return sax->end_array();
6807 bool get_msgpack_object(
const std::size_t len)
6815 for (std::size_t i = 0; i < len; ++i)
6830 return sax->end_object();
6844 bool parse_ubjson_internal(
const bool get_char =
true)
6846 return get_ubjson_value(get_char ? get_ignore_noop() : current);
6863 bool get_ubjson_string(
string_t& result,
const bool get_char =
true)
6880 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6886 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6892 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6898 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6904 return get_number(input_format_t::ubjson, len) and get_string(input_format_t::ubjson, len, result);
6908 auto last_token = get_token_string();
6909 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")));
6917 bool get_ubjson_size_value(std::size_t& result)
6919 switch (get_ignore_noop())
6928 result =
static_cast<std::size_t
>(number);
6939 result =
static_cast<std::size_t
>(number);
6945 std::int16_t number;
6950 result =
static_cast<std::size_t
>(number);
6956 std::int32_t number;
6961 result =
static_cast<std::size_t
>(number);
6967 std::int64_t number;
6972 result =
static_cast<std::size_t
>(number);
6978 auto last_token = get_token_string();
6979 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")));
6994 bool get_ubjson_size_type(std::pair<std::size_t, int>& result)
6996 result.first = string_t::npos;
7003 result.second =
get();
7016 auto last_token = get_token_string();
7017 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")));
7020 return get_ubjson_size_value(result.first);
7025 return get_ubjson_size_value(result.first);
7035 bool get_ubjson_value(
const int prefix)
7039 case std::char_traits<char>::eof():
7040 return unexpect_eof(input_format_t::ubjson,
"value");
7043 return sax->boolean(
true);
7045 return sax->boolean(
false);
7053 return get_number(input_format_t::ubjson, number) and sax->number_unsigned(number);
7059 return get_number(input_format_t::ubjson, number) and sax->number_integer(number);
7064 std::int16_t number;
7065 return get_number(input_format_t::ubjson, number) and sax->number_integer(number);
7070 std::int32_t number;
7071 return get_number(input_format_t::ubjson, number) and sax->number_integer(number);
7076 std::int64_t number;
7077 return get_number(input_format_t::ubjson, number) and sax->number_integer(number);
7083 return get_number(input_format_t::ubjson, number) and sax->number_float(static_cast<number_float_t>(number),
"");
7089 return get_number(input_format_t::ubjson, number) and sax->number_float(static_cast<number_float_t>(number),
"");
7101 auto last_token = get_token_string();
7102 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")));
7104 string_t s(1, static_cast<char>(current));
7105 return sax->string(s);
7111 return get_ubjson_string(s) and sax->string(s);
7115 return get_ubjson_array();
7118 return get_ubjson_object();
7122 auto last_token = get_token_string();
7123 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")));
7131 bool get_ubjson_array()
7133 std::pair<std::size_t, int> size_and_type;
7139 if (size_and_type.first != string_t::npos)
7146 if (size_and_type.second != 0)
7148 if (size_and_type.second !=
'N')
7150 for (std::size_t i = 0; i < size_and_type.first; ++i)
7161 for (std::size_t i = 0; i < size_and_type.first; ++i)
7177 while (current !=
']')
7187 return sax->end_array();
7193 bool get_ubjson_object()
7195 std::pair<std::size_t, int> size_and_type;
7202 if (size_and_type.first != string_t::npos)
7209 if (size_and_type.second != 0)
7211 for (std::size_t i = 0; i < size_and_type.first; ++i)
7226 for (std::size_t i = 0; i < size_and_type.first; ++i)
7247 while (current !=
'}')
7262 return sax->end_object();
7281 return current = ia->get_character();
7287 int get_ignore_noop()
7293 while (current ==
'N');
7311 template<
typename NumberType,
bool InputIsLittleEndian = false>
7315 std::array<std::uint8_t, sizeof(NumberType)> vec;
7316 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
7325 if (is_little_endian != InputIsLittleEndian)
7327 vec[
sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);
7336 std::memcpy(&result, vec.data(),
sizeof(NumberType));
7354 template<
typename NumberType>
7356 const NumberType len,
7359 bool success =
true;
7360 std::generate_n(std::back_inserter(result), len, [
this, &success, &format]()
7367 return static_cast<char>(current);
7382 return sax->parse_error(chars_read,
"<end of file>",
7383 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context)));
7391 std::string get_token_string()
const
7393 std::array<char, 3> cr{{}};
7394 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current));
7395 return std::string{cr.data()};
7405 const std::string& detail,
7406 const std::string& context)
const
7408 std::string error_msg =
"syntax error while parsing ";
7412 case input_format_t::cbor:
7413 error_msg +=
"CBOR";
7416 case input_format_t::msgpack:
7417 error_msg +=
"MessagePack";
7420 case input_format_t::ubjson:
7421 error_msg +=
"UBJSON";
7424 case input_format_t::bson:
7425 error_msg +=
"BSON";
7432 return error_msg +
" " + context +
": " + detail;
7440 int current = std::char_traits<char>::eof();
7443 std::size_t chars_read = 0;
7446 const bool is_little_endian = little_endianess();
7464 #include <initializer_list>
7489 template<
typename BasicJsonType>
7527 case token_type::uninitialized:
7528 return "<uninitialized>";
7529 case token_type::literal_true:
7530 return "true literal";
7531 case token_type::literal_false:
7532 return "false literal";
7533 case token_type::literal_null:
7534 return "null literal";
7535 case token_type::value_string:
7536 return "string literal";
7537 case lexer::token_type::value_unsigned:
7538 case lexer::token_type::value_integer:
7539 case lexer::token_type::value_float:
7540 return "number literal";
7541 case token_type::begin_array:
7543 case token_type::begin_object:
7545 case token_type::end_array:
7547 case token_type::end_object:
7549 case token_type::name_separator:
7551 case token_type::value_separator:
7553 case token_type::parse_error:
7554 return "<parse error>";
7555 case token_type::end_of_input:
7556 return "end of input";
7557 case token_type::literal_or_value:
7558 return "'[', '{', or a literal";
7561 return "unknown token";
7567 : ia(std::move(adapter)), decimal_point_char(get_decimal_point()) {}
7583 static char get_decimal_point() noexcept
7585 const auto loc = localeconv();
7586 assert(loc !=
nullptr);
7587 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7612 assert(current ==
'u');
7615 const auto factors = { 12
u, 8
u, 4
u, 0u };
7616 for (
const auto factor : factors)
7620 if (current >=
'0' and current <=
'9')
7622 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7624 else if (current >=
'A' and current <=
'F')
7626 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7628 else if (current >=
'a' and current <=
'f')
7630 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7638 assert(0x0000 <= codepoint and codepoint <= 0xFFFF);
7657 bool next_byte_in_range(std::initializer_list<int> ranges)
7659 assert(ranges.size() == 2 or ranges.size() == 4 or ranges.size() == 6);
7662 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7671 error_message =
"invalid string: ill-formed UTF-8 byte";
7700 assert(current ==
'\"');
7708 case std::char_traits<char>::eof():
7710 error_message =
"invalid string: missing closing quote";
7711 return token_type::parse_error;
7717 return token_type::value_string;
7761 const int codepoint1 = get_codepoint();
7762 int codepoint = codepoint1;
7766 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7767 return token_type::parse_error;
7771 if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF)
7776 const int codepoint2 = get_codepoint();
7780 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7781 return token_type::parse_error;
7788 codepoint =
static_cast<int>(
7790 (
static_cast<unsigned int>(codepoint1) << 10
u)
7792 +
static_cast<unsigned int>(codepoint2)
7800 error_message =
"invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF";
7801 return token_type::parse_error;
7806 error_message =
"invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF";
7807 return token_type::parse_error;
7814 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7815 return token_type::parse_error;
7820 assert(0x00 <= codepoint and codepoint <= 0x10FFFF);
7823 if (codepoint < 0x80)
7828 else if (codepoint <= 0x7FF)
7831 add(static_cast<int>(0xC0u | (static_cast<unsigned int>(codepoint) >> 6
u)));
7832 add(static_cast<int>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
7834 else if (codepoint <= 0xFFFF)
7837 add(static_cast<int>(0xE0u | (static_cast<unsigned int>(codepoint) >> 12
u)));
7838 add(static_cast<int>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6
u) & 0x3Fu)));
7839 add(static_cast<int>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
7844 add(static_cast<int>(0xF0u | (static_cast<unsigned int>(codepoint) >> 18
u)));
7845 add(static_cast<int>(0x80u | ((static_cast<unsigned int>(codepoint) >> 12
u) & 0x3Fu)));
7846 add(static_cast<int>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6
u) & 0x3Fu)));
7847 add(static_cast<int>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
7855 error_message =
"invalid string: forbidden character after backslash";
7856 return token_type::parse_error;
7865 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7866 return token_type::parse_error;
7871 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7872 return token_type::parse_error;
7877 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7878 return token_type::parse_error;
7883 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7884 return token_type::parse_error;
7889 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7890 return token_type::parse_error;
7895 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7896 return token_type::parse_error;
7901 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7902 return token_type::parse_error;
7907 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7908 return token_type::parse_error;
7913 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7914 return token_type::parse_error;
7919 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7920 return token_type::parse_error;
7925 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7926 return token_type::parse_error;
7931 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7932 return token_type::parse_error;
7937 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7938 return token_type::parse_error;
7943 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7944 return token_type::parse_error;
7949 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7950 return token_type::parse_error;
7955 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7956 return token_type::parse_error;
7961 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7962 return token_type::parse_error;
7967 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7968 return token_type::parse_error;
7973 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7974 return token_type::parse_error;
7979 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7980 return token_type::parse_error;
7985 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7986 return token_type::parse_error;
7991 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7992 return token_type::parse_error;
7997 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7998 return token_type::parse_error;
8003 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
8004 return token_type::parse_error;
8009 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
8010 return token_type::parse_error;
8015 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
8016 return token_type::parse_error;
8021 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
8022 return token_type::parse_error;
8027 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
8028 return token_type::parse_error;
8033 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
8034 return token_type::parse_error;
8039 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
8040 return token_type::parse_error;
8045 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
8046 return token_type::parse_error;
8051 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
8052 return token_type::parse_error;
8189 return token_type::parse_error;
8199 return token_type::parse_error;
8223 return token_type::parse_error;
8233 return token_type::parse_error;
8243 return token_type::parse_error;
8255 return token_type::parse_error;
8265 return token_type::parse_error;
8273 error_message =
"invalid string: ill-formed UTF-8 byte";
8274 return token_type::parse_error;
8281 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
8283 f = std::strtof(str, endptr);
8287 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
8289 f = std::strtod(str, endptr);
8293 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
8295 f = std::strtold(str, endptr);
8345 token_type number_type = token_type::value_unsigned;
8353 goto scan_number_minus;
8359 goto scan_number_zero;
8373 goto scan_number_any1;
8383 number_type = token_type::value_integer;
8389 goto scan_number_zero;
8403 goto scan_number_any1;
8408 error_message =
"invalid number; expected digit after '-'";
8409 return token_type::parse_error;
8419 add(decimal_point_char);
8420 goto scan_number_decimal1;
8427 goto scan_number_exponent;
8431 goto scan_number_done;
8450 goto scan_number_any1;
8455 add(decimal_point_char);
8456 goto scan_number_decimal1;
8463 goto scan_number_exponent;
8467 goto scan_number_done;
8470 scan_number_decimal1:
8472 number_type = token_type::value_float;
8487 goto scan_number_decimal2;
8492 error_message =
"invalid number; expected digit after '.'";
8493 return token_type::parse_error;
8497 scan_number_decimal2:
8513 goto scan_number_decimal2;
8520 goto scan_number_exponent;
8524 goto scan_number_done;
8527 scan_number_exponent:
8529 number_type = token_type::value_float;
8536 goto scan_number_sign;
8551 goto scan_number_any2;
8557 "invalid number; expected '+', '-', or digit after exponent";
8558 return token_type::parse_error;
8578 goto scan_number_any2;
8583 error_message =
"invalid number; expected digit after exponent sign";
8584 return token_type::parse_error;
8604 goto scan_number_any2;
8608 goto scan_number_done;
8616 char* endptr =
nullptr;
8620 if (number_type == token_type::value_unsigned)
8622 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8625 assert(endptr == token_buffer.data() + token_buffer.size());
8630 if (value_unsigned ==
x)
8632 return token_type::value_unsigned;
8636 else if (number_type == token_type::value_integer)
8638 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8641 assert(endptr == token_buffer.data() + token_buffer.size());
8646 if (value_integer ==
x)
8648 return token_type::value_integer;
8655 strtof(value_float, token_buffer.data(), &endptr);
8658 assert(endptr == token_buffer.data() + token_buffer.size());
8660 return token_type::value_float;
8672 assert(current == literal_text[0]);
8673 for (std::size_t i = 1; i <
length; ++i)
8677 error_message =
"invalid literal";
8678 return token_type::parse_error;
8689 void reset() noexcept
8691 token_buffer.clear();
8692 token_string.clear();
8693 token_string.push_back(std::char_traits<char>::to_char_type(current));
8706 std::char_traits<char>::int_type
get()
8709 ++
position.chars_read_current_line;
8718 current = ia->get_character();
8723 token_string.push_back(std::char_traits<char>::to_char_type(current));
8726 if (current ==
'\n')
8729 position.chars_read_current_line = 0;
8750 if (
position.chars_read_current_line == 0)
8759 --
position.chars_read_current_line;
8764 assert(not token_string.empty());
8765 token_string.pop_back();
8772 token_buffer.push_back(std::char_traits<char>::to_char_type(c));
8783 return value_integer;
8789 return value_unsigned;
8801 return token_buffer;
8817 std::string get_token_string()
const
8821 for (
const auto c : token_string)
8823 if (
'\x00' <=
c and
c <=
'\x1F')
8826 std::array<char, 9> cs{{}};
8827 (std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(
c));
8828 result += cs.data();
8833 result.push_back(
c);
8842 constexpr
const char* get_error_message() const noexcept
8844 return error_message;
8860 return get() == 0xBB and
get() == 0xBF;
8872 if (
position.chars_read_total == 0 and not skip_bom())
8874 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8875 return token_type::parse_error;
8883 while (current ==
' ' or current ==
'\t' or current ==
'\n' or current ==
'\r');
8889 return token_type::begin_array;
8891 return token_type::end_array;
8893 return token_type::begin_object;
8895 return token_type::end_object;
8897 return token_type::name_separator;
8899 return token_type::value_separator;
8903 return scan_literal(
"true", 4, token_type::literal_true);
8905 return scan_literal(
"false", 5, token_type::literal_false);
8907 return scan_literal(
"null", 4, token_type::literal_null);
8911 return scan_string();
8925 return scan_number();
8930 case std::char_traits<char>::eof():
8931 return token_type::end_of_input;
8935 error_message =
"invalid literal";
8936 return token_type::parse_error;
8945 std::char_traits<char>::int_type current = std::char_traits<char>::eof();
8948 bool next_unget =
false;
8954 std::vector<char> token_string {};
8960 const char* error_message =
"";
8968 const char decimal_point_char =
'.';
8979 #include <functional>
9012 template<
typename BasicJsonType>
9039 using parser_callback_t =
9040 std::function<bool(int depth, parse_event_t event, BasicJsonType& parsed)>;
9045 const bool allow_exceptions_ =
true)
9046 : callback(
cb), m_lexer(std::move(adapter)), allow_exceptions(allow_exceptions_)
9062 void parse(
const bool strict, BasicJsonType& result)
9067 sax_parse_internal(&sdp);
9068 result.assert_invariant();
9071 if (strict and (get_token() != token_type::end_of_input))
9074 m_lexer.get_token_string(),
9075 parse_error::create(101, m_lexer.get_position(),
9076 exception_message(token_type::end_of_input,
"value")));
9082 result = value_t::discarded;
9088 if (result.is_discarded())
9096 sax_parse_internal(&sdp);
9097 result.assert_invariant();
9100 if (strict and (get_token() != token_type::end_of_input))
9103 m_lexer.get_token_string(),
9104 parse_error::create(101, m_lexer.get_position(),
9105 exception_message(token_type::end_of_input,
"value")));
9111 result = value_t::discarded;
9123 bool accept(
const bool strict =
true)
9126 return sax_parse(&sax_acceptor, strict);
9129 template <
typename SAX>
9131 bool sax_parse(SAX* sax, const
bool strict =
true)
9134 const bool result = sax_parse_internal(sax);
9137 if (result and strict and (get_token() != token_type::end_of_input))
9139 return sax->parse_error(m_lexer.get_position(),
9140 m_lexer.get_token_string(),
9141 parse_error::create(101, m_lexer.get_position(),
9142 exception_message(token_type::end_of_input,
"value")));
9149 template <
typename SAX>
9151 bool sax_parse_internal(SAX* sax)
9155 std::vector<bool> states;
9157 bool skip_to_state_evaluation =
false;
9161 if (not skip_to_state_evaluation)
9166 case token_type::begin_object:
9174 if (get_token() == token_type::end_object)
9186 return sax->parse_error(m_lexer.get_position(),
9187 m_lexer.get_token_string(),
9188 parse_error::create(101, m_lexer.get_position(),
9189 exception_message(token_type::value_string,
"object key")));
9199 return sax->parse_error(m_lexer.get_position(),
9200 m_lexer.get_token_string(),
9201 parse_error::create(101, m_lexer.get_position(),
9202 exception_message(token_type::name_separator,
"object separator")));
9206 states.push_back(
false);
9213 case token_type::begin_array:
9221 if (get_token() == token_type::end_array)
9231 states.push_back(
true);
9237 case token_type::value_float:
9239 const auto res = m_lexer.get_number_float();
9243 return sax->parse_error(m_lexer.get_position(),
9244 m_lexer.get_token_string(),
9245 out_of_range::create(406,
"number overflow parsing '" + m_lexer.get_token_string() +
"'"));
9256 case token_type::literal_false:
9265 case token_type::literal_null:
9274 case token_type::literal_true:
9283 case token_type::value_integer:
9292 case token_type::value_string:
9301 case token_type::value_unsigned:
9310 case token_type::parse_error:
9313 return sax->parse_error(m_lexer.get_position(),
9314 m_lexer.get_token_string(),
9315 parse_error::create(101, m_lexer.get_position(),
9316 exception_message(token_type::uninitialized,
"value")));
9321 return sax->parse_error(m_lexer.get_position(),
9322 m_lexer.get_token_string(),
9323 parse_error::create(101, m_lexer.get_position(),
9324 exception_message(token_type::literal_or_value,
"value")));
9330 skip_to_state_evaluation =
false;
9343 if (get_token() == token_type::value_separator)
9362 assert(not states.empty());
9364 skip_to_state_evaluation =
true;
9368 return sax->parse_error(m_lexer.get_position(),
9369 m_lexer.get_token_string(),
9370 parse_error::create(101, m_lexer.get_position(),
9371 exception_message(token_type::end_array,
"array")));
9376 if (get_token() == token_type::value_separator)
9381 return sax->parse_error(m_lexer.get_position(),
9382 m_lexer.get_token_string(),
9383 parse_error::create(101, m_lexer.get_position(),
9384 exception_message(token_type::value_string,
"object key")));
9395 return sax->parse_error(m_lexer.get_position(),
9396 m_lexer.get_token_string(),
9397 parse_error::create(101, m_lexer.get_position(),
9398 exception_message(token_type::name_separator,
"object separator")));
9418 assert(not states.empty());
9420 skip_to_state_evaluation =
true;
9424 return sax->parse_error(m_lexer.get_position(),
9425 m_lexer.get_token_string(),
9426 parse_error::create(101, m_lexer.get_position(),
9427 exception_message(token_type::end_object,
"object")));
9435 return last_token = m_lexer.scan();
9438 std::string exception_message(
const token_type expected,
const std::string& context)
9440 std::string error_msg =
"syntax error ";
9442 if (not context.empty())
9444 error_msg +=
"while parsing " + context +
" ";
9449 if (last_token == token_type::parse_error)
9451 error_msg += std::string(m_lexer.get_error_message()) +
"; last read: '" +
9452 m_lexer.get_token_string() +
"'";
9456 error_msg +=
"unexpected " + std::string(lexer_t::token_type_name(last_token));
9459 if (expected != token_type::uninitialized)
9461 error_msg +=
"; expected " + std::string(lexer_t::token_type_name(expected));
9475 const bool allow_exceptions =
true;
9519 void set_begin() noexcept
9525 void set_end() noexcept
9531 constexpr
bool is_begin() const noexcept
9533 return m_it == begin_value;
9537 constexpr
bool is_end() const noexcept
9539 return m_it == end_value;
9544 return lhs.m_it == rhs.m_it;
9549 return lhs.m_it < rhs.m_it;
9554 auto result = *
this;
9561 return lhs.m_it - rhs.m_it;
9572 auto result = *
this;
9585 auto result = *
this;
9619 typename BasicJsonType::object_t::iterator object_iterator {};
9621 typename BasicJsonType::array_t::iterator array_iterator {};
9633 #include <type_traits>
9655 template<
typename IteratorType>
class iteration_proxy;
9656 template<
typename IteratorType>
class iteration_proxy_value;
9674 template<
typename BasicJsonType>
9687 "iter_impl only accepts (const) basic_json");
9704 typename BasicJsonType::const_pointer,
9705 typename BasicJsonType::pointer>::type;
9709 typename BasicJsonType::const_reference,
9710 typename BasicJsonType::reference>::type;
9723 assert(m_object !=
nullptr);
9725 switch (m_object->m_type)
9727 case value_t::object:
9729 m_it.object_iterator =
typename object_t::iterator();
9733 case value_t::array:
9735 m_it.array_iterator =
typename array_t::iterator();
9764 : m_object(other.m_object), m_it(other.m_it)
9786 : m_object(other.m_object), m_it(other.m_it)
9807 void set_begin() noexcept
9809 assert(m_object !=
nullptr);
9811 switch (m_object->m_type)
9813 case value_t::object:
9815 m_it.object_iterator = m_object->m_value.object->begin();
9819 case value_t::array:
9821 m_it.array_iterator = m_object->m_value.array->begin();
9828 m_it.primitive_iterator.set_end();
9834 m_it.primitive_iterator.set_begin();
9844 void set_end() noexcept
9846 assert(m_object !=
nullptr);
9848 switch (m_object->m_type)
9850 case value_t::object:
9852 m_it.object_iterator = m_object->m_value.object->end();
9856 case value_t::array:
9858 m_it.array_iterator = m_object->m_value.array->end();
9864 m_it.primitive_iterator.set_end();
9877 assert(m_object !=
nullptr);
9879 switch (m_object->m_type)
9881 case value_t::object:
9883 assert(m_it.object_iterator != m_object->m_value.object->end());
9884 return m_it.object_iterator->second;
9887 case value_t::array:
9889 assert(m_it.array_iterator != m_object->m_value.array->end());
9890 return *m_it.array_iterator;
9894 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
9903 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
9914 assert(m_object !=
nullptr);
9916 switch (m_object->m_type)
9918 case value_t::object:
9920 assert(m_it.object_iterator != m_object->m_value.object->end());
9921 return &(m_it.object_iterator->second);
9924 case value_t::array:
9926 assert(m_it.array_iterator != m_object->m_value.array->end());
9927 return &*m_it.array_iterator;
9937 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
9948 auto result = *
this;
9959 assert(m_object !=
nullptr);
9961 switch (m_object->m_type)
9963 case value_t::object:
9965 std::advance(m_it.object_iterator, 1);
9969 case value_t::array:
9971 std::advance(m_it.array_iterator, 1);
9977 ++m_it.primitive_iterator;
9991 auto result = *
this;
10002 assert(m_object !=
nullptr);
10004 switch (m_object->m_type)
10006 case value_t::object:
10008 std::advance(m_it.object_iterator, -1);
10012 case value_t::array:
10014 std::advance(m_it.array_iterator, -1);
10020 --m_it.primitive_iterator;
10037 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
10040 assert(m_object !=
nullptr);
10042 switch (m_object->m_type)
10044 case value_t::object:
10047 case value_t::array:
10073 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
10076 assert(m_object !=
nullptr);
10078 switch (m_object->m_type)
10080 case value_t::object:
10081 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
10083 case value_t::array:
10097 return not other.operator < (*this);
10124 assert(m_object !=
nullptr);
10126 switch (m_object->m_type)
10128 case value_t::object:
10129 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
10131 case value_t::array:
10133 std::advance(m_it.array_iterator, i);
10139 m_it.primitive_iterator += i;
10153 return operator+=(-i);
10162 auto result = *
this;
10184 auto result = *
this;
10195 assert(m_object !=
nullptr);
10197 switch (m_object->m_type)
10199 case value_t::object:
10200 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
10202 case value_t::array:
10216 assert(m_object !=
nullptr);
10218 switch (m_object->m_type)
10220 case value_t::object:
10221 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
10223 case value_t::array:
10224 return *std::next(m_it.array_iterator, n);
10226 case value_t::null:
10227 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
10236 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
10245 const typename object_t::key_type& key()
const
10247 assert(m_object !=
nullptr);
10251 return m_it.object_iterator->first;
10254 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators"));
10281 #include <iterator>
10310 template<
typename Base>
10382 auto key() const -> decltype(std::declval<Base>().key())
10384 auto it = --this->base();
10391 auto it = --this->base();
10392 return it.operator * ();
10403 #include <algorithm>
10420 template<
typename BasicJsonType>
10450 : reference_tokens(split(
s))
10469 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
10471 [](
const std::string & a,
const std::string & b)
10473 return a +
"/" + escape(b);
10478 operator std::string()
const
10501 reference_tokens.insert(reference_tokens.end(),
10525 push_back(std::move(token));
10656 reference_tokens.pop_back();
10673 const std::string& back()
const
10680 return reference_tokens.back();
10695 void push_back(
const std::string& token)
10697 reference_tokens.push_back(token);
10701 void push_back(std::string&& token)
10703 reference_tokens.push_back(std::move(token));
10720 bool empty() const noexcept
10722 return reference_tokens.empty();
10733 static int array_index(
const std::string&
s)
10735 std::size_t processed_chars = 0;
10736 const int res = std::stoi(s, &processed_chars);
10767 BasicJsonType& get_and_create(BasicJsonType& j)
const
10769 using size_type =
typename BasicJsonType::size_type;
10774 for (
const auto& reference_token : reference_tokens)
10776 switch (result->type())
10778 case detail::value_t::null:
10780 if (reference_token ==
"0")
10783 result = &result->operator[](0);
10788 result = &result->operator[](reference_token);
10793 case detail::value_t::object:
10796 result = &result->operator[](reference_token);
10800 case detail::value_t::array:
10805 result = &result->operator[](
static_cast<size_type
>(array_index(reference_token)));
10847 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
10849 using size_type =
typename BasicJsonType::size_type;
10850 for (
const auto& reference_token : reference_tokens)
10853 if (ptr->is_null())
10857 std::all_of(reference_token.begin(), reference_token.end(),
10858 [](
const unsigned char x)
10860 return std::isdigit(
x);
10864 *ptr = (nums or reference_token ==
"-")
10865 ? detail::value_t::array
10866 : detail::value_t::object;
10869 switch (ptr->type())
10871 case detail::value_t::object:
10874 ptr = &ptr->operator[](reference_token);
10878 case detail::value_t::array:
10884 "array index '" + reference_token +
10885 "' must not begin with '0'"));
10888 if (reference_token ==
"-")
10891 ptr = &ptr->operator[](ptr->m_value.array->size());
10898 ptr = &ptr->operator[](
10899 static_cast<size_type
>(array_index(reference_token)));
10923 BasicJsonType& get_checked(BasicJsonType* ptr)
const
10925 using size_type =
typename BasicJsonType::size_type;
10926 for (
const auto& reference_token : reference_tokens)
10928 switch (ptr->type())
10930 case detail::value_t::object:
10933 ptr = &ptr->at(reference_token);
10937 case detail::value_t::array:
10943 "array index '-' (" +
std::to_string(ptr->m_value.array->size()) +
10944 ") is out of range"));
10951 "array index '" + reference_token +
10952 "' must not begin with '0'"));
10958 ptr = &ptr->at(static_cast<size_type>(array_index(reference_token)));
10988 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
10990 using size_type =
typename BasicJsonType::size_type;
10991 for (
const auto& reference_token : reference_tokens)
10993 switch (ptr->type())
10995 case detail::value_t::object:
10998 ptr = &ptr->operator[](reference_token);
11002 case detail::value_t::array:
11008 "array index '-' (" +
std::to_string(ptr->m_value.array->size()) +
11009 ") is out of range"));
11016 "array index '" + reference_token +
11017 "' must not begin with '0'"));
11023 ptr = &ptr->operator[](
11024 static_cast<size_type
>(array_index(reference_token)));
11047 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
11049 using size_type =
typename BasicJsonType::size_type;
11050 for (
const auto& reference_token : reference_tokens)
11052 switch (ptr->type())
11054 case detail::value_t::object:
11057 ptr = &ptr->at(reference_token);
11061 case detail::value_t::array:
11067 "array index '-' (" +
std::to_string(ptr->m_value.array->size()) +
11068 ") is out of range"));
11075 "array index '" + reference_token +
11076 "' must not begin with '0'"));
11082 ptr = &ptr->at(static_cast<size_type>(array_index(reference_token)));
11103 bool contains(
const BasicJsonType* ptr)
const
11105 using size_type =
typename BasicJsonType::size_type;
11106 for (
const auto& reference_token : reference_tokens)
11108 switch (ptr->type())
11110 case detail::value_t::object:
11112 if (not ptr->contains(reference_token))
11118 ptr = &ptr->operator[](reference_token);
11122 case detail::value_t::array:
11134 "array index '" + reference_token +
11135 "' must not begin with '0'"));
11140 const auto idx =
static_cast<size_type
>(array_index(reference_token));
11141 if (idx >= ptr->size())
11147 ptr = &ptr->operator[](idx);
11179 static std::vector<std::string> split(
const std::string& reference_string)
11181 std::vector<std::string> result;
11184 if (reference_string.empty())
11193 "JSON pointer must be empty or begin with '/' - was: '" +
11194 reference_string +
"'"));
11202 std::size_t slash = reference_string.find_first_of(
'/', 1),
11209 start = (slash == std::string::npos) ? 0 : slash + 1,
11211 slash = reference_string.find_first_of(
'/',
start))
11215 auto reference_token = reference_string.substr(
start, slash -
start);
11218 for (std::size_t
pos = reference_token.find_first_of(
'~');
11219 pos != std::string::npos;
11220 pos = reference_token.find_first_of(
'~',
pos + 1))
11222 assert(reference_token[
pos] ==
'~');
11226 (reference_token[
pos + 1] !=
'0' and
11227 reference_token[
pos + 1] !=
'1')))
11234 unescape(reference_token);
11235 result.push_back(reference_token);
11254 static void replace_substring(std::string&
s,
const std::string& f,
11255 const std::string&
t)
11257 assert(not f.empty());
11258 for (
auto pos = s.find(f);
11259 pos != std::string::npos;
11260 s.replace(
pos, f.size(),
t),
11261 pos = s.find(f,
pos + t.size()))
11266 static std::string escape(std::string
s)
11268 replace_substring(s,
"~",
"~0");
11269 replace_substring(s,
"/",
"~1");
11274 static void unescape(std::string&
s)
11276 replace_substring(s,
"~1",
"/");
11277 replace_substring(s,
"~0",
"~");
11287 static void flatten(
const std::string& reference_string,
11288 const BasicJsonType&
value,
11289 BasicJsonType& result)
11291 switch (value.type())
11293 case detail::value_t::array:
11295 if (value.m_value.array->empty())
11298 result[reference_string] =
nullptr;
11303 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
11306 value.m_value.array->operator[](i), result);
11312 case detail::value_t::object:
11314 if (value.m_value.object->empty())
11317 result[reference_string] =
nullptr;
11322 for (
const auto& element : *value.m_value.object)
11324 flatten(reference_string +
"/" + escape(element.first), element.second, result);
11333 result[reference_string] =
value;
11349 static BasicJsonType
11357 BasicJsonType result;
11360 for (
const auto& element : *value.m_value.object)
11391 return lhs.reference_tokens == rhs.reference_tokens;
11408 return not (lhs == rhs);
11419 #include <initializer_list>
11429 template<
typename BasicJsonType>
11436 : owned_value(std::move(
value)), value_ref(&owned_value), is_rvalue(
true)
11444 : owned_value(init), value_ref(&owned_value), is_rvalue(
true)
11451 : owned_value(std::
forward<Args>(
args)...), value_ref(&owned_value),
11465 return std::move(*value_ref);
11472 return *
static_cast<value_type const*
>(value_ref);
11477 return static_cast<value_type const*
>(value_ref);
11497 #include <algorithm>
11511 #include <algorithm>
11514 #include <iterator>
11529 virtual void write_character(CharType
c) = 0;
11530 virtual void write_characters(
const CharType*
s, std::size_t
length) = 0;
11535 template<
typename CharType>
11539 template<
typename CharType>
11547 void write_character(CharType
c)
override
11555 std::copy(s, s + length, std::back_inserter(
v));
11559 std::vector<CharType>&
v;
11563 template<
typename CharType>
11571 void write_character(CharType
c)
override
11579 stream.write(s, static_cast<std::streamsize>(length));
11587 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
11595 void write_character(CharType
c)
override
11603 str.append(s, length);
11610 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
11646 template<
typename BasicJsonType,
typename CharType>
11666 void write_bson(
const BasicJsonType& j)
11670 case value_t::object:
11672 write_bson_object(*j.m_value.object);
11678 JSON_THROW(type_error::create(317,
"to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name())));
11686 void write_cbor(
const BasicJsonType& j)
11690 case value_t::null:
11692 oa->write_character(to_char_type(0xF6));
11696 case value_t::boolean:
11698 oa->write_character(j.m_value.boolean
11699 ? to_char_type(0xF5)
11700 : to_char_type(0xF4));
11704 case value_t::number_integer:
11706 if (j.m_value.number_integer >= 0)
11711 if (j.m_value.number_integer <= 0x17)
11713 write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11717 oa->write_character(to_char_type(0x18));
11718 write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11722 oa->write_character(to_char_type(0x19));
11723 write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
11727 oa->write_character(to_char_type(0x1A));
11728 write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
11732 oa->write_character(to_char_type(0x1B));
11733 write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
11740 const auto positive_number = -1 - j.m_value.number_integer;
11741 if (j.m_value.number_integer >= -24)
11743 write_number(static_cast<std::uint8_t>(0x20 + positive_number));
11747 oa->write_character(to_char_type(0x38));
11748 write_number(static_cast<std::uint8_t>(positive_number));
11752 oa->write_character(to_char_type(0x39));
11753 write_number(static_cast<std::uint16_t>(positive_number));
11757 oa->write_character(to_char_type(0x3A));
11758 write_number(static_cast<std::uint32_t>(positive_number));
11762 oa->write_character(to_char_type(0x3B));
11763 write_number(static_cast<std::uint64_t>(positive_number));
11769 case value_t::number_unsigned:
11771 if (j.m_value.number_unsigned <= 0x17)
11773 write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
11777 oa->write_character(to_char_type(0x18));
11778 write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
11782 oa->write_character(to_char_type(0x19));
11783 write_number(static_cast<std::uint16_t>(j.m_value.number_unsigned));
11787 oa->write_character(to_char_type(0x1A));
11788 write_number(static_cast<std::uint32_t>(j.m_value.number_unsigned));
11792 oa->write_character(to_char_type(0x1B));
11793 write_number(static_cast<std::uint64_t>(j.m_value.number_unsigned));
11798 case value_t::number_float:
11800 oa->write_character(get_cbor_float_prefix(j.m_value.number_float));
11801 write_number(j.m_value.number_float);
11805 case value_t::string:
11808 const auto N = j.m_value.string->size();
11811 write_number(static_cast<std::uint8_t>(0x60 +
N));
11815 oa->write_character(to_char_type(0x78));
11816 write_number(static_cast<std::uint8_t>(
N));
11820 oa->write_character(to_char_type(0x79));
11821 write_number(static_cast<std::uint16_t>(
N));
11825 oa->write_character(to_char_type(0x7A));
11826 write_number(static_cast<std::uint32_t>(
N));
11831 oa->write_character(to_char_type(0x7B));
11832 write_number(static_cast<std::uint64_t>(
N));
11837 oa->write_characters(
11838 reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
11839 j.m_value.string->size());
11843 case value_t::array:
11846 const auto N = j.m_value.array->size();
11849 write_number(static_cast<std::uint8_t>(0x80 +
N));
11853 oa->write_character(to_char_type(0x98));
11854 write_number(static_cast<std::uint8_t>(
N));
11858 oa->write_character(to_char_type(0x99));
11859 write_number(static_cast<std::uint16_t>(
N));
11863 oa->write_character(to_char_type(0x9A));
11864 write_number(static_cast<std::uint32_t>(
N));
11869 oa->write_character(to_char_type(0x9B));
11870 write_number(static_cast<std::uint64_t>(
N));
11875 for (
const auto& el : *j.m_value.array)
11882 case value_t::object:
11885 const auto N = j.m_value.object->size();
11888 write_number(static_cast<std::uint8_t>(0xA0 +
N));
11892 oa->write_character(to_char_type(0xB8));
11893 write_number(static_cast<std::uint8_t>(
N));
11897 oa->write_character(to_char_type(0xB9));
11898 write_number(static_cast<std::uint16_t>(
N));
11902 oa->write_character(to_char_type(0xBA));
11903 write_number(static_cast<std::uint32_t>(
N));
11908 oa->write_character(to_char_type(0xBB));
11909 write_number(static_cast<std::uint64_t>(
N));
11914 for (
const auto& el : *j.m_value.object)
11916 write_cbor(el.first);
11917 write_cbor(el.second);
11930 void write_msgpack(
const BasicJsonType& j)
11934 case value_t::null:
11936 oa->write_character(to_char_type(0xC0));
11940 case value_t::boolean:
11942 oa->write_character(j.m_value.boolean
11943 ? to_char_type(0xC3)
11944 : to_char_type(0xC2));
11948 case value_t::number_integer:
11950 if (j.m_value.number_integer >= 0)
11955 if (j.m_value.number_unsigned < 128)
11958 write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11963 oa->write_character(to_char_type(0xCC));
11964 write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11969 oa->write_character(to_char_type(0xCD));
11970 write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
11975 oa->write_character(to_char_type(0xCE));
11976 write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
11981 oa->write_character(to_char_type(0xCF));
11982 write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
11987 if (j.m_value.number_integer >= -32)
11990 write_number(static_cast<std::int8_t>(j.m_value.number_integer));
11996 oa->write_character(to_char_type(0xD0));
11997 write_number(static_cast<std::int8_t>(j.m_value.number_integer));
12003 oa->write_character(to_char_type(0xD1));
12004 write_number(static_cast<std::int16_t>(j.m_value.number_integer));
12010 oa->write_character(to_char_type(0xD2));
12011 write_number(static_cast<std::int32_t>(j.m_value.number_integer));
12017 oa->write_character(to_char_type(0xD3));
12018 write_number(static_cast<std::int64_t>(j.m_value.number_integer));
12024 case value_t::number_unsigned:
12026 if (j.m_value.number_unsigned < 128)
12029 write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
12034 oa->write_character(to_char_type(0xCC));
12035 write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
12040 oa->write_character(to_char_type(0xCD));
12041 write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
12046 oa->write_character(to_char_type(0xCE));
12047 write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
12052 oa->write_character(to_char_type(0xCF));
12053 write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
12058 case value_t::number_float:
12060 oa->write_character(get_msgpack_float_prefix(j.m_value.number_float));
12061 write_number(j.m_value.number_float);
12065 case value_t::string:
12068 const auto N = j.m_value.string->size();
12072 write_number(static_cast<std::uint8_t>(0xA0 |
N));
12077 oa->write_character(to_char_type(0xD9));
12078 write_number(static_cast<std::uint8_t>(
N));
12083 oa->write_character(to_char_type(0xDA));
12084 write_number(static_cast<std::uint16_t>(
N));
12089 oa->write_character(to_char_type(0xDB));
12090 write_number(static_cast<std::uint32_t>(
N));
12094 oa->write_characters(
12095 reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
12096 j.m_value.string->size());
12100 case value_t::array:
12103 const auto N = j.m_value.array->size();
12107 write_number(static_cast<std::uint8_t>(0x90 |
N));
12112 oa->write_character(to_char_type(0xDC));
12113 write_number(static_cast<std::uint16_t>(
N));
12118 oa->write_character(to_char_type(0xDD));
12119 write_number(static_cast<std::uint32_t>(
N));
12123 for (
const auto& el : *j.m_value.array)
12130 case value_t::object:
12133 const auto N = j.m_value.object->size();
12137 write_number(static_cast<std::uint8_t>(0x80 | (
N & 0xF)));
12142 oa->write_character(to_char_type(0xDE));
12143 write_number(static_cast<std::uint16_t>(
N));
12148 oa->write_character(to_char_type(0xDF));
12149 write_number(static_cast<std::uint32_t>(
N));
12153 for (
const auto& el : *j.m_value.object)
12155 write_msgpack(el.first);
12156 write_msgpack(el.second);
12172 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
12173 const bool use_type,
const bool add_prefix =
true)
12177 case value_t::null:
12181 oa->write_character(to_char_type(
'Z'));
12186 case value_t::boolean:
12190 oa->write_character(j.m_value.boolean
12191 ? to_char_type(
'T')
12192 : to_char_type(
'F'));
12197 case value_t::number_integer:
12199 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
12203 case value_t::number_unsigned:
12205 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
12209 case value_t::number_float:
12211 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
12215 case value_t::string:
12219 oa->write_character(to_char_type(
'S'));
12221 write_number_with_ubjson_prefix(j.m_value.string->size(),
true);
12222 oa->write_characters(
12223 reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
12224 j.m_value.string->size());
12228 case value_t::array:
12232 oa->write_character(to_char_type(
'['));
12235 bool prefix_required =
true;
12236 if (use_type and not j.m_value.array->empty())
12239 const CharType first_prefix = ubjson_prefix(j.front());
12240 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
12241 [
this, first_prefix](
const BasicJsonType &
v)
12243 return ubjson_prefix(
v) == first_prefix;
12248 prefix_required =
false;
12249 oa->write_character(to_char_type(
'$'));
12250 oa->write_character(first_prefix);
12256 oa->write_character(to_char_type(
'#'));
12257 write_number_with_ubjson_prefix(j.m_value.array->size(),
true);
12260 for (
const auto& el : *j.m_value.array)
12262 write_ubjson(el, use_count, use_type, prefix_required);
12267 oa->write_character(to_char_type(
']'));
12273 case value_t::object:
12277 oa->write_character(to_char_type(
'{'));
12280 bool prefix_required =
true;
12281 if (use_type and not j.m_value.object->empty())
12284 const CharType first_prefix = ubjson_prefix(j.front());
12285 const bool same_prefix = std::all_of(j.begin(), j.end(),
12286 [
this, first_prefix](
const BasicJsonType &
v)
12288 return ubjson_prefix(
v) == first_prefix;
12293 prefix_required =
false;
12294 oa->write_character(to_char_type(
'$'));
12295 oa->write_character(first_prefix);
12301 oa->write_character(to_char_type(
'#'));
12302 write_number_with_ubjson_prefix(j.m_value.object->size(),
true);
12305 for (
const auto& el : *j.m_value.object)
12307 write_number_with_ubjson_prefix(el.first.size(),
true);
12308 oa->write_characters(
12309 reinterpret_cast<const CharType*>(el.first.c_str()),
12311 write_ubjson(el.second, use_count, use_type, prefix_required);
12316 oa->write_character(to_char_type(
'}'));
12338 const auto it = name.find(static_cast<typename string_t::value_type>(0));
12342 "BSON key cannot contain code point U+0000 (at byte " +
std::to_string(
it) +
")"));
12345 return 1ul + name.size() + 1
u;
12354 oa->write_character(to_char_type(element_type));
12355 oa->write_characters(
12356 reinterpret_cast<const CharType*>(name.c_str()),
12366 write_bson_entry_header(name, 0x08);
12367 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
12374 const double value)
12376 write_bson_entry_header(name, 0x01);
12377 write_number<double, true>(
value);
12385 return sizeof(std::int32_t) + value.size() + 1ul;
12394 write_bson_entry_header(name, 0x02);
12396 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size() + 1ul));
12397 oa->write_characters(
12398 reinterpret_cast<const CharType*>(value.c_str()),
12407 write_bson_entry_header(name, 0x0A);
12413 static std::size_t calc_bson_integer_size(
const std::int64_t
value)
12416 ?
sizeof(std::int32_t)
12417 :
sizeof(std::int64_t);
12424 const std::int64_t
value)
12428 write_bson_entry_header(name, 0x10);
12429 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(
value));
12433 write_bson_entry_header(name, 0x12);
12434 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(
value));
12441 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t
value) noexcept
12444 ?
sizeof(std::int32_t)
12445 :
sizeof(std::int64_t);
12452 const std::uint64_t
value)
12456 write_bson_entry_header(name, 0x10 );
12457 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(
value));
12461 write_bson_entry_header(name, 0x12 );
12462 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(
value));
12466 JSON_THROW(out_of_range::create(407,
"integer number " +
std::to_string(value) +
" cannot be represented by BSON as it does not fit int64"));
12474 const typename BasicJsonType::object_t&
value)
12476 write_bson_entry_header(name, 0x03);
12477 write_bson_object(value);
12483 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t&
value)
12485 std::size_t array_index = 0ul;
12487 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)
12489 return result + calc_bson_element_size(
std::to_string(array_index++), el);
12492 return sizeof(std::int32_t) + embedded_document_size + 1ul;
12499 const typename BasicJsonType::array_t&
value)
12501 write_bson_entry_header(name, 0x04);
12502 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_array_size(value)));
12504 std::size_t array_index = 0ul;
12506 for (
const auto& el : value)
12511 oa->write_character(to_char_type(0x00));
12519 const BasicJsonType& j)
12521 const auto header_size = calc_bson_entry_header_size(name);
12524 case value_t::object:
12525 return header_size + calc_bson_object_size(*j.m_value.object);
12527 case value_t::array:
12528 return header_size + calc_bson_array_size(*j.m_value.array);
12530 case value_t::boolean:
12531 return header_size + 1ul;
12533 case value_t::number_float:
12534 return header_size + 8ul;
12536 case value_t::number_integer:
12537 return header_size + calc_bson_integer_size(j.m_value.number_integer);
12539 case value_t::number_unsigned:
12540 return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
12542 case value_t::string:
12543 return header_size + calc_bson_string_size(*j.m_value.string);
12545 case value_t::null:
12546 return header_size + 0ul;
12564 const BasicJsonType& j)
12568 case value_t::object:
12569 return write_bson_object_entry(name, *j.m_value.object);
12571 case value_t::array:
12572 return write_bson_array(name, *j.m_value.array);
12574 case value_t::boolean:
12575 return write_bson_boolean(name, j.m_value.boolean);
12577 case value_t::number_float:
12578 return write_bson_double(name, j.m_value.number_float);
12580 case value_t::number_integer:
12581 return write_bson_integer(name, j.m_value.number_integer);
12583 case value_t::number_unsigned:
12584 return write_bson_unsigned(name, j.m_value.number_unsigned);
12586 case value_t::string:
12587 return write_bson_string(name, *j.m_value.string);
12589 case value_t::null:
12590 return write_bson_null(name);
12606 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t&
value)
12608 std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
12611 return result += calc_bson_element_size(el.first, el.second);
12614 return sizeof(std::int32_t) + document_size + 1ul;
12621 void write_bson_object(
const typename BasicJsonType::object_t&
value)
12623 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_object_size(value)));
12625 for (
const auto& el : value)
12627 write_bson_element(el.first, el.second);
12630 oa->write_character(to_char_type(0x00));
12637 static constexpr CharType get_cbor_float_prefix(
float )
12639 return to_char_type(0xFA);
12642 static constexpr CharType get_cbor_float_prefix(
double )
12644 return to_char_type(0xFB);
12651 static constexpr CharType get_msgpack_float_prefix(
float )
12653 return to_char_type(0xCA);
12656 static constexpr CharType get_msgpack_float_prefix(
double )
12658 return to_char_type(0xCB);
12666 template<
typename NumberType,
typename std::enable_if<
12668 void write_number_with_ubjson_prefix(
const NumberType
n,
12669 const bool add_prefix)
12673 oa->write_character(get_ubjson_float_prefix(n));
12679 template<
typename NumberType,
typename std::enable_if<
12681 void write_number_with_ubjson_prefix(
const NumberType
n,
12682 const bool add_prefix)
12688 oa->write_character(to_char_type(
'i'));
12690 write_number(static_cast<std::uint8_t>(n));
12696 oa->write_character(to_char_type(
'U'));
12698 write_number(static_cast<std::uint8_t>(n));
12704 oa->write_character(to_char_type(
'I'));
12706 write_number(static_cast<std::int16_t>(n));
12712 oa->write_character(to_char_type(
'l'));
12714 write_number(static_cast<std::int32_t>(n));
12720 oa->write_character(to_char_type(
'L'));
12722 write_number(static_cast<std::int64_t>(n));
12726 JSON_THROW(out_of_range::create(407,
"integer number " +
std::to_string(n) +
" cannot be represented by UBJSON as it does not fit int64"));
12731 template<
typename NumberType,
typename std::enable_if<
12734 void write_number_with_ubjson_prefix(
const NumberType
n,
12735 const bool add_prefix)
12741 oa->write_character(to_char_type(
'i'));
12743 write_number(static_cast<std::int8_t>(n));
12749 oa->write_character(to_char_type(
'U'));
12751 write_number(static_cast<std::uint8_t>(n));
12757 oa->write_character(to_char_type(
'I'));
12759 write_number(static_cast<std::int16_t>(n));
12765 oa->write_character(to_char_type(
'l'));
12767 write_number(static_cast<std::int32_t>(n));
12773 oa->write_character(to_char_type(
'L'));
12775 write_number(static_cast<std::int64_t>(n));
12780 JSON_THROW(out_of_range::create(407,
"integer number " +
std::to_string(n) +
" cannot be represented by UBJSON as it does not fit int64"));
12794 CharType ubjson_prefix(
const BasicJsonType& j)
const noexcept
12798 case value_t::null:
12801 case value_t::boolean:
12802 return j.m_value.boolean ?
'T' :
'F';
12804 case value_t::number_integer:
12826 case value_t::number_unsigned:
12848 case value_t::number_float:
12849 return get_ubjson_float_prefix(j.m_value.number_float);
12851 case value_t::string:
12854 case value_t::array:
12857 case value_t::object:
12865 static constexpr CharType get_ubjson_float_prefix(
float )
12870 static constexpr CharType get_ubjson_float_prefix(
double )
12890 template<
typename NumberType,
bool OutputIsLittleEndian = false>
12891 void write_number(
const NumberType
n)
12894 std::array<CharType, sizeof(NumberType)> vec;
12895 std::memcpy(vec.data(), &
n,
sizeof(NumberType));
12898 if (is_little_endian != OutputIsLittleEndian)
12901 std::reverse(vec.begin(), vec.end());
12904 oa->write_characters(vec.data(),
sizeof(NumberType));
12912 template <
typename C = CharType,
12916 return *
reinterpret_cast<char*
>(&
x);
12919 template <
typename C = CharType,
12923 static_assert(
sizeof(
std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
12926 std::memcpy(&result, &
x,
sizeof(
x));
12930 template<
typename C = CharType,
12937 template <
typename InputCharType,
typename C = CharType,
12941 std::is_same<char, typename std::remove_cv<InputCharType>::type>
::value
12943 static constexpr CharType to_char_type(InputCharType
x) noexcept
12963 #include <algorithm>
12974 #include <type_traits>
12987 #include <type_traits>
13015 namespace dtoa_impl
13018 template <
typename Target,
typename Source>
13021 static_assert(
sizeof(
Target) ==
sizeof(
Source),
"size mismatch");
13024 std::memcpy(&target, &source,
sizeof(
Source));
13030 static constexpr
int kPrecision = 64;
13032 std::uint64_t f = 0;
13035 constexpr
diyfp(std::uint64_t f_,
int e_) noexcept : f(f_),
e(e_) {}
13043 assert(
x.e ==
y.e);
13044 assert(
x.f >=
y.f);
13046 return {
x.f -
y.f,
x.e};
13055 static_assert(kPrecision == 64,
"internal error");
13080 const std::uint64_t u_lo =
x.f & 0xFFFFFFFF
u;
13081 const std::uint64_t u_hi =
x.f >> 32
u;
13082 const std::uint64_t v_lo =
y.f & 0xFFFFFFFF
u;
13083 const std::uint64_t v_hi =
y.f >> 32
u;
13085 const std::uint64_t p0 = u_lo * v_lo;
13086 const std::uint64_t p1 = u_lo * v_hi;
13087 const std::uint64_t p2 = u_hi * v_lo;
13088 const std::uint64_t p3 = u_hi * v_hi;
13090 const std::uint64_t p0_hi = p0 >> 32
u;
13091 const std::uint64_t p1_lo = p1 & 0xFFFFFFFF
u;
13092 const std::uint64_t p1_hi = p1 >> 32
u;
13093 const std::uint64_t p2_lo = p2 & 0xFFFFFFFF
u;
13094 const std::uint64_t p2_hi = p2 >> 32
u;
13096 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
13107 Q += std::uint64_t{1} << (64u - 32u - 1
u);
13109 const std::uint64_t
h = p3 + p2_hi + p1_hi + (Q >> 32
u);
13111 return {
h,
x.e +
y.e + 64};
13122 while ((
x.f >> 63
u) == 0)
13135 static diyfp normalize_to(
const diyfp&
x,
const int target_exponent) noexcept
13137 const int delta =
x.e - target_exponent;
13139 assert(delta >= 0);
13140 assert(((
x.f << delta) >> delta) ==
x.f);
13142 return {
x.f <<
delta, target_exponent};
13159 template <
typename FloatType>
13162 assert(std::isfinite(value));
13172 static_assert(std::numeric_limits<FloatType>::is_iec559,
13173 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
13175 constexpr
int kPrecision = std::numeric_limits<FloatType>::digits;
13176 constexpr
int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
13177 constexpr
int kMinExp = 1 - kBias;
13178 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
13180 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
13182 const std::uint64_t
bits = reinterpret_bits<bits_type>(
value);
13183 const std::uint64_t E = bits >> (kPrecision - 1);
13184 const std::uint64_t
F = bits & (kHiddenBit - 1);
13186 const bool is_denormal = E == 0;
13187 const diyfp v = is_denormal
13188 ?
diyfp(F, kMinExp)
13189 : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
13212 const bool lower_boundary_is_closer = F == 0 and E > 1;
13213 const diyfp m_plus = diyfp(2 * v.
f + 1, v.
e - 1);
13214 const diyfp m_minus = lower_boundary_is_closer
13215 ? diyfp(4 * v.
f - 1, v.
e - 2)
13216 : diyfp(2 * v.
f - 1, v.
e - 1);
13219 const diyfp w_plus = diyfp::normalize(m_plus);
13222 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.
e);
13224 return {diyfp::normalize(v), w_minus, w_plus};
13351 constexpr
int kCachedPowersMinDecExp = -300;
13352 constexpr
int kCachedPowersDecStep = 8;
13354 static constexpr std::array<cached_power, 79> kCachedPowers =
13357 { 0xAB70FE17C79AC6CA, -1060, -300 },
13358 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
13359 { 0xBE5691EF416BD60C, -1007, -284 },
13360 { 0x8DD01FAD907FFC3C, -980, -276 },
13361 { 0xD3515C2831559A83, -954, -268 },
13362 { 0x9D71AC8FADA6C9B5, -927, -260 },
13363 { 0xEA9C227723EE8BCB, -901, -252 },
13364 { 0xAECC49914078536D, -874, -244 },
13365 { 0x823C12795DB6CE57, -847, -236 },
13366 { 0xC21094364DFB5637, -821, -228 },
13367 { 0x9096EA6F3848984F, -794, -220 },
13368 { 0xD77485CB25823AC7, -768, -212 },
13369 { 0xA086CFCD97BF97F4, -741, -204 },
13370 { 0xEF340A98172AACE5, -715, -196 },
13371 { 0xB23867FB2A35B28E, -688, -188 },
13372 { 0x84C8D4DFD2C63F3B, -661, -180 },
13373 { 0xC5DD44271AD3CDBA, -635, -172 },
13374 { 0x936B9FCEBB25C996, -608, -164 },
13375 { 0xDBAC6C247D62A584, -582, -156 },
13376 { 0xA3AB66580D5FDAF6, -555, -148 },
13377 { 0xF3E2F893DEC3F126, -529, -140 },
13378 { 0xB5B5ADA8AAFF80B8, -502, -132 },
13379 { 0x87625F056C7C4A8B, -475, -124 },
13380 { 0xC9BCFF6034C13053, -449, -116 },
13381 { 0x964E858C91BA2655, -422, -108 },
13382 { 0xDFF9772470297EBD, -396, -100 },
13383 { 0xA6DFBD9FB8E5B88F, -369, -92 },
13384 { 0xF8A95FCF88747D94, -343, -84 },
13385 { 0xB94470938FA89BCF, -316, -76 },
13386 { 0x8A08F0F8BF0F156B, -289, -68 },
13387 { 0xCDB02555653131B6, -263, -60 },
13388 { 0x993FE2C6D07B7FAC, -236, -52 },
13389 { 0xE45C10C42A2B3B06, -210, -44 },
13390 { 0xAA242499697392D3, -183, -36 },
13391 { 0xFD87B5F28300CA0E, -157, -28 },
13392 { 0xBCE5086492111AEB, -130, -20 },
13393 { 0x8CBCCC096F5088CC, -103, -12 },
13394 { 0xD1B71758E219652C, -77, -4 },
13395 { 0x9C40000000000000, -50, 4 },
13396 { 0xE8D4A51000000000, -24, 12 },
13397 { 0xAD78EBC5AC620000, 3, 20 },
13398 { 0x813F3978F8940984, 30, 28 },
13399 { 0xC097CE7BC90715B3, 56, 36 },
13400 { 0x8F7E32CE7BEA5C70, 83, 44 },
13401 { 0xD5D238A4ABE98068, 109, 52 },
13402 { 0x9F4F2726179A2245, 136, 60 },
13403 { 0xED63A231D4C4FB27, 162, 68 },
13404 { 0xB0DE65388CC8ADA8, 189, 76 },
13405 { 0x83C7088E1AAB65DB, 216, 84 },
13406 { 0xC45D1DF942711D9A, 242, 92 },
13407 { 0x924D692CA61BE758, 269, 100 },
13408 { 0xDA01EE641A708DEA, 295, 108 },
13409 { 0xA26DA3999AEF774A, 322, 116 },
13410 { 0xF209787BB47D6B85, 348, 124 },
13411 { 0xB454E4A179DD1877, 375, 132 },
13412 { 0x865B86925B9BC5C2, 402, 140 },
13413 { 0xC83553C5C8965D3D, 428, 148 },
13414 { 0x952AB45CFA97A0B3, 455, 156 },
13415 { 0xDE469FBD99A05FE3, 481, 164 },
13416 { 0xA59BC234DB398C25, 508, 172 },
13417 { 0xF6C69A72A3989F5C, 534, 180 },
13418 { 0xB7DCBF5354E9BECE, 561, 188 },
13419 { 0x88FCF317F22241E2, 588, 196 },
13420 { 0xCC20CE9BD35C78A5, 614, 204 },
13421 { 0x98165AF37B2153DF, 641, 212 },
13422 { 0xE2A0B5DC971F303A, 667, 220 },
13423 { 0xA8D9D1535CE3B396, 694, 228 },
13424 { 0xFB9B7CD9A4A7443C, 720, 236 },
13425 { 0xBB764C4CA7A44410, 747, 244 },
13426 { 0x8BAB8EEFB6409C1A, 774, 252 },
13427 { 0xD01FEF10A657842C, 800, 260 },
13428 { 0x9B10A4E5E9913129, 827, 268 },
13429 { 0xE7109BFBA19C0C9D, 853, 276 },
13430 { 0xAC2820D9623BF429, 880, 284 },
13431 { 0x80444B5E7AA7CF85, 907, 292 },
13432 { 0xBF21E44003ACDD2D, 933, 300 },
13433 { 0x8E679C2F5E44FF8F, 960, 308 },
13434 { 0xD433179D9C8CB841, 986, 316 },
13435 { 0x9E19DB92B4E31BA9, 1013, 324 },
13443 assert(e >= -1500);
13445 const int f =
kAlpha - e - 1;
13446 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
13448 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
13449 assert(index >= 0);
13450 assert(static_cast<std::size_t>(index) < kCachedPowers.size());
13452 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
13453 assert(
kAlpha <= cached.e + e + 64);
13454 assert(
kGamma >= cached.e + e + 64);
13466 if (n >= 1000000000)
13468 pow10 = 1000000000;
13472 else if (n >= 100000000)
13477 else if (n >= 10000000)
13482 else if (n >= 1000000)
13487 else if (n >= 100000)
13492 else if (n >= 10000)
13497 else if (n >= 1000)
13520 std::uint64_t rest, std::uint64_t ten_k)
13523 assert(dist <= delta);
13524 assert(rest <= delta);
13547 and delta - rest >= ten_k
13548 and (rest + ten_k < dist or dist - rest > rest + ten_k - dist))
13550 assert(buf[len - 1] !=
'0');
13563 static_assert(
kAlpha >= -60,
"internal error");
13564 static_assert(
kGamma <= -32,
"internal error");
13581 std::uint64_t
delta = diyfp::sub(M_plus, M_minus).f;
13582 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
13591 const diyfp one(std::uint64_t{1} << -M_plus.
e, M_plus.
e);
13594 std::uint64_t p2 = M_plus.
f & (
one.f - 1);
13637 buffer[length++] =
static_cast<char>(
'0' +
d);
13656 const std::uint64_t rest = (std::uint64_t{p1} << -
one.e) + p2;
13661 decimal_exponent +=
n;
13672 const std::uint64_t ten_n = std::uint64_t{pow10} << -
one.e;
13673 grisu2_round(buffer, length, dist, delta, rest, ten_n);
13723 assert(p2 > delta);
13736 const std::uint64_t
d = p2 >> -
one.e;
13737 const std::uint64_t r = p2 & (
one.f - 1);
13744 buffer[length++] =
static_cast<char>(
'0' +
d);
13769 decimal_exponent -=
m;
13777 const std::uint64_t ten_m =
one.f;
13801 inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
13804 assert(m_plus.e == m_minus.e);
13805 assert(m_plus.e == v.e);
13818 const diyfp c_minus_k(cached.
f, cached.
e);
13821 const diyfp w = diyfp::mul(v, c_minus_k);
13822 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
13823 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
13846 const diyfp M_minus(w_minus.
f + 1, w_minus.
e);
13847 const diyfp M_plus (w_plus.
f - 1, w_plus.
e );
13849 decimal_exponent = -cached.
k;
13859 template <
typename FloatType>
13863 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
13864 "internal error: not enough precision");
13866 assert(std::isfinite(value));
13922 *buf++ =
static_cast<char>(
'0' +
k);
13926 *buf++ =
static_cast<char>(
'0' +
k / 10);
13928 *buf++ =
static_cast<char>(
'0' +
k);
13932 *buf++ =
static_cast<char>(
'0' +
k / 100);
13934 *buf++ =
static_cast<char>(
'0' +
k / 10);
13936 *buf++ =
static_cast<char>(
'0' +
k);
13954 int min_exp,
int max_exp)
13956 assert(min_exp < 0);
13957 assert(max_exp > 0);
13960 const int n = len + decimal_exponent;
13966 if (k <= n and n <= max_exp)
13971 std::memset(buf + k,
'0', static_cast<size_t>(n - k));
13975 return buf + (n + 2);
13978 if (0 < n and n <= max_exp)
13985 std::memmove(buf + (n + 1), buf + n, static_cast<size_t>(k - n));
13987 return buf + (k + 1);
13990 if (min_exp < n and n <= 0)
13995 std::memmove(buf + (2 + -n), buf, static_cast<size_t>(k));
13998 std::memset(buf + 2,
'0', static_cast<size_t>(-n));
13999 return buf + (2 + (-
n) + k);
14014 std::memmove(buf + 2, buf + 1, static_cast<size_t>(k - 1));
14035 template <
typename FloatType>
14040 static_cast<void>(last);
14041 assert(std::isfinite(value));
14044 if (std::signbit(value))
14059 assert(last - first >= std::numeric_limits<FloatType>::max_digits10);
14066 int decimal_exponent = 0;
14069 assert(len <= std::numeric_limits<FloatType>::max_digits10);
14072 constexpr
int kMinExp = -4;
14074 constexpr
int kMaxExp = std::numeric_limits<FloatType>::digits10;
14076 assert(last - first >= kMaxExp + 2);
14077 assert(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
14078 assert(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
14115 template<
typename BasicJsonType>
14134 , loc(std::localeconv())
14135 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : * (loc->thousands_sep))
14136 , decimal_point(loc->decimal_point == nullptr ?
'\0' : * (loc->decimal_point))
14137 , indent_char(ichar)
14138 , indent_string(512, indent_char)
14139 , error_handler(error_handler_)
14166 void dump(
const BasicJsonType& val,
const bool pretty_print,
14167 const bool ensure_ascii,
14168 const unsigned int indent_step,
14169 const unsigned int current_indent = 0)
14171 switch (val.m_type)
14173 case value_t::object:
14175 if (val.m_value.object->empty())
14177 o->write_characters(
"{}", 2);
14183 o->write_characters(
"{\n", 2);
14186 const auto new_indent = current_indent + indent_step;
14189 indent_string.resize(indent_string.size() * 2,
' ');
14193 auto i = val.m_value.object->cbegin();
14194 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
14196 o->write_characters(indent_string.c_str(), new_indent);
14197 o->write_character(
'\"');
14198 dump_escaped(i->first, ensure_ascii);
14199 o->write_characters(
"\": ", 3);
14200 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
14201 o->write_characters(
",\n", 2);
14205 assert(i != val.m_value.object->cend());
14206 assert(std::next(i) == val.m_value.object->cend());
14207 o->write_characters(indent_string.c_str(), new_indent);
14208 o->write_character(
'\"');
14209 dump_escaped(i->first, ensure_ascii);
14210 o->write_characters(
"\": ", 3);
14211 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
14213 o->write_character(
'\n');
14214 o->write_characters(indent_string.c_str(), current_indent);
14215 o->write_character(
'}');
14219 o->write_character(
'{');
14222 auto i = val.m_value.object->cbegin();
14223 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
14225 o->write_character(
'\"');
14226 dump_escaped(i->first, ensure_ascii);
14227 o->write_characters(
"\":", 2);
14228 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
14229 o->write_character(
',');
14233 assert(i != val.m_value.object->cend());
14234 assert(std::next(i) == val.m_value.object->cend());
14235 o->write_character(
'\"');
14236 dump_escaped(i->first, ensure_ascii);
14237 o->write_characters(
"\":", 2);
14238 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
14240 o->write_character(
'}');
14246 case value_t::array:
14248 if (val.m_value.array->empty())
14250 o->write_characters(
"[]", 2);
14256 o->write_characters(
"[\n", 2);
14259 const auto new_indent = current_indent + indent_step;
14262 indent_string.resize(indent_string.size() * 2,
' ');
14266 for (
auto i = val.m_value.array->cbegin();
14267 i != val.m_value.array->cend() - 1; ++i)
14269 o->write_characters(indent_string.c_str(), new_indent);
14270 dump(*i,
true, ensure_ascii, indent_step, new_indent);
14271 o->write_characters(
",\n", 2);
14275 assert(not val.m_value.array->empty());
14276 o->write_characters(indent_string.c_str(), new_indent);
14277 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
14279 o->write_character(
'\n');
14280 o->write_characters(indent_string.c_str(), current_indent);
14281 o->write_character(
']');
14285 o->write_character(
'[');
14288 for (
auto i = val.m_value.array->cbegin();
14289 i != val.m_value.array->cend() - 1; ++i)
14291 dump(*i,
false, ensure_ascii, indent_step, current_indent);
14292 o->write_character(
',');
14296 assert(not val.m_value.array->empty());
14297 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
14299 o->write_character(
']');
14305 case value_t::string:
14307 o->write_character(
'\"');
14308 dump_escaped(*val.m_value.string, ensure_ascii);
14309 o->write_character(
'\"');
14313 case value_t::boolean:
14315 if (val.m_value.boolean)
14317 o->write_characters(
"true", 4);
14321 o->write_characters(
"false", 5);
14326 case value_t::number_integer:
14328 dump_integer(val.m_value.number_integer);
14332 case value_t::number_unsigned:
14334 dump_integer(val.m_value.number_unsigned);
14338 case value_t::number_float:
14340 dump_float(val.m_value.number_float);
14344 case value_t::discarded:
14346 o->write_characters(
"<discarded>", 11);
14350 case value_t::null:
14352 o->write_characters(
"null", 4);
14380 std::size_t bytes = 0;
14383 std::size_t bytes_after_last_accept = 0;
14384 std::size_t undumped_chars = 0;
14386 for (std::size_t i = 0; i < s.size(); ++i)
14388 const auto byte =
static_cast<uint8_t>(s[i]);
14390 switch (decode(state, codepoint, byte))
14398 string_buffer[bytes++] =
'\\';
14399 string_buffer[bytes++] =
'b';
14405 string_buffer[bytes++] =
'\\';
14406 string_buffer[bytes++] =
't';
14412 string_buffer[bytes++] =
'\\';
14413 string_buffer[bytes++] =
'n';
14419 string_buffer[bytes++] =
'\\';
14420 string_buffer[bytes++] =
'f';
14426 string_buffer[bytes++] =
'\\';
14427 string_buffer[bytes++] =
'r';
14433 string_buffer[bytes++] =
'\\';
14434 string_buffer[bytes++] =
'\"';
14440 string_buffer[bytes++] =
'\\';
14441 string_buffer[bytes++] =
'\\';
14449 if ((codepoint <= 0x1F) or (ensure_ascii and (codepoint >= 0x7F)))
14451 if (codepoint <= 0xFFFF)
14453 (std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
14459 (std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
14469 string_buffer[bytes++] = s[i];
14478 if (string_buffer.size() - bytes < 13)
14480 o->write_characters(string_buffer.data(), bytes);
14485 bytes_after_last_accept = bytes;
14486 undumped_chars = 0;
14492 switch (error_handler)
14494 case error_handler_t::strict:
14496 std::string sn(3,
'\0');
14497 (std::snprintf)(&sn[0], sn.size(),
"%.2X", byte);
14501 case error_handler_t::ignore:
14502 case error_handler_t::replace:
14508 if (undumped_chars > 0)
14515 bytes = bytes_after_last_accept;
14517 if (error_handler == error_handler_t::replace)
14522 string_buffer[bytes++] =
'\\';
14523 string_buffer[bytes++] =
'u';
14524 string_buffer[bytes++] =
'f';
14525 string_buffer[bytes++] =
'f';
14526 string_buffer[bytes++] =
'f';
14527 string_buffer[bytes++] =
'd';
14539 if (string_buffer.size() - bytes < 13)
14541 o->write_characters(string_buffer.data(), bytes);
14545 bytes_after_last_accept = bytes;
14548 undumped_chars = 0;
14551 state = UTF8_ACCEPT;
14563 if (not ensure_ascii)
14566 string_buffer[bytes++] = s[i];
14580 o->write_characters(string_buffer.data(), bytes);
14586 switch (error_handler)
14588 case error_handler_t::strict:
14590 std::string sn(3,
'\0');
14591 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
static_cast<std::uint8_t>(s.back()));
14592 JSON_THROW(type_error::create(316,
"incomplete UTF-8 string; last byte: 0x" + sn));
14595 case error_handler_t::ignore:
14598 o->write_characters(string_buffer.data(), bytes_after_last_accept);
14602 case error_handler_t::replace:
14605 o->write_characters(string_buffer.data(), bytes_after_last_accept);
14609 o->write_characters(
"\\ufffd", 6);
14613 o->write_characters(
"\xEF\xBF\xBD", 3);
14634 unsigned int n_digits = 1;
14643 return n_digits + 1;
14647 return n_digits + 2;
14651 return n_digits + 3;
14671 void dump_integer(NumberType
x)
14673 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
14676 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
14677 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
14678 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
14679 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
14680 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
14681 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
14682 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
14683 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
14684 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
14685 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
14692 o->write_character(
'0');
14697 auto buffer_ptr = number_buffer.begin();
14702 unsigned int n_chars;
14707 abs_value = remove_sign(x);
14710 n_chars = 1 + count_digits(abs_value);
14715 n_chars = count_digits(abs_value);
14719 assert(n_chars < number_buffer.size() - 1);
14723 buffer_ptr += n_chars;
14727 while (abs_value >= 100)
14729 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
14731 *(--buffer_ptr) = digits_to_99[digits_index][1];
14732 *(--buffer_ptr) = digits_to_99[digits_index][0];
14735 if (abs_value >= 10)
14737 const auto digits_index =
static_cast<unsigned>(abs_value);
14738 *(--buffer_ptr) = digits_to_99[digits_index][1];
14739 *(--buffer_ptr) = digits_to_99[digits_index][0];
14743 *(--buffer_ptr) = static_cast<char>(
'0' + abs_value);
14746 o->write_characters(number_buffer.data(), n_chars);
14760 if (not std::isfinite(x))
14762 o->write_characters(
"null", 4);
14771 static constexpr
bool is_ieee_single_or_double
14772 = (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 24 and std::numeric_limits<number_float_t>::max_exponent == 128) or
14773 (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 53 and std::numeric_limits<number_float_t>::max_exponent == 1024);
14775 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
14780 char* begin = number_buffer.data();
14783 o->write_characters(begin, static_cast<size_t>(end - begin));
14789 static constexpr
auto d = std::numeric_limits<number_float_t>::max_digits10;
14792 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g",
d,
x);
14797 assert(static_cast<std::size_t>(len) < number_buffer.size());
14800 if (thousands_sep !=
'\0')
14802 const auto end = std::remove(number_buffer.begin(),
14803 number_buffer.begin() + len, thousands_sep);
14804 std::fill(end, number_buffer.end(),
'\0');
14805 assert((end - number_buffer.begin()) <= len);
14806 len = (end - number_buffer.begin());
14810 if (decimal_point !=
'\0' and decimal_point !=
'.')
14812 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
14813 if (dec_pos != number_buffer.end())
14819 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
14822 const bool value_is_int_like =
14823 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
14826 return c ==
'.' or
c ==
'e';
14829 if (value_is_int_like)
14831 o->write_characters(
".0", 2);
14858 static const std::array<std::uint8_t, 400> utf8d =
14861 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,
14862 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,
14863 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,
14864 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,
14865 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,
14866 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,
14867 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,
14868 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
14869 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
14870 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
14871 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,
14872 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,
14873 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,
14874 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
14880 codep = (state != UTF8_ACCEPT)
14881 ? (byte & 0x3fu) | (codep << 6
u)
14882 : (0xFFu >> type) & (byte);
14884 state = utf8d[256
u + state * 16
u + type];
14919 std::array<char, 64> number_buffer{{}};
14922 const std::lconv* loc =
nullptr;
14924 const char thousands_sep =
'\0';
14926 const char decimal_point =
'\0';
14929 std::array<char, 512> string_buffer{{}};
15040 template<detail::value_t>
friend struct detail::external_constructor;
15041 friend ::nlohmann::json_pointer<basic_json>;
15042 friend ::nlohmann::detail::parser<basic_json>;
15043 friend ::nlohmann::detail::serializer<basic_json>;
15044 template<
typename BasicJsonType>
15045 friend class ::nlohmann::detail::iter_impl;
15046 template<
typename BasicJsonType,
typename CharType>
15047 friend class ::nlohmann::detail::binary_writer;
15048 template<
typename BasicJsonType,
typename SAX>
15049 friend class ::nlohmann::detail::binary_reader;
15050 template<
typename BasicJsonType>
15051 friend class ::nlohmann::detail::json_sax_dom_parser;
15052 template<
typename BasicJsonType>
15053 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
15063 template<
typename BasicJsonType>
15065 template<
typename BasicJsonType>
15067 template<
typename Iterator>
15071 template<
typename CharType>
15083 template<
typename T,
typename SFINAE>
15144 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
15146 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
15199 result[
"copyright"] =
"(C) 2013-2017 Niels Lohmann";
15200 result[
"name"] =
"JSON for Modern C++";
15201 result[
"url"] =
"https://github.com/nlohmann/json";
15202 result[
"version"][
"string"] =
15211 result[
"platform"] =
"win32";
15212 #elif defined __linux__
15213 result[
"platform"] =
"linux";
15214 #elif defined __APPLE__
15215 result[
"platform"] =
"apple";
15216 #elif defined __unix__
15217 result[
"platform"] =
"unix";
15219 result[
"platform"] =
"unknown";
15222 #if defined(__ICC) || defined(__INTEL_COMPILER)
15223 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
15224 #elif defined(__clang__)
15225 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
15226 #elif defined(__GNUC__) || defined(__GNUG__)
15228 #elif defined(__HP_cc) || defined(__HP_aCC)
15229 result[
"compiler"] =
"hp"
15230 #elif defined(__IBMCPP__)
15231 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
15232 #elif defined(_MSC_VER)
15233 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
15234 #elif defined(__PGI)
15235 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
15236 #elif defined(__SUNPRO_CC)
15237 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
15239 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
15245 result[
"compiler"][
"c++"] =
"unknown";
15260 #if defined(JSON_HAS_CPP_14)
15263 using object_comparator_t = std::less<>;
15351 using object_t = ObjectType<StringType,
15354 AllocatorType<std::pair<
const StringType,
15401 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
15698 template<
typename T,
typename... Args>
15702 AllocatorType<T> alloc;
15703 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
15705 auto deleter = [&](
T * object)
15707 AllocatorTraits::deallocate(alloc,
object, 1);
15710 AllocatorTraits::construct(alloc,
object.
get(), std::forward<Args>(
args)...);
15711 assert(
object !=
nullptr);
15712 return object.release();
15775 case value_t::object:
15777 object = create<object_t>();
15781 case value_t::array:
15783 array = create<array_t>();
15787 case value_t::string:
15789 string = create<string_t>(
"");
15793 case value_t::boolean:
15799 case value_t::number_integer:
15805 case value_t::number_unsigned:
15811 case value_t::number_float:
15817 case value_t::null:
15828 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.7.3"));
15838 string = create<string_t>(
value);
15844 string = create<string_t>(std::move(
value));
15850 object = create<object_t>(
value);
15856 object = create<object_t>(std::move(
value));
15862 array = create<array_t>(
value);
15868 array = create<array_t>(std::move(
value));
15874 std::vector<basic_json> stack;
15877 if (
t == value_t::array)
15879 stack.reserve(array->size());
15880 std::move(array->begin(), array->end(), std::back_inserter(stack));
15882 else if (
t == value_t::object)
15884 stack.reserve(object->size());
15885 for (
auto&&
it : *
object)
15887 stack.push_back(std::move(
it.second));
15891 while (not stack.empty())
15894 basic_json current_item(std::move(stack.back()));
15902 std::back_inserter(stack));
15910 stack.push_back(std::move(
it.second));
15922 case value_t::object:
15924 AllocatorType<object_t> alloc;
15925 std::allocator_traits<decltype(alloc)>::destroy(alloc, object);
15926 std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1);
15930 case value_t::array:
15932 AllocatorType<array_t> alloc;
15933 std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
15934 std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
15938 case value_t::string:
15940 AllocatorType<string_t> alloc;
15941 std::allocator_traits<decltype(alloc)>::destroy(alloc, string);
15942 std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);
15963 void assert_invariant() const noexcept
15965 assert(m_type != value_t::object or m_value.object !=
nullptr);
15966 assert(m_type != value_t::array or m_value.array !=
nullptr);
15967 assert(m_type != value_t::string or m_value.string !=
nullptr);
16082 : m_type(v), m_value(v)
16084 assert_invariant();
16108 assert_invariant();
16168 template <
typename CompatibleType,
16174 std::
forward<CompatibleType>(val))))
16177 assert_invariant();
16206 template <
typename BasicJsonType,
16211 using other_boolean_t =
typename BasicJsonType::boolean_t;
16212 using other_number_float_t =
typename BasicJsonType::number_float_t;
16213 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
16214 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
16215 using other_string_t =
typename BasicJsonType::string_t;
16216 using other_object_t =
typename BasicJsonType::object_t;
16217 using other_array_t =
typename BasicJsonType::array_t;
16219 switch (val.type())
16221 case value_t::boolean:
16224 case value_t::number_float:
16227 case value_t::number_integer:
16230 case value_t::number_unsigned:
16233 case value_t::string:
16236 case value_t::object:
16239 case value_t::array:
16242 case value_t::null:
16245 case value_t::discarded:
16246 m_type = value_t::discarded;
16251 assert_invariant();
16329 bool type_deduction =
true,
16330 value_t manual_type = value_t::array)
16334 bool is_an_object = std::all_of(init.begin(), init.end(),
16337 return element_ref->is_array() and element_ref->size() == 2 and (*element_ref)[0].is_string();
16341 if (not type_deduction)
16344 if (manual_type == value_t::array)
16346 is_an_object =
false;
16352 JSON_THROW(type_error::create(301,
"cannot create object from initializer list"));
16359 m_type = value_t::object;
16360 m_value = value_t::object;
16364 auto element = element_ref.moved_or_copied();
16365 m_value.object->emplace(
16366 std::move(*((*element.m_value.array)[0].m_value.string)),
16367 std::move((*element.m_value.array)[1]));
16373 m_type = value_t::array;
16374 m_value.array = create<array_t>(init.begin(), init.end());
16377 assert_invariant();
16492 m_value.array = create<array_t>(cnt, val);
16493 assert_invariant();
16551 template<
class InputIT,
typename std::enable_if<
16556 assert(first.m_object !=
nullptr);
16557 assert(last.m_object !=
nullptr);
16562 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible"));
16566 m_type = first.m_object->m_type;
16571 case value_t::boolean:
16572 case value_t::number_float:
16573 case value_t::number_integer:
16574 case value_t::number_unsigned:
16575 case value_t::string:
16578 or not last.m_it.primitive_iterator.is_end()))
16580 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
16591 case value_t::number_integer:
16593 m_value.number_integer = first.m_object->m_value.number_integer;
16597 case value_t::number_unsigned:
16599 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
16603 case value_t::number_float:
16605 m_value.number_float = first.m_object->m_value.number_float;
16609 case value_t::boolean:
16611 m_value.boolean = first.m_object->m_value.boolean;
16615 case value_t::string:
16617 m_value = *first.m_object->m_value.string;
16621 case value_t::object:
16623 m_value.object = create<object_t>(first.m_it.object_iterator,
16624 last.m_it.object_iterator);
16628 case value_t::array:
16630 m_value.array = create<array_t>(first.m_it.array_iterator,
16631 last.m_it.array_iterator);
16636 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " +
16637 std::string(first.m_object->type_name())));
16640 assert_invariant();
16648 template <
typename JsonRef,
16650 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
16679 : m_type(other.m_type)
16686 case value_t::object:
16692 case value_t::array:
16698 case value_t::string:
16704 case value_t::boolean:
16710 case value_t::number_integer:
16716 case value_t::number_unsigned:
16722 case value_t::number_float:
16732 assert_invariant();
16762 : m_type(std::move(other.m_type)),
16763 m_value(std::move(other.m_value))
16769 other.m_type = value_t::null;
16770 other.m_value = {};
16772 assert_invariant();
16809 swap(m_type, other.m_type);
16810 swap(m_value, other.m_value);
16812 assert_invariant();
16833 assert_invariant();
16834 m_value.destroy(m_type);
16890 const char indent_char =
' ',
16891 const bool ensure_ascii =
false,
16899 s.
dump(*
this,
true, ensure_ascii, static_cast<unsigned int>(indent));
16903 s.
dump(*
this,
false, ensure_ascii, 0);
16971 constexpr
bool is_primitive() const noexcept
16973 return is_null() or is_string() or is_boolean() or is_number();
16998 constexpr
bool is_structured() const noexcept
17000 return is_array() or is_object();
17020 constexpr
bool is_null() const noexcept
17022 return m_type == value_t::null;
17042 constexpr
bool is_boolean() const noexcept
17044 return m_type == value_t::boolean;
17072 constexpr
bool is_number() const noexcept
17074 return is_number_integer() or is_number_float();
17101 constexpr
bool is_number_integer() const noexcept
17103 return m_type == value_t::number_integer or m_type == value_t::number_unsigned;
17129 constexpr
bool is_number_unsigned() const noexcept
17131 return m_type == value_t::number_unsigned;
17157 constexpr
bool is_number_float() const noexcept
17159 return m_type == value_t::number_float;
17179 constexpr
bool is_object() const noexcept
17181 return m_type == value_t::object;
17201 constexpr
bool is_array() const noexcept
17203 return m_type == value_t::array;
17223 constexpr
bool is_string() const noexcept
17225 return m_type == value_t::string;
17250 constexpr
bool is_discarded() const noexcept
17252 return m_type == value_t::discarded;
17293 return m_value.boolean;
17296 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(type_name())));
17302 return is_object() ? m_value.object :
nullptr;
17308 return is_object() ? m_value.object :
nullptr;
17314 return is_array() ? m_value.array :
nullptr;
17320 return is_array() ? m_value.array :
nullptr;
17326 return is_string() ? m_value.string :
nullptr;
17332 return is_string() ? m_value.string :
nullptr;
17338 return is_boolean() ? &m_value.boolean :
nullptr;
17344 return is_boolean() ? &m_value.boolean :
nullptr;
17350 return is_number_integer() ? &m_value.number_integer :
nullptr;
17356 return is_number_integer() ? &m_value.number_integer :
nullptr;
17362 return is_number_unsigned() ? &m_value.number_unsigned :
nullptr;
17368 return is_number_unsigned() ? &m_value.number_unsigned :
nullptr;
17374 return is_number_float() ? &m_value.number_float :
nullptr;
17380 return is_number_float() ? &m_value.number_float :
nullptr;
17394 template<
typename ReferenceType,
typename ThisType>
17395 static ReferenceType get_ref_impl(ThisType& obj)
17398 auto ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
17405 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name())));
17428 std::is_same<typename std::remove_const<BasicJsonType>::type, basic_json_t>
::value,
17453 BasicJsonType
get()
const
17497 template<
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
17498 detail::enable_if_t <
17499 not detail::is_basic_json<ValueType>::value and
17500 detail::has_from_json<basic_json_t, ValueType>::value and
17501 not detail::has_non_default_from_json<basic_json_t, ValueType>::value,
17503 ValueType
get()
const noexcept(noexcept(
17510 "get() cannot be used with reference types, you might want to use get_ref()");
17512 "types must be DefaultConstructible when used with get()");
17550 template<
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
17551 detail::enable_if_t<not std::is_same<basic_json_t, ValueType>::value and
17552 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
17554 ValueType
get()
const noexcept(noexcept(
17558 "get() cannot be used with reference types, you might want to use get_ref()");
17595 template<
typename ValueType,
17600 ValueType & get_to(ValueType&
v)
const noexcept(noexcept(
17608 typename T, std::size_t
N,
17609 typename Array =
T (&)[
N],
17614 std::declval<const basic_json_t&>(),
v)))
17647 template<
typename PointerType,
typename std::enable_if<
17649 auto get_ptr() noexcept -> decltype(std::declval<
basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
17652 return get_impl_ptr(static_cast<PointerType>(
nullptr));
17659 template<
typename PointerType,
typename std::enable_if<
17661 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int>::type = 0>
17662 constexpr
auto get_ptr() const noexcept -> decltype(std::declval<const
basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
17665 return get_impl_ptr(static_cast<PointerType>(
nullptr));
17695 template<
typename PointerType,
typename std::enable_if<
17697 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
17700 return get_ptr<PointerType>();
17707 template<
typename PointerType,
typename std::enable_if<
17709 constexpr
auto get()
const noexcept -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
17712 return get_ptr<PointerType>();
17741 template<
typename ReferenceType,
typename std::enable_if<
17743 ReferenceType get_ref()
17746 return get_ref_impl<ReferenceType>(*this);
17753 template<
typename ReferenceType,
typename std::enable_if<
17755 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int>::type = 0>
17756 ReferenceType get_ref()
const
17759 return get_ref_impl<ReferenceType>(*this);
17791 template <
typename ValueType,
typename std::enable_if <
17793 not std::is_same<ValueType, detail::json_ref<basic_json>>
::value and
17796 and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>
::value
17797 #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) and _MSC_VER <= 1914))
17801 ,
int >::type = 0 >
17802 operator ValueType()
const
17805 return get<ValueType>();
17852 return m_value.array->at(idx);
17862 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(type_name())));
17899 return m_value.array->at(idx);
17909 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(type_name())));
17950 return m_value.object->at(key);
17955 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found"));
17960 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(type_name())));
18001 return m_value.object->at(key);
18006 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found"));
18011 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(type_name())));
18045 m_type = value_t::array;
18046 m_value.
array = create<array_t>();
18047 assert_invariant();
18054 if (idx >= m_value.array->size())
18056 m_value.array->insert(m_value.array->end(),
18057 idx - m_value.array->size() + 1,
18061 return m_value.array->operator[](idx);
18064 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(type_name())));
18091 return m_value.
array->operator[](idx);
18094 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(type_name())));
18129 m_type = value_t::object;
18130 m_value.
object = create<object_t>();
18131 assert_invariant();
18137 return m_value.object->operator[](key);
18140 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(type_name())));
18178 assert(m_value.object->find(key) != m_value.object->end());
18182 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(type_name())));
18212 template<
typename T>
18219 m_type = value_t::object;
18220 m_value = value_t::object;
18221 assert_invariant();
18227 return m_value.object->operator[](key);
18230 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(type_name())));
18263 template<
typename T>
18270 assert(m_value.object->find(key) != m_value.object->end());
18274 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(type_name())));
18327 template<
class ValueType,
typename std::enable_if<
18329 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
18335 const auto it = find(key);
18341 return default_value;
18344 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(type_name())));
18351 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const
18399 template<
class ValueType,
typename std::enable_if<
18413 return default_value;
18417 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(type_name())));
18562 template<
class IteratorType,
typename std::enable_if<
18566 IteratorType erase(IteratorType
pos)
18571 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
18574 IteratorType result = end();
18578 case value_t::boolean:
18579 case value_t::number_float:
18580 case value_t::number_integer:
18581 case value_t::number_unsigned:
18582 case value_t::string:
18586 JSON_THROW(invalid_iterator::create(205,
"iterator out of range"));
18591 AllocatorType<string_t> alloc;
18592 std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
18593 std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
18594 m_value.string =
nullptr;
18597 m_type = value_t::null;
18598 assert_invariant();
18602 case value_t::object:
18604 result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
18608 case value_t::array:
18610 result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
18615 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(type_name())));
18667 template<
class IteratorType,
typename std::enable_if<
18671 IteratorType erase(IteratorType first, IteratorType last)
18676 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value"));
18679 IteratorType result = end();
18683 case value_t::boolean:
18684 case value_t::number_float:
18685 case value_t::number_integer:
18686 case value_t::number_unsigned:
18687 case value_t::string:
18690 or not last.m_it.primitive_iterator.is_end()))
18692 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
18697 AllocatorType<string_t> alloc;
18698 std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
18699 std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
18700 m_value.string =
nullptr;
18703 m_type = value_t::null;
18704 assert_invariant();
18708 case value_t::object:
18710 result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
18711 last.m_it.object_iterator);
18715 case value_t::array:
18717 result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
18718 last.m_it.array_iterator);
18723 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(type_name())));
18763 return m_value.object->erase(key);
18766 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(type_name())));
18803 m_value.array->erase(m_value.array->begin() +
static_cast<difference_type>(idx));
18807 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(type_name())));
18845 template<
typename KeyT>
18848 auto result = end();
18852 result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
18862 template<
typename KeyT>
18865 auto result = cend();
18869 result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
18896 template<
typename KeyT>
18900 return is_object() ? m_value.object->count(std::forward<KeyT>(key)) : 0;
18928 template<
typename KeyT,
typename std::enable_if<
18930 bool contains(KeyT && key)
const
18932 return is_object() and m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
19310 return ref.items();
19319 return ref.items();
19449 bool empty() const noexcept
19453 case value_t::null:
19459 case value_t::array:
19462 return m_value.array->empty();
19465 case value_t::object:
19468 return m_value.object->empty();
19525 case value_t::null:
19531 case value_t::array:
19534 return m_value.array->size();
19537 case value_t::object:
19540 return m_value.object->size();
19595 case value_t::array:
19598 return m_value.array->max_size();
19601 case value_t::object:
19604 return m_value.object->max_size();
19661 void clear() noexcept
19665 case value_t::number_integer:
19667 m_value.number_integer = 0;
19671 case value_t::number_unsigned:
19673 m_value.number_unsigned = 0;
19677 case value_t::number_float:
19679 m_value.number_float = 0.0;
19683 case value_t::boolean:
19685 m_value.boolean =
false;
19689 case value_t::string:
19691 m_value.string->clear();
19695 case value_t::array:
19697 m_value.array->clear();
19701 case value_t::object:
19703 m_value.object->clear();
19737 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(type_name())));
19743 m_type = value_t::array;
19744 m_value = value_t::array;
19745 assert_invariant();
19749 m_value.array->push_back(std::move(val));
19759 push_back(std::move(val));
19772 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(type_name())));
19778 m_type = value_t::array;
19779 m_value = value_t::array;
19780 assert_invariant();
19784 m_value.array->push_back(val);
19822 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(type_name())));
19828 m_type = value_t::object;
19829 m_value = value_t::object;
19830 assert_invariant();
19834 m_value.object->insert(val);
19874 if (is_object() and init.size() == 2 and (*init.begin())->is_string())
19878 std::move(key.
get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
19919 template<
class... Args>
19925 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(type_name())));
19931 m_type = value_t::array;
19932 m_value = value_t::array;
19933 assert_invariant();
19937 #ifdef JSON_HAS_CPP_17
19938 return m_value.array->emplace_back(std::forward<Args>(
args)...);
19940 m_value.array->emplace_back(std::forward<Args>(
args)...);
19941 return m_value.array->back();
19972 template<
class... Args>
19973 std::pair<iterator, bool> emplace(Args&& ...
args)
19978 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(type_name())));
19984 m_type = value_t::object;
19985 m_value = value_t::object;
19986 assert_invariant();
19990 auto res = m_value.object->emplace(std::forward<Args>(
args)...);
19993 it.m_it.object_iterator = res.first;
19996 return {
it, res.second};
20002 template<
typename... Args>
20006 assert(m_value.array !=
nullptr);
20049 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
20053 return insert_iterator(pos, val);
20056 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(type_name())));
20065 return insert(pos, val);
20100 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
20104 return insert_iterator(pos, cnt, val);
20107 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(type_name())));
20145 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(type_name())));
20151 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
20157 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
20162 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container"));
20198 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(type_name())));
20204 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
20208 return insert_iterator(pos, ilist.begin(), ilist.end());
20239 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(type_name())));
20245 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
20251 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects"));
20281 m_type = value_t::object;
20282 m_value.object = create<object_t>();
20283 assert_invariant();
20288 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(type_name())));
20292 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.
type_name())));
20297 m_value.object->operator[](
it.key()) =
it.value();
20332 m_type = value_t::object;
20333 m_value.object = create<object_t>();
20334 assert_invariant();
20339 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(type_name())));
20345 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit"));
20350 or not last.
m_object->is_object()))
20352 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects"));
20355 for (
auto it = first;
it != last; ++
it)
20357 m_value.object->operator[](
it.key()) =
it.value();
20387 assert_invariant();
20419 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(type_name())));
20452 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(type_name())));
20485 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(type_name())));
20556 const auto lhs_type = lhs.type();
20557 const auto rhs_type = rhs.type();
20559 if (lhs_type == rhs_type)
20563 case value_t::array:
20564 return *lhs.m_value.array == *rhs.m_value.array;
20566 case value_t::object:
20567 return *lhs.m_value.object == *rhs.m_value.object;
20569 case value_t::null:
20572 case value_t::string:
20573 return *lhs.m_value.string == *rhs.m_value.string;
20575 case value_t::boolean:
20576 return lhs.m_value.boolean == rhs.m_value.boolean;
20578 case value_t::number_integer:
20579 return lhs.m_value.number_integer == rhs.m_value.number_integer;
20581 case value_t::number_unsigned:
20582 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
20584 case value_t::number_float:
20585 return lhs.m_value.number_float == rhs.m_value.number_float;
20591 else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
20593 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
20595 else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
20597 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
20599 else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
20601 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
20603 else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
20605 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
20607 else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
20609 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
20611 else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
20613 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
20623 template<
typename ScalarType,
typename std::enable_if<
20634 template<
typename ScalarType,
typename std::enable_if<
20661 return not (lhs == rhs);
20668 template<
typename ScalarType,
typename std::enable_if<
20679 template<
typename ScalarType,
typename std::enable_if<
20714 const auto lhs_type = lhs.type();
20715 const auto rhs_type = rhs.type();
20717 if (lhs_type == rhs_type)
20721 case value_t::array:
20724 return (*lhs.m_value.array) < (*rhs.m_value.array);
20726 case value_t::object:
20727 return (*lhs.m_value.object) < (*rhs.m_value.object);
20729 case value_t::null:
20732 case value_t::string:
20733 return (*lhs.m_value.string) < (*rhs.m_value.string);
20735 case value_t::boolean:
20736 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
20738 case value_t::number_integer:
20739 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
20741 case value_t::number_unsigned:
20742 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
20744 case value_t::number_float:
20745 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
20751 else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
20753 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
20755 else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
20757 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
20759 else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
20761 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
20763 else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
20765 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
20767 else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
20769 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
20771 else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
20773 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
20786 template<
typename ScalarType,
typename std::enable_if<
20797 template<
typename ScalarType,
typename std::enable_if<
20825 return not (rhs < lhs);
20832 template<
typename ScalarType,
typename std::enable_if<
20843 template<
typename ScalarType,
typename std::enable_if<
20871 return not (lhs <= rhs);
20878 template<
typename ScalarType,
typename std::enable_if<
20889 template<
typename ScalarType,
typename std::enable_if<
20917 return not (lhs < rhs);
20924 template<
typename ScalarType,
typename std::enable_if<
20935 template<
typename ScalarType,
typename std::enable_if<
20985 const bool pretty_print = o.width() > 0;
20986 const auto indentation = pretty_print ? o.width() : 0;
20993 s.dump(j, pretty_print,
false, static_cast<unsigned int>(indentation));
21006 friend std::ostream& operator>>(const
basic_json& j, std::ostream& o)
21087 const bool allow_exceptions =
true)
21090 parser(i,
cb, allow_exceptions).parse(
true, result);
21096 return parser(i).accept(
true);
21152 template <
typename SAX>
21154 static
bool sax_parse(detail::input_adapter&& i, SAX* sax,
21156 const
bool strict =
true)
21160 ?
parser(std::move(i)).sax_parse(sax, strict)
21213 template<
class IteratorType,
typename std::enable_if<
21215 std::random_access_iterator_tag,
21216 typename std::iterator_traits<IteratorType>::iterator_category>
::value,
int>::type = 0>
21219 const bool allow_exceptions =
true)
21226 template<
class IteratorType,
typename std::enable_if<
21228 std::random_access_iterator_tag,
21229 typename std::iterator_traits<IteratorType>::iterator_category>
::value,
int>::type = 0>
21230 static bool accept(IteratorType first, IteratorType last)
21235 template<
class IteratorType,
class SAX,
typename std::enable_if<
21237 std::random_access_iterator_tag,
21238 typename std::iterator_traits<IteratorType>::iterator_category>
::value,
int>::type = 0>
21240 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax)
21327 const char* type_name() const noexcept
21332 case value_t::null:
21334 case value_t::object:
21336 case value_t::array:
21338 case value_t::string:
21340 case value_t::boolean:
21342 case value_t::discarded:
21343 return "discarded";
21460 std::vector<uint8_t> result;
21461 to_cbor(j, result);
21556 std::vector<uint8_t> result;
21557 to_msgpack(j, result);
21652 const bool use_size =
false,
21653 const bool use_type =
false)
21655 std::vector<uint8_t> result;
21656 to_ubjson(j, result, use_size, use_type);
21661 const bool use_size =
false,
const bool use_type =
false)
21667 const bool use_size =
false,
const bool use_type =
false)
21730 std::vector<uint8_t> result;
21731 to_bson(j, result);
21858 const bool strict =
true,
21859 const bool allow_exceptions =
true)
21864 return res ? result :
basic_json(value_t::discarded);
21870 template<
typename A1,
typename A2,
21874 const bool strict =
true,
21875 const bool allow_exceptions =
true)
21880 return res ? result :
basic_json(value_t::discarded);
21967 const bool strict =
true,
21968 const bool allow_exceptions =
true)
21973 return res ? result :
basic_json(value_t::discarded);
21979 template<
typename A1,
typename A2,
21983 const bool strict =
true,
21984 const bool allow_exceptions =
true)
21989 return res ? result :
basic_json(value_t::discarded);
22055 const bool strict =
true,
22056 const bool allow_exceptions =
true)
22061 return res ? result :
basic_json(value_t::discarded);
22067 template<
typename A1,
typename A2,
22071 const bool strict =
true,
22072 const bool allow_exceptions =
true)
22077 return res ? result :
basic_json(value_t::discarded);
22142 const bool strict =
true,
22143 const bool allow_exceptions =
true)
22148 return res ? result :
basic_json(value_t::discarded);
22154 template<
typename A1,
typename A2,
22158 const bool strict =
true,
22159 const bool allow_exceptions =
true)
22164 return res ? result :
basic_json(value_t::discarded);
22456 enum class patch_operations {
add,
remove, replace, move, copy, test, invalid};
22458 const auto get_op = [](
const std::string & op)
22464 if (op ==
"remove")
22466 return patch_operations::remove;
22468 if (op ==
"replace")
22470 return patch_operations::replace;
22474 return patch_operations::move;
22478 return patch_operations::copy;
22482 return patch_operations::test;
22485 return patch_operations::invalid;
22500 if (top_pointer != ptr)
22502 result.
at(top_pointer);
22506 const auto last_path = ptr.
back();
22512 case value_t::null:
22513 case value_t::object:
22516 parent[last_path] = val;
22520 case value_t::array:
22522 if (last_path ==
"-")
22549 const auto operation_remove = [&result](
json_pointer & ptr)
22552 const auto last_path = ptr.
back();
22560 auto it = parent.
find(last_path);
22567 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found"));
22580 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects"));
22584 for (
const auto& val : json_patch)
22587 const auto get_value = [&val](
const std::string & op,
22588 const std::string & member,
22592 auto it = val.m_value.object->find(member);
22595 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
22600 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'"));
22606 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'"));
22616 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects"));
22620 const std::string op = get_value(
"op",
"op",
true);
22621 const std::string path = get_value(op,
"path",
true);
22624 switch (get_op(op))
22628 operation_add(ptr, get_value(
"add",
"value",
false));
22632 case patch_operations::remove:
22634 operation_remove(ptr);
22638 case patch_operations::replace:
22641 result.
at(ptr) = get_value(
"replace",
"value",
false);
22645 case patch_operations::move:
22647 const std::string from_path = get_value(
"move",
"from",
true);
22657 operation_remove(from_ptr);
22658 operation_add(ptr, v);
22662 case patch_operations::copy:
22664 const std::string from_path = get_value(
"copy",
"from",
true);
22673 operation_add(ptr, v);
22677 case patch_operations::test:
22679 bool success =
false;
22684 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
22694 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump()));
22704 JSON_THROW(parse_error::create(105, 0,
"operation value '" + op +
"' is invalid"));
22747 const std::string& path =
"")
22753 if (source == target)
22758 if (source.
type() != target.
type())
22763 {
"op",
"replace"}, {
"path", path}, {
"value", target}
22768 switch (source.
type())
22770 case value_t::array:
22774 while (i < source.
size() and i < target.
size())
22777 auto temp_diff = diff(source[i], target[i], path +
"/" +
std::to_string(i));
22778 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
22787 while (i < source.
size())
22791 result.
insert(result.
begin() + end_index, object(
22800 while (i < target.
size())
22806 {
"value", target[i]}
22814 case value_t::object:
22822 if (target.
find(
it.key()) != target.
end())
22825 auto temp_diff = diff(
it.value(), target[
it.key()], path +
"/" + key);
22826 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
22833 {
"op",
"remove"}, {
"path", path +
"/" + key}
22841 if (source.
find(
it.key()) == source.
end())
22847 {
"op",
"add"}, {
"path", path +
"/" + key},
22848 {
"value",
it.value()}
22861 {
"op",
"replace"}, {
"path", path}, {
"value", target}
22925 if (not is_object())
22929 for (
auto it = apply_patch.
begin();
it != apply_patch.
end(); ++
it)
22931 if (
it.value().is_null())
22937 operator[](
it.key()).merge_patch(
it.value());
22943 *
this = apply_patch;
22987 return h(j.
dump());
23038 inline nlohmann::
json operator "" _json(const
char*
s, std::
size_t n)
23066 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
23067 #pragma GCC diagnostic pop
23069 #if defined(__clang__)
23070 #pragma GCC diagnostic pop
23074 #undef JSON_INTERNAL_CATCH
23078 #undef JSON_HAS_CPP_14
23079 #undef JSON_HAS_CPP_17
23080 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
23081 #undef NLOHMANN_BASIC_JSON_TPL
23084 #undef JSON_HEDLEY_ALWAYS_INLINE
23085 #undef JSON_HEDLEY_ARM_VERSION
23086 #undef JSON_HEDLEY_ARM_VERSION_CHECK
23087 #undef JSON_HEDLEY_ARRAY_PARAM
23088 #undef JSON_HEDLEY_ASSUME
23089 #undef JSON_HEDLEY_BEGIN_C_DECLS
23090 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
23091 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
23092 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
23093 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
23094 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
23095 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
23096 #undef JSON_HEDLEY_CLANG_HAS_WARNING
23097 #undef JSON_HEDLEY_COMPCERT_VERSION
23098 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
23099 #undef JSON_HEDLEY_CONCAT
23100 #undef JSON_HEDLEY_CONCAT3
23101 #undef JSON_HEDLEY_CONCAT3_EX
23102 #undef JSON_HEDLEY_CONCAT_EX
23103 #undef JSON_HEDLEY_CONST
23104 #undef JSON_HEDLEY_CONSTEXPR
23105 #undef JSON_HEDLEY_CONST_CAST
23106 #undef JSON_HEDLEY_CPP_CAST
23107 #undef JSON_HEDLEY_CRAY_VERSION
23108 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
23109 #undef JSON_HEDLEY_C_DECL
23110 #undef JSON_HEDLEY_DEPRECATED
23111 #undef JSON_HEDLEY_DEPRECATED_FOR
23112 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
23113 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
23114 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
23115 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
23116 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
23117 #undef JSON_HEDLEY_DIAGNOSTIC_POP
23118 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
23119 #undef JSON_HEDLEY_DMC_VERSION
23120 #undef JSON_HEDLEY_DMC_VERSION_CHECK
23121 #undef JSON_HEDLEY_EMPTY_BASES
23122 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
23123 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
23124 #undef JSON_HEDLEY_END_C_DECLS
23125 #undef JSON_HEDLEY_FLAGS
23126 #undef JSON_HEDLEY_FLAGS_CAST
23127 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
23128 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
23129 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
23130 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
23131 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
23132 #undef JSON_HEDLEY_GCC_HAS_FEATURE
23133 #undef JSON_HEDLEY_GCC_HAS_WARNING
23134 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
23135 #undef JSON_HEDLEY_GCC_VERSION
23136 #undef JSON_HEDLEY_GCC_VERSION_CHECK
23137 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
23138 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
23139 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
23140 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
23141 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
23142 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
23143 #undef JSON_HEDLEY_GNUC_HAS_WARNING
23144 #undef JSON_HEDLEY_GNUC_VERSION
23145 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
23146 #undef JSON_HEDLEY_HAS_ATTRIBUTE
23147 #undef JSON_HEDLEY_HAS_BUILTIN
23148 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
23149 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
23150 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
23151 #undef JSON_HEDLEY_HAS_EXTENSION
23152 #undef JSON_HEDLEY_HAS_FEATURE
23153 #undef JSON_HEDLEY_HAS_WARNING
23154 #undef JSON_HEDLEY_IAR_VERSION
23155 #undef JSON_HEDLEY_IAR_VERSION_CHECK
23156 #undef JSON_HEDLEY_IBM_VERSION
23157 #undef JSON_HEDLEY_IBM_VERSION_CHECK
23158 #undef JSON_HEDLEY_IMPORT
23159 #undef JSON_HEDLEY_INLINE
23160 #undef JSON_HEDLEY_INTEL_VERSION
23161 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
23162 #undef JSON_HEDLEY_IS_CONSTANT
23163 #undef JSON_HEDLEY_IS_CONSTEXPR_
23164 #undef JSON_HEDLEY_LIKELY
23165 #undef JSON_HEDLEY_MALLOC
23166 #undef JSON_HEDLEY_MESSAGE
23167 #undef JSON_HEDLEY_MSVC_VERSION
23168 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
23169 #undef JSON_HEDLEY_NEVER_INLINE
23170 #undef JSON_HEDLEY_NON_NULL
23171 #undef JSON_HEDLEY_NO_ESCAPE
23172 #undef JSON_HEDLEY_NO_RETURN
23173 #undef JSON_HEDLEY_NO_THROW
23174 #undef JSON_HEDLEY_NULL
23175 #undef JSON_HEDLEY_PELLES_VERSION
23176 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
23177 #undef JSON_HEDLEY_PGI_VERSION
23178 #undef JSON_HEDLEY_PGI_VERSION_CHECK
23179 #undef JSON_HEDLEY_PREDICT
23180 #undef JSON_HEDLEY_PRINTF_FORMAT
23181 #undef JSON_HEDLEY_PRIVATE
23182 #undef JSON_HEDLEY_PUBLIC
23183 #undef JSON_HEDLEY_PURE
23184 #undef JSON_HEDLEY_REINTERPRET_CAST
23185 #undef JSON_HEDLEY_REQUIRE
23186 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
23187 #undef JSON_HEDLEY_REQUIRE_MSG
23188 #undef JSON_HEDLEY_RESTRICT
23189 #undef JSON_HEDLEY_RETURNS_NON_NULL
23190 #undef JSON_HEDLEY_SENTINEL
23191 #undef JSON_HEDLEY_STATIC_ASSERT
23192 #undef JSON_HEDLEY_STATIC_CAST
23193 #undef JSON_HEDLEY_STRINGIFY
23194 #undef JSON_HEDLEY_STRINGIFY_EX
23195 #undef JSON_HEDLEY_SUNPRO_VERSION
23196 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
23197 #undef JSON_HEDLEY_TINYC_VERSION
23198 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
23199 #undef JSON_HEDLEY_TI_ARMCL_VERSION
23200 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
23201 #undef JSON_HEDLEY_TI_CL2000_VERSION
23202 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
23203 #undef JSON_HEDLEY_TI_CL430_VERSION
23204 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
23205 #undef JSON_HEDLEY_TI_CL6X_VERSION
23206 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
23207 #undef JSON_HEDLEY_TI_CL7X_VERSION
23208 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
23209 #undef JSON_HEDLEY_TI_CLPRU_VERSION
23210 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
23211 #undef JSON_HEDLEY_TI_VERSION
23212 #undef JSON_HEDLEY_TI_VERSION_CHECK
23213 #undef JSON_HEDLEY_UNAVAILABLE
23214 #undef JSON_HEDLEY_UNLIKELY
23215 #undef JSON_HEDLEY_UNPREDICTABLE
23216 #undef JSON_HEDLEY_UNREACHABLE
23217 #undef JSON_HEDLEY_UNREACHABLE_RETURN
23218 #undef JSON_HEDLEY_VERSION
23219 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
23220 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
23221 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
23222 #undef JSON_HEDLEY_VERSION_ENCODE
23223 #undef JSON_HEDLEY_WARNING
23224 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
23225 #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
23226 #undef JSON_HEDLEY_FALL_THROUGH
23230 #endif // INCLUDE_NLOHMANN_JSON_HPP_