6 #ifndef JSON_H_INCLUDED 7 #define JSON_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;
150 explicit StaticString(
const char* czstring) : c_str_(czstring) {}
152 operator const char*()
const {
return c_str_; }
154 const char* c_str()
const {
return c_str_; }
198 using Members = std::vector<String>;
201 using UInt = Json::UInt;
202 using Int = Json::Int;
203 #if defined(JSON_HAS_INT64) 204 using UInt64 = Json::UInt64;
205 using Int64 = Json::Int64;
206 #endif // defined(JSON_HAS_INT64) 207 using LargestInt = Json::LargestInt;
208 using LargestUInt = Json::LargestUInt;
209 using ArrayIndex = Json::ArrayIndex;
212 using value_type = std::string;
216 static const Value& null;
217 static const Value& nullRef;
221 static Value const& nullSingleton();
224 static constexpr LargestInt minLargestInt =
225 LargestInt(~(LargestUInt(-1) / 2));
227 static constexpr LargestInt maxLargestInt = LargestInt(LargestUInt(-1) / 2);
229 static constexpr LargestUInt maxLargestUInt = LargestUInt(-1);
232 static constexpr Int minInt = Int(~(UInt(-1) / 2));
234 static constexpr Int maxInt = Int(UInt(-1) / 2);
236 static constexpr UInt maxUInt = UInt(-1);
238 #if defined(JSON_HAS_INT64) 240 static constexpr Int64 minInt64 = Int64(~(UInt64(-1) / 2));
242 static constexpr Int64 maxInt64 = Int64(UInt64(-1) / 2);
244 static constexpr UInt64 maxUInt64 = UInt64(-1);
245 #endif // defined(JSON_HAS_INT64) 247 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 };
264 CZString(ArrayIndex index);
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;
273 bool operator==(CZString
const& other)
const;
274 ArrayIndex index()
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);
344 Value(
const String& value);
346 Value(std::nullptr_t ptr) =
delete;
357 void swap(
Value& other);
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;
382 String asString()
const;
386 bool getString(
char const** begin,
char const** end)
const;
389 #if defined(JSON_HAS_INT64) 390 Int64 asInt64()
const;
391 UInt64 asUInt64()
const;
392 #endif // if defined(JSON_HAS_INT64) 393 LargestInt asLargestInt()
const;
394 LargestUInt asLargestUInt()
const;
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;
413 template <
typename T> T as()
const JSONCPP_TEMPLATE_DELETE;
414 template <
typename T>
bool is()
const JSONCPP_TEMPLATE_DELETE;
416 bool isConvertibleTo(
ValueType other)
const;
419 ArrayIndex size()
const;
426 explicit operator bool()
const;
438 void resize(ArrayIndex newSize);
446 Value& operator[](ArrayIndex index);
447 Value& operator[](
int index);
454 const Value& operator[](ArrayIndex index)
const;
455 const Value& operator[](
int index)
const;
460 Value get(ArrayIndex index,
const Value& defaultValue)
const;
462 bool isValidIndex(ArrayIndex index)
const;
470 bool insert(ArrayIndex index,
const Value& newValue);
471 bool insert(ArrayIndex index,
Value&& newValue);
476 Value& operator[](
const char* key);
479 const Value& operator[](
const char* key)
const;
482 Value& operator[](
const String& key);
486 const Value& operator[](
const String& 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;
511 Value get(
const String& key,
const Value& defaultValue)
const;
515 Value const* find(
char const* begin,
char const* end)
const;
519 Value* demand(
char const* begin,
char const* end);
525 void removeMember(
const char* key);
528 void removeMember(
const String& key);
531 bool removeMember(
const char* key,
Value* removed);
538 bool removeMember(String
const& key,
Value* removed);
540 bool removeMember(
const char* begin,
const char* end,
Value* removed);
547 bool removeIndex(ArrayIndex index,
Value* removed);
551 bool isMember(
const char* key)
const;
554 bool isMember(
const String& key)
const;
556 bool isMember(
const char* begin,
const char* end)
const;
563 Members getMemberNames()
const;
566 JSONCPP_DEPRECATED(
"Use setComment(String const&) instead.")
568 setComment(String(comment, strlen(comment)), placement);
572 setComment(String(comment, len), placement);
580 String toStyledString()
const;
590 void setOffsetStart(ptrdiff_t start);
591 void setOffsetLimit(ptrdiff_t limit);
592 ptrdiff_t getOffsetStart()
const;
593 ptrdiff_t getOffsetLimit()
const;
597 bits_.value_type_ =
static_cast<unsigned char>(v);
599 bool isAllocated()
const {
return bits_.allocated_; }
600 void setIsAllocated(
bool v) { bits_.allocated_ = v; }
602 void initBasic(
ValueType type,
bool allocated =
false);
603 void dupPayload(
const Value& other);
604 void releasePayload();
605 void dupMeta(
const Value& other);
607 Value& resolveReference(
const char* key);
608 Value& resolveReference(
const char* key,
const char* end);
630 unsigned int value_type_ : 8;
632 unsigned int allocated_ : 1;
637 Comments() =
default;
638 Comments(
const Comments& that);
639 Comments(Comments&& that) noexcept;
640 Comments& operator=(
const Comments& that);
641 Comments& operator=(Comments&& that) noexcept;
647 using Array = std::array<String, numberOfCommentPlacement>;
648 std::unique_ptr<Array> ptr_;
658 template <>
inline bool Value::as<bool>()
const {
return asBool(); }
659 template <>
inline bool Value::is<bool>()
const {
return isBool(); }
661 template <>
inline Int Value::as<Int>()
const {
return asInt(); }
662 template <>
inline bool Value::is<Int>()
const {
return isInt(); }
664 template <>
inline UInt Value::as<UInt>()
const {
return asUInt(); }
665 template <>
inline bool Value::is<UInt>()
const {
return isUInt(); }
667 #if defined(JSON_HAS_INT64) 668 template <>
inline Int64 Value::as<Int64>()
const {
return asInt64(); }
669 template <>
inline bool Value::is<Int64>()
const {
return isInt64(); }
671 template <>
inline UInt64 Value::as<UInt64>()
const {
return asUInt64(); }
672 template <>
inline bool Value::is<UInt64>()
const {
return isUInt64(); }
675 template <>
inline double Value::as<double>()
const {
return asDouble(); }
676 template <>
inline bool Value::is<double>()
const {
return isDouble(); }
678 template <>
inline String Value::as<String>()
const {
return asString(); }
679 template <>
inline bool Value::is<String>()
const {
return isString(); }
683 template <>
inline float Value::as<float>()
const {
return asFloat(); }
684 template <>
inline const char* Value::as<const char*>()
const {
701 enum Kind { kindNone = 0, kindIndex, kindKey };
704 Kind kind_{kindNone};
726 const Value& resolve(
const Value& root)
const;
733 using InArgs = std::vector<const PathArgument*>;
734 using Args = std::vector<PathArgument>;
736 void makePath(
const String& path,
const InArgs& in);
737 void addPathInArg(
const String& path,
const InArgs& in,
738 InArgs::const_iterator& itInArg, PathArgument::Kind kind);
739 static void invalidPath(
const String& path,
int location);
749 using iterator_category = std::bidirectional_iterator_tag;
750 using size_t =
unsigned int;
751 using difference_type = int;
754 bool operator==(
const SelfType& other)
const {
return isEqual(other); }
756 bool operator!=(
const SelfType& other)
const {
return !isEqual(other); }
758 difference_type operator-(
const SelfType& other)
const {
759 return other.computeDistance(*
this);
779 JSONCPP_DEPRECATED(
"Use `key = name();` instead.")
780 char const* memberName()
const;
784 char const* memberName(
char const** end)
const;
793 const Value& deref()
const;
800 difference_type computeDistance(
const SelfType& other)
const;
802 bool isEqual(
const SelfType& other)
const;
807 Value::ObjectValues::iterator current_;
865 reference operator*()
const {
return deref(); }
867 pointer operator->()
const {
return &deref(); }
877 using size_t =
unsigned int;
878 using difference_type = int;
890 explicit ValueIterator(
const Value::ObjectValues::iterator& current);
923 pointer operator->()
const {
return const_cast<pointer>(&deref()); }
932 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 934 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 936 #endif // JSON_H_INCLUDED unsigned integer value
Definition: value.h:111
double value
Definition: value.h:112
signed integer value
Definition: value.h:110
Experimental and untested: represents an element of the "path" to access a node.
Definition: value.h:691
Lightweight wrapper to tag static string.
Definition: value.h:148
Represents a JSON value.
Definition: value.h:194
a comment placed on the line before a value
Definition: value.h:120
JSONCPP_NORETURN void throwRuntimeError(String const &msg)
used internally
Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
Definition: value.h:95
Base class for all exceptions we throw.
Definition: value.h:68
PrecisionType
Type of precision for formatting of real values.
Definition: value.h:129
object value (collection of name/value pairs).
Definition: value.h:116
bool value
Definition: value.h:114
void swap(Value &other)
Swap everything.
ValueType
Type of the value held by a Value object.
Definition: value.h:108
root value)
Definition: value.h:124
JSON (JavaScript Object Notation).
Definition: allocator.h:15
a comment just after a value on the same line
Definition: value.h:121
we set max number of digits after "." in string
Definition: value.h:131
base class for Value iterators.
Definition: value.h:747
CommentPlacement
Definition: value.h:119
Exceptions which the user cannot easily avoid.
Definition: value.h:84
a comment on the line after a value (only make sense for
Definition: value.h:122
'null' value
Definition: value.h:109
UTF-8 string value.
Definition: value.h:113
JSONCPP_NORETURN void throwLogicError(String const &msg)
used internally
Iterator for object and array value.
Definition: value.h:872
we set max number of significant digits in string
Definition: value.h:130
Experimental and untested: represents a "path" to access a node.
Definition: value.h:718
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... */.
Definition: value.h:571
const iterator for object and array value.
Definition: value.h:821
reference operator*() const
Definition: value.h:922
array value (ordered list)
Definition: value.h:115