passenger 5.0.30 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +30 -1
  3. data/CONTRIBUTING.md +1 -1
  4. data/CONTRIBUTORS +2 -0
  5. data/bin/passenger-install-nginx-module +18 -13
  6. data/build/agent.rb +1 -0
  7. data/build/basics.rb +1 -0
  8. data/build/cxx_tests.rb +6 -1
  9. data/build/misc.rb +3 -0
  10. data/build/packaging.rb +5 -17
  11. data/build/support/cxx_dependency_map.rb +100 -0
  12. data/build/support/vendor/cxxcodebuilder/lib/cxxcodebuilder/builder.rb +4 -1
  13. data/build/test_basics.rb +12 -2
  14. data/dev/ci/run_travis.sh +6 -2
  15. data/doc/Users guide Apache.html +7 -2
  16. data/doc/Users guide Apache.txt +4 -0
  17. data/resources/templates/error_layout.css +70 -84
  18. data/resources/templates/error_layout.html.template +84 -93
  19. data/resources/templates/standalone/http.erb +17 -13
  20. data/resources/templates/standalone/server.erb +2 -1
  21. data/resources/templates/undisclosed_error.html.template +52 -51
  22. data/resources/update_check_client_cert.p12 +0 -0
  23. data/resources/update_check_client_cert.pem +89 -0
  24. data/resources/update_check_server_pubkey.pem +14 -0
  25. data/src/agent/Core/ApplicationPool/ErrorRenderer.h +15 -1
  26. data/src/agent/Core/Controller.h +3 -2
  27. data/src/agent/Core/Controller/CheckoutSession.cpp +5 -4
  28. data/src/agent/Core/Controller/ForwardResponse.cpp +1 -1
  29. data/src/agent/Core/Controller/InitRequest.cpp +2 -0
  30. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +1 -0
  31. data/src/agent/Core/Controller/Request.h +1 -0
  32. data/src/agent/Core/CoreMain.cpp +99 -2
  33. data/src/agent/Core/OptionParser.h +18 -1
  34. data/src/agent/Core/SecurityUpdateChecker.h +559 -0
  35. data/src/agent/Shared/Base.cpp +6 -1
  36. data/src/agent/TempDirToucher/TempDirToucherMain.cpp +52 -0
  37. data/src/agent/Watchdog/InstanceDirToucher.cpp +1 -2
  38. data/src/agent/Watchdog/WatchdogMain.cpp +31 -40
  39. data/src/apache2_module/Configuration.cpp +12 -0
  40. data/src/apache2_module/Configuration.hpp +5 -0
  41. data/src/apache2_module/ConfigurationCommands.cpp +19 -19
  42. data/src/apache2_module/ConfigurationCommands.cpp.cxxcodebuilder +2 -2
  43. data/src/apache2_module/ConfigurationFields.hpp +19 -19
  44. data/src/apache2_module/ConfigurationFields.hpp.cxxcodebuilder +2 -2
  45. data/src/apache2_module/ConfigurationSetters.cpp +19 -19
  46. data/src/apache2_module/ConfigurationSetters.cpp.cxxcodebuilder +2 -2
  47. data/src/apache2_module/CreateDirConfig.cpp +19 -19
  48. data/src/apache2_module/CreateDirConfig.cpp.cxxcodebuilder +2 -2
  49. data/src/apache2_module/Hooks.cpp +10 -1
  50. data/src/apache2_module/MergeDirConfig.cpp +19 -19
  51. data/src/apache2_module/MergeDirConfig.cpp.cxxcodebuilder +2 -2
  52. data/src/apache2_module/SetHeaders.cpp +19 -19
  53. data/src/apache2_module/SetHeaders.cpp.cxxcodebuilder +2 -2
  54. data/src/cxx_supportlib/Constants.h +22 -22
  55. data/src/cxx_supportlib/Constants.h.cxxcodebuilder +4 -1
  56. data/src/cxx_supportlib/Crypto.cpp +977 -0
  57. data/src/cxx_supportlib/Crypto.h +147 -0
  58. data/src/cxx_supportlib/InstanceDirectory.h +55 -2
  59. data/src/cxx_supportlib/Utils/Curl.h +24 -10
  60. data/src/cxx_supportlib/Utils/JsonUtils.h +1 -1
  61. data/src/cxx_supportlib/oxt/detail/spin_lock_darwin.hpp +2 -0
  62. data/src/cxx_supportlib/vendor-modified/boost/system/error_code.hpp +3 -3
  63. data/src/cxx_supportlib/vendor-modified/jsoncpp/json-forwards.h +167 -92
  64. data/src/cxx_supportlib/vendor-modified/jsoncpp/json.h +1827 -1542
  65. data/src/cxx_supportlib/vendor-modified/jsoncpp/jsoncpp.cpp +4705 -3652
  66. data/src/cxx_supportlib/vendor-modified/libev/Changes +46 -15
  67. data/src/cxx_supportlib/vendor-modified/libev/LICENSE +1 -1
  68. data/src/cxx_supportlib/vendor-modified/libev/Makefile.in +215 -128
  69. data/src/cxx_supportlib/vendor-modified/libev/aclocal.m4 +466 -275
  70. data/src/cxx_supportlib/vendor-modified/libev/config.guess +312 -418
  71. data/src/cxx_supportlib/vendor-modified/libev/config.sub +246 -105
  72. data/src/cxx_supportlib/vendor-modified/libev/configure +276 -72
  73. data/src/cxx_supportlib/vendor-modified/libev/configure.ac +2 -1
  74. data/src/cxx_supportlib/vendor-modified/libev/depcomp +346 -185
  75. data/src/cxx_supportlib/vendor-modified/libev/ev++.h +1 -1
  76. data/src/cxx_supportlib/vendor-modified/libev/ev.c +530 -190
  77. data/src/cxx_supportlib/vendor-modified/libev/ev.h +23 -14
  78. data/src/cxx_supportlib/vendor-modified/libev/ev_epoll.c +12 -6
  79. data/src/cxx_supportlib/vendor-modified/libev/ev_kqueue.c +9 -5
  80. data/src/cxx_supportlib/vendor-modified/libev/ev_poll.c +6 -3
  81. data/src/cxx_supportlib/vendor-modified/libev/ev_port.c +8 -4
  82. data/src/cxx_supportlib/vendor-modified/libev/ev_select.c +4 -2
  83. data/src/cxx_supportlib/vendor-modified/libev/ev_vars.h +3 -2
  84. data/src/cxx_supportlib/vendor-modified/libev/ev_win32.c +3 -4
  85. data/src/cxx_supportlib/vendor-modified/libev/install-sh +433 -219
  86. data/src/cxx_supportlib/vendor-modified/libev/libev.m4 +6 -6
  87. data/src/cxx_supportlib/vendor-modified/libev/ltmain.sh +2 -2
  88. data/src/cxx_supportlib/vendor-modified/libev/missing +167 -288
  89. data/src/cxx_supportlib/vendor-modified/libev/mkinstalldirs +72 -21
  90. data/src/cxx_supportlib/vendor-modified/modp_b64.cpp +4 -106
  91. data/src/cxx_supportlib/vendor-modified/modp_b64_data.h +37 -1
  92. data/src/cxx_supportlib/vendor-modified/modp_b64_strict_aliasing.cpp +119 -0
  93. data/src/helper-scripts/node-loader.js +72 -1
  94. data/src/nginx_module/CacheLocationConfig.c +52 -19
  95. data/src/nginx_module/CacheLocationConfig.c.cxxcodebuilder +2 -2
  96. data/src/nginx_module/Configuration.c +26 -1
  97. data/src/nginx_module/Configuration.h +2 -0
  98. data/src/nginx_module/ConfigurationCommands.c +35 -19
  99. data/src/nginx_module/ConfigurationCommands.c.cxxcodebuilder +2 -2
  100. data/src/nginx_module/ContentHandler.c +1 -1
  101. data/src/nginx_module/CreateLocationConfig.c +22 -19
  102. data/src/nginx_module/CreateLocationConfig.c.cxxcodebuilder +2 -2
  103. data/src/nginx_module/LocationConfig.h +21 -19
  104. data/src/nginx_module/LocationConfig.h.cxxcodebuilder +2 -2
  105. data/src/nginx_module/MergeLocationConfig.c +25 -19
  106. data/src/nginx_module/MergeLocationConfig.c.cxxcodebuilder +2 -2
  107. data/src/nginx_module/ngx_http_passenger_module.c +8 -4
  108. data/src/ruby_supportlib/phusion_passenger.rb +9 -4
  109. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +2 -2
  110. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance_registry.rb +1 -1
  111. data/src/ruby_supportlib/phusion_passenger/common_library.rb +13 -0
  112. data/src/ruby_supportlib/phusion_passenger/config/nginx_engine_compiler.rb +5 -2
  113. data/src/ruby_supportlib/phusion_passenger/constants.rb +1 -1
  114. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +15 -3
  115. data/src/ruby_supportlib/phusion_passenger/platform_info/crypto.rb +51 -0
  116. data/src/ruby_supportlib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +7 -0
  117. data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +17 -0
  118. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +4 -2
  119. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +4 -0
  120. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +5 -0
  121. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/app.rb +19 -10
  122. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/base.rb +25 -0
  123. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/gdb_controller.rb +38 -103
  124. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/lldb_controller.rb +178 -0
  125. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/utils.rb +94 -0
  126. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/version.rb +2 -2
  127. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +2 -2
  128. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
  129. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +5 -3
  130. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +9 -7
  131. metadata +14 -4
@@ -1,33 +1,33 @@
1
1
  /// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).
2
- /// It is intented to be used with #include <json/json.h>
2
+ /// It is intended to be used with #include "json/json.h"
3
3
 
4
4
  // //////////////////////////////////////////////////////////////////////
5
5
  // Beginning of content of file: LICENSE
6
6
  // //////////////////////////////////////////////////////////////////////
7
7
 
