6 #ifndef CPPTL_JSON_H_INCLUDED
7 #define CPPTL_JSON_H_INCLUDED
9 #if !defined(JSON_IS_AMALGAMATION)
16 #ifndef JSON_USE_CPPTL_SMALLMAP
19 #include <cpptl/smallmap.h>
22 #include <cpptl/forwards.h>
28 #if !defined(JSONCPP_NORETURN)
29 # if defined(_MSC_VER)
30 # define JSONCPP_NORETURN __declspec(noreturn)
31 # elif defined(__GNUC__)
32 # define JSONCPP_NORETURN __attribute__ ((__noreturn__))
34 # define JSONCPP_NORETURN
40 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
42 #pragma warning(disable : 4251)
58 ~
Exception() JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;
59 char const* what()
const JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;
133 explicit StaticString(
const char* czstring) : c_str_(czstring) {}
135 operator const char*()
const {
return c_str_; }
137 const char* c_str()
const {
return c_str_; }
180 typedef std::vector<JSONCPP_STRING> Members;
183 typedef Json::UInt UInt;
184 typedef Json::Int Int;
185 #if defined(JSON_HAS_INT64)
186 typedef Json::UInt64 UInt64;
187 typedef Json::Int64 Int64;
189 typedef Json::LargestInt LargestInt;
190 typedef Json::LargestUInt LargestUInt;
191 typedef Json::ArrayIndex ArrayIndex;
194 typedef std::string value_type;
214 #if defined(JSON_HAS_INT64)
224 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
227 enum DuplicationPolicy {
233 CZString(
char const* str,
unsigned length, DuplicationPolicy allocate);
235 #if JSON_HAS_RVALUE_REFERENCES
241 #if JSON_HAS_RVALUE_REFERENCES
247 ArrayIndex index()
const;
249 char const* data()
const;
250 unsigned length()
const;
251 bool isStaticString()
const;
258 unsigned length_: 30;
269 #ifndef JSON_USE_CPPTL_SMALLMAP
270 typedef std::map<CZString, Value> ObjectValues;
272 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
295 #if defined(JSON_HAS_INT64)
301 Value(
const char* begin,
const char* end);
319 #ifdef JSON_USE_CPPTL
320 Value(
const CppTL::ConstString& value);
325 #if JSON_HAS_RVALUE_REFERENCES
357 #if JSONCPP_USING_SECURE_MEMORY
358 unsigned getCStringLength()
const;
365 char const** begin,
char const** end)
const;
366 #ifdef JSON_USE_CPPTL
367 CppTL::ConstString asConstString()
const;
371 #if defined(JSON_HAS_INT64)
372 Int64 asInt64()
const;
373 UInt64 asUInt64()
const;
375 LargestInt asLargestInt()
const;
376 LargestUInt asLargestUInt()
const;
377 float asFloat()
const;
378 double asDouble()
const;
387 bool isIntegral()
const;
390 bool isString()
const;
391 bool isArray()
const;
392 bool isObject()
const;
394 bool isConvertibleTo(
ValueType other)
const;
404 explicit operator bool()
const;
455 #if JSON_HAS_RVALUE_REFERENCES
486 #ifdef JSON_USE_CPPTL
488 Value& operator[](
const CppTL::ConstString& key);
491 const Value& operator[](
const CppTL::ConstString& key)
const;
499 Value get(
const char* begin,
const char* end,
const Value& defaultValue)
const;
504 #ifdef JSON_USE_CPPTL
507 Value get(
const CppTL::ConstString& key,
const Value& defaultValue)
const;
512 Value const*
find(
char const* begin,
char const* end)
const;
556 bool isMember(
const char* begin,
const char* end)
const;
557 #ifdef JSON_USE_CPPTL
559 bool isMember(
const CppTL::ConstString& key)
const;
585 JSONCPP_STRING toStyledString() const;
595 void setOffsetStart(ptrdiff_t start);
596 void setOffsetLimit(ptrdiff_t limit);
597 ptrdiff_t getOffsetStart() const;
598 ptrdiff_t getOffsetLimit() const;
601 void initBasic(
ValueType type,
bool allocated = false);
603 Value& resolveReference(const
char* key);
604 Value& resolveReference(const
char* key, const
char* end);
610 void setComment(
const char* text,
size_t len);
633 unsigned int allocated_ : 1;
679 Path(
const JSONCPP_STRING& path,
686 const Value& resolve(
const Value& root)
const;
693 typedef std::vector<const PathArgument*> InArgs;
694 typedef std::vector<PathArgument> Args;
696 void makePath(
const JSONCPP_STRING& path,
const InArgs& in);
697 void addPathInArg(
const JSONCPP_STRING& path,
699 InArgs::const_iterator& itInArg,
700 PathArgument::Kind kind);
701 void invalidPath(
const JSONCPP_STRING& path,
int location);
711 typedef std::bidirectional_iterator_tag iterator_category;
712 typedef unsigned int size_t;
713 typedef int difference_type;
721 return other.computeDistance(*
this);
740 char const* memberName() const;
744 char const* memberName(
char const** end) const;
747 Value& deref() const;
753 difference_type computeDistance(const
SelfType& other) const;
760 Value::ObjectValues::iterator current_;
817 reference operator*()
const {
return deref(); }
819 pointer operator->()
const {
return &deref(); }
829 typedef unsigned int size_t;
830 typedef int difference_type;
842 explicit ValueIterator(
const Value::ObjectValues::iterator& current);
868 reference operator*()
const {
return deref(); }
870 pointer operator->()
const {
return &deref(); }
884 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
tBool operator<(const tErrorCode &lhs, const tErrorCode &rhs)
Less-than operator for POD error type.
tBool operator<=(const tErrorCode &lhs, const tErrorCode &rhs)
Less-than-or-equal operator for POD error type.
tBool operator>(const tErrorCode &lhs, const tErrorCode &rhs)
Greater-than operator for POD error type.
tBool operator!=(const tErrorCode &lhs, const tErrorCode &rhs)
Compare two POD error code types for inequality.
tBool operator==(const tErrorCode &lhs, const tErrorCode &rhs)
Compare two POD error code types for equality.
tBool operator>=(const tErrorCode &lhs, const tErrorCode &rhs)
Greater-than-or-equal operator for POD error type.
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.
Value & make(Value &root) const
Creates the "path" to access the specified node and returns a reference on the node.
Exceptions which the user cannot easily avoid.
Lightweight wrapper to tag static string.
const iterator for object and array value.
Value(const StaticString &value)
Constructs a value from a static string.
static const Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
Value & append(const Value &value)
Append value to array at the end.
static const Value & nullRef
just a kludge for binary-compatibility; same as null
Value & operator[](const JSONCPP_STRING &key)
Access an object value by name, create a null member if it does not exist.
static const LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
bool removeIndex(ArrayIndex i, Value *removed)
Remove the indexed array element.
Value get(ArrayIndex index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
static const LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
Value(const Value &other)
Deep copy.
const char * asCString() const
Embedded zeroes could cause you trouble!
ArrayIndex size() const
Number of values in array or object.
const Value & operator[](const JSONCPP_STRING &key) const
Access an object value by name, returns null if there is no member with that name.
Value(const char *begin, const char *end)
Copy all, incl zeroes.
Value const * find(char const *begin, char const *end) const
Most general and efficient version of isMember()const, get()const, and operator[]const.
const Value & operator[](int index) const
Access an array element (zero based index ) (You may need to say 'value[0u]' to get your compiler to ...
static const Int minInt
Minimum signed int value that can be stored in a Json::Value.
bool empty() const
Return true if empty array, empty object, or null; otherwise, false.
static Value const & nullSingleton()
Prefer this to null or nullRef.
Value(ValueType type=nullValue)
Create a default Value of the given type.
void resize(ArrayIndex size)
Resize the array to size elements.
void copyPayload(const Value &other)
copy values but leave comments and source offsets in place.
Value(const JSONCPP_STRING &value)
Copy data() til size(). Embedded zeroes too.
Value(const char *value)
Copy til first 0. (NULL causes to seg-fault.)
bool isMember(const JSONCPP_STRING &key) const
Return true if the object has a member named key.
void copy(const Value &other)
copy everything.
Value & operator[](const StaticString &key)
Access an object value by name, create a null member if it does not exist.
static const UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
Value const * demand(char const *begin, char const *end)
Most general and efficient version of object-mutators.
bool getString(char const **begin, char const **end) const
Get raw char* of string-value.
static const LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
bool isMember(const char *begin, const char *end) const
Same as isMember(JSONCPP_STRING const& key)const.
Value get(const char *key, const Value &defaultValue) const
Return the member named key if it exist, defaultValue otherwise.
bool isValidIndex(ArrayIndex index) const
Return true if index < size().
Value get(const JSONCPP_STRING &key, const Value &defaultValue) const
Return the member named key if it exist, defaultValue otherwise.
Value get(const char *begin, const char *end, const Value &defaultValue) const
Return the member named key if it exist, defaultValue otherwise.
Members getMemberNames() const
Return a list of the member names.
Value & operator[](ArrayIndex index)
Access an array element (zero based index ).
Value & operator[](const char *key)
Access an object value by name, create a null member if it does not exist.
bool removeMember(const char *begin, const char *end, Value *removed)
Same as removeMember(JSONCPP_STRING const& key, Value* removed)
void removeMember(const JSONCPP_STRING &key)
Same as removeMember(const char*)
Value & operator=(Value other)
Deep copy, then swap(other).
static const UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
const Value & operator[](ArrayIndex index) const
Access an array element (zero based index ) (You may need to say 'value[0u]' to get your compiler to ...
static const Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
void swap(Value &other)
Swap everything.
void clear()
Remove all object members and array elements.
void swapPayload(Value &other)
Swap values but leave comments and source offsets in place.
bool operator<(const Value &other) const
Compare payload only, not comments etc.
JSONCPP_STRING asString() const
Embedded zeroes are possible.
bool removeMember(JSONCPP_STRING const &key, Value *removed)
Remove the named map member.
void removeMember(const char *key)
Remove and return the named member.
bool isMember(const char *key) const
Return true if the object has a member named key.
const Value & operator[](const char *key) const
Access an object value by name, returns null if there is no member with that name.
static const Int maxInt
Maximum signed int value that can be stored in a Json::Value.
bool removeMember(const char *key, Value *removed)
Same as removeMember(const char* begin, const char* end, Value* removed), but 'key' is null-terminate...
Value & operator[](int index)
Access an array element (zero based index ).
base class for Value iterators.
UInt index() const
Return the index of the referenced Value, or -1 if it is not an arrayValue.
Value key() const
Return either the index or the member name of the referenced value as a Value.
JSONCPP_STRING name() const
Return the member name of the referenced Value, or "" if it is not an objectValue.
Iterator for object and array value.
simple_pointer_iterator< T >::difference_type operator-(const simple_pointer_iterator< T > &r1, const simple_pointer_iterator< T > &r2)
Define arithmetic - operation between iterators.
JSON (JavaScript Object Notation).
JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const &msg)
used internally
JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const &msg)
used internally
class JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead") JSON_API Reader
Unserialize a JSON document into a Value.
@ 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.
@ intValue
signed integer value
@ arrayValue
array value (ordered list)
@ uintValue
unsigned integer value
@ objectValue
object value (collection of name/value pairs).
int compare(const void *buf1, std::size_t buf1_size, const void *buf2, std::size_t buf2_size)
Portable safe memcmp.
bool copy(void *dest, std::size_t dest_size, const void *source, std::size_t bytes_to_copy)
Portable safe memcopy.
bool isInt64(const std::string &str)
Check whether a string can be converted to a value of the given numeric type.
bool isNumeric(const char *str)
Check whether a string is convertible to a value of type Numeric for generic programming.
bool isEqual(const char *left, const char *right)
Compares two 0-terminated C-strings for equality.
bool isBool(const std::string &str)
Check whether a string can be converted to a boolean type.
bool isDouble(const std::string &str)
Check whether a string can be converted to a value of the given numeric type.
bool isUInt64(const std::string &str)
Check whether a string can be converted to a value of the given numeric type.