simdjson 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.clang-format +5 -0
  3. data/.gitignore +14 -0
  4. data/.gitmodules +3 -0
  5. data/.rubocop.yml +9 -0
  6. data/.travis.yml +7 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +39 -0
  10. data/Rakefile +32 -0
  11. data/benchmark/apache_builds.json +4421 -0
  12. data/benchmark/demo.json +15 -0
  13. data/benchmark/github_events.json +1390 -0
  14. data/benchmark/run_benchmark.rb +30 -0
  15. data/ext/simdjson/extconf.rb +22 -0
  16. data/ext/simdjson/simdjson.cpp +76 -0
  17. data/ext/simdjson/simdjson.hpp +6 -0
  18. data/lib/simdjson/version.rb +3 -0
  19. data/lib/simdjson.rb +2 -0
  20. data/simdjson.gemspec +35 -0
  21. data/vendor/.gitkeep +0 -0
  22. data/vendor/simdjson/AUTHORS +3 -0
  23. data/vendor/simdjson/CMakeLists.txt +63 -0
  24. data/vendor/simdjson/CONTRIBUTORS +27 -0
  25. data/vendor/simdjson/Dockerfile +10 -0
  26. data/vendor/simdjson/LICENSE +201 -0
  27. data/vendor/simdjson/Makefile +203 -0
  28. data/vendor/simdjson/Notes.md +85 -0
  29. data/vendor/simdjson/README.md +581 -0
  30. data/vendor/simdjson/amalgamation.sh +158 -0
  31. data/vendor/simdjson/benchmark/CMakeLists.txt +8 -0
  32. data/vendor/simdjson/benchmark/benchmark.h +223 -0
  33. data/vendor/simdjson/benchmark/distinctuseridcompetition.cpp +347 -0
  34. data/vendor/simdjson/benchmark/linux/linux-perf-events.h +93 -0
  35. data/vendor/simdjson/benchmark/minifiercompetition.cpp +181 -0
  36. data/vendor/simdjson/benchmark/parse.cpp +393 -0
  37. data/vendor/simdjson/benchmark/parseandstatcompetition.cpp +305 -0
  38. data/vendor/simdjson/benchmark/parsingcompetition.cpp +298 -0
  39. data/vendor/simdjson/benchmark/statisticalmodel.cpp +208 -0
  40. data/vendor/simdjson/dependencies/jsoncppdist/json/json-forwards.h +344 -0
  41. data/vendor/simdjson/dependencies/jsoncppdist/json/json.h +2366 -0
  42. data/vendor/simdjson/dependencies/jsoncppdist/jsoncpp.cpp +5418 -0
  43. data/vendor/simdjson/doc/apache_builds.jsonparseandstat.png +0 -0
  44. data/vendor/simdjson/doc/gbps.png +0 -0
  45. data/vendor/simdjson/doc/github_events.jsonparseandstat.png +0 -0
  46. data/vendor/simdjson/doc/twitter.jsonparseandstat.png +0 -0
  47. data/vendor/simdjson/doc/update-center.jsonparseandstat.png +0 -0
  48. data/vendor/simdjson/images/halvarflake.png +0 -0
  49. data/vendor/simdjson/images/logo.png +0 -0
  50. data/vendor/simdjson/include/simdjson/common_defs.h +102 -0
  51. data/vendor/simdjson/include/simdjson/isadetection.h +152 -0
  52. data/vendor/simdjson/include/simdjson/jsoncharutils.h +301 -0
  53. data/vendor/simdjson/include/simdjson/jsonformatutils.h +202 -0
  54. data/vendor/simdjson/include/simdjson/jsonioutil.h +32 -0
  55. data/vendor/simdjson/include/simdjson/jsonminifier.h +30 -0
  56. data/vendor/simdjson/include/simdjson/jsonparser.h +250 -0
  57. data/vendor/simdjson/include/simdjson/numberparsing.h +587 -0
  58. data/vendor/simdjson/include/simdjson/padded_string.h +70 -0
  59. data/vendor/simdjson/include/simdjson/parsedjson.h +544 -0
  60. data/vendor/simdjson/include/simdjson/portability.h +172 -0
  61. data/vendor/simdjson/include/simdjson/simdjson.h +44 -0
  62. data/vendor/simdjson/include/simdjson/simdjson_version.h +13 -0
  63. data/vendor/simdjson/include/simdjson/simdprune_tables.h +35074 -0
  64. data/vendor/simdjson/include/simdjson/simdutf8check_arm64.h +180 -0
  65. data/vendor/simdjson/include/simdjson/simdutf8check_haswell.h +198 -0
  66. data/vendor/simdjson/include/simdjson/simdutf8check_westmere.h +169 -0
  67. data/vendor/simdjson/include/simdjson/stage1_find_marks.h +121 -0
  68. data/vendor/simdjson/include/simdjson/stage1_find_marks_arm64.h +210 -0
  69. data/vendor/simdjson/include/simdjson/stage1_find_marks_flatten.h +93 -0
  70. data/vendor/simdjson/include/simdjson/stage1_find_marks_flatten_haswell.h +95 -0
  71. data/vendor/simdjson/include/simdjson/stage1_find_marks_haswell.h +210 -0
  72. data/vendor/simdjson/include/simdjson/stage1_find_marks_macros.h +239 -0
  73. data/vendor/simdjson/include/simdjson/stage1_find_marks_westmere.h +194 -0
  74. data/vendor/simdjson/include/simdjson/stage2_build_tape.h +85 -0
  75. data/vendor/simdjson/include/simdjson/stringparsing.h +105 -0
  76. data/vendor/simdjson/include/simdjson/stringparsing_arm64.h +56 -0
  77. data/vendor/simdjson/include/simdjson/stringparsing_haswell.h +43 -0
  78. data/vendor/simdjson/include/simdjson/stringparsing_macros.h +88 -0
  79. data/vendor/simdjson/include/simdjson/stringparsing_westmere.h +41 -0
  80. data/vendor/simdjson/jsonexamples/small/jsoniter_scala/README.md +4 -0
  81. data/vendor/simdjson/scripts/dumpsimplestats.sh +11 -0
  82. data/vendor/simdjson/scripts/issue150.sh +14 -0
  83. data/vendor/simdjson/scripts/javascript/README.md +3 -0
  84. data/vendor/simdjson/scripts/javascript/generatelargejson.js +19 -0
  85. data/vendor/simdjson/scripts/minifier.sh +11 -0
  86. data/vendor/simdjson/scripts/parseandstat.sh +24 -0
  87. data/vendor/simdjson/scripts/parser.sh +11 -0
  88. data/vendor/simdjson/scripts/parsingcompdata.sh +26 -0
  89. data/vendor/simdjson/scripts/plotparse.sh +98 -0
  90. data/vendor/simdjson/scripts/selectparser.sh +11 -0
  91. data/vendor/simdjson/scripts/setupfortesting/disablehyperthreading.sh +15 -0
  92. data/vendor/simdjson/scripts/setupfortesting/powerpolicy.sh +32 -0
  93. data/vendor/simdjson/scripts/setupfortesting/setupfortesting.sh +6 -0
  94. data/vendor/simdjson/scripts/setupfortesting/turboboost.sh +51 -0
  95. data/vendor/simdjson/scripts/testjson2json.sh +99 -0
  96. data/vendor/simdjson/scripts/transitions/Makefile +10 -0
  97. data/vendor/simdjson/scripts/transitions/generatetransitions.cpp +20 -0
  98. data/vendor/simdjson/singleheader/README.md +1 -0
  99. data/vendor/simdjson/singleheader/amalgamation_demo.cpp +20 -0
  100. data/vendor/simdjson/singleheader/simdjson.cpp +1652 -0
  101. data/vendor/simdjson/singleheader/simdjson.h +39692 -0
  102. data/vendor/simdjson/src/CMakeLists.txt +67 -0
  103. data/vendor/simdjson/src/jsonioutil.cpp +35 -0
  104. data/vendor/simdjson/src/jsonminifier.cpp +285 -0
  105. data/vendor/simdjson/src/jsonparser.cpp +91 -0
  106. data/vendor/simdjson/src/parsedjson.cpp +323 -0
  107. data/vendor/simdjson/src/parsedjsoniterator.cpp +272 -0
  108. data/vendor/simdjson/src/simdjson.cpp +30 -0
  109. data/vendor/simdjson/src/stage1_find_marks.cpp +41 -0
  110. data/vendor/simdjson/src/stage2_build_tape.cpp +567 -0
  111. data/vendor/simdjson/style/clang-format-check.sh +25 -0
  112. data/vendor/simdjson/style/clang-format.sh +25 -0
  113. data/vendor/simdjson/style/run-clang-format.py +326 -0
  114. data/vendor/simdjson/tape.md +134 -0
  115. data/vendor/simdjson/tests/CMakeLists.txt +25 -0
  116. data/vendor/simdjson/tests/allparserscheckfile.cpp +192 -0
  117. data/vendor/simdjson/tests/basictests.cpp +75 -0
  118. data/vendor/simdjson/tests/jsoncheck.cpp +136 -0
  119. data/vendor/simdjson/tests/numberparsingcheck.cpp +224 -0
  120. data/vendor/simdjson/tests/pointercheck.cpp +38 -0
  121. data/vendor/simdjson/tests/singleheadertest.cpp +22 -0
  122. data/vendor/simdjson/tests/stringparsingcheck.cpp +408 -0
  123. data/vendor/simdjson/tools/CMakeLists.txt +3 -0
  124. data/vendor/simdjson/tools/cmake/FindCTargets.cmake +15 -0
  125. data/vendor/simdjson/tools/cmake/FindOptions.cmake +52 -0
  126. data/vendor/simdjson/tools/json2json.cpp +112 -0
  127. data/vendor/simdjson/tools/jsonpointer.cpp +93 -0
  128. data/vendor/simdjson/tools/jsonstats.cpp +143 -0
  129. data/vendor/simdjson/tools/minify.cpp +21 -0
  130. data/vendor/simdjson/tools/release.py +125 -0
  131. data/vendor/simdjson/windows/dirent_portable.h +1043 -0
  132. metadata +273 -0
