Go to the documentation of this file.
6 #ifndef JSON_H_INCLUDED
7 #define JSON_H_INCLUDED
9 #if !defined(JSON_IS_AMALGAMATION)
11 #endif // if !defined(JSON_IS_AMALGAMATION)
16 #if !defined(JSONCPP_NORETURN)
17 #if defined(_MSC_VER) && _MSC_VER == 1800
18 #define JSONCPP_NORETURN __declspec(noreturn)
20 #define JSONCPP_NORETURN [[noreturn]]
27 #if !defined(JSONCPP_TEMPLATE_DELETE)
28 #if defined(__clang__) && defined(__apple_build_version__)
29 #if __apple_build_version__ <= 8000042
30 #define JSONCPP_TEMPLATE_DELETE
32 #elif defined(__clang__)
33 #if __clang_major__ == 3 && __clang_minor__ <= 8
34 #define JSONCPP_TEMPLATE_DELETE
37 #if !defined(JSONCPP_TEMPLATE_DELETE)
38 #define JSONCPP_TEMPLATE_DELETE = delete
51 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
53 #pragma warning(disable : 4251)
54 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
62 #if JSON_USE_EXCEPTION
71 char const* what() const noexcept override;
151 operator const char*()
const {
return c_str_; }
153 const char*
c_str()
const {
return c_str_; }
202 #if defined(JSON_HAS_INT64)
205 #endif // defined(JSON_HAS_INT64)
220 static Value const& nullSingleton();
237 #if defined(JSON_HAS_INT64)
244 #endif // defined(JSON_HAS_INT64)
245 static constexpr
UInt defaultRealPrecision = 17;
250 static constexpr
double maxUInt64AsDouble = 18446744073709551615.0;
259 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
262 enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
264 CZString(
char const* str,
unsigned length, DuplicationPolicy allocate);
265 CZString(CZString
const& other);
266 CZString(CZString&& other);
268 CZString& operator=(
const CZString& other);
269 CZString& operator=(CZString&& other);
271 bool operator<(CZString
const& other)
const;
275 char const* data()
const;
276 unsigned length()
const;
277 bool isStaticString()
const;
280 void swap(CZString& other);
282 struct StringStorage {
283 unsigned policy_ : 2;
284 unsigned length_ : 30;
290 StringStorage storage_;
295 typedef std::map<CZString, Value> ObjectValues;
296 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
318 #if defined(JSON_HAS_INT64)
321 #endif // if defined(JSON_HAS_INT64)
323 Value(
const char* value);
324 Value(
const char* begin,
const char* end);
358 void swapPayload(
Value& other);
361 void copy(
const Value& other);
363 void copyPayload(
const Value& other);
368 bool operator<(
const Value& other)
const;
369 bool operator<=(
const Value& other)
const;
370 bool operator>=(
const Value& other)
const;
371 bool operator>(
const Value& other)
const;
374 int compare(
const Value& other)
const;
376 const char* asCString()
const;
377 #if JSONCPP_USING_SECURE_MEMORY
378 unsigned getCStringLength()
const;
385 bool getString(
char const** begin,
char const** end)
const;
388 #if defined(JSON_HAS_INT64)
389 Int64 asInt64()
const;
391 #endif // if defined(JSON_HAS_INT64)
394 float asFloat()
const;
395 double asDouble()
const;
401 bool isInt64()
const;
403 bool isUInt64()
const;
404 bool isIntegral()
const;
405 bool isDouble()
const;
406 bool isNumeric()
const;
407 bool isString()
const;
408 bool isArray()
const;
409 bool isObject()
const;
415 bool isConvertibleTo(
ValueType other) const;
425 explicit operator
bool() const;
446 Value& operator[](
int index);
454 const
Value& operator[](
int index) const;
475 Value& operator[](const
char* key);
478 const
Value& operator[](const
char* key) const;
501 Value get(const
char* key, const
Value& defaultValue) const;
505 Value get(const
char* begin, const
char* end,
506 const
Value& defaultValue) const;
514 Value const* find(
char const* begin,
char const* end) const;
518 Value* demand(
char const* begin,
char const* end);
524 void removeMember(const
char* key);
527 void removeMember(const
String& key);
530 bool removeMember(const
char* key,
Value* removed);
537 bool removeMember(
String const& key,
Value* removed);
539 bool removeMember(const
char* begin, const
char* end,
Value* removed);
550 bool isMember(const
char* key) const;
553 bool isMember(const
String& key) const;
555 bool isMember(const
char* begin, const
char* end) const;
562 Members getMemberNames() const;
567 setComment(
String(comment, strlen(comment)), placement);
571 setComment(
String(comment, len), placement);
579 String toStyledString()
const;
581 const_iterator begin()
const;
582 const_iterator end()
const;
589 void setOffsetStart(ptrdiff_t start);
590 void setOffsetLimit(ptrdiff_t limit);
591 ptrdiff_t getOffsetStart()
const;
592 ptrdiff_t getOffsetLimit()
const;
596 bits_.value_type_ =
static_cast<unsigned char>(v);
598 bool isAllocated()
const {
return bits_.allocated_; }
599 void setIsAllocated(
bool v) { bits_.allocated_ = v; }
601 void initBasic(
ValueType type,
bool allocated =
false);
602 void dupPayload(
const Value& other);
603 void releasePayload();
604 void dupMeta(
const Value& other);
606 Value& resolveReference(
const char* key);
607 Value& resolveReference(
const char* key,
const char* end);
636 Comments() =
default;
637 Comments(
const Comments& that);
638 Comments(Comments&& that);
639 Comments& operator=(
const Comments& that);
640 Comments& operator=(Comments&& that);
646 using Array = std::array<String, numberOfCommentPlacement>;
647 std::unique_ptr<Array> ptr_;
657 template <>
inline bool Value::as<bool>()
const {
return asBool(); }
658 template <>
inline bool Value::is<bool>()
const {
return isBool(); }
660 template <>
inline Int Value::as<Int>()
const {
return asInt(); }
661 template <>
inline bool Value::is<Int>()
const {
return isInt(); }
663 template <>
inline UInt Value::as<UInt>()
const {
return asUInt(); }
664 template <>
inline bool Value::is<UInt>()
const {
return isUInt(); }
666 #if defined(JSON_HAS_INT64)
667 template <>
inline Int64 Value::as<Int64>()
const {
return asInt64(); }
668 template <>
inline bool Value::is<Int64>()
const {
return isInt64(); }
670 template <>
inline UInt64 Value::as<UInt64>()
const {
return asUInt64(); }
671 template <>
inline bool Value::is<UInt64>()
const {
return isUInt64(); }
674 template <>
inline double Value::as<double>()
const {
return asDouble(); }
675 template <>
inline bool Value::is<double>()
const {
return isDouble(); }
677 template <>
inline String Value::as<String>()
const {
return asString(); }
678 template <>
inline bool Value::is<String>()
const {
return isString(); }
682 template <>
inline float Value::as<float>()
const {
return asFloat(); }
683 template <>
inline const char* Value::as<const char*>()
const {
700 enum Kind { kindNone = 0, kindIndex, kindKey };
703 Kind kind_{kindNone};
725 const Value& resolve(
const Value& root)
const;
732 using InArgs = std::vector<const PathArgument*>;
733 using Args = std::vector<PathArgument>;
735 void makePath(
const String& path,
const InArgs& in);
736 void addPathInArg(
const String& path,
const InArgs& in,
737 InArgs::const_iterator& itInArg, PathArgument::Kind kind);
738 static void invalidPath(
const String& path,
int location);
749 using size_t =
unsigned int;
779 char const* memberName() const;
783 char const* memberName(
char const** end) const;
792 const
Value& deref() const;
801 bool isEqual(const
SelfType& other) const;
806 Value::ObjectValues::iterator current_;
876 using size_t =
unsigned int;
889 explicit ValueIterator(
const Value::ObjectValues::iterator& current);
931 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
933 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
935 #endif // JSON_H_INCLUDED
bool operator!=(const SelfType &other) const
#define JSONCPP_TEMPLATE_DELETE
pointer operator->() const
ValueType
Type of the value held by a Value object.
@ numberOfCommentPlacement
root value)
Json::LargestUInt LargestUInt
@ uintValue
unsigned integer value
@ significantDigits
we set max number of significant digits in string
@ commentAfterOnSameLine
a comment just after a value on the same line
const iterator for object and array value.
bool operator==(const SelfType &other) const
@ commentBefore
a comment placed on the line before a value
Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
@ stringValue
UTF-8 string value.
Iterator for object and array value.
bool operator==(const SecureAllocator< T > &, const SecureAllocator< U > &)
difference_type computeDistance(const SelfType &other) const
Experimental and untested: represents a "path" to access a node.
std::bidirectional_iterator_tag iterator_category
@ commentAfter
a comment on the line after a value (only make sense for
@ intValue
signed integer value
@ decimalPlaces
we set max number of digits after "." in string
bool operator!=(const SecureAllocator< T > &, const SecureAllocator< U > &)
~Exception() noexcept override
ValueIterator(const ValueIterator &other)
@ arrayValue
array value (ordered list)
PrecisionType
Type of precision for formatting of real values.
void swap(Value &other)
Swap everything.
Base class for all exceptions we throw.
StaticString(const char *czstring)
Json::LargestInt LargestInt
Experimental and untested: represents an element of the "path" to access a node.
Json::ArrayIndex ArrayIndex
#define JSONCPP_DEPRECATED(message)
void swap(Value &a, Value &b)
JSON (JavaScript Object Notation).
#define JSON_API
If defined, indicates that the source file is amalgamated to prevent private header inclusion.
std::vector< String > Members
base class for Value iterators.
@ objectValue
object value (collection of name/value pairs).
const char * c_str() const
Value(std::nullptr_t ptr)=delete
static const Value & nullRef
std::basic_string< char, std::char_traits< char >, Allocator< char > > String
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... */.
reference operator*() const
T as() const =delete
The as<T> and is<T> member function templates and specializations.
difference_type operator-(const SelfType &other) const
Lightweight wrapper to tag static string.
Exceptions which the user cannot easily avoid.