8
8
  /*
9
- The JsonCpp library's source code, including accompanying documentation,
9
+ The JsonCpp library's source code, including accompanying documentation,
10
10
  tests and demonstration applications, are licensed under the following
11
11
  conditions...
12
12
 
13
- The author (Baptiste Lepilleur) explicitly disclaims copyright in all
14
- jurisdictions which recognize such a disclaimer. In such jurisdictions,
13
+ The author (Baptiste Lepilleur) explicitly disclaims copyright in all
14
+ jurisdictions which recognize such a disclaimer. In such jurisdictions,
15
15
  this software is released into the Public Domain.
16
16
 
17
17
  In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
18
18
  2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
19
19
  released under the terms of the MIT License (see below).
20
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
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
24
  Public Domain/MIT License conditions described here, as they choose.
25
25
 
26
26
  The MIT License is about as close to Public Domain as a license can get, and is
27
27
  described in clear, concise terms at:
28
28
 
29
29
  http://en.wikipedia.org/wiki/MIT_License
30
-
30
+
31
31
  The full text of the MIT License follows:
32
32
 
33
33
  ========================================================================
@@ -76,7 +76,41 @@ license you like.
76
76
  # define JSON_AMALGATED_H_INCLUDED
77
77
  /// If defined, indicates that the source file is amalgated
78
78
  /// to prevent private header inclusion.
79
- #define JSON_IS_AMALGATED
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.7.7"
91
+ # define JSONCPP_VERSION_MAJOR 1
92
+ # define JSONCPP_VERSION_MINOR 7
93
+ # define JSONCPP_VERSION_PATCH 7
94
+ # define JSONCPP_VERSION_QUALIFIER
95
+ # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
96
+
97
+ #ifdef JSONCPP_USING_SECURE_MEMORY
98
+ #undef JSONCPP_USING_SECURE_MEMORY
99
+ #endif
100
+ #define JSONCPP_USING_SECURE_MEMORY 0
101
+ // If non-zero, the library zeroes any memory that it has allocated before
102
+ // it frees its memory.
103
+
104
+ #endif // JSON_VERSION_H_INCLUDED
105
+
106
+ // //////////////////////////////////////////////////////////////////////
107
+ // End of content of file: include/json/version.h
108
+ // //////////////////////////////////////////////////////////////////////
109
+
110
+
111
+
112
+
113
+
80
114
 
81
115
  // //////////////////////////////////////////////////////////////////////
82
116
  // Beginning of content of file: include/json/config.h
@@ -88,95 +122,177 @@ license you like.
88
122
  // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
89
123
 
90
124
  #ifndef JSON_CONFIG_H_INCLUDED
91
- # define JSON_CONFIG_H_INCLUDED
125
+ #define JSON_CONFIG_H_INCLUDED
126
+ #include <stddef.h>
127
+ #include <string> //typedef String
128
+ #include <stdint.h> //typedef int64_t, uint64_t
92
129
 
93
130
  /// If defined, indicates that json library is embedded in CppTL library.
94
131
  //# define JSON_IN_CPPTL 1
95
132
 
96
133
  /// If defined, indicates that json may leverage CppTL library
97
134
  //# define JSON_USE_CPPTL 1
98
- /// If defined, indicates that cpptl vector based map should be used instead of std::map
135
+ /// If defined, indicates that cpptl vector based map should be used instead of
136
+ /// std::map
99
137
  /// as Value container.
100
138
  //# define JSON_USE_CPPTL_SMALLMAP 1
101
- /// If defined, indicates that Json specific container should be used
102
- /// (hash table & simple deque container with customizable allocator).
103
- /// THIS FEATURE IS STILL EXPERIMENTAL! There is know bugs: See #3177332
104
- //# define JSON_VALUE_USE_INTERNAL_MAP 1
105
- /// Force usage of standard new/malloc based allocator instead of memory pool based allocator.
106
- /// The memory pools allocator used optimization (initializing Value and ValueInternalLink
107
- /// as if it was a POD) that may cause some validation tool to report errors.
108
- /// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined.
109
- //# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
110
-
111
- /// If defined, indicates that Json use exception to report invalid type manipulation
112
- /// instead of C assert macro.
113
- # define JSON_USE_EXCEPTION 1
139
+
140
+ // If non-zero, the library uses exceptions to report bad input instead of C
141
+ // assertion macros. The default is to use exceptions.
142
+ #ifndef JSON_USE_EXCEPTION
143
+ #define JSON_USE_EXCEPTION 1
144
+ #endif
114
145
 
115
146
  /// If defined, indicates that the source file is amalgated
116
147
  /// to prevent private header inclusion.
117
148
  /// Remarks: it is automatically defined in the generated amalgated header.
118
- #define JSON_IS_AMALGAMATION
149
+ // #define JSON_IS_AMALGAMATION
119
150
 
151
+ #ifdef JSON_IN_CPPTL
152
+ #include <cpptl/config.h>
153
+ #ifndef JSON_USE_CPPTL
154
+ #define JSON_USE_CPPTL 1
155
+ #endif
156
+ #endif
120
157
 
121
- # ifdef JSON_IN_CPPTL
122
- # include <cpptl/config.h>
123
- # ifndef JSON_USE_CPPTL
124
- # define JSON_USE_CPPTL 1
125
- # endif
126
- # endif
127
-
128
- # ifdef JSON_IN_CPPTL
129
- # define JSON_API CPPTL_API
130
- # elif defined(JSON_DLL_BUILD)
131
- # define JSON_API __declspec(dllexport)
132
- # elif defined(JSON_DLL)
133
- # define JSON_API __declspec(dllimport)
134
- # else
135
- # define JSON_API
136
- # endif
158
+ #ifdef JSON_IN_CPPTL
159
+ #define JSON_API CPPTL_API
160
+ #elif defined(JSON_DLL_BUILD)
161
+ #if defined(_MSC_VER) || defined(__MINGW32__)
162
+ #define JSON_API __declspec(dllexport)
163
+ #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
164
+ #endif // if defined(_MSC_VER)
165
+ #elif defined(JSON_DLL)
166
+ #if defined(_MSC_VER) || defined(__MINGW32__)
167
+ #define JSON_API __declspec(dllimport)
168
+ #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
169
+ #endif // if defined(_MSC_VER)
170
+ #endif // ifdef JSON_IN_CPPTL
171
+ #if !defined(JSON_API)
172
+ #define JSON_API
173
+ #endif
137
174
 
138
- // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer
175
+ // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
176
+ // integer
139
177
  // Storages, and 64 bits integer support is disabled.
140
178
  // #define JSON_NO_INT64 1
141
179
 
142
- #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
143
- // Microsoft Visual Studio 6 only support conversion from __int64 to double
144
- // (no conversion from unsigned __int64).
145
- #define JSON_USE_INT64_DOUBLE_CONVERSION 1
146
- #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
180
+ #if defined(_MSC_VER) // MSVC
181
+ # if _MSC_VER <= 1200 // MSVC 6
182
+ // Microsoft Visual Studio 6 only support conversion from __int64 to double
183
+ // (no conversion from unsigned __int64).
184
+ # define JSON_USE_INT64_DOUBLE_CONVERSION 1
185
+ // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
186
+ // characters in the debug information)
187
+ // All projects I've ever seen with VS6 were using this globally (not bothering
188
+ // with pragma push/pop).
189
+ # pragma warning(disable : 4786)
190
+ # endif // MSVC 6
191
+
192
+ # if _MSC_VER >= 1500 // MSVC 2008
193
+ /// Indicates that the following function is deprecated.
194
+ # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
195
+ # endif
196
+
197
+ #endif // defined(_MSC_VER)
198
+
199
+ // In c++11 the override keyword allows you to explicity define that a function
200
+ // is intended to override the base-class version. This makes the code more
201
+ // managable and fixes a set of common hard-to-find bugs.
202
+ #if __cplusplus >= 201103L
203
+ # define JSONCPP_OVERRIDE override
204
+ #elif defined(_MSC_VER) && _MSC_VER > 1600
205
+ # define JSONCPP_OVERRIDE override
206
+ #else
207
+ # define JSONCPP_OVERRIDE
208
+ #endif
209
+
210
+ #ifndef JSON_HAS_RVALUE_REFERENCES
211
+
212
+ #if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010
213
+ #define JSON_HAS_RVALUE_REFERENCES 1
214
+ #endif // MSVC >= 2010
215
+
216
+ #ifdef __clang__
217
+ #if __has_feature(cxx_rvalue_references)
218
+ #define JSON_HAS_RVALUE_REFERENCES 1
219
+ #endif // has_feature
147
220
 
148
- #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
149
- /// Indicates that the following function is deprecated.
150
- # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
221
+ #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
222
+ #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
223
+ #define JSON_HAS_RVALUE_REFERENCES 1
224
+ #endif // GXX_EXPERIMENTAL
225
+
226
+ #endif // __clang__ || __GNUC__
227
+
228
+ #endif // not defined JSON_HAS_RVALUE_REFERENCES
229
+
230
+ #ifndef JSON_HAS_RVALUE_REFERENCES
231
+ #define JSON_HAS_RVALUE_REFERENCES 0
151
232
  #endif
152
233
 
234
+ #ifdef __clang__
235
+ #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
236
+ # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
237
+ # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
238
+ # elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
239
+ # define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
240
+ # endif // GNUC version
241
+ #endif // __clang__ || __GNUC__
242
+
153
243
  #if !defined(JSONCPP_DEPRECATED)
154
- # define JSONCPP_DEPRECATED(message)
244
+ #define JSONCPP_DEPRECATED(message)
155
245
  #endif // if !defined(JSONCPP_DEPRECATED)
156
246
 
247
+ #if __GNUC__ >= 6
248
+ # define JSON_USE_INT64_DOUBLE_CONVERSION 1
249
+ #endif
250
+
251
+ #if !defined(JSON_IS_AMALGAMATION)
252
+
253
+ # include "version.h"
254
+
255
+ # if JSONCPP_USING_SECURE_MEMORY
256
+ # include "allocator.h" //typedef Allocator
257
+ # endif
258
+
259
+ #endif // if !defined(JSON_IS_AMALGAMATION)
260
+
157
261
  namespace Json {
158
- typedef int Int;
159
- typedef unsigned int UInt;
160
- # if defined(JSON_NO_INT64)
161
- typedef int LargestInt;
162
- typedef unsigned int LargestUInt;
163
- # undef JSON_HAS_INT64
164
- # else // if defined(JSON_NO_INT64)
165
- // For Microsoft Visual use specific types as long long is not supported
166
- # if defined(_MSC_VER) // Microsoft Visual Studio
167
- typedef __int64 Int64;
168
- typedef unsigned __int64 UInt64;
169
- # else // if defined(_MSC_VER) // Other platforms, use long long
170
- typedef long long int Int64;
171
- typedef unsigned long long int UInt64;
172
- # endif // if defined(_MSC_VER)
173
- typedef Int64 LargestInt;
174
- typedef UInt64 LargestUInt;
175
- # define JSON_HAS_INT64
176
- # endif // if defined(JSON_NO_INT64)
262
+ typedef int Int;
263
+ typedef unsigned int UInt;
264
+ #if defined(JSON_NO_INT64)
265
+ typedef int LargestInt;
266
+ typedef unsigned int LargestUInt;
267
+ #undef JSON_HAS_INT64
268
+ #else // if defined(JSON_NO_INT64)
269
+ // For Microsoft Visual use specific types as long long is not supported
270
+ #if defined(_MSC_VER) // Microsoft Visual Studio
271
+ typedef __int64 Int64;
272
+ typedef unsigned __int64 UInt64;
273
+ #else // if defined(_MSC_VER) // Other platforms, use long long
274
+ typedef int64_t Int64;
275
+ typedef uint64_t UInt64;
276
+ #endif // if defined(_MSC_VER)
277
+ typedef Int64 LargestInt;
278
+ typedef UInt64 LargestUInt;
279
+ #define JSON_HAS_INT64
280
+ #endif // if defined(JSON_NO_INT64)
281
+ #if JSONCPP_USING_SECURE_MEMORY
282
+ #define JSONCPP_STRING std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
283
+ #define JSONCPP_OSTRINGSTREAM std::basic_ostringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >
284
+ #define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char>>
285
+ #define JSONCPP_ISTRINGSTREAM std::basic_istringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >
286
+ #define JSONCPP_ISTREAM std::istream
287
+ #else
288
+ #define JSONCPP_STRING std::string
289
+ #define JSONCPP_OSTRINGSTREAM std::ostringstream
290
+ #define JSONCPP_OSTREAM std::ostream
291
+ #define JSONCPP_ISTRINGSTREAM std::istringstream
292
+ #define JSONCPP_ISTREAM std::istream
293
+ #endif // if JSONCPP_USING_SECURE_MEMORY
177
294
  } // end namespace Json
178
295
 
179
-
180
296
  #endif // JSON_CONFIG_H_INCLUDED
181
297
 
182
298
  // //////////////////////////////////////////////////////////////////////
@@ -198,42 +314,35 @@ namespace Json {
198
314
  // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
199
315
 
200
316
  #ifndef JSON_FORWARDS_H_INCLUDED
201
- # define JSON_FORWARDS_H_INCLUDED
317
+ #define JSON_FORWARDS_H_INCLUDED
202
318
 
203
319
  #if !defined(JSON_IS_AMALGAMATION)
204
- # include "config.h"
320
+ #include "config.h"
205
321
  #endif // if !defined(JSON_IS_AMALGAMATION)
206
322
 
207
323
  namespace Json {
208
324
 
209
- // writer.h
210
- class FastWriter;
211
- class StyledWriter;
212
-
213
- // reader.h
214
- class Reader;
215
-
216
- // features.h
217
- class Features;
218
-
219
- // value.h
220
- typedef unsigned int ArrayIndex;
221
- class StaticString;
222
- class Path;
223
- class PathArgument;
224
- class Value;
225
- class ValueIteratorBase;
226
- class ValueIterator;
227
- class ValueConstIterator;
228
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
229
- class ValueMapAllocator;
230
- class ValueInternalLink;
231
- class ValueInternalArray;
232
- class ValueInternalMap;
233
- #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
325
+ // writer.h
326
+ class FastWriter;
327
+ class StyledWriter;
234
328
 
235
- } // namespace Json
329
+ // reader.h
330
+ class Reader;
331
+
332
+ // features.h
333
+ class Features;
334
+
335
+ // value.h
336
+ typedef unsigned int ArrayIndex;
337
+ class StaticString;
338
+ class Path;
339
+ class PathArgument;
340
+ class Value;
341
+ class ValueIteratorBase;
342
+ class ValueIterator;
343
+ class ValueConstIterator;
236
344
 
345
+ } // namespace Json
237
346
 
238
347
  #endif // JSON_FORWARDS_H_INCLUDED
239
348
 
@@ -256,45 +365,53 @@ namespace Json {
256
365
  // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
257
366
 
258
367
  #ifndef CPPTL_JSON_FEATURES_H_INCLUDED
259
- # define CPPTL_JSON_FEATURES_H_INCLUDED
368
+ #define CPPTL_JSON_FEATURES_H_INCLUDED
260
369
 
261
370
  #if !defined(JSON_IS_AMALGAMATION)
262
- # include "forwards.h"
371
+ #include "forwards.h"
263
372
  #endif // if !defined(JSON_IS_AMALGAMATION)
264
373
 
265
374
  namespace Json {
266
375
 
267
- /** \brief Configuration passed to reader and writer.
268
- * This configuration object can be used to force the Reader or Writer
269
- * to behave in a standard conforming way.
270
- */
271
- class JSON_API Features
272
- {
273
- public:
274
- /** \brief A configuration that allows all features and assumes all strings are UTF-8.
275
- * - C & C++ comments are allowed
276
- * - Root object can be any JSON value
277
- * - Assumes Value strings are encoded in UTF-8
278
- */
279
- static Features all();
280
-
281
- /** \brief A configuration that is strictly compatible with the JSON specification.
282
- * - Comments are forbidden.
283
- * - Root object must be either an array or an object value.
284
- * - Assumes Value strings are encoded in UTF-8
285
- */
286
- static Features strictMode();
287
-
288
- /** \brief Initialize the configuration like JsonConfig::allFeatures;
289
- */
290
- Features();
291
-
292
- /// \c true if comments are allowed. Default: \c true.
293
- bool allowComments_;
294
-
295
- /// \c true if root must be either an array or an object value. Default: \c false.
296
- bool strictRoot_;
297
- };
376
+ /** \brief Configuration passed to reader and writer.
377
+ * This configuration object can be used to force the Reader or Writer
378
+ * to behave in a standard conforming way.
379
+ */
380
+ class JSON_API Features {
381
+ public:
382
+ /** \brief A configuration that allows all features and assumes all strings
383
+ * are UTF-8.
384
+ * - C & C++ comments are allowed
385
+ * - Root object can be any JSON value
386
+ * - Assumes Value strings are encoded in UTF-8
387
+ */
388
+ static Features all();
389
+
390
+ /** \brief A configuration that is strictly compatible with the JSON
391
+ * specification.
392
+ * - Comments are forbidden.
393
+ * - Root object must be either an array or an object value.
394
+ * - Assumes Value strings are encoded in UTF-8
395
+ */
396
+ static Features strictMode();
397
+
398
+ /** \brief Initialize the configuration like JsonConfig::allFeatures;
399
+ */
400
+ Features();
401
+
402
+ /// \c true if comments are allowed. Default: \c true.
403
+ bool allowComments_;
404
+
405
+ /// \c true if root must be either an array or an object value. Default: \c
406
+ /// false.
407
+ bool strictRoot_;
408
+
409
+ /// \c true if dropped null placeholders are allowed. Default: \c false.
410
+ bool allowDroppedNullPlaceholders_;
411
+
412
+ /// \c true if numeric object key are allowed. Default: \c false.
413
+ bool allowNumericKeys_;
414
+ };
298
415
 
299
416
  } // namespace Json
300
417
 
@@ -319,1101 +436,865 @@ namespace Json {
319
436
  // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
320
437
 
321
438
  #ifndef CPPTL_JSON_H_INCLUDED
322
- # define CPPTL_JSON_H_INCLUDED
439
+ #define CPPTL_JSON_H_INCLUDED
323
440
 
324
441
  #if !defined(JSON_IS_AMALGAMATION)
325
- # include "forwards.h"
442
+ #include "forwards.h"
326
443
  #endif // if !defined(JSON_IS_AMALGAMATION)
327
- # include <string>
328
- # include <vector>
444
+ #include <string>
445
+ #include <vector>
446
+ #include <exception>
329
447
 
330
- # ifndef JSON_USE_CPPTL_SMALLMAP
331
- # include <map>
332
- # else
333
- # include <cpptl/smallmap.h>
334
- # endif
335
- # ifdef JSON_USE_CPPTL
336
- # include <cpptl/forwards.h>
337
- # endif
448
+ #ifndef JSON_USE_CPPTL_SMALLMAP
449
+ #include <map>
450
+ #else
451
+ #include <cpptl/smallmap.h>
452
+ #endif
453
+ #ifdef JSON_USE_CPPTL
454
+ #include <cpptl/forwards.h>
455
+ #endif
456
+
457
+ //Conditional NORETURN attribute on the throw functions would:
458
+ // a) suppress false positives from static code analysis
459
+ // b) possibly improve optimization opportunities.
460
+ #if !defined(JSONCPP_NORETURN)
461
+ # if defined(_MSC_VER)
462
+ # define JSONCPP_NORETURN __declspec(noreturn)
463
+ # elif defined(__GNUC__)
464
+ # define JSONCPP_NORETURN __attribute__ ((__noreturn__))
465
+ # else
466
+ # define JSONCPP_NORETURN
467
+ # endif
468
+ #endif
469
+
470
+ // Disable warning C4251: <data member>: <type> needs to have dll-interface to
471
+ // be used by...
472
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
473
+ #pragma warning(push)
474
+ #pragma warning(disable : 4251)
475
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
338
476
 
339
477
  /** \brief JSON (JavaScript Object Notation).
340
478
  */
341
479
  namespace Json {
342
480
 
343
- /** \brief Type of the value held by a Value object.
344
- */
345
- enum ValueType
346
- {
347
- nullValue = 0, ///< 'null' value
348
- intValue, ///< signed integer value
349
- uintValue, ///< unsigned integer value
350
- realValue, ///< double value
351
- stringValue, ///< UTF-8 string value
352
- booleanValue, ///< bool value
353
- arrayValue, ///< array value (ordered list)
354
- objectValue ///< object value (collection of name/value pairs).
355
- };
356
-
357
- enum CommentPlacement
358
- {
359
- commentBefore = 0, ///< a comment placed on the line before a value
360
- commentAfterOnSameLine, ///< a comment just after a value on the same line
361
- commentAfter, ///< a comment on the line after a value (only make sense for root value)
362
- numberOfCommentPlacement
363
- };
481
+ /** Base class for all exceptions we throw.
482
+ *
483
+ * We use nothing but these internally. Of course, STL can throw others.
484
+ */
485
+ class JSON_API Exception : public std::exception {
486
+ public:
487
+ Exception(JSONCPP_STRING const& msg);
488
+ ~Exception() throw() JSONCPP_OVERRIDE;
489
+ char const* what() const throw() JSONCPP_OVERRIDE;
490
+ protected:
491
+ JSONCPP_STRING msg_;
492
+ };
493
+
494
+ /** Exceptions which the user cannot easily avoid.
495
+ *
496
+ * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
497
+ *
498
+ * \remark derived from Json::Exception
499
+ */
500
+ class JSON_API RuntimeError : public Exception {
501
+ public:
502
+ RuntimeError(JSONCPP_STRING const& msg);
503
+ };
504
+
505
+ /** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
506
+ *
507
+ * These are precondition-violations (user bugs) and internal errors (our bugs).
508
+ *
509
+ * \remark derived from Json::Exception
510
+ */
511
+ class JSON_API LogicError : public Exception {
512
+ public:
513
+ LogicError(JSONCPP_STRING const& msg);
514
+ };
515
+
516
+ /// used internally
517
+ JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg);
518
+ /// used internally
519
+ JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg);
520
+
521
+ /** \brief Type of the value held by a Value object.
522
+ */
523
+ enum ValueType {
524
+ nullValue = 0, ///< 'null' value
525
+ intValue, ///< signed integer value
526
+ uintValue, ///< unsigned integer value
527
+ realValue, ///< double value
528
+ stringValue, ///< UTF-8 string value
529
+ booleanValue, ///< bool value
530
+ arrayValue, ///< array value (ordered list)
531
+ objectValue ///< object value (collection of name/value pairs).
532
+ };
533
+
534
+ enum CommentPlacement {
535
+ commentBefore = 0, ///< a comment placed on the line before a value
536
+ commentAfterOnSameLine, ///< a comment just after a value on the same line
537
+ commentAfter, ///< a comment on the line after a value (only make sense for
538
+ /// root value)
539
+ numberOfCommentPlacement
540
+ };
364
541
 
365
542
  //# ifdef JSON_USE_CPPTL
366
543
  // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
367
544
  // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
368
545
  //# endif
369
546
 
