summaryrefslogtreecommitdiff
path: root/json/json.h
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2018-10-14 22:47:22 -0400
committerBrian Potchik <brian@vector35.com>2018-10-18 17:50:25 -0400
commit80cb1f68c83112c4d99893ad2f23bf22abdc4a6d (patch)
tree9ebd185b5d61fedccfd811d5b4a4720a1f669da0 /json/json.h
parente01f0e0fe635c0fe703fbdd09d44a5d7da7c4b93 (diff)
Initial Enhanced Settings System.
Diffstat (limited to 'json/json.h')
-rw-r--r--json/json.h498
1 files changed, 298 insertions, 200 deletions
diff --git a/json/json.h b/json/json.h
index 1561a120..51a38e65 100644
--- a/json/json.h
+++ b/json/json.h
@@ -1,4 +1,4 @@
-/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).
+/// Json-cpp amalgamated header (http://jsoncpp.sourceforge.net/).
/// It is intended to be used with #include "json/json.h"
// //////////////////////////////////////////////////////////////////////
@@ -10,13 +10,13 @@ The JsonCpp library's source code, including accompanying documentation,
tests and demonstration applications, are licensed under the following
conditions...
-The author (Baptiste Lepilleur) explicitly disclaims copyright in all
+Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
jurisdictions which recognize such a disclaimer. In such jurisdictions,
this software is released into the Public Domain.
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
-2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
-released under the terms of the MIT License (see below).
+2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
+The JsonCpp Authors, and is released under the terms of the MIT License (see below).
In jurisdictions which recognize Public Domain property, the user of this
software may choose to accept it either as 1) Public Domain, 2) under the
@@ -31,7 +31,7 @@ described in clear, concise terms at:
The full text of the MIT License follows:
========================================================================
-Copyright (c) 2007-2010 Baptiste Lepilleur
+Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
@@ -72,9 +72,9 @@ license you like.
-#ifndef JSON_AMALGATED_H_INCLUDED
-# define JSON_AMALGATED_H_INCLUDED
-/// If defined, indicates that the source file is amalgated
+#ifndef JSON_AMALGAMATED_H_INCLUDED
+# define JSON_AMALGAMATED_H_INCLUDED
+/// If defined, indicates that the source file is amalgamated
/// to prevent private header inclusion.
#define JSON_IS_AMALGAMATION
@@ -85,15 +85,16 @@ license you like.
// DO NOT EDIT. This file (and "version") is generated by CMake.
// Run CMake configure step to update it.
#ifndef JSON_VERSION_H_INCLUDED
-# define JSON_VERSION_H_INCLUDED
+#define JSON_VERSION_H_INCLUDED
-# define JSONCPP_VERSION_STRING "1.8.0"
-# define JSONCPP_VERSION_MAJOR 1
-# define JSONCPP_VERSION_MINOR 8
-# define JSONCPP_VERSION_PATCH 0
-
-# define JSONCPP_VERSION_QUALIFIER
-# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
+#define JSONCPP_VERSION_STRING "1.8.4"
+#define JSONCPP_VERSION_MAJOR 1
+#define JSONCPP_VERSION_MINOR 8
+#define JSONCPP_VERSION_PATCH 4
+#define JSONCPP_VERSION_QUALIFIER
+#define JSONCPP_VERSION_HEXA \
+ ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
+ (JSONCPP_VERSION_PATCH << 8))
#ifdef JSONCPP_USING_SECURE_MEMORY
#undef JSONCPP_USING_SECURE_MEMORY
@@ -117,7 +118,7 @@ license you like.
// Beginning of content of file: include/json/config.h
// //////////////////////////////////////////////////////////////////////
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -125,9 +126,8 @@ license you like.
#ifndef JSON_CONFIG_H_INCLUDED
#define JSON_CONFIG_H_INCLUDED
#include <stddef.h>
-
-#include <string> //typedef String
#include <stdint.h> //typedef int64_t, uint64_t
+#include <string> //typedef String
/// If defined, indicates that json library is embedded in CppTL library.
//# define JSON_IN_CPPTL 1
@@ -145,9 +145,9 @@ license you like.
#define JSON_USE_EXCEPTION 1
#endif
-/// If defined, indicates that the source file is amalgated
+/// If defined, indicates that the source file is amalgamated
/// to prevent private header inclusion.
-/// Remarks: it is automatically defined in the generated amalgated header.
+/// Remarks: it is automatically defined in the generated amalgamated header.
// #define JSON_IS_AMALGAMATION
#ifdef JSON_IN_CPPTL
@@ -180,40 +180,47 @@ license you like.
// #define JSON_NO_INT64 1
#if defined(_MSC_VER) // MSVC
-# if _MSC_VER <= 1200 // MSVC 6
- // Microsoft Visual Studio 6 only support conversion from __int64 to double
- // (no conversion from unsigned __int64).
-# define JSON_USE_INT64_DOUBLE_CONVERSION 1
- // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
- // characters in the debug information)
- // All projects I've ever seen with VS6 were using this globally (not bothering
- // with pragma push/pop).
-# pragma warning(disable : 4786)
-# endif // MSVC 6
+#if _MSC_VER <= 1200 // MSVC 6
+// Microsoft Visual Studio 6 only support conversion from __int64 to double
+// (no conversion from unsigned __int64).
+#define JSON_USE_INT64_DOUBLE_CONVERSION 1
+// Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
+// characters in the debug information)
+// All projects I've ever seen with VS6 were using this globally (not bothering
+// with pragma push/pop).
+#pragma warning(disable : 4786)
+#endif // MSVC 6
-# if _MSC_VER >= 1500 // MSVC 2008
- /// Indicates that the following function is deprecated.
-# define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
-# endif
+#if _MSC_VER >= 1500 // MSVC 2008
+ /// Indicates that the following function is deprecated.
+#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
+#endif
#endif // defined(_MSC_VER)
-// In c++11 the override keyword allows you to explicity define that a function
+// In c++11 the override keyword allows you to explicitly define that a function
// is intended to override the base-class version. This makes the code more
-// managable and fixes a set of common hard-to-find bugs.
-
+// manageable and fixes a set of common hard-to-find bugs.
#if __cplusplus >= 201103L
-# define JSONCPP_OVERRIDE override
-# define JSONCPP_NOEXCEPT noexcept
+#define JSONCPP_OVERRIDE override
+#define JSONCPP_NOEXCEPT noexcept
+#define JSONCPP_OP_EXPLICIT explicit
#elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900
-# define JSONCPP_OVERRIDE override
-# define JSONCPP_NOEXCEPT throw()
+#define JSONCPP_OVERRIDE override
+#define JSONCPP_NOEXCEPT throw()
+#if _MSC_VER >= 1800 // MSVC 2013
+#define JSONCPP_OP_EXPLICIT explicit
+#else
+#define JSONCPP_OP_EXPLICIT
+#endif
#elif defined(_MSC_VER) && _MSC_VER >= 1900
-# define JSONCPP_OVERRIDE override
-# define JSONCPP_NOEXCEPT noexcept
+#define JSONCPP_OVERRIDE override
+#define JSONCPP_NOEXCEPT noexcept
+#define JSONCPP_OP_EXPLICIT explicit
#else
-# define JSONCPP_OVERRIDE
-# define JSONCPP_NOEXCEPT throw()
+#define JSONCPP_OVERRIDE
+#define JSONCPP_NOEXCEPT throw()
+#define JSONCPP_OP_EXPLICIT
#endif
#ifndef JSON_HAS_RVALUE_REFERENCES
@@ -225,12 +232,12 @@ license you like.
#ifdef __clang__
#if __has_feature(cxx_rvalue_references)
#define JSON_HAS_RVALUE_REFERENCES 1
-#endif // has_feature
+#endif // has_feature
#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
#define JSON_HAS_RVALUE_REFERENCES 1
-#endif // GXX_EXPERIMENTAL
+#endif // GXX_EXPERIMENTAL
#endif // __clang__ || __GNUC__
@@ -241,12 +248,15 @@ license you like.
#endif
#ifdef __clang__
+#if __has_extension(attribute_deprecated_with_message)
+#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
+#endif
#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
-# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
-# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
-# elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
-# define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
-# endif // GNUC version
+#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
+#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
+#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
+#endif // GNUC version
#endif // __clang__ || __GNUC__
#if !defined(JSONCPP_DEPRECATED)
@@ -254,16 +264,16 @@ license you like.
#endif // if !defined(JSONCPP_DEPRECATED)
#if __GNUC__ >= 6
-# define JSON_USE_INT64_DOUBLE_CONVERSION 1
+#define JSON_USE_INT64_DOUBLE_CONVERSION 1
#endif
#if !defined(JSON_IS_AMALGAMATION)
-# include "version.h"
+#include "version.h"
-# if JSONCPP_USING_SECURE_MEMORY
-# include "allocator.h" //typedef Allocator
-# endif
+#if JSONCPP_USING_SECURE_MEMORY
+#include "allocator.h" //typedef Allocator
+#endif
#endif // if !defined(JSON_IS_AMALGAMATION)
@@ -280,27 +290,30 @@ typedef unsigned int LargestUInt;
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else // if defined(_MSC_VER) // Other platforms, use long long
-
typedef int64_t Int64;
typedef uint64_t UInt64;
-
-#endif // if defined(_MSC_VER)
+#endif // if defined(_MSC_VER)
typedef Int64 LargestInt;
typedef UInt64 LargestUInt;
#define JSON_HAS_INT64
#endif // if defined(JSON_NO_INT64)
#if JSONCPP_USING_SECURE_MEMORY
-#define JSONCPP_STRING std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
-#define JSONCPP_OSTRINGSTREAM std::basic_ostringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >
-#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char>>
-#define JSONCPP_ISTRINGSTREAM std::basic_istringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >
-#define JSONCPP_ISTREAM std::istream
+#define JSONCPP_STRING \
+ std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
+#define JSONCPP_OSTRINGSTREAM \
+ std::basic_ostringstream<char, std::char_traits<char>, \
+ Json::SecureAllocator<char> >
+#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char> >
+#define JSONCPP_ISTRINGSTREAM \
+ std::basic_istringstream<char, std::char_traits<char>, \
+ Json::SecureAllocator<char> >
+#define JSONCPP_ISTREAM std::istream
#else
-#define JSONCPP_STRING std::string
+#define JSONCPP_STRING std::string
#define JSONCPP_OSTRINGSTREAM std::ostringstream
-#define JSONCPP_OSTREAM std::ostream
+#define JSONCPP_OSTREAM std::ostream
#define JSONCPP_ISTRINGSTREAM std::istringstream
-#define JSONCPP_ISTREAM std::istream
+#define JSONCPP_ISTREAM std::istream
#endif // if JSONCPP_USING_SECURE_MEMORY
} // end namespace Json
@@ -319,7 +332,7 @@ typedef UInt64 LargestUInt;
// Beginning of content of file: include/json/forwards.h
// //////////////////////////////////////////////////////////////////////
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -370,7 +383,7 @@ class ValueConstIterator;
// Beginning of content of file: include/json/features.h
// //////////////////////////////////////////////////////////////////////
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -445,7 +458,7 @@ public:
// Beginning of content of file: include/json/value.h
// //////////////////////////////////////////////////////////////////////
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -456,9 +469,9 @@ public:
#if !defined(JSON_IS_AMALGAMATION)
#include "forwards.h"
#endif // if !defined(JSON_IS_AMALGAMATION)
+#include <exception>
#include <string>
#include <vector>
-#include <exception>
#ifndef JSON_USE_CPPTL_SMALLMAP
#include <map>
@@ -469,17 +482,17 @@ public:
#include <cpptl/forwards.h>
#endif
-//Conditional NORETURN attribute on the throw functions would:
-// a) suppress false positives from static code analysis
+// Conditional NORETURN attribute on the throw functions would:
+// a) suppress false positives from static code analysis
// b) possibly improve optimization opportunities.
#if !defined(JSONCPP_NORETURN)
-# if defined(_MSC_VER)
-# define JSONCPP_NORETURN __declspec(noreturn)
-# elif defined(__GNUC__)
-# define JSONCPP_NORETURN __attribute__ ((__noreturn__))
-# else
-# define JSONCPP_NORETURN
-# endif
+#if defined(_MSC_VER)
+#define JSONCPP_NORETURN __declspec(noreturn)
+#elif defined(__GNUC__)
+#define JSONCPP_NORETURN __attribute__((__noreturn__))
+#else
+#define JSONCPP_NORETURN
+#endif
#endif
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
@@ -502,7 +515,6 @@ namespace Json {
class JSON_API Exception : public std::exception {
public:
Exception(JSONCPP_STRING const& msg);
-
~Exception() JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;
char const* what() const JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;
@@ -513,7 +525,7 @@ protected:
/** Exceptions which the user cannot easily avoid.
*
* E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
- *
+ *
* \remark derived from Json::Exception
*/
class JSON_API RuntimeError : public Exception {
@@ -524,7 +536,7 @@ public:
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
*
* These are precondition-violations (user bugs) and internal errors (our bugs).
- *
+ *
* \remark derived from Json::Exception
*/
class JSON_API LogicError : public Exception {
@@ -558,6 +570,13 @@ enum CommentPlacement {
numberOfCommentPlacement
};
+/** \brief Type of precision for formatting of real values.
+ */
+enum PrecisionType {
+ significantDigits = 0, ///< we set max number of significant digits in string
+ decimalPlaces ///< we set max number of digits after "." in string
+};
+
//# ifdef JSON_USE_CPPTL
// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
// typedef CppTL::AnyEnumerator<const Value &> EnumValues;
@@ -565,7 +584,7 @@ enum CommentPlacement {
/** \brief Lightweight wrapper to tag static string.
*
- * Value constructor and objectValue member assignement takes advantage of the
+ * Value constructor and objectValue member assignment takes advantage of the
* StaticString and avoid the cost of string duplication when storing the
* string or the member name.
*
@@ -625,6 +644,7 @@ private:
*/
class JSON_API Value {
friend class ValueIteratorBase;
+
public:
typedef std::vector<JSONCPP_STRING> Members;
typedef ValueIterator iterator;
@@ -639,9 +659,13 @@ public:
typedef Json::LargestUInt LargestUInt;
typedef Json::ArrayIndex ArrayIndex;
- static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value().
- static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null
+ // Required for boost integration, e. g. BOOST_TEST
+ typedef std::string value_type;
+ static const Value& null; ///< We regret this reference to a global instance;
+ ///< prefer the simpler Value().
+ static const Value& nullRef; ///< just a kludge for binary-compatibility; same
+ ///< as null
static Value const& nullSingleton(); ///< Prefer this to null or nullRef.
/// Minimum signed integer value that can be stored in a Json::Value.
@@ -667,15 +691,21 @@ public:
static const UInt64 maxUInt64;
#endif // defined(JSON_HAS_INT64)
+ /// Default precision for real value for string representation.
+ static const UInt defaultRealPrecision;
+
+// Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler
+// when using gcc and clang backend compilers. CZString
+// cannot be defined as private. See issue #486
+#ifdef __NVCC__
+public:
+#else
private:
+#endif
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
class CZString {
public:
- enum DuplicationPolicy {
- noDuplication = 0,
- duplicate,
- duplicateOnCopy
- };
+ enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
CZString(ArrayIndex index);
CZString(char const* str, unsigned length, DuplicationPolicy allocate);
CZString(CZString const& other);
@@ -683,11 +713,16 @@ private:
CZString(CZString&& other);
#endif
~CZString();
- CZString& operator=(CZString other);
+ CZString& operator=(const CZString& other);
+
+#if JSON_HAS_RVALUE_REFERENCES
+ CZString& operator=(CZString&& other);
+#endif
+
bool operator<(CZString const& other) const;
bool operator==(CZString const& other) const;
ArrayIndex index() const;
- //const char* c_str() const; ///< \deprecated
+ // const char* c_str() const; ///< \deprecated
char const* data() const;
unsigned length() const;
bool isStaticString() const;
@@ -696,11 +731,11 @@ private:
void swap(CZString& other);
struct StringStorage {
- unsigned policy_: 2;
- unsigned length_: 30; // 1GB max
+ unsigned policy_ : 2;
+ unsigned length_ : 30; // 1GB max
};
- char const* cstr_; // actually, a prefixed string, unless policy is noDup
+ char const* cstr_; // actually, a prefixed string, unless policy is noDup
union {
ArrayIndex index_;
StringStorage storage_;
@@ -757,7 +792,8 @@ Json::Value obj_value(Json::objectValue); // {}
* \endcode
*/
Value(const StaticString& value);
- Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded zeroes too.
+ Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded
+ ///< zeroes too.
#ifdef JSON_USE_CPPTL
Value(const CppTL::ConstString& value);
#endif
@@ -771,13 +807,20 @@ Json::Value obj_value(Json::objectValue); // {}
~Value();
/// Deep copy, then swap(other).
- /// \note Over-write existing comments. To preserve comments, use #swapPayload().
+ /// \note Over-write existing comments. To preserve comments, use
+ /// #swapPayload().
Value& operator=(Value other);
+
/// Swap everything.
void swap(Value& other);
/// Swap values but leave comments and source offsets in place.
void swapPayload(Value& other);
+ /// copy everything.
+ void copy(const Value& other);
+ /// copy values but leave comments and source offsets in place.
+ void copyPayload(const Value& other);
+
ValueType type() const;
/// Compare payload only, not comments etc.
@@ -791,14 +834,14 @@ Json::Value obj_value(Json::objectValue); // {}
const char* asCString() const; ///< Embedded zeroes could cause you trouble!
#if JSONCPP_USING_SECURE_MEMORY
- unsigned getCStringLength() const; //Allows you to understand the length of the CString
+ unsigned getCStringLength() const; // Allows you to understand the length of
+ // the CString
#endif
JSONCPP_STRING asString() const; ///< Embedded zeroes are possible.
/** Get raw char* of string-value.
* \return false if !string. (Seg-fault if str or end are NULL.)
*/
- bool getString(
- char const** begin, char const** end) const;
+ bool getString(char const** begin, char const** end) const;
#ifdef JSON_USE_CPPTL
CppTL::ConstString asConstString() const;
#endif
@@ -836,20 +879,20 @@ Json::Value obj_value(Json::objectValue); // {}
/// otherwise, false.
bool empty() const;
- /// Return isNull()
- bool operator!() const;
+ /// Return !isNull()
+ JSONCPP_OP_EXPLICIT operator bool() const;
/// Remove all object members and array elements.
/// \pre type() is arrayValue, objectValue, or nullValue
/// \post type() is unchanged
void clear();
- /// Resize the array to size elements.
+ /// Resize the array to newSize elements.
/// New elements are initialized to null.
/// May only be called on nullValue or arrayValue.
/// \pre type() is arrayValue or nullValue
/// \post type() is arrayValue
- void resize(ArrayIndex size);
+ void resize(ArrayIndex newSize);
/// Access an array element (zero based index ).
/// If the array contains less than index element, then null value are
@@ -888,6 +931,10 @@ Json::Value obj_value(Json::objectValue); // {}
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
Value& append(const Value& value);
+#if JSON_HAS_RVALUE_REFERENCES
+ Value& append(Value&& value);
+#endif
+
/// Access an object value by name, create a null member if it does not exist.
/// \note Because of our implementation, keys are limited to 2^30 -1 chars.
/// Exceeding that will cause an exception.
@@ -905,7 +952,8 @@ Json::Value obj_value(Json::objectValue); // {}
/** \brief Access an object value by name, create a null member if it does not
exist.
- * If the object has no entry for that name, then the member name used to store
+ * If the object has no entry for that name, then the member name used to
+ store
* the new entry is not duplicated.
* Example of use:
* \code
@@ -928,7 +976,8 @@ Json::Value obj_value(Json::objectValue); // {}
/// Return the member named key if it exist, defaultValue otherwise.
/// \note deep copy
/// \note key may contain embedded nulls.
- Value get(const char* begin, const char* end, const Value& defaultValue) const;
+ Value
+ get(const char* begin, const char* end, const Value& defaultValue) const;
/// Return the member named key if it exist, defaultValue otherwise.
/// \note deep copy
/// \param key may contain embedded nulls.
@@ -953,11 +1002,11 @@ Json::Value obj_value(Json::objectValue); // {}
/// \pre type() is objectValue or nullValue
/// \post type() is unchanged
/// \deprecated
- Value removeMember(const char* key);
+ void removeMember(const char* key);
/// Same as removeMember(const char*)
/// \param key may contain embedded nulls.
/// \deprecated
- Value removeMember(const JSONCPP_STRING& key);
+ void removeMember(const JSONCPP_STRING& key);
/// Same as removeMember(const char* begin, const char* end, Value* removed),
/// but 'key' is null-terminated.
bool removeMember(const char* key, Value* removed);
@@ -974,9 +1023,9 @@ Json::Value obj_value(Json::objectValue); // {}
O(n) expensive operations.
Update 'removed' iff removed.
- \return true iff removed (no exceptions)
+ \return true if removed (no exceptions)
*/
- bool removeIndex(ArrayIndex i, Value* removed);
+ bool removeIndex(ArrayIndex index, Value* removed);
/// Return true if the object has a member named key.
/// \note 'key' must be null-terminated.
@@ -1031,6 +1080,9 @@ Json::Value obj_value(Json::objectValue); // {}
private:
void initBasic(ValueType type, bool allocated = false);
+ void dupPayload(const Value& other);
+ void releasePayload();
+ void dupMeta(const Value& other);
Value& resolveReference(const char* key);
Value& resolveReference(const char* key, const char* end);
@@ -1058,12 +1110,14 @@ private:
LargestUInt uint_;
double real_;
bool bool_;
- char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
+ char* string_; // actually ptr to unsigned, followed by str, unless
+ // !allocated_
ObjectValues* map_;
} value_;
ValueType type_ : 8;
- unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
- // If not allocated_, string_ must be null-terminated.
+ unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is
+ // useless. If not allocated_, string_ must be
+ // null-terminated.
CommentInfo* comments_;
// [start, limit) byte offsets in the source JSON text from which this Value
@@ -1085,11 +1139,7 @@ public:
PathArgument(const JSONCPP_STRING& key);
private:
- enum Kind {
- kindNone = 0,
- kindIndex,
- kindKey
- };
+ enum Kind { kindNone = 0, kindIndex, kindKey };
JSONCPP_STRING key_;
ArrayIndex index_;
Kind kind_;
@@ -1130,7 +1180,7 @@ private:
const InArgs& in,
InArgs::const_iterator& itInArg,
PathArgument::Kind kind);
- void invalidPath(const JSONCPP_STRING& path, int location);
+ static void invalidPath(const JSONCPP_STRING& path, int location);
Args args_;
};
@@ -1157,7 +1207,8 @@ public:
/// Value.
Value key() const;
- /// Return the index of the referenced Value, or -1 if it is not an arrayValue.
+ /// Return the index of the referenced Value, or -1 if it is not an
+ /// arrayValue.
UInt index() const;
/// Return the member name of the referenced Value, or "" if it is not an
@@ -1167,7 +1218,8 @@ public:
/// Return the member name of the referenced Value. "" if it is not an
/// objectValue.
- /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.
+ /// \deprecated This cannot be used for UTF-8 strings, since there can be
+ /// embedded nulls.
JSONCPP_DEPRECATED("Use `key = name();` instead.")
char const* memberName() const;
/// Return the member name of the referenced Value, or NULL if it is not an
@@ -1208,8 +1260,8 @@ class JSON_API ValueConstIterator : public ValueIteratorBase {
public:
typedef const Value value_type;
- //typedef unsigned int size_t;
- //typedef int difference_type;
+ // typedef unsigned int size_t;
+ // typedef int difference_type;
typedef const Value& reference;
typedef const Value* pointer;
typedef ValueConstIterator SelfType;
@@ -1218,9 +1270,10 @@ public:
ValueConstIterator(ValueIterator const& other);
private:
-/*! \internal Use by Value to create an iterator.
- */
+ /*! \internal Use by Value to create an iterator.
+ */
explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
+
public:
SelfType& operator=(const ValueIteratorBase& other);
@@ -1269,9 +1322,10 @@ public:
ValueIterator(const ValueIterator& other);
private:
-/*! \internal Use by Value to create an iterator.
- */
+ /*! \internal Use by Value to create an iterator.
+ */
explicit ValueIterator(const Value::ObjectValues::iterator& current);
+
public:
SelfType& operator=(const SelfType& other);
@@ -1302,14 +1356,9 @@ public:
pointer operator->() const { return &deref(); }
};
-} // namespace Json
-
+inline void swap(Value& a, Value& b) { a.swap(b); }
-namespace std {
-/// Specialize std::swap() for Json::Value.
-template<>
-inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
-}
+} // namespace Json
#pragma pack(pop)
@@ -1332,7 +1381,7 @@ inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
// Beginning of content of file: include/json/reader.h
// //////////////////////////////////////////////////////////////////////
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -1346,9 +1395,9 @@ inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <deque>
#include <iosfwd>
+#include <istream>
#include <stack>
#include <string>
-#include <istream>
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
// be used by...
@@ -1386,11 +1435,13 @@ public:
/** \brief Constructs a Reader allowing all features
* for parsing.
*/
+ JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
Reader();
/** \brief Constructs a Reader allowing the specified feature set
* for parsing.
*/
+ JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
Reader(const Features& features);
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
@@ -1483,7 +1534,9 @@ public:
* \return \c true if the error was successfully added, \c false if either
* Value offset exceeds the document size.
*/
- bool pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra);
+ bool pushError(const Value& value,
+ const JSONCPP_STRING& message,
+ const Value& extra);
/** \brief Return whether there are any errors.
* \return \c true if there are no errors to report \c false if
@@ -1550,7 +1603,8 @@ private:
Location& current,
Location end,
unsigned int& unicode);
- bool addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);
+ bool
+ addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);
bool recoverFromError(TokenType skipUntilToken);
bool addErrorAndRecover(const JSONCPP_STRING& message,
Token& token,
@@ -1564,6 +1618,9 @@ private:
void addComment(Location begin, Location end, CommentPlacement placement);
void skipCommentTokens(Token& token);
+ static bool containsNewLine(Location begin, Location end);
+ static JSONCPP_STRING normalizeEOL(Location begin, Location end);
+
typedef std::stack<Value*> Nodes;
Nodes nodes_;
Errors errors_;
@@ -1576,7 +1633,7 @@ private:
JSONCPP_STRING commentsBefore_;
Features features_;
bool collectComments_;
-}; // Reader
+}; // Reader
/** Interface for reading JSON from a char array.
*/
@@ -1585,7 +1642,8 @@ public:
virtual ~CharReader() {}
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
document.
- * The document must be a UTF-8 encoded string containing the document to read.
+ * The document must be a UTF-8 encoded string containing the document to
+ read.
*
* \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
document to read.
@@ -1600,9 +1658,10 @@ public:
* \return \c true if the document was successfully parsed, \c false if an
error occurred.
*/
- virtual bool parse(
- char const* beginDoc, char const* endDoc,
- Value* root, JSONCPP_STRING* errs) = 0;
+ virtual bool parse(char const* beginDoc,
+ char const* endDoc,
+ Value* root,
+ JSONCPP_STRING* errs) = 0;
class JSON_API Factory {
public:
@@ -1611,8 +1670,8 @@ public:
* \throw std::exception if something goes wrong (e.g. invalid settings)
*/
virtual CharReader* newCharReader() const = 0;
- }; // Factory
-}; // CharReader
+ }; // Factory
+}; // CharReader
/** \brief Build a CharReader implementation.
@@ -1642,7 +1701,8 @@ public:
- `"strictRoot": false or true`
- true if root must be either an array or an object value
- `"allowDroppedNullPlaceholders": false or true`
- - true if dropped null placeholders are allowed. (See StreamWriterBuilder.)
+ - true if dropped null placeholders are allowed. (See
+ StreamWriterBuilder.)
- `"allowNumericKeys": false or true`
- true if numeric object keys are allowed.
- `"allowSingleQuotes": false or true`
@@ -1656,9 +1716,10 @@ public:
- If true, `parse()` returns false when extra non-whitespace trails
the JSON value in the input string.
- `"rejectDupKeys": false or true`
- - If true, `parse()` returns false when a key is duplicated within an object.
+ - If true, `parse()` returns false when a key is duplicated within an
+ object.
- `"allowSpecialFloats": false or true`
- - If true, special float values (NaNs and infinities) are allowed
+ - If true, special float values (NaNs and infinities) are allowed
and their values are lossfree restorable.
You can examine 'settings_` yourself
@@ -1697,13 +1758,13 @@ public:
};
/** Consume entire stream and use its begin/end.
- * Someday we might have a real StreamReader, but for now this
- * is convenient.
- */
-bool JSON_API parseFromStream(
- CharReader::Factory const&,
- JSONCPP_ISTREAM&,
- Value* root, std::string* errs);
+ * Someday we might have a real StreamReader, but for now this
+ * is convenient.
+ */
+bool JSON_API parseFromStream(CharReader::Factory const&,
+ JSONCPP_ISTREAM&,
+ Value* root,
+ std::string* errs);
/** \brief Read from 'sin' into 'root'.
@@ -1754,7 +1815,7 @@ JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
// Beginning of content of file: include/json/writer.h
// //////////////////////////////////////////////////////////////////////
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -1765,18 +1826,17 @@ JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
#if !defined(JSON_IS_AMALGAMATION)
#include "value.h"
#endif // if !defined(JSON_IS_AMALGAMATION)
-#include <vector>
-#include <string>
#include <ostream>
+#include <string>
+#include <vector>
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
// be used by...
-#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4251)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
-
#pragma pack(push, 8)
namespace Json {
@@ -1798,15 +1858,15 @@ Usage:
*/
class JSON_API StreamWriter {
protected:
- JSONCPP_OSTREAM* sout_; // not owned; will not delete
+ JSONCPP_OSTREAM* sout_; // not owned; will not delete
public:
StreamWriter();
virtual ~StreamWriter();
/** Write Value into document as configured in sub-class.
Do not take ownership of sout, but maintain a reference during function.
\pre sout != NULL
- \return zero on success (For now, we always return zero, so check the stream instead.)
- \throw std::exception possibly, depending on configuration
+ \return zero on success (For now, we always return zero, so check the
+ stream instead.) \throw std::exception possibly, depending on configuration
*/
virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0;
@@ -1819,14 +1879,14 @@ public:
* \throw std::exception if something goes wrong (e.g. invalid settings)
*/
virtual StreamWriter* newStreamWriter() const = 0;
- }; // Factory
-}; // StreamWriter
+ }; // Factory
+}; // StreamWriter
/** \brief Write into stringstream, then return string, for convenience.
* A StreamWriter will be created from the factory, used, and then deleted.
*/
-JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory, Value const& root);
-
+JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory,
+ Value const& root);
/** \brief Build a StreamWriter implementation.
@@ -1850,18 +1910,23 @@ public:
/** Configuration of this builder.
Available settings (case-sensitive):
- "commentStyle": "None" or "All"
- - "indentation": "<anything>"
+ - "indentation": "<anything>".
+ - Setting this to an empty string also omits newline characters.
- "enableYAMLCompatibility": false or true
- slightly change the whitespace around colons
- "dropNullPlaceholders": false or true
- Drop the "null" string from the writer's output for nullValues.
Strictly speaking, this is not valid JSON. But when the output is being
- fed to a browser's Javascript, it makes for smaller output and the
+ fed to a browser's JavaScript, it makes for smaller output and the
browser can handle the output just fine.
- "useSpecialFloats": false or true
- If true, outputs non-finite floating point values in the following way:
- NaN values as "NaN", positive infinity as "Infinity", and negative infinity
- as "-Infinity".
+ NaN values as "NaN", positive infinity as "Infinity", and negative
+ infinity as "-Infinity".
+ - "precision": int
+ - Number of precision digits for formatting of real values.
+ - "precisionType": "significant"(default) or "decimal"
+ - Type of precision for formatting of real values.
You can examine 'settings_` yourself
to see the defaults. You can also write and read them just like any
@@ -1897,7 +1962,7 @@ public:
/** \brief Abstract class for writers.
* \deprecated Use StreamWriter. (And really, this is an implementation detail.)
*/
-class JSON_API Writer {
+class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {
public:
virtual ~Writer();
@@ -1909,12 +1974,16 @@ public:
*
* The JSON document is written in a single line. It is not intended for 'human'
*consumption,
- * but may be usefull to support feature such as RPC where bandwith is limited.
+ * but may be useful to support feature such as RPC where bandwidth is limited.
* \sa Reader, Value
* \deprecated Use StreamWriterBuilder.
*/
-class JSON_API FastWriter : public Writer {
-
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable : 4996) // Deriving from deprecated class
+#endif
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter
+ : public Writer {
public:
FastWriter();
~FastWriter() JSONCPP_OVERRIDE {}
@@ -1923,7 +1992,7 @@ public:
/** \brief Drop the "null" string from the writer's output for nullValues.
* Strictly speaking, this is not valid JSON. But when the output is being
- * fed to a browser's Javascript, it makes for smaller output and the
+ * fed to a browser's JavaScript, it makes for smaller output and the
* browser can handle the output just fine.
*/
void dropNullPlaceholders();
@@ -1937,10 +2006,13 @@ private:
void writeValue(const Value& value);
JSONCPP_STRING document_;
- bool yamlCompatiblityEnabled_;
+ bool yamlCompatibilityEnabled_;
bool dropNullPlaceholders_;
bool omitEndingLineFeed_;
};
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
*human friendly way.
@@ -1966,7 +2038,12 @@ private:
* \sa Reader, Value, Value::setComment()
* \deprecated Use StreamWriterBuilder.
*/
-class JSON_API StyledWriter : public Writer {
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable : 4996) // Deriving from deprecated class
+#endif
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
+ StyledWriter : public Writer {
public:
StyledWriter();
~StyledWriter() JSONCPP_OVERRIDE {}
@@ -1981,7 +2058,7 @@ public: // overridden from Writer
private:
void writeValue(const Value& value);
void writeArrayValue(const Value& value);
- bool isMultineArray(const Value& value);
+ bool isMultilineArray(const Value& value);
void pushValue(const JSONCPP_STRING& value);
void writeIndent();
void writeWithIndent(const JSONCPP_STRING& value);
@@ -1989,7 +2066,7 @@ private:
void unindent();
void writeCommentBeforeValue(const Value& root);
void writeCommentAfterValueOnSameLine(const Value& root);
- bool hasCommentForValue(const Value& value);
+ static bool hasCommentForValue(const Value& value);
static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
typedef std::vector<JSONCPP_STRING> ChildValues;
@@ -2001,6 +2078,9 @@ private:
unsigned int indentSize_;
bool addChildValues_;
};
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
human friendly way,
@@ -2024,13 +2104,20 @@ private:
* If the Value have comments then they are outputed according to their
#CommentPlacement.
*
- * \param indentation Each level will be indented by this amount extra.
* \sa Reader, Value, Value::setComment()
* \deprecated Use StreamWriterBuilder.
*/
-class JSON_API StyledStreamWriter {
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable : 4996) // Deriving from deprecated class
+#endif
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
+ StyledStreamWriter {
public:
- StyledStreamWriter(JSONCPP_STRING indentation = "\t");
+ /**
+ * \param indentation Each level will be indented by this amount extra.
+ */
+ StyledStreamWriter(const JSONCPP_STRING& indentation = "\t");
~StyledStreamWriter() {}
public:
@@ -2045,7 +2132,7 @@ public:
private:
void writeValue(const Value& value);
void writeArrayValue(const Value& value);
- bool isMultineArray(const Value& value);
+ bool isMultilineArray(const Value& value);
void pushValue(const JSONCPP_STRING& value);
void writeIndent();
void writeWithIndent(const JSONCPP_STRING& value);
@@ -2053,7 +2140,7 @@ private:
void unindent();
void writeCommentBeforeValue(const Value& root);
void writeCommentAfterValueOnSameLine(const Value& root);
- bool hasCommentForValue(const Value& value);
+ static bool hasCommentForValue(const Value& value);
static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
typedef std::vector<JSONCPP_STRING> ChildValues;
@@ -2066,6 +2153,9 @@ private:
bool addChildValues_ : 1;
bool indented_ : 1;
};
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
#if defined(JSON_HAS_INT64)
JSONCPP_STRING JSON_API valueToString(Int value);
@@ -2073,7 +2163,10 @@ JSONCPP_STRING JSON_API valueToString(UInt value);
#endif // if defined(JSON_HAS_INT64)
JSONCPP_STRING JSON_API valueToString(LargestInt value);
JSONCPP_STRING JSON_API valueToString(LargestUInt value);
-JSONCPP_STRING JSON_API valueToString(double value);
+JSONCPP_STRING JSON_API
+valueToString(double value,
+ unsigned int precision = Value::defaultRealPrecision,
+ PrecisionType precisionType = PrecisionType::significantDigits);
JSONCPP_STRING JSON_API valueToString(bool value);
JSONCPP_STRING JSON_API valueToQuotedString(const char* value);
@@ -2104,7 +2197,7 @@ JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
// Beginning of content of file: include/json/assertions.h
// //////////////////////////////////////////////////////////////////////
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -2112,8 +2205,8 @@ JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
-#include <stdlib.h>
#include <sstream>
+#include <stdlib.h>
#if !defined(JSON_IS_AMALGAMATION)
#include "config.h"
@@ -2126,30 +2219,35 @@ JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
#if JSON_USE_EXCEPTION
// @todo <= add detail about condition in exception
-# define JSON_ASSERT(condition) \
- {if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
+#define JSON_ASSERT(condition) \
+ { \
+ if (!(condition)) { \
+ Json::throwLogicError("assert json failed"); \
+ } \
+ }
-# define JSON_FAIL_MESSAGE(message) \
+#define JSON_FAIL_MESSAGE(message) \
{ \
- JSONCPP_OSTRINGSTREAM oss; oss << message; \
+ JSONCPP_OSTRINGSTREAM oss; \
+ oss << message; \
Json::throwLogicError(oss.str()); \
abort(); \
}
#else // JSON_USE_EXCEPTION
-# define JSON_ASSERT(condition) assert(condition)
+#define JSON_ASSERT(condition) assert(condition)
// The call to assert() will show the failure message in debug builds. In
// release builds we abort, for a core-dump or debugger.
-# define JSON_FAIL_MESSAGE(message) \
+#define JSON_FAIL_MESSAGE(message) \
{ \
- JSONCPP_OSTRINGSTREAM oss; oss << message; \
+ JSONCPP_OSTRINGSTREAM oss; \
+ oss << message; \
assert(false && oss.str().c_str()); \
abort(); \
}
-
#endif
#define JSON_ASSERT_MESSAGE(condition, message) \
@@ -2167,4 +2265,4 @@ JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
-#endif //ifndef JSON_AMALGATED_H_INCLUDED
+#endif //ifndef JSON_AMALGAMATED_H_INCLUDED