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 inline Value(std::string_view value)
361 : Value(value.data(), value.data() + value.length()) {}
362#endif
363 Value(bool value);
364 Value(std::nullptr_t ptr) = delete;
365 Value(const Value& other);
366 Value(Value&& other) noexcept;
367 ~Value();
368
371 Value& operator=(const Value& other);
372 Value& operator=(Value&& other) noexcept;
373
375 void swap(Value& other);
377 void swapPayload(Value& other);
378
380 void copy(const Value& other);
382 void copyPayload(const Value& other);
383
384 ValueType type() const;
385
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 bool operator!=(const Value& other) const;
393 int compare(const Value& other) const;
394
395 const char* asCString() const;
396#if JSONCPP_USE_SECURE_MEMORY
397 unsigned getCStringLength() const; // Allows you to understand the length of
398 // the CString
399#endif
400 String asString() const;
404 bool getString(char const** begin, char const** end) const;
405#ifdef JSONCPP_HAS_STRING_VIEW
409 inline bool getString(std::string_view* str) const {
410 char const* begin;
411 char const* end;
412 if (!getString(&begin, &end))
413 return false;
414 *str = std::string_view(begin, static_cast<size_t>(end - begin));
415 return true;
416 }
417#endif
418 Int asInt() const;
419 UInt asUInt() const;
420#if defined(JSON_HAS_INT64)
421 Int64 asInt64() const;
422 UInt64 asUInt64() const;
423#endif // if defined(JSON_HAS_INT64)
424 LargestInt asLargestInt() const;
425 LargestUInt asLargestUInt() const;
426 float asFloat() const;
427 double asDouble() const;
428 bool asBool() const;
429
430 bool isNull() const;
431 bool isBool() const;
432 bool isInt() const;
433 bool isInt64() const;
434 bool isUInt() const;
435 bool isUInt64() const;
436 bool isIntegral() const;
437 bool isDouble() const;
438 bool isNumeric() const;
439 bool isString() const;
440 bool isArray() const;
441 bool isObject() const;
442
444 template <typename T> T as() const JSONCPP_TEMPLATE_DELETE;
445 template <typename T> bool is() const JSONCPP_TEMPLATE_DELETE;
446
447 bool isConvertibleTo(ValueType other) const;
448
450 ArrayIndex size() const;
451
454 bool empty() const;
455
457 explicit operator bool() const;
458
462 void clear();
463
469 void resize(ArrayIndex newSize);
470
477 Value& operator[](ArrayIndex index);
478 Value& operator[](int index);
480
485 const Value& operator[](ArrayIndex index) const;
486 const Value& operator[](int index) const;
488
491 Value get(ArrayIndex index, const Value& defaultValue) const;
493 bool isValidIndex(ArrayIndex index) const;
497 Value& append(const Value& value);
498 Value& append(Value&& value);
499
501 bool insert(ArrayIndex index, const Value& newValue);
502 bool insert(ArrayIndex index, Value&& newValue);
503
504#ifdef JSONCPP_HAS_STRING_VIEW
507 inline Value& operator[](std::string_view key) {
508 return resolveReference(key.data(), key.data() + key.length());
509 }
513 inline const Value& operator[](std::string_view key) const {
514 Value const* found = find(key.data(), key.data() + key.length());
515 if (!found)
516 return nullSingleton();
517 return *found;
518 }
519#endif
523 Value& operator[](const char* key);
526 const Value& operator[](const char* key) const;
529 Value& operator[](const String& key);
533 const Value& operator[](const String& key) const;
546 Value& operator[](const StaticString& key);
547#ifdef JSONCPP_HAS_STRING_VIEW
550 inline Value get(std::string_view key, const Value& defaultValue) const {
551 return get(key.data(), key.data() + key.length(), defaultValue);
552 }
553#endif
556 Value get(const char* key, const Value& defaultValue) const;
560 Value get(const String& key, const Value& defaultValue) const;
564 Value get(const char* begin, const char* end,
565 const Value& defaultValue) const;
569 Value const* find(char const* begin, char const* end) const;
572 Value const* find(const String& key) const;
573
575 template <typename T, bool (T::*TMemFn)() const>
576 Value const* findValue(const String& key) const {
577 Value const* found = find(key);
578 if (!found || !(found->*TMemFn)())
579 return nullptr;
580 return found;
581 }
582
583 Value const* findNull(const String& key) const;
584 Value const* findBool(const String& key) const;
585 Value const* findInt(const String& key) const;
586 Value const* findInt64(const String& key) const;
587 Value const* findUInt(const String& key) const;
588 Value const* findUInt64(const String& key) const;
589 Value const* findIntegral(const String& key) const;
590 Value const* findDouble(const String& key) const;
591 Value const* findNumeric(const String& key) const;
592 Value const* findString(const String& key) const;
593 Value const* findArray(const String& key) const;
594 Value const* findObject(const String& key) const;
595
599 Value* demand(char const* begin, char const* end);
605#if JSONCPP_HAS_STRING_VIEW
606 inline void removeMember(std::string_view key) {
607 removeMember(key.data(), key.data() + key.length(), nullptr);
608 }
609#endif
610 void removeMember(const char* key);
613 void removeMember(const String& key);
620#if JSONCPP_HAS_STRING_VIEW
621 inline bool removeMember(std::string_view key, Value* removed) {
622 return removeMember(key.data(), key.data() + key.length(), removed);
623 }
624#endif
625 bool removeMember(String const& key, Value* removed);
628 bool removeMember(const char* key, Value* removed);
630 bool removeMember(const char* begin, const char* end, Value* removed);
637 bool removeIndex(ArrayIndex index, Value* removed);
638
639#ifdef JSONCPP_HAS_STRING_VIEW
642 inline bool isMember(std::string_view key) const {
643 return isMember(key.data(), key.data() + key.length());
644 }
645#endif
648 bool isMember(const char* key) const;
651 bool isMember(const String& key) const;
653 bool isMember(const char* begin, const char* end) const;
654
660 Members getMemberNames() const;
661
663 JSONCPP_DEPRECATED("Use setComment(String const&) instead.")
664 void setComment(const char* comment, CommentPlacement placement) {
665 setComment(String(comment, strlen(comment)), placement);
666 }
668 void setComment(const char* comment, size_t len, CommentPlacement placement) {
669 setComment(String(comment, len), placement);
670 }
671
672 void setComment(String comment, CommentPlacement placement);
673 bool hasComment(CommentPlacement placement) const;
675 String getComment(CommentPlacement placement) const;
676
677 String toStyledString() const;
678
679 const_iterator begin() const;
680 const_iterator end() const;
681
682 iterator begin();
683 iterator end();
684
688 const Value& front() const;
689
693 Value& front();
694
698 const Value& back() const;
699
703 Value& back();
704
705 // Accessors for the [start, limit) range of bytes within the JSON text from
706 // which this value was parsed, if any.
707 void setOffsetStart(ptrdiff_t start);
708 void setOffsetLimit(ptrdiff_t limit);
709 ptrdiff_t getOffsetStart() const;
710 ptrdiff_t getOffsetLimit() const;
711
712private:
713 void setType(ValueType v) {
714 bits_.value_type_ = static_cast<unsigned char>(v);
715 }
716 bool isAllocated() const { return bits_.allocated_; }
717 void setIsAllocated(bool v) { bits_.allocated_ = v; }
718
719 void initBasic(ValueType type, bool allocated = false);
720 void dupPayload(const Value& other);
721 void releasePayload();
722 void dupMeta(const Value& other);
723
724 Value& resolveReference(const char* key);
725 Value& resolveReference(const char* key, const char* end);
726
727 // struct MemberNamesTransform
728 //{
729 // typedef const char *result_type;
730 // const char *operator()( const CZString &name ) const
731 // {
732 // return name.c_str();
733 // }
734 //};
735
736 union ValueHolder {
737 LargestInt int_;
738 LargestUInt uint_;
739 double real_;
740 bool bool_;
741 char* string_; // if allocated_, ptr to { unsigned, char[] }.
742 ObjectValues* map_;
743 } value_;
744
745 struct {
746 // Really a ValueType, but types should agree for bitfield packing.
747 unsigned int value_type_ : 8;
748 // Unless allocated_, string_ must be null-terminated.
749 unsigned int allocated_ : 1;
750 } bits_;
751
752 class Comments {
753 public:
754 Comments() = default;
755 Comments(const Comments& that);
756 Comments(Comments&& that) noexcept;
757 Comments& operator=(const Comments& that);
758 Comments& operator=(Comments&& that) noexcept;
759 bool has(CommentPlacement slot) const;
760 String get(CommentPlacement slot) const;
761 void set(CommentPlacement slot, String comment);
762
763 private:
764 using Array = std::array<String, numberOfCommentPlacement>;
765 std::unique_ptr<Array> ptr_;
766 };
767 Comments comments_;
768
769 // [start, limit) byte offsets in the source JSON text from which this Value
770 // was extracted.
771 ptrdiff_t start_;
772 ptrdiff_t limit_;
773};
774
775template <> inline bool Value::as<bool>() const { return asBool(); }
776template <> inline bool Value::is<bool>() const { return isBool(); }
777
778template <> inline Int Value::as<Int>() const { return asInt(); }
779template <> inline bool Value::is<Int>() const { return isInt(); }
780
781template <> inline UInt Value::as<UInt>() const { return asUInt(); }
782template <> inline bool Value::is<UInt>() const { return isUInt(); }
783
784#if defined(JSON_HAS_INT64)
785template <> inline Int64 Value::as<Int64>() const { return asInt64(); }
786template <> inline bool Value::is<Int64>() const { return isInt64(); }
787
788template <> inline UInt64 Value::as<UInt64>() const { return asUInt64(); }
789template <> inline bool Value::is<UInt64>() const { return isUInt64(); }
790#endif
791
792template <> inline double Value::as<double>() const { return asDouble(); }
793template <> inline bool Value::is<double>() const { return isDouble(); }
794
795template <> inline String Value::as<String>() const { return asString(); }
796template <> inline bool Value::is<String>() const { return isString(); }
797
800template <> inline float Value::as<float>() const { return asFloat(); }
801template <> inline const char* Value::as<const char*>() const {
802 return asCString();
803}
804
809public:
810 friend class Path;
811
814 PathArgument(const char* key);
815 PathArgument(String key);
816
817private:
818 enum Kind { kindNone = 0, kindIndex, kindKey };
819 String key_;
820 ArrayIndex index_{};
821 Kind kind_{kindNone};
822};
823
836public:
837 Path(const String& path, const PathArgument& a1 = PathArgument(),
838 const PathArgument& a2 = PathArgument(),
839 const PathArgument& a3 = PathArgument(),
840 const PathArgument& a4 = PathArgument(),
841 const PathArgument& a5 = PathArgument());
842
843 const Value& resolve(const Value& root) const;
844 Value resolve(const Value& root, const Value& defaultValue) const;
847 Value& make(Value& root) const;
848
849private:
850 using InArgs = std::vector<const PathArgument*>;
851 using Args = std::vector<PathArgument>;
852
853 void makePath(const String& path, const InArgs& in);
854 void addPathInArg(const String& path, const InArgs& in,
855 InArgs::const_iterator& itInArg, PathArgument::Kind kind);
856 static void invalidPath(const String& path, int location);
857
858 Args args_;
859};
860
865public:
866 using iterator_category = std::bidirectional_iterator_tag;
867 using size_t = unsigned int;
868 using difference_type = int;
870
871 bool operator==(const SelfType& other) const { return isEqual(other); }
872
873 bool operator!=(const SelfType& other) const { return !isEqual(other); }
874
875 difference_type operator-(const SelfType& other) const {
876 return other.computeDistance(*this);
877 }
878
881 Value key() const;
882
885 UInt index() const;
886
890 String name() const;
891
896 JSONCPP_DEPRECATED("Use `key = name();` instead.")
897 char const* memberName() const;
901 char const* memberName(char const** end) const;
902
903protected:
910 const Value& deref() const;
911 Value& deref();
912
913 void increment();
914
915 void decrement();
916
917 difference_type computeDistance(const SelfType& other) const;
918
919 bool isEqual(const SelfType& other) const;
920
921 void copy(const SelfType& other);
922
923private:
924 Value::ObjectValues::iterator current_;
925 // Indicates that iterator is for a null value.
926 bool isNull_{true};
927
928public:
929 // For some reason, BORLAND needs these at the end, rather
930 // than earlier. No idea why.
932 explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
933};
934
939 friend class Value;
940
941public:
942 using value_type = const Value;
943 // typedef unsigned int size_t;
944 // typedef int difference_type;
945 using reference = const Value&;
946 using pointer = const Value*;
948
950 ValueConstIterator(ValueIterator const& other);
951
952private:
955 explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
956
957public:
958 SelfType& operator=(const ValueIteratorBase& other);
959
961 SelfType temp(*this);
962 ++*this;
963 return temp;
964 }
965
967 SelfType temp(*this);
968 --*this;
969 return temp;
970 }
971
973 decrement();
974 return *this;
975 }
976
978 increment();
979 return *this;
980 }
981
982 reference operator*() const { return deref(); }
983
984 pointer operator->() const { return &deref(); }
985};
986
990 friend class Value;
991
992public:
994 using size_t = unsigned int;
995 using difference_type = int;
996 using reference = Value&;
997 using pointer = Value*;
999
1001 explicit ValueIterator(const ValueConstIterator& other);
1003
1004private:
1007 explicit ValueIterator(const Value::ObjectValues::iterator& current);
1008
1009public:
1010 SelfType& operator=(const SelfType& other);
1011
1013 SelfType temp(*this);
1014 ++*this;
1015 return temp;
1016 }
1017
1019 SelfType temp(*this);
1020 --*this;
1021 return temp;
1022 }
1023
1025 decrement();
1026 return *this;
1027 }
1028
1030 increment();
1031 return *this;
1032 }
1033
1039 reference operator*() const { return const_cast<reference>(deref()); }
1040 pointer operator->() const { return const_cast<pointer>(&deref()); }
1041};
1042
1043inline void swap(Value& a, Value& b) { a.swap(b); }
1044
1045inline const Value& Value::front() const { return *begin(); }
1046
1047inline Value& Value::front() { return *begin(); }
1048
1049inline const Value& Value::back() const { return *(--end()); }
1050
1051inline Value& Value::back() { return *(--end()); }
1052
1053} // namespace Json
1054
1055#pragma pack(pop)
1056
1057#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1058#pragma warning(pop)
1059#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1060
1061#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:808
friend class Path
Definition value.h:810
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:938
SelfType & operator--()
Definition value.h:972
pointer operator->() const
Definition value.h:984
const Value & reference
Definition value.h:945
ValueConstIterator SelfType
Definition value.h:947
SelfType operator--(int)
Definition value.h:966
SelfType & operator++()
Definition value.h:977
SelfType operator++(int)
Definition value.h:960
const Value value_type
Definition value.h:942
SelfType & operator=(const ValueIteratorBase &other)
reference operator*() const
Definition value.h:982
const Value * pointer
Definition value.h:946
friend class Value
Definition value.h:939
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
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:668
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:1045
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:664
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:576
ValueType type() const
const Value & back() const
Returns a reference to the last element in the Value.
Definition value.h:1049
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
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 asBool() const
bool isUInt() 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:747
friend class ValueIteratorBase
Definition value.h:208
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:749
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
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:864
bool isEqual(const SelfType &other) const
bool operator==(const SelfType &other) const
Definition value.h:871
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:867
void copy(const SelfType &other)
std::bidirectional_iterator_tag iterator_category
Definition value.h:866
difference_type operator-(const SelfType &other) const
Definition value.h:875
bool operator!=(const SelfType &other) const
Definition value.h:873
const Value & deref() const
ValueIteratorBase SelfType
Definition value.h:869
difference_type computeDistance(const SelfType &other) const
Iterator for object and array value.
Definition value.h:989
SelfType operator--(int)
Definition value.h:1018
SelfType & operator--()
Definition value.h:1024
Value * pointer
Definition value.h:997
reference operator*() const
Definition value.h:1039
SelfType & operator++()
Definition value.h:1029
ValueIterator SelfType
Definition value.h:998
unsigned int size_t
Definition value.h:994
Value & reference
Definition value.h:996
ValueIterator(const ValueIterator &other)
pointer operator->() const
Definition value.h:1040
SelfType & operator=(const SelfType &other)
SelfType operator++(int)
Definition value.h:1012
friend class Value
Definition value.h:990
#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:1043
#define JSONCPP_TEMPLATE_DELETE
Definition value.h:38
#define JSONCPP_NORETURN
Definition value.h:18