6 #ifndef JSON_VALUE_H_INCLUDED
7 #define JSON_VALUE_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 4275)
54 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
63 #if JSON_USE_EXCEPTION
72 char const* what()
const noexcept
override;
152 operator const char*()
const {
return c_str_; }
154 const char*
c_str()
const {
return c_str_; }
203 #if defined(JSON_HAS_INT64)
206 #endif // defined(JSON_HAS_INT64)
221 static Value const& nullSingleton();
238 #if defined(JSON_HAS_INT64)
245 #endif // defined(JSON_HAS_INT64)
246 static constexpr
UInt defaultRealPrecision = 17;
251 static constexpr
double maxUInt64AsDouble = 18446744073709551615.0;
260 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
263 enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
265 CZString(
char const* str,
unsigned length, DuplicationPolicy allocate);
266 CZString(CZString
const& other);
267 CZString(CZString&& other) noexcept;
269 CZString& operator=(
const CZString& other);
270 CZString& operator=(CZString&& other) noexcept;
272 bool operator<(CZString
const& other)
const;
276 char const* data()
const;
277 unsigned length()
const;
278 bool isStaticString()
const;
281 void swap(CZString& other);
283 struct StringStorage {
284 unsigned policy_ : 2;
285 unsigned length_ : 30;
291 StringStorage storage_;
296 typedef std::map<CZString, Value> ObjectValues;
297 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
319 #if defined(JSON_HAS_INT64)
322 #endif // if defined(JSON_HAS_INT64)
324 Value(
const char* value);
325 Value(
const char* begin,
const char* end);
346 Value(std::nullptr_t ptr) =
delete;
359 void swapPayload(
Value& other);
362 void copy(const
Value& other);
364 void copyPayload(const
Value& other);
369 bool operator<(const
Value& other) const;
370 bool operator<=(const
Value& other) const;
371 bool operator>=(const
Value& other) const;
372 bool operator>(const
Value& other) const;
373 bool operator==(const
Value& other) const;
374 bool operator!=(const
Value& other) const;
375 int compare(const
Value& other) const;
377 const
char* asCString() const;
378 #if JSONCPP_USING_SECURE_MEMORY
379 unsigned getCStringLength()
const;
386 bool getString(
char const** begin,
char const** end)
const;
389 #if defined(JSON_HAS_INT64)
390 Int64 asInt64()
const;
392 #endif // if defined(JSON_HAS_INT64)
395 float asFloat()
const;
396 double asDouble()
const;
402 bool isInt64()
const;
404 bool isUInt64()
const;
405 bool isIntegral()
const;
406 bool isDouble()
const;
407 bool isNumeric()
const;
408 bool isString()
const;
409 bool isArray()
const;
410 bool isObject()
const;
416 bool isConvertibleTo(
ValueType other) const;
426 explicit operator
bool() const;
447 Value& operator[](
int index);
455 const
Value& operator[](
int index) const;
476 Value& operator[](const
char* key);
479 const
Value& operator[](const
char* key) const;
502 Value get(const
char* key, const
Value& defaultValue) const;
506 Value get(const
char* begin, const
char* end,
507 const
Value& defaultValue) const;
515 Value const* find(
char const* begin,
char const* end) const;
522 Value* demand(
char const* begin,
char const* end);
528 void removeMember(const
char* key);
531 void removeMember(const
String& key);
534 bool removeMember(const
char* key,
Value* removed);
541 bool removeMember(
String const& key,
Value* removed);
543 bool removeMember(const
char* begin, const
char* end,
Value* removed);
554 bool isMember(const
char* key) const;
557 bool isMember(const
String& key) const;
559 bool isMember(const
char* begin, const
char* end) const;
566 Members getMemberNames() const;
571 setComment(
String(comment, strlen(comment)), placement);
575 setComment(
String(comment, len), placement);
583 String toStyledString()
const;
585 const_iterator begin()
const;
586 const_iterator end()
const;
594 const Value& front()
const;
604 const Value& back()
const;
613 void setOffsetStart(ptrdiff_t start);
614 void setOffsetLimit(ptrdiff_t limit);
615 ptrdiff_t getOffsetStart()
const;
616 ptrdiff_t getOffsetLimit()
const;
620 bits_.value_type_ =
static_cast<unsigned char>(v);
622 bool isAllocated()
const {
return bits_.allocated_; }
623 void setIsAllocated(
bool v) { bits_.allocated_ = v; }
625 void initBasic(
ValueType type,
bool allocated =
false);
626 void dupPayload(
const Value& other);
627 void releasePayload();
628 void dupMeta(
const Value& other);
630 Value& resolveReference(
const char* key);
631 Value& resolveReference(
const char* key,
const char* end);
653 unsigned int value_type_ : 8;
655 unsigned int allocated_ : 1;
660 Comments() =
default;
661 Comments(
const Comments& that);
662 Comments(Comments&& that) noexcept;
663 Comments& operator=(
const Comments& that);
664 Comments& operator=(Comments&& that) noexcept;
670 using Array = std::array<String, numberOfCommentPlacement>;
671 std::unique_ptr<Array> ptr_;
681 template <>
inline bool Value::as<bool>()
const {
return asBool(); }
682 template <>
inline bool Value::is<bool>()
const {
return isBool(); }
684 template <>
inline Int Value::as<Int>()
const {
return asInt(); }
685 template <>
inline bool Value::is<Int>()
const {
return isInt(); }
687 template <>
inline UInt Value::as<UInt>()
const {
return asUInt(); }
688 template <>
inline bool Value::is<UInt>()
const {
return isUInt(); }
690 #if defined(JSON_HAS_INT64)
691 template <>
inline Int64 Value::as<Int64>()
const {
return asInt64(); }
692 template <>
inline bool Value::is<Int64>()
const {
return isInt64(); }
694 template <>
inline UInt64 Value::as<UInt64>()
const {
return asUInt64(); }
695 template <>
inline bool Value::is<UInt64>()
const {
return isUInt64(); }
698 template <>
inline double Value::as<double>()
const {
return asDouble(); }
699 template <>
inline bool Value::is<double>()
const {
return isDouble(); }
701 template <>
inline String Value::as<String>()
const {
return asString(); }
702 template <>
inline bool Value::is<String>()
const {
return isString(); }
706 template <>
inline float Value::as<float>()
const {
return asFloat(); }
707 template <>
inline const char* Value::as<const char*>()
const {
724 enum Kind { kindNone = 0, kindIndex, kindKey };
727 Kind kind_{kindNone};
749 const Value& resolve(
const Value& root)
const;
756 using InArgs = std::vector<const PathArgument*>;
757 using Args = std::vector<PathArgument>;
759 void makePath(
const String& path,
const InArgs& in);
760 void addPathInArg(
const String& path,
const InArgs& in,
761 InArgs::const_iterator& itInArg, PathArgument::Kind kind);
762 static void invalidPath(
const String& path,
int location);
773 using size_t =
unsigned int;
803 char const* memberName() const;
807 char const* memberName(
char const** end) const;
816 const
Value& deref() const;
823 difference_type computeDistance(const SelfType& other) const;
825 bool isEqual(const SelfType& other) const;
827 void copy(const SelfType& other);
830 Value::ObjectValues::iterator current_;
838 explicit ValueIteratorBase(
const Value::ObjectValues::iterator& current);
900 using size_t =
unsigned int;
913 explicit ValueIterator(
const Value::ObjectValues::iterator& current);
963 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
965 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
967 #endif // JSON_H_INCLUDED
#define JSONCPP_DEPRECATED(message)
pointer operator->() const
const Value & front() const
Returns a reference to the first element in the Value.
#define JSON_API
If defined, indicates that the source file is amalgamated to prevent private header inclusion...
reference operator*() const
PrecisionType
Type of precision for formatting of real values.
base class for Value iterators.
array value (ordered list)
#define JSONCPP_TEMPLATE_DELETE
Json::LargestUInt LargestUInt
Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... */.
object value (collection of name/value pairs).
std::bidirectional_iterator_tag iterator_category
Lightweight wrapper to tag static string.
std::basic_string< char, std::char_traits< char >, Allocator< char >> String
difference_type computeDistance(const SelfType &other) const
bool operator!=(const SelfType &other) const
const iterator for object and array value.
Experimental and untested: represents an element of the "path" to access a node.
StaticString(const char *czstring)
std::vector< String > Members
void swap(Value &a, Value &b)
JSON (JavaScript Object Notation).
bool operator==(const SecureAllocator< T > &, const SecureAllocator< U > &)
we set max number of digits after "." in string
void swap(Value &other)
Swap everything.
Experimental and untested: represents a "path" to access a node.
const char * c_str() const
Json::LargestInt LargestInt
static const Value & nullRef
difference_type operator-(const SelfType &other) const
reference operator*() const
Exceptions which the user cannot easily avoid.
a comment on the line after a value (only make sense for
we set max number of significant digits in string
Iterator for object and array value.
ValueType
Type of the value held by a Value object.
Json::ArrayIndex ArrayIndex
static const Value & null
a comment placed on the line before a value
a comment just after a value on the same line
const_iterator begin() const
Base class for all exceptions we throw.
bool operator==(const SelfType &other) const
pointer operator->() const
const Value & back() const
Returns a reference to the last element in the Value.
const_iterator end() const