6#ifndef CPPTL_JSON_H_INCLUDED
7#define CPPTL_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]]
30#ifndef JSON_USE_CPPTL_SMALLMAP
33#include <cpptl/smallmap.h>
36#include <cpptl/forwards.h>
41#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
43#pragma warning(disable : 4251)
146 operator const char*()
const {
return c_str_; }
148 const char*
c_str()
const {
return c_str_; }
197#if defined(JSON_HAS_INT64)
215 static Value const& nullSingleton();
232#if defined(JSON_HAS_INT64)
241 static constexpr UInt defaultRealPrecision = 17;
245 static constexpr double maxUInt64AsDouble = 18446744073709551615.0;
254#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
257 enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
259 CZString(
char const* str,
unsigned length, DuplicationPolicy allocate);
260 CZString(CZString
const& other);
261 CZString(CZString&& other);
263 CZString& operator=(
const CZString& other);
264 CZString& operator=(CZString&& other);
266 bool operator<(CZString
const& other)
const;
270 char const* data()
const;
271 unsigned length()
const;
272 bool isStaticString()
const;
275 void swap(CZString& other);
277 struct StringStorage {
278 unsigned policy_ : 2;
279 unsigned length_ : 30;
285 StringStorage storage_;
290#ifndef JSON_USE_CPPTL_SMALLMAP
291 typedef std::map<CZString, Value> ObjectValues;
293 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
317#if defined(JSON_HAS_INT64)
322 Value(
const char* value);
323 Value(
const char* begin,
const char* end);
344 Value(
const CppTL::ConstString& value);
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;
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;
388 CppTL::ConstString asConstString()
const;
392#if defined(JSON_HAS_INT64)
393 Int64 asInt64()
const;
398 float asFloat()
const;
399 double asDouble()
const;
405 bool isInt64()
const;
407 bool isUInt64()
const;
408 bool isIntegral()
const;
409 bool isDouble()
const;
410 bool isNumeric()
const;
411 bool isString()
const;
412 bool isArray()
const;
413 bool isObject()
const;
416 template <
typename T> T
as()
const =
delete;
417 template <
typename T>
bool is()
const =
delete;
419 bool isConvertibleTo(
ValueType other)
const;
450 Value& operator[](
int index);
458 const Value& operator[](
int index)
const;
477 Value& operator[](
const char* key);
480 const Value& operator[](
const char* key)
const;
503 Value& operator[](
const CppTL::ConstString& key);
506 const Value& operator[](
const CppTL::ConstString& key)
const;
510 Value get(
const char* key,
const Value& defaultValue)
const;
514 Value get(
const char* begin,
const char* end,
515 const Value& defaultValue)
const;
523 Value get(
const CppTL::ConstString& key,
const Value& defaultValue)
const;
528 Value const* find(
char const* begin,
char const* end)
const;
532 Value* demand(
char const* begin,
char const* end);
538 void removeMember(
const char* key);
541 void removeMember(
const String& key);
544 bool removeMember(
const char* key,
Value* removed);
551 bool removeMember(
String const& key,
Value* removed);
553 bool removeMember(
const char* begin,
const char* end,
Value* removed);
564 bool isMember(
const char* key)
const;
567 bool isMember(
const String& key)
const;
569 bool isMember(
const char* begin,
const char* end)
const;
572 bool isMember(
const CppTL::ConstString& key)
const;
580 Members getMemberNames()
const;
590 setComment(
String(comment, strlen(comment)), placement);
594 setComment(
String(comment, len), placement);
602 String toStyledString()
const;
604 const_iterator begin()
const;
605 const_iterator end()
const;
612 void setOffsetStart(ptrdiff_t start);
613 void setOffsetLimit(ptrdiff_t limit);
614 ptrdiff_t getOffsetStart()
const;
615 ptrdiff_t getOffsetLimit()
const;
619 bits_.value_type_ =
static_cast<unsigned char>(v);
621 bool isAllocated()
const {
return bits_.allocated_; }
622 void setIsAllocated(
bool v) { bits_.allocated_ = v; }
624 void initBasic(ValueType type,
bool allocated =
false);
625 void dupPayload(
const Value& other);
626 void releasePayload();
627 void dupMeta(
const Value& other);
629 Value& resolveReference(
const char* key);
630 Value& resolveReference(
const char* key,
const char* end);
659 Comments() =
default;
660 Comments(
const Comments& that);
661 Comments(Comments&& that);
662 Comments& operator=(
const Comments& that);
663 Comments& operator=(Comments&& that);
669 using Array = std::array<String, numberOfCommentPlacement>;
670 std::unique_ptr<Array> ptr_;
680template <>
inline bool Value::as<bool>()
const {
return asBool(); }
681template <>
inline bool Value::is<bool>()
const {
return isBool(); }
683template <>
inline Int Value::as<Int>()
const {
return asInt(); }
684template <>
inline bool Value::is<Int>()
const {
return isInt(); }
686template <>
inline UInt Value::as<UInt>()
const {
return asUInt(); }
687template <>
inline bool Value::is<UInt>()
const {
return isUInt(); }
689#if defined(JSON_HAS_INT64)
690template <>
inline Int64 Value::as<Int64>()
const {
return asInt64(); }
691template <>
inline bool Value::is<Int64>()
const {
return isInt64(); }
693template <>
inline UInt64 Value::as<UInt64>()
const {
return asUInt64(); }
694template <>
inline bool Value::is<UInt64>()
const {
return isUInt64(); }
697template <>
inline double Value::as<double>()
const {
return asDouble(); }
698template <>
inline bool Value::is<double>()
const {
return isDouble(); }
700template <>
inline String Value::as<String>()
const {
return asString(); }
701template <>
inline bool Value::is<String>()
const {
return isString(); }
705template <>
inline float Value::as<float>()
const {
return asFloat(); }
706template <>
inline const char* Value::as<const char*>()
const {
710template <>
inline CppTL::ConstString Value::as<CppTL::ConstString>()
const {
711 return asConstString();
728 enum Kind { kindNone = 0, kindIndex, kindKey };
731 Kind kind_{kindNone};
753 const Value& resolve(
const Value& root)
const;
760 typedef std::vector<const PathArgument*> InArgs;
761 typedef std::vector<PathArgument> Args;
763 void makePath(
const String& path,
const InArgs& in);
764 void addPathInArg(
const String& path,
const InArgs& in,
765 InArgs::const_iterator& itInArg, PathArgument::Kind kind);
766 static void invalidPath(
const String& path,
int location);
807 char const* memberName() const;
811 char const* memberName(
char const** end) const;
820 const
Value& deref() const;
829 bool isEqual(const
SelfType& other) const;
834 Value::ObjectValues::iterator current_;
917 explicit ValueIterator(
const Value::ObjectValues::iterator& current);
959#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Base class for all exceptions we throw.
Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
Experimental and untested: represents an element of the "path" to access a node.
Experimental and untested: represents a "path" to access a node.
Exceptions which the user cannot easily avoid.
Lightweight wrapper to tag static string.
const char * c_str() const
StaticString(const char *czstring)
const iterator for object and array value.
ValueConstIterator SelfType
pointer operator->() const
reference operator*() const
Json::ArrayIndex ArrayIndex
Json::LargestInt LargestInt
static const Value & null
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... */.
T as() const =delete
The as<T> and is<T> member function templates and specializations.
std::vector< String > Members
Json::LargestUInt LargestUInt
void swap(Value &other)
Swap everything.
static const Value & nullRef
ValueConstIterator const_iterator
base class for Value iterators.
std::bidirectional_iterator_tag iterator_category
bool operator==(const SelfType &other) const
difference_type operator-(const SelfType &other) const
ValueIteratorBase SelfType
bool operator!=(const SelfType &other) const
difference_type computeDistance(const SelfType &other) const
Iterator for object and array value.
ValueIterator(const ValueIterator &other)
#define JSON_API
If defined, indicates that the source file is amalgamated to prevent private header inclusion.
#define JSONCPP_OP_EXPLICIT
#define JSONCPP_DEPRECATED(message)
JSON (JavaScript Object Notation).
std::basic_string< char, std::char_traits< char >, Allocator< char > > String
@ commentAfterOnSameLine
a comment just after a value on the same line
@ commentBefore
a comment placed on the line before a value
@ numberOfCommentPlacement
root value)
@ commentAfter
a comment on the line after a value (only make sense for
ValueType
Type of the value held by a Value object.
@ stringValue
UTF-8 string value.
@ arrayValue
array value (ordered list)
@ intValue
signed integer value
@ objectValue
object value (collection of name/value pairs).
@ uintValue
unsigned integer value
bool operator==(const SecureAllocator< T > &, const SecureAllocator< U > &)
bool operator!=(const SecureAllocator< T > &, const SecureAllocator< U > &)
PrecisionType
Type of precision for formatting of real values.
@ decimalPlaces
we set max number of digits after "." in string
@ significantDigits
we set max number of significant digits in string
void swap(Value &a, Value &b)