JsonCpp project page Classes Namespace JsonCpp home page

value.h
Go to the documentation of this file.
1// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
2// Distributed under MIT license, or public domain if desired and
3// recognized in your jurisdiction.
4// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5
6#ifndef JSON_VALUE_H_INCLUDED
7#define JSON_VALUE_H_INCLUDED
8
9#if !defined(JSON_IS_AMALGAMATION)
10#include "forwards.h"
11#endif // if !defined(JSON_IS_AMALGAMATION)
12
13// Conditional NORETURN attribute on the throw functions would:
14// a) suppress false positives from static code analysis
15// b) possibly improve optimization opportunities.
16#if !defined(JSONCPP_NORETURN)
17#if defined(_MSC_VER) && _MSC_VER == 1800
18#define JSONCPP_NORETURN __declspec(noreturn)
19#else
20#define JSONCPP_NORETURN [[noreturn]]
21#endif
22#endif
23
24// Support for '= delete' with template declarations was a late addition
25// to the c++11 standard and is rejected by clang 3.8 and Apple clang 8.2
26// even though these declare themselves to be c++11 compilers.
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
31#endif
32#elif defined(__clang__)
33#if __clang_major__ == 3 && __clang_minor__ <= 8
34#define JSONCPP_TEMPLATE_DELETE
35#endif
36#endif
37#if !defined(JSONCPP_TEMPLATE_DELETE)
38#define JSONCPP_TEMPLATE_DELETE = delete
39#endif
40#endif
41
42#ifndef JSONCPP_HAS_STRING_VIEW
43#if __cplusplus >= 201703L
44#define JSONCPP_HAS_STRING_VIEW 1
45#endif
46#endif
47
48#include <array>
49#include <exception>
50#include <map>
51#include <memory>
52#include <string>
53#include <vector>
54
55// Forward declaration for testing.
56struct ValueTest;
57
58#ifdef JSONCPP_HAS_STRING_VIEW
59#include <string_view>
60#endif
61
62// Disable warning C4251: <data member>: <type> needs to have dll-interface to
63// be used by...
64#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
65#pragma warning(push)
66#pragma warning(disable : 4251 4275)
67#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
68
69#pragma pack(push)
70#pragma pack()
71
74namespace Json {
75
76#if JSON_USE_EXCEPTION
81class JSON_API Exception : public std::exception {
82public:
83 Exception(String msg);
84 ~Exception() noexcept override;
85 char const* what() const noexcept override;
86
87protected:
89};
90
98public:
99 RuntimeError(String const& msg);
100};
101
109public:
110 LogicError(String const& msg);
111};
112#endif
113
115JSONCPP_NORETURN void throwRuntimeError(String const& msg);
117JSONCPP_NORETURN void throwLogicError(String const& msg);
118
131
139
146
162public:
163 explicit StaticString(const char* czstring) : c_str_(czstring) {}
164
165 operator const char*() const { return c_str_; }
166
167 const char* c_str() const { return c_str_; }
168
169private:
170 const char* c_str_;
171};
172
208 friend class ValueIteratorBase;
209 friend struct ::ValueTest;
210
211public:
212 using Members = std::vector<String>;
216 using Int = Json::Int;
217#if defined(JSON_HAS_INT64)
220#endif // defined(JSON_HAS_INT64)
224
225 // Required for boost integration, e. g. BOOST_TEST
226 using value_type = std::string;
227
228#if JSON_USE_NULLREF
229 // Binary compatibility kludges, do not use.
230 static const Value& null;
231 static const Value& nullRef;
232#endif
233
234 // null and nullRef are deprecated, use this instead.
235 static Value const& nullSingleton();
236
238 static constexpr LargestInt minLargestInt =
239 LargestInt(~(LargestUInt(-1) / 2));
241 static constexpr LargestInt maxLargestInt = LargestInt(LargestUInt(-1) / 2);
243 static constexpr LargestUInt maxLargestUInt = LargestUInt(-1);
244
246 static constexpr Int minInt = Int(~(UInt(-1) / 2));
248 static constexpr Int maxInt = Int(UInt(-1) / 2);
250 static constexpr UInt maxUInt = UInt(-1);
251
252#if defined(JSON_HAS_INT64)
254 static constexpr Int64 minInt64 = Int64(~(UInt64(-1) / 2));
256 static constexpr Int64 maxInt64 = Int64(UInt64(-1) / 2);
258 static constexpr UInt64 maxUInt64 = UInt64(-1);
259#endif // defined(JSON_HAS_INT64)
261 static constexpr UInt defaultRealPrecision = 17;
262 // The constant is hard-coded because some compiler have trouble
263 // converting Value::maxUInt64 to a double correctly (AIX/xlC).
264 // Assumes that UInt64 is a 64 bits integer.
265 static constexpr double maxUInt64AsDouble = 18446744073709551615.0;
266// Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler
267// when using gcc and clang backend compilers. CZString
268// cannot be defined as private. See issue #486
269#ifdef __NVCC__
270public:
271#else
272private:
273#endif
274#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
275 class JSON_API CZString {
276 public:
277 enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
278 CZString(ArrayIndex index);
279 CZString(char const* str, unsigned length, DuplicationPolicy allocate);
280 CZString(CZString const& other);
281 CZString(CZString&& other) noexcept;
282 ~CZString();
283 CZString& operator=(const CZString& other);
284 CZString& operator=(CZString&& other) noexcept;
285
286 bool operator<(CZString const& other) const;
287 bool operator==(CZString const& other) const;
288 ArrayIndex index() const;
289 // const char* c_str() const; ///< \deprecated
290 char const* data() const;
291 unsigned length() const;
292 bool isStaticString() const;
293
294 private:
295 void swap(CZString& other);
296
297 struct StringStorage {
298 unsigned policy_ : 2;
299 unsigned length_ : 30; // 1GB max
300 };
301
302 char const* cstr_; // actually, a prefixed string, unless policy is noDup
303 union {
304 ArrayIndex index_;
305 StringStorage storage_;
306 };
307 };
308
309public:
310 typedef std::map<CZString, Value> ObjectValues;
311#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
312
313public:
330 Value(ValueType type = nullValue);
331 Value(Int value);
332 Value(UInt value);
333#if defined(JSON_HAS_INT64)
334 Value(Int64 value);
335 Value(UInt64 value);
336#endif // if defined(JSON_HAS_INT64)
337 Value(double value);
338 Value(const char* value);
339 Value(const char* begin, const char* end);
357 Value(const StaticString& value);
358 Value(const String& value);
359#ifdef JSONCPP_HAS_STRING_VIEW
360 Value(std::string_view value);
361#endif
362 Value(bool value);
363 Value(std::nullptr_t ptr) = delete;
364 Value(const Value& other);
365 Value(Value&& other) noexcept;
366 ~Value();
367
370 Value& operator=(const Value& other);
371 Value& operator=(Value&& other) noexcept;
372
374 void swap(Value& other);
376 void swapPayload(Value& other);
377
379 void copy(const Value& other);
381 void copyPayload(const Value& other);
382
383 ValueType type() const;
384
386 bool operator<(const Value& other) const;
387 bool operator<=(const Value& other) const;
388 bool operator>=(const Value& other) const;
389 bool operator>(const Value& other) const;
390 bool operator==(const Value& other) const;
391 bool operator!=(const Value& other) const;
392 int compare(const Value& other) const;
393
394 const char* asCString() const;
395#if JSONCPP_USE_SECURE_MEMORY
396 unsigned getCStringLength() const; // Allows you to understand the length of
397 // the CString
398#endif
399 String asString() const;
403 bool getString(char const** begin, char const** end) const;
404#ifdef JSONCPP_HAS_STRING_VIEW
408 bool getString(std::string_view* str) const;
409#endif
410 Int asInt() const;
411 UInt asUInt() const;
412#if defined(JSON_HAS_INT64)
413 Int64 asInt64() const;
414 UInt64 asUInt64() const;
415#endif // if defined(JSON_HAS_INT64)
416 LargestInt asLargestInt() const;
418 float asFloat() const;
419 double asDouble() const;
420 bool asBool() const;
421
422 bool isNull() const;
423 bool isBool() const;
424 bool isInt() const;
425 bool isInt64() const;
426 bool isUInt() const;
427 bool isUInt64() const;
428 bool isIntegral() const;
429 bool isDouble() const;
430 bool isNumeric() const;
431 bool isString() const;
432 bool isArray() const;
433 bool isObject() const;
434
436 template <typename T> T as() const JSONCPP_TEMPLATE_DELETE;
437 template <typename T> bool is() const JSONCPP_TEMPLATE_DELETE;
438
439 bool isConvertibleTo(ValueType other) const;
440
442 ArrayIndex size() const;
443
446 bool empty() const;
447
449 explicit operator bool() const;
450
454 void clear();
455
461 void resize(ArrayIndex newSize);
462
469 Value& operator[](ArrayIndex index);
470 Value& operator[](int index);
472
477 const Value& operator[](ArrayIndex index) const;
478 const Value& operator[](int index) const;
480
483 Value get(ArrayIndex index, const Value& defaultValue) const;
485 bool isValidIndex(ArrayIndex index) const;
489 Value& append(const Value& value);
490 Value& append(Value&& value);
491
493 bool insert(ArrayIndex index, const Value& newValue);
494 bool insert(ArrayIndex index, Value&& newValue);
495
496#ifdef JSONCPP_HAS_STRING_VIEW
499 Value& operator[](std::string_view key);
503 const Value& operator[](std::string_view key) const;
504#else
508 Value& operator[](const char* key);
511 const Value& operator[](const char* key) const;
514 Value& operator[](const String& key);
518 const Value& operator[](const String& key) const;
519#endif
532 Value& operator[](const StaticString& key);
533#ifdef JSONCPP_HAS_STRING_VIEW
536 Value get(std::string_view key, const Value& defaultValue) const;
537#else
540 Value get(const char* key, const Value& defaultValue) const;
544 Value get(const String& key, const Value& defaultValue) const;
545#endif
549 Value get(const char* begin, const char* end,
550 const Value& defaultValue) const;
554 Value const* find(char const* begin, char const* end) const;
557 Value const* find(const String& key) const;
558
560 template <typename T, bool (T::*TMemFn)() const>
561 Value const* findValue(const String& key) const {
562 Value const* found = find(key);
563 if (!found || !(found->*TMemFn)())
564 return nullptr;
565 return found;
566 }
567
568 Value const* findNull(const String& key) const;
569 Value const* findBool(const String& key) const;
570 Value const* findInt(const String& key) const;
571 Value const* findInt64(const String& key) const;
572 Value const* findUInt(const String& key) const;
573 Value const* findUInt64(const String& key) const;
574 Value const* findIntegral(const String& key) const;
575 Value const* findDouble(const String& key) const;
576 Value const* findNumeric(const String& key) const;
577 Value const* findString(const String& key) const;
578 Value const* findArray(const String& key) const;
579 Value const* findObject(const String& key) const;
580
584 Value* demand(char const* begin, char const* end);
590#if JSONCPP_HAS_STRING_VIEW
591 void removeMember(std::string_view key);
592#else
593 void removeMember(const char* key);
596 void removeMember(const String& key);
597#endif
604#if JSONCPP_HAS_STRING_VIEW
605 bool removeMember(std::string_view key, Value* removed);
606#else
607 bool removeMember(String const& key, Value* removed);
610 bool removeMember(const char* key, Value* removed);
611#endif
613 bool removeMember(const char* begin, const char* end, Value* removed);
620 bool removeIndex(ArrayIndex index, Value* removed);
621
622#ifdef JSONCPP_HAS_STRING_VIEW
625 bool isMember(std::string_view key) const;
626#else
629 bool isMember(const char* key) const;
632 bool isMember(const String& key) const;
633#endif
635 bool isMember(const char* begin, const char* end) const;
636
642 Members getMemberNames() const;
643
645 JSONCPP_DEPRECATED("Use setComment(String const&) instead.")
646 void setComment(const char* comment, CommentPlacement placement) {
647 setComment(String(comment, strlen(comment)), placement);
648 }
650 void setComment(const char* comment, size_t len, CommentPlacement placement) {
651 setComment(String(comment, len), placement);
652 }
653
654 void setComment(String comment, CommentPlacement placement);
655 bool hasComment(CommentPlacement placement) const;
657 String getComment(CommentPlacement placement) const;
658
659 String toStyledString() const;
660
661 const_iterator begin() const;
662 const_iterator end() const;
663
664 iterator begin();
665 iterator end();
666
670 const Value& front() const;
671
675 Value& front();
676
680 const Value& back() const;
681
685 Value& back();
686
687 // Accessors for the [start, limit) range of bytes within the JSON text from
688 // which this value was parsed, if any.
689 void setOffsetStart(ptrdiff_t start);
690 void setOffsetLimit(ptrdiff_t limit);
691 ptrdiff_t getOffsetStart() const;
692 ptrdiff_t getOffsetLimit() const;
693
694private:
695 void setType(ValueType v) {
696 bits_.value_type_ = static_cast<unsigned char>(v);
697 }
698 bool isAllocated() const { return bits_.allocated_; }
699 void setIsAllocated(bool v) { bits_.allocated_ = v; }
700
701 void initBasic(ValueType type, bool allocated = false);
702 void dupPayload(const Value& other);
703 void releasePayload();
704 void dupMeta(const Value& other);
705
706 Value& resolveReference(const char* key);
707 Value& resolveReference(const char* key, const char* end);
708
709 // struct MemberNamesTransform
710 //{
711 // typedef const char *result_type;
712 // const char *operator()( const CZString &name ) const
713 // {
714 // return name.c_str();
715 // }
716 //};
717
718 union ValueHolder {
719 LargestInt int_;
720 LargestUInt uint_;
721 double real_;
722 bool bool_;
723 char* string_; // if allocated_, ptr to { unsigned, char[] }.
724 ObjectValues* map_;
725 } value_;
726
727 struct {
728 // Really a ValueType, but types should agree for bitfield packing.
729 unsigned int value_type_ : 8;
730 // Unless allocated_, string_ must be null-terminated.
731 unsigned int allocated_ : 1;
732 } bits_;
733
734 class Comments {
735 public:
736 Comments() = default;
737 Comments(const Comments& that);
738 Comments(Comments&& that) noexcept;
739 Comments& operator=(const Comments& that);
740 Comments& operator=(Comments&& that) noexcept;
741 bool has(CommentPlacement slot) const;
742 String get(CommentPlacement slot) const;
743 void set(CommentPlacement slot, String comment);
744
745 private:
746 using Array = std::array<String, numberOfCommentPlacement>;
747 std::unique_ptr<Array> ptr_;
748 };
749 Comments comments_;
750
751 // [start, limit) byte offsets in the source JSON text from which this Value
752 // was extracted.
753 ptrdiff_t start_;
754 ptrdiff_t limit_;
755};
756
757template <> inline bool Value::as<bool>() const { return asBool(); }
758template <> inline bool Value::is<bool>() const { return isBool(); }
759
760template <> inline Int Value::as<Int>() const { return asInt(); }
761template <> inline bool Value::is<Int>() const { return isInt(); }
762
763template <> inline UInt Value::as<UInt>() const { return asUInt(); }
764template <> inline bool Value::is<UInt>() const { return isUInt(); }
765
766#if defined(JSON_HAS_INT64)
767template <> inline Int64 Value::as<Int64>() const { return asInt64(); }
768template <> inline bool Value::is<Int64>() const { return isInt64(); }
769
770template <> inline UInt64 Value::as<UInt64>() const { return asUInt64(); }
771template <> inline bool Value::is<UInt64>() const { return isUInt64(); }
772#endif
773
774template <> inline double Value::as<double>() const { return asDouble(); }
775template <> inline bool Value::is<double>() const { return isDouble(); }
776
777template <> inline String Value::as<String>() const { return asString(); }
778template <> inline bool Value::is<String>() const { return isString(); }
779
782template <> inline float Value::as<float>() const { return asFloat(); }
783template <> inline const char* Value::as<const char*>() const {
784 return asCString();
785}
786
791public:
792 friend class Path;
793
796 PathArgument(const char* key);
797 PathArgument(String key);
798
799private:
800 enum Kind { kindNone = 0, kindIndex, kindKey };
801 String key_;
802 ArrayIndex index_{};
803 Kind kind_{kindNone};
804};
805
818public:
819 Path(const String& path, const PathArgument& a1 = PathArgument(),
820 const PathArgument& a2 = PathArgument(),
821 const PathArgument& a3 = PathArgument(),
822 const PathArgument& a4 = PathArgument(),
823 const PathArgument& a5 = PathArgument());
824
825 const Value& resolve(const Value& root) const;
826 Value resolve(const Value& root, const Value& defaultValue) const;
829 Value& make(Value& root) const;
830
831private:
832 using InArgs = std::vector<const PathArgument*>;
833 using Args = std::vector<PathArgument>;
834
835 void makePath(const String& path, const InArgs& in);
836 void addPathInArg(const String& path, const InArgs& in,
837 InArgs::const_iterator& itInArg, PathArgument::Kind kind);
838 static void invalidPath(const String& path, int location);
839
840 Args args_;
841};
842
847public:
848 using iterator_category = std::bidirectional_iterator_tag;
849 using size_t = unsigned int;
850 using difference_type = int;
852
853 bool operator==(const SelfType& other) const { return isEqual(other); }
854
855 bool operator!=(const SelfType& other) const { return !isEqual(other); }
856
857 difference_type operator-(const SelfType& other) const {
858 return other.computeDistance(*this);
859 }
860
863 Value key() const;
864
867 UInt index() const;
868
872 String name() const;
873
878 JSONCPP_DEPRECATED("Use `key = name();` instead.")
879 char const* memberName() const;
883 char const* memberName(char const** end) const;
884
885protected:
892 const Value& deref() const;
893 Value& deref();
894
895 void increment();
896
897 void decrement();
898
899 difference_type computeDistance(const SelfType& other) const;
900
901 bool isEqual(const SelfType& other) const;
902
903 void copy(const SelfType& other);
904
905private:
906 Value::ObjectValues::iterator current_;
907 // Indicates that iterator is for a null value.
908 bool isNull_{true};
909
910public:
911 // For some reason, BORLAND needs these at the end, rather
912 // than earlier. No idea why.
914 explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
915};
916
921 friend class Value;
922
923public:
924 using value_type = const Value;
925 // typedef unsigned int size_t;
926 // typedef int difference_type;
927 using reference = const Value&;
928 using pointer = const Value*;
930
932 ValueConstIterator(ValueIterator const& other);
933
934private:
937 explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
938
939public:
940 SelfType& operator=(const ValueIteratorBase& other);
941
943 SelfType temp(*this);
944 ++*this;
945 return temp;
946 }
947
949 SelfType temp(*this);
950 --*this;
951 return temp;
952 }
953
955 decrement();
956 return *this;
957 }
958
960 increment();
961 return *this;
962 }
963
964 reference operator*() const { return deref(); }
965
966 pointer operator->() const { return &deref(); }
967};
968
972 friend class Value;
973
974public:
976 using size_t = unsigned int;
977 using difference_type = int;
978 using reference = Value&;
979 using pointer = Value*;
981
983 explicit ValueIterator(const ValueConstIterator& other);
985
986private:
989 explicit ValueIterator(const Value::ObjectValues::iterator& current);
990
991public:
992 SelfType& operator=(const SelfType& other);
993
995 SelfType temp(*this);
996 ++*this;
997 return temp;
998 }
999
1001 SelfType temp(*this);
1002 --*this;
1003 return temp;
1004 }
1005
1007 decrement();
1008 return *this;
1009 }
1010
1012 increment();
1013 return *this;
1014 }
1015
1021 reference operator*() const { return const_cast<reference>(deref()); }
1022 pointer operator->() const { return const_cast<pointer>(&deref()); }
1023};
1024
1025inline void swap(Value& a, Value& b) { a.swap(b); }
1026
1027inline const Value& Value::front() const { return *begin(); }
1028
1029inline Value& Value::front() { return *begin(); }
1030
1031inline const Value& Value::back() const { return *(--end()); }
1032
1033inline Value& Value::back() { return *(--end()); }
1034
1035} // namespace Json
1036
1037#pragma pack(pop)
1038
1039#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1040#pragma warning(pop)
1041#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1042
1043#endif // JSON_H_INCLUDED
char const * what() const noexcept override
~Exception() noexcept override
Exception(String msg)
String msg_
Definition value.h:88
LogicError(String const &msg)
Experimental and untested: represents an element of the "path" to access a node.
Definition value.h:790
friend class Path
Definition value.h:792
Path(const String &path, const PathArgument &a1=PathArgument(), const PathArgument &a2=PathArgument(), const PathArgument &a3=PathArgument(), const PathArgument &a4=PathArgument(), const PathArgument &a5=PathArgument())
Value & make(Value &root) const
Creates the "path" to access the specified node and returns a reference on the node.
const Value & resolve(const Value &root) const
RuntimeError(String const &msg)
Lightweight wrapper to tag static string.
Definition value.h:161
const char * c_str() const
Definition value.h:167
StaticString(const char *czstring)
Definition value.h:163
const iterator for object and array value.
Definition value.h:920
SelfType & operator--()
Definition value.h:954
pointer operator->() const
Definition value.h:966
const Value & reference
Definition value.h:927
ValueConstIterator SelfType
Definition value.h:929
SelfType operator--(int)
Definition value.h:948
SelfType & operator++()
Definition value.h:959
SelfType operator++(int)
Definition value.h:942
const Value value_type
Definition value.h:924
SelfType & operator=(const ValueIteratorBase &other)
reference operator*() const
Definition value.h:964
const Value * pointer
Definition value.h:928
friend class Value
Definition value.h:921
Represents a JSON value.
Definition value.h:207
const_iterator begin() const
Value get(ArrayIndex index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
bool empty() const
Return true if empty array, empty object, or null; otherwise, false.
Value(std::nullptr_t ptr)=delete
static constexpr LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
Definition value.h:241
Json::ArrayIndex ArrayIndex
Definition value.h:223
UInt64 asUInt64() const
ArrayIndex size() const
Number of values in array or object.
Json::UInt UInt
Definition value.h:215
bool isArray() const
const char * asCString() const
Embedded zeroes could cause you trouble!
bool operator==(const Value &other) const
static constexpr Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
Definition value.h:256
void copy(const Value &other)
copy everything.
static const Value & null
Definition value.h:230
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... *‍/.
Definition value.h:650
bool getString(char const **begin, char const **end) const
Get raw char* of string-value.
T as() const =delete
The as<T> and is<T> member function templates and specializations.
static constexpr double maxUInt64AsDouble
Definition value.h:265
std::vector< String > Members
Definition value.h:212
const_iterator end() const
bool operator<=(const Value &other) const
const Value & front() const
Returns a reference to the first element in the Value.
Definition value.h:1027
bool operator>(const Value &other) const
bool isDouble() const
bool isInt64() const
void clear()
Remove all object members and array elements.
String asString() const
Embedded zeroes are possible.
void swapPayload(Value &other)
Swap values but leave comments and source offsets in place.
CommentPlacement placement
Definition value.h:646
Int asInt() const
ValueIterator iterator
Definition value.h:213
Json::LargestInt LargestInt
Definition value.h:221
Json::LargestUInt LargestUInt
Definition value.h:222
ValueConstIterator const_iterator
Definition value.h:214
bool isString() const
UInt asUInt() const
Json::UInt64 UInt64
Definition value.h:218
void resize(ArrayIndex newSize)
Resize the array to newSize elements.
Value & operator[](ArrayIndex index)
Value & append(const Value &value)
Append value to array at the end.
bool operator!=(const Value &other) const
bool isUInt64() const
Value const * findValue(const String &key) const
Calls find and only returns a valid pointer if the type is found.
Definition value.h:561
ValueType type() const
bool isObject() const
const Value & back() const
Returns a reference to the last element in the Value.
Definition value.h:1031
Int64 asInt64() const
void swap(Value &other)
Swap everything.
bool operator<(const Value &other) const
Compare payload only, not comments etc.
Json::Int Int
Definition value.h:216
static const Value & nullRef
Definition value.h:231
LargestInt asLargestInt() const
bool isBool() const
void copyPayload(const Value &other)
copy values but leave comments and source offsets in place.
static constexpr Int maxInt
Maximum signed int value that can be stored in a Json::Value.
Definition value.h:248
bool isIntegral() const
bool asBool() const
bool isUInt() const
bool isNull() const
static constexpr LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
Definition value.h:243
bool isValidIndex(ArrayIndex index) const
Return true if index < size().
unsigned int value_type_
Definition value.h:729
friend class ValueIteratorBase
Definition value.h:208
LargestUInt asLargestUInt() const
Json::Int64 Int64
Definition value.h:219
Value(ValueType type=nullValue)
Create a default Value of the given type.
static constexpr UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
Definition value.h:258
Value & operator=(const Value &other)
static constexpr Int minInt
Minimum signed int value that can be stored in a Json::Value.
Definition value.h:246
unsigned int allocated_
Definition value.h:731
bool insert(ArrayIndex index, const Value &newValue)
Insert value in array at specific index.
static constexpr Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
Definition value.h:254
std::string value_type
Definition value.h:226
bool is() const =delete
int compare(const Value &other) const
static constexpr LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
Definition value.h:238
bool isConvertibleTo(ValueType other) const
static Value const & nullSingleton()
float asFloat() const
bool isNumeric() const
Value const * find(char const *begin, char const *end) const
Most general and efficient version of isMember()const, get()const, and operator[]const.
double asDouble() const
bool operator>=(const Value &other) const
static constexpr UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
Definition value.h:250
bool isInt() const
base class for Value iterators.
Definition value.h:846
bool isEqual(const SelfType &other) const
bool operator==(const SelfType &other) const
Definition value.h:853
char const * memberName(char const **end) const
Return the member name of the referenced Value, or NULL if it is not an objectValue.
unsigned int size_t
Definition value.h:849
void copy(const SelfType &other)
std::bidirectional_iterator_tag iterator_category
Definition value.h:848
difference_type operator-(const SelfType &other) const
Definition value.h:857
bool operator!=(const SelfType &other) const
Definition value.h:855
const Value & deref() const
ValueIteratorBase SelfType
Definition value.h:851
difference_type computeDistance(const SelfType &other) const
Iterator for object and array value.
Definition value.h:971
SelfType operator--(int)
Definition value.h:1000
SelfType & operator--()
Definition value.h:1006
Value * pointer
Definition value.h:979
reference operator*() const
Definition value.h:1021
SelfType & operator++()
Definition value.h:1011
ValueIterator SelfType
Definition value.h:980
unsigned int size_t
Definition value.h:976
Value & reference
Definition value.h:978
ValueIterator(const ValueIterator &other)
pointer operator->() const
Definition value.h:1022
SelfType & operator=(const SelfType &other)
SelfType operator++(int)
Definition value.h:994
friend class Value
Definition value.h:972
#define JSON_API
If defined, indicates that the source file is amalgamated to prevent private header inclusion.
Definition config.h:50
#define JSONCPP_DEPRECATED(message)
Definition config.h:89
JSON (JavaScript Object Notation).
Definition allocator.h:16
unsigned __int64 UInt64
Definition config.h:118
unsigned int ArrayIndex
Definition forwards.h:32
__int64 Int64
Definition config.h:117
Int64 LargestInt
Definition config.h:123
CommentPlacement
Definition value.h:132
@ commentAfterOnSameLine
a comment just after a value on the same line
Definition value.h:134
@ commentBefore
a comment placed on the line before a value
Definition value.h:133
@ numberOfCommentPlacement
root value)
Definition value.h:137
@ commentAfter
a comment on the line after a value (only make sense for
Definition value.h:135
unsigned int UInt
Definition config.h:109
ValueType
Type of the value held by a Value object.
Definition value.h:121
@ booleanValue
bool value
Definition value.h:127
@ nullValue
'null' value
Definition value.h:122
@ stringValue
UTF-8 string value.
Definition value.h:126
@ realValue
double value
Definition value.h:125
@ arrayValue
array value (ordered list)
Definition value.h:128
@ intValue
signed integer value
Definition value.h:123
@ objectValue
object value (collection of name/value pairs).
Definition value.h:129
@ uintValue
unsigned integer value
Definition value.h:124
int Int
Definition config.h:108
std::basic_string< char, std::char_traits< char >, Allocator< char > > String
Definition config.h:132
UInt64 LargestUInt
Definition config.h:124
PrecisionType
Type of precision for formatting of real values.
Definition value.h:142
@ decimalPlaces
we set max number of digits after "." in string
Definition value.h:144
@ significantDigits
we set max number of significant digits in string
Definition value.h:143
void swap(Value &a, Value &b)
Definition value.h:1025
#define JSONCPP_TEMPLATE_DELETE
Definition value.h:38
#define JSONCPP_NORETURN
Definition value.h:18