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