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