Path: blob/trunk/third_party/cpp/json-cpp/include/json/json.h
2868 views
/// Json-cpp amalgamated header (http://jsoncpp.sourceforge.net/).1/// It is intended to be used with #include "json/json.h"23// //////////////////////////////////////////////////////////////////////4// Beginning of content of file: LICENSE5// //////////////////////////////////////////////////////////////////////67/*8The JsonCpp library's source code, including accompanying documentation,9tests and demonstration applications, are licensed under the following10conditions...1112Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all13jurisdictions which recognize such a disclaimer. In such jurisdictions,14this software is released into the Public Domain.1516In jurisdictions which do not recognize Public Domain property (e.g. Germany as of172010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and18The JsonCpp Authors, and is released under the terms of the MIT License (see below).1920In jurisdictions which recognize Public Domain property, the user of this21software may choose to accept it either as 1) Public Domain, 2) under the22conditions of the MIT License (see below), or 3) under the terms of dual23Public Domain/MIT License conditions described here, as they choose.2425The MIT License is about as close to Public Domain as a license can get, and is26described in clear, concise terms at:2728http://en.wikipedia.org/wiki/MIT_License2930The full text of the MIT License follows:3132========================================================================33Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors3435Permission is hereby granted, free of charge, to any person36obtaining a copy of this software and associated documentation37files (the "Software"), to deal in the Software without38restriction, including without limitation the rights to use, copy,39modify, merge, publish, distribute, sublicense, and/or sell copies40of the Software, and to permit persons to whom the Software is41furnished to do so, subject to the following conditions:4243The above copyright notice and this permission notice shall be44included in all copies or substantial portions of the Software.4546THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,47EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF48MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND49NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS50BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN51ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN52CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE53SOFTWARE.54========================================================================55(END LICENSE TEXT)5657The MIT license is compatible with both the GPL and commercial58software, affording one all of the rights of Public Domain with the59minor nuisance of being required to keep the above copyright notice60and license text in the source code. Note also that by accepting the61Public Domain "license" you can re-license your copy using whatever62license you like.6364*/6566// //////////////////////////////////////////////////////////////////////67// End of content of file: LICENSE68// //////////////////////////////////////////////////////////////////////697071727374#ifndef JSON_AMALGAMATED_H_INCLUDED75# define JSON_AMALGAMATED_H_INCLUDED76/// If defined, indicates that the source file is amalgamated77/// to prevent private header inclusion.78#define JSON_IS_AMALGAMATION7980// //////////////////////////////////////////////////////////////////////81// Beginning of content of file: include/json/version.h82// //////////////////////////////////////////////////////////////////////8384// DO NOT EDIT. This file (and "version") is generated by CMake.85// Run CMake configure step to update it.86#ifndef JSON_VERSION_H_INCLUDED87# define JSON_VERSION_H_INCLUDED8889# define JSONCPP_VERSION_STRING "1.8.4"90# define JSONCPP_VERSION_MAJOR 191# define JSONCPP_VERSION_MINOR 892# define JSONCPP_VERSION_PATCH 493# define JSONCPP_VERSION_QUALIFIER94# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))9596#ifdef JSONCPP_USING_SECURE_MEMORY97#undef JSONCPP_USING_SECURE_MEMORY98#endif99#define JSONCPP_USING_SECURE_MEMORY 0100// If non-zero, the library zeroes any memory that it has allocated before101// it frees its memory.102103#endif // JSON_VERSION_H_INCLUDED104105// //////////////////////////////////////////////////////////////////////106// End of content of file: include/json/version.h107// //////////////////////////////////////////////////////////////////////108109110111112113114// //////////////////////////////////////////////////////////////////////115// Beginning of content of file: include/json/config.h116// //////////////////////////////////////////////////////////////////////117118// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors119// Distributed under MIT license, or public domain if desired and120// recognized in your jurisdiction.121// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE122123#ifndef JSON_CONFIG_H_INCLUDED124#define JSON_CONFIG_H_INCLUDED125#include <stddef.h>126#include <string> //typedef String127#include <stdint.h> //typedef int64_t, uint64_t128129/// If defined, indicates that json library is embedded in CppTL library.130//# define JSON_IN_CPPTL 1131132/// If defined, indicates that json may leverage CppTL library133//# define JSON_USE_CPPTL 1134/// If defined, indicates that cpptl vector based map should be used instead of135/// std::map136/// as Value container.137//# define JSON_USE_CPPTL_SMALLMAP 1138139// If non-zero, the library uses exceptions to report bad input instead of C140// assertion macros. The default is to use exceptions.141#ifndef JSON_USE_EXCEPTION142#define JSON_USE_EXCEPTION 1143#endif144145/// If defined, indicates that the source file is amalgamated146/// to prevent private header inclusion.147/// Remarks: it is automatically defined in the generated amalgamated header.148// #define JSON_IS_AMALGAMATION149150#ifdef JSON_IN_CPPTL151#include <cpptl/config.h>152#ifndef JSON_USE_CPPTL153#define JSON_USE_CPPTL 1154#endif155#endif156157#ifdef JSON_IN_CPPTL158#define JSON_API CPPTL_API159#elif defined(JSON_DLL_BUILD)160#if defined(_MSC_VER) || defined(__MINGW32__)161#define JSON_API __declspec(dllexport)162#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING163#endif // if defined(_MSC_VER)164#elif defined(JSON_DLL)165#if defined(_MSC_VER) || defined(__MINGW32__)166#define JSON_API __declspec(dllimport)167#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING168#endif // if defined(_MSC_VER)169#endif // ifdef JSON_IN_CPPTL170#if !defined(JSON_API)171#define JSON_API172#endif173174// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for175// integer176// Storages, and 64 bits integer support is disabled.177// #define JSON_NO_INT64 1178179#if defined(_MSC_VER) // MSVC180# if _MSC_VER <= 1200 // MSVC 6181// Microsoft Visual Studio 6 only support conversion from __int64 to double182// (no conversion from unsigned __int64).183# define JSON_USE_INT64_DOUBLE_CONVERSION 1184// Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'185// characters in the debug information)186// All projects I've ever seen with VS6 were using this globally (not bothering187// with pragma push/pop).188# pragma warning(disable : 4786)189# endif // MSVC 6190191# if _MSC_VER >= 1500 // MSVC 2008192/// Indicates that the following function is deprecated.193# define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))194# endif195196#endif // defined(_MSC_VER)197198// In c++11 the override keyword allows you to explicitly define that a function199// is intended to override the base-class version. This makes the code more200// manageable and fixes a set of common hard-to-find bugs.201#if __cplusplus >= 201103L202# define JSONCPP_OVERRIDE override203# define JSONCPP_NOEXCEPT noexcept204# define JSONCPP_OP_EXPLICIT explicit205#elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900206# define JSONCPP_OVERRIDE override207# define JSONCPP_NOEXCEPT throw()208# if _MSC_VER >= 1800 // MSVC 2013209# define JSONCPP_OP_EXPLICIT explicit210# else211# define JSONCPP_OP_EXPLICIT212# endif213#elif defined(_MSC_VER) && _MSC_VER >= 1900214# define JSONCPP_OVERRIDE override215# define JSONCPP_NOEXCEPT noexcept216# define JSONCPP_OP_EXPLICIT explicit217#else218# define JSONCPP_OVERRIDE219# define JSONCPP_NOEXCEPT throw()220# define JSONCPP_OP_EXPLICIT221#endif222223#ifndef JSON_HAS_RVALUE_REFERENCES224225#if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010226#define JSON_HAS_RVALUE_REFERENCES 1227#endif // MSVC >= 2010228229#ifdef __clang__230#if __has_feature(cxx_rvalue_references)231#define JSON_HAS_RVALUE_REFERENCES 1232#endif // has_feature233234#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)235#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)236#define JSON_HAS_RVALUE_REFERENCES 1237#endif // GXX_EXPERIMENTAL238239#endif // __clang__ || __GNUC__240241#endif // not defined JSON_HAS_RVALUE_REFERENCES242243#ifndef JSON_HAS_RVALUE_REFERENCES244#define JSON_HAS_RVALUE_REFERENCES 0245#endif246247#ifdef __clang__248# if __has_extension(attribute_deprecated_with_message)249# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))250# endif251#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)252# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))253# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))254# elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))255# define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))256# endif // GNUC version257#endif // __clang__ || __GNUC__258259#if !defined(JSONCPP_DEPRECATED)260#define JSONCPP_DEPRECATED(message)261#endif // if !defined(JSONCPP_DEPRECATED)262263#if __GNUC__ >= 6264# define JSON_USE_INT64_DOUBLE_CONVERSION 1265#endif266267#if !defined(JSON_IS_AMALGAMATION)268269# include "version.h"270271# if JSONCPP_USING_SECURE_MEMORY272# include "allocator.h" //typedef Allocator273# endif274275#endif // if !defined(JSON_IS_AMALGAMATION)276277namespace Json {278typedef int Int;279typedef unsigned int UInt;280#if defined(JSON_NO_INT64)281typedef int LargestInt;282typedef unsigned int LargestUInt;283#undef JSON_HAS_INT64284#else // if defined(JSON_NO_INT64)285// For Microsoft Visual use specific types as long long is not supported286#if defined(_MSC_VER) // Microsoft Visual Studio287typedef __int64 Int64;288typedef unsigned __int64 UInt64;289#else // if defined(_MSC_VER) // Other platforms, use long long290typedef int64_t Int64;291typedef uint64_t UInt64;292#endif // if defined(_MSC_VER)293typedef Int64 LargestInt;294typedef UInt64 LargestUInt;295#define JSON_HAS_INT64296#endif // if defined(JSON_NO_INT64)297#if JSONCPP_USING_SECURE_MEMORY298#define JSONCPP_STRING std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >299#define JSONCPP_OSTRINGSTREAM std::basic_ostringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >300#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char>>301#define JSONCPP_ISTRINGSTREAM std::basic_istringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >302#define JSONCPP_ISTREAM std::istream303#else304#define JSONCPP_STRING std::string305#define JSONCPP_OSTRINGSTREAM std::ostringstream306#define JSONCPP_OSTREAM std::ostream307#define JSONCPP_ISTRINGSTREAM std::istringstream308#define JSONCPP_ISTREAM std::istream309#endif // if JSONCPP_USING_SECURE_MEMORY310} // end namespace Json311312#endif // JSON_CONFIG_H_INCLUDED313314// //////////////////////////////////////////////////////////////////////315// End of content of file: include/json/config.h316// //////////////////////////////////////////////////////////////////////317318319320321322323// //////////////////////////////////////////////////////////////////////324// Beginning of content of file: include/json/forwards.h325// //////////////////////////////////////////////////////////////////////326327// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors328// Distributed under MIT license, or public domain if desired and329// recognized in your jurisdiction.330// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE331332#ifndef JSON_FORWARDS_H_INCLUDED333#define JSON_FORWARDS_H_INCLUDED334335#if !defined(JSON_IS_AMALGAMATION)336#include "config.h"337#endif // if !defined(JSON_IS_AMALGAMATION)338339namespace Json {340341// writer.h342class FastWriter;343class StyledWriter;344345// reader.h346class Reader;347348// features.h349class Features;350351// value.h352typedef unsigned int ArrayIndex;353class StaticString;354class Path;355class PathArgument;356class Value;357class ValueIteratorBase;358class ValueIterator;359class ValueConstIterator;360361} // namespace Json362363#endif // JSON_FORWARDS_H_INCLUDED364365// //////////////////////////////////////////////////////////////////////366// End of content of file: include/json/forwards.h367// //////////////////////////////////////////////////////////////////////368369370371372373374// //////////////////////////////////////////////////////////////////////375// Beginning of content of file: include/json/features.h376// //////////////////////////////////////////////////////////////////////377378// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors379// Distributed under MIT license, or public domain if desired and380// recognized in your jurisdiction.381// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE382383#ifndef CPPTL_JSON_FEATURES_H_INCLUDED384#define CPPTL_JSON_FEATURES_H_INCLUDED385386#if !defined(JSON_IS_AMALGAMATION)387#include "forwards.h"388#endif // if !defined(JSON_IS_AMALGAMATION)389390#pragma pack(push, 8)391392namespace Json {393394/** \brief Configuration passed to reader and writer.395* This configuration object can be used to force the Reader or Writer396* to behave in a standard conforming way.397*/398class JSON_API Features {399public:400/** \brief A configuration that allows all features and assumes all strings401* are UTF-8.402* - C & C++ comments are allowed403* - Root object can be any JSON value404* - Assumes Value strings are encoded in UTF-8405*/406static Features all();407408/** \brief A configuration that is strictly compatible with the JSON409* specification.410* - Comments are forbidden.411* - Root object must be either an array or an object value.412* - Assumes Value strings are encoded in UTF-8413*/414static Features strictMode();415416/** \brief Initialize the configuration like JsonConfig::allFeatures;417*/418Features();419420/// \c true if comments are allowed. Default: \c true.421bool allowComments_;422423/// \c true if root must be either an array or an object value. Default: \c424/// false.425bool strictRoot_;426427/// \c true if dropped null placeholders are allowed. Default: \c false.428bool allowDroppedNullPlaceholders_;429430/// \c true if numeric object key are allowed. Default: \c false.431bool allowNumericKeys_;432};433434} // namespace Json435436#pragma pack(pop)437438#endif // CPPTL_JSON_FEATURES_H_INCLUDED439440// //////////////////////////////////////////////////////////////////////441// End of content of file: include/json/features.h442// //////////////////////////////////////////////////////////////////////443444445446447448449// //////////////////////////////////////////////////////////////////////450// Beginning of content of file: include/json/value.h451// //////////////////////////////////////////////////////////////////////452453// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors454// Distributed under MIT license, or public domain if desired and455// recognized in your jurisdiction.456// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE457458#ifndef CPPTL_JSON_H_INCLUDED459#define CPPTL_JSON_H_INCLUDED460461#if !defined(JSON_IS_AMALGAMATION)462#include "forwards.h"463#endif // if !defined(JSON_IS_AMALGAMATION)464#include <string>465#include <vector>466#include <exception>467468#ifndef JSON_USE_CPPTL_SMALLMAP469#include <map>470#else471#include <cpptl/smallmap.h>472#endif473#ifdef JSON_USE_CPPTL474#include <cpptl/forwards.h>475#endif476477//Conditional NORETURN attribute on the throw functions would:478// a) suppress false positives from static code analysis479// b) possibly improve optimization opportunities.480#if !defined(JSONCPP_NORETURN)481# if defined(_MSC_VER)482# define JSONCPP_NORETURN __declspec(noreturn)483# elif defined(__GNUC__)484# define JSONCPP_NORETURN __attribute__ ((__noreturn__))485# else486# define JSONCPP_NORETURN487# endif488#endif489490// Disable warning C4251: <data member>: <type> needs to have dll-interface to491// be used by...492#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)493#pragma warning(push)494#pragma warning(disable : 4251)495#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)496497#pragma pack(push, 8)498499/** \brief JSON (JavaScript Object Notation).500*/501namespace Json {502503/** Base class for all exceptions we throw.504*505* We use nothing but these internally. Of course, STL can throw others.506*/507class JSON_API Exception : public std::exception {508public:509Exception(JSONCPP_STRING const& msg);510~Exception() JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;511char const* what() const JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;512protected:513JSONCPP_STRING msg_;514};515516/** Exceptions which the user cannot easily avoid.517*518* E.g. out-of-memory (when we use malloc), stack-overflow, malicious input519*520* \remark derived from Json::Exception521*/522class JSON_API RuntimeError : public Exception {523public:524RuntimeError(JSONCPP_STRING const& msg);525};526527/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.528*529* These are precondition-violations (user bugs) and internal errors (our bugs).530*531* \remark derived from Json::Exception532*/533class JSON_API LogicError : public Exception {534public:535LogicError(JSONCPP_STRING const& msg);536};537538/// used internally539JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg);540/// used internally541JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg);542543/** \brief Type of the value held by a Value object.544*/545enum ValueType {546nullValue = 0, ///< 'null' value547intValue, ///< signed integer value548uintValue, ///< unsigned integer value549realValue, ///< double value550stringValue, ///< UTF-8 string value551booleanValue, ///< bool value552arrayValue, ///< array value (ordered list)553objectValue ///< object value (collection of name/value pairs).554};555556enum CommentPlacement {557commentBefore = 0, ///< a comment placed on the line before a value558commentAfterOnSameLine, ///< a comment just after a value on the same line559commentAfter, ///< a comment on the line after a value (only make sense for560/// root value)561numberOfCommentPlacement562};563564/** \brief Type of precision for formatting of real values.565*/566enum PrecisionType {567significantDigits = 0, ///< we set max number of significant digits in string568decimalPlaces ///< we set max number of digits after "." in string569};570571//# ifdef JSON_USE_CPPTL572// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;573// typedef CppTL::AnyEnumerator<const Value &> EnumValues;574//# endif575576/** \brief Lightweight wrapper to tag static string.577*578* Value constructor and objectValue member assignment takes advantage of the579* StaticString and avoid the cost of string duplication when storing the580* string or the member name.581*582* Example of usage:583* \code584* Json::Value aValue( StaticString("some text") );585* Json::Value object;586* static const StaticString code("code");587* object[code] = 1234;588* \endcode589*/590class JSON_API StaticString {591public:592explicit StaticString(const char* czstring) : c_str_(czstring) {}593594operator const char*() const { return c_str_; }595596const char* c_str() const { return c_str_; }597598private:599const char* c_str_;600};601602/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.603*604* This class is a discriminated union wrapper that can represents a:605* - signed integer [range: Value::minInt - Value::maxInt]606* - unsigned integer (range: 0 - Value::maxUInt)607* - double608* - UTF-8 string609* - boolean610* - 'null'611* - an ordered list of Value612* - collection of name/value pairs (javascript object)613*614* The type of the held value is represented by a #ValueType and615* can be obtained using type().616*617* Values of an #objectValue or #arrayValue can be accessed using operator[]()618* methods.619* Non-const methods will automatically create the a #nullValue element620* if it does not exist.621* The sequence of an #arrayValue will be automatically resized and initialized622* with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.623*624* The get() methods can be used to obtain default value in the case the625* required element does not exist.626*627* It is possible to iterate over the list of a #objectValue values using628* the getMemberNames() method.629*630* \note #Value string-length fit in size_t, but keys must be < 2^30.631* (The reason is an implementation detail.) A #CharReader will raise an632* exception if a bound is exceeded to avoid security holes in your app,633* but the Value API does *not* check bounds. That is the responsibility634* of the caller.635*/636class JSON_API Value {637friend class ValueIteratorBase;638public:639typedef std::vector<JSONCPP_STRING> Members;640typedef ValueIterator iterator;641typedef ValueConstIterator const_iterator;642typedef Json::UInt UInt;643typedef Json::Int Int;644#if defined(JSON_HAS_INT64)645typedef Json::UInt64 UInt64;646typedef Json::Int64 Int64;647#endif // defined(JSON_HAS_INT64)648typedef Json::LargestInt LargestInt;649typedef Json::LargestUInt LargestUInt;650typedef Json::ArrayIndex ArrayIndex;651652// Required for boost integration, e. g. BOOST_TEST653typedef std::string value_type;654655static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value().656static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null657static Value const& nullSingleton(); ///< Prefer this to null or nullRef.658659/// Minimum signed integer value that can be stored in a Json::Value.660static const LargestInt minLargestInt;661/// Maximum signed integer value that can be stored in a Json::Value.662static const LargestInt maxLargestInt;663/// Maximum unsigned integer value that can be stored in a Json::Value.664static const LargestUInt maxLargestUInt;665666/// Minimum signed int value that can be stored in a Json::Value.667static const Int minInt;668/// Maximum signed int value that can be stored in a Json::Value.669static const Int maxInt;670/// Maximum unsigned int value that can be stored in a Json::Value.671static const UInt maxUInt;672673#if defined(JSON_HAS_INT64)674/// Minimum signed 64 bits int value that can be stored in a Json::Value.675static const Int64 minInt64;676/// Maximum signed 64 bits int value that can be stored in a Json::Value.677static const Int64 maxInt64;678/// Maximum unsigned 64 bits int value that can be stored in a Json::Value.679static const UInt64 maxUInt64;680#endif // defined(JSON_HAS_INT64)681682/// Default precision for real value for string representation.683static const UInt defaultRealPrecision;684685// Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler686// when using gcc and clang backend compilers. CZString687// cannot be defined as private. See issue #486688#ifdef __NVCC__689public:690#else691private:692#endif693#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION694class CZString {695public:696enum DuplicationPolicy {697noDuplication = 0,698duplicate,699duplicateOnCopy700};701CZString(ArrayIndex index);702CZString(char const* str, unsigned length, DuplicationPolicy allocate);703CZString(CZString const& other);704#if JSON_HAS_RVALUE_REFERENCES705CZString(CZString&& other);706#endif707~CZString();708CZString& operator=(const CZString& other);709710#if JSON_HAS_RVALUE_REFERENCES711CZString& operator=(CZString&& other);712#endif713714bool operator<(CZString const& other) const;715bool operator==(CZString const& other) const;716ArrayIndex index() const;717//const char* c_str() const; ///< \deprecated718char const* data() const;719unsigned length() const;720bool isStaticString() const;721722private:723void swap(CZString& other);724725struct StringStorage {726unsigned policy_: 2;727unsigned length_: 30; // 1GB max728};729730char const* cstr_; // actually, a prefixed string, unless policy is noDup731union {732ArrayIndex index_;733StringStorage storage_;734};735};736737public:738#ifndef JSON_USE_CPPTL_SMALLMAP739typedef std::map<CZString, Value> ObjectValues;740#else741typedef CppTL::SmallMap<CZString, Value> ObjectValues;742#endif // ifndef JSON_USE_CPPTL_SMALLMAP743#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION744745public:746/** \brief Create a default Value of the given type.747748This is a very useful constructor.749To create an empty array, pass arrayValue.750To create an empty object, pass objectValue.751Another Value can then be set to this one by assignment.752This is useful since clear() and resize() will not alter types.753754Examples:755\code756Json::Value null_value; // null757Json::Value arr_value(Json::arrayValue); // []758Json::Value obj_value(Json::objectValue); // {}759\endcode760*/761Value(ValueType type = nullValue);762Value(Int value);763Value(UInt value);764#if defined(JSON_HAS_INT64)765Value(Int64 value);766Value(UInt64 value);767#endif // if defined(JSON_HAS_INT64)768Value(double value);769Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)770Value(const char* begin, const char* end); ///< Copy all, incl zeroes.771/** \brief Constructs a value from a static string.772773* Like other value string constructor but do not duplicate the string for774* internal storage. The given string must remain alive after the call to this775* constructor.776* \note This works only for null-terminated strings. (We cannot change the777* size of this class, so we have nowhere to store the length,778* which might be computed later for various operations.)779*780* Example of usage:781* \code782* static StaticString foo("some text");783* Json::Value aValue(foo);784* \endcode785*/786Value(const StaticString& value);787Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded zeroes too.788#ifdef JSON_USE_CPPTL789Value(const CppTL::ConstString& value);790#endif791Value(bool value);792/// Deep copy.793Value(const Value& other);794#if JSON_HAS_RVALUE_REFERENCES795/// Move constructor796Value(Value&& other);797#endif798~Value();799800/// Deep copy, then swap(other).801/// \note Over-write existing comments. To preserve comments, use #swapPayload().802Value& operator=(Value other);803804/// Swap everything.805void swap(Value& other);806/// Swap values but leave comments and source offsets in place.807void swapPayload(Value& other);808809/// copy everything.810void copy(const Value& other);811/// copy values but leave comments and source offsets in place.812void copyPayload(const Value& other);813814ValueType type() const;815816/// Compare payload only, not comments etc.817bool operator<(const Value& other) const;818bool operator<=(const Value& other) const;819bool operator>=(const Value& other) const;820bool operator>(const Value& other) const;821bool operator==(const Value& other) const;822bool operator!=(const Value& other) const;823int compare(const Value& other) const;824825const char* asCString() const; ///< Embedded zeroes could cause you trouble!826#if JSONCPP_USING_SECURE_MEMORY827unsigned getCStringLength() const; //Allows you to understand the length of the CString828#endif829JSONCPP_STRING asString() const; ///< Embedded zeroes are possible.830/** Get raw char* of string-value.831* \return false if !string. (Seg-fault if str or end are NULL.)832*/833bool getString(834char const** begin, char const** end) const;835#ifdef JSON_USE_CPPTL836CppTL::ConstString asConstString() const;837#endif838Int asInt() const;839UInt asUInt() const;840#if defined(JSON_HAS_INT64)841Int64 asInt64() const;842UInt64 asUInt64() const;843#endif // if defined(JSON_HAS_INT64)844LargestInt asLargestInt() const;845LargestUInt asLargestUInt() const;846float asFloat() const;847double asDouble() const;848bool asBool() const;849850bool isNull() const;851bool isBool() const;852bool isInt() const;853bool isInt64() const;854bool isUInt() const;855bool isUInt64() const;856bool isIntegral() const;857bool isDouble() const;858bool isNumeric() const;859bool isString() const;860bool isArray() const;861bool isObject() const;862863bool isConvertibleTo(ValueType other) const;864865/// Number of values in array or object866ArrayIndex size() const;867868/// \brief Return true if empty array, empty object, or null;869/// otherwise, false.870bool empty() const;871872/// Return !isNull()873JSONCPP_OP_EXPLICIT operator bool() const;874875/// Remove all object members and array elements.876/// \pre type() is arrayValue, objectValue, or nullValue877/// \post type() is unchanged878void clear();879880/// Resize the array to size elements.881/// New elements are initialized to null.882/// May only be called on nullValue or arrayValue.883/// \pre type() is arrayValue or nullValue884/// \post type() is arrayValue885void resize(ArrayIndex size);886887/// Access an array element (zero based index ).888/// If the array contains less than index element, then null value are889/// inserted890/// in the array so that its size is index+1.891/// (You may need to say 'value[0u]' to get your compiler to distinguish892/// this from the operator[] which takes a string.)893Value& operator[](ArrayIndex index);894895/// Access an array element (zero based index ).896/// If the array contains less than index element, then null value are897/// inserted898/// in the array so that its size is index+1.899/// (You may need to say 'value[0u]' to get your compiler to distinguish900/// this from the operator[] which takes a string.)901Value& operator[](int index);902903/// Access an array element (zero based index )904/// (You may need to say 'value[0u]' to get your compiler to distinguish905/// this from the operator[] which takes a string.)906const Value& operator[](ArrayIndex index) const;907908/// Access an array element (zero based index )909/// (You may need to say 'value[0u]' to get your compiler to distinguish910/// this from the operator[] which takes a string.)911const Value& operator[](int index) const;912913/// If the array contains at least index+1 elements, returns the element914/// value,915/// otherwise returns defaultValue.916Value get(ArrayIndex index, const Value& defaultValue) const;917/// Return true if index < size().918bool isValidIndex(ArrayIndex index) const;919/// \brief Append value to array at the end.920///921/// Equivalent to jsonvalue[jsonvalue.size()] = value;922Value& append(const Value& value);923924#if JSON_HAS_RVALUE_REFERENCES925Value& append(Value&& value);926#endif927928/// Access an object value by name, create a null member if it does not exist.929/// \note Because of our implementation, keys are limited to 2^30 -1 chars.930/// Exceeding that will cause an exception.931Value& operator[](const char* key);932/// Access an object value by name, returns null if there is no member with933/// that name.934const Value& operator[](const char* key) const;935/// Access an object value by name, create a null member if it does not exist.936/// \param key may contain embedded nulls.937Value& operator[](const JSONCPP_STRING& key);938/// Access an object value by name, returns null if there is no member with939/// that name.940/// \param key may contain embedded nulls.941const Value& operator[](const JSONCPP_STRING& key) const;942/** \brief Access an object value by name, create a null member if it does not943exist.944945* If the object has no entry for that name, then the member name used to store946* the new entry is not duplicated.947* Example of use:948* \code949* Json::Value object;950* static const StaticString code("code");951* object[code] = 1234;952* \endcode953*/954Value& operator[](const StaticString& key);955#ifdef JSON_USE_CPPTL956/// Access an object value by name, create a null member if it does not exist.957Value& operator[](const CppTL::ConstString& key);958/// Access an object value by name, returns null if there is no member with959/// that name.960const Value& operator[](const CppTL::ConstString& key) const;961#endif962/// Return the member named key if it exist, defaultValue otherwise.963/// \note deep copy964Value get(const char* key, const Value& defaultValue) const;965/// Return the member named key if it exist, defaultValue otherwise.966/// \note deep copy967/// \note key may contain embedded nulls.968Value get(const char* begin, const char* end, const Value& defaultValue) const;969/// Return the member named key if it exist, defaultValue otherwise.970/// \note deep copy971/// \param key may contain embedded nulls.972Value get(const JSONCPP_STRING& key, const Value& defaultValue) const;973#ifdef JSON_USE_CPPTL974/// Return the member named key if it exist, defaultValue otherwise.975/// \note deep copy976Value get(const CppTL::ConstString& key, const Value& defaultValue) const;977#endif978/// Most general and efficient version of isMember()const, get()const,979/// and operator[]const980/// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30981Value const* find(char const* begin, char const* end) const;982/// Most general and efficient version of object-mutators.983/// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30984/// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.985Value const* demand(char const* begin, char const* end);986/// \brief Remove and return the named member.987///988/// Do nothing if it did not exist.989/// \return the removed Value, or null.990/// \pre type() is objectValue or nullValue991/// \post type() is unchanged992/// \deprecated993void removeMember(const char* key);994/// Same as removeMember(const char*)995/// \param key may contain embedded nulls.996/// \deprecated997void removeMember(const JSONCPP_STRING& key);998/// Same as removeMember(const char* begin, const char* end, Value* removed),999/// but 'key' is null-terminated.1000bool removeMember(const char* key, Value* removed);1001/** \brief Remove the named map member.10021003Update 'removed' iff removed.1004\param key may contain embedded nulls.1005\return true iff removed (no exceptions)1006*/1007bool removeMember(JSONCPP_STRING const& key, Value* removed);1008/// Same as removeMember(JSONCPP_STRING const& key, Value* removed)1009bool removeMember(const char* begin, const char* end, Value* removed);1010/** \brief Remove the indexed array element.10111012O(n) expensive operations.1013Update 'removed' iff removed.1014\return true iff removed (no exceptions)1015*/1016bool removeIndex(ArrayIndex i, Value* removed);10171018/// Return true if the object has a member named key.1019/// \note 'key' must be null-terminated.1020bool isMember(const char* key) const;1021/// Return true if the object has a member named key.1022/// \param key may contain embedded nulls.1023bool isMember(const JSONCPP_STRING& key) const;1024/// Same as isMember(JSONCPP_STRING const& key)const1025bool isMember(const char* begin, const char* end) const;1026#ifdef JSON_USE_CPPTL1027/// Return true if the object has a member named key.1028bool isMember(const CppTL::ConstString& key) const;1029#endif10301031/// \brief Return a list of the member names.1032///1033/// If null, return an empty list.1034/// \pre type() is objectValue or nullValue1035/// \post if type() was nullValue, it remains nullValue1036Members getMemberNames() const;10371038//# ifdef JSON_USE_CPPTL1039// EnumMemberNames enumMemberNames() const;1040// EnumValues enumValues() const;1041//# endif10421043/// \deprecated Always pass len.1044JSONCPP_DEPRECATED("Use setComment(JSONCPP_STRING const&) instead.")1045void setComment(const char* comment, CommentPlacement placement);1046/// Comments must be //... or /* ... */1047void setComment(const char* comment, size_t len, CommentPlacement placement);1048/// Comments must be //... or /* ... */1049void setComment(const JSONCPP_STRING& comment, CommentPlacement placement);1050bool hasComment(CommentPlacement placement) const;1051/// Include delimiters and embedded newlines.1052JSONCPP_STRING getComment(CommentPlacement placement) const;10531054JSONCPP_STRING toStyledString() const;10551056const_iterator begin() const;1057const_iterator end() const;10581059iterator begin();1060iterator end();10611062// Accessors for the [start, limit) range of bytes within the JSON text from1063// which this value was parsed, if any.1064void setOffsetStart(ptrdiff_t start);1065void setOffsetLimit(ptrdiff_t limit);1066ptrdiff_t getOffsetStart() const;1067ptrdiff_t getOffsetLimit() const;10681069private:1070void initBasic(ValueType type, bool allocated = false);1071void dupPayload(const Value& other);1072void releasePayload();1073void dupMeta(const Value& other);10741075Value& resolveReference(const char* key);1076Value& resolveReference(const char* key, const char* end);10771078struct CommentInfo {1079CommentInfo();1080~CommentInfo();10811082void setComment(const char* text, size_t len);10831084char* comment_;1085};10861087// struct MemberNamesTransform1088//{1089// typedef const char *result_type;1090// const char *operator()( const CZString &name ) const1091// {1092// return name.c_str();1093// }1094//};10951096union ValueHolder {1097LargestInt int_;1098LargestUInt uint_;1099double real_;1100bool bool_;1101char* string_; // actually ptr to unsigned, followed by str, unless !allocated_1102ObjectValues* map_;1103} value_;1104ValueType type_ : 8;1105unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.1106// If not allocated_, string_ must be null-terminated.1107CommentInfo* comments_;11081109// [start, limit) byte offsets in the source JSON text from which this Value1110// was extracted.1111ptrdiff_t start_;1112ptrdiff_t limit_;1113};11141115/** \brief Experimental and untested: represents an element of the "path" to1116* access a node.1117*/1118class JSON_API PathArgument {1119public:1120friend class Path;11211122PathArgument();1123PathArgument(ArrayIndex index);1124PathArgument(const char* key);1125PathArgument(const JSONCPP_STRING& key);11261127private:1128enum Kind {1129kindNone = 0,1130kindIndex,1131kindKey1132};1133JSONCPP_STRING key_;1134ArrayIndex index_;1135Kind kind_;1136};11371138/** \brief Experimental and untested: represents a "path" to access a node.1139*1140* Syntax:1141* - "." => root node1142* - ".[n]" => elements at index 'n' of root node (an array value)1143* - ".name" => member named 'name' of root node (an object value)1144* - ".name1.name2.name3"1145* - ".[0][1][2].name1[3]"1146* - ".%" => member name is provided as parameter1147* - ".[%]" => index is provied as parameter1148*/1149class JSON_API Path {1150public:1151Path(const JSONCPP_STRING& path,1152const PathArgument& a1 = PathArgument(),1153const PathArgument& a2 = PathArgument(),1154const PathArgument& a3 = PathArgument(),1155const PathArgument& a4 = PathArgument(),1156const PathArgument& a5 = PathArgument());11571158const Value& resolve(const Value& root) const;1159Value resolve(const Value& root, const Value& defaultValue) const;1160/// Creates the "path" to access the specified node and returns a reference on1161/// the node.1162Value& make(Value& root) const;11631164private:1165typedef std::vector<const PathArgument*> InArgs;1166typedef std::vector<PathArgument> Args;11671168void makePath(const JSONCPP_STRING& path, const InArgs& in);1169void addPathInArg(const JSONCPP_STRING& path,1170const InArgs& in,1171InArgs::const_iterator& itInArg,1172PathArgument::Kind kind);1173void invalidPath(const JSONCPP_STRING& path, int location);11741175Args args_;1176};11771178/** \brief base class for Value iterators.1179*1180*/1181class JSON_API ValueIteratorBase {1182public:1183typedef std::bidirectional_iterator_tag iterator_category;1184typedef unsigned int size_t;1185typedef int difference_type;1186typedef ValueIteratorBase SelfType;11871188bool operator==(const SelfType& other) const { return isEqual(other); }11891190bool operator!=(const SelfType& other) const { return !isEqual(other); }11911192difference_type operator-(const SelfType& other) const {1193return other.computeDistance(*this);1194}11951196/// Return either the index or the member name of the referenced value as a1197/// Value.1198Value key() const;11991200/// Return the index of the referenced Value, or -1 if it is not an arrayValue.1201UInt index() const;12021203/// Return the member name of the referenced Value, or "" if it is not an1204/// objectValue.1205/// \note Avoid `c_str()` on result, as embedded zeroes are possible.1206JSONCPP_STRING name() const;12071208/// Return the member name of the referenced Value. "" if it is not an1209/// objectValue.1210/// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.1211JSONCPP_DEPRECATED("Use `key = name();` instead.")1212char const* memberName() const;1213/// Return the member name of the referenced Value, or NULL if it is not an1214/// objectValue.1215/// \note Better version than memberName(). Allows embedded nulls.1216char const* memberName(char const** end) const;12171218protected:1219Value& deref() const;12201221void increment();12221223void decrement();12241225difference_type computeDistance(const SelfType& other) const;12261227bool isEqual(const SelfType& other) const;12281229void copy(const SelfType& other);12301231private:1232Value::ObjectValues::iterator current_;1233// Indicates that iterator is for a null value.1234bool isNull_;12351236public:1237// For some reason, BORLAND needs these at the end, rather1238// than earlier. No idea why.1239ValueIteratorBase();1240explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);1241};12421243/** \brief const iterator for object and array value.1244*1245*/1246class JSON_API ValueConstIterator : public ValueIteratorBase {1247friend class Value;12481249public:1250typedef const Value value_type;1251//typedef unsigned int size_t;1252//typedef int difference_type;1253typedef const Value& reference;1254typedef const Value* pointer;1255typedef ValueConstIterator SelfType;12561257ValueConstIterator();1258ValueConstIterator(ValueIterator const& other);12591260private:1261/*! \internal Use by Value to create an iterator.1262*/1263explicit ValueConstIterator(const Value::ObjectValues::iterator& current);1264public:1265SelfType& operator=(const ValueIteratorBase& other);12661267SelfType operator++(int) {1268SelfType temp(*this);1269++*this;1270return temp;1271}12721273SelfType operator--(int) {1274SelfType temp(*this);1275--*this;1276return temp;1277}12781279SelfType& operator--() {1280decrement();1281return *this;1282}12831284SelfType& operator++() {1285increment();1286return *this;1287}12881289reference operator*() const { return deref(); }12901291pointer operator->() const { return &deref(); }1292};12931294/** \brief Iterator for object and array value.1295*/1296class JSON_API ValueIterator : public ValueIteratorBase {1297friend class Value;12981299public:1300typedef Value value_type;1301typedef unsigned int size_t;1302typedef int difference_type;1303typedef Value& reference;1304typedef Value* pointer;1305typedef ValueIterator SelfType;13061307ValueIterator();1308explicit ValueIterator(const ValueConstIterator& other);1309ValueIterator(const ValueIterator& other);13101311private:1312/*! \internal Use by Value to create an iterator.1313*/1314explicit ValueIterator(const Value::ObjectValues::iterator& current);1315public:1316SelfType& operator=(const SelfType& other);13171318SelfType operator++(int) {1319SelfType temp(*this);1320++*this;1321return temp;1322}13231324SelfType operator--(int) {1325SelfType temp(*this);1326--*this;1327return temp;1328}13291330SelfType& operator--() {1331decrement();1332return *this;1333}13341335SelfType& operator++() {1336increment();1337return *this;1338}13391340reference operator*() const { return deref(); }13411342pointer operator->() const { return &deref(); }1343};13441345inline void swap(Value& a, Value& b) { a.swap(b); }13461347} // namespace Json13481349#pragma pack(pop)13501351#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)1352#pragma warning(pop)1353#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)13541355#endif // CPPTL_JSON_H_INCLUDED13561357// //////////////////////////////////////////////////////////////////////1358// End of content of file: include/json/value.h1359// //////////////////////////////////////////////////////////////////////1360136113621363136413651366// //////////////////////////////////////////////////////////////////////1367// Beginning of content of file: include/json/reader.h1368// //////////////////////////////////////////////////////////////////////13691370// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors1371// Distributed under MIT license, or public domain if desired and1372// recognized in your jurisdiction.1373// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE13741375#ifndef CPPTL_JSON_READER_H_INCLUDED1376#define CPPTL_JSON_READER_H_INCLUDED13771378#if !defined(JSON_IS_AMALGAMATION)1379#include "features.h"1380#include "value.h"1381#endif // if !defined(JSON_IS_AMALGAMATION)1382#include <deque>1383#include <iosfwd>1384#include <stack>1385#include <string>1386#include <istream>13871388// Disable warning C4251: <data member>: <type> needs to have dll-interface to1389// be used by...1390#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)1391#pragma warning(push)1392#pragma warning(disable : 4251)1393#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)13941395#pragma pack(push, 8)13961397namespace Json {13981399/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a1400*Value.1401*1402* \deprecated Use CharReader and CharReaderBuilder.1403*/1404class JSON_API Reader {1405public:1406typedef char Char;1407typedef const Char* Location;14081409/** \brief An error tagged with where in the JSON text it was encountered.1410*1411* The offsets give the [start, limit) range of bytes within the text. Note1412* that this is bytes, not codepoints.1413*1414*/1415struct StructuredError {1416ptrdiff_t offset_start;1417ptrdiff_t offset_limit;1418JSONCPP_STRING message;1419};14201421/** \brief Constructs a Reader allowing all features1422* for parsing.1423*/1424JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")1425Reader();14261427/** \brief Constructs a Reader allowing the specified feature set1428* for parsing.1429*/1430JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")1431Reader(const Features& features);14321433/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>1434* document.1435* \param document UTF-8 encoded string containing the document to read.1436* \param root [out] Contains the root value of the document if it was1437* successfully parsed.1438* \param collectComments \c true to collect comment and allow writing them1439* back during1440* serialization, \c false to discard comments.1441* This parameter is ignored if1442* Features::allowComments_1443* is \c false.1444* \return \c true if the document was successfully parsed, \c false if an1445* error occurred.1446*/1447bool1448parse(const std::string& document, Value& root, bool collectComments = true);14491450/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>1451document.1452* \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the1453document to read.1454* \param endDoc Pointer on the end of the UTF-8 encoded string of the1455document to read.1456* Must be >= beginDoc.1457* \param root [out] Contains the root value of the document if it was1458* successfully parsed.1459* \param collectComments \c true to collect comment and allow writing them1460back during1461* serialization, \c false to discard comments.1462* This parameter is ignored if1463Features::allowComments_1464* is \c false.1465* \return \c true if the document was successfully parsed, \c false if an1466error occurred.1467*/1468bool parse(const char* beginDoc,1469const char* endDoc,1470Value& root,1471bool collectComments = true);14721473/// \brief Parse from input stream.1474/// \see Json::operator>>(std::istream&, Json::Value&).1475bool parse(JSONCPP_ISTREAM& is, Value& root, bool collectComments = true);14761477/** \brief Returns a user friendly string that list errors in the parsed1478* document.1479* \return Formatted error message with the list of errors with their location1480* in1481* the parsed document. An empty string is returned if no error1482* occurred1483* during parsing.1484* \deprecated Use getFormattedErrorMessages() instead (typo fix).1485*/1486JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")1487JSONCPP_STRING getFormatedErrorMessages() const;14881489/** \brief Returns a user friendly string that list errors in the parsed1490* document.1491* \return Formatted error message with the list of errors with their location1492* in1493* the parsed document. An empty string is returned if no error1494* occurred1495* during parsing.1496*/1497JSONCPP_STRING getFormattedErrorMessages() const;14981499/** \brief Returns a vector of structured erros encounted while parsing.1500* \return A (possibly empty) vector of StructuredError objects. Currently1501* only one error can be returned, but the caller should tolerate1502* multiple1503* errors. This can occur if the parser recovers from a non-fatal1504* parse error and then encounters additional errors.1505*/1506std::vector<StructuredError> getStructuredErrors() const;15071508/** \brief Add a semantic error message.1509* \param value JSON Value location associated with the error1510* \param message The error message.1511* \return \c true if the error was successfully added, \c false if the1512* Value offset exceeds the document size.1513*/1514bool pushError(const Value& value, const JSONCPP_STRING& message);15151516/** \brief Add a semantic error message with extra context.1517* \param value JSON Value location associated with the error1518* \param message The error message.1519* \param extra Additional JSON Value location to contextualize the error1520* \return \c true if the error was successfully added, \c false if either1521* Value offset exceeds the document size.1522*/1523bool pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra);15241525/** \brief Return whether there are any errors.1526* \return \c true if there are no errors to report \c false if1527* errors have occurred.1528*/1529bool good() const;15301531private:1532enum TokenType {1533tokenEndOfStream = 0,1534tokenObjectBegin,1535tokenObjectEnd,1536tokenArrayBegin,1537tokenArrayEnd,1538tokenString,1539tokenNumber,1540tokenTrue,1541tokenFalse,1542tokenNull,1543tokenArraySeparator,1544tokenMemberSeparator,1545tokenComment,1546tokenError1547};15481549class Token {1550public:1551TokenType type_;1552Location start_;1553Location end_;1554};15551556class ErrorInfo {1557public:1558Token token_;1559JSONCPP_STRING message_;1560Location extra_;1561};15621563typedef std::deque<ErrorInfo> Errors;15641565bool readToken(Token& token);1566void skipSpaces();1567bool match(Location pattern, int patternLength);1568bool readComment();1569bool readCStyleComment();1570bool readCppStyleComment();1571bool readString();1572void readNumber();1573bool readValue();1574bool readObject(Token& token);1575bool readArray(Token& token);1576bool decodeNumber(Token& token);1577bool decodeNumber(Token& token, Value& decoded);1578bool decodeString(Token& token);1579bool decodeString(Token& token, JSONCPP_STRING& decoded);1580bool decodeDouble(Token& token);1581bool decodeDouble(Token& token, Value& decoded);1582bool decodeUnicodeCodePoint(Token& token,1583Location& current,1584Location end,1585unsigned int& unicode);1586bool decodeUnicodeEscapeSequence(Token& token,1587Location& current,1588Location end,1589unsigned int& unicode);1590bool addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);1591bool recoverFromError(TokenType skipUntilToken);1592bool addErrorAndRecover(const JSONCPP_STRING& message,1593Token& token,1594TokenType skipUntilToken);1595void skipUntilSpace();1596Value& currentValue();1597Char getNextChar();1598void1599getLocationLineAndColumn(Location location, int& line, int& column) const;1600JSONCPP_STRING getLocationLineAndColumn(Location location) const;1601void addComment(Location begin, Location end, CommentPlacement placement);1602void skipCommentTokens(Token& token);16031604static bool containsNewLine(Location begin, Location end);1605static JSONCPP_STRING normalizeEOL(Location begin, Location end);16061607typedef std::stack<Value*> Nodes;1608Nodes nodes_;1609Errors errors_;1610JSONCPP_STRING document_;1611Location begin_;1612Location end_;1613Location current_;1614Location lastValueEnd_;1615Value* lastValue_;1616JSONCPP_STRING commentsBefore_;1617Features features_;1618bool collectComments_;1619}; // Reader16201621/** Interface for reading JSON from a char array.1622*/1623class JSON_API CharReader {1624public:1625virtual ~CharReader() {}1626/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>1627document.1628* The document must be a UTF-8 encoded string containing the document to read.1629*1630* \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the1631document to read.1632* \param endDoc Pointer on the end of the UTF-8 encoded string of the1633document to read.1634* Must be >= beginDoc.1635* \param root [out] Contains the root value of the document if it was1636* successfully parsed.1637* \param errs [out] Formatted error messages (if not NULL)1638* a user friendly string that lists errors in the parsed1639* document.1640* \return \c true if the document was successfully parsed, \c false if an1641error occurred.1642*/1643virtual bool parse(1644char const* beginDoc, char const* endDoc,1645Value* root, JSONCPP_STRING* errs) = 0;16461647class JSON_API Factory {1648public:1649virtual ~Factory() {}1650/** \brief Allocate a CharReader via operator new().1651* \throw std::exception if something goes wrong (e.g. invalid settings)1652*/1653virtual CharReader* newCharReader() const = 0;1654}; // Factory1655}; // CharReader16561657/** \brief Build a CharReader implementation.16581659Usage:1660\code1661using namespace Json;1662CharReaderBuilder builder;1663builder["collectComments"] = false;1664Value value;1665JSONCPP_STRING errs;1666bool ok = parseFromStream(builder, std::cin, &value, &errs);1667\endcode1668*/1669class JSON_API CharReaderBuilder : public CharReader::Factory {1670public:1671// Note: We use a Json::Value so that we can add data-members to this class1672// without a major version bump.1673/** Configuration of this builder.1674These are case-sensitive.1675Available settings (case-sensitive):1676- `"collectComments": false or true`1677- true to collect comment and allow writing them1678back during serialization, false to discard comments.1679This parameter is ignored if allowComments is false.1680- `"allowComments": false or true`1681- true if comments are allowed.1682- `"strictRoot": false or true`1683- true if root must be either an array or an object value1684- `"allowDroppedNullPlaceholders": false or true`1685- true if dropped null placeholders are allowed. (See StreamWriterBuilder.)1686- `"allowNumericKeys": false or true`1687- true if numeric object keys are allowed.1688- `"allowSingleQuotes": false or true`1689- true if '' are allowed for strings (both keys and values)1690- `"stackLimit": integer`1691- Exceeding stackLimit (recursive depth of `readValue()`) will1692cause an exception.1693- This is a security issue (seg-faults caused by deeply nested JSON),1694so the default is low.1695- `"failIfExtra": false or true`1696- If true, `parse()` returns false when extra non-whitespace trails1697the JSON value in the input string.1698- `"rejectDupKeys": false or true`1699- If true, `parse()` returns false when a key is duplicated within an object.1700- `"allowSpecialFloats": false or true`1701- If true, special float values (NaNs and infinities) are allowed1702and their values are lossfree restorable.17031704You can examine 'settings_` yourself1705to see the defaults. You can also write and read them just like any1706JSON Value.1707\sa setDefaults()1708*/1709Json::Value settings_;17101711CharReaderBuilder();1712~CharReaderBuilder() JSONCPP_OVERRIDE;17131714CharReader* newCharReader() const JSONCPP_OVERRIDE;17151716/** \return true if 'settings' are legal and consistent;1717* otherwise, indicate bad settings via 'invalid'.1718*/1719bool validate(Json::Value* invalid) const;17201721/** A simple way to update a specific setting.1722*/1723Value& operator[](JSONCPP_STRING key);17241725/** Called by ctor, but you can use this to reset settings_.1726* \pre 'settings' != NULL (but Json::null is fine)1727* \remark Defaults:1728* \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults1729*/1730static void setDefaults(Json::Value* settings);1731/** Same as old Features::strictMode().1732* \pre 'settings' != NULL (but Json::null is fine)1733* \remark Defaults:1734* \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode1735*/1736static void strictMode(Json::Value* settings);1737};17381739/** Consume entire stream and use its begin/end.1740* Someday we might have a real StreamReader, but for now this1741* is convenient.1742*/1743bool JSON_API parseFromStream(1744CharReader::Factory const&,1745JSONCPP_ISTREAM&,1746Value* root, std::string* errs);17471748/** \brief Read from 'sin' into 'root'.17491750Always keep comments from the input JSON.17511752This can be used to read a file into a particular sub-object.1753For example:1754\code1755Json::Value root;1756cin >> root["dir"]["file"];1757cout << root;1758\endcode1759Result:1760\verbatim1761{1762"dir": {1763"file": {1764// The input stream JSON would be nested here.1765}1766}1767}1768\endverbatim1769\throw std::exception on parse error.1770\see Json::operator<<()1771*/1772JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);17731774} // namespace Json17751776#pragma pack(pop)17771778#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)1779#pragma warning(pop)1780#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)17811782#endif // CPPTL_JSON_READER_H_INCLUDED17831784// //////////////////////////////////////////////////////////////////////1785// End of content of file: include/json/reader.h1786// //////////////////////////////////////////////////////////////////////1787178817891790179117921793// //////////////////////////////////////////////////////////////////////1794// Beginning of content of file: include/json/writer.h1795// //////////////////////////////////////////////////////////////////////17961797// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors1798// Distributed under MIT license, or public domain if desired and1799// recognized in your jurisdiction.1800// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE18011802#ifndef JSON_WRITER_H_INCLUDED1803#define JSON_WRITER_H_INCLUDED18041805#if !defined(JSON_IS_AMALGAMATION)1806#include "value.h"1807#endif // if !defined(JSON_IS_AMALGAMATION)1808#include <vector>1809#include <string>1810#include <ostream>18111812// Disable warning C4251: <data member>: <type> needs to have dll-interface to1813// be used by...1814#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER)1815#pragma warning(push)1816#pragma warning(disable : 4251)1817#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)18181819#pragma pack(push, 8)18201821namespace Json {18221823class Value;18241825/**18261827Usage:1828\code1829using namespace Json;1830void writeToStdout(StreamWriter::Factory const& factory, Value const& value) {1831std::unique_ptr<StreamWriter> const writer(1832factory.newStreamWriter());1833writer->write(value, &std::cout);1834std::cout << std::endl; // add lf and flush1835}1836\endcode1837*/1838class JSON_API StreamWriter {1839protected:1840JSONCPP_OSTREAM* sout_; // not owned; will not delete1841public:1842StreamWriter();1843virtual ~StreamWriter();1844/** Write Value into document as configured in sub-class.1845Do not take ownership of sout, but maintain a reference during function.1846\pre sout != NULL1847\return zero on success (For now, we always return zero, so check the stream instead.)1848\throw std::exception possibly, depending on configuration1849*/1850virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0;18511852/** \brief A simple abstract factory.1853*/1854class JSON_API Factory {1855public:1856virtual ~Factory();1857/** \brief Allocate a CharReader via operator new().1858* \throw std::exception if something goes wrong (e.g. invalid settings)1859*/1860virtual StreamWriter* newStreamWriter() const = 0;1861}; // Factory1862}; // StreamWriter18631864/** \brief Write into stringstream, then return string, for convenience.1865* A StreamWriter will be created from the factory, used, and then deleted.1866*/1867JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory, Value const& root);186818691870/** \brief Build a StreamWriter implementation.18711872Usage:1873\code1874using namespace Json;1875Value value = ...;1876StreamWriterBuilder builder;1877builder["commentStyle"] = "None";1878builder["indentation"] = " "; // or whatever you like1879std::unique_ptr<Json::StreamWriter> writer(1880builder.newStreamWriter());1881writer->write(value, &std::cout);1882std::cout << std::endl; // add lf and flush1883\endcode1884*/1885class JSON_API StreamWriterBuilder : public StreamWriter::Factory {1886public:1887// Note: We use a Json::Value so that we can add data-members to this class1888// without a major version bump.1889/** Configuration of this builder.1890Available settings (case-sensitive):1891- "commentStyle": "None" or "All"1892- "indentation": "<anything>".1893- Setting this to an empty string also omits newline characters.1894- "enableYAMLCompatibility": false or true1895- slightly change the whitespace around colons1896- "dropNullPlaceholders": false or true1897- Drop the "null" string from the writer's output for nullValues.1898Strictly speaking, this is not valid JSON. But when the output is being1899fed to a browser's JavaScript, it makes for smaller output and the1900browser can handle the output just fine.1901- "useSpecialFloats": false or true1902- If true, outputs non-finite floating point values in the following way:1903NaN values as "NaN", positive infinity as "Infinity", and negative infinity1904as "-Infinity".1905- "precision": int1906- Number of precision digits for formatting of real values.1907- "precisionType": "significant"(default) or "decimal"1908- Type of precision for formatting of real values.19091910You can examine 'settings_` yourself1911to see the defaults. You can also write and read them just like any1912JSON Value.1913\sa setDefaults()1914*/1915Json::Value settings_;19161917StreamWriterBuilder();1918~StreamWriterBuilder() JSONCPP_OVERRIDE;19191920/**1921* \throw std::exception if something goes wrong (e.g. invalid settings)1922*/1923StreamWriter* newStreamWriter() const JSONCPP_OVERRIDE;19241925/** \return true if 'settings' are legal and consistent;1926* otherwise, indicate bad settings via 'invalid'.1927*/1928bool validate(Json::Value* invalid) const;1929/** A simple way to update a specific setting.1930*/1931Value& operator[](JSONCPP_STRING key);19321933/** Called by ctor, but you can use this to reset settings_.1934* \pre 'settings' != NULL (but Json::null is fine)1935* \remark Defaults:1936* \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults1937*/1938static void setDefaults(Json::Value* settings);1939};19401941/** \brief Abstract class for writers.1942* \deprecated Use StreamWriter. (And really, this is an implementation detail.)1943*/1944class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {1945public:1946virtual ~Writer();19471948virtual JSONCPP_STRING write(const Value& root) = 0;1949};19501951/** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format1952*without formatting (not human friendly).1953*1954* The JSON document is written in a single line. It is not intended for 'human'1955*consumption,1956* but may be useful to support feature such as RPC where bandwidth is limited.1957* \sa Reader, Value1958* \deprecated Use StreamWriterBuilder.1959*/1960#if defined(_MSC_VER)1961#pragma warning(push)1962#pragma warning(disable:4996) // Deriving from deprecated class1963#endif1964class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter : public Writer {1965public:1966FastWriter();1967~FastWriter() JSONCPP_OVERRIDE {}19681969void enableYAMLCompatibility();19701971/** \brief Drop the "null" string from the writer's output for nullValues.1972* Strictly speaking, this is not valid JSON. But when the output is being1973* fed to a browser's JavaScript, it makes for smaller output and the1974* browser can handle the output just fine.1975*/1976void dropNullPlaceholders();19771978void omitEndingLineFeed();19791980public: // overridden from Writer1981JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE;19821983private:1984void writeValue(const Value& value);19851986JSONCPP_STRING document_;1987bool yamlCompatibilityEnabled_;1988bool dropNullPlaceholders_;1989bool omitEndingLineFeed_;1990};1991#if defined(_MSC_VER)1992#pragma warning(pop)1993#endif19941995/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a1996*human friendly way.1997*1998* The rules for line break and indent are as follow:1999* - Object value:2000* - if empty then print {} without indent and line break2001* - if not empty the print '{', line break & indent, print one value per2002*line2003* and then unindent and line break and print '}'.2004* - Array value:2005* - if empty then print [] without indent and line break2006* - if the array contains no object value, empty array or some other value2007*types,2008* and all the values fit on one lines, then print the array on a single2009*line.2010* - otherwise, it the values do not fit on one line, or the array contains2011* object or non empty array, then print one value per line.2012*2013* If the Value have comments then they are outputed according to their2014*#CommentPlacement.2015*2016* \sa Reader, Value, Value::setComment()2017* \deprecated Use StreamWriterBuilder.2018*/2019#if defined(_MSC_VER)2020#pragma warning(push)2021#pragma warning(disable:4996) // Deriving from deprecated class2022#endif2023class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledWriter : public Writer {2024public:2025StyledWriter();2026~StyledWriter() JSONCPP_OVERRIDE {}20272028public: // overridden from Writer2029/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.2030* \param root Value to serialize.2031* \return String containing the JSON document that represents the root value.2032*/2033JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE;20342035private:2036void writeValue(const Value& value);2037void writeArrayValue(const Value& value);2038bool isMultilineArray(const Value& value);2039void pushValue(const JSONCPP_STRING& value);2040void writeIndent();2041void writeWithIndent(const JSONCPP_STRING& value);2042void indent();2043void unindent();2044void writeCommentBeforeValue(const Value& root);2045void writeCommentAfterValueOnSameLine(const Value& root);2046bool hasCommentForValue(const Value& value);2047static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);20482049typedef std::vector<JSONCPP_STRING> ChildValues;20502051ChildValues childValues_;2052JSONCPP_STRING document_;2053JSONCPP_STRING indentString_;2054unsigned int rightMargin_;2055unsigned int indentSize_;2056bool addChildValues_;2057};2058#if defined(_MSC_VER)2059#pragma warning(pop)2060#endif20612062/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a2063human friendly way,2064to a stream rather than to a string.2065*2066* The rules for line break and indent are as follow:2067* - Object value:2068* - if empty then print {} without indent and line break2069* - if not empty the print '{', line break & indent, print one value per2070line2071* and then unindent and line break and print '}'.2072* - Array value:2073* - if empty then print [] without indent and line break2074* - if the array contains no object value, empty array or some other value2075types,2076* and all the values fit on one lines, then print the array on a single2077line.2078* - otherwise, it the values do not fit on one line, or the array contains2079* object or non empty array, then print one value per line.2080*2081* If the Value have comments then they are outputed according to their2082#CommentPlacement.2083*2084* \sa Reader, Value, Value::setComment()2085* \deprecated Use StreamWriterBuilder.2086*/2087#if defined(_MSC_VER)2088#pragma warning(push)2089#pragma warning(disable:4996) // Deriving from deprecated class2090#endif2091class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledStreamWriter {2092public:2093/**2094* \param indentation Each level will be indented by this amount extra.2095*/2096StyledStreamWriter(JSONCPP_STRING indentation = "\t");2097~StyledStreamWriter() {}20982099public:2100/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.2101* \param out Stream to write to. (Can be ostringstream, e.g.)2102* \param root Value to serialize.2103* \note There is no point in deriving from Writer, since write() should not2104* return a value.2105*/2106void write(JSONCPP_OSTREAM& out, const Value& root);21072108private:2109void writeValue(const Value& value);2110void writeArrayValue(const Value& value);2111bool isMultilineArray(const Value& value);2112void pushValue(const JSONCPP_STRING& value);2113void writeIndent();2114void writeWithIndent(const JSONCPP_STRING& value);2115void indent();2116void unindent();2117void writeCommentBeforeValue(const Value& root);2118void writeCommentAfterValueOnSameLine(const Value& root);2119bool hasCommentForValue(const Value& value);2120static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);21212122typedef std::vector<JSONCPP_STRING> ChildValues;21232124ChildValues childValues_;2125JSONCPP_OSTREAM* document_;2126JSONCPP_STRING indentString_;2127unsigned int rightMargin_;2128JSONCPP_STRING indentation_;2129bool addChildValues_ : 1;2130bool indented_ : 1;2131};2132#if defined(_MSC_VER)2133#pragma warning(pop)2134#endif21352136#if defined(JSON_HAS_INT64)2137JSONCPP_STRING JSON_API valueToString(Int value);2138JSONCPP_STRING JSON_API valueToString(UInt value);2139#endif // if defined(JSON_HAS_INT64)2140JSONCPP_STRING JSON_API valueToString(LargestInt value);2141JSONCPP_STRING JSON_API valueToString(LargestUInt value);2142JSONCPP_STRING JSON_API valueToString(double value, unsigned int precision = Value::defaultRealPrecision,2143PrecisionType precisionType = PrecisionType::significantDigits);2144JSONCPP_STRING JSON_API valueToString(bool value);2145JSONCPP_STRING JSON_API valueToQuotedString(const char* value);21462147/// \brief Output using the StyledStreamWriter.2148/// \see Json::operator>>()2149JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);21502151} // namespace Json21522153#pragma pack(pop)21542155#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)2156#pragma warning(pop)2157#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)21582159#endif // JSON_WRITER_H_INCLUDED21602161// //////////////////////////////////////////////////////////////////////2162// End of content of file: include/json/writer.h2163// //////////////////////////////////////////////////////////////////////2164216521662167216821692170// //////////////////////////////////////////////////////////////////////2171// Beginning of content of file: include/json/assertions.h2172// //////////////////////////////////////////////////////////////////////21732174// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors2175// Distributed under MIT license, or public domain if desired and2176// recognized in your jurisdiction.2177// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE21782179#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED2180#define CPPTL_JSON_ASSERTIONS_H_INCLUDED21812182#include <stdlib.h>2183#include <sstream>21842185#if !defined(JSON_IS_AMALGAMATION)2186#include "config.h"2187#endif // if !defined(JSON_IS_AMALGAMATION)21882189/** It should not be possible for a maliciously designed file to2190* cause an abort() or seg-fault, so these macros are used only2191* for pre-condition violations and internal logic errors.2192*/2193#if JSON_USE_EXCEPTION21942195// @todo <= add detail about condition in exception2196# define JSON_ASSERT(condition) \2197{if (!(condition)) {Json::throwLogicError( "assert json failed" );}}21982199# define JSON_FAIL_MESSAGE(message) \2200{ \2201JSONCPP_OSTRINGSTREAM oss; oss << message; \2202Json::throwLogicError(oss.str()); \2203abort(); \2204}22052206#else // JSON_USE_EXCEPTION22072208# define JSON_ASSERT(condition) assert(condition)22092210// The call to assert() will show the failure message in debug builds. In2211// release builds we abort, for a core-dump or debugger.2212# define JSON_FAIL_MESSAGE(message) \2213{ \2214JSONCPP_OSTRINGSTREAM oss; oss << message; \2215assert(false && oss.str().c_str()); \2216abort(); \2217}221822192220#endif22212222#define JSON_ASSERT_MESSAGE(condition, message) \2223if (!(condition)) { \2224JSON_FAIL_MESSAGE(message); \2225}22262227#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED22282229// //////////////////////////////////////////////////////////////////////2230// End of content of file: include/json/assertions.h2231// //////////////////////////////////////////////////////////////////////223222332234223522362237#endif //ifndef JSON_AMALGAMATED_H_INCLUDED223822392240