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