370
- /** \brief Lightweight wrapper to tag static string.
371
- *
372
- * Value constructor and objectValue member assignement takes advantage of the
373
- * StaticString and avoid the cost of string duplication when storing the
374
- * string or the member name.
375
- *
376
- * Example of usage:
377
- * \code
378
- * Json::Value aValue( StaticString("some text") );
379
- * Json::Value object;
380
- * static const StaticString code("code");
381
- * object[code] = 1234;
382
- * \endcode
383
- */
384
- class JSON_API StaticString
385
- {
386
- public:
387
- explicit StaticString( const char *czstring )
388
- : str_( czstring )
389
- {
390
- }
391
-
392
- operator const char *() const
393
- {
394
- return str_;
395
- }
396
-
397
- const char *c_str() const
398
- {
399
- return str_;
400
- }
401
-
402
- private:
403
- const char *str_;
404
- };
405
-
406
- /** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
407
- *
408
- * This class is a discriminated union wrapper that can represents a:
409
- * - signed integer [range: Value::minInt - Value::maxInt]
410
- * - unsigned integer (range: 0 - Value::maxUInt)
411
- * - double
412
- * - UTF-8 string
413
- * - boolean
414
- * - 'null'
415
- * - an ordered list of Value
416
- * - collection of name/value pairs (javascript object)
417
- *
418
- * The type of the held value is represented by a #ValueType and
419
- * can be obtained using type().
420
- *
421
- * values of an #objectValue or #arrayValue can be accessed using operator[]() methods.
422
- * Non const methods will automatically create the a #nullValue element
423
- * if it does not exist.
424
- * The sequence of an #arrayValue will be automatically resize and initialized
425
- * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
426
- *
427
- * The get() methods can be used to obtanis default value in the case the required element
428
- * does not exist.
429
- *
430
- * It is possible to iterate over the list of a #objectValue values using
431
- * the getMemberNames() method.
432
- */
433
- class JSON_API Value
434
- {
435
- friend class ValueIteratorBase;
436
- # ifdef JSON_VALUE_USE_INTERNAL_MAP
437
- friend class ValueInternalLink;
438
- friend class ValueInternalMap;
439
- # endif
440
- public:
441
- typedef std::vector<std::string> Members;
442
- typedef ValueIterator iterator;
443
- typedef ValueConstIterator const_iterator;
444
- typedef Json::UInt UInt;
445
- typedef Json::Int Int;
446
- # if defined(JSON_HAS_INT64)
447
- typedef Json::UInt64 UInt64;
448
- typedef Json::Int64 Int64;
547
+ /** \brief Lightweight wrapper to tag static string.
548
+ *
549
+ * Value constructor and objectValue member assignement takes advantage of the
550
+ * StaticString and avoid the cost of string duplication when storing the
551
+ * string or the member name.
552
+ *
553
+ * Example of usage:
554
+ * \code
555
+ * Json::Value aValue( StaticString("some text") );
556
+ * Json::Value object;
557
+ * static const StaticString code("code");
558
+ * object[code] = 1234;
559
+ * \endcode
560
+ */
561
+ class JSON_API StaticString {
562
+ public:
563
+ explicit StaticString(const char* czstring) : c_str_(czstring) {}
564
+
565
+ operator const char*() const { return c_str_; }
566
+
567
+ const char* c_str() const { return c_str_; }
568
+
569
+ private:
570
+ const char* c_str_;
571
+ };
572
+
573
+ /** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
574
+ *
575
+ * This class is a discriminated union wrapper that can represents a:
576
+ * - signed integer [range: Value::minInt - Value::maxInt]
577
+ * - unsigned integer (range: 0 - Value::maxUInt)
578
+ * - double
579
+ * - UTF-8 string
580
+ * - boolean
581
+ * - 'null'
582
+ * - an ordered list of Value
583
+ * - collection of name/value pairs (javascript object)
584
+ *
585
+ * The type of the held value is represented by a #ValueType and
586
+ * can be obtained using type().
587
+ *
588
+ * Values of an #objectValue or #arrayValue can be accessed using operator[]()
589
+ * methods.
590
+ * Non-const methods will automatically create the a #nullValue element
591
+ * if it does not exist.
592
+ * The sequence of an #arrayValue will be automatically resized and initialized
593
+ * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
594
+ *
595
+ * The get() methods can be used to obtain default value in the case the
596
+ * required element does not exist.
597
+ *
598
+ * It is possible to iterate over the list of a #objectValue values using
599
+ * the getMemberNames() method.
600
+ *
601
+ * \note #Value string-length fit in size_t, but keys must be < 2^30.
602
+ * (The reason is an implementation detail.) A #CharReader will raise an
603
+ * exception if a bound is exceeded to avoid security holes in your app,
604
+ * but the Value API does *not* check bounds. That is the responsibility
605
+ * of the caller.
606
+ */
607
+ class JSON_API Value {
608
+ friend class ValueIteratorBase;
609
+ public:
610
+ typedef std::vector<JSONCPP_STRING> Members;
611
+ typedef ValueIterator iterator;
612
+ typedef ValueConstIterator const_iterator;
613
+ typedef Json::UInt UInt;
614
+ typedef Json::Int Int;
615
+ #if defined(JSON_HAS_INT64)
616
+ typedef Json::UInt64 UInt64;
617
+ typedef Json::Int64 Int64;
449
618
  #endif // defined(JSON_HAS_INT64)
450
- typedef Json::LargestInt LargestInt;
451
- typedef Json::LargestUInt LargestUInt;
452
- typedef Json::ArrayIndex ArrayIndex;
453
-
454
- static const Value null;
455
- /// Minimum signed integer value that can be stored in a Json::Value.
456
- static const LargestInt minLargestInt;
457
- /// Maximum signed integer value that can be stored in a Json::Value.
458
- static const LargestInt maxLargestInt;
459
- /// Maximum unsigned integer value that can be stored in a Json::Value.
460
- static const LargestUInt maxLargestUInt;
461
-
462
- /// Minimum signed int value that can be stored in a Json::Value.
463
- static const Int minInt;
464
- /// Maximum signed int value that can be stored in a Json::Value.
465
- static const Int maxInt;
466
- /// Maximum unsigned int value that can be stored in a Json::Value.
467
- static const UInt maxUInt;
468
-
469
- /// Minimum signed 64 bits int value that can be stored in a Json::Value.
470
- static const Int64 minInt64;
471
- /// Maximum signed 64 bits int value that can be stored in a Json::Value.
472
- static const Int64 maxInt64;
473
- /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
474
- static const UInt64 maxUInt64;
475
-
476
- private:
619
+ typedef Json::LargestInt LargestInt;
620
+ typedef Json::LargestUInt LargestUInt;
621
+ typedef Json::ArrayIndex ArrayIndex;
622
+
623
+ static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value().
624
+ static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null
625
+ static Value const& nullSingleton(); ///< Prefer this to null or nullRef.
626
+
627
+ /// Minimum signed integer value that can be stored in a Json::Value.
628
+ static const LargestInt minLargestInt;
629
+ /// Maximum signed integer value that can be stored in a Json::Value.
630
+ static const LargestInt maxLargestInt;
631
+ /// Maximum unsigned integer value that can be stored in a Json::Value.
632
+ static const LargestUInt maxLargestUInt;
633
+
634
+ /// Minimum signed int value that can be stored in a Json::Value.
635
+ static const Int minInt;
636
+ /// Maximum signed int value that can be stored in a Json::Value.
637
+ static const Int maxInt;
638
+ /// Maximum unsigned int value that can be stored in a Json::Value.
639
+ static const UInt maxUInt;
640
+
641
+ #if defined(JSON_HAS_INT64)
642
+ /// Minimum signed 64 bits int value that can be stored in a Json::Value.
643
+ static const Int64 minInt64;
644
+ /// Maximum signed 64 bits int value that can be stored in a Json::Value.
645
+ static const Int64 maxInt64;
646
+ /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
647
+ static const UInt64 maxUInt64;
648
+ #endif // defined(JSON_HAS_INT64)
649
+
650
+ private:
477
651
  #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
478
- # ifndef JSON_VALUE_USE_INTERNAL_MAP
479
- class CZString
480
- {
481
- public:
482
- enum DuplicationPolicy
483
- {
484
- noDuplication = 0,
485
- duplicate,
486
- duplicateOnCopy
487
- };
488
- CZString( ArrayIndex index );
489
- CZString( const char *cstr, DuplicationPolicy allocate );
490
- CZString( const CZString &other );
491
- ~CZString();
492
- CZString &operator =( const CZString &other );
493
- bool operator<( const CZString &other ) const;
494
- bool operator==( const CZString &other ) const;
495
- ArrayIndex index() const;
496
- const char *c_str() const;
497
- bool isStaticString() const;
498
- private:
499
- void swap( CZString &other );
500
- const char *cstr_;
501
- ArrayIndex index_;
502
- };
503
-
504
- public:
505
- # ifndef JSON_USE_CPPTL_SMALLMAP
506
- typedef std::map<CZString, Value> ObjectValues;
507
- # else
508
- typedef CppTL::SmallMap<CZString, Value> ObjectValues;
509
- # endif // ifndef JSON_USE_CPPTL_SMALLMAP
510
- # endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
652
+ class CZString {
653
+ public:
654
+ enum DuplicationPolicy {
655
+ noDuplication = 0,
656
+ duplicate,
657
+ duplicateOnCopy
658
+ };
659
+ CZString(ArrayIndex index);
660
+ CZString(char const* str, unsigned length, DuplicationPolicy allocate);
661
+ CZString(CZString const& other);
662
+ #if JSON_HAS_RVALUE_REFERENCES
663
+ CZString(CZString&& other);
664
+ #endif
665
+ ~CZString();
666
+ CZString& operator=(CZString other);
667
+ bool operator<(CZString const& other) const;
668
+ bool operator==(CZString const& other) const;
669
+ ArrayIndex index() const;
670
+ //const char* c_str() const; ///< \deprecated
671
+ char const* data() const;
672
+ unsigned length() const;
673
+ bool isStaticString() const;
674
+
675
+ private:
676
+ void swap(CZString& other);
677
+
678
+ struct StringStorage {
679
+ unsigned policy_: 2;
680
+ unsigned length_: 30; // 1GB max
681
+ };
682
+
683
+ char const* cstr_; // actually, a prefixed string, unless policy is noDup
684
+ union {
685
+ ArrayIndex index_;
686
+ StringStorage storage_;
687
+ };
688
+ };
689
+
690
+ public:
691
+ #ifndef JSON_USE_CPPTL_SMALLMAP
692
+ typedef std::map<CZString, Value> ObjectValues;
693
+ #else
694
+ typedef CppTL::SmallMap<CZString, Value> ObjectValues;
695
+ #endif // ifndef JSON_USE_CPPTL_SMALLMAP
511
696
  #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
512
697
 
513
- public:
514
- /** \brief Create a default Value of the given type.
515
-
516
- This is a very useful constructor.
517
- To create an empty array, pass arrayValue.
518
- To create an empty object, pass objectValue.
519
- Another Value can then be set to this one by assignment.
520
- This is useful since clear() and resize() will not alter types.
521
-
522
- Examples:
523
- \code
524
- Json::Value null_value; // null
525
- Json::Value arr_value(Json::arrayValue); // []
526
- Json::Value obj_value(Json::objectValue); // {}
527
- \endcode
528
- */
529
- Value( ValueType type = nullValue );
530
- Value( Int value );
531
- Value( UInt value );
698
+ public:
699
+ /** \brief Create a default Value of the given type.
700
+
701
+ This is a very useful constructor.
702
+ To create an empty array, pass arrayValue.
703
+ To create an empty object, pass objectValue.
704
+ Another Value can then be set to this one by assignment.
705
+ This is useful since clear() and resize() will not alter types.
706
+
707
+ Examples:
708
+ \code
709
+ Json::Value null_value; // null
710
+ Json::Value arr_value(Json::arrayValue); // []
711
+ Json::Value obj_value(Json::objectValue); // {}
712
+ \endcode
713
+ */
714
+ Value(ValueType type = nullValue);
715
+ Value(Int value);
716
+ Value(UInt value);
532
717
  #if defined(JSON_HAS_INT64)
533
- Value( Int64 value );
534
- Value( UInt64 value );
718
+ Value(Int64 value);
719
+ Value(UInt64 value);
535
720
  #endif // if defined(JSON_HAS_INT64)
536
- Value( double value );
537
- Value( const char *value );
538
- Value( const char *beginValue, const char *endValue );
539
- /** \brief Constructs a value from a static string.
540
-
541
- * Like other value string constructor but do not duplicate the string for
542
- * internal storage. The given string must remain alive after the call to this
543
- * constructor.
544
- * Example of usage:
545
- * \code
546
- * Json::Value aValue( StaticString("some text") );
547
- * \endcode
548
- */
549
- Value( const StaticString &value );
550
- Value( const std::string &value );
551
- # ifdef JSON_USE_CPPTL
552
- Value( const CppTL::ConstString &value );
553
- # endif
554
- Value( bool value );
555
- Value( const Value &other );
556
- virtual ~Value();
557
-
558
- Value &operator=( const Value &other );
559
- /// Swap values.
560
- /// \note Currently, comments are intentionally not swapped, for
561
- /// both logic and efficiency.
562
- void swap( Value &other );
563
-
564
- ValueType type() const;
721
+ Value(double value);
722
+ Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)
723
+ Value(const char* begin, const char* end); ///< Copy all, incl zeroes.
724
+ /** \brief Constructs a value from a static string.
725
+
726
+ * Like other value string constructor but do not duplicate the string for
727
+ * internal storage. The given string must remain alive after the call to this
728
+ * constructor.
729
+ * \note This works only for null-terminated strings. (We cannot change the
730
+ * size of this class, so we have nowhere to store the length,
731
+ * which might be computed later for various operations.)
732
+ *
733
+ * Example of usage:
734
+ * \code
735
+ * static StaticString foo("some text");
736
+ * Json::Value aValue(foo);
737
+ * \endcode
738
+ */
739
+ Value(const StaticString& value);
740
+ Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded zeroes too.
741
+ #ifdef JSON_USE_CPPTL
742
+ Value(const CppTL::ConstString& value);
743
+ #endif
744
+ Value(bool value);
745
+ /// Deep copy.
746
+ Value(const Value& other);
747
+ #if JSON_HAS_RVALUE_REFERENCES
748
+ /// Move constructor
749
+ Value(Value&& other);
750
+ #endif
751
+ virtual ~Value();
752
+
753
+ /// Deep copy, then swap(other).
754
+ /// \note Over-write existing comments. To preserve comments, use #swapPayload().
755
+ Value& operator=(Value other);
756
+ /// Swap everything.
757
+ void swap(Value& other);
758
+ /// Swap values but leave comments and source offsets in place.
759
+ void swapPayload(Value& other);
760
+
761
+ ValueType type() const;
762
+
763
+ /// Compare payload only, not comments etc.
764
+ bool operator<(const Value& other) const;
765
+ bool operator<=(const Value& other) const;
766
+ bool operator>=(const Value& other) const;
767
+ bool operator>(const Value& other) const;
768
+ bool operator==(const Value& other) const;
769
+ bool operator!=(const Value& other) const;
770
+ int compare(const Value& other) const;
771
+
772
+ const char* asCString() const; ///< Embedded zeroes could cause you trouble!
773
+ #if JSONCPP_USING_SECURE_MEMORY
774
+ unsigned getCStringLength() const; //Allows you to understand the length of the CString
775
+ #endif
776
+ JSONCPP_STRING asString() const; ///< Embedded zeroes are possible.
777
+ /** Get raw char* of string-value.
778
+ * \return false if !string. (Seg-fault if str or end are NULL.)
779
+ */
780
+ bool getString(
781
+ char const** begin, char const** end) const;
782
+ #ifdef JSON_USE_CPPTL
783
+ CppTL::ConstString asConstString() const;
784
+ #endif
785
+ Int asInt() const;
786
+ UInt asUInt() const;
787
+ #if defined(JSON_HAS_INT64)
788
+ Int64 asInt64() const;
789
+ UInt64 asUInt64() const;
790
+ #endif // if defined(JSON_HAS_INT64)
791
+ LargestInt asLargestInt() const;
792
+ LargestUInt asLargestUInt() const;
793
+ float asFloat() const;
794
+ double asDouble() const;
795
+ bool asBool() const;
796
+
797
+ bool isNull() const;
798
+ bool isBool() const;
799
+ bool isInt() const;
800
+ bool isInt64() const;
801
+ bool isUInt() const;
802
+ bool isUInt64() const;
803
+ bool isIntegral() const;
804
+ bool isDouble() const;
805
+ bool isNumeric() const;
806
+ bool isString() const;
807
+ bool isArray() const;
808
+ bool isObject() const;
809
+
810
+ bool isConvertibleTo(ValueType other) const;
811
+
812
+ /// Number of values in array or object
813
+ ArrayIndex size() const;
814
+
815
+ /// \brief Return true if empty array, empty object, or null;
816
+ /// otherwise, false.
817
+ bool empty() const;
818
+
819
+ /// Return isNull()
820
+ bool operator!() const;
821
+
822
+ /// Remove all object members and array elements.
823
+ /// \pre type() is arrayValue, objectValue, or nullValue
824
+ /// \post type() is unchanged
825
+ void clear();
826
+
827
+ /// Resize the array to size elements.
828
+ /// New elements are initialized to null.
829
+ /// May only be called on nullValue or arrayValue.
830
+ /// \pre type() is arrayValue or nullValue
831
+ /// \post type() is arrayValue
832
+ void resize(ArrayIndex size);
833
+
834
+ /// Access an array element (zero based index ).
835
+ /// If the array contains less than index element, then null value are
836
+ /// inserted
837
+ /// in the array so that its size is index+1.
838
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
839
+ /// this from the operator[] which takes a string.)
840
+ Value& operator[](ArrayIndex index);
841
+
842
+ /// Access an array element (zero based index ).
843
+ /// If the array contains less than index element, then null value are
844
+ /// inserted
845
+ /// in the array so that its size is index+1.
846
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
847
+ /// this from the operator[] which takes a string.)
848
+ Value& operator[](int index);
849
+
850
+ /// Access an array element (zero based index )
851
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
852
+ /// this from the operator[] which takes a string.)
853
+ const Value& operator[](ArrayIndex index) const;
854
+
855
+ /// Access an array element (zero based index )
856
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
857
+ /// this from the operator[] which takes a string.)
858
+ const Value& operator[](int index) const;
859
+
860
+ /// If the array contains at least index+1 elements, returns the element
861
+ /// value,
862
+ /// otherwise returns defaultValue.
863
+ Value get(ArrayIndex index, const Value& defaultValue) const;
864
+ /// Return true if index < size().
865
+ bool isValidIndex(ArrayIndex index) const;
866
+ /// \brief Append value to array at the end.
867
+ ///
868
+ /// Equivalent to jsonvalue[jsonvalue.size()] = value;
869
+ Value& append(const Value& value);
870
+
871
+ /// Access an object value by name, create a null member if it does not exist.
872
+ /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
873
+ /// Exceeding that will cause an exception.
874
+ Value& operator[](const char* key);
875
+ /// Access an object value by name, returns null if there is no member with
876
+ /// that name.
877
+ const Value& operator[](const char* key) const;
878
+ /// Access an object value by name, create a null member if it does not exist.
879
+ /// \param key may contain embedded nulls.
880
+ Value& operator[](const JSONCPP_STRING& key);
881
+ /// Access an object value by name, returns null if there is no member with
882
+ /// that name.
883
+ /// \param key may contain embedded nulls.
884
+ const Value& operator[](const JSONCPP_STRING& key) const;
885
+ /** \brief Access an object value by name, create a null member if it does not
886
+ exist.
887
+
888
+ * If the object has no entry for that name, then the member name used to store
889
+ * the new entry is not duplicated.
890
+ * Example of use:
891
+ * \code
892
+ * Json::Value object;
893
+ * static const StaticString code("code");
894
+ * object[code] = 1234;
895
+ * \endcode
896
+ */
897
+ Value& operator[](const StaticString& key);
898
+ #ifdef JSON_USE_CPPTL
899
+ /// Access an object value by name, create a null member if it does not exist.
900
+ Value& operator[](const CppTL::ConstString& key);
901
+ /// Access an object value by name, returns null if there is no member with
902
+ /// that name.
903
+ const Value& operator[](const CppTL::ConstString& key) const;
904
+ #endif
905
+ /// Return the member named key if it exist, defaultValue otherwise.
906
+ /// \note deep copy
907
+ Value get(const char* key, const Value& defaultValue) const;
908
+ /// Return the member named key if it exist, defaultValue otherwise.
909
+ /// \note deep copy
910
+ /// \note key may contain embedded nulls.
911
+ Value get(const char* begin, const char* end, const Value& defaultValue) const;
912
+ /// Return the member named key if it exist, defaultValue otherwise.
913
+ /// \note deep copy
914
+ /// \param key may contain embedded nulls.
915
+ Value get(const JSONCPP_STRING& key, const Value& defaultValue) const;
916
+ #ifdef JSON_USE_CPPTL
917
+ /// Return the member named key if it exist, defaultValue otherwise.
918
+ /// \note deep copy
919
+ Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
920
+ #endif
921
+ /// Most general and efficient version of isMember()const, get()const,
922
+ /// and operator[]const
923
+ /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
924
+ Value const* find(char const* begin, char const* end) const;
925
+ /// Most general and efficient version of object-mutators.
926
+ /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
927
+ /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
928
+ Value const* demand(char const* begin, char const* end);
929
+ /// \brief Remove and return the named member.
930
+ ///
931
+ /// Do nothing if it did not exist.
932
+ /// \return the removed Value, or null.
933
+ /// \pre type() is objectValue or nullValue
934
+ /// \post type() is unchanged
935
+ /// \deprecated
936
+ Value removeMember(const char* key);
937
+ /// Same as removeMember(const char*)
938
+ /// \param key may contain embedded nulls.
939
+ /// \deprecated
940
+ Value removeMember(const JSONCPP_STRING& key);
941
+ /// Same as removeMember(const char* begin, const char* end, Value* removed),
942
+ /// but 'key' is null-terminated.
943
+ bool removeMember(const char* key, Value* removed);
944
+ /** \brief Remove the named map member.
945
+
946
+ Update 'removed' iff removed.
947
+ \param key may contain embedded nulls.
948
+ \return true iff removed (no exceptions)
949
+ */
950
+ bool removeMember(JSONCPP_STRING const& key, Value* removed);
951
+ /// Same as removeMember(JSONCPP_STRING const& key, Value* removed)
952
+ bool removeMember(const char* begin, const char* end, Value* removed);
953
+ /** \brief Remove the indexed array element.
954
+
955
+ O(n) expensive operations.
956
+ Update 'removed' iff removed.
957
+ \return true iff removed (no exceptions)
958
+ */
959
+ bool removeIndex(ArrayIndex i, Value* removed);
960
+
961
+ /// Return true if the object has a member named key.
962
+ /// \note 'key' must be null-terminated.
963
+ bool isMember(const char* key) const;
964
+ /// Return true if the object has a member named key.
965
+ /// \param key may contain embedded nulls.
966
+ bool isMember(const JSONCPP_STRING& key) const;
967
+ /// Same as isMember(JSONCPP_STRING const& key)const
968
+ bool isMember(const char* begin, const char* end) const;
969
+ #ifdef JSON_USE_CPPTL
970
+ /// Return true if the object has a member named key.
971
+ bool isMember(const CppTL::ConstString& key) const;
972
+ #endif
565
973
 
566
- bool operator <( const Value &other ) const;
567
- bool operator <=( const Value &other ) const;
568
- bool operator >=( const Value &other ) const;
569
- bool operator >( const Value &other ) const;
974
+ /// \brief Return a list of the member names.
975
+ ///
976
+ /// If null, return an empty list.
977
+ /// \pre type() is objectValue or nullValue
978
+ /// \post if type() was nullValue, it remains nullValue
979
+ Members getMemberNames() const;
980
+
981
+ //# ifdef JSON_USE_CPPTL
982
+ // EnumMemberNames enumMemberNames() const;
983
+ // EnumValues enumValues() const;
984
+ //# endif
985
+
986
+ /// \deprecated Always pass len.
987
+ JSONCPP_DEPRECATED("Use setComment(JSONCPP_STRING const&) instead.")
988
+ void setComment(const char* comment, CommentPlacement placement);
989
+ /// Comments must be //... or /* ... */
990
+ void setComment(const char* comment, size_t len, CommentPlacement placement);
991
+ /// Comments must be //... or /* ... */
992
+ void setComment(const JSONCPP_STRING& comment, CommentPlacement placement);
993
+ bool hasComment(CommentPlacement placement) const;
994
+ /// Include delimiters and embedded newlines.
995
+ JSONCPP_STRING getComment(CommentPlacement placement) const;
996
+
997
+ JSONCPP_STRING toStyledString() const;
998
+
999
+ const_iterator begin() const;
1000
+ const_iterator end() const;
1001
+
1002
+ iterator begin();
1003
+ iterator end();
1004
+
1005
+ // Accessors for the [start, limit) range of bytes within the JSON text from
1006
+ // which this value was parsed, if any.
1007
+ void setOffsetStart(ptrdiff_t start);
1008
+ void setOffsetLimit(ptrdiff_t limit);
1009
+ ptrdiff_t getOffsetStart() const;
1010
+ ptrdiff_t getOffsetLimit() const;
1011
+
1012
+ private:
1013
+ void initBasic(ValueType type, bool allocated = false);
1014
+
1015
+ Value& resolveReference(const char* key);
1016
+ Value& resolveReference(const char* key, const char* end);
1017
+
1018
+ struct CommentInfo {
1019
+ CommentInfo();
1020
+ ~CommentInfo();
1021
+
1022
+ void setComment(const char* text, size_t len);
1023
+
1024
+ char* comment_;
1025
+ };
1026
+
1027
+ // struct MemberNamesTransform
1028
+ //{
1029
+ // typedef const char *result_type;
1030
+ // const char *operator()( const CZString &name ) const
1031
+ // {
1032
+ // return name.c_str();
1033
+ // }
1034
+ //};
1035
+
1036
+ union ValueHolder {
1037
+ LargestInt int_;
1038
+ LargestUInt uint_;
1039
+ double real_;
1040
+ bool bool_;
1041
+ char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
1042
+ ObjectValues* map_;
1043
+ } value_;
1044
+ ValueType type_ : 8;
1045
+ unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
1046
+ // If not allocated_, string_ must be null-terminated.
1047
+ CommentInfo* comments_;
1048
+
1049
+ // [start, limit) byte offsets in the source JSON text from which this Value
1050
+ // was extracted.
1051
+ ptrdiff_t start_;
1052
+ ptrdiff_t limit_;
1053
+ };
570
1054
 
