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