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