6#ifndef NIM_CPP_WRAPPER_UTIL_JSON_H_INCLUDED
7#define NIM_CPP_WRAPPER_UTIL_JSON_H_INCLUDED
9#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)
72 char const* what()
const noexcept override;
102JSONCPP_NORETURN
void throwRuntimeError(String
const& msg);
104JSONCPP_NORETURN
void throwLogicError(String
const& msg);
120enum CommentPlacement {
122 commentAfterOnSameLine,
125 numberOfCommentPlacement
131 significantDigits = 0,
152 : c_str_(czstring) {}
154 operator const char*()
const {
return c_str_; }
156 const char* c_str()
const {
return c_str_; }
200 using Members = std::vector<String>;
203 using UInt = nim_cpp_wrapper_util::Json::UInt;
204 using Int = nim_cpp_wrapper_util::Json::Int;
205#if defined(JSON_HAS_INT64)
206 using UInt64 = nim_cpp_wrapper_util::Json::UInt64;
207 using Int64 = nim_cpp_wrapper_util::Json::Int64;
209 using LargestInt = nim_cpp_wrapper_util::Json::LargestInt;
210 using LargestUInt = nim_cpp_wrapper_util::Json::LargestUInt;
211 using ArrayIndex = nim_cpp_wrapper_util::Json::ArrayIndex;
214 using value_type = std::string;
218 static const Value& null;
219 static const Value& nullRef;
223 static Value const& nullSingleton();
226 static constexpr LargestInt minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
228 static constexpr LargestInt maxLargestInt = LargestInt(LargestUInt(-1) / 2);
230 static constexpr LargestUInt maxLargestUInt = LargestUInt(-1);
233 static constexpr Int minInt = Int(~(UInt(-1) / 2));
235 static constexpr Int maxInt = Int(UInt(-1) / 2);
237 static constexpr UInt maxUInt = UInt(-1);
239#if defined(JSON_HAS_INT64)
241 static constexpr Int64 minInt64 = Int64(~(UInt64(-1) / 2));
243 static constexpr Int64 maxInt64 = Int64(UInt64(-1) / 2);
245 static constexpr UInt64 maxUInt64 = UInt64(-1);
248 static constexpr UInt defaultRealPrecision = 17;
252 static constexpr double maxUInt64AsDouble = 18446744073709551615.0;
261#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
264 enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
265 CZString(ArrayIndex index);
266 CZString(
char const* str,
unsigned length, DuplicationPolicy allocate);
267 CZString(CZString
const& other);
268 CZString(CZString&& other);
270 CZString& operator=(
const CZString& other);
271 CZString& operator=(CZString&& other);
273 bool operator<(CZString
const& other)
const;
275 ArrayIndex index()
const;
277 char const* data()
const;
278 unsigned length()
const;
279 bool isStaticString()
const;
282 void swap(CZString& other);
284 struct StringStorage {
285 unsigned policy_ : 2;
286 unsigned length_ : 30;
292 StringStorage storage_;
297 typedef std::map<CZString, Value> ObjectValues;
317 Value(ValueType type = nullValue);
320#if defined(JSON_HAS_INT64)
325 Value(
const char* value);
326 Value(
const char* begin,
const char* end);
345 Value(
const String& value);
347 Value(std::nullptr_t ptr) =
delete;
358 void swap(
Value& other);
360 void swapPayload(
Value& other);
363 void copy(
const Value& other);
365 void copyPayload(
const Value& other);
367 ValueType type()
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;
375 bool operator!=(
const Value& other)
const;
376 int compare(
const Value& other)
const;
378 const char* asCString()
const;
379#if JSONCPP_USING_SECURE_MEMORY
380 unsigned getCStringLength()
const;
383 String asString()
const;
387 bool getString(
char const** begin,
char const** end)
const;
390#if defined(JSON_HAS_INT64)
391 Int64 asInt64()
const;
392 UInt64 asUInt64()
const;
394 LargestInt asLargestInt()
const;
395 LargestUInt asLargestUInt()
const;
396 float asFloat()
const;
397 double asDouble()
const;
403 bool isInt64()
const;
405 bool isUInt64()
const;
406 bool isIntegral()
const;
407 bool isDouble()
const;
408 bool isNumeric()
const;
409 bool isString()
const;
410 bool isArray()
const;
411 bool isObject()
const;
414 template <
typename T>
415 T
as() const JSONCPP_TEMPLATE_DELETE;
416 template <typename T>
417 bool is() const JSONCPP_TEMPLATE_DELETE;
419 bool isConvertibleTo(ValueType other) const;
422 ArrayIndex size() const;
429 explicit operator
bool() const;
441 void resize(ArrayIndex newSize);
449 Value& operator[](ArrayIndex index);
450 Value& operator[](
int index);
457 const
Value& operator[](ArrayIndex index) const;
458 const
Value& operator[](
int index) const;
463 Value get(ArrayIndex index, const
Value& defaultValue) const;
465 bool isValidIndex(ArrayIndex index) const;
473 bool insert(ArrayIndex index, const
Value& newValue);
474 bool insert(ArrayIndex index,
Value&& newValue);
479 Value& operator[](const
char* key);
482 const
Value& operator[](const
char* key) const;
485 Value& operator[](const String& key);
489 const
Value& operator[](const String& key) const;
505 Value get(const
char* key, const
Value& defaultValue) const;
509 Value get(const
char* begin, const
char* end, const
Value& defaultValue) const;
513 Value get(const String& key, const
Value& defaultValue) const;
517 Value const* find(
char const* begin,
char const* end) const;
521 Value* demand(
char const* begin,
char const* end);
527 void removeMember(const
char* key);
530 void removeMember(const String& key);
533 bool removeMember(const
char* key,
Value* removed);
540 bool removeMember(String const& key,
Value* removed);
542 bool removeMember(const
char* begin, const
char* end,
Value* removed);
549 bool removeIndex(ArrayIndex index,
Value* removed);
553 bool isMember(const
char* key) const;
556 bool isMember(const String& key) const;
558 bool isMember(const
char* begin, const
char* end) const;
565 Members getMemberNames() const;
568 void setComment(const
char* comment, CommentPlacement placement) {
569 setComment(String(comment, strlen(comment)), placement);
572 void setComment(
const char* comment,
size_t len, CommentPlacement placement) {
573 setComment(String(comment, len), placement);
576 void setComment(String comment, CommentPlacement placement);
577 bool hasComment(CommentPlacement placement)
const;
579 String getComment(CommentPlacement placement)
const;
581 String toStyledString()
const;
583 const_iterator begin()
const;
584 const_iterator end()
const;
591 void setOffsetStart(ptrdiff_t start);
592 void setOffsetLimit(ptrdiff_t limit);
593 ptrdiff_t getOffsetStart()
const;
594 ptrdiff_t getOffsetLimit()
const;
597 void setType(ValueType v) {
598 bits_.value_type_ =
static_cast<unsigned char>(v);
600 bool isAllocated()
const {
601 return bits_.allocated_;
603 void setIsAllocated(
bool v) {
604 bits_.allocated_ = v;
607 void initBasic(ValueType type,
bool allocated =
false);
608 void dupPayload(
const Value& other);
609 void releasePayload();
610 void dupMeta(
const Value& other);
612 Value& resolveReference(
const char* key);
613 Value& resolveReference(
const char* key,
const char* end);
635 unsigned int value_type_ : 8;
637 unsigned int allocated_ : 1;
642 Comments() =
default;
643 Comments(
const Comments& that);
644 Comments(Comments&& that);
645 Comments& operator=(
const Comments& that);
646 Comments& operator=(Comments&& that);
647 bool has(CommentPlacement slot)
const;
648 String get(CommentPlacement slot)
const;
649 void set(CommentPlacement slot, String comment);
652 using Array = std::array<String, numberOfCommentPlacement>;
653 std::unique_ptr<Array> ptr_;
664inline bool Value::as<bool>()
const {
668inline bool Value::is<bool>()
const {
673inline Int Value::as<Int>()
const {
677inline bool Value::is<Int>()
const {
682inline UInt Value::as<UInt>()
const {
686inline bool Value::is<UInt>()
const {
690#if defined(JSON_HAS_INT64)
692inline Int64 Value::as<Int64>()
const {
696inline bool Value::is<Int64>()
const {
701inline UInt64 Value::as<UInt64>()
const {
705inline bool Value::is<UInt64>()
const {
711inline double Value::as<double>()
const {
715inline bool Value::is<double>()
const {
720inline String Value::as<String>()
const {
724inline bool Value::is<String>()
const {
731inline float Value::as<float>()
const {
735inline const char* Value::as<const char*>()
const {
752 enum Kind { kindNone = 0, kindIndex, kindKey };
755 Kind kind_{kindNone};
771 Path(
const String& path,
778 const Value& resolve(
const Value& root)
const;
785 using InArgs = std::vector<const PathArgument*>;
786 using Args = std::vector<PathArgument>;
788 void makePath(
const String& path,
const InArgs& in);
789 void addPathInArg(
const String& path,
const InArgs& in, InArgs::const_iterator& itInArg, PathArgument::Kind kind);
790 static void invalidPath(
const String& path,
int location);
800 using iterator_category = std::bidirectional_iterator_tag;
801 using size_t =
unsigned int;
802 using difference_type = int;
807 bool operator!=(
const SelfType& other)
const {
return !isEqual(other); }
809 difference_type operator-(
const SelfType& other)
const {
return other.computeDistance(*
this); }
828 char const* memberName()
const;
832 char const* memberName(
char const** end)
const;
841 const Value& deref()
const;
848 difference_type computeDistance(
const SelfType& other)
const;
850 bool isEqual(
const SelfType& other)
const;
855 Value::ObjectValues::iterator current_;
913 reference operator*()
const {
return deref(); }
915 pointer operator->()
const {
return &deref(); }
925 using size_t =
unsigned int;
926 using difference_type = int;
938 explicit ValueIterator(
const Value::ObjectValues::iterator& current);
971 pointer operator->() {
return &deref(); }
974inline void swap(Value& a, Value& b) {
983#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Experimental and untested: represents an element of the "path" to access a node.
Definition: value.h:742
Experimental and untested: represents a "path" to access a node.
Definition: value.h:769
Lightweight wrapper to tag static string.
Definition: value.h:149
const iterator for object and array value.
Definition: value.h:869
Represents a JSON value.
Definition: value.h:196
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... */.
Definition: value.h:572
const char * asCString() const
Embedded zeroes could cause you trouble!
Definition: json_value.cpp:599
T as() const JSONCPP_TEMPLATE_DELETE
The as<T> and is<T> member function templates and specializations.
String asString() const
Embedded zeroes are possible.
Definition: json_value.cpp:632
base class for Value iterators.
Definition: value.h:798
Iterator for object and array value.
Definition: value.h:920
reference operator*()
Definition: value.h:970
bool operator==(const NIMChatRoomExitReasonInfo &info, NIMChatRoomExitReason code)
Definition: nim_chatroom_helper.cpp:13
JSON (JavaScript Object Notation).
Definition: allocator.h:14