@@ -0,0 +1,2366 @@
1
+ /// Json-cpp amalgamated header (http://jsoncpp.sourceforge.net/).
2
+ /// It is intended to be used with #include "json/json.h"
3
+
4
+ // //////////////////////////////////////////////////////////////////////
5
+ // Beginning of content of file: LICENSE
6
+ // //////////////////////////////////////////////////////////////////////
7
+
8
+ /*
9
+ The JsonCpp library's source code, including accompanying documentation,
10
+ tests and demonstration applications, are licensed under the following
11
+ conditions...
12
+
13
+ Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
14
+ jurisdictions which recognize such a disclaimer. In such jurisdictions,
15
+ this software is released into the Public Domain.
16
+
17
+ In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
18
+ 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
19
+ The JsonCpp Authors, and is released under the terms of the MIT License (see below).
20
+
21
+ In jurisdictions which recognize Public Domain property, the user of this
22
+ software may choose to accept it either as 1) Public Domain, 2) under the
23
+ conditions of the MIT License (see below), or 3) under the terms of dual
24
+ Public Domain/MIT License conditions described here, as they choose.
25
+
26
+ The MIT License is about as close to Public Domain as a license can get, and is
27
+ described in clear, concise terms at:
28
+
29
+ http://en.wikipedia.org/wiki/MIT_License
30
+
31
+ The full text of the MIT License follows:
32
+
33
+ ========================================================================
34
+ Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
35
+
36
+ Permission is hereby granted, free of charge, to any person
37
+ obtaining a copy of this software and associated documentation
38
+ files (the "Software"), to deal in the Software without
39
+ restriction, including without limitation the rights to use, copy,
40
+ modify, merge, publish, distribute, sublicense, and/or sell copies
41
+ of the Software, and to permit persons to whom the Software is
42
+ furnished to do so, subject to the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be
45
+ included in all copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
51
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
52
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54
+ SOFTWARE.
55
+ ========================================================================
56
+ (END LICENSE TEXT)
57
+
58
+ The MIT license is compatible with both the GPL and commercial
59
+ software, affording one all of the rights of Public Domain with the
60
+ minor nuisance of being required to keep the above copyright notice
61
+ and license text in the source code. Note also that by accepting the
62
+ Public Domain "license" you can re-license your copy using whatever
63
+ license you like.
64
+
65
+ */
66
+
67
+ // //////////////////////////////////////////////////////////////////////
68
+ // End of content of file: LICENSE
69
+ // //////////////////////////////////////////////////////////////////////
70
+
71
+
72
+
73
+
74
+
75
+ #ifndef JSON_AMALGAMATED_H_INCLUDED
76
+ # define JSON_AMALGAMATED_H_INCLUDED
77
+ /// If defined, indicates that the source file is amalgamated
78
+ /// to prevent private header inclusion.
79
+ #define JSON_IS_AMALGAMATION
80
+
81
+ // //////////////////////////////////////////////////////////////////////
82
+ // Beginning of content of file: include/json/version.h
83
+ // //////////////////////////////////////////////////////////////////////
84
+
85
+ // DO NOT EDIT. This file (and "version") is generated by CMake.
86
+ // Run CMake configure step to update it.
87
+ #ifndef JSON_VERSION_H_INCLUDED
88
+ #define JSON_VERSION_H_INCLUDED
89
+
90
+ #define JSONCPP_VERSION_STRING "1.8.4"
91
+ #define JSONCPP_VERSION_MAJOR 1
92
+ #define JSONCPP_VERSION_MINOR 8
93
+ #define JSONCPP_VERSION_PATCH 4
94
+ #define JSONCPP_VERSION_QUALIFIER
95
+ #define JSONCPP_VERSION_HEXA \
96
+ ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
97
+ (JSONCPP_VERSION_PATCH << 8))
98
+
99
+ #ifdef JSONCPP_USING_SECURE_MEMORY
100
+ #undef JSONCPP_USING_SECURE_MEMORY
101
+ #endif
102
+ #define JSONCPP_USING_SECURE_MEMORY 0
103
+ // If non-zero, the library zeroes any memory that it has allocated before
104
+ // it frees its memory.
105
+
106
+ #endif // JSON_VERSION_H_INCLUDED
107
+
108
+ // //////////////////////////////////////////////////////////////////////
109
+ // End of content of file: include/json/version.h
110
+ // //////////////////////////////////////////////////////////////////////
111
+
112
+
113
+
114
+
115
+
116
+
117
+ // //////////////////////////////////////////////////////////////////////
118
+ // Beginning of content of file: include/json/allocator.h
119
+ // //////////////////////////////////////////////////////////////////////
120
+
121
+ // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
122
+ // Distributed under MIT license, or public domain if desired and
123
+ // recognized in your jurisdiction.
124
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
125
+
126
+ #ifndef CPPTL_JSON_ALLOCATOR_H_INCLUDED
127
+ #define CPPTL_JSON_ALLOCATOR_H_INCLUDED
128
+
129
+ #include <cstring>
130
+ #include <memory>
131
+
132
+ #pragma pack(push, 8)
133
+
134
+ namespace Json {
135
+ template <typename T> class SecureAllocator {
136
+ public:
137
+ // Type definitions
138
+ using value_type = T;
139
+ using pointer = T*;
140
+ using const_pointer = const T*;
141
+ using reference = T&;
142
+ using const_reference = const T&;
143
+ using size_type = std::size_t;
144
+ using difference_type = std::ptrdiff_t;
145
+
146
+ /**
147
+ * Allocate memory for N items using the standard allocator.
148
+ */
149
+ pointer allocate(size_type n) {
150
+ // allocate using "global operator new"
151
+ return static_cast<pointer>(::operator new(n * sizeof(T)));
152
+ }
153
+
154
+ /**
155
+ * Release memory which was allocated for N items at pointer P.
156
+ *
157
+ * The memory block is filled with zeroes before being released.
158
+ * The pointer argument is tagged as "volatile" to prevent the
159
+ * compiler optimizing out this critical step.
160
+ */
161
+ void deallocate(volatile pointer p, size_type n) {
162
+ std::memset(p, 0, n * sizeof(T));
163
+ // free using "global operator delete"
164
+ ::operator delete(p);
165
+ }
166
+
167
+ /**
168
+ * Construct an item in-place at pointer P.
169
+ */
170
+ template <typename... Args> void construct(pointer p, Args&&... args) {
171
+ // construct using "placement new" and "perfect forwarding"
172
+ ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
173
+ }
174
+
175
+ size_type max_size() const { return size_t(-1) / sizeof(T); }
176
+
177
+ pointer address(reference x) const { return std::addressof(x); }
178
+
179
+ const_pointer address(const_reference x) const { return std::addressof(x); }
180
+
181
+ /**
182
+ * Destroy an item in-place at pointer P.
183
+ */
184
+ void destroy(pointer p) {
185
+ // destroy using "explicit destructor"
186
+ p->~T();
187
+ }
188
+
189
+ // Boilerplate
190
+ SecureAllocator() {}
191
+ template <typename U> SecureAllocator(const SecureAllocator<U>&) {}
192
+ template <typename U> struct rebind { using other = SecureAllocator<U>; };
193
+ };
194
+
195
+ template <typename T, typename U>
196
+ bool operator==(const SecureAllocator<T>&, const SecureAllocator<U>&) {
197
+ return true;
198
+ }
199
+
200
+ template <typename T, typename U>
201
+ bool operator!=(const SecureAllocator<T>&, const SecureAllocator<U>&) {
202
+ return false;
203
+ }
204
+
205
+ } // namespace Json
206
+
207
+ #pragma pack(pop)
208
+
209
+ #endif // CPPTL_JSON_ALLOCATOR_H_INCLUDED
210
+
211
+ // //////////////////////////////////////////////////////////////////////
212
+ // End of content of file: include/json/allocator.h
213
+ // //////////////////////////////////////////////////////////////////////
214
+
215
+
216
+
217
+
218
+
219
+
220
+ // //////////////////////////////////////////////////////////////////////
221
+ // Beginning of content of file: include/json/config.h
222
+ // //////////////////////////////////////////////////////////////////////
223
+
224
+ // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
225
+ // Distributed under MIT license, or public domain if desired and
226
+ // recognized in your jurisdiction.
227
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
228
+
229
+ #ifndef JSON_CONFIG_H_INCLUDED
230
+ #define JSON_CONFIG_H_INCLUDED
231
+ #include <cstddef>
232
+ #include <cstdint>
233
+ #include <istream>
234
+ #include <memory>
235
+ #include <ostream>
236
+ #include <sstream>
237
+ #include <string>
238
+ #include <type_traits>
239
+
240
+ /// If defined, indicates that json library is embedded in CppTL library.
241
+ //# define JSON_IN_CPPTL 1
242
+
243
+ /// If defined, indicates that json may leverage CppTL library
244
+ //# define JSON_USE_CPPTL 1
245
+ /// If defined, indicates that cpptl vector based map should be used instead of
246
+ /// std::map
247
+ /// as Value container.
248
+ //# define JSON_USE_CPPTL_SMALLMAP 1
249
+
250
+ // If non-zero, the library uses exceptions to report bad input instead of C
251
+ // assertion macros. The default is to use exceptions.
252
+ #ifndef JSON_USE_EXCEPTION
253
+ #define JSON_USE_EXCEPTION 1
254
+ #endif
255
+
256
+ /// If defined, indicates that the source file is amalgamated
257
+ /// to prevent private header inclusion.
258
+ /// Remarks: it is automatically defined in the generated amalgamated header.
259
+ // #define JSON_IS_AMALGAMATION
260
+
261
+ #ifdef JSON_IN_CPPTL
262
+ #include <cpptl/config.h>
263
+ #ifndef JSON_USE_CPPTL
264
+ #define JSON_USE_CPPTL 1
265
+ #endif
266
+ #endif
267
+
268
+ #ifdef JSON_IN_CPPTL
269
+ #define JSON_API CPPTL_API
270
+ #elif defined(JSON_DLL_BUILD)
271
+ #if defined(_MSC_VER) || defined(__MINGW32__)
272
+ #define JSON_API __declspec(dllexport)
273
+ #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
274
+ #endif // if defined(_MSC_VER)
275
+ #elif defined(JSON_DLL)
276
+ #if defined(_MSC_VER) || defined(__MINGW32__)
277
+ #define JSON_API __declspec(dllimport)
278
+ #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
279
+ #endif // if defined(_MSC_VER)
280
+ #endif // ifdef JSON_IN_CPPTL
281
+ #if !defined(JSON_API)
282
+ #define JSON_API
283
+ #endif
284
+
285
+ #if defined(_MSC_VER) && _MSC_VER < 1800
286
+ #error \
287
+ "ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities"
288
+ #endif
289
+
290
+ #if defined(_MSC_VER) && _MSC_VER < 1900
291
+ // As recommended at
292
+ // https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
293
+ extern JSON_API int
294
+ msvc_pre1900_c99_snprintf(char* outBuf, size_t size, const char* format, ...);
295
+ #define jsoncpp_snprintf msvc_pre1900_c99_snprintf
296
+ #else
297
+ #define jsoncpp_snprintf std::snprintf
298
+ #endif
299
+
300
+ // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
301
+ // integer
302
+ // Storages, and 64 bits integer support is disabled.
303
+ // #define JSON_NO_INT64 1
304
+
305
+ #if defined(_MSC_VER) // MSVC
306
+ #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
307
+ #endif // defined(_MSC_VER)
308
+
309
+ // JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools.
310
+ // C++11 should be used directly in JSONCPP.
311
+ #define JSONCPP_OVERRIDE override
312
+
313
+ #if __cplusplus >= 201103L
314
+ #define JSONCPP_NOEXCEPT noexcept
315
+ #define JSONCPP_OP_EXPLICIT explicit
316
+ #elif defined(_MSC_VER) && _MSC_VER < 1900
317
+ #define JSONCPP_NOEXCEPT throw()
318
+ #define JSONCPP_OP_EXPLICIT explicit
319
+ #elif defined(_MSC_VER) && _MSC_VER >= 1900
320
+ #define JSONCPP_NOEXCEPT noexcept
321
+ #define JSONCPP_OP_EXPLICIT explicit
322
+ #else
323
+ #define JSONCPP_NOEXCEPT throw()
324
+ #define JSONCPP_OP_EXPLICIT
325
+ #endif
326
+
327
+ #ifndef JSON_HAS_RVALUE_REFERENCES
328
+
329
+ #if defined(_MSC_VER)
330
+ #define JSON_HAS_RVALUE_REFERENCES 1
331
+ #endif // MSVC >= 2013
332
+
333
+ #ifdef __clang__
334
+ #if __has_feature(cxx_rvalue_references)
335
+ #define JSON_HAS_RVALUE_REFERENCES 1
336
+ #endif // has_feature
337
+
338
+ #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
339
+ #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
340
+ #define JSON_HAS_RVALUE_REFERENCES 1
341
+ #endif // GXX_EXPERIMENTAL
342
+
343
+ #endif // __clang__ || __GNUC__
344
+
345
+ #endif // not defined JSON_HAS_RVALUE_REFERENCES
346
+
347
+ #ifndef JSON_HAS_RVALUE_REFERENCES
348
+ #define JSON_HAS_RVALUE_REFERENCES 0
349
+ #endif
350
+
351
+ #ifdef __clang__
352
+ #if __has_extension(attribute_deprecated_with_message)
353
+ #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
354
+ #endif
355
+ #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
356
+ #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
357
+ #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
358
+ #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
359
+ #define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
360
+ #endif // GNUC version
361
+ #endif // __clang__ || __GNUC__
362
+
363
+ #if !defined(JSONCPP_DEPRECATED)
364
+ #define JSONCPP_DEPRECATED(message)
365
+ #endif // if !defined(JSONCPP_DEPRECATED)
366
+
367
+ #if __GNUC__ >= 6
368
+ #define JSON_USE_INT64_DOUBLE_CONVERSION 1
369
+ #endif
370
+
371
+ #if !defined(JSON_IS_AMALGAMATION)
372
+
373
+ #include "allocator.h"
374
+ #include "version.h"
375
+
376
+ #endif // if !defined(JSON_IS_AMALGAMATION)
377
+
378
+ namespace Json {
379
+ typedef int Int;
380
+ typedef unsigned int UInt;
381
+ #if defined(JSON_NO_INT64)
382
+ typedef int LargestInt;
383
+ typedef unsigned int LargestUInt;
384
+ #undef JSON_HAS_INT64
385
+ #else // if defined(JSON_NO_INT64)
386
+ // For Microsoft Visual use specific types as long long is not supported
387
+ #if defined(_MSC_VER) // Microsoft Visual Studio
388
+ typedef __int64 Int64;
389
+ typedef unsigned __int64 UInt64;
390
+ #else // if defined(_MSC_VER) // Other platforms, use long long
391
+ typedef int64_t Int64;
392
+ typedef uint64_t UInt64;
393
+ #endif // if defined(_MSC_VER)
394
+ typedef Int64 LargestInt;
395
+ typedef UInt64 LargestUInt;
396
+ #define JSON_HAS_INT64
397
+ #endif // if defined(JSON_NO_INT64)
398
+
399
+ template <typename T>
400
+ using Allocator = typename std::conditional<JSONCPP_USING_SECURE_MEMORY,
401
+ SecureAllocator<T>,
402
+ std::allocator<T>>::type;
403
+ using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
404
+ using IStringStream = std::basic_istringstream<String::value_type,
405
+ String::traits_type,
406
+ String::allocator_type>;
407
+ using OStringStream = std::basic_ostringstream<String::value_type,
408
+ String::traits_type,
409
+ String::allocator_type>;
410
+ using IStream = std::istream;
411
+ using OStream = std::ostream;
412
+ } // namespace Json
413
+
414
+ // Legacy names (formerly macros).
415
+ using JSONCPP_STRING = Json::String;
416
+ using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
417
+ using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
418
+ using JSONCPP_ISTREAM = Json::IStream;
419
+ using JSONCPP_OSTREAM = Json::OStream;
420
+
421
+ #endif // JSON_CONFIG_H_INCLUDED
422
+
423
+ // //////////////////////////////////////////////////////////////////////
424
+ // End of content of file: include/json/config.h
425
+ // //////////////////////////////////////////////////////////////////////
426
+
427
+
428
+
429
+
430
+
431
+
432
+ // //////////////////////////////////////////////////////////////////////
433
+ // Beginning of content of file: include/json/forwards.h
434
+ // //////////////////////////////////////////////////////////////////////
435
+
436
+ // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
437
+ // Distributed under MIT license, or public domain if desired and
438
+ // recognized in your jurisdiction.
439
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
440
+
441
+ #ifndef JSON_FORWARDS_H_INCLUDED
442
+ #define JSON_FORWARDS_H_INCLUDED
443
+
444
+ #if !defined(JSON_IS_AMALGAMATION)
445
+ #include "config.h"
446
+ #endif // if !defined(JSON_IS_AMALGAMATION)
447
+
448
+ namespace Json {
449
+
450
+ // writer.h
451
+ class FastWriter;
452
+ class StyledWriter;
453
+
454
+ // reader.h
455
+ class Reader;
456
+
457
+ // features.h
458
+ class Features;
459
+
460
+ // value.h
461
+ typedef unsigned int ArrayIndex;
462
+ class StaticString;
463
+ class Path;
464
+ class PathArgument;
465
+ class Value;
466
+ class ValueIteratorBase;
467
+ class ValueIterator;
468
+ class ValueConstIterator;
469
+
470
+ } // namespace Json
471
+
472
+ #endif // JSON_FORWARDS_H_INCLUDED
473
+
474
+ // //////////////////////////////////////////////////////////////////////
475
+ // End of content of file: include/json/forwards.h
476
+ // //////////////////////////////////////////////////////////////////////
477
+
478
+
479
+
480
+
481
+
482
+
483
+ // //////////////////////////////////////////////////////////////////////
484
+ // Beginning of content of file: include/json/features.h
485
+ // //////////////////////////////////////////////////////////////////////
486
+
487
+ // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
488
+ // Distributed under MIT license, or public domain if desired and
489
+ // recognized in your jurisdiction.
490
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
491
+
492
+ #ifndef CPPTL_JSON_FEATURES_H_INCLUDED
493
+ #define CPPTL_JSON_FEATURES_H_INCLUDED
494
+
495
+ #if !defined(JSON_IS_AMALGAMATION)
496
+ #include "forwards.h"
497
+ #endif // if !defined(JSON_IS_AMALGAMATION)
498
+
499
+ #pragma pack(push, 8)
500
+
501
+ namespace Json {
502
+
503
+ /** \brief Configuration passed to reader and writer.
504
+ * This configuration object can be used to force the Reader or Writer
505
+ * to behave in a standard conforming way.
506
+ */
507
+ class JSON_API Features {
508
+ public:
509
+ /** \brief A configuration that allows all features and assumes all strings
510
+ * are UTF-8.
511
+ * - C & C++ comments are allowed
512
+ * - Root object can be any JSON value
513
+ * - Assumes Value strings are encoded in UTF-8
514
+ */
515
+ static Features all();
516
+
517
+ /** \brief A configuration that is strictly compatible with the JSON
518
+ * specification.
519
+ * - Comments are forbidden.
520
+ * - Root object must be either an array or an object value.
521
+ * - Assumes Value strings are encoded in UTF-8
522
+ */
523
+ static Features strictMode();
524
+
525
+ /** \brief Initialize the configuration like JsonConfig::allFeatures;
526
+ */
527
+ Features();
528
+
529
+ /// \c true if comments are allowed. Default: \c true.
530
+ bool allowComments_{true};
531
+
532
+ /// \c true if root must be either an array or an object value. Default: \c
533
+ /// false.
534
+ bool strictRoot_{false};
535
+
536
+ /// \c true if dropped null placeholders are allowed. Default: \c false.
537
+ bool allowDroppedNullPlaceholders_{false};
538
+
539
+ /// \c true if numeric object key are allowed. Default: \c false.
540
+ bool allowNumericKeys_{false};
541
+ };
542
+
543
+ } // namespace Json
544
+
545
+ #pragma pack(pop)
546
+
547
+ #endif // CPPTL_JSON_FEATURES_H_INCLUDED
548
+
549
+ // //////////////////////////////////////////////////////////////////////
550
+ // End of content of file: include/json/features.h
551
+ // //////////////////////////////////////////////////////////////////////
552
+
553
+
554
+
555
+
556
+
557
+
558
+ // //////////////////////////////////////////////////////////////////////
559
+ // Beginning of content of file: include/json/value.h
560
+ // //////////////////////////////////////////////////////////////////////
561
+
562
+ // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
563
+ // Distributed under MIT license, or public domain if desired and
564
+ // recognized in your jurisdiction.
565
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
566
+
567
+ #ifndef CPPTL_JSON_H_INCLUDED
568
+ #define CPPTL_JSON_H_INCLUDED
569
+
570
+ #if !defined(JSON_IS_AMALGAMATION)
571
+ #include "forwards.h"
572
+ #endif // if !defined(JSON_IS_AMALGAMATION)
573
+ #include <exception>
574
+ #include <string>
575
+ #include <vector>
576
+
577
+ #ifndef JSON_USE_CPPTL_SMALLMAP
578
+ #include <map>
579
+ #else
580
+ #include <cpptl/smallmap.h>
581
+ #endif
582
+ #ifdef JSON_USE_CPPTL
583
+ #include <cpptl/forwards.h>
584
+ #endif
585
+
586
+ // Conditional NORETURN attribute on the throw functions would:
587
+ // a) suppress false positives from static code analysis
588
+ // b) possibly improve optimization opportunities.
589
+ #if !defined(JSONCPP_NORETURN)
590
+ #if defined(_MSC_VER)
591
+ #define JSONCPP_NORETURN __declspec(noreturn)
592
+ #elif defined(__GNUC__)
593
+ #define JSONCPP_NORETURN __attribute__((__noreturn__))
594
+ #else
595
+ #define JSONCPP_NORETURN
596
+ #endif
597
+ #endif
598
+
599
+ // Disable warning C4251: <data member>: <type> needs to have dll-interface to
600
+ // be used by...
601
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
602
+ #pragma warning(push)
603
+ #pragma warning(disable : 4251)
604
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
605
+
606
+ #pragma pack(push, 8)
607
+
608
+ /** \brief JSON (JavaScript Object Notation).
609
+ */
610
+ namespace Json {
611
+
612
+ /** Base class for all exceptions we throw.
613
+ *
614
+ * We use nothing but these internally. Of course, STL can throw others.
615
+ */
616
+ class JSON_API Exception : public std::exception {
617
+ public:
618
+ Exception(String msg);
619
+ ~Exception() JSONCPP_NOEXCEPT override;
620
+ char const* what() const JSONCPP_NOEXCEPT override;
621
+
622
+ protected:
623
+ String msg_;
624
+ };
625
+
626
+ /** Exceptions which the user cannot easily avoid.
627
+ *
628
+ * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
629
+ *
630
+ * \remark derived from Json::Exception
631
+ */
632
+ class JSON_API RuntimeError : public Exception {
633
+ public:
634
+ RuntimeError(String const& msg);
635
+ };
636
+
637
+ /** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
638
+ *
639
+ * These are precondition-violations (user bugs) and internal errors (our bugs).
640
+ *
641
+ * \remark derived from Json::Exception
642
+ */
643
+ class JSON_API LogicError : public Exception {
644
+ public:
645
+ LogicError(String const& msg);
646
+ };
647
+
648
+ /// used internally
649
+ JSONCPP_NORETURN void throwRuntimeError(String const& msg);
650
+ /// used internally
651
+ JSONCPP_NORETURN void throwLogicError(String const& msg);
652
+
653
+ /** \brief Type of the value held by a Value object.
654
+ */
655
+ enum ValueType {
656
+ nullValue = 0, ///< 'null' value
657
+ intValue, ///< signed integer value
658
+ uintValue, ///< unsigned integer value
659
+ realValue, ///< double value
660
+ stringValue, ///< UTF-8 string value
661
+ booleanValue, ///< bool value
662
+ arrayValue, ///< array value (ordered list)
663
+ objectValue ///< object value (collection of name/value pairs).
664
+ };
665
+
666
+ enum CommentPlacement {
667
+ commentBefore = 0, ///< a comment placed on the line before a value
668
+ commentAfterOnSameLine, ///< a comment just after a value on the same line
669
+ commentAfter, ///< a comment on the line after a value (only make sense for
670
+ /// root value)
671
+ numberOfCommentPlacement
672
+ };
673
+
674
+ /** \brief Type of precision for formatting of real values.
675
+ */
676
+ enum PrecisionType {
677
+ significantDigits = 0, ///< we set max number of significant digits in string
678
+ decimalPlaces ///< we set max number of digits after "." in string
679
+ };
680
+
681
+ //# ifdef JSON_USE_CPPTL
682
+ // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
683
+ // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
684
+ //# endif
685
+
686
+ /** \brief Lightweight wrapper to tag static string.
687
+ *
688
+ * Value constructor and objectValue member assignment takes advantage of the
689
+ * StaticString and avoid the cost of string duplication when storing the
690
+ * string or the member name.
691
+ *
692
+ * Example of usage:
693
+ * \code
694
+ * Json::Value aValue( StaticString("some text") );
695
+ * Json::Value object;
696
+ * static const StaticString code("code");
697
+ * object[code] = 1234;
698
+ * \endcode
699
+ */
700
+ class JSON_API StaticString {
701
+ public:
702
+ explicit StaticString(const char* czstring) : c_str_(czstring) {}
703
+
704
+ operator const char*() const { return c_str_; }
705
+
706
+ const char* c_str() const { return c_str_; }
707
+
708
+ private:
709
+ const char* c_str_;
710
+ };
711
+
712
+ /** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
713
+ *
714
+ * This class is a discriminated union wrapper that can represents a:
715
+ * - signed integer [range: Value::minInt - Value::maxInt]
716
+ * - unsigned integer (range: 0 - Value::maxUInt)
717
+ * - double
718
+ * - UTF-8 string
719
+ * - boolean
720
+ * - 'null'
721
+ * - an ordered list of Value
722
+ * - collection of name/value pairs (javascript object)
723
+ *
724
+ * The type of the held value is represented by a #ValueType and
725
+ * can be obtained using type().
726
+ *
727
+ * Values of an #objectValue or #arrayValue can be accessed using operator[]()
728
+ * methods.
729
+ * Non-const methods will automatically create the a #nullValue element
730
+ * if it does not exist.
731
+ * The sequence of an #arrayValue will be automatically resized and initialized
732
+ * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
733
+ *
734
+ * The get() methods can be used to obtain default value in the case the
735
+ * required element does not exist.
736
+ *
737
+ * It is possible to iterate over the list of member keys of an object using
738
+ * the getMemberNames() method.
739
+ *
740
+ * \note #Value string-length fit in size_t, but keys must be < 2^30.
741
+ * (The reason is an implementation detail.) A #CharReader will raise an
742
+ * exception if a bound is exceeded to avoid security holes in your app,
743
+ * but the Value API does *not* check bounds. That is the responsibility
744
+ * of the caller.
745
+ */
746
+ class JSON_API Value {
747
+ friend class ValueIteratorBase;
748
+
749
+ public:
750
+ typedef std::vector<String> Members;
751
+ typedef ValueIterator iterator;
752
+ typedef ValueConstIterator const_iterator;
753
+ typedef Json::UInt UInt;
754
+ typedef Json::Int Int;
755
+ #if defined(JSON_HAS_INT64)
756
+ typedef Json::UInt64 UInt64;
757
+ typedef Json::Int64 Int64;
758
+ #endif // defined(JSON_HAS_INT64)
759
+ typedef Json::LargestInt LargestInt;
760
+ typedef Json::LargestUInt LargestUInt;
761
+ typedef Json::ArrayIndex ArrayIndex;
762
+
763
+ // Required for boost integration, e. g. BOOST_TEST
764
+ typedef std::string value_type;
765
+
766
+ static const Value& null; ///< We regret this reference to a global instance;
767
+ ///< prefer the simpler Value().
768
+ static const Value& nullRef; ///< just a kludge for binary-compatibility; same
769
+ ///< as null
770
+ static Value const& nullSingleton(); ///< Prefer this to null or nullRef.
771
+
772
+ /// Minimum signed integer value that can be stored in a Json::Value.
773
+ static const LargestInt minLargestInt;
774
+ /// Maximum signed integer value that can be stored in a Json::Value.
775
+ static const LargestInt maxLargestInt;
776
+ /// Maximum unsigned integer value that can be stored in a Json::Value.
777
+ static const LargestUInt maxLargestUInt;
778
+
779
+ /// Minimum signed int value that can be stored in a Json::Value.
780
+ static const Int minInt;
781
+ /// Maximum signed int value that can be stored in a Json::Value.
782
+ static const Int maxInt;
783
+ /// Maximum unsigned int value that can be stored in a Json::Value.
784
+ static const UInt maxUInt;
785
+
786
+ #if defined(JSON_HAS_INT64)
787
+ /// Minimum signed 64 bits int value that can be stored in a Json::Value.
788
+ static const Int64 minInt64;
789
+ /// Maximum signed 64 bits int value that can be stored in a Json::Value.
790
+ static const Int64 maxInt64;
791
+ /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
792
+ static const UInt64 maxUInt64;
793
+ #endif // defined(JSON_HAS_INT64)
794
+
795
+ /// Default precision for real value for string representation.
796
+ static const UInt defaultRealPrecision;
797
+
798
+ // Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler
799
+ // when using gcc and clang backend compilers. CZString
800
+ // cannot be defined as private. See issue #486
801
+ #ifdef __NVCC__
802
+ public:
803
+ #else
804
+ private:
805
+ #endif
806
+ #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
807
+ class CZString {
808
+ public:
809
+ enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
810
+ CZString(ArrayIndex index);
811
+ CZString(char const* str, unsigned length, DuplicationPolicy allocate);
812
+ CZString(CZString const& other);
813
+ #if JSON_HAS_RVALUE_REFERENCES
814
+ CZString(CZString&& other);
815
+ #endif
816
+ ~CZString();
817
+ CZString& operator=(const CZString& other);
818
+
819
+ #if JSON_HAS_RVALUE_REFERENCES
820
+ CZString& operator=(CZString&& other);
821
+ #endif
822
+
823
+ bool operator<(CZString const& other) const;
824
+ bool operator==(CZString const& other) const;
825
+ ArrayIndex index() const;
826
+ // const char* c_str() const; ///< \deprecated
827
+ char const* data() const;
828
+ unsigned length() const;
829
+ bool isStaticString() const;
830
+
831
+ private:
832
+ void swap(CZString& other);
833
+
834
+ struct StringStorage {
835
+ unsigned policy_ : 2;
836
+ unsigned length_ : 30; // 1GB max
837
+ };
838
+
839
+ char const* cstr_; // actually, a prefixed string, unless policy is noDup
840
+ union {
841
+ ArrayIndex index_;
842
+ StringStorage storage_;
843
+ };
844
+ };
845
+
846
+ public:
847
+ #ifndef JSON_USE_CPPTL_SMALLMAP
848
+ typedef std::map<CZString, Value> ObjectValues;
849
+ #else
850
+ typedef CppTL::SmallMap<CZString, Value> ObjectValues;
851
+ #endif // ifndef JSON_USE_CPPTL_SMALLMAP
852
+ #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
853
+
854
+ public:
855
+ /** \brief Create a default Value of the given type.
856
+
857
+ This is a very useful constructor.
858
+ To create an empty array, pass arrayValue.
859
+ To create an empty object, pass objectValue.
860
+ Another Value can then be set to this one by assignment.
861
+ This is useful since clear() and resize() will not alter types.
862
+
863
+ Examples:
864
+ \code
865
+ Json::Value null_value; // null
866
+ Json::Value arr_value(Json::arrayValue); // []
867
+ Json::Value obj_value(Json::objectValue); // {}
868
+ \endcode
869
+ */
870
+ Value(ValueType type = nullValue);
871
+ Value(Int value);
872
+ Value(UInt value);
873
+ #if defined(JSON_HAS_INT64)
874
+ Value(Int64 value);
875
+ Value(UInt64 value);
876
+ #endif // if defined(JSON_HAS_INT64)
877
+ Value(double value);
878
+ Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)
879
+ Value(const char* begin, const char* end); ///< Copy all, incl zeroes.
880
+ /** \brief Constructs a value from a static string.
881
+
882
+ * Like other value string constructor but do not duplicate the string for
883
+ * internal storage. The given string must remain alive after the call to this
884
+ * constructor.
885
+ * \note This works only for null-terminated strings. (We cannot change the
886
+ * size of this class, so we have nowhere to store the length,
887
+ * which might be computed later for various operations.)
888
+ *
889
+ * Example of usage:
890
+ * \code
891
+ * static StaticString foo("some text");
892
+ * Json::Value aValue(foo);
893
+ * \endcode
894
+ */
895
+ Value(const StaticString& value);
896
+ Value(const String& value); ///< Copy data() til size(). Embedded
897
+ ///< zeroes too.
898
+ #ifdef JSON_USE_CPPTL
899
+ Value(const CppTL::ConstString& value);
900
+ #endif
901
+ Value(bool value);
902
+ Value(const Value& other);
903
+ Value(Value&& other);
904
+ ~Value();
905
+
906
+ /// \note Overwrite existing comments. To preserve comments, use
907
+ /// #swapPayload().
908
+ Value& operator=(const Value& other);
909
+ Value& operator=(Value&& other);
910
+
911
+ /// Swap everything.
912
+ void swap(Value& other);
913
+ /// Swap values but leave comments and source offsets in place.
914
+ void swapPayload(Value& other);
915
+
916
+ /// copy everything.
917
+ void copy(const Value& other);
918
+ /// copy values but leave comments and source offsets in place.
919
+ void copyPayload(const Value& other);
920
+
921
+ ValueType type() const;
922
+
923
+ /// Compare payload only, not comments etc.
924
+ bool operator<(const Value& other) const;
925
+ bool operator<=(const Value& other) const;
926
+ bool operator>=(const Value& other) const;
927
+ bool operator>(const Value& other) const;
928
+ bool operator==(const Value& other) const;
929
+ bool operator!=(const Value& other) const;
930
+ int compare(const Value& other) const;
931
+
932
+ const char* asCString() const; ///< Embedded zeroes could cause you trouble!
933
+ #if JSONCPP_USING_SECURE_MEMORY
934
+ unsigned getCStringLength() const; // Allows you to understand the length of
935
+ // the CString
936
+ #endif
937
+ String asString() const; ///< Embedded zeroes are possible.
938
+ /** Get raw char* of string-value.
939
+ * \return false if !string. (Seg-fault if str or end are NULL.)
940
+ */
941
+ bool getString(char const** begin, char const** end) const;
942
+ #ifdef JSON_USE_CPPTL
943
+ CppTL::ConstString asConstString() const;
944
+ #endif
945
+ Int asInt() const;
946
+ UInt asUInt() const;
947
+ #if defined(JSON_HAS_INT64)
948
+ Int64 asInt64() const;
949
+ UInt64 asUInt64() const;
950
+ #endif // if defined(JSON_HAS_INT64)
951
+ LargestInt asLargestInt() const;
952
+ LargestUInt asLargestUInt() const;
953
+ float asFloat() const;
954
+ double asDouble() const;
955
+ bool asBool() const;
956
+
957
+ bool isNull() const;
958
+ bool isBool() const;
959
+ bool isInt() const;
960
+ bool isInt64() const;
961
+ bool isUInt() const;
962
+ bool isUInt64() const;
963
+ bool isIntegral() const;
964
+ bool isDouble() const;
965
+ bool isNumeric() const;
966
+ bool isString() const;
967
+ bool isArray() const;
968
+ bool isObject() const;
969
+
970
+ bool isConvertibleTo(ValueType other) const;
971
+
972
+ /// Number of values in array or object
973
+ ArrayIndex size() const;
974
+
975
+ /// \brief Return true if empty array, empty object, or null;
976
+ /// otherwise, false.
977
+ bool empty() const;
978
+
979
+ /// Return !isNull()
980
+ JSONCPP_OP_EXPLICIT operator bool() const;
981
+
982
+ /// Remove all object members and array elements.
983
+ /// \pre type() is arrayValue, objectValue, or nullValue
984
+ /// \post type() is unchanged
985
+ void clear();
986
+
987
+ /// Resize the array to newSize elements.
988
+ /// New elements are initialized to null.
989
+ /// May only be called on nullValue or arrayValue.
990
+ /// \pre type() is arrayValue or nullValue
991
+ /// \post type() is arrayValue
992
+ void resize(ArrayIndex newSize);
993
+
994
+ /// Access an array element (zero based index ).
995
+ /// If the array contains less than index element, then null value are
996
+ /// inserted
997
+ /// in the array so that its size is index+1.
998
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
999
+ /// this from the operator[] which takes a string.)
1000
+ Value& operator[](ArrayIndex index);
1001
+
1002
+ /// Access an array element (zero based index ).
1003
+ /// If the array contains less than index element, then null value are
1004
+ /// inserted
1005
+ /// in the array so that its size is index+1.
1006
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
1007
+ /// this from the operator[] which takes a string.)
1008
+ Value& operator[](int index);
1009
+
1010
+ /// Access an array element (zero based index )
1011
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
1012
+ /// this from the operator[] which takes a string.)
1013
+ const Value& operator[](ArrayIndex index) const;
1014
+
1015
+ /// Access an array element (zero based index )
1016
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
1017
+ /// this from the operator[] which takes a string.)
1018
+ const Value& operator[](int index) const;
1019
+
1020
+ /// If the array contains at least index+1 elements, returns the element
1021
+ /// value,
1022
+ /// otherwise returns defaultValue.
1023
+ Value get(ArrayIndex index, const Value& defaultValue) const;
1024
+ /// Return true if index < size().
1025
+ bool isValidIndex(ArrayIndex index) const;
1026
+ /// \brief Append value to array at the end.
1027
+ ///
1028
+ /// Equivalent to jsonvalue[jsonvalue.size()] = value;
1029
+ Value& append(const Value& value);
1030
+
1031
+ #if JSON_HAS_RVALUE_REFERENCES
1032
+ Value& append(Value&& value);
1033
+ #endif
1034
+
1035
+ /// Access an object value by name, create a null member if it does not exist.
1036
+ /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
1037
+ /// Exceeding that will cause an exception.
1038
+ Value& operator[](const char* key);
1039
+ /// Access an object value by name, returns null if there is no member with
1040
+ /// that name.
1041
+ const Value& operator[](const char* key) const;
1042
+ /// Access an object value by name, create a null member if it does not exist.
1043
+ /// \param key may contain embedded nulls.
1044
+ Value& operator[](const String& key);
1045
+ /// Access an object value by name, returns null if there is no member with
1046
+ /// that name.
1047
+ /// \param key may contain embedded nulls.
1048
+ const Value& operator[](const String& key) const;
1049
+ /** \brief Access an object value by name, create a null member if it does not
1050
+ exist.
1051
+
1052
+ * If the object has no entry for that name, then the member name used to
1053
+ store
1054
+ * the new entry is not duplicated.
1055
+ * Example of use:
1056
+ * \code
1057
+ * Json::Value object;
1058
+ * static const StaticString code("code");
1059
+ * object[code] = 1234;
1060
+ * \endcode
1061
+ */
1062
+ Value& operator[](const StaticString& key);
1063
+ #ifdef JSON_USE_CPPTL
1064
+ /// Access an object value by name, create a null member if it does not exist.
1065
+ Value& operator[](const CppTL::ConstString& key);
1066
+ /// Access an object value by name, returns null if there is no member with
1067
+ /// that name.
1068
+ const Value& operator[](const CppTL::ConstString& key) const;
1069
+ #endif
1070
+ /// Return the member named key if it exist, defaultValue otherwise.
1071
+ /// \note deep copy
1072
+ Value get(const char* key, const Value& defaultValue) const;
1073
+ /// Return the member named key if it exist, defaultValue otherwise.
1074
+ /// \note deep copy
1075
+ /// \note key may contain embedded nulls.
1076
+ Value
1077
+ get(const char* begin, const char* end, const Value& defaultValue) const;
1078
+ /// Return the member named key if it exist, defaultValue otherwise.
1079
+ /// \note deep copy
1080
+ /// \param key may contain embedded nulls.
1081
+ Value get(const String& key, const Value& defaultValue) const;
1082
+ #ifdef JSON_USE_CPPTL
1083
+ /// Return the member named key if it exist, defaultValue otherwise.
1084
+ /// \note deep copy
1085
+ Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
1086
+ #endif
1087
+ /// Most general and efficient version of isMember()const, get()const,
1088
+ /// and operator[]const
1089
+ /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
1090
+ Value const* find(char const* begin, char const* end) const;
1091
+ /// Most general and efficient version of object-mutators.
1092
+ /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
1093
+ /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
1094
+ Value const* demand(char const* begin, char const* end);
1095
+ /// \brief Remove and return the named member.
1096
+ ///
1097
+ /// Do nothing if it did not exist.
1098
+ /// \pre type() is objectValue or nullValue
1099
+ /// \post type() is unchanged
1100
+ void removeMember(const char* key);
1101
+ /// Same as removeMember(const char*)
1102
+ /// \param key may contain embedded nulls.
1103
+ void removeMember(const String& key);
1104
+ /// Same as removeMember(const char* begin, const char* end, Value* removed),
1105
+ /// but 'key' is null-terminated.
1106
+ bool removeMember(const char* key, Value* removed);
1107
+ /** \brief Remove the named map member.
1108
+
1109
+ Update 'removed' iff removed.
1110
+ \param key may contain embedded nulls.
1111
+ \return true iff removed (no exceptions)
1112
+ */
1113
+ bool removeMember(String const& key, Value* removed);
1114
+ /// Same as removeMember(String const& key, Value* removed)
1115
+ bool removeMember(const char* begin, const char* end, Value* removed);
1116
+ /** \brief Remove the indexed array element.
1117
+
1118
+ O(n) expensive operations.
1119
+ Update 'removed' iff removed.
1120
+ \return true if removed (no exceptions)
1121
+ */
1122
+ bool removeIndex(ArrayIndex index, Value* removed);
1123
+
1124
+ /// Return true if the object has a member named key.
1125
+ /// \note 'key' must be null-terminated.
1126
+ bool isMember(const char* key) const;
1127
+ /// Return true if the object has a member named key.
1128
+ /// \param key may contain embedded nulls.
1129
+ bool isMember(const String& key) const;
1130
+ /// Same as isMember(String const& key)const
1131
+ bool isMember(const char* begin, const char* end) const;
1132
+ #ifdef JSON_USE_CPPTL
1133
+ /// Return true if the object has a member named key.
1134
+ bool isMember(const CppTL::ConstString& key) const;
1135
+ #endif
1136
+
1137
+ /// \brief Return a list of the member names.
1138
+ ///
1139
+ /// If null, return an empty list.
1140
+ /// \pre type() is objectValue or nullValue
1141
+ /// \post if type() was nullValue, it remains nullValue
1142
+ Members getMemberNames() const;
1143
+
1144
+ //# ifdef JSON_USE_CPPTL
1145
+ // EnumMemberNames enumMemberNames() const;
1146
+ // EnumValues enumValues() const;
1147
+ //# endif
1148
+
1149
+ /// \deprecated Always pass len.
1150
+ JSONCPP_DEPRECATED("Use setComment(String const&) instead.")
1151
+ void setComment(const char* comment, CommentPlacement placement);
1152
+ /// Comments must be //... or /* ... */
1153
+ void setComment(const char* comment, size_t len, CommentPlacement placement);
1154
+ /// Comments must be //... or /* ... */
1155
+ void setComment(const String& comment, CommentPlacement placement);
1156
+ bool hasComment(CommentPlacement placement) const;
1157
+ /// Include delimiters and embedded newlines.
1158
+ String getComment(CommentPlacement placement) const;
1159
+
1160
+ String toStyledString() const;
1161
+
1162
+ const_iterator begin() const;
1163
+ const_iterator end() const;
1164
+
1165
+ iterator begin();
1166
+ iterator end();
1167
+
1168
+ // Accessors for the [start, limit) range of bytes within the JSON text from
1169
+ // which this value was parsed, if any.
1170
+ void setOffsetStart(ptrdiff_t start);
1171
+ void setOffsetLimit(ptrdiff_t limit);
1172
+ ptrdiff_t getOffsetStart() const;
1173
+ ptrdiff_t getOffsetLimit() const;
1174
+
1175
+ private:
1176
+ void setType(ValueType v) { bits_.value_type_ = v; }
1177
+ bool isAllocated() const { return bits_.allocated_; }
1178
+ void setIsAllocated(bool v) { bits_.allocated_ = v; }
1179
+
1180
+ void initBasic(ValueType type, bool allocated = false);
1181
+ void dupPayload(const Value& other);
1182
+ void releasePayload();
1183
+ void dupMeta(const Value& other);
1184
+
1185
+ Value& resolveReference(const char* key);
1186
+ Value& resolveReference(const char* key, const char* end);
1187
+
1188
+ struct CommentInfo {
1189
+ CommentInfo();
1190
+ ~CommentInfo();
1191
+
1192
+ void setComment(const char* text, size_t len);
1193
+
1194
+ char* comment_{nullptr};
1195
+ };
1196
+
1197
+ // struct MemberNamesTransform
1198
+ //{
1199
+ // typedef const char *result_type;
1200
+ // const char *operator()( const CZString &name ) const
1201
+ // {
1202
+ // return name.c_str();
1203
+ // }
1204
+ //};
1205
+
1206
+ union ValueHolder {
1207
+ LargestInt int_;
1208
+ LargestUInt uint_;
1209
+ double real_;
1210
+ bool bool_;
1211
+ char* string_; // if allocated_, ptr to { unsigned, char[] }.
1212
+ ObjectValues* map_;
1213
+ } value_;
1214
+
1215
+ struct {
1216
+ // Really a ValueType, but types should agree for bitfield packing.
1217
+ unsigned int value_type_ : 8;
1218
+ // Unless allocated_, string_ must be null-terminated.
1219
+ unsigned int allocated_ : 1;
1220
+ } bits_;
1221
+
1222
+ CommentInfo* comments_;
1223
+
1224
+ // [start, limit) byte offsets in the source JSON text from which this Value
1225
+ // was extracted.
1226
+ ptrdiff_t start_;
1227
+ ptrdiff_t limit_;
1228
+ };
1229
+
1230
+ /** \brief Experimental and untested: represents an element of the "path" to
1231
+ * access a node.
1232
+ */
1233
+ class JSON_API PathArgument {
1234
+ public:
1235
+ friend class Path;
1236
+
1237
+ PathArgument();
1238
+ PathArgument(ArrayIndex index);
1239
+ PathArgument(const char* key);
1240
+ PathArgument(const String& key);
1241
+
1242
+ private:
1243
+ enum Kind { kindNone = 0, kindIndex, kindKey };
1244
+ String key_;
1245
+ ArrayIndex index_{};
1246
+ Kind kind_{kindNone};
1247
+ };
1248
+
1249
+ /** \brief Experimental and untested: represents a "path" to access a node.
1250
+ *
1251
+ * Syntax:
1252
+ * - "." => root node
1253
+ * - ".[n]" => elements at index 'n' of root node (an array value)
1254
+ * - ".name" => member named 'name' of root node (an object value)
1255
+ * - ".name1.name2.name3"
1256
+ * - ".[0][1][2].name1[3]"
1257
+ * - ".%" => member name is provided as parameter
1258
+ * - ".[%]" => index is provied as parameter
1259
+ */
1260
+ class JSON_API Path {
1261
+ public:
1262
+ Path(const String& path,
1263
+ const PathArgument& a1 = PathArgument(),
1264
+ const PathArgument& a2 = PathArgument(),
1265
+ const PathArgument& a3 = PathArgument(),
1266
+ const PathArgument& a4 = PathArgument(),
1267
+ const PathArgument& a5 = PathArgument());
1268
+
1269
+ const Value& resolve(const Value& root) const;
1270
+ Value resolve(const Value& root, const Value& defaultValue) const;
1271
+ /// Creates the "path" to access the specified node and returns a reference on
1272
+ /// the node.
1273
+ Value& make(Value& root) const;
1274
+
1275
+ private:
1276
+ typedef std::vector<const PathArgument*> InArgs;
1277
+ typedef std::vector<PathArgument> Args;
1278
+
1279
+ void makePath(const String& path, const InArgs& in);
1280
+ void addPathInArg(const String& path,
1281
+ const InArgs& in,
1282
+ InArgs::const_iterator& itInArg,
1283
+ PathArgument::Kind kind);
1284
+ static void invalidPath(const String& path, int location);
1285
+
1286
+ Args args_;
1287
+ };
1288
+
1289
+ /** \brief base class for Value iterators.
1290
+ *
1291
+ */
1292
+ class JSON_API ValueIteratorBase {
1293
+ public:
1294
+ typedef std::bidirectional_iterator_tag iterator_category;
1295
+ typedef unsigned int size_t;
1296
+ typedef int difference_type;
1297
+ typedef ValueIteratorBase SelfType;
1298
+
1299
+ bool operator==(const SelfType& other) const { return isEqual(other); }
1300
+
1301
+ bool operator!=(const SelfType& other) const { return !isEqual(other); }
1302
+
1303
+ difference_type operator-(const SelfType& other) const {
1304
+ return other.computeDistance(*this);
1305
+ }
1306
+
1307
+ /// Return either the index or the member name of the referenced value as a
1308
+ /// Value.
1309
+ Value key() const;
1310
+
1311
+ /// Return the index of the referenced Value, or -1 if it is not an
1312
+ /// arrayValue.
1313
+ UInt index() const;
1314
+
1315
+ /// Return the member name of the referenced Value, or "" if it is not an
1316
+ /// objectValue.
1317
+ /// \note Avoid `c_str()` on result, as embedded zeroes are possible.
1318
+ String name() const;
1319
+
1320
+ /// Return the member name of the referenced Value. "" if it is not an
1321
+ /// objectValue.
1322
+ /// \deprecated This cannot be used for UTF-8 strings, since there can be
1323
+ /// embedded nulls.
1324
+ JSONCPP_DEPRECATED("Use `key = name();` instead.")
1325
+ char const* memberName() const;
1326
+ /// Return the member name of the referenced Value, or NULL if it is not an
1327
+ /// objectValue.
1328
+ /// \note Better version than memberName(). Allows embedded nulls.
1329
+ char const* memberName(char const** end) const;
1330
+
1331
+ protected:
1332
+ Value& deref() const;
1333
+
1334
+ void increment();
1335
+
1336
+ void decrement();
1337
+
1338
+ difference_type computeDistance(const SelfType& other) const;
1339
+
1340
+ bool isEqual(const SelfType& other) const;
1341
+
1342
+ void copy(const SelfType& other);
1343
+
1344
+ private:
1345
+ Value::ObjectValues::iterator current_;
1346
+ // Indicates that iterator is for a null value.
1347
+ bool isNull_{true};
1348
+
1349
+ public:
1350
+ // For some reason, BORLAND needs these at the end, rather
1351
+ // than earlier. No idea why.
1352
+ ValueIteratorBase();
1353
+ explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
1354
+ };
1355
+
1356
+ /** \brief const iterator for object and array value.
1357
+ *
1358
+ */
1359
+ class JSON_API ValueConstIterator : public ValueIteratorBase {
1360
+ friend class Value;
1361
+
1362
+ public:
1363
+ typedef const Value value_type;
1364
+ // typedef unsigned int size_t;
1365
+ // typedef int difference_type;
1366
+ typedef const Value& reference;
1367
+ typedef const Value* pointer;
1368
+ typedef ValueConstIterator SelfType;
1369
+
1370
+ ValueConstIterator();
1371
+ ValueConstIterator(ValueIterator const& other);
1372
+
1373
+ private:
1374
+ /*! \internal Use by Value to create an iterator.
1375
+ */
1376
+ explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
1377
+
1378
+ public:
1379
+ SelfType& operator=(const ValueIteratorBase& other);
1380
+
1381
+ SelfType operator++(int) {
1382
+ SelfType temp(*this);
1383
+ ++*this;
1384
+ return temp;
1385
+ }
1386
+
1387
+ SelfType operator--(int) {
1388
+ SelfType temp(*this);
1389
+ --*this;
1390
+ return temp;
1391
+ }
1392
+
1393
+ SelfType& operator--() {
1394
+ decrement();
1395
+ return *this;
1396
+ }
1397
+
1398
+ SelfType& operator++() {
1399
+ increment();
1400
+ return *this;
1401
+ }
1402
+
1403
+ reference operator*() const { return deref(); }
1404
+
1405
+ pointer operator->() const { return &deref(); }
1406
+ };
1407
+
1408
+ /** \brief Iterator for object and array value.
1409
+ */
1410
+ class JSON_API ValueIterator : public ValueIteratorBase {
1411
+ friend class Value;
1412
+
1413
+ public:
1414
+ typedef Value value_type;
1415
+ typedef unsigned int size_t;
1416
+ typedef int difference_type;
1417
+ typedef Value& reference;
1418
+ typedef Value* pointer;
1419
+ typedef ValueIterator SelfType;
1420
+
1421
+ ValueIterator();
1422
+ explicit ValueIterator(const ValueConstIterator& other);
1423
+ ValueIterator(const ValueIterator& other);
1424
+
1425
+ private:
1426
+ /*! \internal Use by Value to create an iterator.
1427
+ */
1428
+ explicit ValueIterator(const Value::ObjectValues::iterator& current);
1429
+
1430
+ public:
1431
+ SelfType& operator=(const SelfType& other);
1432
+
1433
+ SelfType operator++(int) {
1434
+ SelfType temp(*this);
1435
+ ++*this;
1436
+ return temp;
1437
+ }
1438
+
1439
+ SelfType operator--(int) {
1440
+ SelfType temp(*this);
1441
+ --*this;
1442
+ return temp;
1443
+ }
1444
+
1445
+ SelfType& operator--() {
1446
+ decrement();
1447
+ return *this;
1448
+ }
1449
+
1450
+ SelfType& operator++() {
1451
+ increment();
1452
+ return *this;
1453
+ }
1454
+
1455
+ reference operator*() const { return deref(); }
1456
+
1457
+ pointer operator->() const { return &deref(); }
1458
+ };
1459
+
1460
+ inline void swap(Value& a, Value& b) { a.swap(b); }
1461
+
1462
+ } // namespace Json
1463
+
1464
+ #pragma pack(pop)
1465
+
1466
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1467
+ #pragma warning(pop)
1468
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1469
+
1470
+ #endif // CPPTL_JSON_H_INCLUDED
1471
+
1472
+ // //////////////////////////////////////////////////////////////////////
1473
+ // End of content of file: include/json/value.h
1474
+ // //////////////////////////////////////////////////////////////////////
1475
+
1476
+
1477
+
1478
+
1479
+
1480
+
1481
+ // //////////////////////////////////////////////////////////////////////
1482
+ // Beginning of content of file: include/json/reader.h
1483
+ // //////////////////////////////////////////////////////////////////////
1484
+
1485
+ // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
1486
+ // Distributed under MIT license, or public domain if desired and
1487
+ // recognized in your jurisdiction.
1488
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1489
+
1490
+ #ifndef CPPTL_JSON_READER_H_INCLUDED
1491
+ #define CPPTL_JSON_READER_H_INCLUDED
1492
+
1493
+ #if !defined(JSON_IS_AMALGAMATION)
1494
+ #include "features.h"
1495
+ #include "value.h"
1496
+ #endif // if !defined(JSON_IS_AMALGAMATION)
1497
+ #include <deque>
1498
+ #include <iosfwd>
1499
+ #include <istream>
1500
+ #include <stack>
1501
+ #include <string>
1502
+
1503
+ // Disable warning C4251: <data member>: <type> needs to have dll-interface to
1504
+ // be used by...
1505
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1506
+ #pragma warning(push)
1507
+ #pragma warning(disable : 4251)
1508
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1509
+
1510
+ #pragma pack(push, 8)
1511
+
1512
+ namespace Json {
1513
+
1514
+ /** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
1515
+ *Value.
1516
+ *
1517
+ * \deprecated Use CharReader and CharReaderBuilder.
1518
+ */
1519
+ class JSON_API Reader {
1520
+ public:
1521
+ typedef char Char;
1522
+ typedef const Char* Location;
1523
+
1524
+ /** \brief An error tagged with where in the JSON text it was encountered.
1525
+ *
1526
+ * The offsets give the [start, limit) range of bytes within the text. Note
1527
+ * that this is bytes, not codepoints.
1528
+ *
1529
+ */
1530
+ struct StructuredError {
1531
+ ptrdiff_t offset_start;
1532
+ ptrdiff_t offset_limit;
1533
+ String message;
1534
+ };
1535
+
1536
+ /** \brief Constructs a Reader allowing all features
1537
+ * for parsing.
1538
+ */
1539
+ JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
1540
+ Reader();
1541
+
1542
+ /** \brief Constructs a Reader allowing the specified feature set
1543
+ * for parsing.
1544
+ */
1545
+ JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
1546
+ Reader(const Features& features);
1547
+
1548
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
1549
+ * document.
1550
+ * \param document UTF-8 encoded string containing the document to read.
1551
+ * \param root [out] Contains the root value of the document if it was
1552
+ * successfully parsed.
1553
+ * \param collectComments \c true to collect comment and allow writing them
1554
+ * back during
1555
+ * serialization, \c false to discard comments.
1556
+ * This parameter is ignored if
1557
+ * Features::allowComments_
1558
+ * is \c false.
1559
+ * \return \c true if the document was successfully parsed, \c false if an
1560
+ * error occurred.
1561
+ */
1562
+ bool
1563
+ parse(const std::string& document, Value& root, bool collectComments = true);
1564
+
1565
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
1566
+ document.
1567
+ * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
1568
+ document to read.
1569
+ * \param endDoc Pointer on the end of the UTF-8 encoded string of the
1570
+ document to read.
1571
+ * Must be >= beginDoc.
1572
+ * \param root [out] Contains the root value of the document if it was
1573
+ * successfully parsed.
1574
+ * \param collectComments \c true to collect comment and allow writing them
1575
+ back during
1576
+ * serialization, \c false to discard comments.
1577
+ * This parameter is ignored if
1578
+ Features::allowComments_
1579
+ * is \c false.
1580
+ * \return \c true if the document was successfully parsed, \c false if an
1581
+ error occurred.
1582
+ */
1583
+ bool parse(const char* beginDoc,
1584
+ const char* endDoc,
1585
+ Value& root,
1586
+ bool collectComments = true);
1587
+
1588
+ /// \brief Parse from input stream.
1589
+ /// \see Json::operator>>(std::istream&, Json::Value&).
1590
+ bool parse(IStream& is, Value& root, bool collectComments = true);
1591
+
1592
+ /** \brief Returns a user friendly string that list errors in the parsed
1593
+ * document.
1594
+ * \return Formatted error message with the list of errors with their location
1595
+ * in
1596
+ * the parsed document. An empty string is returned if no error
1597
+ * occurred
1598
+ * during parsing.
1599
+ * \deprecated Use getFormattedErrorMessages() instead (typo fix).
1600
+ */
1601
+ JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
1602
+ String getFormatedErrorMessages() const;
1603
+
1604
+ /** \brief Returns a user friendly string that list errors in the parsed
1605
+ * document.
1606
+ * \return Formatted error message with the list of errors with their location
1607
+ * in
1608
+ * the parsed document. An empty string is returned if no error
1609
+ * occurred
1610
+ * during parsing.
1611
+ */
1612
+ String getFormattedErrorMessages() const;
1613
+
1614
+ /** \brief Returns a vector of structured erros encounted while parsing.
1615
+ * \return A (possibly empty) vector of StructuredError objects. Currently
1616
+ * only one error can be returned, but the caller should tolerate
1617
+ * multiple
1618
+ * errors. This can occur if the parser recovers from a non-fatal
1619
+ * parse error and then encounters additional errors.
1620
+ */
1621
+ std::vector<StructuredError> getStructuredErrors() const;
1622
+
1623
+ /** \brief Add a semantic error message.
1624
+ * \param value JSON Value location associated with the error
1625
+ * \param message The error message.
1626
+ * \return \c true if the error was successfully added, \c false if the
1627
+ * Value offset exceeds the document size.
1628
+ */
1629
+ bool pushError(const Value& value, const String& message);
1630
+
1631
+ /** \brief Add a semantic error message with extra context.
1632
+ * \param value JSON Value location associated with the error
1633
+ * \param message The error message.
1634
+ * \param extra Additional JSON Value location to contextualize the error
1635
+ * \return \c true if the error was successfully added, \c false if either
1636
+ * Value offset exceeds the document size.
1637
+ */
1638
+ bool pushError(const Value& value, const String& message, const Value& extra);
1639
+
1640
+ /** \brief Return whether there are any errors.
1641
+ * \return \c true if there are no errors to report \c false if
1642
+ * errors have occurred.
1643
+ */
1644
+ bool good() const;
1645
+
1646
+ private:
1647
+ enum TokenType {
1648
+ tokenEndOfStream = 0,
1649
+ tokenObjectBegin,
1650
+ tokenObjectEnd,
1651
+ tokenArrayBegin,
1652
+ tokenArrayEnd,
1653
+ tokenString,
1654
+ tokenNumber,
1655
+ tokenTrue,
1656
+ tokenFalse,
1657
+ tokenNull,
1658
+ tokenArraySeparator,
1659
+ tokenMemberSeparator,
1660
+ tokenComment,
1661
+ tokenError
1662
+ };
1663
+
1664
+ class Token {
1665
+ public:
1666
+ TokenType type_;
1667
+ Location start_;
1668
+ Location end_;
1669
+ };
1670
+
1671
+ class ErrorInfo {
1672
+ public:
1673
+ Token token_;
1674
+ String message_;
1675
+ Location extra_;
1676
+ };
1677
+
1678
+ typedef std::deque<ErrorInfo> Errors;
1679
+
1680
+ bool readToken(Token& token);
1681
+ void skipSpaces();
1682
+ bool match(Location pattern, int patternLength);
1683
+ bool readComment();
1684
+ bool readCStyleComment();
1685
+ bool readCppStyleComment();
1686
+ bool readString();
1687
+ void readNumber();
1688
+ bool readValue();
1689
+ bool readObject(Token& token);
1690
+ bool readArray(Token& token);
1691
+ bool decodeNumber(Token& token);
1692
+ bool decodeNumber(Token& token, Value& decoded);
1693
+ bool decodeString(Token& token);
1694
+ bool decodeString(Token& token, String& decoded);
1695
+ bool decodeDouble(Token& token);
1696
+ bool decodeDouble(Token& token, Value& decoded);
1697
+ bool decodeUnicodeCodePoint(Token& token,
1698
+ Location& current,
1699
+ Location end,
1700
+ unsigned int& unicode);
1701
+ bool decodeUnicodeEscapeSequence(Token& token,
1702
+ Location& current,
1703
+ Location end,
1704
+ unsigned int& unicode);
1705
+ bool addError(const String& message, Token& token, Location extra = nullptr);
1706
+ bool recoverFromError(TokenType skipUntilToken);
1707
+ bool addErrorAndRecover(const String& message,
1708
+ Token& token,
1709
+ TokenType skipUntilToken);
1710
+ void skipUntilSpace();
1711
+ Value& currentValue();
1712
+ Char getNextChar();
1713
+ void
1714
+ getLocationLineAndColumn(Location location, int& line, int& column) const;
1715
+ String getLocationLineAndColumn(Location location) const;
1716
+ void addComment(Location begin, Location end, CommentPlacement placement);
1717
+ void skipCommentTokens(Token& token);
1718
+
1719
+ static bool containsNewLine(Location begin, Location end);
1720
+ static String normalizeEOL(Location begin, Location end);
1721
+
1722
+ typedef std::stack<Value*> Nodes;
1723
+ Nodes nodes_;
1724
+ Errors errors_;
1725
+ String document_;
1726
+ Location begin_{};
1727
+ Location end_{};
1728
+ Location current_{};
1729
+ Location lastValueEnd_{};
1730
+ Value* lastValue_{};
1731
+ String commentsBefore_;
1732
+ Features features_;
1733
+ bool collectComments_{};
1734
+ }; // Reader
1735
+
1736
+ /** Interface for reading JSON from a char array.
1737
+ */
1738
+ class JSON_API CharReader {
1739
+ public:
1740
+ virtual ~CharReader() = default;
1741
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
1742
+ document.
1743
+ * The document must be a UTF-8 encoded string containing the document to
1744
+ read.
1745
+ *
1746
+ * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
1747
+ document to read.
1748
+ * \param endDoc Pointer on the end of the UTF-8 encoded string of the
1749
+ document to read.
1750
+ * Must be >= beginDoc.
1751
+ * \param root [out] Contains the root value of the document if it was
1752
+ * successfully parsed.
1753
+ * \param errs [out] Formatted error messages (if not NULL)
1754
+ * a user friendly string that lists errors in the parsed
1755
+ * document.
1756
+ * \return \c true if the document was successfully parsed, \c false if an
1757
+ error occurred.
1758
+ */
1759
+ virtual bool parse(char const* beginDoc,
1760
+ char const* endDoc,
1761
+ Value* root,
1762
+ String* errs) = 0;
1763
+
1764
+ class JSON_API Factory {
1765
+ public:
1766
+ virtual ~Factory() = default;
1767
+ /** \brief Allocate a CharReader via operator new().
1768
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
1769
+ */
1770
+ virtual CharReader* newCharReader() const = 0;
1771
+ }; // Factory
1772
+ }; // CharReader
1773
+
1774
+ /** \brief Build a CharReader implementation.
1775
+
1776
+ Usage:
1777
+ \code
1778
+ using namespace Json;
1779
+ CharReaderBuilder builder;
1780
+ builder["collectComments"] = false;
1781
+ Value value;
1782
+ String errs;
1783
+ bool ok = parseFromStream(builder, std::cin, &value, &errs);
1784
+ \endcode
1785
+ */
1786
+ class JSON_API CharReaderBuilder : public CharReader::Factory {
1787
+ public:
1788
+ // Note: We use a Json::Value so that we can add data-members to this class
1789
+ // without a major version bump.
1790
+ /** Configuration of this builder.
1791
+ These are case-sensitive.
1792
+ Available settings (case-sensitive):
1793
+ - `"collectComments": false or true`
1794
+ - true to collect comment and allow writing them
1795
+ back during serialization, false to discard comments.
1796
+ This parameter is ignored if allowComments is false.
1797
+ - `"allowComments": false or true`
1798
+ - true if comments are allowed.
1799
+ - `"strictRoot": false or true`
1800
+ - true if root must be either an array or an object value
1801
+ - `"allowDroppedNullPlaceholders": false or true`
1802
+ - true if dropped null placeholders are allowed. (See
1803
+ StreamWriterBuilder.)
1804
+ - `"allowNumericKeys": false or true`
1805
+ - true if numeric object keys are allowed.
1806
+ - `"allowSingleQuotes": false or true`
1807
+ - true if '' are allowed for strings (both keys and values)
1808
+ - `"stackLimit": integer`
1809
+ - Exceeding stackLimit (recursive depth of `readValue()`) will
1810
+ cause an exception.
1811
+ - This is a security issue (seg-faults caused by deeply nested JSON),
1812
+ so the default is low.
1813
+ - `"failIfExtra": false or true`
1814
+ - If true, `parse()` returns false when extra non-whitespace trails
1815
+ the JSON value in the input string.
1816
+ - `"rejectDupKeys": false or true`
1817
+ - If true, `parse()` returns false when a key is duplicated within an
1818
+ object.
1819
+ - `"allowSpecialFloats": false or true`
1820
+ - If true, special float values (NaNs and infinities) are allowed
1821
+ and their values are lossfree restorable.
1822
+
1823
+ You can examine 'settings_` yourself
1824
+ to see the defaults. You can also write and read them just like any
1825
+ JSON Value.
1826
+ \sa setDefaults()
1827
+ */
1828
+ Json::Value settings_;
1829
+
1830
+ CharReaderBuilder();
1831
+ ~CharReaderBuilder() override;
1832
+
1833
+ CharReader* newCharReader() const override;
1834
+
1835
+ /** \return true if 'settings' are legal and consistent;
1836
+ * otherwise, indicate bad settings via 'invalid'.
1837
+ */
1838
+ bool validate(Json::Value* invalid) const;
1839
+
1840
+ /** A simple way to update a specific setting.
1841
+ */
1842
+ Value& operator[](const String& key);
1843
+
1844
+ /** Called by ctor, but you can use this to reset settings_.
1845
+ * \pre 'settings' != NULL (but Json::null is fine)
1846
+ * \remark Defaults:
1847
+ * \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
1848
+ */
1849
+ static void setDefaults(Json::Value* settings);
1850
+ /** Same as old Features::strictMode().
1851
+ * \pre 'settings' != NULL (but Json::null is fine)
1852
+ * \remark Defaults:
1853
+ * \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
1854
+ */
1855
+ static void strictMode(Json::Value* settings);
1856
+ };
1857
+
1858
+ /** Consume entire stream and use its begin/end.
1859
+ * Someday we might have a real StreamReader, but for now this
1860
+ * is convenient.
1861
+ */
1862
+ bool JSON_API parseFromStream(CharReader::Factory const&,
1863
+ IStream&,
1864
+ Value* root,
1865
+ std::string* errs);
1866
+
1867
+ /** \brief Read from 'sin' into 'root'.
1868
+
1869
+ Always keep comments from the input JSON.
1870
+
1871
+ This can be used to read a file into a particular sub-object.
1872
+ For example:
1873
+ \code
1874
+ Json::Value root;
1875
+ cin >> root["dir"]["file"];
1876
+ cout << root;
1877
+ \endcode
1878
+ Result:
1879
+ \verbatim
1880
+ {
1881
+ "dir": {
1882
+ "file": {
1883
+ // The input stream JSON would be nested here.
1884
+ }
1885
+ }
1886
+ }
1887
+ \endverbatim
1888
+ \throw std::exception on parse error.
1889
+ \see Json::operator<<()
1890
+ */
1891
+ JSON_API IStream& operator>>(IStream&, Value&);
1892
+
1893
+ } // namespace Json
1894
+
1895
+ #pragma pack(pop)
1896
+
1897
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1898
+ #pragma warning(pop)
1899
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1900
+
1901
+ #endif // CPPTL_JSON_READER_H_INCLUDED
1902
+
1903
+ // //////////////////////////////////////////////////////////////////////
1904
+ // End of content of file: include/json/reader.h
1905
+ // //////////////////////////////////////////////////////////////////////
1906
+
1907
+
1908
+
1909
+
1910
+
1911
+
1912
+ // //////////////////////////////////////////////////////////////////////
1913
+ // Beginning of content of file: include/json/writer.h
1914
+ // //////////////////////////////////////////////////////////////////////
1915
+
1916
+ // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
1917
+ // Distributed under MIT license, or public domain if desired and
1918
+ // recognized in your jurisdiction.
1919
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1920
+
1921
+ #ifndef JSON_WRITER_H_INCLUDED
1922
+ #define JSON_WRITER_H_INCLUDED
1923
+
1924
+ #if !defined(JSON_IS_AMALGAMATION)
1925
+ #include "value.h"
1926
+ #endif // if !defined(JSON_IS_AMALGAMATION)
1927
+ #include <ostream>
1928
+ #include <string>
1929
+ #include <vector>
1930
+
1931
+ // Disable warning C4251: <data member>: <type> needs to have dll-interface to
1932
+ // be used by...
1933
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER)
1934
+ #pragma warning(push)
1935
+ #pragma warning(disable : 4251)
1936
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1937
+
1938
+ #pragma pack(push, 8)
1939
+
1940
+ namespace Json {
1941
+
1942
+ class Value;
1943
+
1944
+ /**
1945
+
1946
+ Usage:
1947
+ \code
1948
+ using namespace Json;
1949
+ void writeToStdout(StreamWriter::Factory const& factory, Value const& value) {
1950
+ std::unique_ptr<StreamWriter> const writer(
1951
+ factory.newStreamWriter());
1952
+ writer->write(value, &std::cout);
1953
+ std::cout << std::endl; // add lf and flush
1954
+ }
1955
+ \endcode
1956
+ */
1957
+ class JSON_API StreamWriter {
1958
+ protected:
1959
+ OStream* sout_; // not owned; will not delete
1960
+ public:
1961
+ StreamWriter();
1962
+ virtual ~StreamWriter();
1963
+ /** Write Value into document as configured in sub-class.
1964
+ Do not take ownership of sout, but maintain a reference during function.
1965
+ \pre sout != NULL
1966
+ \return zero on success (For now, we always return zero, so check the
1967
+ stream instead.) \throw std::exception possibly, depending on configuration
1968
+ */
1969
+ virtual int write(Value const& root, OStream* sout) = 0;
1970
+
1971
+ /** \brief A simple abstract factory.
1972
+ */
1973
+ class JSON_API Factory {
1974
+ public:
1975
+ virtual ~Factory();
1976
+ /** \brief Allocate a CharReader via operator new().
1977
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
1978
+ */
1979
+ virtual StreamWriter* newStreamWriter() const = 0;
1980
+ }; // Factory
1981
+ }; // StreamWriter
1982
+
1983
+ /** \brief Write into stringstream, then return string, for convenience.
1984
+ * A StreamWriter will be created from the factory, used, and then deleted.
1985
+ */
1986
+ String JSON_API writeString(StreamWriter::Factory const& factory,
1987
+ Value const& root);
1988
+
1989
+ /** \brief Build a StreamWriter implementation.
1990
+
1991
+ Usage:
1992
+ \code
1993
+ using namespace Json;
1994
+ Value value = ...;
1995
+ StreamWriterBuilder builder;
1996
+ builder["commentStyle"] = "None";
1997
+ builder["indentation"] = " "; // or whatever you like
1998
+ std::unique_ptr<Json::StreamWriter> writer(
1999
+ builder.newStreamWriter());
2000
+ writer->write(value, &std::cout);
2001
+ std::cout << std::endl; // add lf and flush
2002
+ \endcode
2003
+ */
2004
+ class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
2005
+ public:
2006
+ // Note: We use a Json::Value so that we can add data-members to this class
2007
+ // without a major version bump.
2008
+ /** Configuration of this builder.
2009
+ Available settings (case-sensitive):
2010
+ - "commentStyle": "None" or "All"
2011
+ - "indentation": "<anything>".
2012
+ - Setting this to an empty string also omits newline characters.
2013
+ - "enableYAMLCompatibility": false or true
2014
+ - slightly change the whitespace around colons
2015
+ - "dropNullPlaceholders": false or true
2016
+ - Drop the "null" string from the writer's output for nullValues.
2017
+ Strictly speaking, this is not valid JSON. But when the output is being
2018
+ fed to a browser's JavaScript, it makes for smaller output and the
2019
+ browser can handle the output just fine.
2020
+ - "useSpecialFloats": false or true
2021
+ - If true, outputs non-finite floating point values in the following way:
2022
+ NaN values as "NaN", positive infinity as "Infinity", and negative
2023
+ infinity as "-Infinity".
2024
+ - "precision": int
2025
+ - Number of precision digits for formatting of real values.
2026
+ - "precisionType": "significant"(default) or "decimal"
2027
+ - Type of precision for formatting of real values.
2028
+
2029
+ You can examine 'settings_` yourself
2030
+ to see the defaults. You can also write and read them just like any
2031
+ JSON Value.
2032
+ \sa setDefaults()
2033
+ */
2034
+ Json::Value settings_;
2035
+
2036
+ StreamWriterBuilder();
2037
+ ~StreamWriterBuilder() override;
2038
+
2039
+ /**
2040
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
2041
+ */
2042
+ StreamWriter* newStreamWriter() const override;
2043
+
2044
+ /** \return true if 'settings' are legal and consistent;
2045
+ * otherwise, indicate bad settings via 'invalid'.
2046
+ */
2047
+ bool validate(Json::Value* invalid) const;
2048
+ /** A simple way to update a specific setting.
2049
+ */
2050
+ Value& operator[](const String& key);
2051
+
2052
+ /** Called by ctor, but you can use this to reset settings_.
2053
+ * \pre 'settings' != NULL (but Json::null is fine)
2054
+ * \remark Defaults:
2055
+ * \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults
2056
+ */
2057
+ static void setDefaults(Json::Value* settings);
2058
+ };
2059
+
2060
+ /** \brief Abstract class for writers.
2061
+ * \deprecated Use StreamWriter. (And really, this is an implementation detail.)
2062
+ */
2063
+ class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {
2064
+ public:
2065
+ virtual ~Writer();
2066
+
2067
+ virtual String write(const Value& root) = 0;
2068
+ };
2069
+
2070
+ /** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format
2071
+ *without formatting (not human friendly).
2072
+ *
2073
+ * The JSON document is written in a single line. It is not intended for 'human'
2074
+ *consumption,
2075
+ * but may be useful to support feature such as RPC where bandwidth is limited.
2076
+ * \sa Reader, Value
2077
+ * \deprecated Use StreamWriterBuilder.
2078
+ */
2079
+ #if defined(_MSC_VER)
2080
+ #pragma warning(push)
2081
+ #pragma warning(disable : 4996) // Deriving from deprecated class
2082
+ #endif
2083
+ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter
2084
+ : public Writer {
2085
+ public:
2086
+ FastWriter();
2087
+ ~FastWriter() override = default;
2088
+
2089
+ void enableYAMLCompatibility();
2090
+
2091
+ /** \brief Drop the "null" string from the writer's output for nullValues.
2092
+ * Strictly speaking, this is not valid JSON. But when the output is being
2093
+ * fed to a browser's JavaScript, it makes for smaller output and the
2094
+ * browser can handle the output just fine.
2095
+ */
2096
+ void dropNullPlaceholders();
2097
+
2098
+ void omitEndingLineFeed();
2099
+
2100
+ public: // overridden from Writer
2101
+ String write(const Value& root) override;
2102
+
2103
+ private:
2104
+ void writeValue(const Value& value);
2105
+
2106
+ String document_;
2107
+ bool yamlCompatibilityEnabled_{false};
2108
+ bool dropNullPlaceholders_{false};
2109
+ bool omitEndingLineFeed_{false};
2110
+ };
2111
+ #if defined(_MSC_VER)
2112
+ #pragma warning(pop)
2113
+ #endif
2114
+
2115
+ /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
2116
+ *human friendly way.
2117
+ *
2118
+ * The rules for line break and indent are as follow:
2119
+ * - Object value:
2120
+ * - if empty then print {} without indent and line break
2121
+ * - if not empty the print '{', line break & indent, print one value per
2122
+ *line
2123
+ * and then unindent and line break and print '}'.
2124
+ * - Array value:
2125
+ * - if empty then print [] without indent and line break
2126
+ * - if the array contains no object value, empty array or some other value
2127
+ *types,
2128
+ * and all the values fit on one lines, then print the array on a single
2129
+ *line.
2130
+ * - otherwise, it the values do not fit on one line, or the array contains
2131
+ * object or non empty array, then print one value per line.
2132
+ *
2133
+ * If the Value have comments then they are outputed according to their
2134
+ *#CommentPlacement.
2135
+ *
2136
+ * \sa Reader, Value, Value::setComment()
2137
+ * \deprecated Use StreamWriterBuilder.
2138
+ */
2139
+ #if defined(_MSC_VER)
2140
+ #pragma warning(push)
2141
+ #pragma warning(disable : 4996) // Deriving from deprecated class
2142
+ #endif
2143
+ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
2144
+ StyledWriter : public Writer {
2145
+ public:
2146
+ StyledWriter();
2147
+ ~StyledWriter() override = default;
2148
+
2149
+ public: // overridden from Writer
2150
+ /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
2151
+ * \param root Value to serialize.
2152
+ * \return String containing the JSON document that represents the root value.
2153
+ */
2154
+ String write(const Value& root) override;
2155
+
2156
+ private:
2157
+ void writeValue(const Value& value);
2158
+ void writeArrayValue(const Value& value);
2159
+ bool isMultilineArray(const Value& value);
2160
+ void pushValue(const String& value);
2161
+ void writeIndent();
2162
+ void writeWithIndent(const String& value);
2163
+ void indent();
2164
+ void unindent();
2165
+ void writeCommentBeforeValue(const Value& root);
2166
+ void writeCommentAfterValueOnSameLine(const Value& root);
2167
+ static bool hasCommentForValue(const Value& value);
2168
+ static String normalizeEOL(const String& text);
2169
+
2170
+ typedef std::vector<String> ChildValues;
2171
+
2172
+ ChildValues childValues_;
2173
+ String document_;
2174
+ String indentString_;
2175
+ unsigned int rightMargin_{74};
2176
+ unsigned int indentSize_{3};
2177
+ bool addChildValues_{false};
2178
+ };
2179
+ #if defined(_MSC_VER)
2180
+ #pragma warning(pop)
2181
+ #endif
2182
+
2183
+ /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
2184
+ human friendly way,
2185
+ to a stream rather than to a string.
2186
+ *
2187
+ * The rules for line break and indent are as follow:
2188
+ * - Object value:
2189
+ * - if empty then print {} without indent and line break
2190
+ * - if not empty the print '{', line break & indent, print one value per
2191
+ line
2192
+ * and then unindent and line break and print '}'.
2193
+ * - Array value:
2194
+ * - if empty then print [] without indent and line break
2195
+ * - if the array contains no object value, empty array or some other value
2196
+ types,
2197
+ * and all the values fit on one lines, then print the array on a single
2198
+ line.
2199
+ * - otherwise, it the values do not fit on one line, or the array contains
2200
+ * object or non empty array, then print one value per line.
2201
+ *
2202
+ * If the Value have comments then they are outputed according to their
2203
+ #CommentPlacement.
2204
+ *
2205
+ * \sa Reader, Value, Value::setComment()
2206
+ * \deprecated Use StreamWriterBuilder.
2207
+ */
2208
+ #if defined(_MSC_VER)
2209
+ #pragma warning(push)
2210
+ #pragma warning(disable : 4996) // Deriving from deprecated class
2211
+ #endif
2212
+ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
2213
+ StyledStreamWriter {
2214
+ public:
2215
+ /**
2216
+ * \param indentation Each level will be indented by this amount extra.
2217
+ */
2218
+ StyledStreamWriter(String indentation = "\t");
2219
+ ~StyledStreamWriter() = default;
2220
+
2221
+ public:
2222
+ /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
2223
+ * \param out Stream to write to. (Can be ostringstream, e.g.)
2224
+ * \param root Value to serialize.
2225
+ * \note There is no point in deriving from Writer, since write() should not
2226
+ * return a value.
2227
+ */
2228
+ void write(OStream& out, const Value& root);
2229
+
2230
+ private:
2231
+ void writeValue(const Value& value);
2232
+ void writeArrayValue(const Value& value);
2233
+ bool isMultilineArray(const Value& value);
2234
+ void pushValue(const String& value);
2235
+ void writeIndent();
2236
+ void writeWithIndent(const String& value);
2237
+ void indent();
2238
+ void unindent();
2239
+ void writeCommentBeforeValue(const Value& root);
2240
+ void writeCommentAfterValueOnSameLine(const Value& root);
2241
+ static bool hasCommentForValue(const Value& value);
2242
+ static String normalizeEOL(const String& text);
2243
+
2244
+ typedef std::vector<String> ChildValues;
2245
+
2246
+ ChildValues childValues_;
2247
+ OStream* document_;
2248
+ String indentString_;
2249
+ unsigned int rightMargin_{74};
2250
+ String indentation_;
2251
+ bool addChildValues_ : 1;
2252
+ bool indented_ : 1;
2253
+ };
2254
+ #if defined(_MSC_VER)
2255
+ #pragma warning(pop)
2256
+ #endif
2257
+
2258
+ #if defined(JSON_HAS_INT64)
2259
+ String JSON_API valueToString(Int value);
2260
+ String JSON_API valueToString(UInt value);
2261
+ #endif // if defined(JSON_HAS_INT64)
2262
+ String JSON_API valueToString(LargestInt value);
2263
+ String JSON_API valueToString(LargestUInt value);
2264
+ String JSON_API
2265
+ valueToString(double value,
2266
+ unsigned int precision = Value::defaultRealPrecision,
2267
+ PrecisionType precisionType = PrecisionType::significantDigits);
2268
+ String JSON_API valueToString(bool value);
2269
+ String JSON_API valueToQuotedString(const char* value);
2270
+
2271
+ /// \brief Output using the StyledStreamWriter.
2272
+ /// \see Json::operator>>()
2273
+ JSON_API OStream& operator<<(OStream&, const Value& root);
2274
+
2275
+ } // namespace Json
2276
+
2277
+ #pragma pack(pop)
2278
+
2279
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
2280
+ #pragma warning(pop)
2281
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
2282
+
2283
+ #endif // JSON_WRITER_H_INCLUDED
2284
+
2285
+ // //////////////////////////////////////////////////////////////////////
2286
+ // End of content of file: include/json/writer.h
2287
+ // //////////////////////////////////////////////////////////////////////
2288
+
2289
+
2290
+
2291
+
2292
+
2293
+
2294
+ // //////////////////////////////////////////////////////////////////////
2295
+ // Beginning of content of file: include/json/assertions.h
2296
+ // //////////////////////////////////////////////////////////////////////
2297
+
2298
+ // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
2299
+ // Distributed under MIT license, or public domain if desired and
2300
+ // recognized in your jurisdiction.
2301
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
2302
+
2303
+ #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
2304
+ #define CPPTL_JSON_ASSERTIONS_H_INCLUDED
2305
+
2306
+ #include <cstdlib>
2307
+ #include <sstream>
2308
+
2309
+ #if !defined(JSON_IS_AMALGAMATION)
2310
+ #include "config.h"
2311
+ #endif // if !defined(JSON_IS_AMALGAMATION)
2312
+
2313
+ /** It should not be possible for a maliciously designed file to
2314
+ * cause an abort() or seg-fault, so these macros are used only
2315
+ * for pre-condition violations and internal logic errors.
2316
+ */
2317
+ #if JSON_USE_EXCEPTION
2318
+
2319
+ // @todo <= add detail about condition in exception
2320
+ #define JSON_ASSERT(condition) \
2321
+ { \
2322
+ if (!(condition)) { \
2323
+ Json::throwLogicError("assert json failed"); \
2324
+ } \
2325
+ }
2326
+
2327
+ #define JSON_FAIL_MESSAGE(message) \
2328
+ { \
2329
+ OStringStream oss; \
2330
+ oss << message; \
2331
+ Json::throwLogicError(oss.str()); \
2332
+ abort(); \
2333
+ }
2334
+
2335
+ #else // JSON_USE_EXCEPTION
2336
+
2337
+ #define JSON_ASSERT(condition) assert(condition)
2338
+
2339
+ // The call to assert() will show the failure message in debug builds. In
2340
+ // release builds we abort, for a core-dump or debugger.
2341
+ #define JSON_FAIL_MESSAGE(message) \
2342
+ { \
2343
+ OStringStream oss; \
2344
+ oss << message; \
2345
+ assert(false && oss.str().c_str()); \
2346
+ abort(); \
2347
+ }
2348
+
2349
+ #endif
2350
+
2351
+ #define JSON_ASSERT_MESSAGE(condition, message) \
2352
+ if (!(condition)) { \
2353
+ JSON_FAIL_MESSAGE(message); \
2354
+ }
2355
+
2356
+ #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
2357
+
2358
+ // //////////////////////////////////////////////////////////////////////
2359
+ // End of content of file: include/json/assertions.h
2360
+ // //////////////////////////////////////////////////////////////////////
2361
+
2362
+
2363
+
2364
+
2365
+
2366
+ #endif //ifndef JSON_AMALGAMATED_H_INCLUDED