571
- bool operator ==( const Value &other ) const;
572
- bool operator !=( const Value &other ) const;
1055
+ /** \brief Experimental and untested: represents an element of the "path" to
1056
+ * access a node.
1057
+ */
1058
+ class JSON_API PathArgument {
1059
+ public:
1060
+ friend class Path;
1061
+
1062
+ PathArgument();
1063
+ PathArgument(ArrayIndex index);
1064
+ PathArgument(const char* key);
1065
+ PathArgument(const JSONCPP_STRING& key);
1066
+
1067
+ private:
1068
+ enum Kind {
1069
+ kindNone = 0,
1070
+ kindIndex,
1071
+ kindKey
1072
+ };
1073
+ JSONCPP_STRING key_;
1074
+ ArrayIndex index_;
1075
+ Kind kind_;
1076
+ };
573
1077
 
574
- int compare( const Value &other ) const;
1078
+ /** \brief Experimental and untested: represents a "path" to access a node.
1079
+ *
1080
+ * Syntax:
1081
+ * - "." => root node
1082
+ * - ".[n]" => elements at index 'n' of root node (an array value)
1083
+ * - ".name" => member named 'name' of root node (an object value)
1084
+ * - ".name1.name2.name3"
1085
+ * - ".[0][1][2].name1[3]"
1086
+ * - ".%" => member name is provided as parameter
1087
+ * - ".[%]" => index is provied as parameter
1088
+ */
1089
+ class JSON_API Path {
1090
+ public:
1091
+ Path(const JSONCPP_STRING& path,
1092
+ const PathArgument& a1 = PathArgument(),
1093
+ const PathArgument& a2 = PathArgument(),
1094
+ const PathArgument& a3 = PathArgument(),
1095
+ const PathArgument& a4 = PathArgument(),
1096
+ const PathArgument& a5 = PathArgument());
1097
+
1098
+ const Value& resolve(const Value& root) const;
1099
+ Value resolve(const Value& root, const Value& defaultValue) const;
1100
+ /// Creates the "path" to access the specified node and returns a reference on
1101
+ /// the node.
1102
+ Value& make(Value& root) const;
1103
+
1104
+ private:
1105
+ typedef std::vector<const PathArgument*> InArgs;
1106
+ typedef std::vector<PathArgument> Args;
1107
+
1108
+ void makePath(const JSONCPP_STRING& path, const InArgs& in);
1109
+ void addPathInArg(const JSONCPP_STRING& path,
1110
+ const InArgs& in,
1111
+ InArgs::const_iterator& itInArg,
1112
+ PathArgument::Kind kind);
1113
+ void invalidPath(const JSONCPP_STRING& path, int location);
1114
+
1115
+ Args args_;
1116
+ };
575
1117
 
576
- const char *asCString() const;
577
- std::string asString() const;
578
- # ifdef JSON_USE_CPPTL
579
- CppTL::ConstString asConstString() const;
580
- # endif
581
- Int asInt() const;
582
- UInt asUInt() const;
583
- Int64 asInt64() const;
584
- UInt64 asUInt64() const;
585
- LargestInt asLargestInt() const;
586
- LargestUInt asLargestUInt() const;
587
- float asFloat() const;
588
- double asDouble() const;
589
- bool asBool() const;
590
-
591
- bool isNull() const;
592
- bool isBool() const;
593
- bool isInt() const;
594
- bool isUInt() const;
595
- bool isIntegral() const;
596
- bool isDouble() const;
597
- bool isNumeric() const;
598
- bool isString() const;
599
- bool isArray() const;
600
- bool isObject() const;
601
-
602
- bool isConvertibleTo( ValueType other ) const;
603
-
604
- /// Number of values in array or object
605
- ArrayIndex size() const;
606
-
607
- /// \brief Return true if empty array, empty object, or null;
608
- /// otherwise, false.
609
- bool empty() const;
610
-
611
- /// Return isNull()
612
- bool operator!() const;
613
-
614
- /// Remove all object members and array elements.
615
- /// \pre type() is arrayValue, objectValue, or nullValue
616
- /// \post type() is unchanged
617
- void clear();
618
-
619
- /// Resize the array to size elements.
620
- /// New elements are initialized to null.
621
- /// May only be called on nullValue or arrayValue.
622
- /// \pre type() is arrayValue or nullValue
623
- /// \post type() is arrayValue
624
- void resize( ArrayIndex size );
625
-
626
- /// Access an array element (zero based index ).
627
- /// If the array contains less than index element, then null value are inserted
628
- /// in the array so that its size is index+1.
629
- /// (You may need to say 'value[0u]' to get your compiler to distinguish
630
- /// this from the operator[] which takes a string.)
631
- Value &operator[]( ArrayIndex index );
632
-
633
- /// Access an array element (zero based index ).
634
- /// If the array contains less than index element, then null value are inserted
635
- /// in the array so that its size is index+1.
636
- /// (You may need to say 'value[0u]' to get your compiler to distinguish
637
- /// this from the operator[] which takes a string.)
638
- Value &operator[]( int index );
639
-
640
- /// Access an array element (zero based index )
641
- /// (You may need to say 'value[0u]' to get your compiler to distinguish
642
- /// this from the operator[] which takes a string.)
643
- const Value &operator[]( ArrayIndex index ) const;
644
-
645
- /// Access an array element (zero based index )
646
- /// (You may need to say 'value[0u]' to get your compiler to distinguish
647
- /// this from the operator[] which takes a string.)
648
- const Value &operator[]( int index ) const;
649
-
650
- /// If the array contains at least index+1 elements, returns the element value,
651
- /// otherwise returns defaultValue.
652
- Value get( ArrayIndex index,
653
- const Value &defaultValue ) const;
654
- /// Return true if index < size().
655
- bool isValidIndex( ArrayIndex index ) const;
656
- /// \brief Append value to array at the end.
657
- ///
658
- /// Equivalent to jsonvalue[jsonvalue.size()] = value;
659
- Value &append( const Value &value );
660
-
661
- /// Access an object value by name, create a null member if it does not exist.
662
- Value &operator[]( const char *key );
663
- /// Access an object value by name, returns null if there is no member with that name.
664
- const Value &operator[]( const char *key ) const;
665
- /// Access an object value by name, create a null member if it does not exist.
666
- Value &operator[]( const std::string &key );
667
- /// Access an object value by name, returns null if there is no member with that name.
668
- const Value &operator[]( const std::string &key ) const;
669
- /** \brief Access an object value by name, create a null member if it does not exist.
670
-
671
- * If the object as no entry for that name, then the member name used to store
672
- * the new entry is not duplicated.
673
- * Example of use:
674
- * \code
675
- * Json::Value object;
676
- * static const StaticString code("code");
677
- * object[code] = 1234;
678
- * \endcode
679
- */
680
- Value &operator[]( const StaticString &key );
681
- # ifdef JSON_USE_CPPTL
682
- /// Access an object value by name, create a null member if it does not exist.
683
- Value &operator[]( const CppTL::ConstString &key );
684
- /// Access an object value by name, returns null if there is no member with that name.
685
- const Value &operator[]( const CppTL::ConstString &key ) const;
686
- # endif
687
- /// Return the member named key if it exist, defaultValue otherwise.
688
- Value get( const char *key,
689
- const Value &defaultValue ) const;
690
- /// Return the member named key if it exist, defaultValue otherwise.
691
- Value get( const std::string &key,
692
- const Value &defaultValue ) const;
693
- # ifdef JSON_USE_CPPTL
694
- /// Return the member named key if it exist, defaultValue otherwise.
695
- Value get( const CppTL::ConstString &key,
696
- const Value &defaultValue ) const;
697
- # endif
698
- /// \brief Remove and return the named member.
699
- ///
700
- /// Do nothing if it did not exist.
701
- /// \return the removed Value, or null.
702
- /// \pre type() is objectValue or nullValue
703
- /// \post type() is unchanged
704
- Value removeMember( const char* key );
705
- /// Same as removeMember(const char*)
706
- Value removeMember( const std::string &key );
707
-
708
- /// Return true if the object has a member named key.
709
- bool isMember( const char *key ) const;
710
- /// Return true if the object has a member named key.
711
- bool isMember( const std::string &key ) const;
712
- # ifdef JSON_USE_CPPTL
713
- /// Return true if the object has a member named key.
714
- bool isMember( const CppTL::ConstString &key ) const;
715
- # endif
1118
+ /** \brief base class for Value iterators.
1119
+ *
1120
+ */
1121
+ class JSON_API ValueIteratorBase {
1122
+ public:
1123
+ typedef std::bidirectional_iterator_tag iterator_category;
1124
+ typedef unsigned int size_t;
1125
+ typedef int difference_type;
1126
+ typedef ValueIteratorBase SelfType;
716
1127
 
717
- /// \brief Return a list of the member names.
718
- ///
719
- /// If null, return an empty list.
720
- /// \pre type() is objectValue or nullValue
721
- /// \post if type() was nullValue, it remains nullValue
722
- Members getMemberNames() const;
1128
+ bool operator==(const SelfType& other) const { return isEqual(other); }
723
1129
 
724
- //# ifdef JSON_USE_CPPTL
725
- // EnumMemberNames enumMemberNames() const;
726
- // EnumValues enumValues() const;
727
- //# endif
1130
+ bool operator!=(const SelfType& other) const { return !isEqual(other); }
728
1131
 
729
- /// Comments must be //... or /* ... */
730
- void setComment( const char *comment,
731
- CommentPlacement placement );
732
- /// Comments must be //... or /* ... */
733
- void setComment( const std::string &comment,
734
- CommentPlacement placement );
735
- bool hasComment( CommentPlacement placement ) const;
736
- /// Include delimiters and embedded newlines.
737
- std::string getComment( CommentPlacement placement ) const;
738
-
739
- std::string toStyledString() const;
740
-
741
- const_iterator begin() const;
742
- const_iterator end() const;
743
-
744
- iterator begin();
745
- iterator end();
746
-
747
- private:
748
- Value &resolveReference( const char *key,
749
- bool isStatic );
750
-
751
- # ifdef JSON_VALUE_USE_INTERNAL_MAP
752
- inline bool isItemAvailable() const
753
- {
754
- return itemIsUsed_ == 0;
755
- }
756
-
757
- inline void setItemUsed( bool isUsed = true )
758
- {
759
- itemIsUsed_ = isUsed ? 1 : 0;
760
- }
761
-
762
- inline bool isMemberNameStatic() const
763
- {
764
- return memberNameIsStatic_ == 0;
765
- }
766
-
767
- inline void setMemberNameIsStatic( bool isStatic )
768
- {
769
- memberNameIsStatic_ = isStatic ? 1 : 0;
770
- }
771
- # endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
772
-
773
- private:
774
- struct CommentInfo
775
- {
776
- CommentInfo();
777
- ~CommentInfo();
778
-
779
- void setComment( const char *text );
780
-
781
- char *comment_;
782
- };
783
-
784
- //struct MemberNamesTransform
785
- //{
786
- // typedef const char *result_type;
787
- // const char *operator()( const CZString &name ) const
788
- // {
789
- // return name.c_str();
790
- // }
791
- //};
792
-
793
- union ValueHolder
794
- {
795
- LargestInt int_;
796
- LargestUInt uint_;
797
- double real_;
798
- bool bool_;
799
- char *string_;
800
- # ifdef JSON_VALUE_USE_INTERNAL_MAP
801
- ValueInternalArray *array_;
802
- ValueInternalMap *map_;
803
- #else
804
- ObjectValues *map_;
805
- # endif
806
- } value_;
807
- ValueType type_ : 8;
808
- int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
809
- # ifdef JSON_VALUE_USE_INTERNAL_MAP
810
- unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
811
- int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
812
- # endif
813
- CommentInfo *comments_;
814
- };
1132
+ difference_type operator-(const SelfType& other) const {
1133
+ return other.computeDistance(*this);
1134
+ }
815
1135
 
