20#include <xrpl/beast/core/LexicalCast.h>
21#include <xrpl/beast/utility/instrumentation.h>
22#include <xrpl/json/detail/json_assert.h>
23#include <xrpl/json/json_forwards.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/json/json_writer.h>
66 length = value ? (
unsigned int)strlen(value) : 0;
68 char* newString =
static_cast<char*
>(malloc(length + 1));
70 memcpy(newString, value, length);
71 newString[length] = 0;
83static ValueAllocator*&
116 allocate == duplicate ?
valueAllocator()->makeMemberName(cstr) : cstr)
123 other.index_ != noDuplication && other.cstr_ != 0
128 ? (other.index_ == noDuplication ? noDuplication : duplicate)
135 if (cstr_ && index_ == duplicate)
142 if (cstr_ && other.
cstr_)
143 return strcmp(cstr_, other.
cstr_) < 0;
145 return index_ < other.
index_;
151 if (cstr_ && other.
cstr_)
152 return strcmp(cstr_, other.
cstr_) == 0;
154 return index_ == other.
index_;
172 return index_ == noDuplication;
218 UNREACHABLE(
"Json::Value::Value(ValueType) : invalid type");
297 UNREACHABLE(
"Json::Value::Value(Value const&) : invalid type");
327 UNREACHABLE(
"Json::Value::~Value : invalid type");
341 : value_(other.value_), type_(other.type_), allocated_(other.allocated_)
344 other.allocated_ = 0;
350 Value tmp(std::move(other));
364 int temp2 = allocated_;
365 allocated_ = other.allocated_;
366 other.allocated_ = temp2;
383 return (i < ui) ? -1 : (i == ui) ? 0 : 1;
430 UNREACHABLE(
"Json::operator<(Value, Value) : invalid type");
478 UNREACHABLE(
"Json::operator==(Value, Value) : invalid type");
517 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to string");
521 UNREACHABLE(
"Json::Value::asString : invalid type");
542 "integer out of signed integer range");
548 "Real out of signed integer range");
556 return beast::lexicalCastThrow<int>(str);
561 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to int");
565 UNREACHABLE(
"Json::Value::asInt : invalid type");
583 "Negative integer can not be converted to unsigned integer");
592 "Real out of unsigned integer range");
600 return beast::lexicalCastThrow<unsigned int>(str);
605 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to uint");
609 UNREACHABLE(
"Json::Value::asUInt : invalid type");
639 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to double");
643 UNREACHABLE(
"Json::Value::asDouble : invalid type");
677 UNREACHABLE(
"Json::Value::asBool : invalid type");
735 UNREACHABLE(
"Json::Value::isConvertible : invalid type");
761 return (*itLast).first.index() + 1;
771 UNREACHABLE(
"Json::Value::size : invalid type");
778Value::operator bool()
const
785 auto s = asCString();
789 return !(isArray() || isObject()) || size();
797 "Json::Value::clear : valid type");
816 "Json::Value::operator[](UInt) : valid type");
827 ObjectValues::value_type defaultValue(key,
null);
837 "Json::Value::operator[](UInt) const : valid type");
862 "Json::Value::resolveReference : valid type");
874 ObjectValues::value_type defaultValue(actualKey,
null);
876 Value& value = (*it).second;
883 Value const* value = &((*this)[index]);
884 return value == &
null ? defaultValue : *value;
890 return index <
size();
898 "Json::Value::operator[](const char*) const : valid type");
915 return (*
this)[key.
c_str()];
921 return (*
this)[key.
c_str()];
933 return (*
this)[key.
c_str()];
939 return (*
this)[
size()] = value;
945 return (*
this)[
size()] = std::move(value);
951 Value const* value = &((*this)[key]);
952 return value == &
null ? defaultValue : *value;
958 return get(key.
c_str(), defaultValue);
966 "Json::Value::removeMember : valid type");
977 Value old(it->second);
994 Value const* value = &((*this)[key]);
995 return value != &
null;
1009 "Json::Value::getMemberNames : valid type");
1019 for (; it != itEnd; ++it)
1101 return writer.
write(*
this);
char * duplicateStringValue(char const *value, unsigned int length=unknown) override
virtual ~DefaultValueAllocator()=default
void releaseMemberName(char *memberName) override
char * makeMemberName(char const *memberName) override
void releaseStringValue(char *value) override
Lightweight wrapper to tag static string.
constexpr char const * c_str() const
Writes a Value in JSON format in a human friendly way.
std::string write(Value const &root) override
Serialize a Value in JSON format.
Experimental do not use: Allocator to customize member name and string value memory management done b...
virtual void releaseStringValue(char *value)=0
virtual char * duplicateStringValue(char const *value, unsigned int length=unknown)=0
virtual void releaseMemberName(char *memberName)=0
const iterator for object and array value.
Iterator for object and array value.
bool isStaticString() const
char const * c_str() const
bool operator==(CZString const &other) const
bool operator<(CZString const &other) const
const_iterator begin() const
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
std::string toStyledString() const
const_iterator end() const
bool isObjectOrNull() const
static UInt const maxUInt
void clear()
Remove all object members and array elements.
char const * asCString() const
union Json::Value::ValueHolder value_
ValueConstIterator const_iterator
Members getMemberNames() const
Return a list of the member names.
std::vector< std::string > Members
Value & operator=(Value const &other)
Value removeMember(char const *key)
Remove and return the named member.
void swap(Value &other) noexcept
Swap values.
bool isValidIndex(UInt index) const
Return true if index < size().
std::string asString() const
Returns the unquoted string value.
bool isNull() const
isNull() tests to see if this field is null.
bool isMember(char const *key) const
Return true if the object has a member named key.
bool isArrayOrNull() const
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
Value(ValueType type=nullValue)
Create a default Value of the given type.
std::map< CZString, Value > ObjectValues
Value & resolveReference(char const *key, bool isStatic)
bool isConvertibleTo(ValueType other) const
Value & operator[](UInt index)
Access an array element (zero based index ).
JSON (JavaScript Object Notation).
std::string to_string(Value const &)
Writes a Json::Value to an std::string.
static struct Json::DummyValueAllocatorInitializer dummyValueAllocatorInitializer
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<(Value const &, Value const &)
bool operator==(StaticString x, StaticString y)
static ValueAllocator *& valueAllocator()
static int integerCmp(Int i, UInt ui)
DummyValueAllocatorInitializer()