rt300@13
|
1 /// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).
|
rt300@13
|
2 /// It is intented to be used with #include <json/json.h>
|
rt300@13
|
3
|
rt300@13
|
4 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
5 // Beginning of content of file: LICENSE
|
rt300@13
|
6 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
7
|
rt300@13
|
8 /*
|
rt300@13
|
9 The JsonCpp library's source code, including accompanying documentation,
|
rt300@13
|
10 tests and demonstration applications, are licensed under the following
|
rt300@13
|
11 conditions...
|
rt300@13
|
12
|
rt300@13
|
13 The author (Baptiste Lepilleur) explicitly disclaims copyright in all
|
rt300@13
|
14 jurisdictions which recognize such a disclaimer. In such jurisdictions,
|
rt300@13
|
15 this software is released into the Public Domain.
|
rt300@13
|
16
|
rt300@13
|
17 In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
|
rt300@13
|
18 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
|
rt300@13
|
19 released under the terms of the MIT License (see below).
|
rt300@13
|
20
|
rt300@13
|
21 In jurisdictions which recognize Public Domain property, the user of this
|
rt300@13
|
22 software may choose to accept it either as 1) Public Domain, 2) under the
|
rt300@13
|
23 conditions of the MIT License (see below), or 3) under the terms of dual
|
rt300@13
|
24 Public Domain/MIT License conditions described here, as they choose.
|
rt300@13
|
25
|
rt300@13
|
26 The MIT License is about as close to Public Domain as a license can get, and is
|
rt300@13
|
27 described in clear, concise terms at:
|
rt300@13
|
28
|
rt300@13
|
29 http://en.wikipedia.org/wiki/MIT_License
|
rt300@13
|
30
|
rt300@13
|
31 The full text of the MIT License follows:
|
rt300@13
|
32
|
rt300@13
|
33 ========================================================================
|
rt300@13
|
34 Copyright (c) 2007-2010 Baptiste Lepilleur
|
rt300@13
|
35
|
rt300@13
|
36 Permission is hereby granted, free of charge, to any person
|
rt300@13
|
37 obtaining a copy of this software and associated documentation
|
rt300@13
|
38 files (the "Software"), to deal in the Software without
|
rt300@13
|
39 restriction, including without limitation the rights to use, copy,
|
rt300@13
|
40 modify, merge, publish, distribute, sublicense, and/or sell copies
|
rt300@13
|
41 of the Software, and to permit persons to whom the Software is
|
rt300@13
|
42 furnished to do so, subject to the following conditions:
|
rt300@13
|
43
|
rt300@13
|
44 The above copyright notice and this permission notice shall be
|
rt300@13
|
45 included in all copies or substantial portions of the Software.
|
rt300@13
|
46
|
rt300@13
|
47 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
rt300@13
|
48 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
rt300@13
|
49 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
rt300@13
|
50 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
rt300@13
|
51 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
rt300@13
|
52 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
rt300@13
|
53 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
rt300@13
|
54 SOFTWARE.
|
rt300@13
|
55 ========================================================================
|
rt300@13
|
56 (END LICENSE TEXT)
|
rt300@13
|
57
|
rt300@13
|
58 The MIT license is compatible with both the GPL and commercial
|
rt300@13
|
59 software, affording one all of the rights of Public Domain with the
|
rt300@13
|
60 minor nuisance of being required to keep the above copyright notice
|
rt300@13
|
61 and license text in the source code. Note also that by accepting the
|
rt300@13
|
62 Public Domain "license" you can re-license your copy using whatever
|
rt300@13
|
63 license you like.
|
rt300@13
|
64
|
rt300@13
|
65 */
|
rt300@13
|
66
|
rt300@13
|
67 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
68 // End of content of file: LICENSE
|
rt300@13
|
69 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
70
|
rt300@13
|
71
|
rt300@13
|
72
|
rt300@13
|
73
|
rt300@13
|
74
|
rt300@13
|
75 #ifndef JSON_AMALGATED_H_INCLUDED
|
rt300@13
|
76 # define JSON_AMALGATED_H_INCLUDED
|
rt300@13
|
77 /// If defined, indicates that the source file is amalgated
|
rt300@13
|
78 /// to prevent private header inclusion.
|
rt300@13
|
79 #define JSON_IS_AMALGAMATION
|
rt300@13
|
80
|
rt300@13
|
81 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
82 // Beginning of content of file: include/json/config.h
|
rt300@13
|
83 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
84
|
rt300@13
|
85 // Copyright 2007-2010 Baptiste Lepilleur
|
rt300@13
|
86 // Distributed under MIT license, or public domain if desired and
|
rt300@13
|
87 // recognized in your jurisdiction.
|
rt300@13
|
88 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
rt300@13
|
89
|
rt300@13
|
90 #ifndef JSON_CONFIG_H_INCLUDED
|
rt300@13
|
91 # define JSON_CONFIG_H_INCLUDED
|
rt300@13
|
92
|
rt300@13
|
93 /// If defined, indicates that json library is embedded in CppTL library.
|
rt300@13
|
94 //# define JSON_IN_CPPTL 1
|
rt300@13
|
95
|
rt300@13
|
96 /// If defined, indicates that json may leverage CppTL library
|
rt300@13
|
97 //# define JSON_USE_CPPTL 1
|
rt300@13
|
98 /// If defined, indicates that cpptl vector based map should be used instead of std::map
|
rt300@13
|
99 /// as Value container.
|
rt300@13
|
100 //# define JSON_USE_CPPTL_SMALLMAP 1
|
rt300@13
|
101 /// If defined, indicates that Json specific container should be used
|
rt300@13
|
102 /// (hash table & simple deque container with customizable allocator).
|
rt300@13
|
103 /// THIS FEATURE IS STILL EXPERIMENTAL! There is know bugs: See #3177332
|
rt300@13
|
104 //# define JSON_VALUE_USE_INTERNAL_MAP 1
|
rt300@13
|
105 /// Force usage of standard new/malloc based allocator instead of memory pool based allocator.
|
rt300@13
|
106 /// The memory pools allocator used optimization (initializing Value and ValueInternalLink
|
rt300@13
|
107 /// as if it was a POD) that may cause some validation tool to report errors.
|
rt300@13
|
108 /// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined.
|
rt300@13
|
109 //# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
|
rt300@13
|
110
|
rt300@13
|
111 /// If defined, indicates that Json use exception to report invalid type manipulation
|
rt300@13
|
112 /// instead of C assert macro.
|
rt300@13
|
113 # define JSON_USE_EXCEPTION 1
|
rt300@13
|
114
|
rt300@13
|
115 /// If defined, indicates that the source file is amalgated
|
rt300@13
|
116 /// to prevent private header inclusion.
|
rt300@13
|
117 /// Remarks: it is automatically defined in the generated amalgated header.
|
rt300@13
|
118 // #define JSON_IS_AMALGAMATION
|
rt300@13
|
119
|
rt300@13
|
120
|
rt300@13
|
121 # ifdef JSON_IN_CPPTL
|
rt300@13
|
122 # include <cpptl/config.h>
|
rt300@13
|
123 # ifndef JSON_USE_CPPTL
|
rt300@13
|
124 # define JSON_USE_CPPTL 1
|
rt300@13
|
125 # endif
|
rt300@13
|
126 # endif
|
rt300@13
|
127
|
rt300@13
|
128 # ifdef JSON_IN_CPPTL
|
rt300@13
|
129 # define JSON_API CPPTL_API
|
rt300@13
|
130 # elif defined(JSON_DLL_BUILD)
|
rt300@13
|
131 # define JSON_API __declspec(dllexport)
|
rt300@13
|
132 # elif defined(JSON_DLL)
|
rt300@13
|
133 # define JSON_API __declspec(dllimport)
|
rt300@13
|
134 # else
|
rt300@13
|
135 # define JSON_API
|
rt300@13
|
136 # endif
|
rt300@13
|
137
|
rt300@13
|
138 // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer
|
rt300@13
|
139 // Storages, and 64 bits integer support is disabled.
|
rt300@13
|
140 // #define JSON_NO_INT64 1
|
rt300@13
|
141
|
rt300@13
|
142 #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
|
rt300@13
|
143 // Microsoft Visual Studio 6 only support conversion from __int64 to double
|
rt300@13
|
144 // (no conversion from unsigned __int64).
|
rt300@13
|
145 #define JSON_USE_INT64_DOUBLE_CONVERSION 1
|
rt300@13
|
146 #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
|
rt300@13
|
147
|
rt300@13
|
148 #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
|
rt300@13
|
149 /// Indicates that the following function is deprecated.
|
rt300@13
|
150 # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
|
rt300@13
|
151 #endif
|
rt300@13
|
152
|
rt300@13
|
153 #if !defined(JSONCPP_DEPRECATED)
|
rt300@13
|
154 # define JSONCPP_DEPRECATED(message)
|
rt300@13
|
155 #endif // if !defined(JSONCPP_DEPRECATED)
|
rt300@13
|
156
|
rt300@13
|
157 namespace Json {
|
rt300@13
|
158 typedef int Int;
|
rt300@13
|
159 typedef unsigned int UInt;
|
rt300@13
|
160 # if defined(JSON_NO_INT64)
|
rt300@13
|
161 typedef int LargestInt;
|
rt300@13
|
162 typedef unsigned int LargestUInt;
|
rt300@13
|
163 # undef JSON_HAS_INT64
|
rt300@13
|
164 # else // if defined(JSON_NO_INT64)
|
rt300@13
|
165 // For Microsoft Visual use specific types as long long is not supported
|
rt300@13
|
166 # if defined(_MSC_VER) // Microsoft Visual Studio
|
rt300@13
|
167 typedef __int64 Int64;
|
rt300@13
|
168 typedef unsigned __int64 UInt64;
|
rt300@13
|
169 # else // if defined(_MSC_VER) // Other platforms, use long long
|
rt300@13
|
170 typedef long long int Int64;
|
rt300@13
|
171 typedef unsigned long long int UInt64;
|
rt300@13
|
172 # endif // if defined(_MSC_VER)
|
rt300@13
|
173 typedef Int64 LargestInt;
|
rt300@13
|
174 typedef UInt64 LargestUInt;
|
rt300@13
|
175 # define JSON_HAS_INT64
|
rt300@13
|
176 # endif // if defined(JSON_NO_INT64)
|
rt300@13
|
177 } // end namespace Json
|
rt300@13
|
178
|
rt300@13
|
179
|
rt300@13
|
180 #endif // JSON_CONFIG_H_INCLUDED
|
rt300@13
|
181
|
rt300@13
|
182 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
183 // End of content of file: include/json/config.h
|
rt300@13
|
184 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
185
|
rt300@13
|
186
|
rt300@13
|
187
|
rt300@13
|
188
|
rt300@13
|
189
|
rt300@13
|
190
|
rt300@13
|
191 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
192 // Beginning of content of file: include/json/forwards.h
|
rt300@13
|
193 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
194
|
rt300@13
|
195 // Copyright 2007-2010 Baptiste Lepilleur
|
rt300@13
|
196 // Distributed under MIT license, or public domain if desired and
|
rt300@13
|
197 // recognized in your jurisdiction.
|
rt300@13
|
198 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
rt300@13
|
199
|
rt300@13
|
200 #ifndef JSON_FORWARDS_H_INCLUDED
|
rt300@13
|
201 # define JSON_FORWARDS_H_INCLUDED
|
rt300@13
|
202
|
rt300@13
|
203 #if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
204 # include "config.h"
|
rt300@13
|
205 #endif // if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
206
|
rt300@13
|
207 namespace Json {
|
rt300@13
|
208
|
rt300@13
|
209 // writer.h
|
rt300@13
|
210 class FastWriter;
|
rt300@13
|
211 class StyledWriter;
|
rt300@13
|
212
|
rt300@13
|
213 // reader.h
|
rt300@13
|
214 class Reader;
|
rt300@13
|
215
|
rt300@13
|
216 // features.h
|
rt300@13
|
217 class Features;
|
rt300@13
|
218
|
rt300@13
|
219 // value.h
|
rt300@13
|
220 typedef unsigned int ArrayIndex;
|
rt300@13
|
221 class StaticString;
|
rt300@13
|
222 class Path;
|
rt300@13
|
223 class PathArgument;
|
rt300@13
|
224 class Value;
|
rt300@13
|
225 class ValueIteratorBase;
|
rt300@13
|
226 class ValueIterator;
|
rt300@13
|
227 class ValueConstIterator;
|
rt300@13
|
228 #ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
229 class ValueMapAllocator;
|
rt300@13
|
230 class ValueInternalLink;
|
rt300@13
|
231 class ValueInternalArray;
|
rt300@13
|
232 class ValueInternalMap;
|
rt300@13
|
233 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
234
|
rt300@13
|
235 } // namespace Json
|
rt300@13
|
236
|
rt300@13
|
237
|
rt300@13
|
238 #endif // JSON_FORWARDS_H_INCLUDED
|
rt300@13
|
239
|
rt300@13
|
240 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
241 // End of content of file: include/json/forwards.h
|
rt300@13
|
242 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
243
|
rt300@13
|
244
|
rt300@13
|
245
|
rt300@13
|
246
|
rt300@13
|
247
|
rt300@13
|
248
|
rt300@13
|
249 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
250 // Beginning of content of file: include/json/features.h
|
rt300@13
|
251 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
252
|
rt300@13
|
253 // Copyright 2007-2010 Baptiste Lepilleur
|
rt300@13
|
254 // Distributed under MIT license, or public domain if desired and
|
rt300@13
|
255 // recognized in your jurisdiction.
|
rt300@13
|
256 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
rt300@13
|
257
|
rt300@13
|
258 #ifndef CPPTL_JSON_FEATURES_H_INCLUDED
|
rt300@13
|
259 # define CPPTL_JSON_FEATURES_H_INCLUDED
|
rt300@13
|
260
|
rt300@13
|
261 #if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
262 # include "forwards.h"
|
rt300@13
|
263 #endif // if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
264
|
rt300@13
|
265 namespace Json {
|
rt300@13
|
266
|
rt300@13
|
267 /** \brief Configuration passed to reader and writer.
|
rt300@13
|
268 * This configuration object can be used to force the Reader or Writer
|
rt300@13
|
269 * to behave in a standard conforming way.
|
rt300@13
|
270 */
|
rt300@13
|
271 class JSON_API Features
|
rt300@13
|
272 {
|
rt300@13
|
273 public:
|
rt300@13
|
274 /** \brief A configuration that allows all features and assumes all strings are UTF-8.
|
rt300@13
|
275 * - C & C++ comments are allowed
|
rt300@13
|
276 * - Root object can be any JSON value
|
rt300@13
|
277 * - Assumes Value strings are encoded in UTF-8
|
rt300@13
|
278 */
|
rt300@13
|
279 static Features all();
|
rt300@13
|
280
|
rt300@13
|
281 /** \brief A configuration that is strictly compatible with the JSON specification.
|
rt300@13
|
282 * - Comments are forbidden.
|
rt300@13
|
283 * - Root object must be either an array or an object value.
|
rt300@13
|
284 * - Assumes Value strings are encoded in UTF-8
|
rt300@13
|
285 */
|
rt300@13
|
286 static Features strictMode();
|
rt300@13
|
287
|
rt300@13
|
288 /** \brief Initialize the configuration like JsonConfig::allFeatures;
|
rt300@13
|
289 */
|
rt300@13
|
290 Features();
|
rt300@13
|
291
|
rt300@13
|
292 /// \c true if comments are allowed. Default: \c true.
|
rt300@13
|
293 bool allowComments_;
|
rt300@13
|
294
|
rt300@13
|
295 /// \c true if root must be either an array or an object value. Default: \c false.
|
rt300@13
|
296 bool strictRoot_;
|
rt300@13
|
297 };
|
rt300@13
|
298
|
rt300@13
|
299 } // namespace Json
|
rt300@13
|
300
|
rt300@13
|
301 #endif // CPPTL_JSON_FEATURES_H_INCLUDED
|
rt300@13
|
302
|
rt300@13
|
303 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
304 // End of content of file: include/json/features.h
|
rt300@13
|
305 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
306
|
rt300@13
|
307
|
rt300@13
|
308
|
rt300@13
|
309
|
rt300@13
|
310
|
rt300@13
|
311
|
rt300@13
|
312 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
313 // Beginning of content of file: include/json/value.h
|
rt300@13
|
314 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
315
|
rt300@13
|
316 // Copyright 2007-2010 Baptiste Lepilleur
|
rt300@13
|
317 // Distributed under MIT license, or public domain if desired and
|
rt300@13
|
318 // recognized in your jurisdiction.
|
rt300@13
|
319 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
rt300@13
|
320
|
rt300@13
|
321 #ifndef CPPTL_JSON_H_INCLUDED
|
rt300@13
|
322 # define CPPTL_JSON_H_INCLUDED
|
rt300@13
|
323
|
rt300@13
|
324 #if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
325 # include "forwards.h"
|
rt300@13
|
326 #endif // if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
327 # include <string>
|
rt300@13
|
328 # include <vector>
|
rt300@13
|
329
|
rt300@13
|
330 # ifndef JSON_USE_CPPTL_SMALLMAP
|
rt300@13
|
331 # include <map>
|
rt300@13
|
332 # else
|
rt300@13
|
333 # include <cpptl/smallmap.h>
|
rt300@13
|
334 # endif
|
rt300@13
|
335 # ifdef JSON_USE_CPPTL
|
rt300@13
|
336 # include <cpptl/forwards.h>
|
rt300@13
|
337 # endif
|
rt300@13
|
338
|
rt300@13
|
339 /** \brief JSON (JavaScript Object Notation).
|
rt300@13
|
340 */
|
rt300@13
|
341 namespace Json {
|
rt300@13
|
342
|
rt300@13
|
343 /** \brief Type of the value held by a Value object.
|
rt300@13
|
344 */
|
rt300@13
|
345 enum ValueType
|
rt300@13
|
346 {
|
rt300@13
|
347 nullValue = 0, ///< 'null' value
|
rt300@13
|
348 intValue, ///< signed integer value
|
rt300@13
|
349 uintValue, ///< unsigned integer value
|
rt300@13
|
350 realValue, ///< double value
|
rt300@13
|
351 stringValue, ///< UTF-8 string value
|
rt300@13
|
352 booleanValue, ///< bool value
|
rt300@13
|
353 arrayValue, ///< array value (ordered list)
|
rt300@13
|
354 objectValue ///< object value (collection of name/value pairs).
|
rt300@13
|
355 };
|
rt300@13
|
356
|
rt300@13
|
357 enum CommentPlacement
|
rt300@13
|
358 {
|
rt300@13
|
359 commentBefore = 0, ///< a comment placed on the line before a value
|
rt300@13
|
360 commentAfterOnSameLine, ///< a comment just after a value on the same line
|
rt300@13
|
361 commentAfter, ///< a comment on the line after a value (only make sense for root value)
|
rt300@13
|
362 numberOfCommentPlacement
|
rt300@13
|
363 };
|
rt300@13
|
364
|
rt300@13
|
365 //# ifdef JSON_USE_CPPTL
|
rt300@13
|
366 // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
|
rt300@13
|
367 // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
|
rt300@13
|
368 //# endif
|
rt300@13
|
369
|
rt300@13
|
370 /** \brief Lightweight wrapper to tag static string.
|
rt300@13
|
371 *
|
rt300@13
|
372 * Value constructor and objectValue member assignement takes advantage of the
|
rt300@13
|
373 * StaticString and avoid the cost of string duplication when storing the
|
rt300@13
|
374 * string or the member name.
|
rt300@13
|
375 *
|
rt300@13
|
376 * Example of usage:
|
rt300@13
|
377 * \code
|
rt300@13
|
378 * Json::Value aValue( StaticString("some text") );
|
rt300@13
|
379 * Json::Value object;
|
rt300@13
|
380 * static const StaticString code("code");
|
rt300@13
|
381 * object[code] = 1234;
|
rt300@13
|
382 * \endcode
|
rt300@13
|
383 */
|
rt300@13
|
384 class JSON_API StaticString
|
rt300@13
|
385 {
|
rt300@13
|
386 public:
|
rt300@13
|
387 explicit StaticString( const char *czstring )
|
rt300@13
|
388 : str_( czstring )
|
rt300@13
|
389 {
|
rt300@13
|
390 }
|
rt300@13
|
391
|
rt300@13
|
392 operator const char *() const
|
rt300@13
|
393 {
|
rt300@13
|
394 return str_;
|
rt300@13
|
395 }
|
rt300@13
|
396
|
rt300@13
|
397 const char *c_str() const
|
rt300@13
|
398 {
|
rt300@13
|
399 return str_;
|
rt300@13
|
400 }
|
rt300@13
|
401
|
rt300@13
|
402 private:
|
rt300@13
|
403 const char *str_;
|
rt300@13
|
404 };
|
rt300@13
|
405
|
rt300@13
|
406 /** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
|
rt300@13
|
407 *
|
rt300@13
|
408 * This class is a discriminated union wrapper that can represents a:
|
rt300@13
|
409 * - signed integer [range: Value::minInt - Value::maxInt]
|
rt300@13
|
410 * - unsigned integer (range: 0 - Value::maxUInt)
|
rt300@13
|
411 * - double
|
rt300@13
|
412 * - UTF-8 string
|
rt300@13
|
413 * - boolean
|
rt300@13
|
414 * - 'null'
|
rt300@13
|
415 * - an ordered list of Value
|
rt300@13
|
416 * - collection of name/value pairs (javascript object)
|
rt300@13
|
417 *
|
rt300@13
|
418 * The type of the held value is represented by a #ValueType and
|
rt300@13
|
419 * can be obtained using type().
|
rt300@13
|
420 *
|
rt300@13
|
421 * values of an #objectValue or #arrayValue can be accessed using operator[]() methods.
|
rt300@13
|
422 * Non const methods will automatically create the a #nullValue element
|
rt300@13
|
423 * if it does not exist.
|
rt300@13
|
424 * The sequence of an #arrayValue will be automatically resize and initialized
|
rt300@13
|
425 * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
|
rt300@13
|
426 *
|
rt300@13
|
427 * The get() methods can be used to obtanis default value in the case the required element
|
rt300@13
|
428 * does not exist.
|
rt300@13
|
429 *
|
rt300@13
|
430 * It is possible to iterate over the list of a #objectValue values using
|
rt300@13
|
431 * the getMemberNames() method.
|
rt300@13
|
432 */
|
rt300@13
|
433 class JSON_API Value
|
rt300@13
|
434 {
|
rt300@13
|
435 friend class ValueIteratorBase;
|
rt300@13
|
436 # ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
437 friend class ValueInternalLink;
|
rt300@13
|
438 friend class ValueInternalMap;
|
rt300@13
|
439 # endif
|
rt300@13
|
440 public:
|
rt300@13
|
441 typedef std::vector<std::string> Members;
|
rt300@13
|
442 typedef ValueIterator iterator;
|
rt300@13
|
443 typedef ValueConstIterator const_iterator;
|
rt300@13
|
444 typedef Json::UInt UInt;
|
rt300@13
|
445 typedef Json::Int Int;
|
rt300@13
|
446 # if defined(JSON_HAS_INT64)
|
rt300@13
|
447 typedef Json::UInt64 UInt64;
|
rt300@13
|
448 typedef Json::Int64 Int64;
|
rt300@13
|
449 #endif // defined(JSON_HAS_INT64)
|
rt300@13
|
450 typedef Json::LargestInt LargestInt;
|
rt300@13
|
451 typedef Json::LargestUInt LargestUInt;
|
rt300@13
|
452 typedef Json::ArrayIndex ArrayIndex;
|
rt300@13
|
453
|
rt300@13
|
454 static const Value null;
|
rt300@13
|
455 /// Minimum signed integer value that can be stored in a Json::Value.
|
rt300@13
|
456 static const LargestInt minLargestInt;
|
rt300@13
|
457 /// Maximum signed integer value that can be stored in a Json::Value.
|
rt300@13
|
458 static const LargestInt maxLargestInt;
|
rt300@13
|
459 /// Maximum unsigned integer value that can be stored in a Json::Value.
|
rt300@13
|
460 static const LargestUInt maxLargestUInt;
|
rt300@13
|
461
|
rt300@13
|
462 /// Minimum signed int value that can be stored in a Json::Value.
|
rt300@13
|
463 static const Int minInt;
|
rt300@13
|
464 /// Maximum signed int value that can be stored in a Json::Value.
|
rt300@13
|
465 static const Int maxInt;
|
rt300@13
|
466 /// Maximum unsigned int value that can be stored in a Json::Value.
|
rt300@13
|
467 static const UInt maxUInt;
|
rt300@13
|
468
|
rt300@13
|
469 /// Minimum signed 64 bits int value that can be stored in a Json::Value.
|
rt300@13
|
470 static const Int64 minInt64;
|
rt300@13
|
471 /// Maximum signed 64 bits int value that can be stored in a Json::Value.
|
rt300@13
|
472 static const Int64 maxInt64;
|
rt300@13
|
473 /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
|
rt300@13
|
474 static const UInt64 maxUInt64;
|
rt300@13
|
475
|
rt300@13
|
476 private:
|
rt300@13
|
477 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
rt300@13
|
478 # ifndef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
479 class CZString
|
rt300@13
|
480 {
|
rt300@13
|
481 public:
|
rt300@13
|
482 enum DuplicationPolicy
|
rt300@13
|
483 {
|
rt300@13
|
484 noDuplication = 0,
|
rt300@13
|
485 duplicate,
|
rt300@13
|
486 duplicateOnCopy
|
rt300@13
|
487 };
|
rt300@13
|
488 CZString( ArrayIndex index );
|
rt300@13
|
489 CZString( const char *cstr, DuplicationPolicy allocate );
|
rt300@13
|
490 CZString( const CZString &other );
|
rt300@13
|
491 ~CZString();
|
rt300@13
|
492 CZString &operator =( const CZString &other );
|
rt300@13
|
493 bool operator<( const CZString &other ) const;
|
rt300@13
|
494 bool operator==( const CZString &other ) const;
|
rt300@13
|
495 ArrayIndex index() const;
|
rt300@13
|
496 const char *c_str() const;
|
rt300@13
|
497 bool isStaticString() const;
|
rt300@13
|
498 private:
|
rt300@13
|
499 void swap( CZString &other );
|
rt300@13
|
500 const char *cstr_;
|
rt300@13
|
501 ArrayIndex index_;
|
rt300@13
|
502 };
|
rt300@13
|
503
|
rt300@13
|
504 public:
|
rt300@13
|
505 # ifndef JSON_USE_CPPTL_SMALLMAP
|
rt300@13
|
506 typedef std::map<CZString, Value> ObjectValues;
|
rt300@13
|
507 # else
|
rt300@13
|
508 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
|
rt300@13
|
509 # endif // ifndef JSON_USE_CPPTL_SMALLMAP
|
rt300@13
|
510 # endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
511 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
rt300@13
|
512
|
rt300@13
|
513 public:
|
rt300@13
|
514 /** \brief Create a default Value of the given type.
|
rt300@13
|
515
|
rt300@13
|
516 This is a very useful constructor.
|
rt300@13
|
517 To create an empty array, pass arrayValue.
|
rt300@13
|
518 To create an empty object, pass objectValue.
|
rt300@13
|
519 Another Value can then be set to this one by assignment.
|
rt300@13
|
520 This is useful since clear() and resize() will not alter types.
|
rt300@13
|
521
|
rt300@13
|
522 Examples:
|
rt300@13
|
523 \code
|
rt300@13
|
524 Json::Value null_value; // null
|
rt300@13
|
525 Json::Value arr_value(Json::arrayValue); // []
|
rt300@13
|
526 Json::Value obj_value(Json::objectValue); // {}
|
rt300@13
|
527 \endcode
|
rt300@13
|
528 */
|
rt300@13
|
529 Value( ValueType type = nullValue );
|
rt300@13
|
530 Value( Int value );
|
rt300@13
|
531 Value( UInt value );
|
rt300@13
|
532 #if defined(JSON_HAS_INT64)
|
rt300@13
|
533 Value( Int64 value );
|
rt300@13
|
534 Value( UInt64 value );
|
rt300@13
|
535 #endif // if defined(JSON_HAS_INT64)
|
rt300@13
|
536 Value( double value );
|
rt300@13
|
537 Value( const char *value );
|
rt300@13
|
538 Value( const char *beginValue, const char *endValue );
|
rt300@13
|
539 /** \brief Constructs a value from a static string.
|
rt300@13
|
540
|
rt300@13
|
541 * Like other value string constructor but do not duplicate the string for
|
rt300@13
|
542 * internal storage. The given string must remain alive after the call to this
|
rt300@13
|
543 * constructor.
|
rt300@13
|
544 * Example of usage:
|
rt300@13
|
545 * \code
|
rt300@13
|
546 * Json::Value aValue( StaticString("some text") );
|
rt300@13
|
547 * \endcode
|
rt300@13
|
548 */
|
rt300@13
|
549 Value( const StaticString &value );
|
rt300@13
|
550 Value( const std::string &value );
|
rt300@13
|
551 # ifdef JSON_USE_CPPTL
|
rt300@13
|
552 Value( const CppTL::ConstString &value );
|
rt300@13
|
553 # endif
|
rt300@13
|
554 Value( bool value );
|
rt300@13
|
555 Value( const Value &other );
|
rt300@13
|
556 ~Value();
|
rt300@13
|
557
|
rt300@13
|
558 Value &operator=( const Value &other );
|
rt300@13
|
559 /// Swap values.
|
rt300@13
|
560 /// \note Currently, comments are intentionally not swapped, for
|
rt300@13
|
561 /// both logic and efficiency.
|
rt300@13
|
562 void swap( Value &other );
|
rt300@13
|
563
|
rt300@13
|
564 ValueType type() const;
|
rt300@13
|
565
|
rt300@13
|
566 bool operator <( const Value &other ) const;
|
rt300@13
|
567 bool operator <=( const Value &other ) const;
|
rt300@13
|
568 bool operator >=( const Value &other ) const;
|
rt300@13
|
569 bool operator >( const Value &other ) const;
|
rt300@13
|
570
|
rt300@13
|
571 bool operator ==( const Value &other ) const;
|
rt300@13
|
572 bool operator !=( const Value &other ) const;
|
rt300@13
|
573
|
rt300@13
|
574 int compare( const Value &other ) const;
|
rt300@13
|
575
|
rt300@13
|
576 const char *asCString() const;
|
rt300@13
|
577 std::string asString() const;
|
rt300@13
|
578 # ifdef JSON_USE_CPPTL
|
rt300@13
|
579 CppTL::ConstString asConstString() const;
|
rt300@13
|
580 # endif
|
rt300@13
|
581 Int asInt() const;
|
rt300@13
|
582 UInt asUInt() const;
|
rt300@13
|
583 Int64 asInt64() const;
|
rt300@13
|
584 UInt64 asUInt64() const;
|
rt300@13
|
585 LargestInt asLargestInt() const;
|
rt300@13
|
586 LargestUInt asLargestUInt() const;
|
rt300@13
|
587 float asFloat() const;
|
rt300@13
|
588 double asDouble() const;
|
rt300@13
|
589 bool asBool() const;
|
rt300@13
|
590
|
rt300@13
|
591 bool isNull() const;
|
rt300@13
|
592 bool isBool() const;
|
rt300@13
|
593 bool isInt() const;
|
rt300@13
|
594 bool isUInt() const;
|
rt300@13
|
595 bool isIntegral() const;
|
rt300@13
|
596 bool isDouble() const;
|
rt300@13
|
597 bool isNumeric() const;
|
rt300@13
|
598 bool isString() const;
|
rt300@13
|
599 bool isArray() const;
|
rt300@13
|
600 bool isObject() const;
|
rt300@13
|
601
|
rt300@13
|
602 bool isConvertibleTo( ValueType other ) const;
|
rt300@13
|
603
|
rt300@13
|
604 /// Number of values in array or object
|
rt300@13
|
605 ArrayIndex size() const;
|
rt300@13
|
606
|
rt300@13
|
607 /// \brief Return true if empty array, empty object, or null;
|
rt300@13
|
608 /// otherwise, false.
|
rt300@13
|
609 bool empty() const;
|
rt300@13
|
610
|
rt300@13
|
611 /// Return isNull()
|
rt300@13
|
612 bool operator!() const;
|
rt300@13
|
613
|
rt300@13
|
614 /// Remove all object members and array elements.
|
rt300@13
|
615 /// \pre type() is arrayValue, objectValue, or nullValue
|
rt300@13
|
616 /// \post type() is unchanged
|
rt300@13
|
617 void clear();
|
rt300@13
|
618
|
rt300@13
|
619 /// Resize the array to size elements.
|
rt300@13
|
620 /// New elements are initialized to null.
|
rt300@13
|
621 /// May only be called on nullValue or arrayValue.
|
rt300@13
|
622 /// \pre type() is arrayValue or nullValue
|
rt300@13
|
623 /// \post type() is arrayValue
|
rt300@13
|
624 void resize( ArrayIndex size );
|
rt300@13
|
625
|
rt300@13
|
626 /// Access an array element (zero based index ).
|
rt300@13
|
627 /// If the array contains less than index element, then null value are inserted
|
rt300@13
|
628 /// in the array so that its size is index+1.
|
rt300@13
|
629 /// (You may need to say 'value[0u]' to get your compiler to distinguish
|
rt300@13
|
630 /// this from the operator[] which takes a string.)
|
rt300@13
|
631 Value &operator[]( ArrayIndex index );
|
rt300@13
|
632
|
rt300@13
|
633 /// Access an array element (zero based index ).
|
rt300@13
|
634 /// If the array contains less than index element, then null value are inserted
|
rt300@13
|
635 /// in the array so that its size is index+1.
|
rt300@13
|
636 /// (You may need to say 'value[0u]' to get your compiler to distinguish
|
rt300@13
|
637 /// this from the operator[] which takes a string.)
|
rt300@13
|
638 Value &operator[]( int index );
|
rt300@13
|
639
|
rt300@13
|
640 /// Access an array element (zero based index )
|
rt300@13
|
641 /// (You may need to say 'value[0u]' to get your compiler to distinguish
|
rt300@13
|
642 /// this from the operator[] which takes a string.)
|
rt300@13
|
643 const Value &operator[]( ArrayIndex index ) const;
|
rt300@13
|
644
|
rt300@13
|
645 /// Access an array element (zero based index )
|
rt300@13
|
646 /// (You may need to say 'value[0u]' to get your compiler to distinguish
|
rt300@13
|
647 /// this from the operator[] which takes a string.)
|
rt300@13
|
648 const Value &operator[]( int index ) const;
|
rt300@13
|
649
|
rt300@13
|
650 /// If the array contains at least index+1 elements, returns the element value,
|
rt300@13
|
651 /// otherwise returns defaultValue.
|
rt300@13
|
652 Value get( ArrayIndex index,
|
rt300@13
|
653 const Value &defaultValue ) const;
|
rt300@13
|
654 /// Return true if index < size().
|
rt300@13
|
655 bool isValidIndex( ArrayIndex index ) const;
|
rt300@13
|
656 /// \brief Append value to array at the end.
|
rt300@13
|
657 ///
|
rt300@13
|
658 /// Equivalent to jsonvalue[jsonvalue.size()] = value;
|
rt300@13
|
659 Value &append( const Value &value );
|
rt300@13
|
660
|
rt300@13
|
661 /// Access an object value by name, create a null member if it does not exist.
|
rt300@13
|
662 Value &operator[]( const char *key );
|
rt300@13
|
663 /// Access an object value by name, returns null if there is no member with that name.
|
rt300@13
|
664 const Value &operator[]( const char *key ) const;
|
rt300@13
|
665 /// Access an object value by name, create a null member if it does not exist.
|
rt300@13
|
666 Value &operator[]( const std::string &key );
|
rt300@13
|
667 /// Access an object value by name, returns null if there is no member with that name.
|
rt300@13
|
668 const Value &operator[]( const std::string &key ) const;
|
rt300@13
|
669 /** \brief Access an object value by name, create a null member if it does not exist.
|
rt300@13
|
670
|
rt300@13
|
671 * If the object as no entry for that name, then the member name used to store
|
rt300@13
|
672 * the new entry is not duplicated.
|
rt300@13
|
673 * Example of use:
|
rt300@13
|
674 * \code
|
rt300@13
|
675 * Json::Value object;
|
rt300@13
|
676 * static const StaticString code("code");
|
rt300@13
|
677 * object[code] = 1234;
|
rt300@13
|
678 * \endcode
|
rt300@13
|
679 */
|
rt300@13
|
680 Value &operator[]( const StaticString &key );
|
rt300@13
|
681 # ifdef JSON_USE_CPPTL
|
rt300@13
|
682 /// Access an object value by name, create a null member if it does not exist.
|
rt300@13
|
683 Value &operator[]( const CppTL::ConstString &key );
|
rt300@13
|
684 /// Access an object value by name, returns null if there is no member with that name.
|
rt300@13
|
685 const Value &operator[]( const CppTL::ConstString &key ) const;
|
rt300@13
|
686 # endif
|
rt300@13
|
687 /// Return the member named key if it exist, defaultValue otherwise.
|
rt300@13
|
688 Value get( const char *key,
|
rt300@13
|
689 const Value &defaultValue ) const;
|
rt300@13
|
690 /// Return the member named key if it exist, defaultValue otherwise.
|
rt300@13
|
691 Value get( const std::string &key,
|
rt300@13
|
692 const Value &defaultValue ) const;
|
rt300@13
|
693 # ifdef JSON_USE_CPPTL
|
rt300@13
|
694 /// Return the member named key if it exist, defaultValue otherwise.
|
rt300@13
|
695 Value get( const CppTL::ConstString &key,
|
rt300@13
|
696 const Value &defaultValue ) const;
|
rt300@13
|
697 # endif
|
rt300@13
|
698 /// \brief Remove and return the named member.
|
rt300@13
|
699 ///
|
rt300@13
|
700 /// Do nothing if it did not exist.
|
rt300@13
|
701 /// \return the removed Value, or null.
|
rt300@13
|
702 /// \pre type() is objectValue or nullValue
|
rt300@13
|
703 /// \post type() is unchanged
|
rt300@13
|
704 Value removeMember( const char* key );
|
rt300@13
|
705 /// Same as removeMember(const char*)
|
rt300@13
|
706 Value removeMember( const std::string &key );
|
rt300@13
|
707
|
rt300@13
|
708 /// Return true if the object has a member named key.
|
rt300@13
|
709 bool isMember( const char *key ) const;
|
rt300@13
|
710 /// Return true if the object has a member named key.
|
rt300@13
|
711 bool isMember( const std::string &key ) const;
|
rt300@13
|
712 # ifdef JSON_USE_CPPTL
|
rt300@13
|
713 /// Return true if the object has a member named key.
|
rt300@13
|
714 bool isMember( const CppTL::ConstString &key ) const;
|
rt300@13
|
715 # endif
|
rt300@13
|
716
|
rt300@13
|
717 /// \brief Return a list of the member names.
|
rt300@13
|
718 ///
|
rt300@13
|
719 /// If null, return an empty list.
|
rt300@13
|
720 /// \pre type() is objectValue or nullValue
|
rt300@13
|
721 /// \post if type() was nullValue, it remains nullValue
|
rt300@13
|
722 Members getMemberNames() const;
|
rt300@13
|
723
|
rt300@13
|
724 //# ifdef JSON_USE_CPPTL
|
rt300@13
|
725 // EnumMemberNames enumMemberNames() const;
|
rt300@13
|
726 // EnumValues enumValues() const;
|
rt300@13
|
727 //# endif
|
rt300@13
|
728
|
rt300@13
|
729 /// Comments must be //... or /* ... */
|
rt300@13
|
730 void setComment( const char *comment,
|
rt300@13
|
731 CommentPlacement placement );
|
rt300@13
|
732 /// Comments must be //... or /* ... */
|
rt300@13
|
733 void setComment( const std::string &comment,
|
rt300@13
|
734 CommentPlacement placement );
|
rt300@13
|
735 bool hasComment( CommentPlacement placement ) const;
|
rt300@13
|
736 /// Include delimiters and embedded newlines.
|
rt300@13
|
737 std::string getComment( CommentPlacement placement ) const;
|
rt300@13
|
738
|
rt300@13
|
739 std::string toStyledString() const;
|
rt300@13
|
740
|
rt300@13
|
741 const_iterator begin() const;
|
rt300@13
|
742 const_iterator end() const;
|
rt300@13
|
743
|
rt300@13
|
744 iterator begin();
|
rt300@13
|
745 iterator end();
|
rt300@13
|
746
|
rt300@13
|
747 private:
|
rt300@13
|
748 Value &resolveReference( const char *key,
|
rt300@13
|
749 bool isStatic );
|
rt300@13
|
750
|
rt300@13
|
751 # ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
752 inline bool isItemAvailable() const
|
rt300@13
|
753 {
|
rt300@13
|
754 return itemIsUsed_ == 0;
|
rt300@13
|
755 }
|
rt300@13
|
756
|
rt300@13
|
757 inline void setItemUsed( bool isUsed = true )
|
rt300@13
|
758 {
|
rt300@13
|
759 itemIsUsed_ = isUsed ? 1 : 0;
|
rt300@13
|
760 }
|
rt300@13
|
761
|
rt300@13
|
762 inline bool isMemberNameStatic() const
|
rt300@13
|
763 {
|
rt300@13
|
764 return memberNameIsStatic_ == 0;
|
rt300@13
|
765 }
|
rt300@13
|
766
|
rt300@13
|
767 inline void setMemberNameIsStatic( bool isStatic )
|
rt300@13
|
768 {
|
rt300@13
|
769 memberNameIsStatic_ = isStatic ? 1 : 0;
|
rt300@13
|
770 }
|
rt300@13
|
771 # endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
772
|
rt300@13
|
773 private:
|
rt300@13
|
774 struct CommentInfo
|
rt300@13
|
775 {
|
rt300@13
|
776 CommentInfo();
|
rt300@13
|
777 ~CommentInfo();
|
rt300@13
|
778
|
rt300@13
|
779 void setComment( const char *text );
|
rt300@13
|
780
|
rt300@13
|
781 char *comment_;
|
rt300@13
|
782 };
|
rt300@13
|
783
|
rt300@13
|
784 //struct MemberNamesTransform
|
rt300@13
|
785 //{
|
rt300@13
|
786 // typedef const char *result_type;
|
rt300@13
|
787 // const char *operator()( const CZString &name ) const
|
rt300@13
|
788 // {
|
rt300@13
|
789 // return name.c_str();
|
rt300@13
|
790 // }
|
rt300@13
|
791 //};
|
rt300@13
|
792
|
rt300@13
|
793 union ValueHolder
|
rt300@13
|
794 {
|
rt300@13
|
795 LargestInt int_;
|
rt300@13
|
796 LargestUInt uint_;
|
rt300@13
|
797 double real_;
|
rt300@13
|
798 bool bool_;
|
rt300@13
|
799 char *string_;
|
rt300@13
|
800 # ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
801 ValueInternalArray *array_;
|
rt300@13
|
802 ValueInternalMap *map_;
|
rt300@13
|
803 #else
|
rt300@13
|
804 ObjectValues *map_;
|
rt300@13
|
805 # endif
|
rt300@13
|
806 } value_;
|
rt300@13
|
807 ValueType type_ : 8;
|
rt300@13
|
808 int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
|
rt300@13
|
809 # ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
810 unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
|
rt300@13
|
811 int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
|
rt300@13
|
812 # endif
|
rt300@13
|
813 CommentInfo *comments_;
|
rt300@13
|
814 };
|
rt300@13
|
815
|
rt300@13
|
816
|
rt300@13
|
817 /** \brief Experimental and untested: represents an element of the "path" to access a node.
|
rt300@13
|
818 */
|
rt300@13
|
819 class PathArgument
|
rt300@13
|
820 {
|
rt300@13
|
821 public:
|
rt300@13
|
822 friend class Path;
|
rt300@13
|
823
|
rt300@13
|
824 PathArgument();
|
rt300@13
|
825 PathArgument( ArrayIndex index );
|
rt300@13
|
826 PathArgument( const char *key );
|
rt300@13
|
827 PathArgument( const std::string &key );
|
rt300@13
|
828
|
rt300@13
|
829 private:
|
rt300@13
|
830 enum Kind
|
rt300@13
|
831 {
|
rt300@13
|
832 kindNone = 0,
|
rt300@13
|
833 kindIndex,
|
rt300@13
|
834 kindKey
|
rt300@13
|
835 };
|
rt300@13
|
836 std::string key_;
|
rt300@13
|
837 ArrayIndex index_;
|
rt300@13
|
838 Kind kind_;
|
rt300@13
|
839 };
|
rt300@13
|
840
|
rt300@13
|
841 /** \brief Experimental and untested: represents a "path" to access a node.
|
rt300@13
|
842 *
|
rt300@13
|
843 * Syntax:
|
rt300@13
|
844 * - "." => root node
|
rt300@13
|
845 * - ".[n]" => elements at index 'n' of root node (an array value)
|
rt300@13
|
846 * - ".name" => member named 'name' of root node (an object value)
|
rt300@13
|
847 * - ".name1.name2.name3"
|
rt300@13
|
848 * - ".[0][1][2].name1[3]"
|
rt300@13
|
849 * - ".%" => member name is provided as parameter
|
rt300@13
|
850 * - ".[%]" => index is provied as parameter
|
rt300@13
|
851 */
|
rt300@13
|
852 class Path
|
rt300@13
|
853 {
|
rt300@13
|
854 public:
|
rt300@13
|
855 Path( const std::string &path,
|
rt300@13
|
856 const PathArgument &a1 = PathArgument(),
|
rt300@13
|
857 const PathArgument &a2 = PathArgument(),
|
rt300@13
|
858 const PathArgument &a3 = PathArgument(),
|
rt300@13
|
859 const PathArgument &a4 = PathArgument(),
|
rt300@13
|
860 const PathArgument &a5 = PathArgument() );
|
rt300@13
|
861
|
rt300@13
|
862 const Value &resolve( const Value &root ) const;
|
rt300@13
|
863 Value resolve( const Value &root,
|
rt300@13
|
864 const Value &defaultValue ) const;
|
rt300@13
|
865 /// Creates the "path" to access the specified node and returns a reference on the node.
|
rt300@13
|
866 Value &make( Value &root ) const;
|
rt300@13
|
867
|
rt300@13
|
868 private:
|
rt300@13
|
869 typedef std::vector<const PathArgument *> InArgs;
|
rt300@13
|
870 typedef std::vector<PathArgument> Args;
|
rt300@13
|
871
|
rt300@13
|
872 void makePath( const std::string &path,
|
rt300@13
|
873 const InArgs &in );
|
rt300@13
|
874 void addPathInArg( const std::string &path,
|
rt300@13
|
875 const InArgs &in,
|
rt300@13
|
876 InArgs::const_iterator &itInArg,
|
rt300@13
|
877 PathArgument::Kind kind );
|
rt300@13
|
878 void invalidPath( const std::string &path,
|
rt300@13
|
879 int location );
|
rt300@13
|
880
|
rt300@13
|
881 Args args_;
|
rt300@13
|
882 };
|
rt300@13
|
883
|
rt300@13
|
884
|
rt300@13
|
885
|
rt300@13
|
886 #ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
887 /** \brief Allocator to customize Value internal map.
|
rt300@13
|
888 * Below is an example of a simple implementation (default implementation actually
|
rt300@13
|
889 * use memory pool for speed).
|
rt300@13
|
890 * \code
|
rt300@13
|
891 class DefaultValueMapAllocator : public ValueMapAllocator
|
rt300@13
|
892 {
|
rt300@13
|
893 public: // overridden from ValueMapAllocator
|
rt300@13
|
894 virtual ValueInternalMap *newMap()
|
rt300@13
|
895 {
|
rt300@13
|
896 return new ValueInternalMap();
|
rt300@13
|
897 }
|
rt300@13
|
898
|
rt300@13
|
899 virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other )
|
rt300@13
|
900 {
|
rt300@13
|
901 return new ValueInternalMap( other );
|
rt300@13
|
902 }
|
rt300@13
|
903
|
rt300@13
|
904 virtual void destructMap( ValueInternalMap *map )
|
rt300@13
|
905 {
|
rt300@13
|
906 delete map;
|
rt300@13
|
907 }
|
rt300@13
|
908
|
rt300@13
|
909 virtual ValueInternalLink *allocateMapBuckets( unsigned int size )
|
rt300@13
|
910 {
|
rt300@13
|
911 return new ValueInternalLink[size];
|
rt300@13
|
912 }
|
rt300@13
|
913
|
rt300@13
|
914 virtual void releaseMapBuckets( ValueInternalLink *links )
|
rt300@13
|
915 {
|
rt300@13
|
916 delete [] links;
|
rt300@13
|
917 }
|
rt300@13
|
918
|
rt300@13
|
919 virtual ValueInternalLink *allocateMapLink()
|
rt300@13
|
920 {
|
rt300@13
|
921 return new ValueInternalLink();
|
rt300@13
|
922 }
|
rt300@13
|
923
|
rt300@13
|
924 virtual void releaseMapLink( ValueInternalLink *link )
|
rt300@13
|
925 {
|
rt300@13
|
926 delete link;
|
rt300@13
|
927 }
|
rt300@13
|
928 };
|
rt300@13
|
929 * \endcode
|
rt300@13
|
930 */
|
rt300@13
|
931 class JSON_API ValueMapAllocator
|
rt300@13
|
932 {
|
rt300@13
|
933 public:
|
rt300@13
|
934 virtual ~ValueMapAllocator();
|
rt300@13
|
935 virtual ValueInternalMap *newMap() = 0;
|
rt300@13
|
936 virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0;
|
rt300@13
|
937 virtual void destructMap( ValueInternalMap *map ) = 0;
|
rt300@13
|
938 virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0;
|
rt300@13
|
939 virtual void releaseMapBuckets( ValueInternalLink *links ) = 0;
|
rt300@13
|
940 virtual ValueInternalLink *allocateMapLink() = 0;
|
rt300@13
|
941 virtual void releaseMapLink( ValueInternalLink *link ) = 0;
|
rt300@13
|
942 };
|
rt300@13
|
943
|
rt300@13
|
944 /** \brief ValueInternalMap hash-map bucket chain link (for internal use only).
|
rt300@13
|
945 * \internal previous_ & next_ allows for bidirectional traversal.
|
rt300@13
|
946 */
|
rt300@13
|
947 class JSON_API ValueInternalLink
|
rt300@13
|
948 {
|
rt300@13
|
949 public:
|
rt300@13
|
950 enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture.
|
rt300@13
|
951 enum InternalFlags {
|
rt300@13
|
952 flagAvailable = 0,
|
rt300@13
|
953 flagUsed = 1
|
rt300@13
|
954 };
|
rt300@13
|
955
|
rt300@13
|
956 ValueInternalLink();
|
rt300@13
|
957
|
rt300@13
|
958 ~ValueInternalLink();
|
rt300@13
|
959
|
rt300@13
|
960 Value items_[itemPerLink];
|
rt300@13
|
961 char *keys_[itemPerLink];
|
rt300@13
|
962 ValueInternalLink *previous_;
|
rt300@13
|
963 ValueInternalLink *next_;
|
rt300@13
|
964 };
|
rt300@13
|
965
|
rt300@13
|
966
|
rt300@13
|
967 /** \brief A linked page based hash-table implementation used internally by Value.
|
rt300@13
|
968 * \internal ValueInternalMap is a tradional bucket based hash-table, with a linked
|
rt300@13
|
969 * list in each bucket to handle collision. There is an addional twist in that
|
rt300@13
|
970 * each node of the collision linked list is a page containing a fixed amount of
|
rt300@13
|
971 * value. This provides a better compromise between memory usage and speed.
|
rt300@13
|
972 *
|
rt300@13
|
973 * Each bucket is made up of a chained list of ValueInternalLink. The last
|
rt300@13
|
974 * link of a given bucket can be found in the 'previous_' field of the following bucket.
|
rt300@13
|
975 * The last link of the last bucket is stored in tailLink_ as it has no following bucket.
|
rt300@13
|
976 * Only the last link of a bucket may contains 'available' item. The last link always
|
rt300@13
|
977 * contains at least one element unless is it the bucket one very first link.
|
rt300@13
|
978 */
|
rt300@13
|
979 class JSON_API ValueInternalMap
|
rt300@13
|
980 {
|
rt300@13
|
981 friend class ValueIteratorBase;
|
rt300@13
|
982 friend class Value;
|
rt300@13
|
983 public:
|
rt300@13
|
984 typedef unsigned int HashKey;
|
rt300@13
|
985 typedef unsigned int BucketIndex;
|
rt300@13
|
986
|
rt300@13
|
987 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
rt300@13
|
988 struct IteratorState
|
rt300@13
|
989 {
|
rt300@13
|
990 IteratorState()
|
rt300@13
|
991 : map_(0)
|
rt300@13
|
992 , link_(0)
|
rt300@13
|
993 , itemIndex_(0)
|
rt300@13
|
994 , bucketIndex_(0)
|
rt300@13
|
995 {
|
rt300@13
|
996 }
|
rt300@13
|
997 ValueInternalMap *map_;
|
rt300@13
|
998 ValueInternalLink *link_;
|
rt300@13
|
999 BucketIndex itemIndex_;
|
rt300@13
|
1000 BucketIndex bucketIndex_;
|
rt300@13
|
1001 };
|
rt300@13
|
1002 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
rt300@13
|
1003
|
rt300@13
|
1004 ValueInternalMap();
|
rt300@13
|
1005 ValueInternalMap( const ValueInternalMap &other );
|
rt300@13
|
1006 ValueInternalMap &operator =( const ValueInternalMap &other );
|
rt300@13
|
1007 ~ValueInternalMap();
|
rt300@13
|
1008
|
rt300@13
|
1009 void swap( ValueInternalMap &other );
|
rt300@13
|
1010
|
rt300@13
|
1011 BucketIndex size() const;
|
rt300@13
|
1012
|
rt300@13
|
1013 void clear();
|
rt300@13
|
1014
|
rt300@13
|
1015 bool reserveDelta( BucketIndex growth );
|
rt300@13
|
1016
|
rt300@13
|
1017 bool reserve( BucketIndex newItemCount );
|
rt300@13
|
1018
|
rt300@13
|
1019 const Value *find( const char *key ) const;
|
rt300@13
|
1020
|
rt300@13
|
1021 Value *find( const char *key );
|
rt300@13
|
1022
|
rt300@13
|
1023 Value &resolveReference( const char *key,
|
rt300@13
|
1024 bool isStatic );
|
rt300@13
|
1025
|
rt300@13
|
1026 void remove( const char *key );
|
rt300@13
|
1027
|
rt300@13
|
1028 void doActualRemove( ValueInternalLink *link,
|
rt300@13
|
1029 BucketIndex index,
|
rt300@13
|
1030 BucketIndex bucketIndex );
|
rt300@13
|
1031
|
rt300@13
|
1032 ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex );
|
rt300@13
|
1033
|
rt300@13
|
1034 Value &setNewItem( const char *key,
|
rt300@13
|
1035 bool isStatic,
|
rt300@13
|
1036 ValueInternalLink *link,
|
rt300@13
|
1037 BucketIndex index );
|
rt300@13
|
1038
|
rt300@13
|
1039 Value &unsafeAdd( const char *key,
|
rt300@13
|
1040 bool isStatic,
|
rt300@13
|
1041 HashKey hashedKey );
|
rt300@13
|
1042
|
rt300@13
|
1043 HashKey hash( const char *key ) const;
|
rt300@13
|
1044
|
rt300@13
|
1045 int compare( const ValueInternalMap &other ) const;
|
rt300@13
|
1046
|
rt300@13
|
1047 private:
|
rt300@13
|
1048 void makeBeginIterator( IteratorState &it ) const;
|
rt300@13
|
1049 void makeEndIterator( IteratorState &it ) const;
|
rt300@13
|
1050 static bool equals( const IteratorState &x, const IteratorState &other );
|
rt300@13
|
1051 static void increment( IteratorState &iterator );
|
rt300@13
|
1052 static void incrementBucket( IteratorState &iterator );
|
rt300@13
|
1053 static void decrement( IteratorState &iterator );
|
rt300@13
|
1054 static const char *key( const IteratorState &iterator );
|
rt300@13
|
1055 static const char *key( const IteratorState &iterator, bool &isStatic );
|
rt300@13
|
1056 static Value &value( const IteratorState &iterator );
|
rt300@13
|
1057 static int distance( const IteratorState &x, const IteratorState &y );
|
rt300@13
|
1058
|
rt300@13
|
1059 private:
|
rt300@13
|
1060 ValueInternalLink *buckets_;
|
rt300@13
|
1061 ValueInternalLink *tailLink_;
|
rt300@13
|
1062 BucketIndex bucketsSize_;
|
rt300@13
|
1063 BucketIndex itemCount_;
|
rt300@13
|
1064 };
|
rt300@13
|
1065
|
rt300@13
|
1066 /** \brief A simplified deque implementation used internally by Value.
|
rt300@13
|
1067 * \internal
|
rt300@13
|
1068 * It is based on a list of fixed "page", each page contains a fixed number of items.
|
rt300@13
|
1069 * Instead of using a linked-list, a array of pointer is used for fast item look-up.
|
rt300@13
|
1070 * Look-up for an element is as follow:
|
rt300@13
|
1071 * - compute page index: pageIndex = itemIndex / itemsPerPage
|
rt300@13
|
1072 * - look-up item in page: pages_[pageIndex][itemIndex % itemsPerPage]
|
rt300@13
|
1073 *
|
rt300@13
|
1074 * Insertion is amortized constant time (only the array containing the index of pointers
|
rt300@13
|
1075 * need to be reallocated when items are appended).
|
rt300@13
|
1076 */
|
rt300@13
|
1077 class JSON_API ValueInternalArray
|
rt300@13
|
1078 {
|
rt300@13
|
1079 friend class Value;
|
rt300@13
|
1080 friend class ValueIteratorBase;
|
rt300@13
|
1081 public:
|
rt300@13
|
1082 enum { itemsPerPage = 8 }; // should be a power of 2 for fast divide and modulo.
|
rt300@13
|
1083 typedef Value::ArrayIndex ArrayIndex;
|
rt300@13
|
1084 typedef unsigned int PageIndex;
|
rt300@13
|
1085
|
rt300@13
|
1086 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
rt300@13
|
1087 struct IteratorState // Must be a POD
|
rt300@13
|
1088 {
|
rt300@13
|
1089 IteratorState()
|
rt300@13
|
1090 : array_(0)
|
rt300@13
|
1091 , currentPageIndex_(0)
|
rt300@13
|
1092 , currentItemIndex_(0)
|
rt300@13
|
1093 {
|
rt300@13
|
1094 }
|
rt300@13
|
1095 ValueInternalArray *array_;
|
rt300@13
|
1096 Value **currentPageIndex_;
|
rt300@13
|
1097 unsigned int currentItemIndex_;
|
rt300@13
|
1098 };
|
rt300@13
|
1099 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
rt300@13
|
1100
|
rt300@13
|
1101 ValueInternalArray();
|
rt300@13
|
1102 ValueInternalArray( const ValueInternalArray &other );
|
rt300@13
|
1103 ValueInternalArray &operator =( const ValueInternalArray &other );
|
rt300@13
|
1104 ~ValueInternalArray();
|
rt300@13
|
1105 void swap( ValueInternalArray &other );
|
rt300@13
|
1106
|
rt300@13
|
1107 void clear();
|
rt300@13
|
1108 void resize( ArrayIndex newSize );
|
rt300@13
|
1109
|
rt300@13
|
1110 Value &resolveReference( ArrayIndex index );
|
rt300@13
|
1111
|
rt300@13
|
1112 Value *find( ArrayIndex index ) const;
|
rt300@13
|
1113
|
rt300@13
|
1114 ArrayIndex size() const;
|
rt300@13
|
1115
|
rt300@13
|
1116 int compare( const ValueInternalArray &other ) const;
|
rt300@13
|
1117
|
rt300@13
|
1118 private:
|
rt300@13
|
1119 static bool equals( const IteratorState &x, const IteratorState &other );
|
rt300@13
|
1120 static void increment( IteratorState &iterator );
|
rt300@13
|
1121 static void decrement( IteratorState &iterator );
|
rt300@13
|
1122 static Value &dereference( const IteratorState &iterator );
|
rt300@13
|
1123 static Value &unsafeDereference( const IteratorState &iterator );
|
rt300@13
|
1124 static int distance( const IteratorState &x, const IteratorState &y );
|
rt300@13
|
1125 static ArrayIndex indexOf( const IteratorState &iterator );
|
rt300@13
|
1126 void makeBeginIterator( IteratorState &it ) const;
|
rt300@13
|
1127 void makeEndIterator( IteratorState &it ) const;
|
rt300@13
|
1128 void makeIterator( IteratorState &it, ArrayIndex index ) const;
|
rt300@13
|
1129
|
rt300@13
|
1130 void makeIndexValid( ArrayIndex index );
|
rt300@13
|
1131
|
rt300@13
|
1132 Value **pages_;
|
rt300@13
|
1133 ArrayIndex size_;
|
rt300@13
|
1134 PageIndex pageCount_;
|
rt300@13
|
1135 };
|
rt300@13
|
1136
|
rt300@13
|
1137 /** \brief Experimental: do not use. Allocator to customize Value internal array.
|
rt300@13
|
1138 * Below is an example of a simple implementation (actual implementation use
|
rt300@13
|
1139 * memory pool).
|
rt300@13
|
1140 \code
|
rt300@13
|
1141 class DefaultValueArrayAllocator : public ValueArrayAllocator
|
rt300@13
|
1142 {
|
rt300@13
|
1143 public: // overridden from ValueArrayAllocator
|
rt300@13
|
1144 virtual ~DefaultValueArrayAllocator()
|
rt300@13
|
1145 {
|
rt300@13
|
1146 }
|
rt300@13
|
1147
|
rt300@13
|
1148 virtual ValueInternalArray *newArray()
|
rt300@13
|
1149 {
|
rt300@13
|
1150 return new ValueInternalArray();
|
rt300@13
|
1151 }
|
rt300@13
|
1152
|
rt300@13
|
1153 virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other )
|
rt300@13
|
1154 {
|
rt300@13
|
1155 return new ValueInternalArray( other );
|
rt300@13
|
1156 }
|
rt300@13
|
1157
|
rt300@13
|
1158 virtual void destruct( ValueInternalArray *array )
|
rt300@13
|
1159 {
|
rt300@13
|
1160 delete array;
|
rt300@13
|
1161 }
|
rt300@13
|
1162
|
rt300@13
|
1163 virtual void reallocateArrayPageIndex( Value **&indexes,
|
rt300@13
|
1164 ValueInternalArray::PageIndex &indexCount,
|
rt300@13
|
1165 ValueInternalArray::PageIndex minNewIndexCount )
|
rt300@13
|
1166 {
|
rt300@13
|
1167 ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1;
|
rt300@13
|
1168 if ( minNewIndexCount > newIndexCount )
|
rt300@13
|
1169 newIndexCount = minNewIndexCount;
|
rt300@13
|
1170 void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount );
|
rt300@13
|
1171 if ( !newIndexes )
|
rt300@13
|
1172 throw std::bad_alloc();
|
rt300@13
|
1173 indexCount = newIndexCount;
|
rt300@13
|
1174 indexes = static_cast<Value **>( newIndexes );
|
rt300@13
|
1175 }
|
rt300@13
|
1176 virtual void releaseArrayPageIndex( Value **indexes,
|
rt300@13
|
1177 ValueInternalArray::PageIndex indexCount )
|
rt300@13
|
1178 {
|
rt300@13
|
1179 if ( indexes )
|
rt300@13
|
1180 free( indexes );
|
rt300@13
|
1181 }
|
rt300@13
|
1182
|
rt300@13
|
1183 virtual Value *allocateArrayPage()
|
rt300@13
|
1184 {
|
rt300@13
|
1185 return static_cast<Value *>( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) );
|
rt300@13
|
1186 }
|
rt300@13
|
1187
|
rt300@13
|
1188 virtual void releaseArrayPage( Value *value )
|
rt300@13
|
1189 {
|
rt300@13
|
1190 if ( value )
|
rt300@13
|
1191 free( value );
|
rt300@13
|
1192 }
|
rt300@13
|
1193 };
|
rt300@13
|
1194 \endcode
|
rt300@13
|
1195 */
|
rt300@13
|
1196 class JSON_API ValueArrayAllocator
|
rt300@13
|
1197 {
|
rt300@13
|
1198 public:
|
rt300@13
|
1199 virtual ~ValueArrayAllocator();
|
rt300@13
|
1200 virtual ValueInternalArray *newArray() = 0;
|
rt300@13
|
1201 virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0;
|
rt300@13
|
1202 virtual void destructArray( ValueInternalArray *array ) = 0;
|
rt300@13
|
1203 /** \brief Reallocate array page index.
|
rt300@13
|
1204 * Reallocates an array of pointer on each page.
|
rt300@13
|
1205 * \param indexes [input] pointer on the current index. May be \c NULL.
|
rt300@13
|
1206 * [output] pointer on the new index of at least
|
rt300@13
|
1207 * \a minNewIndexCount pages.
|
rt300@13
|
1208 * \param indexCount [input] current number of pages in the index.
|
rt300@13
|
1209 * [output] number of page the reallocated index can handle.
|
rt300@13
|
1210 * \b MUST be >= \a minNewIndexCount.
|
rt300@13
|
1211 * \param minNewIndexCount Minimum number of page the new index must be able to
|
rt300@13
|
1212 * handle.
|
rt300@13
|
1213 */
|
rt300@13
|
1214 virtual void reallocateArrayPageIndex( Value **&indexes,
|
rt300@13
|
1215 ValueInternalArray::PageIndex &indexCount,
|
rt300@13
|
1216 ValueInternalArray::PageIndex minNewIndexCount ) = 0;
|
rt300@13
|
1217 virtual void releaseArrayPageIndex( Value **indexes,
|
rt300@13
|
1218 ValueInternalArray::PageIndex indexCount ) = 0;
|
rt300@13
|
1219 virtual Value *allocateArrayPage() = 0;
|
rt300@13
|
1220 virtual void releaseArrayPage( Value *value ) = 0;
|
rt300@13
|
1221 };
|
rt300@13
|
1222 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
1223
|
rt300@13
|
1224
|
rt300@13
|
1225 /** \brief base class for Value iterators.
|
rt300@13
|
1226 *
|
rt300@13
|
1227 */
|
rt300@13
|
1228 class ValueIteratorBase
|
rt300@13
|
1229 {
|
rt300@13
|
1230 public:
|
rt300@13
|
1231 typedef unsigned int size_t;
|
rt300@13
|
1232 typedef int difference_type;
|
rt300@13
|
1233 typedef ValueIteratorBase SelfType;
|
rt300@13
|
1234
|
rt300@13
|
1235 ValueIteratorBase();
|
rt300@13
|
1236 #ifndef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
1237 explicit ValueIteratorBase( const Value::ObjectValues::iterator ¤t );
|
rt300@13
|
1238 #else
|
rt300@13
|
1239 ValueIteratorBase( const ValueInternalArray::IteratorState &state );
|
rt300@13
|
1240 ValueIteratorBase( const ValueInternalMap::IteratorState &state );
|
rt300@13
|
1241 #endif
|
rt300@13
|
1242
|
rt300@13
|
1243 bool operator ==( const SelfType &other ) const
|
rt300@13
|
1244 {
|
rt300@13
|
1245 return isEqual( other );
|
rt300@13
|
1246 }
|
rt300@13
|
1247
|
rt300@13
|
1248 bool operator !=( const SelfType &other ) const
|
rt300@13
|
1249 {
|
rt300@13
|
1250 return !isEqual( other );
|
rt300@13
|
1251 }
|
rt300@13
|
1252
|
rt300@13
|
1253 difference_type operator -( const SelfType &other ) const
|
rt300@13
|
1254 {
|
rt300@13
|
1255 return computeDistance( other );
|
rt300@13
|
1256 }
|
rt300@13
|
1257
|
rt300@13
|
1258 /// Return either the index or the member name of the referenced value as a Value.
|
rt300@13
|
1259 Value key() const;
|
rt300@13
|
1260
|
rt300@13
|
1261 /// Return the index of the referenced Value. -1 if it is not an arrayValue.
|
rt300@13
|
1262 UInt index() const;
|
rt300@13
|
1263
|
rt300@13
|
1264 /// Return the member name of the referenced Value. "" if it is not an objectValue.
|
rt300@13
|
1265 const char *memberName() const;
|
rt300@13
|
1266
|
rt300@13
|
1267 protected:
|
rt300@13
|
1268 Value &deref() const;
|
rt300@13
|
1269
|
rt300@13
|
1270 void increment();
|
rt300@13
|
1271
|
rt300@13
|
1272 void decrement();
|
rt300@13
|
1273
|
rt300@13
|
1274 difference_type computeDistance( const SelfType &other ) const;
|
rt300@13
|
1275
|
rt300@13
|
1276 bool isEqual( const SelfType &other ) const;
|
rt300@13
|
1277
|
rt300@13
|
1278 void copy( const SelfType &other );
|
rt300@13
|
1279
|
rt300@13
|
1280 private:
|
rt300@13
|
1281 #ifndef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
1282 Value::ObjectValues::iterator current_;
|
rt300@13
|
1283 // Indicates that iterator is for a null value.
|
rt300@13
|
1284 bool isNull_;
|
rt300@13
|
1285 #else
|
rt300@13
|
1286 union
|
rt300@13
|
1287 {
|
rt300@13
|
1288 ValueInternalArray::IteratorState array_;
|
rt300@13
|
1289 ValueInternalMap::IteratorState map_;
|
rt300@13
|
1290 } iterator_;
|
rt300@13
|
1291 bool isArray_;
|
rt300@13
|
1292 #endif
|
rt300@13
|
1293 };
|
rt300@13
|
1294
|
rt300@13
|
1295 /** \brief const iterator for object and array value.
|
rt300@13
|
1296 *
|
rt300@13
|
1297 */
|
rt300@13
|
1298 class ValueConstIterator : public ValueIteratorBase
|
rt300@13
|
1299 {
|
rt300@13
|
1300 friend class Value;
|
rt300@13
|
1301 public:
|
rt300@13
|
1302 typedef unsigned int size_t;
|
rt300@13
|
1303 typedef int difference_type;
|
rt300@13
|
1304 typedef const Value &reference;
|
rt300@13
|
1305 typedef const Value *pointer;
|
rt300@13
|
1306 typedef ValueConstIterator SelfType;
|
rt300@13
|
1307
|
rt300@13
|
1308 ValueConstIterator();
|
rt300@13
|
1309 private:
|
rt300@13
|
1310 /*! \internal Use by Value to create an iterator.
|
rt300@13
|
1311 */
|
rt300@13
|
1312 #ifndef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
1313 explicit ValueConstIterator( const Value::ObjectValues::iterator ¤t );
|
rt300@13
|
1314 #else
|
rt300@13
|
1315 ValueConstIterator( const ValueInternalArray::IteratorState &state );
|
rt300@13
|
1316 ValueConstIterator( const ValueInternalMap::IteratorState &state );
|
rt300@13
|
1317 #endif
|
rt300@13
|
1318 public:
|
rt300@13
|
1319 SelfType &operator =( const ValueIteratorBase &other );
|
rt300@13
|
1320
|
rt300@13
|
1321 SelfType operator++( int )
|
rt300@13
|
1322 {
|
rt300@13
|
1323 SelfType temp( *this );
|
rt300@13
|
1324 ++*this;
|
rt300@13
|
1325 return temp;
|
rt300@13
|
1326 }
|
rt300@13
|
1327
|
rt300@13
|
1328 SelfType operator--( int )
|
rt300@13
|
1329 {
|
rt300@13
|
1330 SelfType temp( *this );
|
rt300@13
|
1331 --*this;
|
rt300@13
|
1332 return temp;
|
rt300@13
|
1333 }
|
rt300@13
|
1334
|
rt300@13
|
1335 SelfType &operator--()
|
rt300@13
|
1336 {
|
rt300@13
|
1337 decrement();
|
rt300@13
|
1338 return *this;
|
rt300@13
|
1339 }
|
rt300@13
|
1340
|
rt300@13
|
1341 SelfType &operator++()
|
rt300@13
|
1342 {
|
rt300@13
|
1343 increment();
|
rt300@13
|
1344 return *this;
|
rt300@13
|
1345 }
|
rt300@13
|
1346
|
rt300@13
|
1347 reference operator *() const
|
rt300@13
|
1348 {
|
rt300@13
|
1349 return deref();
|
rt300@13
|
1350 }
|
rt300@13
|
1351 };
|
rt300@13
|
1352
|
rt300@13
|
1353
|
rt300@13
|
1354 /** \brief Iterator for object and array value.
|
rt300@13
|
1355 */
|
rt300@13
|
1356 class ValueIterator : public ValueIteratorBase
|
rt300@13
|
1357 {
|
rt300@13
|
1358 friend class Value;
|
rt300@13
|
1359 public:
|
rt300@13
|
1360 typedef unsigned int size_t;
|
rt300@13
|
1361 typedef int difference_type;
|
rt300@13
|
1362 typedef Value &reference;
|
rt300@13
|
1363 typedef Value *pointer;
|
rt300@13
|
1364 typedef ValueIterator SelfType;
|
rt300@13
|
1365
|
rt300@13
|
1366 ValueIterator();
|
rt300@13
|
1367 ValueIterator( const ValueConstIterator &other );
|
rt300@13
|
1368 ValueIterator( const ValueIterator &other );
|
rt300@13
|
1369 private:
|
rt300@13
|
1370 /*! \internal Use by Value to create an iterator.
|
rt300@13
|
1371 */
|
rt300@13
|
1372 #ifndef JSON_VALUE_USE_INTERNAL_MAP
|
rt300@13
|
1373 explicit ValueIterator( const Value::ObjectValues::iterator ¤t );
|
rt300@13
|
1374 #else
|
rt300@13
|
1375 ValueIterator( const ValueInternalArray::IteratorState &state );
|
rt300@13
|
1376 ValueIterator( const ValueInternalMap::IteratorState &state );
|
rt300@13
|
1377 #endif
|
rt300@13
|
1378 public:
|
rt300@13
|
1379
|
rt300@13
|
1380 SelfType &operator =( const SelfType &other );
|
rt300@13
|
1381
|
rt300@13
|
1382 SelfType operator++( int )
|
rt300@13
|
1383 {
|
rt300@13
|
1384 SelfType temp( *this );
|
rt300@13
|
1385 ++*this;
|
rt300@13
|
1386 return temp;
|
rt300@13
|
1387 }
|
rt300@13
|
1388
|
rt300@13
|
1389 SelfType operator--( int )
|
rt300@13
|
1390 {
|
rt300@13
|
1391 SelfType temp( *this );
|
rt300@13
|
1392 --*this;
|
rt300@13
|
1393 return temp;
|
rt300@13
|
1394 }
|
rt300@13
|
1395
|
rt300@13
|
1396 SelfType &operator--()
|
rt300@13
|
1397 {
|
rt300@13
|
1398 decrement();
|
rt300@13
|
1399 return *this;
|
rt300@13
|
1400 }
|
rt300@13
|
1401
|
rt300@13
|
1402 SelfType &operator++()
|
rt300@13
|
1403 {
|
rt300@13
|
1404 increment();
|
rt300@13
|
1405 return *this;
|
rt300@13
|
1406 }
|
rt300@13
|
1407
|
rt300@13
|
1408 reference operator *() const
|
rt300@13
|
1409 {
|
rt300@13
|
1410 return deref();
|
rt300@13
|
1411 }
|
rt300@13
|
1412 };
|
rt300@13
|
1413
|
rt300@13
|
1414
|
rt300@13
|
1415 } // namespace Json
|
rt300@13
|
1416
|
rt300@13
|
1417
|
rt300@13
|
1418 #endif // CPPTL_JSON_H_INCLUDED
|
rt300@13
|
1419
|
rt300@13
|
1420 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1421 // End of content of file: include/json/value.h
|
rt300@13
|
1422 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1423
|
rt300@13
|
1424
|
rt300@13
|
1425
|
rt300@13
|
1426
|
rt300@13
|
1427
|
rt300@13
|
1428
|
rt300@13
|
1429 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1430 // Beginning of content of file: include/json/reader.h
|
rt300@13
|
1431 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1432
|
rt300@13
|
1433 // Copyright 2007-2010 Baptiste Lepilleur
|
rt300@13
|
1434 // Distributed under MIT license, or public domain if desired and
|
rt300@13
|
1435 // recognized in your jurisdiction.
|
rt300@13
|
1436 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
rt300@13
|
1437
|
rt300@13
|
1438 #ifndef CPPTL_JSON_READER_H_INCLUDED
|
rt300@13
|
1439 # define CPPTL_JSON_READER_H_INCLUDED
|
rt300@13
|
1440
|
rt300@13
|
1441 #if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
1442 # include "features.h"
|
rt300@13
|
1443 # include "value.h"
|
rt300@13
|
1444 #endif // if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
1445 # include <deque>
|
rt300@13
|
1446 # include <stack>
|
rt300@13
|
1447 # include <string>
|
rt300@13
|
1448 # include <iostream>
|
rt300@13
|
1449
|
rt300@13
|
1450 namespace Json {
|
rt300@13
|
1451
|
rt300@13
|
1452 /** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a Value.
|
rt300@13
|
1453 *
|
rt300@13
|
1454 */
|
rt300@13
|
1455 class JSON_API Reader
|
rt300@13
|
1456 {
|
rt300@13
|
1457 public:
|
rt300@13
|
1458 typedef char Char;
|
rt300@13
|
1459 typedef const Char *Location;
|
rt300@13
|
1460
|
rt300@13
|
1461 /** \brief Constructs a Reader allowing all features
|
rt300@13
|
1462 * for parsing.
|
rt300@13
|
1463 */
|
rt300@13
|
1464 Reader();
|
rt300@13
|
1465
|
rt300@13
|
1466 /** \brief Constructs a Reader allowing the specified feature set
|
rt300@13
|
1467 * for parsing.
|
rt300@13
|
1468 */
|
rt300@13
|
1469 Reader( const Features &features );
|
rt300@13
|
1470
|
rt300@13
|
1471 /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
|
rt300@13
|
1472 * \param document UTF-8 encoded string containing the document to read.
|
rt300@13
|
1473 * \param root [out] Contains the root value of the document if it was
|
rt300@13
|
1474 * successfully parsed.
|
rt300@13
|
1475 * \param collectComments \c true to collect comment and allow writing them back during
|
rt300@13
|
1476 * serialization, \c false to discard comments.
|
rt300@13
|
1477 * This parameter is ignored if Features::allowComments_
|
rt300@13
|
1478 * is \c false.
|
rt300@13
|
1479 * \return \c true if the document was successfully parsed, \c false if an error occurred.
|
rt300@13
|
1480 */
|
rt300@13
|
1481 bool parse( const std::string &document,
|
rt300@13
|
1482 Value &root,
|
rt300@13
|
1483 bool collectComments = true );
|
rt300@13
|
1484
|
rt300@13
|
1485 /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
|
rt300@13
|
1486 * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the document to read.
|
rt300@13
|
1487 * \param endDoc Pointer on the end of the UTF-8 encoded string of the document to read.
|
rt300@13
|
1488 \ Must be >= beginDoc.
|
rt300@13
|
1489 * \param root [out] Contains the root value of the document if it was
|
rt300@13
|
1490 * successfully parsed.
|
rt300@13
|
1491 * \param collectComments \c true to collect comment and allow writing them back during
|
rt300@13
|
1492 * serialization, \c false to discard comments.
|
rt300@13
|
1493 * This parameter is ignored if Features::allowComments_
|
rt300@13
|
1494 * is \c false.
|
rt300@13
|
1495 * \return \c true if the document was successfully parsed, \c false if an error occurred.
|
rt300@13
|
1496 */
|
rt300@13
|
1497 bool parse( const char *beginDoc, const char *endDoc,
|
rt300@13
|
1498 Value &root,
|
rt300@13
|
1499 bool collectComments = true );
|
rt300@13
|
1500
|
rt300@13
|
1501 /// \brief Parse from input stream.
|
rt300@13
|
1502 /// \see Json::operator>>(std::istream&, Json::Value&).
|
rt300@13
|
1503 bool parse( std::istream &is,
|
rt300@13
|
1504 Value &root,
|
rt300@13
|
1505 bool collectComments = true );
|
rt300@13
|
1506
|
rt300@13
|
1507 /** \brief Returns a user friendly string that list errors in the parsed document.
|
rt300@13
|
1508 * \return Formatted error message with the list of errors with their location in
|
rt300@13
|
1509 * the parsed document. An empty string is returned if no error occurred
|
rt300@13
|
1510 * during parsing.
|
rt300@13
|
1511 * \deprecated Use getFormattedErrorMessages() instead (typo fix).
|
rt300@13
|
1512 */
|
rt300@13
|
1513 JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead")
|
rt300@13
|
1514 std::string getFormatedErrorMessages() const;
|
rt300@13
|
1515
|
rt300@13
|
1516 /** \brief Returns a user friendly string that list errors in the parsed document.
|
rt300@13
|
1517 * \return Formatted error message with the list of errors with their location in
|
rt300@13
|
1518 * the parsed document. An empty string is returned if no error occurred
|
rt300@13
|
1519 * during parsing.
|
rt300@13
|
1520 */
|
rt300@13
|
1521 std::string getFormattedErrorMessages() const;
|
rt300@13
|
1522
|
rt300@13
|
1523 private:
|
rt300@13
|
1524 enum TokenType
|
rt300@13
|
1525 {
|
rt300@13
|
1526 tokenEndOfStream = 0,
|
rt300@13
|
1527 tokenObjectBegin,
|
rt300@13
|
1528 tokenObjectEnd,
|
rt300@13
|
1529 tokenArrayBegin,
|
rt300@13
|
1530 tokenArrayEnd,
|
rt300@13
|
1531 tokenString,
|
rt300@13
|
1532 tokenNumber,
|
rt300@13
|
1533 tokenTrue,
|
rt300@13
|
1534 tokenFalse,
|
rt300@13
|
1535 tokenNull,
|
rt300@13
|
1536 tokenArraySeparator,
|
rt300@13
|
1537 tokenMemberSeparator,
|
rt300@13
|
1538 tokenComment,
|
rt300@13
|
1539 tokenError
|
rt300@13
|
1540 };
|
rt300@13
|
1541
|
rt300@13
|
1542 class Token
|
rt300@13
|
1543 {
|
rt300@13
|
1544 public:
|
rt300@13
|
1545 TokenType type_;
|
rt300@13
|
1546 Location start_;
|
rt300@13
|
1547 Location end_;
|
rt300@13
|
1548 };
|
rt300@13
|
1549
|
rt300@13
|
1550 class ErrorInfo
|
rt300@13
|
1551 {
|
rt300@13
|
1552 public:
|
rt300@13
|
1553 Token token_;
|
rt300@13
|
1554 std::string message_;
|
rt300@13
|
1555 Location extra_;
|
rt300@13
|
1556 };
|
rt300@13
|
1557
|
rt300@13
|
1558 typedef std::deque<ErrorInfo> Errors;
|
rt300@13
|
1559
|
rt300@13
|
1560 bool expectToken( TokenType type, Token &token, const char *message );
|
rt300@13
|
1561 bool readToken( Token &token );
|
rt300@13
|
1562 void skipSpaces();
|
rt300@13
|
1563 bool match( Location pattern,
|
rt300@13
|
1564 int patternLength );
|
rt300@13
|
1565 bool readComment();
|
rt300@13
|
1566 bool readCStyleComment();
|
rt300@13
|
1567 bool readCppStyleComment();
|
rt300@13
|
1568 bool readString();
|
rt300@13
|
1569 void readNumber();
|
rt300@13
|
1570 bool readValue();
|
rt300@13
|
1571 bool readObject( Token &token );
|
rt300@13
|
1572 bool readArray( Token &token );
|
rt300@13
|
1573 bool decodeNumber( Token &token );
|
rt300@13
|
1574 bool decodeString( Token &token );
|
rt300@13
|
1575 bool decodeString( Token &token, std::string &decoded );
|
rt300@13
|
1576 bool decodeDouble( Token &token );
|
rt300@13
|
1577 bool decodeUnicodeCodePoint( Token &token,
|
rt300@13
|
1578 Location ¤t,
|
rt300@13
|
1579 Location end,
|
rt300@13
|
1580 unsigned int &unicode );
|
rt300@13
|
1581 bool decodeUnicodeEscapeSequence( Token &token,
|
rt300@13
|
1582 Location ¤t,
|
rt300@13
|
1583 Location end,
|
rt300@13
|
1584 unsigned int &unicode );
|
rt300@13
|
1585 bool addError( const std::string &message,
|
rt300@13
|
1586 Token &token,
|
rt300@13
|
1587 Location extra = 0 );
|
rt300@13
|
1588 bool recoverFromError( TokenType skipUntilToken );
|
rt300@13
|
1589 bool addErrorAndRecover( const std::string &message,
|
rt300@13
|
1590 Token &token,
|
rt300@13
|
1591 TokenType skipUntilToken );
|
rt300@13
|
1592 void skipUntilSpace();
|
rt300@13
|
1593 Value ¤tValue();
|
rt300@13
|
1594 Char getNextChar();
|
rt300@13
|
1595 void getLocationLineAndColumn( Location location,
|
rt300@13
|
1596 int &line,
|
rt300@13
|
1597 int &column ) const;
|
rt300@13
|
1598 std::string getLocationLineAndColumn( Location location ) const;
|
rt300@13
|
1599 void addComment( Location begin,
|
rt300@13
|
1600 Location end,
|
rt300@13
|
1601 CommentPlacement placement );
|
rt300@13
|
1602 void skipCommentTokens( Token &token );
|
rt300@13
|
1603
|
rt300@13
|
1604 typedef std::stack<Value *> Nodes;
|
rt300@13
|
1605 Nodes nodes_;
|
rt300@13
|
1606 Errors errors_;
|
rt300@13
|
1607 std::string document_;
|
rt300@13
|
1608 Location begin_;
|
rt300@13
|
1609 Location end_;
|
rt300@13
|
1610 Location current_;
|
rt300@13
|
1611 Location lastValueEnd_;
|
rt300@13
|
1612 Value *lastValue_;
|
rt300@13
|
1613 std::string commentsBefore_;
|
rt300@13
|
1614 Features features_;
|
rt300@13
|
1615 bool collectComments_;
|
rt300@13
|
1616 };
|
rt300@13
|
1617
|
rt300@13
|
1618 /** \brief Read from 'sin' into 'root'.
|
rt300@13
|
1619
|
rt300@13
|
1620 Always keep comments from the input JSON.
|
rt300@13
|
1621
|
rt300@13
|
1622 This can be used to read a file into a particular sub-object.
|
rt300@13
|
1623 For example:
|
rt300@13
|
1624 \code
|
rt300@13
|
1625 Json::Value root;
|
rt300@13
|
1626 cin >> root["dir"]["file"];
|
rt300@13
|
1627 cout << root;
|
rt300@13
|
1628 \endcode
|
rt300@13
|
1629 Result:
|
rt300@13
|
1630 \verbatim
|
rt300@13
|
1631 {
|
rt300@13
|
1632 "dir": {
|
rt300@13
|
1633 "file": {
|
rt300@13
|
1634 // The input stream JSON would be nested here.
|
rt300@13
|
1635 }
|
rt300@13
|
1636 }
|
rt300@13
|
1637 }
|
rt300@13
|
1638 \endverbatim
|
rt300@13
|
1639 \throw std::exception on parse error.
|
rt300@13
|
1640 \see Json::operator<<()
|
rt300@13
|
1641 */
|
rt300@13
|
1642 std::istream& operator>>( std::istream&, Value& );
|
rt300@13
|
1643
|
rt300@13
|
1644 } // namespace Json
|
rt300@13
|
1645
|
rt300@13
|
1646 #endif // CPPTL_JSON_READER_H_INCLUDED
|
rt300@13
|
1647
|
rt300@13
|
1648 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1649 // End of content of file: include/json/reader.h
|
rt300@13
|
1650 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1651
|
rt300@13
|
1652
|
rt300@13
|
1653
|
rt300@13
|
1654
|
rt300@13
|
1655
|
rt300@13
|
1656
|
rt300@13
|
1657 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1658 // Beginning of content of file: include/json/writer.h
|
rt300@13
|
1659 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1660
|
rt300@13
|
1661 // Copyright 2007-2010 Baptiste Lepilleur
|
rt300@13
|
1662 // Distributed under MIT license, or public domain if desired and
|
rt300@13
|
1663 // recognized in your jurisdiction.
|
rt300@13
|
1664 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
rt300@13
|
1665
|
rt300@13
|
1666 #ifndef JSON_WRITER_H_INCLUDED
|
rt300@13
|
1667 # define JSON_WRITER_H_INCLUDED
|
rt300@13
|
1668
|
rt300@13
|
1669 #if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
1670 # include "value.h"
|
rt300@13
|
1671 #endif // if !defined(JSON_IS_AMALGAMATION)
|
rt300@13
|
1672 # include <vector>
|
rt300@13
|
1673 # include <string>
|
rt300@13
|
1674 # include <iostream>
|
rt300@13
|
1675
|
rt300@13
|
1676 namespace Json {
|
rt300@13
|
1677
|
rt300@13
|
1678 class Value;
|
rt300@13
|
1679
|
rt300@13
|
1680 /** \brief Abstract class for writers.
|
rt300@13
|
1681 */
|
rt300@13
|
1682 class JSON_API Writer
|
rt300@13
|
1683 {
|
rt300@13
|
1684 public:
|
rt300@13
|
1685 virtual ~Writer();
|
rt300@13
|
1686
|
rt300@13
|
1687 virtual std::string write( const Value &root ) = 0;
|
rt300@13
|
1688 };
|
rt300@13
|
1689
|
rt300@13
|
1690 /** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format without formatting (not human friendly).
|
rt300@13
|
1691 *
|
rt300@13
|
1692 * The JSON document is written in a single line. It is not intended for 'human' consumption,
|
rt300@13
|
1693 * but may be usefull to support feature such as RPC where bandwith is limited.
|
rt300@13
|
1694 * \sa Reader, Value
|
rt300@13
|
1695 */
|
rt300@13
|
1696 class JSON_API FastWriter : public Writer
|
rt300@13
|
1697 {
|
rt300@13
|
1698 public:
|
rt300@13
|
1699 FastWriter();
|
rt300@13
|
1700 virtual ~FastWriter(){}
|
rt300@13
|
1701
|
rt300@13
|
1702 void enableYAMLCompatibility();
|
rt300@13
|
1703
|
rt300@13
|
1704 public: // overridden from Writer
|
rt300@13
|
1705 virtual std::string write( const Value &root );
|
rt300@13
|
1706
|
rt300@13
|
1707 private:
|
rt300@13
|
1708 void writeValue( const Value &value );
|
rt300@13
|
1709
|
rt300@13
|
1710 std::string document_;
|
rt300@13
|
1711 bool yamlCompatiblityEnabled_;
|
rt300@13
|
1712 };
|
rt300@13
|
1713
|
rt300@13
|
1714 /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way.
|
rt300@13
|
1715 *
|
rt300@13
|
1716 * The rules for line break and indent are as follow:
|
rt300@13
|
1717 * - Object value:
|
rt300@13
|
1718 * - if empty then print {} without indent and line break
|
rt300@13
|
1719 * - if not empty the print '{', line break & indent, print one value per line
|
rt300@13
|
1720 * and then unindent and line break and print '}'.
|
rt300@13
|
1721 * - Array value:
|
rt300@13
|
1722 * - if empty then print [] without indent and line break
|
rt300@13
|
1723 * - if the array contains no object value, empty array or some other value types,
|
rt300@13
|
1724 * and all the values fit on one lines, then print the array on a single line.
|
rt300@13
|
1725 * - otherwise, it the values do not fit on one line, or the array contains
|
rt300@13
|
1726 * object or non empty array, then print one value per line.
|
rt300@13
|
1727 *
|
rt300@13
|
1728 * If the Value have comments then they are outputed according to their #CommentPlacement.
|
rt300@13
|
1729 *
|
rt300@13
|
1730 * \sa Reader, Value, Value::setComment()
|
rt300@13
|
1731 */
|
rt300@13
|
1732 class JSON_API StyledWriter: public Writer
|
rt300@13
|
1733 {
|
rt300@13
|
1734 public:
|
rt300@13
|
1735 StyledWriter();
|
rt300@13
|
1736 virtual ~StyledWriter(){}
|
rt300@13
|
1737
|
rt300@13
|
1738 public: // overridden from Writer
|
rt300@13
|
1739 /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
|
rt300@13
|
1740 * \param root Value to serialize.
|
rt300@13
|
1741 * \return String containing the JSON document that represents the root value.
|
rt300@13
|
1742 */
|
rt300@13
|
1743 virtual std::string write( const Value &root );
|
rt300@13
|
1744
|
rt300@13
|
1745 private:
|
rt300@13
|
1746 void writeValue( const Value &value );
|
rt300@13
|
1747 void writeArrayValue( const Value &value );
|
rt300@13
|
1748 bool isMultineArray( const Value &value );
|
rt300@13
|
1749 void pushValue( const std::string &value );
|
rt300@13
|
1750 void writeIndent();
|
rt300@13
|
1751 void writeWithIndent( const std::string &value );
|
rt300@13
|
1752 void indent();
|
rt300@13
|
1753 void unindent();
|
rt300@13
|
1754 void writeCommentBeforeValue( const Value &root );
|
rt300@13
|
1755 void writeCommentAfterValueOnSameLine( const Value &root );
|
rt300@13
|
1756 bool hasCommentForValue( const Value &value );
|
rt300@13
|
1757 static std::string normalizeEOL( const std::string &text );
|
rt300@13
|
1758
|
rt300@13
|
1759 typedef std::vector<std::string> ChildValues;
|
rt300@13
|
1760
|
rt300@13
|
1761 ChildValues childValues_;
|
rt300@13
|
1762 std::string document_;
|
rt300@13
|
1763 std::string indentString_;
|
rt300@13
|
1764 int rightMargin_;
|
rt300@13
|
1765 int indentSize_;
|
rt300@13
|
1766 bool addChildValues_;
|
rt300@13
|
1767 };
|
rt300@13
|
1768
|
rt300@13
|
1769 /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way,
|
rt300@13
|
1770 to a stream rather than to a string.
|
rt300@13
|
1771 *
|
rt300@13
|
1772 * The rules for line break and indent are as follow:
|
rt300@13
|
1773 * - Object value:
|
rt300@13
|
1774 * - if empty then print {} without indent and line break
|
rt300@13
|
1775 * - if not empty the print '{', line break & indent, print one value per line
|
rt300@13
|
1776 * and then unindent and line break and print '}'.
|
rt300@13
|
1777 * - Array value:
|
rt300@13
|
1778 * - if empty then print [] without indent and line break
|
rt300@13
|
1779 * - if the array contains no object value, empty array or some other value types,
|
rt300@13
|
1780 * and all the values fit on one lines, then print the array on a single line.
|
rt300@13
|
1781 * - otherwise, it the values do not fit on one line, or the array contains
|
rt300@13
|
1782 * object or non empty array, then print one value per line.
|
rt300@13
|
1783 *
|
rt300@13
|
1784 * If the Value have comments then they are outputed according to their #CommentPlacement.
|
rt300@13
|
1785 *
|
rt300@13
|
1786 * \param indentation Each level will be indented by this amount extra.
|
rt300@13
|
1787 * \sa Reader, Value, Value::setComment()
|
rt300@13
|
1788 */
|
rt300@13
|
1789 class JSON_API StyledStreamWriter
|
rt300@13
|
1790 {
|
rt300@13
|
1791 public:
|
rt300@13
|
1792 StyledStreamWriter( std::string indentation="\t" );
|
rt300@13
|
1793 ~StyledStreamWriter(){}
|
rt300@13
|
1794
|
rt300@13
|
1795 public:
|
rt300@13
|
1796 /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
|
rt300@13
|
1797 * \param out Stream to write to. (Can be ostringstream, e.g.)
|
rt300@13
|
1798 * \param root Value to serialize.
|
rt300@13
|
1799 * \note There is no point in deriving from Writer, since write() should not return a value.
|
rt300@13
|
1800 */
|
rt300@13
|
1801 void write( std::ostream &out, const Value &root );
|
rt300@13
|
1802
|
rt300@13
|
1803 private:
|
rt300@13
|
1804 void writeValue( const Value &value );
|
rt300@13
|
1805 void writeArrayValue( const Value &value );
|
rt300@13
|
1806 bool isMultineArray( const Value &value );
|
rt300@13
|
1807 void pushValue( const std::string &value );
|
rt300@13
|
1808 void writeIndent();
|
rt300@13
|
1809 void writeWithIndent( const std::string &value );
|
rt300@13
|
1810 void indent();
|
rt300@13
|
1811 void unindent();
|
rt300@13
|
1812 void writeCommentBeforeValue( const Value &root );
|
rt300@13
|
1813 void writeCommentAfterValueOnSameLine( const Value &root );
|
rt300@13
|
1814 bool hasCommentForValue( const Value &value );
|
rt300@13
|
1815 static std::string normalizeEOL( const std::string &text );
|
rt300@13
|
1816
|
rt300@13
|
1817 typedef std::vector<std::string> ChildValues;
|
rt300@13
|
1818
|
rt300@13
|
1819 ChildValues childValues_;
|
rt300@13
|
1820 std::ostream* document_;
|
rt300@13
|
1821 std::string indentString_;
|
rt300@13
|
1822 int rightMargin_;
|
rt300@13
|
1823 std::string indentation_;
|
rt300@13
|
1824 bool addChildValues_;
|
rt300@13
|
1825 };
|
rt300@13
|
1826
|
rt300@13
|
1827 # if defined(JSON_HAS_INT64)
|
rt300@13
|
1828 std::string JSON_API valueToString( Int value );
|
rt300@13
|
1829 std::string JSON_API valueToString( UInt value );
|
rt300@13
|
1830 # endif // if defined(JSON_HAS_INT64)
|
rt300@13
|
1831 std::string JSON_API valueToString( LargestInt value );
|
rt300@13
|
1832 std::string JSON_API valueToString( LargestUInt value );
|
rt300@13
|
1833 std::string JSON_API valueToString( double value );
|
rt300@13
|
1834 std::string JSON_API valueToString( bool value );
|
rt300@13
|
1835 std::string JSON_API valueToQuotedString( const char *value );
|
rt300@13
|
1836
|
rt300@13
|
1837 /// \brief Output using the StyledStreamWriter.
|
rt300@13
|
1838 /// \see Json::operator>>()
|
rt300@13
|
1839 std::ostream& operator<<( std::ostream&, const Value &root );
|
rt300@13
|
1840
|
rt300@13
|
1841 } // namespace Json
|
rt300@13
|
1842
|
rt300@13
|
1843
|
rt300@13
|
1844
|
rt300@13
|
1845 #endif // JSON_WRITER_H_INCLUDED
|
rt300@13
|
1846
|
rt300@13
|
1847 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1848 // End of content of file: include/json/writer.h
|
rt300@13
|
1849 // //////////////////////////////////////////////////////////////////////
|
rt300@13
|
1850
|
rt300@13
|
1851
|
rt300@13
|
1852
|
rt300@13
|
1853
|
rt300@13
|
1854
|
rt300@13
|
1855 #endif //ifndef JSON_AMALGATED_H_INCLUDED
|