1136
+ /// Return either the index or the member name of the referenced value as a
1137
+ /// Value.
1138
+ Value key() const;
816
1139
 
817
- /** \brief Experimental and untested: represents an element of the "path" to access a node.
818
- */
819
- class PathArgument
820
- {
821
- public:
822
- friend class Path;
823
-
824
- PathArgument();
825
- PathArgument( ArrayIndex index );
826
- PathArgument( const char *key );
827
- PathArgument( const std::string &key );
828
-
829
- private:
830
- enum Kind
831
- {
832
- kindNone = 0,
833
- kindIndex,
834
- kindKey
835
- };
836
- std::string key_;
837
- ArrayIndex index_;
838
- Kind kind_;
839
- };
840
-
841
- /** \brief Experimental and untested: represents a "path" to access a node.
842
- *
843
- * Syntax:
844
- * - "." => root node
845
- * - ".[n]" => elements at index 'n' of root node (an array value)
846
- * - ".name" => member named 'name' of root node (an object value)
847
- * - ".name1.name2.name3"
848
- * - ".[0][1][2].name1[3]"
849
- * - ".%" => member name is provided as parameter
850
- * - ".[%]" => index is provied as parameter
851
- */
852
- class Path
853
- {
854
- public:
855
- Path( const std::string &path,
856
- const PathArgument &a1 = PathArgument(),
857
- const PathArgument &a2 = PathArgument(),
858
- const PathArgument &a3 = PathArgument(),
859
- const PathArgument &a4 = PathArgument(),
860
- const PathArgument &a5 = PathArgument() );
861
-
862
- const Value &resolve( const Value &root ) const;
863
- Value resolve( const Value &root,
864
- const Value &defaultValue ) const;
865
- /// Creates the "path" to access the specified node and returns a reference on the node.
866
- Value &make( Value &root ) const;
867
-
868
- private:
869
- typedef std::vector<const PathArgument *> InArgs;
870
- typedef std::vector<PathArgument> Args;
871
-
872
- void makePath( const std::string &path,
873
- const InArgs &in );
874
- void addPathInArg( const std::string &path,
875
- const InArgs &in,
876
- InArgs::const_iterator &itInArg,
877
- PathArgument::Kind kind );
878
- void invalidPath( const std::string &path,
879
- int location );
880
-
881
- Args args_;
882
- };
883
-
884
-
885
-
886
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
887
- /** \brief Allocator to customize Value internal map.
888
- * Below is an example of a simple implementation (default implementation actually
889
- * use memory pool for speed).
890
- * \code
891
- class DefaultValueMapAllocator : public ValueMapAllocator
892
- {
893
- public: // overridden from ValueMapAllocator
894
- virtual ValueInternalMap *newMap()
895
- {
896
- return new ValueInternalMap();
897
- }
898
-
899
- virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other )
900
- {
901
- return new ValueInternalMap( other );
902
- }
903
-
904
- virtual void destructMap( ValueInternalMap *map )
905
- {
906
- delete map;
907
- }
908
-
909
- virtual ValueInternalLink *allocateMapBuckets( unsigned int size )
910
- {
911
- return new ValueInternalLink[size];
912
- }
913
-
914
- virtual void releaseMapBuckets( ValueInternalLink *links )
915
- {
916
- delete [] links;
917
- }
918
-
919
- virtual ValueInternalLink *allocateMapLink()
920
- {
921
- return new ValueInternalLink();
922
- }
923
-
924
- virtual void releaseMapLink( ValueInternalLink *link )
925
- {
926
- delete link;
927
- }
928
- };
929
- * \endcode
930
- */
931
- class JSON_API ValueMapAllocator
932
- {
933
- public:
934
- virtual ~ValueMapAllocator();
935
- virtual ValueInternalMap *newMap() = 0;
936
- virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0;
937
- virtual void destructMap( ValueInternalMap *map ) = 0;
938
- virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0;
939
- virtual void releaseMapBuckets( ValueInternalLink *links ) = 0;
940
- virtual ValueInternalLink *allocateMapLink() = 0;
941
- virtual void releaseMapLink( ValueInternalLink *link ) = 0;
942
- };
943
-
944
- /** \brief ValueInternalMap hash-map bucket chain link (for internal use only).
945
- * \internal previous_ & next_ allows for bidirectional traversal.
946
- */
947
- class JSON_API ValueInternalLink
948
- {
949
- public:
950
- enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture.
951
- enum InternalFlags {
952
- flagAvailable = 0,
953
- flagUsed = 1
954
- };
955
-
956
- ValueInternalLink();
957
-
958
- ~ValueInternalLink();
959
-
960
- Value items_[itemPerLink];
961
- char *keys_[itemPerLink];
962
- ValueInternalLink *previous_;
963
- ValueInternalLink *next_;
964
- };
965
-
966
-
967
- /** \brief A linked page based hash-table implementation used internally by Value.
968
- * \internal ValueInternalMap is a tradional bucket based hash-table, with a linked
969
- * list in each bucket to handle collision. There is an addional twist in that
970
- * each node of the collision linked list is a page containing a fixed amount of
971
- * value. This provides a better compromise between memory usage and speed.
972
- *
973
- * Each bucket is made up of a chained list of ValueInternalLink. The last
974
- * link of a given bucket can be found in the 'previous_' field of the following bucket.
975
- * The last link of the last bucket is stored in tailLink_ as it has no following bucket.
976
- * Only the last link of a bucket may contains 'available' item. The last link always
977
- * contains at least one element unless is it the bucket one very first link.
978
- */
979
- class JSON_API ValueInternalMap
980
- {
981
- friend class ValueIteratorBase;
982
- friend class Value;
983
- public:
984
- typedef unsigned int HashKey;
985
- typedef unsigned int BucketIndex;
986
-
987
- # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
988
- struct IteratorState
989
- {
990
- IteratorState()
991
- : map_(0)
992
- , link_(0)
993
- , itemIndex_(0)
994
- , bucketIndex_(0)
995
- {
996
- }
997
- ValueInternalMap *map_;
998
- ValueInternalLink *link_;
999
- BucketIndex itemIndex_;
1000
- BucketIndex bucketIndex_;
1001
- };
1002
- # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1003
-
1004
- ValueInternalMap();
1005
- ValueInternalMap( const ValueInternalMap &other );
1006
- ValueInternalMap &operator =( const ValueInternalMap &other );
1007
- ~ValueInternalMap();
1008
-
1009
- void swap( ValueInternalMap &other );
1010
-
1011
- BucketIndex size() const;
1012
-
1013
- void clear();
1014
-
1015
- bool reserveDelta( BucketIndex growth );
1016
-
1017
- bool reserve( BucketIndex newItemCount );
1018
-
1019
- const Value *find( const char *key ) const;
1020
-
1021
- Value *find( const char *key );
1022
-
1023
- Value &resolveReference( const char *key,
1024
- bool isStatic );
1025
-
1026
- void remove( const char *key );
1027
-
1028
- void doActualRemove( ValueInternalLink *link,
1029
- BucketIndex index,
1030
- BucketIndex bucketIndex );
1031
-
1032
- ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex );
1033
-
1034
- Value &setNewItem( const char *key,
1035
- bool isStatic,
1036
- ValueInternalLink *link,
1037
- BucketIndex index );
1038
-
1039
- Value &unsafeAdd( const char *key,
1040
- bool isStatic,
1041
- HashKey hashedKey );
1042
-
1043
- HashKey hash( const char *key ) const;
1044
-
1045
- int compare( const ValueInternalMap &other ) const;
1046
-
1047
- private:
1048
- void makeBeginIterator( IteratorState &it ) const;
1049
- void makeEndIterator( IteratorState &it ) const;
1050
- static bool equals( const IteratorState &x, const IteratorState &other );
1051
- static void increment( IteratorState &iterator );
1052
- static void incrementBucket( IteratorState &iterator );
1053
- static void decrement( IteratorState &iterator );
1054
- static const char *key( const IteratorState &iterator );
1055
- static const char *key( const IteratorState &iterator, bool &isStatic );
1056
- static Value &value( const IteratorState &iterator );
1057
- static int distance( const IteratorState &x, const IteratorState &y );
1058
-
1059
- private:
1060
- ValueInternalLink *buckets_;
1061
- ValueInternalLink *tailLink_;
1062
- BucketIndex bucketsSize_;
1063
- BucketIndex itemCount_;
1064
- };
1065
-
1066
- /** \brief A simplified deque implementation used internally by Value.
1067
- * \internal
1068
- * It is based on a list of fixed "page", each page contains a fixed number of items.
1069
- * Instead of using a linked-list, a array of pointer is used for fast item look-up.
1070
- * Look-up for an element is as follow:
1071
- * - compute page index: pageIndex = itemIndex / itemsPerPage
1072
- * - look-up item in page: pages_[pageIndex][itemIndex % itemsPerPage]
1073
- *
1074
- * Insertion is amortized constant time (only the array containing the index of pointers
1075
- * need to be reallocated when items are appended).
1076
- */
1077
- class JSON_API ValueInternalArray
1078
- {
1079
- friend class Value;
1080
- friend class ValueIteratorBase;
1081
- public:
1082
- enum { itemsPerPage = 8 }; // should be a power of 2 for fast divide and modulo.
1083
- typedef Value::ArrayIndex ArrayIndex;
1084
- typedef unsigned int PageIndex;
1085
-
1086
- # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1087
- struct IteratorState // Must be a POD
1088
- {
1089
- IteratorState()
1090
- : array_(0)
1091
- , currentPageIndex_(0)
1092
- , currentItemIndex_(0)
1093
- {
1094
- }
1095
- ValueInternalArray *array_;
1096
- Value **currentPageIndex_;
1097
- unsigned int currentItemIndex_;
1098
- };
1099
- # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1100
-
1101
- ValueInternalArray();
1102
- ValueInternalArray( const ValueInternalArray &other );
1103
- ValueInternalArray &operator =( const ValueInternalArray &other );
1104
- ~ValueInternalArray();
1105
- void swap( ValueInternalArray &other );
1106
-
1107
- void clear();
1108
- void resize( ArrayIndex newSize );
1109
-
1110
- Value &resolveReference( ArrayIndex index );
1111
-
1112
- Value *find( ArrayIndex index ) const;
1113
-
1114
- ArrayIndex size() const;
1115
-
1116
- int compare( const ValueInternalArray &other ) const;
1117
-
1118
- private:
1119
- static bool equals( const IteratorState &x, const IteratorState &other );
1120
- static void increment( IteratorState &iterator );
1121
- static void decrement( IteratorState &iterator );
1122
- static Value &dereference( const IteratorState &iterator );
1123
- static Value &unsafeDereference( const IteratorState &iterator );
1124
- static int distance( const IteratorState &x, const IteratorState &y );
1125
- static ArrayIndex indexOf( const IteratorState &iterator );
1126
- void makeBeginIterator( IteratorState &it ) const;
1127
- void makeEndIterator( IteratorState &it ) const;
1128
- void makeIterator( IteratorState &it, ArrayIndex index ) const;
1129
-
1130
- void makeIndexValid( ArrayIndex index );
1131
-
1132
- Value **pages_;
1133
- ArrayIndex size_;
1134
- PageIndex pageCount_;
1135
- };
1136
-
1137
- /** \brief Experimental: do not use. Allocator to customize Value internal array.
1138
- * Below is an example of a simple implementation (actual implementation use
1139
- * memory pool).
1140
- \code
1141
- class DefaultValueArrayAllocator : public ValueArrayAllocator
1142
- {
1143
- public: // overridden from ValueArrayAllocator
1144
- virtual ~DefaultValueArrayAllocator()
1145
- {
1146
- }
1147
-
1148
- virtual ValueInternalArray *newArray()
1149
- {
1150
- return new ValueInternalArray();
1151
- }
1152
-
1153
- virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other )
1154
- {
1155
- return new ValueInternalArray( other );
1156
- }
1157
-
1158
- virtual void destruct( ValueInternalArray *array )
1159
- {
1160
- delete array;
1161
- }
1162
-
1163
- virtual void reallocateArrayPageIndex( Value **&indexes,
1164
- ValueInternalArray::PageIndex &indexCount,
1165
- ValueInternalArray::PageIndex minNewIndexCount )
1166
- {
1167
- ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1;
1168
- if ( minNewIndexCount > newIndexCount )
1169
- newIndexCount = minNewIndexCount;
1170
- void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount );
1171
- if ( !newIndexes )
1172
- throw std::bad_alloc();
1173
- indexCount = newIndexCount;
1174
- indexes = static_cast<Value **>( newIndexes );
1175
- }
1176
- virtual void releaseArrayPageIndex( Value **indexes,
1177
- ValueInternalArray::PageIndex indexCount )
1178
- {
1179
- if ( indexes )
1180
- free( indexes );
1181
- }
1182
-
1183
- virtual Value *allocateArrayPage()
1184
- {
1185
- return static_cast<Value *>( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) );
1186
- }
1187
-
1188
- virtual void releaseArrayPage( Value *value )
1189
- {
1190
- if ( value )
1191
- free( value );
1192
- }
1193
- };
1194
- \endcode
1195
- */
1196
- class JSON_API ValueArrayAllocator
1197
- {
1198
- public:
1199
- virtual ~ValueArrayAllocator();
1200
- virtual ValueInternalArray *newArray() = 0;
1201
- virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0;
1202
- virtual void destructArray( ValueInternalArray *array ) = 0;
1203
- /** \brief Reallocate array page index.
1204
- * Reallocates an array of pointer on each page.
1205
- * \param indexes [input] pointer on the current index. May be \c NULL.
1206
- * [output] pointer on the new index of at least
1207
- * \a minNewIndexCount pages.
1208
- * \param indexCount [input] current number of pages in the index.
1209
- * [output] number of page the reallocated index can handle.
1210
- * \b MUST be >= \a minNewIndexCount.
1211
- * \param minNewIndexCount Minimum number of page the new index must be able to
1212
- * handle.
1213
- */
1214
- virtual void reallocateArrayPageIndex( Value **&indexes,
1215
- ValueInternalArray::PageIndex &indexCount,
1216
- ValueInternalArray::PageIndex minNewIndexCount ) = 0;
1217
- virtual void releaseArrayPageIndex( Value **indexes,
1218
- ValueInternalArray::PageIndex indexCount ) = 0;
1219
- virtual Value *allocateArrayPage() = 0;
1220
- virtual void releaseArrayPage( Value *value ) = 0;
1221
- };
1222
- #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
1223
-
1224
-
1225
- /** \brief base class for Value iterators.
1226
- *
1227
- */
1228
- class ValueIteratorBase
1229
- {
1230
- public:
1231
- typedef unsigned int size_t;
1232
- typedef int difference_type;
1233
- typedef ValueIteratorBase SelfType;
1234
-
1235
- ValueIteratorBase();
1236
- #ifndef JSON_VALUE_USE_INTERNAL_MAP
1237
- explicit ValueIteratorBase( const Value::ObjectValues::iterator &current );
1238
- #else
1239
- ValueIteratorBase( const ValueInternalArray::IteratorState &state );
1240
- ValueIteratorBase( const ValueInternalMap::IteratorState &state );
1241
- #endif
1140
+ /// Return the index of the referenced Value, or -1 if it is not an arrayValue.
1141
+ UInt index() const;
1242
1142
 
1243
- bool operator ==( const SelfType &other ) const
1244
- {
1245
- return isEqual( other );
1246
- }
1143
+ /// Return the member name of the referenced Value, or "" if it is not an
1144
+ /// objectValue.
1145
+ /// \note Avoid `c_str()` on result, as embedded zeroes are possible.
1146
+ JSONCPP_STRING name() const;
1247
1147
 
1248
- bool operator !=( const SelfType &other ) const
1249
- {
1250
- return !isEqual( other );
1251
- }
1148
+ /// Return the member name of the referenced Value. "" if it is not an
1149
+ /// objectValue.
1150
+ /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.
1151
+ JSONCPP_DEPRECATED("Use `key = name();` instead.")
1152
+ char const* memberName() const;
1153
+ /// Return the member name of the referenced Value, or NULL if it is not an
1154
+ /// objectValue.
1155
+ /// \note Better version than memberName(). Allows embedded nulls.
1156
+ char const* memberName(char const** end) const;
1252
1157
 
1253
- difference_type operator -( const SelfType &other ) const
1254
- {
1255
- return computeDistance( other );
1256
- }
1158
+ protected:
1159
+ Value& deref() const;
1257
1160
 
1258
- /// Return either the index or the member name of the referenced value as a Value.
1259
- Value key() const;
1161
+ void increment();
1260
1162
 
1261
- /// Return the index of the referenced Value. -1 if it is not an arrayValue.
1262
- UInt index() const;
1163
+ void decrement();
1263
1164
 
1264
- /// Return the member name of the referenced Value. "" if it is not an objectValue.
1265
- const char *memberName() const;
1165
+ difference_type computeDistance(const SelfType& other) const;
1266
1166
 
1267
- protected:
1268
- Value &deref() const;
1167
+ bool isEqual(const SelfType& other) const;
1269
1168
 
1270
- void increment();
1169
+ void copy(const SelfType& other);
1271
1170
 
1272
- void decrement();
1171
+ private:
1172
+ Value::ObjectValues::iterator current_;
1173
+ // Indicates that iterator is for a null value.
1174
+ bool isNull_;
1273
1175
 
1274
- difference_type computeDistance( const SelfType &other ) const;
1176
+ public:
1177
+ // For some reason, BORLAND needs these at the end, rather
1178
+ // than earlier. No idea why.
1179
+ ValueIteratorBase();
1180
+ explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
1181
+ };
1275
1182
 
