JsonCpp project page | Classes | Namespace | JsonCpp home page

value.h
Go to the documentation of this file.
// 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
#ifndef JSON_VALUE_H_INCLUDED
#define JSON_VALUE_H_INCLUDED
#if !defined(JSON_IS_AMALGAMATION)
#include "forwards.h"
#endif // if !defined(JSON_IS_AMALGAMATION)
// 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) && _MSC_VER == 1800
#define JSONCPP_NORETURN __declspec(noreturn)
#else
#define JSONCPP_NORETURN [[noreturn]]
#endif
#endif
// Support for '= delete' with template declarations was a late addition
// to the c++11 standard and is rejected by clang 3.8 and Apple clang 8.2
// even though these declare themselves to be c++11 compilers.
#if !defined(JSONCPP_TEMPLATE_DELETE)
#if defined(__clang__) && defined(__apple_build_version__)
#if __apple_build_version__ <= 8000042
#define JSONCPP_TEMPLATE_DELETE
#endif
#elif defined(__clang__)
#if __clang_major__ == 3 && __clang_minor__ <= 8
#define JSONCPP_TEMPLATE_DELETE
#endif
#endif
#if !defined(JSONCPP_TEMPLATE_DELETE)
#define JSONCPP_TEMPLATE_DELETE = delete
#endif
#endif
#ifndef JSONCPP_HAS_STRING_VIEW
#if __cplusplus >= 201703L
#define JSONCPP_HAS_STRING_VIEW 1
#endif
#endif
#include <array>
#include <exception>
#include <map>
#include <memory>
#include <string>
#include <vector>
// Forward declaration for testing.
struct ValueTest;
#ifdef JSONCPP_HAS_STRING_VIEW
#include <string_view>
#endif
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
// be used by...
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma warning(push)
#pragma warning(disable : 4251 4275)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma pack(push)
#pragma pack()
namespace Json {
#if JSON_USE_EXCEPTION
class JSON_API Exception : public std::exception {
public:
Exception(String msg);
~Exception() noexcept override;
char const* what() const noexcept override;
protected:
String msg_;
};
class JSON_API RuntimeError : public Exception {
public:
RuntimeError(String const& msg);
};
class JSON_API LogicError : public Exception {
public:
LogicError(String const& msg);
};
#endif
JSONCPP_NORETURN void throwRuntimeError(String const& msg);
JSONCPP_NORETURN void throwLogicError(String const& msg);
enum ValueType {
nullValue = 0,
intValue,
uintValue,
realValue,
stringValue,
booleanValue,
arrayValue,
objectValue
};
enum CommentPlacement {
commentBefore = 0,
commentAfterOnSameLine,
commentAfter,
numberOfCommentPlacement
};
enum PrecisionType {
significantDigits = 0,
decimalPlaces
};
class JSON_API StaticString {
public:
explicit StaticString(const char* czstring) : c_str_(czstring) {}
operator const char*() const { return c_str_; }
const char* c_str() const { return c_str_; }
private:
const char* c_str_;
};
class JSON_API Value {
friend class ValueIteratorBase;
friend struct ::ValueTest;
public:
using Members = std::vector<String>;
using iterator = ValueIterator;
using const_iterator = ValueConstIterator;
using UInt = Json::UInt;
using Int = Json::Int;
#if defined(JSON_HAS_INT64)
using UInt64 = Json::UInt64;
using Int64 = Json::Int64;
#endif // defined(JSON_HAS_INT64)
using LargestInt = Json::LargestInt;
using LargestUInt = Json::LargestUInt;
using ArrayIndex = Json::ArrayIndex;
// Required for boost integration, e. g. BOOST_TEST
using value_type = std::string;
#if JSON_USE_NULLREF
// Binary compatibility kludges, do not use.
static const Value& null;
static const Value& nullRef;
#endif
// null and nullRef are deprecated, use this instead.
static Value const& nullSingleton();
static constexpr LargestInt minLargestInt =
LargestInt(~(LargestUInt(-1) / 2));
static constexpr LargestInt maxLargestInt = LargestInt(LargestUInt(-1) / 2);
static constexpr LargestUInt maxLargestUInt = LargestUInt(-1);
static constexpr Int minInt = Int(~(UInt(-1) / 2));
static constexpr Int maxInt = Int(UInt(-1) / 2);
static constexpr UInt maxUInt = UInt(-1);
#if defined(JSON_HAS_INT64)
static constexpr Int64 minInt64 = Int64(~(UInt64(-1) / 2));
static constexpr Int64 maxInt64 = Int64(UInt64(-1) / 2);
static constexpr UInt64 maxUInt64 = UInt64(-1);
#endif // defined(JSON_HAS_INT64)
static constexpr UInt defaultRealPrecision = 17;
// The constant is hard-coded because some compiler have trouble
// converting Value::maxUInt64 to a double correctly (AIX/xlC).
// Assumes that UInt64 is a 64 bits integer.
static constexpr double maxUInt64AsDouble = 18446744073709551615.0;
// 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 JSON_API CZString {
public:
enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
CZString(ArrayIndex index);
CZString(char const* str, unsigned length, DuplicationPolicy allocate);
CZString(CZString const& other);
CZString(CZString&& other) noexcept;
~CZString();
CZString& operator=(const CZString& other);
CZString& operator=(CZString&& other) noexcept;
bool operator<(CZString const& other) const;
bool operator==(CZString const& other) const;
ArrayIndex index() const;
// const char* c_str() const; ///< \deprecated
char const* data() const;
unsigned length() const;
bool isStaticString() const;
private:
void swap(CZString& other);
struct StringStorage {
unsigned policy_ : 2;
unsigned length_ : 30; // 1GB max
};
char const* cstr_; // actually, a prefixed string, unless policy is noDup
union {
ArrayIndex index_;
StringStorage storage_;
};
};
public:
typedef std::map<CZString, Value> ObjectValues;
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
public:
Value(ValueType type = nullValue);
Value(Int value);
Value(UInt value);
#if defined(JSON_HAS_INT64)
Value(Int64 value);
Value(UInt64 value);
#endif // if defined(JSON_HAS_INT64)
Value(double value);
Value(const char* value);
Value(const char* begin, const char* end);
Value(const StaticString& value);
Value(const String& value);
#ifdef JSONCPP_HAS_STRING_VIEW
inline Value(std::string_view value)
: Value(value.data(), value.data() + value.length()) {}
#endif
Value(bool value);
Value(std::nullptr_t ptr) = delete;
Value(const Value& other);
Value(Value&& other) noexcept;
~Value();
Value& operator=(const Value& other);
Value& operator=(Value&& other) noexcept;
void swap(Value& other);
void swapPayload(Value& other);
void copy(const Value& other);
void copyPayload(const Value& other);
ValueType type() const;
bool operator<(const Value& other) const;
bool operator<=(const Value& other) const;
bool operator>=(const Value& other) const;
bool operator>(const Value& other) const;
bool operator==(const Value& other) const;
bool operator!=(const Value& other) const;
int compare(const Value& other) const;
const char* asCString() const;
#if JSONCPP_USE_SECURE_MEMORY
unsigned getCStringLength() const; // Allows you to understand the length of
// the CString
#endif
String asString() const;
bool getString(char const** begin, char const** end) const;
#ifdef JSONCPP_HAS_STRING_VIEW
inline bool getString(std::string_view* str) const {
char const* begin;
char const* end;
if (!getString(&begin, &end))
return false;
*str = std::string_view(begin, static_cast<size_t>(end - begin));
return true;
}
#endif
Int asInt() const;
UInt asUInt() const;
#if defined(JSON_HAS_INT64)
Int64 asInt64() const;
UInt64 asUInt64() const;
#endif // if defined(JSON_HAS_INT64)
LargestInt asLargestInt() const;
LargestUInt asLargestUInt() const;
float asFloat() const;
double asDouble() const;
bool asBool() const;
bool isNull() const;
bool isBool() const;
bool isInt() const;
bool isInt64() const;
bool isUInt() const;
bool isUInt64() const;
bool isIntegral() const;
bool isDouble() const;
bool isNumeric() const;
bool isString() const;
bool isArray() const;
bool isObject() const;
template <typename T> T as() const JSONCPP_TEMPLATE_DELETE;
template <typename T> bool is() const JSONCPP_TEMPLATE_DELETE;
bool isConvertibleTo(ValueType other) const;
ArrayIndex size() const;
bool empty() const;
explicit operator bool() const;
void clear();
void resize(ArrayIndex newSize);
Value& operator[](ArrayIndex index);
Value& operator[](int index);
const Value& operator[](ArrayIndex index) const;
const Value& operator[](int index) const;
Value get(ArrayIndex index, const Value& defaultValue) const;
bool isValidIndex(ArrayIndex index) const;
Value& append(const Value& value);
Value& append(Value&& value);
bool insert(ArrayIndex index, const Value& newValue);
bool insert(ArrayIndex index, Value&& newValue);
#ifdef JSONCPP_HAS_STRING_VIEW
inline Value& operator[](std::string_view key) {
return resolveReference(key.data(), key.data() + key.length());
}
inline const Value& operator[](std::string_view key) const {
Value const* found = find(key.data(), key.data() + key.length());
if (!found)
return nullSingleton();
return *found;
}
#endif
Value& operator[](const char* key);
const Value& operator[](const char* key) const;
Value& operator[](const String& key);
const Value& operator[](const String& key) const;
Value& operator[](const StaticString& key);
#ifdef JSONCPP_HAS_STRING_VIEW
inline Value get(std::string_view key, const Value& defaultValue) const {
return get(key.data(), key.data() + key.length(), defaultValue);
}
#endif
Value get(const char* key, const Value& defaultValue) const;
Value get(const String& key, const Value& defaultValue) const;
Value get(const char* begin, const char* end,
const Value& defaultValue) const;
Value const* find(char const* begin, char const* end) const;
Value const* find(const String& key) const;
template <typename T, bool (T::*TMemFn)() const>
Value const* findValue(const String& key) const {
Value const* found = find(key);
if (!found || !(found->*TMemFn)())
return nullptr;
return found;
}
Value const* findNull(const String& key) const;
Value const* findBool(const String& key) const;
Value const* findInt(const String& key) const;
Value const* findInt64(const String& key) const;
Value const* findUInt(const String& key) const;
Value const* findUInt64(const String& key) const;
Value const* findIntegral(const String& key) const;
Value const* findDouble(const String& key) const;
Value const* findNumeric(const String& key) const;
Value const* findString(const String& key) const;
Value const* findArray(const String& key) const;
Value const* findObject(const String& key) const;
Value* demand(char const* begin, char const* end);
#if JSONCPP_HAS_STRING_VIEW
inline void removeMember(std::string_view key) {
removeMember(key.data(), key.data() + key.length(), nullptr);
}
#endif
void removeMember(const char* key);
void removeMember(const String& key);
#if JSONCPP_HAS_STRING_VIEW
inline bool removeMember(std::string_view key, Value* removed) {
return removeMember(key.data(), key.data() + key.length(), removed);
}
#endif
bool removeMember(String const& key, Value* removed);
bool removeMember(const char* key, Value* removed);
bool removeMember(const char* begin, const char* end, Value* removed);
bool removeIndex(ArrayIndex index, Value* removed);
#ifdef JSONCPP_HAS_STRING_VIEW
inline bool isMember(std::string_view key) const {
return isMember(key.data(), key.data() + key.length());
}
#endif
bool isMember(const char* key) const;
bool isMember(const String& key) const;
bool isMember(const char* begin, const char* end) const;
Members getMemberNames() const;
JSONCPP_DEPRECATED("Use setComment(String const&) instead.")
void setComment(const char* comment, CommentPlacement placement) {
setComment(String(comment, strlen(comment)), placement);
}
void setComment(const char* comment, size_t len, CommentPlacement placement) {
setComment(String(comment, len), placement);
}
void setComment(String comment, CommentPlacement placement);
bool hasComment(CommentPlacement placement) const;
String getComment(CommentPlacement placement) const;
String toStyledString() const;
const_iterator begin() const;
const_iterator end() const;
iterator begin();
iterator end();
// \brief Returns a view of member pairs for range-based for loops.
ValueMembersView members();
// \brief Returns a view of member pairs for range-based for loops.
ValueConstMembersView members() const;
const Value& front() const;
Value& front();
const Value& back() const;
Value& back();
// Accessors for the [start, limit) range of bytes within the JSON text from
// which this value was parsed, if any.
void setOffsetStart(ptrdiff_t start);
void setOffsetLimit(ptrdiff_t limit);
ptrdiff_t getOffsetStart() const;
ptrdiff_t getOffsetLimit() const;
private:
void setType(ValueType v) {
bits_.value_type_ = static_cast<unsigned char>(v);
}
bool isAllocated() const { return bits_.allocated_; }
void setIsAllocated(bool v) { bits_.allocated_ = v; }
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);
// struct MemberNamesTransform
//{
// typedef const char *result_type;
// const char *operator()( const CZString &name ) const
// {
// return name.c_str();
// }
//};
union ValueHolder {
LargestInt int_;
LargestUInt uint_;
double real_;
bool bool_;
char* string_; // if allocated_, ptr to { unsigned, char[] }.
ObjectValues* map_;
} value_;
struct {
// Really a ValueType, but types should agree for bitfield packing.
unsigned int value_type_ : 8;
// Unless allocated_, string_ must be null-terminated.
unsigned int allocated_ : 1;
} bits_;
class Comments {
public:
Comments() = default;
Comments(const Comments& that);
Comments(Comments&& that) noexcept;
Comments& operator=(const Comments& that);
Comments& operator=(Comments&& that) noexcept;
bool has(CommentPlacement slot) const;
String get(CommentPlacement slot) const;
void set(CommentPlacement slot, String comment);
private:
using Array = std::array<String, numberOfCommentPlacement>;
std::unique_ptr<Array> ptr_;
};
Comments comments_;
// [start, limit) byte offsets in the source JSON text from which this Value
// was extracted.
ptrdiff_t start_;
ptrdiff_t limit_;
};
template <> inline bool Value::as<bool>() const { return asBool(); }
template <> inline bool Value::is<bool>() const { return isBool(); }
template <> inline Int Value::as<Int>() const { return asInt(); }
template <> inline bool Value::is<Int>() const { return isInt(); }
template <> inline UInt Value::as<UInt>() const { return asUInt(); }
template <> inline bool Value::is<UInt>() const { return isUInt(); }
#if defined(JSON_HAS_INT64)
template <> inline Int64 Value::as<Int64>() const { return asInt64(); }
template <> inline bool Value::is<Int64>() const { return isInt64(); }
template <> inline UInt64 Value::as<UInt64>() const { return asUInt64(); }
template <> inline bool Value::is<UInt64>() const { return isUInt64(); }
#endif
template <> inline double Value::as<double>() const { return asDouble(); }
template <> inline bool Value::is<double>() const { return isDouble(); }
template <> inline String Value::as<String>() const { return asString(); }
template <> inline bool Value::is<String>() const { return isString(); }
template <> inline float Value::as<float>() const { return asFloat(); }
template <> inline const char* Value::as<const char*>() const {
return asCString();
}
class JSON_API PathArgument {
public:
friend class Path;
PathArgument();
PathArgument(ArrayIndex index);
PathArgument(const char* key);
PathArgument(String key);
private:
enum Kind { kindNone = 0, kindIndex, kindKey };
String key_;
ArrayIndex index_{};
Kind kind_{kindNone};
};
class JSON_API Path {
public:
Path(const String& path, const PathArgument& a1 = PathArgument(),
const PathArgument& a2 = PathArgument(),
const PathArgument& a3 = PathArgument(),
const PathArgument& a4 = PathArgument(),
const PathArgument& a5 = PathArgument());
const Value& resolve(const Value& root) const;
Value resolve(const Value& root, const Value& defaultValue) const;
Value& make(Value& root) const;
private:
using InArgs = std::vector<const PathArgument*>;
using Args = std::vector<PathArgument>;
void makePath(const String& path, const InArgs& in);
void addPathInArg(const String& path, const InArgs& in,
InArgs::const_iterator& itInArg, PathArgument::Kind kind);
static void invalidPath(const String& path, int location);
Args args_;
};
class JSON_API ValueIteratorBase {
public:
using iterator_category = std::bidirectional_iterator_tag;
using size_t = unsigned int;
using difference_type = int;
using SelfType = ValueIteratorBase;
bool operator==(const SelfType& other) const { return isEqual(other); }
bool operator!=(const SelfType& other) const { return !isEqual(other); }
difference_type operator-(const SelfType& other) const {
return other.computeDistance(*this);
}
Value key() const;
UInt index() const;
String name() const;
JSONCPP_DEPRECATED("Use `key = name();` instead.")
char const* memberName() const;
char const* memberName(char const** end) const;
protected:
const Value& deref() const;
Value& deref();
void increment();
void decrement();
difference_type computeDistance(const SelfType& other) const;
bool isEqual(const SelfType& other) const;
void copy(const SelfType& other);
private:
Value::ObjectValues::iterator current_;
// Indicates that iterator is for a null value.
bool isNull_{true};
public:
// For some reason, BORLAND needs these at the end, rather
// than earlier. No idea why.
ValueIteratorBase();
explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
};
class JSON_API ValueConstIterator : public ValueIteratorBase {
friend class Value;
public:
using value_type = const Value;
// typedef unsigned int size_t;
// typedef int difference_type;
using reference = const Value&;
using pointer = const Value*;
using SelfType = ValueConstIterator;
ValueConstIterator();
ValueConstIterator(ValueIterator const& other);
private:
explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
public:
SelfType& operator=(const ValueIteratorBase& other);
SelfType operator++(int) {
SelfType temp(*this);
++*this;
return temp;
}
SelfType operator--(int) {
SelfType temp(*this);
--*this;
return temp;
}
SelfType& operator--() {
decrement();
return *this;
}
SelfType& operator++() {
increment();
return *this;
}
reference operator*() const { return deref(); }
pointer operator->() const { return &deref(); }
};
class JSON_API ValueIterator : public ValueIteratorBase {
friend class Value;
public:
using value_type = Value;
using size_t = unsigned int;
using difference_type = int;
using reference = Value&;
using pointer = Value*;
using SelfType = ValueIterator;
ValueIterator();
explicit ValueIterator(const ValueConstIterator& other);
ValueIterator(const ValueIterator& other);
private:
explicit ValueIterator(const Value::ObjectValues::iterator& current);
public:
SelfType& operator=(const SelfType& other);
SelfType operator++(int) {
SelfType temp(*this);
++*this;
return temp;
}
SelfType operator--(int) {
SelfType temp(*this);
--*this;
return temp;
}
SelfType& operator--() {
decrement();
return *this;
}
SelfType& operator++() {
increment();
return *this;
}
reference operator*() const { return const_cast<reference>(deref()); }
pointer operator->() const { return const_cast<pointer>(&deref()); }
};
struct MemberProxy {
const String name;
Value& value;
};
struct ConstMemberProxy {
const String name;
const Value& value;
};
class ValueMembersIterator {
public:
using iterator_category = std::forward_iterator_tag;
using value_type = MemberProxy;
using difference_type = int;
using pointer = MemberProxy*;
using reference = MemberProxy;
ValueMembersIterator() = default;
explicit ValueMembersIterator(ValueIterator const& iter) : it_(iter) {}
ValueMembersIterator& operator++() {
++it_;
return *this;
}
ValueMembersIterator operator++(int) {
ValueMembersIterator temp(*this);
++*this;
return temp;
}
bool operator==(ValueMembersIterator const& other) const {
return it_ == other.it_;
}
bool operator!=(ValueMembersIterator const& other) const {
return it_ != other.it_;
}
MemberProxy operator*() const { return MemberProxy{it_.name(), *it_}; }
private:
ValueIterator it_;
};
class ValueConstMembersIterator {
public:
using iterator_category = std::forward_iterator_tag;
using value_type = ConstMemberProxy;
using difference_type = int;
using pointer = ConstMemberProxy*;
using reference = ConstMemberProxy;
ValueConstMembersIterator() = default;
explicit ValueConstMembersIterator(ValueConstIterator const& iter)
: it_(iter) {}
ValueConstMembersIterator& operator++() {
++it_;
return *this;
}
ValueConstMembersIterator operator++(int) {
ValueConstMembersIterator temp(*this);
++*this;
return temp;
}
bool operator==(ValueConstMembersIterator const& other) const {
return it_ == other.it_;
}
bool operator!=(ValueConstMembersIterator const& other) const {
return it_ != other.it_;
}
ConstMemberProxy operator*() const {
return ConstMemberProxy{it_.name(), *it_};
}
private:
ValueConstIterator it_;
};
class ValueMembersView {
public:
ValueMembersView(ValueIterator begin, ValueIterator end)
: begin_(begin), end_(end) {}
ValueMembersIterator begin() const { return ValueMembersIterator(begin_); }
ValueMembersIterator end() const { return ValueMembersIterator(end_); }
private:
ValueIterator begin_;
ValueIterator end_;
};
class ValueConstMembersView {
public:
ValueConstMembersView(ValueConstIterator begin, ValueConstIterator end)
: begin_(begin), end_(end) {}
ValueConstMembersIterator begin() const {
return ValueConstMembersIterator(begin_);
}
ValueConstMembersIterator end() const {
return ValueConstMembersIterator(end_);
}
private:
ValueConstIterator begin_;
ValueConstIterator end_;
};
inline ValueMembersView Value::members() {
return ValueMembersView(begin(), end());
}
inline ValueConstMembersView Value::members() const {
return ValueConstMembersView(begin(), end());
}
inline void swap(Value& a, Value& b) { a.swap(b); }
inline const Value& Value::front() const { return *begin(); }
inline Value& Value::front() { return *begin(); }
inline const Value& Value::back() const { return *(--end()); }
inline Value& Value::back() { return *(--end()); }
} // namespace Json
#pragma pack(pop)
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma warning(pop)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#endif // JSON_H_INCLUDED
Json::Exception::what
char const * what() const noexcept override
Definition json_value.cpp:233
Json::Exception::~Exception
~Exception() noexcept override
Json::Exception::Exception
Exception(String msg)
Definition json_value.cpp:231
Json::Exception::msg_
String msg_
Definition value.h:88
Json::LogicError::LogicError
LogicError(String const &msg)
Definition json_value.cpp:235
Json::PathArgument
Experimental and untested: represents an element of the "path" to access a node.
Definition value.h:813
Json::PathArgument::PathArgument
PathArgument()
Json::PathArgument::Path
friend class Path
Definition value.h:815
Json::Path::Path
Path(const String &path, const PathArgument &a1=PathArgument(), const PathArgument &a2=PathArgument(), const PathArgument &a3=PathArgument(), const PathArgument &a4=PathArgument(), const PathArgument &a5=PathArgument())
Definition json_value.cpp:1619
Json::Path::make
Value & make(Value &root) const
Creates the "path" to access the specified node and returns a reference on the node.
Definition json_value.cpp:1722
Json::Path::resolve
const Value & resolve(const Value &root) const
Definition json_value.cpp:1679
Json::RuntimeError::RuntimeError
RuntimeError(String const &msg)
Definition json_value.cpp:234
Json::StaticString
Lightweight wrapper to tag static string.
Definition value.h:161
Json::StaticString::c_str
const char * c_str() const
Definition value.h:167
Json::StaticString::StaticString
StaticString(const char *czstring)
Definition value.h:163
Json::ValueConstIterator
const iterator for object and array value.
Definition value.h:943
Json::ValueConstIterator::ValueConstIterator
ValueConstIterator()
Json::ValueConstIterator::operator--
SelfType & operator--()
Definition value.h:977
Json::ValueConstIterator::operator->
pointer operator->() const
Definition value.h:989
Json::ValueConstIterator::reference
const Value & reference
Definition value.h:950
Json::ValueConstIterator::SelfType
ValueConstIterator SelfType
Definition value.h:952
Json::ValueConstIterator::operator--
SelfType operator--(int)
Definition value.h:971
Json::ValueConstIterator::operator++
SelfType & operator++()
Definition value.h:982
Json::ValueConstIterator::operator++
SelfType operator++(int)
Definition value.h:965
Json::ValueConstIterator::value_type
const Value value_type
Definition value.h:947
Json::ValueConstIterator::operator=
SelfType & operator=(const ValueIteratorBase &other)
Definition json_valueiterator.inl:126
Json::ValueConstIterator::operator*
reference operator*() const
Definition value.h:987
Json::ValueConstIterator::pointer
const Value * pointer
Definition value.h:951
Json::ValueConstIterator::Value
friend class Value
Definition value.h:944
Json::ValueConstMembersIterator
Iterator adapter for range-based for loops.
Definition value.h:1099
Json::ValueConstMembersIterator::pointer
ConstMemberProxy * pointer
Definition value.h:1104
Json::ValueConstMembersIterator::operator!=
bool operator!=(ValueConstMembersIterator const &other) const
Definition value.h:1123
Json::ValueConstMembersIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition value.h:1101
Json::ValueConstMembersIterator::ValueConstMembersIterator
ValueConstMembersIterator(ValueConstIterator const &iter)
Definition value.h:1108
Json::ValueConstMembersIterator::reference
ConstMemberProxy reference
Definition value.h:1105
Json::ValueConstMembersIterator::operator==
bool operator==(ValueConstMembersIterator const &other) const
Definition value.h:1120
Json::ValueConstMembersIterator::operator++
ValueConstMembersIterator operator++(int)
Definition value.h:1115
Json::ValueConstMembersIterator::ValueConstMembersIterator
ValueConstMembersIterator()=default
Json::ValueConstMembersIterator::value_type
ConstMemberProxy value_type
Definition value.h:1102
Json::ValueConstMembersIterator::difference_type
int difference_type
Definition value.h:1103
Json::ValueConstMembersIterator::operator++
ValueConstMembersIterator & operator++()
Definition value.h:1111
Json::ValueConstMembersIterator::operator*
ConstMemberProxy operator*() const
Definition value.h:1126
Json::ValueConstMembersView
Range-based for loop adapter for object members.
Definition value.h:1150
Json::ValueConstMembersView::ValueConstMembersView
ValueConstMembersView(ValueConstIterator begin, ValueConstIterator end)
Definition value.h:1152
Json::ValueConstMembersView::begin
ValueConstMembersIterator begin() const
Definition value.h:1154
Json::ValueConstMembersView::end
ValueConstMembersIterator end() const
Definition value.h:1157
Json::Value
Represents a JSON value.
Definition value.h:207
Json::Value::begin
const_iterator begin() const
Definition json_value.cpp:1552
Json::Value::get
Value get(ArrayIndex index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
Definition json_value.cpp:1129
Json::Value::empty
bool empty() const
Return true if empty array, empty object, or null; otherwise, false.
Definition json_value.cpp:932
Json::Value::Value
Value(std::nullptr_t ptr)=delete
Json::Value::maxLargestInt
static constexpr LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
Definition value.h:241
Json::Value::ArrayIndex
Json::ArrayIndex ArrayIndex
Definition value.h:223
Json::Value::asUInt64
UInt64 asUInt64() const
Definition json_value.cpp:771
Json::Value::size
ArrayIndex size() const
Number of values in array or object.
Definition json_value.cpp:909
Json::Value::UInt
Json::UInt UInt
Definition value.h:215
Json::Value::asCString
const char * asCString() const
Embedded zeroes could cause you trouble!
Definition json_value.cpp:635
Json::Value::operator==
bool operator==(const Value &other) const
Definition json_value.cpp:591
Json::Value::maxInt64
static constexpr Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
Definition value.h:256
Json::Value::copy
void copy(const Value &other)
copy everything.
Definition json_value.cpp:518
Json::Value::null
static const Value & null
Definition value.h:230
Json::Value::setComment
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... *‍/.
Definition value.h:668
Json::Value::getString
bool getString(char const **begin, char const **end) const
Get raw char* of string-value.
Definition json_value.cpp:661
Json::Value::as
T as() const =delete
The as<T> and is<T> member function templates and specializations.
Json::Value::maxUInt64AsDouble
static constexpr double maxUInt64AsDouble
Definition value.h:265
Json::Value::Members
std::vector< String > Members
Definition value.h:212
Json::Value::end
const_iterator end() const
Definition json_value.cpp:1565
Json::Value::operator<=
bool operator<=(const Value &other) const
Definition json_value.cpp:585
Json::Value::front
const Value & front() const
Returns a reference to the first element in the Value.
Definition value.h:1175
Json::Value::operator>
bool operator>(const Value &other) const
Definition json_value.cpp:589
Json::Value::isDouble
bool isDouble() const
Definition json_value.cpp:1469
Json::Value::isInt64
bool isInt64() const
Definition json_value.cpp:1399
Json::Value::clear
void clear()
Remove all object members and array elements.
Definition json_value.cpp:940
Json::Value::asString
String asString() const
Embedded zeroes are possible.
Definition json_value.cpp:673
Json::Value::swapPayload
void swapPayload(Value &other)
Swap values but leave comments and source offsets in place.
Definition json_value.cpp:501
Json::Value::placement
CommentPlacement placement
Definition value.h:664
Json::Value::asInt
Int asInt() const
Definition json_value.cpp:699
Json::Value::iterator
ValueIterator iterator
Definition value.h:213
Json::Value::LargestInt
Json::LargestInt LargestInt
Definition value.h:221
Json::Value::LargestUInt
Json::LargestUInt LargestUInt
Definition value.h:222
Json::Value::const_iterator
ValueConstIterator const_iterator
Definition value.h:214
Json::Value::isString
bool isString() const
Definition json_value.cpp:1475
Json::Value::asUInt
UInt asUInt() const
Definition json_value.cpp:721
Json::Value::UInt64
Json::UInt64 UInt64
Definition value.h:218
Json::Value::resize
void resize(ArrayIndex newSize)
Resize the array to newSize elements.
Definition json_value.cpp:956
Json::Value::operator[]
Value & operator[](ArrayIndex index)
Definition json_value.cpp:977
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition json_value.cpp:1221
Json::Value::operator!=
bool operator!=(const Value &other) const
Definition json_value.cpp:633
Json::Value::isUInt64
bool isUInt64() const
Definition json_value.cpp:1423
Json::Value::findValue
Value const * findValue(const String &key) const
Calls find and only returns a valid pointer if the type is found.
Definition value.h:576
Json::Value::type
ValueType type() const
Definition json_value.cpp:523
Json::Value::members
ValueMembersView members()
Definition value.h:1166
Json::Value::back
const Value & back() const
Returns a reference to the last element in the Value.
Definition value.h:1179
Json::Value::asInt64
Int64 asInt64() const
Definition json_value.cpp:745
Json::Value::swap
void swap(Value &other)
Swap everything.
Definition json_value.cpp:511
Json::Value::operator<
bool operator<(const Value &other) const
Compare payload only, not comments etc.
Definition json_value.cpp:535
Json::Value::Int
Json::Int Int
Definition value.h:216
Json::Value::nullRef
static const Value & nullRef
Definition value.h:231
Json::Value::isBool
bool isBool() const
Definition json_value.cpp:1355
Json::Value::copyPayload
void copyPayload(const Value &other)
copy values but leave comments and source offsets in place.
Definition json_value.cpp:506
Json::Value::maxInt
static constexpr Int maxInt
Maximum signed int value that can be stored in a Json::Value.
Definition value.h:248
Json::Value::asBool
bool asBool() const
Definition json_value.cpp:854
Json::Value::isUInt
bool isUInt() const
Definition json_value.cpp:1376
Json::Value::maxLargestUInt
static constexpr LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
Definition value.h:243
Json::Value::isValidIndex
bool isValidIndex(ArrayIndex index) const
Return true if index < size().
Definition json_value.cpp:1134
Json::Value::value_type_
unsigned int value_type_
Definition value.h:752
Json::Value::ValueIteratorBase
friend class ValueIteratorBase
Definition value.h:208
Json::Value::Int64
Json::Int64 Int64
Definition value.h:219
Json::Value::Value
Value(ValueType type=nullValue)
Create a default Value of the given type.
Definition json_value.cpp:392
Json::Value::maxUInt64
static constexpr UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
Definition value.h:258
Json::Value::operator=
Value & operator=(const Value &other)
Definition json_value.cpp:491
Json::Value::minInt
static constexpr Int minInt
Minimum signed int value that can be stored in a Json::Value.
Definition value.h:246
Json::Value::allocated_
unsigned int allocated_
Definition value.h:754
Json::Value::insert
bool insert(ArrayIndex index, const Value &newValue)
Insert value in array at specific index.
Definition json_value.cpp:1233
Json::Value::minInt64
static constexpr Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
Definition value.h:254
Json::Value::value_type
std::string value_type
Definition value.h:226
Json::Value::is
bool is() const =delete
Json::Value::compare
int compare(const Value &other) const
Definition json_value.cpp:527
Json::Value::minLargestInt
static constexpr LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
Definition value.h:238
Json::Value::isConvertibleTo
bool isConvertibleTo(ValueType other) const
Definition json_value.cpp:875
Json::Value::nullSingleton
static Value const & nullSingleton()
Definition json_value.cpp:70
Json::Value::asFloat
float asFloat() const
Definition json_value.cpp:831
Json::Value::find
Value const * find(char const *begin, char const *end) const
Most general and efficient version of isMember()const, get()const, and operator[]const.
Definition json_value.cpp:1136
Json::Value::asDouble
double asDouble() const
Definition json_value.cpp:809
Json::Value::operator>=
bool operator>=(const Value &other) const
Definition json_value.cpp:587
Json::Value::maxUInt
static constexpr UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
Definition value.h:250
Json::Value::isInt
bool isInt() const
Definition json_value.cpp:1357
Json::ValueIteratorBase
base class for Value iterators.
Definition value.h:869
Json::ValueIteratorBase::isEqual
bool isEqual(const SelfType &other) const
Definition json_valueiterator.inl:55
Json::ValueIteratorBase::operator==
bool operator==(const SelfType &other) const
Definition value.h:876
Json::ValueIteratorBase::memberName
char const * memberName(char const **end) const
Return the member name of the referenced Value, or NULL if it is not an objectValue.
Definition json_valueiterator.inl:93
Json::ValueIteratorBase::size_t
unsigned int size_t
Definition value.h:872
Json::ValueIteratorBase::copy
void copy(const SelfType &other)
Definition json_valueiterator.inl:62
Json::ValueIteratorBase::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition value.h:871
Json::ValueIteratorBase::operator-
difference_type operator-(const SelfType &other) const
Definition value.h:880
Json::ValueIteratorBase::operator!=
bool operator!=(const SelfType &other) const
Definition value.h:878
Json::ValueIteratorBase::deref
const Value & deref() const
Definition json_valueiterator.inl:25
Json::ValueIteratorBase::SelfType
ValueIteratorBase SelfType
Definition value.h:874
Json::ValueIteratorBase::computeDistance
difference_type computeDistance(const SelfType &other) const
Definition json_valueiterator.inl:32
Json::ValueIteratorBase::ValueIteratorBase
ValueIteratorBase()
Definition json_valueiterator.inl:18
Json::ValueIteratorBase::increment
void increment()
Definition json_valueiterator.inl:27
Json::ValueIteratorBase::difference_type
int difference_type
Definition value.h:873
Json::ValueIteratorBase::decrement
void decrement()
Definition json_valueiterator.inl:29
Json::ValueIterator
Iterator for object and array value.
Definition value.h:994
Json::ValueIterator::operator--
SelfType operator--(int)
Definition value.h:1023
Json::ValueIterator::ValueIterator
ValueIterator()
Json::ValueIterator::operator--
SelfType & operator--()
Definition value.h:1029
Json::ValueIterator::pointer
Value * pointer
Definition value.h:1002
Json::ValueIterator::operator*
reference operator*() const
Definition value.h:1044
Json::ValueIterator::operator++
SelfType & operator++()
Definition value.h:1034
Json::ValueIterator::SelfType
ValueIterator SelfType
Definition value.h:1003
Json::ValueIterator::size_t
unsigned int size_t
Definition value.h:999
Json::ValueIterator::reference
Value & reference
Definition value.h:1001
Json::ValueIterator::difference_type
int difference_type
Definition value.h:1000
Json::ValueIterator::ValueIterator
ValueIterator(const ValueIterator &other)
Json::ValueIterator::operator->
pointer operator->() const
Definition value.h:1045
Json::ValueIterator::operator=
SelfType & operator=(const SelfType &other)
Definition json_valueiterator.inl:151
Json::ValueIterator::value_type
Value value_type
Definition value.h:998
Json::ValueIterator::operator++
SelfType operator++(int)
Definition value.h:1017
Json::ValueIterator::Value
friend class Value
Definition value.h:995
Json::ValueMembersIterator
Iterator adapter for range-based for loops.
Definition value.h:1065
Json::ValueMembersIterator::reference
MemberProxy reference
Definition value.h:1071
Json::ValueMembersIterator::operator!=
bool operator!=(ValueMembersIterator const &other) const
Definition value.h:1088
Json::ValueMembersIterator::operator++
ValueMembersIterator & operator++()
Definition value.h:1076
Json::ValueMembersIterator::pointer
MemberProxy * pointer
Definition value.h:1070
Json::ValueMembersIterator::value_type
MemberProxy value_type
Definition value.h:1068
Json::ValueMembersIterator::operator++
ValueMembersIterator operator++(int)
Definition value.h:1080
Json::ValueMembersIterator::difference_type
int difference_type
Definition value.h:1069
Json::ValueMembersIterator::ValueMembersIterator
ValueMembersIterator()=default
Json::ValueMembersIterator::operator==
bool operator==(ValueMembersIterator const &other) const
Definition value.h:1085
Json::ValueMembersIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition value.h:1067
Json::ValueMembersIterator::ValueMembersIterator
ValueMembersIterator(ValueIterator const &iter)
Definition value.h:1074
Json::ValueMembersIterator::operator*
MemberProxy operator*() const
Definition value.h:1091
Json::ValueMembersView
Range-based for loop adapter for object members.
Definition value.h:1136
Json::ValueMembersView::begin
ValueMembersIterator begin() const
Definition value.h:1140
Json::ValueMembersView::ValueMembersView
ValueMembersView(ValueIterator begin, ValueIterator end)
Definition value.h:1138
Json::ValueMembersView::end
ValueMembersIterator end() const
Definition value.h:1141
JSON_API
#define JSON_API
If defined, indicates that the source file is amalgamated to prevent private header inclusion.
Definition config.h:50
JSONCPP_DEPRECATED
#define JSONCPP_DEPRECATED(message)
Definition config.h:89
forwards.h
Json
JSON (JavaScript Object Notation).
Definition allocator.h:16
Json::UInt64
unsigned __int64 UInt64
Definition config.h:119
Json::ArrayIndex
unsigned int ArrayIndex
Definition forwards.h:32
Json::Int64
__int64 Int64
Definition config.h:118
Json::LargestInt
Int64 LargestInt
Definition config.h:124
Json::CommentPlacement
CommentPlacement
Definition value.h:132
Json::commentAfterOnSameLine
@ commentAfterOnSameLine
a comment just after a value on the same line
Definition value.h:134
Json::commentBefore
@ commentBefore
a comment placed on the line before a value
Definition value.h:133
Json::numberOfCommentPlacement
@ numberOfCommentPlacement
root value)
Definition value.h:137
Json::commentAfter
@ commentAfter
a comment on the line after a value (only make sense for
Definition value.h:135
Json::UInt
unsigned int UInt
Definition config.h:110
Json::ValueType
ValueType
Type of the value held by a Value object.
Definition value.h:121
Json::booleanValue
@ booleanValue
bool value
Definition value.h:127
Json::nullValue
@ nullValue
'null' value
Definition value.h:122
Json::stringValue
@ stringValue
UTF-8 string value.
Definition value.h:126
Json::realValue
@ realValue
double value
Definition value.h:125
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition value.h:128
Json::intValue
@ intValue
signed integer value
Definition value.h:123
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition value.h:129
Json::uintValue
@ uintValue
unsigned integer value
Definition value.h:124
Json::Int
int Int
Definition config.h:109
Json::String
std::basic_string< char, std::char_traits< char >, Allocator< char > > String
Definition config.h:135
Json::LargestUInt
UInt64 LargestUInt
Definition config.h:125
Json::PrecisionType
PrecisionType
Type of precision for formatting of real values.
Definition value.h:142
Json::decimalPlaces
@ decimalPlaces
we set max number of digits after "." in string
Definition value.h:144
Json::significantDigits
@ significantDigits
we set max number of significant digits in string
Definition value.h:143
Json::swap
void swap(Value &a, Value &b)
Definition value.h:1173
Json::ConstMemberProxy
Proxy struct to enable range-based for loops over const object members.
Definition value.h:1058
Json::ConstMemberProxy::name
const String name
Definition value.h:1059
Json::ConstMemberProxy::value
const Value & value
Definition value.h:1060
Json::MemberProxy
Proxy struct to enable range-based for loops over object members.
Definition value.h:1050
Json::MemberProxy::name
const String name
Definition value.h:1051
Json::MemberProxy::value
Value & value
Definition value.h:1052
JSONCPP_TEMPLATE_DELETE
#define JSONCPP_TEMPLATE_DELETE
Definition value.h:38
JSONCPP_NORETURN
#define JSONCPP_NORETURN
Definition value.h:18