1276
- bool isEqual( const SelfType &other ) const;
1183
+ /** \brief const iterator for object and array value.
1184
+ *
1185
+ */
1186
+ class JSON_API ValueConstIterator : public ValueIteratorBase {
1187
+ friend class Value;
1188
+
1189
+ public:
1190
+ typedef const Value value_type;
1191
+ //typedef unsigned int size_t;
1192
+ //typedef int difference_type;
1193
+ typedef const Value& reference;
1194
+ typedef const Value* pointer;
1195
+ typedef ValueConstIterator SelfType;
1196
+
1197
+ ValueConstIterator();
1198
+ ValueConstIterator(ValueIterator const& other);
1199
+
1200
+ private:
1201
+ /*! \internal Use by Value to create an iterator.
1202
+ */
1203
+ explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
1204
+ public:
1205
+ SelfType& operator=(const ValueIteratorBase& other);
1206
+
1207
+ SelfType operator++(int) {
1208
+ SelfType temp(*this);
1209
+ ++*this;
1210
+ return temp;
1211
+ }
1212
+
1213
+ SelfType operator--(int) {
1214
+ SelfType temp(*this);
1215
+ --*this;
1216
+ return temp;
1217
+ }
1218
+
1219
+ SelfType& operator--() {
1220
+ decrement();
1221
+ return *this;
1222
+ }
1223
+
1224
+ SelfType& operator++() {
1225
+ increment();
1226
+ return *this;
1227
+ }
1228
+
1229
+ reference operator*() const { return deref(); }
1230
+
1231
+ pointer operator->() const { return &deref(); }
1232
+ };
1277
1233
 
1278
- void copy( const SelfType &other );
1234
+ /** \brief Iterator for object and array value.
1235
+ */
1236
+ class JSON_API ValueIterator : public ValueIteratorBase {
1237
+ friend class Value;
1238
+
1239
+ public:
1240
+ typedef Value value_type;
1241
+ typedef unsigned int size_t;
1242
+ typedef int difference_type;
1243
+ typedef Value& reference;
1244
+ typedef Value* pointer;
1245
+ typedef ValueIterator SelfType;
1246
+
1247
+ ValueIterator();
1248
+ explicit ValueIterator(const ValueConstIterator& other);
1249
+ ValueIterator(const ValueIterator& other);
1250
+
1251
+ private:
1252
+ /*! \internal Use by Value to create an iterator.
1253
+ */
1254
+ explicit ValueIterator(const Value::ObjectValues::iterator& current);
1255
+ public:
1256
+ SelfType& operator=(const SelfType& other);
1257
+
1258
+ SelfType operator++(int) {
1259
+ SelfType temp(*this);
1260
+ ++*this;
1261
+ return temp;
1262
+ }
1263
+
1264
+ SelfType operator--(int) {
1265
+ SelfType temp(*this);
1266
+ --*this;
1267
+ return temp;
1268
+ }
1269
+
1270
+ SelfType& operator--() {
1271
+ decrement();
1272
+ return *this;
1273
+ }
1274
+
1275
+ SelfType& operator++() {
1276
+ increment();
1277
+ return *this;
1278
+ }
1279
+
1280
+ reference operator*() const { return deref(); }
1281
+
1282
+ pointer operator->() const { return &deref(); }
1283
+ };
1279
1284
 
1280
- private:
1281
- #ifndef JSON_VALUE_USE_INTERNAL_MAP
1282
- Value::ObjectValues::iterator current_;
1283
- // Indicates that iterator is for a null value.
1284
- bool isNull_;
1285
- #else
1286
- union
1287
- {
1288
- ValueInternalArray::IteratorState array_;
1289
- ValueInternalMap::IteratorState map_;
1290
- } iterator_;
1291
- bool isArray_;
1292
- #endif
1293
- };
1285
+ } // namespace Json
1294
1286
 
1295
- /** \brief const iterator for object and array value.
1296
- *
1297
- */
1298
- class ValueConstIterator : public ValueIteratorBase
1299
- {
1300
- friend class Value;
1301
- public:
1302
- typedef unsigned int size_t;
1303
- typedef int difference_type;
1304
- typedef const Value &reference;
1305
- typedef const Value *pointer;
1306
- typedef ValueConstIterator SelfType;
1307
-
1308
- ValueConstIterator();
1309
- private:
1310
- /*! \internal Use by Value to create an iterator.
1311
- */
1312
- #ifndef JSON_VALUE_USE_INTERNAL_MAP
1313
- explicit ValueConstIterator( const Value::ObjectValues::iterator &current );
1314
- #else
1315
- ValueConstIterator( const ValueInternalArray::IteratorState &state );
1316
- ValueConstIterator( const ValueInternalMap::IteratorState &state );
1317
- #endif
1318
- public:
1319
- SelfType &operator =( const ValueIteratorBase &other );
1320
-
1321
- SelfType operator++( int )
1322
- {
1323
- SelfType temp( *this );
1324
- ++*this;
1325
- return temp;
1326
- }
1327
-
1328
- SelfType operator--( int )
1329
- {
1330
- SelfType temp( *this );
1331
- --*this;
1332
- return temp;
1333
- }
1334
-
1335
- SelfType &operator--()
1336
- {
1337
- decrement();
1338
- return *this;
1339
- }
1340
-
1341
- SelfType &operator++()
1342
- {
1343
- increment();
1344
- return *this;
1345
- }
1346
-
1347
- reference operator *() const
1348
- {
1349
- return deref();
1350
- }
1351
- };
1352
-
1353
-
1354
- /** \brief Iterator for object and array value.
1355
- */
1356
- class ValueIterator : public ValueIteratorBase
1357
- {
1358
- friend class Value;
1359
- public:
1360
- typedef unsigned int size_t;
1361
- typedef int difference_type;
1362
- typedef Value &reference;
1363
- typedef Value *pointer;
1364
- typedef ValueIterator SelfType;
1365
-
1366
- ValueIterator();
1367
- ValueIterator( const ValueConstIterator &other );
1368
- ValueIterator( const ValueIterator &other );
1369
- private:
1370
- /*! \internal Use by Value to create an iterator.
1371
- */
1372
- #ifndef JSON_VALUE_USE_INTERNAL_MAP
1373
- explicit ValueIterator( const Value::ObjectValues::iterator &current );
1374
- #else
1375
- ValueIterator( const ValueInternalArray::IteratorState &state );
1376
- ValueIterator( const ValueInternalMap::IteratorState &state );
1377
- #endif
1378
- public:
1379
-
1380
- SelfType &operator =( const SelfType &other );
1381
-
1382
- SelfType operator++( int )
1383
- {
1384
- SelfType temp( *this );
1385
- ++*this;
1386
- return temp;
1387
- }
1388
-
1389
- SelfType operator--( int )
1390
- {
1391
- SelfType temp( *this );
1392
- --*this;
1393
- return temp;
1394
- }
1395
-
1396
- SelfType &operator--()
1397
- {
1398
- decrement();
1399
- return *this;
1400
- }
1401
-
1402
- SelfType &operator++()
1403
- {
1404
- increment();
1405
- return *this;
1406
- }
1407
-
1408
- reference operator *() const
1409
- {
1410
- return deref();
1411
- }
1412
- };
1413
1287
 
1288
+ namespace std {
1289
+ /// Specialize std::swap() for Json::Value.
1290
+ template<>
1291
+ inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
1292
+ }
1414
1293
 
1415
- } // namespace Json
1416
1294
 
1295
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1296
+ #pragma warning(pop)
1297
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1417
1298
 
1418
1299
  #endif // CPPTL_JSON_H_INCLUDED
1419
1300
 
@@ -1436,213 +1317,403 @@ public: // overridden from ValueArrayAllocator
1436
1317
  // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1437
1318
 
1438
1319
  #ifndef CPPTL_JSON_READER_H_INCLUDED
1439
- # define CPPTL_JSON_READER_H_INCLUDED
1320
+ #define CPPTL_JSON_READER_H_INCLUDED
1440
1321
 
1441
1322
  #if !defined(JSON_IS_AMALGAMATION)
1442
- # include "features.h"
1443
- # include "value.h"
1323
+ #include "features.h"
1324
+ #include "value.h"
1444
1325
  #endif // if !defined(JSON_IS_AMALGAMATION)
1445
- # include <deque>
1446
- # include <stack>
1447
- # include <string>
1448
- # include <iostream>
1326
+ #include <deque>
1327
+ #include <iosfwd>
1328
+ #include <stack>
1329
+ #include <string>
1330
+ #include <istream>
1331
+
1332
+ // Disable warning C4251: <data member>: <type> needs to have dll-interface to
1333
+ // be used by...
1334
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1335
+ #pragma warning(push)
1336
+ #pragma warning(disable : 4251)
1337
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1449
1338
 
1450
1339
  namespace Json {
1451
1340
 
1452
- /** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a Value.
1453
- *
1341
+ /** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
1342
+ *Value.
1343
+ *
1344
+ * \deprecated Use CharReader and CharReaderBuilder.
1345
+ */
1346
+ class JSON_API Reader {
1347
+ public:
1348
+ typedef char Char;
1349
+ typedef const Char* Location;
1350
+
1351
+ /** \brief An error tagged with where in the JSON text it was encountered.
1352
+ *
1353
+ * The offsets give the [start, limit) range of bytes within the text. Note
1354
+ * that this is bytes, not codepoints.
1355
+ *
1356
+ */
1357
+ struct StructuredError {
1358
+ ptrdiff_t offset_start;
1359
+ ptrdiff_t offset_limit;
1360
+ JSONCPP_STRING message;
1361
+ };
1362
+
1363
+ /** \brief Constructs a Reader allowing all features
1364
+ * for parsing.
1365
+ */
1366
+ Reader();
1367
+
1368
+ /** \brief Constructs a Reader allowing the specified feature set
1369
+ * for parsing.
1370
+ */
1371
+ Reader(const Features& features);
1372
+
1373
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
1374
+ * document.
1375
+ * \param document UTF-8 encoded string containing the document to read.
1376
+ * \param root [out] Contains the root value of the document if it was
1377
+ * successfully parsed.
1378
+ * \param collectComments \c true to collect comment and allow writing them
1379
+ * back during
1380
+ * serialization, \c false to discard comments.
1381
+ * This parameter is ignored if
1382
+ * Features::allowComments_
1383
+ * is \c false.
1384
+ * \return \c true if the document was successfully parsed, \c false if an
1385
+ * error occurred.
1386
+ */
1387
+ bool
1388
+ parse(const std::string& document, Value& root, bool collectComments = true);
1389
+
1390
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
1391
+ document.
1392
+ * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
1393
+ document to read.
1394
+ * \param endDoc Pointer on the end of the UTF-8 encoded string of the
1395
+ document to read.
1396
+ * Must be >= beginDoc.
1397
+ * \param root [out] Contains the root value of the document if it was
1398
+ * successfully parsed.
1399
+ * \param collectComments \c true to collect comment and allow writing them
1400
+ back during
1401
+ * serialization, \c false to discard comments.
1402
+ * This parameter is ignored if
1403
+ Features::allowComments_
1404
+ * is \c false.
1405
+ * \return \c true if the document was successfully parsed, \c false if an
1406
+ error occurred.
1407
+ */
1408
+ bool parse(const char* beginDoc,
1409
+ const char* endDoc,
1410
+ Value& root,
1411
+ bool collectComments = true);
1412
+
1413
+ /// \brief Parse from input stream.
1414
+ /// \see Json::operator>>(std::istream&, Json::Value&).
1415
+ bool parse(JSONCPP_ISTREAM& is, Value& root, bool collectComments = true);
1416
+
1417
+ /** \brief Returns a user friendly string that list errors in the parsed
1418
+ * document.
1419
+ * \return Formatted error message with the list of errors with their location
1420
+ * in
1421
+ * the parsed document. An empty string is returned if no error
1422
+ * occurred
1423
+ * during parsing.
1424
+ * \deprecated Use getFormattedErrorMessages() instead (typo fix).
1425
+ */
1426
+ JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
1427
+ JSONCPP_STRING getFormatedErrorMessages() const;
1428
+
1429
+ /** \brief Returns a user friendly string that list errors in the parsed
1430
+ * document.
1431
+ * \return Formatted error message with the list of errors with their location
1432
+ * in
1433
+ * the parsed document. An empty string is returned if no error
1434
+ * occurred
1435
+ * during parsing.
1436
+ */
1437
+ JSONCPP_STRING getFormattedErrorMessages() const;
1438
+
1439
+ /** \brief Returns a vector of structured erros encounted while parsing.
1440
+ * \return A (possibly empty) vector of StructuredError objects. Currently
1441
+ * only one error can be returned, but the caller should tolerate
1442
+ * multiple
1443
+ * errors. This can occur if the parser recovers from a non-fatal
1444
+ * parse error and then encounters additional errors.
1445
+ */
1446
+ std::vector<StructuredError> getStructuredErrors() const;
1447
+
1448
+ /** \brief Add a semantic error message.
1449
+ * \param value JSON Value location associated with the error
1450
+ * \param message The error message.
1451
+ * \return \c true if the error was successfully added, \c false if the
1452
+ * Value offset exceeds the document size.
1453
+ */
1454
+ bool pushError(const Value& value, const JSONCPP_STRING& message);
1455
+
1456
+ /** \brief Add a semantic error message with extra context.
1457
+ * \param value JSON Value location associated with the error
1458
+ * \param message The error message.
1459
+ * \param extra Additional JSON Value location to contextualize the error
1460
+ * \return \c true if the error was successfully added, \c false if either
1461
+ * Value offset exceeds the document size.
1462
+ */
1463
+ bool pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra);
1464
+
1465
+ /** \brief Return whether there are any errors.
1466
+ * \return \c true if there are no errors to report \c false if
1467
+ * errors have occurred.
1468
+ */
1469
+ bool good() const;
1470
+
1471
+ private:
1472
+ enum TokenType {
1473
+ tokenEndOfStream = 0,
1474
+ tokenObjectBegin,
1475
+ tokenObjectEnd,
1476
+ tokenArrayBegin,
1477
+ tokenArrayEnd,
1478
+ tokenString,
1479
+ tokenNumber,
1480
+ tokenTrue,
1481
+ tokenFalse,
1482
+ tokenNull,
1483
+ tokenArraySeparator,
1484
+ tokenMemberSeparator,
1485
+ tokenComment,
1486
+ tokenError
1487
+ };
1488
+
1489
+ class Token {
1490
+ public:
1491
+ TokenType type_;
1492
+ Location start_;
1493
+ Location end_;
1494
+ };
1495
+
1496
+ class ErrorInfo {
1497
+ public:
1498
+ Token token_;
1499
+ JSONCPP_STRING message_;
1500
+ Location extra_;
1501
+ };
1502
+
1503
+ typedef std::deque<ErrorInfo> Errors;
1504
+
1505
+ bool readToken(Token& token);
1506
+ void skipSpaces();
1507
+ bool match(Location pattern, int patternLength);
1508
+ bool readComment();
1509
+ bool readCStyleComment();
1510
+ bool readCppStyleComment();
1511
+ bool readString();
1512
+ void readNumber();
1513
+ bool readValue();
1514
+ bool readObject(Token& token);
1515
+ bool readArray(Token& token);
1516
+ bool decodeNumber(Token& token);
1517
+ bool decodeNumber(Token& token, Value& decoded);
1518
+ bool decodeString(Token& token);
1519
+ bool decodeString(Token& token, JSONCPP_STRING& decoded);
1520
+ bool decodeDouble(Token& token);
1521
+ bool decodeDouble(Token& token, Value& decoded);
1522
+ bool decodeUnicodeCodePoint(Token& token,
1523
+ Location& current,
1524
+ Location end,
1525
+ unsigned int& unicode);
1526
+ bool decodeUnicodeEscapeSequence(Token& token,
1527
+ Location& current,
1528
+ Location end,
1529
+ unsigned int& unicode);
1530
+ bool addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);
1531
+ bool recoverFromError(TokenType skipUntilToken);
1532
+ bool addErrorAndRecover(const JSONCPP_STRING& message,
1533
+ Token& token,
1534
+ TokenType skipUntilToken);
1535
+ void skipUntilSpace();
1536
+ Value& currentValue();
1537
+ Char getNextChar();
1538
+ void
1539
+ getLocationLineAndColumn(Location location, int& line, int& column) const;
1540
+ JSONCPP_STRING getLocationLineAndColumn(Location location) const;
1541
+ void addComment(Location begin, Location end, CommentPlacement placement);
1542
+ void skipCommentTokens(Token& token);
1543
+
1544
+ typedef std::stack<Value*> Nodes;
1545
+ Nodes nodes_;
1546
+ Errors errors_;
1547
+ JSONCPP_STRING document_;
1548
+ Location begin_;
1549
+ Location end_;
1550
+ Location current_;
1551
+ Location lastValueEnd_;
1552
+ Value* lastValue_;
1553
+ JSONCPP_STRING commentsBefore_;
1554
+ Features features_;
1555
+ bool collectComments_;
1556
+ }; // Reader
1557
+
1558
+ /** Interface for reading JSON from a char array.
1559
+ */
1560
+ class JSON_API CharReader {
1561
+ public:
1562
+ virtual ~CharReader() {}
1563
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
1564
+ document.
1565
+ * The document must be a UTF-8 encoded string containing the document to read.
1566
+ *
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 errs [out] Formatted error messages (if not NULL)
1575
+ * a user friendly string that lists errors in the parsed
1576
+ * document.
1577
+ * \return \c true if the document was successfully parsed, \c false if an
1578
+ error occurred.
1579
+ */
1580
+ virtual bool parse(
1581
+ char const* beginDoc, char const* endDoc,
1582
+ Value* root, JSONCPP_STRING* errs) = 0;
1583
+
1584
+ class JSON_API Factory {
1585
+ public:
1586
+ virtual ~Factory() {}
1587
+ /** \brief Allocate a CharReader via operator new().
1588
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
1589
+ */
1590
+ virtual CharReader* newCharReader() const = 0;
1591
+ }; // Factory
1592
+ }; // CharReader
1593
+
1594
+ /** \brief Build a CharReader implementation.
1595
+
1596
+ Usage:
1597
+ \code
1598
+ using namespace Json;
1599
+ CharReaderBuilder builder;
1600
+ builder["collectComments"] = false;
1601
+ Value value;
1602
+ JSONCPP_STRING errs;
1603
+ bool ok = parseFromStream(builder, std::cin, &value, &errs);
1604
+ \endcode
1605
+ */
1606
+ class JSON_API CharReaderBuilder : public CharReader::Factory {
1607
+ public:
1608
+ // Note: We use a Json::Value so that we can add data-members to this class
1609
+ // without a major version bump.
1610
+ /** Configuration of this builder.
1611
+ These are case-sensitive.
1612
+ Available settings (case-sensitive):
1613
+ - `"collectComments": false or true`
1614
+ - true to collect comment and allow writing them
1615
+ back during serialization, false to discard comments.
1616
+ This parameter is ignored if allowComments is false.
1617
+ - `"allowComments": false or true`
1618
+ - true if comments are allowed.
1619
+ - `"strictRoot": false or true`
1620
+ - true if root must be either an array or an object value
1621
+ - `"allowDroppedNullPlaceholders": false or true`
1622
+ - true if dropped null placeholders are allowed. (See StreamWriterBuilder.)
1623
+ - `"allowNumericKeys": false or true`
1624
+ - true if numeric object keys are allowed.
1625
+ - `"allowSingleQuotes": false or true`
1626
+ - true if '' are allowed for strings (both keys and values)
1627
+ - `"stackLimit": integer`
1628
+ - Exceeding stackLimit (recursive depth of `readValue()`) will
1629
+ cause an exception.
1630
+ - This is a security issue (seg-faults caused by deeply nested JSON),
1631
+ so the default is low.
1632
+ - `"failIfExtra": false or true`
1633
+ - If true, `parse()` returns false when extra non-whitespace trails
1634
+ the JSON value in the input string.
1635
+ - `"rejectDupKeys": false or true`
1636
+ - If true, `parse()` returns false when a key is duplicated within an object.
1637
+ - `"allowSpecialFloats": false or true`
1638
+ - If true, special float values (NaNs and infinities) are allowed
1639
+ and their values are lossfree restorable.
1640
+
1641
+ You can examine 'settings_` yourself
1642
+ to see the defaults. You can also write and read them just like any
1643
+ JSON Value.
1644
+ \sa setDefaults()
1454
1645
  */
1455
- class JSON_API Reader
1456
- {
1457
- public:
1458
- typedef char Char;
1459
- typedef const Char *Location;
1460
-
1461
- /** \brief Constructs a Reader allowing all features
1462
- * for parsing.
1463
- */
1464
- Reader();
1465
-
1466
- /** \brief Constructs a Reader allowing the specified feature set
1467
- * for parsing.
1468
- */
1469
- Reader( const Features &features );
1470
-
1471
- /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
1472
- * \param document UTF-8 encoded string containing the document to read.
1473
- * \param root [out] Contains the root value of the document if it was
1474
- * successfully parsed.
1475
- * \param collectComments \c true to collect comment and allow writing them back during
1476
- * serialization, \c false to discard comments.
1477
- * This parameter is ignored if Features::allowComments_
1478
- * is \c false.
1479
- * \return \c true if the document was successfully parsed, \c false if an error occurred.
1480
- */
1481
- bool parse( const std::string &document,
1482
- Value &root,
1483
- bool collectComments = true );
1484
-
1485
- /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
1486
- * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the document to read.
1487
- * \param endDoc Pointer on the end of the UTF-8 encoded string of the document to read.
1488
- \ Must be >= beginDoc.
1489
- * \param root [out] Contains the root value of the document if it was
1490
- * successfully parsed.
1491
- * \param collectComments \c true to collect comment and allow writing them back during
1492
- * serialization, \c false to discard comments.
1493
- * This parameter is ignored if Features::allowComments_
1494
- * is \c false.
1495
- * \return \c true if the document was successfully parsed, \c false if an error occurred.
1496
- */
1497
- bool parse( const char *beginDoc, const char *endDoc,
1498
- Value &root,
1499
- bool collectComments = true );
1500
-
1501
- /// \brief Parse from input stream.
1502
- /// \see Json::operator>>(std::istream&, Json::Value&).
1503
- bool parse( std::istream &is,
1504
- Value &root,
1505
- bool collectComments = true );
1506
-
1507
- /** \brief Returns a user friendly string that list errors in the parsed document.
1508
- * \return Formatted error message with the list of errors with their location in
1509
- * the parsed document. An empty string is returned if no error occurred
1510
- * during parsing.
1511
- * \deprecated Use getFormattedErrorMessages() instead (typo fix).
1512
- */
1513
- JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead")
1514
- std::string getFormatedErrorMessages() const;
1515
-
1516
- /** \brief Returns a user friendly string that list errors in the parsed document.
1517
- * \return Formatted error message with the list of errors with their location in
1518
- * the parsed document. An empty string is returned if no error occurred
1519
- * during parsing.
1520
- */
1521
- std::string getFormattedErrorMessages() const;
1522
-
1523
- private:
1524
- enum TokenType
1525
- {
1526
- tokenEndOfStream = 0,
1527
- tokenObjectBegin,
1528
- tokenObjectEnd,
1529
- tokenArrayBegin,
1530
- tokenArrayEnd,
1531
- tokenString,
1532
- tokenNumber,
1533
- tokenTrue,
1534
- tokenFalse,
1535
- tokenNull,
1536
- tokenArraySeparator,
1537
- tokenMemberSeparator,
1538
- tokenComment,
1539
- tokenError
1540
- };
1541
-
1542
- class Token
1543
- {
1544
- public:
1545
- TokenType type_;
1546
- Location start_;
1547
- Location end_;
1548
- };
1549
-
1550
- class ErrorInfo
1551
- {
1552
- public:
1553
- Token token_;
1554
- std::string message_;
1555
- Location extra_;
1556
- };
1557
-
1558
- typedef std::deque<ErrorInfo> Errors;
1559
-
1560
- bool expectToken( TokenType type, Token &token, const char *message );
1561
- bool readToken( Token &token );
1562
- void skipSpaces();
1563
- bool match( Location pattern,
1564
- int patternLength );
1565
- bool readComment();
1566
- bool readCStyleComment();
1567
- bool readCppStyleComment();
1568
- bool readString();
1569
- void readNumber();
1570
- bool readValue();
1571
- bool readObject( Token &token );
1572
- bool readArray( Token &token );
1573
- bool decodeNumber( Token &token );
1574
- bool decodeString( Token &token );
1575
- bool decodeString( Token &token, std::string &decoded );
1576
- bool decodeDouble( Token &token );
1577
- bool decodeUnicodeCodePoint( Token &token,
1578
- Location &current,
1579
- Location end,
1580
- unsigned int &unicode );
1581
- bool decodeUnicodeEscapeSequence( Token &token,
1582
- Location &current,
1583
- Location end,
1584
- unsigned int &unicode );
1585
- bool addError( const std::string &message,
1586
- Token &token,
1587
- Location extra = 0 );
1588
- bool recoverFromError( TokenType skipUntilToken );
1589
- bool addErrorAndRecover( const std::string &message,
1590
- Token &token,
1591
- TokenType skipUntilToken );
1592
- void skipUntilSpace();
1593
- Value &currentValue();
1594
- Char getNextChar();
1595
- void getLocationLineAndColumn( Location location,
1596
- int &line,
1597
- int &column ) const;
1598
- std::string getLocationLineAndColumn( Location location ) const;
1599
- void addComment( Location begin,
1600
- Location end,
1601
- CommentPlacement placement );
1602
- void skipCommentTokens( Token &token );
1603
-
1604
- typedef std::stack<Value *> Nodes;
1605
- Nodes nodes_;
1606
- Errors errors_;
1607
- std::string document_;
1608
- Location begin_;
1609
- Location end_;
1610
- Location current_;
1611
- Location lastValueEnd_;
1612
- Value *lastValue_;
1613
- std::string commentsBefore_;
1614
- Features features_;
1615
- bool collectComments_;
1616
- };
1617
-
1618
- /** \brief Read from 'sin' into 'root'.
1619
-
1620
- Always keep comments from the input JSON.
1621
-
1622
- This can be used to read a file into a particular sub-object.
1623
- For example:
1624
- \code
1625
- Json::Value root;
1626
- cin >> root["dir"]["file"];
1627
- cout << root;
1628
- \endcode
1629
- Result:
1630
- \verbatim
1631
- {
1632
- "dir": {
1633
- "file": {
1634
- // The input stream JSON would be nested here.
1635
- }
1636
- }
1637
- }
1638
- \endverbatim
1639
- \throw std::exception on parse error.
1640
- \see Json::operator<<()
1646
+ Json::Value settings_;
1647
+
1648
+ CharReaderBuilder();
1649
+ ~CharReaderBuilder() JSONCPP_OVERRIDE;
1650
+
1651
+ CharReader* newCharReader() const JSONCPP_OVERRIDE;
1652
+
1653
+ /** \return true if 'settings' are legal and consistent;
1654
+ * otherwise, indicate bad settings via 'invalid'.
1655
+ */
1656
+ bool validate(Json::Value* invalid) const;
1657
+
1658
+ /** A simple way to update a specific setting.
1659
+ */
1660
+ Value& operator[](JSONCPP_STRING key);
1661
+
1662
+ /** Called by ctor, but you can use this to reset settings_.
1663
+ * \pre 'settings' != NULL (but Json::null is fine)
1664
+ * \remark Defaults:
1665
+ * \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
1641
1666
  */
1642
- std::istream& operator>>( std::istream&, Value& );
1667
+ static void setDefaults(Json::Value* settings);
1668
+ /** Same as old Features::strictMode().
1669
+ * \pre 'settings' != NULL (but Json::null is fine)
1670
+ * \remark Defaults:
1671
+ * \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
1672
+ */
1673
+ static void strictMode(Json::Value* settings);
1674
+ };
1675
+
1676
+ /** Consume entire stream and use its begin/end.
1677
+ * Someday we might have a real StreamReader, but for now this
1678
+ * is convenient.
1679
+ */
1680
+ bool JSON_API parseFromStream(
1681
+ CharReader::Factory const&,
1682
+ JSONCPP_ISTREAM&,
1683
+ Value* root, std::string* errs);
1684
+
1685
+ /** \brief Read from 'sin' into 'root'.
1686
+
1687
+ Always keep comments from the input JSON.
1688
+
1689
+ This can be used to read a file into a particular sub-object.
1690
+ For example:
1691
+ \code
1692
+ Json::Value root;
1693
+ cin >> root["dir"]["file"];
1694
+ cout << root;
1695
+ \endcode
1696
+ Result:
1697
+ \verbatim
1698
+ {
1699
+ "dir": {
1700
+ "file": {
1701
+ // The input stream JSON would be nested here.
1702
+ }
1703
+ }
1704
+ }
1705
+ \endverbatim
1706
+ \throw std::exception on parse error.
1707
+ \see Json::operator<<()
1708
+ */
1709
+ JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
1643
1710
 
1644
1711
  } // namespace Json
1645
1712
 
1713
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1714
+ #pragma warning(pop)
1715
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1716
+
1646
1717
  #endif // CPPTL_JSON_READER_H_INCLUDED
1647
1718
 
1648
1719
  // //////////////////////////////////////////////////////////////////////
@@ -1664,183 +1735,329 @@ namespace Json {
1664
1735
  // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1665
1736
 
1666
1737
  #ifndef JSON_WRITER_H_INCLUDED
1667
- # define JSON_WRITER_H_INCLUDED
1738
+ #define JSON_WRITER_H_INCLUDED
1668
1739
 
1669
1740
  #if !defined(JSON_IS_AMALGAMATION)
1670
- # include "value.h"
1741
+ #include "value.h"
1671
1742
  #endif // if !defined(JSON_IS_AMALGAMATION)
1672
- # include <vector>
1673
- # include <string>
1674
- # include <iostream>
1743
+ #include <vector>
1744
+ #include <string>
1745
+ #include <ostream>
1746
+
1747
+ // Disable warning C4251: <data member>: <type> needs to have dll-interface to
1748
+ // be used by...
1749
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1750
+ #pragma warning(push)
1751
+ #pragma warning(disable : 4251)
1752
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1675
1753
 
1676
1754
  namespace Json {
1677
1755
 
1678
- class Value;
1756
+ class Value;
1679
1757
 
1680
- /** \brief Abstract class for writers.
1681
- */
1682
- class JSON_API Writer
1683
- {
1684
- public:
1685
- virtual ~Writer();
1686
-
1687
- virtual std::string write( const Value &root ) = 0;
1688
- };
1689
-
1690
- /** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format without formatting (not human friendly).
1691
- *
1692
- * The JSON document is written in a single line. It is not intended for 'human' consumption,
1693
- * but may be usefull to support feature such as RPC where bandwith is limited.
1694
- * \sa Reader, Value
1695
- */
1696
- class JSON_API FastWriter : public Writer
1697
- {
1698
- public:
1699
- FastWriter();
1700
- virtual ~FastWriter(){}
1701
-
1702
- void enableYAMLCompatibility();
1703
-
1704
- public: // overridden from Writer
1705
- virtual std::string write( const Value &root );
1706
-
1707
- private:
1708
- void writeValue( const Value &value );
1709
-
1710
- std::string document_;
1711
- bool yamlCompatiblityEnabled_;
1712
- };
1713
-
1714
- /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way.
1715
- *
1716
- * The rules for line break and indent are as follow:
1717
- * - Object value:
1718
- * - if empty then print {} without indent and line break
1719
- * - if not empty the print '{', line break & indent, print one value per line
1720
- * and then unindent and line break and print '}'.
1721
- * - Array value:
1722
- * - if empty then print [] without indent and line break
1723
- * - if the array contains no object value, empty array or some other value types,
1724
- * and all the values fit on one lines, then print the array on a single line.
1725
- * - otherwise, it the values do not fit on one line, or the array contains
1726
- * object or non empty array, then print one value per line.
1727
- *
1728
- * If the Value have comments then they are outputed according to their #CommentPlacement.
1729
- *
1730
- * \sa Reader, Value, Value::setComment()
1731
- */
1732
- class JSON_API StyledWriter: public Writer
1733
- {
1734
- public:
1735
- StyledWriter();
1736
- virtual ~StyledWriter(){}
1737
-
1738
- public: // overridden from Writer
1739
- /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
1740
- * \param root Value to serialize.
1741
- * \return String containing the JSON document that represents the root value.
1742
- */
1743
- virtual std::string write( const Value &root );
1744
-
1745
- private:
1746
- void writeValue( const Value &value );
1747
- void writeArrayValue( const Value &value );
1748
- bool isMultineArray( const Value &value );
1749
- void pushValue( const std::string &value );
1750
- void writeIndent();
1751
- void writeWithIndent( const std::string &value );
1752
- void indent();
1753
- void unindent();
1754
- void writeCommentBeforeValue( const Value &root );
1755
- void writeCommentAfterValueOnSameLine( const Value &root );
1756
- bool hasCommentForValue( const Value &value );
1757
- static std::string normalizeEOL( const std::string &text );
1758
-
1759
- typedef std::vector<std::string> ChildValues;
1760
-
1761
- ChildValues childValues_;
1762
- std::string document_;
1763
- std::string indentString_;
1764
- int rightMargin_;
1765
- int indentSize_;
1766
- bool addChildValues_;
1767
- };
1768
-
1769
- /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way,
1770
- to a stream rather than to a string.
1771
- *
1772
- * The rules for line break and indent are as follow:
1773
- * - Object value:
1774
- * - if empty then print {} without indent and line break
1775
- * - if not empty the print '{', line break & indent, print one value per line
1776
- * and then unindent and line break and print '}'.
1777
- * - Array value:
1778
- * - if empty then print [] without indent and line break
1779
- * - if the array contains no object value, empty array or some other value types,
1780
- * and all the values fit on one lines, then print the array on a single line.
1781
- * - otherwise, it the values do not fit on one line, or the array contains
1782
- * object or non empty array, then print one value per line.
1783
- *
1784
- * If the Value have comments then they are outputed according to their #CommentPlacement.
1785
- *
1786
- * \param indentation Each level will be indented by this amount extra.
1787
- * \sa Reader, Value, Value::setComment()
1758
+ /**
1759
+
1760
+ Usage:
1761
+ \code
1762
+ using namespace Json;
1763
+ void writeToStdout(StreamWriter::Factory const& factory, Value const& value) {
1764
+ std::unique_ptr<StreamWriter> const writer(
1765
+ factory.newStreamWriter());
1766
+ writer->write(value, &std::cout);
1767
+ std::cout << std::endl; // add lf and flush
1768
+ }
1769
+ \endcode
1770
+ */
1771
+ class JSON_API StreamWriter {
1772
+ protected:
1773
+ JSONCPP_OSTREAM* sout_; // not owned; will not delete
1774
+ public:
1775
+ StreamWriter();
1776
+ virtual ~StreamWriter();
1777
+ /** Write Value into document as configured in sub-class.
1778
+ Do not take ownership of sout, but maintain a reference during function.
1779
+ \pre sout != NULL
1780
+ \return zero on success (For now, we always return zero, so check the stream instead.)
1781
+ \throw std::exception possibly, depending on configuration
1782
+ */
1783
+ virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0;
1784
+
1785
+ /** \brief A simple abstract factory.
1786
+ */
1787
+ class JSON_API Factory {
1788
+ public:
1789
+ virtual ~Factory();
1790
+ /** \brief Allocate a CharReader via operator new().
1791
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
1792
+ */
1793
+ virtual StreamWriter* newStreamWriter() const = 0;
1794
+ }; // Factory
1795
+ }; // StreamWriter
1796
+
1797
+ /** \brief Write into stringstream, then return string, for convenience.
1798
+ * A StreamWriter will be created from the factory, used, and then deleted.
1799
+ */
1800
+ JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory, Value const& root);
1801
+
1802
+
1803
+ /** \brief Build a StreamWriter implementation.
1804
+
1805
+ Usage:
1806
+ \code
1807
+ using namespace Json;
1808
+ Value value = ...;
1809
+ StreamWriterBuilder builder;
1810
+ builder["commentStyle"] = "None";
1811
+ builder["indentation"] = " "; // or whatever you like
1812
+ std::unique_ptr<Json::StreamWriter> writer(
1813
+ builder.newStreamWriter());
1814
+ writer->write(value, &std::cout);
1815
+ std::cout << std::endl; // add lf and flush
1816
+ \endcode
1817
+ */
1818
+ class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
1819
+ public:
1820
+ // Note: We use a Json::Value so that we can add data-members to this class
1821
+ // without a major version bump.
1822
+ /** Configuration of this builder.
1823
+ Available settings (case-sensitive):
1824
+ - "commentStyle": "None" or "All"
1825
+ - "indentation": "<anything>"
1826
+ - "enableYAMLCompatibility": false or true
1827
+ - slightly change the whitespace around colons
1828
+ - "dropNullPlaceholders": false or true
1829
+ - Drop the "null" string from the writer's output for nullValues.
1830
+ Strictly speaking, this is not valid JSON. But when the output is being
1831
+ fed to a browser's Javascript, it makes for smaller output and the
1832
+ browser can handle the output just fine.
1833
+ - "useSpecialFloats": false or true
1834
+ - If true, outputs non-finite floating point values in the following way:
1835
+ NaN values as "NaN", positive infinity as "Infinity", and negative infinity
1836
+ as "-Infinity".
1837
+
1838
+ You can examine 'settings_` yourself
1839
+ to see the defaults. You can also write and read them just like any
1840
+ JSON Value.
1841
+ \sa setDefaults()
1788
1842
  */
1789
- class JSON_API StyledStreamWriter
1790
- {
1791
- public:
1792
- StyledStreamWriter( std::string indentation="\t" );
1793
- ~StyledStreamWriter(){}
1794
-
1795
- public:
1796
- /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
1797
- * \param out Stream to write to. (Can be ostringstream, e.g.)
1798
- * \param root Value to serialize.
1799
- * \note There is no point in deriving from Writer, since write() should not return a value.
1800
- */
1801
- void write( std::ostream &out, const Value &root );
1802
-
1803
- private:
1804
- void writeValue( const Value &value );
1805
- void writeArrayValue( const Value &value );
1806
- bool isMultineArray( const Value &value );
1807
- void pushValue( const std::string &value );
1808
- void writeIndent();
1809
- void writeWithIndent( const std::string &value );
1810
- void indent();
1811
- void unindent();
1812
- void writeCommentBeforeValue( const Value &root );
1813
- void writeCommentAfterValueOnSameLine( const Value &root );
1814
- bool hasCommentForValue( const Value &value );
1815
- static std::string normalizeEOL( const std::string &text );
1816
-
1817
- typedef std::vector<std::string> ChildValues;
1818
-
1819
- ChildValues childValues_;
1820
- std::ostream* document_;
1821
- std::string indentString_;
1822
- int rightMargin_;
1823
- std::string indentation_;
1824
- bool addChildValues_;
1825
- };
1826
-
1827
- # if defined(JSON_HAS_INT64)
1828
- std::string JSON_API valueToString( Int value );
1829
- std::string JSON_API valueToString( UInt value );
1830
- # endif // if defined(JSON_HAS_INT64)
1831
- std::string JSON_API valueToString( LargestInt value );
1832
- std::string JSON_API valueToString( LargestUInt value );
1833
- std::string JSON_API valueToString( double value );
1834
- std::string JSON_API valueToString( bool value );
1835
- std::string JSON_API valueToQuotedString( const char *value );
1836
-
1837
- /// \brief Output using the StyledStreamWriter.
1838
- /// \see Json::operator>>()
1839
- std::ostream& operator<<( std::ostream&, const Value &root );
1843
+ Json::Value settings_;
1840
1844
 
1841
- } // namespace Json
1845
+ StreamWriterBuilder();
1846
+ ~StreamWriterBuilder() JSONCPP_OVERRIDE;
1847
+
1848
+ /**
1849
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
1850
+ */
1851
+ StreamWriter* newStreamWriter() const JSONCPP_OVERRIDE;
1852
+
1853
+ /** \return true if 'settings' are legal and consistent;
1854
+ * otherwise, indicate bad settings via 'invalid'.
1855
+ */
1856
+ bool validate(Json::Value* invalid) const;
1857
+ /** A simple way to update a specific setting.
1858
+ */
1859
+ Value& operator[](JSONCPP_STRING key);
1860
+
1861
+ /** Called by ctor, but you can use this to reset settings_.
1862
+ * \pre 'settings' != NULL (but Json::null is fine)
1863
+ * \remark Defaults:
1864
+ * \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults
1865
+ */
1866
+ static void setDefaults(Json::Value* settings);
1867
+ };
1868
+
1869
+ /** \brief Abstract class for writers.
1870
+ * \deprecated Use StreamWriter. (And really, this is an implementation detail.)
1871
+ */
1872
+ class JSON_API Writer {
1873
+ public:
1874
+ virtual ~Writer();
1875
+
1876
+ virtual JSONCPP_STRING write(const Value& root) = 0;
1877
+ };
1878
+
1879
+ /** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format
1880
+ *without formatting (not human friendly).
1881
+ *
1882
+ * The JSON document is written in a single line. It is not intended for 'human'
1883
+ *consumption,
1884
+ * but may be usefull to support feature such as RPC where bandwith is limited.
1885
+ * \sa Reader, Value
1886
+ * \deprecated Use StreamWriterBuilder.
1887
+ */
1888
+ class JSON_API FastWriter : public Writer {
1889
+
1890
+ public:
1891
+ FastWriter();
1892
+ ~FastWriter() JSONCPP_OVERRIDE {}
1893
+
1894
+ void enableYAMLCompatibility();
1842
1895
 
1896
+ /** \brief Drop the "null" string from the writer's output for nullValues.
1897
+ * Strictly speaking, this is not valid JSON. But when the output is being
1898
+ * fed to a browser's Javascript, it makes for smaller output and the
1899
+ * browser can handle the output just fine.
1900
+ */
1901
+ void dropNullPlaceholders();
1902
+
1903
+ void omitEndingLineFeed();
1904
+
1905
+ public: // overridden from Writer
1906
+ JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE;
1907
+
1908
+ private:
1909
+ void writeValue(const Value& value);
1910
+
1911
+ JSONCPP_STRING document_;
1912
+ bool yamlCompatiblityEnabled_;
1913
+ bool dropNullPlaceholders_;
1914
+ bool omitEndingLineFeed_;
1915
+ };
1916
+
1917
+ /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
1918
+ *human friendly way.
1919
+ *
1920
+ * The rules for line break and indent are as follow:
1921
+ * - Object value:
1922
+ * - if empty then print {} without indent and line break
1923
+ * - if not empty the print '{', line break & indent, print one value per
1924
+ *line
1925
+ * and then unindent and line break and print '}'.
1926
+ * - Array value:
1927
+ * - if empty then print [] without indent and line break
1928
+ * - if the array contains no object value, empty array or some other value
1929
+ *types,
1930
+ * and all the values fit on one lines, then print the array on a single
1931
+ *line.
1932
+ * - otherwise, it the values do not fit on one line, or the array contains
1933
+ * object or non empty array, then print one value per line.
1934
+ *
1935
+ * If the Value have comments then they are outputed according to their
1936
+ *#CommentPlacement.
1937
+ *
1938
+ * \sa Reader, Value, Value::setComment()
1939
+ * \deprecated Use StreamWriterBuilder.
1940
+ */
1941
+ class JSON_API StyledWriter : public Writer {
1942
+ public:
1943
+ StyledWriter();
1944
+ ~StyledWriter() JSONCPP_OVERRIDE {}
1945
+
1946
+ public: // overridden from Writer
1947
+ /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
1948
+ * \param root Value to serialize.
1949
+ * \return String containing the JSON document that represents the root value.
1950
+ */
1951
+ JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE;
1952
+
1953
+ private:
1954
+ void writeValue(const Value& value);
1955
+ void writeArrayValue(const Value& value);
1956
+ bool isMultineArray(const Value& value);
1957
+ void pushValue(const JSONCPP_STRING& value);
1958
+ void writeIndent();
1959
+ void writeWithIndent(const JSONCPP_STRING& value);
1960
+ void indent();
1961
+ void unindent();
1962
+ void writeCommentBeforeValue(const Value& root);
1963
+ void writeCommentAfterValueOnSameLine(const Value& root);
1964
+ bool hasCommentForValue(const Value& value);
1965
+ static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
1966
+
1967
+ typedef std::vector<JSONCPP_STRING> ChildValues;
1968
+
1969
+ ChildValues childValues_;
1970
+ JSONCPP_STRING document_;
1971
+ JSONCPP_STRING indentString_;
1972
+ unsigned int rightMargin_;
1973
+ unsigned int indentSize_;
1974
+ bool addChildValues_;
1975
+ };
1843
1976
 
1977
+ /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
1978
+ human friendly way,
1979
+ to a stream rather than to a string.
1980
+ *
1981
+ * The rules for line break and indent are as follow:
1982
+ * - Object value:
1983
+ * - if empty then print {} without indent and line break
1984
+ * - if not empty the print '{', line break & indent, print one value per
1985
+ line
1986
+ * and then unindent and line break and print '}'.
1987
+ * - Array value:
1988
+ * - if empty then print [] without indent and line break
1989
+ * - if the array contains no object value, empty array or some other value
1990
+ types,
1991
+ * and all the values fit on one lines, then print the array on a single
1992
+ line.
1993
+ * - otherwise, it the values do not fit on one line, or the array contains
1994
+ * object or non empty array, then print one value per line.
1995
+ *
1996
+ * If the Value have comments then they are outputed according to their
1997
+ #CommentPlacement.
1998
+ *
1999
+ * \param indentation Each level will be indented by this amount extra.
2000
+ * \sa Reader, Value, Value::setComment()
2001
+ * \deprecated Use StreamWriterBuilder.
2002
+ */
2003
+ class JSON_API StyledStreamWriter {
2004
+ public:
2005
+ StyledStreamWriter(JSONCPP_STRING indentation = "\t");
2006
+ ~StyledStreamWriter() {}
2007
+
2008
+ public:
2009
+ /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
2010
+ * \param out Stream to write to. (Can be ostringstream, e.g.)
2011
+ * \param root Value to serialize.
2012
+ * \note There is no point in deriving from Writer, since write() should not
2013
+ * return a value.
2014
+ */
2015
+ void write(JSONCPP_OSTREAM& out, const Value& root);
2016
+
2017
+ private:
2018
+ void writeValue(const Value& value);
2019
+ void writeArrayValue(const Value& value);
2020
+ bool isMultineArray(const Value& value);
2021
+ void pushValue(const JSONCPP_STRING& value);
2022
+ void writeIndent();
2023
+ void writeWithIndent(const JSONCPP_STRING& value);
2024
+ void indent();
2025
+ void unindent();
2026
+ void writeCommentBeforeValue(const Value& root);
2027
+ void writeCommentAfterValueOnSameLine(const Value& root);
2028
+ bool hasCommentForValue(const Value& value);
2029
+ static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
2030
+
2031
+ typedef std::vector<JSONCPP_STRING> ChildValues;
2032
+
2033
+ ChildValues childValues_;
2034
+ JSONCPP_OSTREAM* document_;
2035
+ JSONCPP_STRING indentString_;
2036
+ unsigned int rightMargin_;
2037
+ JSONCPP_STRING indentation_;
2038
+ bool addChildValues_ : 1;
2039
+ bool indented_ : 1;
2040
+ };
2041
+
2042
+ #if defined(JSON_HAS_INT64)
2043
+ JSONCPP_STRING JSON_API valueToString(Int value);
2044
+ JSONCPP_STRING JSON_API valueToString(UInt value);
2045
+ #endif // if defined(JSON_HAS_INT64)
2046
+ JSONCPP_STRING JSON_API valueToString(LargestInt value);
2047
+ JSONCPP_STRING JSON_API valueToString(LargestUInt value);
2048
+ JSONCPP_STRING JSON_API valueToString(double value);
2049
+ JSONCPP_STRING JSON_API valueToString(bool value);
2050
+ JSONCPP_STRING JSON_API valueToQuotedString(const char* value);
2051
+
2052
+ /// \brief Output using the StyledStreamWriter.
2053
+ /// \see Json::operator>>()
2054
+ JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
2055
+
2056
+ } // namespace Json
2057
+
2058
+ #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
2059
+ #pragma warning(pop)
2060
+ #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1844
2061
 
1845
2062
  #endif // JSON_WRITER_H_INCLUDED
1846
2063
 
@@ -1852,4 +2069,72 @@ namespace Json {
1852
2069
 
1853
2070
 
1854
2071
 
2072
+
2073
+ // //////////////////////////////////////////////////////////////////////
2074
+ // Beginning of content of file: include/json/assertions.h
2075
+ // //////////////////////////////////////////////////////////////////////
2076
+
2077
+ // Copyright 2007-2010 Baptiste Lepilleur
2078
+ // Distributed under MIT license, or public domain if desired and
2079
+ // recognized in your jurisdiction.
2080
+ // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
2081
+
2082
+ #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
2083
+ #define CPPTL_JSON_ASSERTIONS_H_INCLUDED
2084
+
2085
+ #include <stdlib.h>
2086
+ #include <sstream>
2087
+
2088
+ #if !defined(JSON_IS_AMALGAMATION)
2089
+ #include "config.h"
2090
+ #endif // if !defined(JSON_IS_AMALGAMATION)
2091
+
2092
+ /** It should not be possible for a maliciously designed file to
2093
+ * cause an abort() or seg-fault, so these macros are used only
2094
+ * for pre-condition violations and internal logic errors.
2095
+ */
2096
+ #if JSON_USE_EXCEPTION
2097
+
2098
+ // @todo <= add detail about condition in exception
2099
+ # define JSON_ASSERT(condition) \
2100
+ {if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
2101
+
2102
+ # define JSON_FAIL_MESSAGE(message) \
2103
+ { \
2104
+ JSONCPP_OSTRINGSTREAM oss; oss << message; \
2105
+ Json::throwLogicError(oss.str()); \
2106
+ abort(); \
2107
+ }
2108
+
2109
+ #else // JSON_USE_EXCEPTION
2110
+
2111
+ # define JSON_ASSERT(condition) assert(condition)
2112
+
2113
+ // The call to assert() will show the failure message in debug builds. In
2114
+ // release builds we abort, for a core-dump or debugger.
2115
+ # define JSON_FAIL_MESSAGE(message) \
2116
+ { \
2117
+ JSONCPP_OSTRINGSTREAM oss; oss << message; \
2118
+ assert(false && oss.str().c_str()); \
2119
+ abort(); \
2120
+ }
2121
+
2122
+
2123
+ #endif
2124
+
2125
+ #define JSON_ASSERT_MESSAGE(condition, message) \
2126
+ if (!(condition)) { \
2127
+ JSON_FAIL_MESSAGE(message); \
2128
+ }
2129
+
2130
+ #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
2131
+
2132
+ // //////////////////////////////////////////////////////////////////////
2133
+ // End of content of file: include/json/assertions.h
2134
+ // //////////////////////////////////////////////////////////////////////
2135
+
2136
+
2137
+
2138
+
2139
+
1855
2140
  #endif //ifndef JSON_AMALGATED_H_INCLUDED