20#include <xrpl/basics/contract.h>
21#include <xrpl/beast/core/LexicalCast.h>
22#include <xrpl/json/detail/json_assert.h>
23#include <xrpl/json/json_writer.h>
24#include <xrpl/json/to_string.h>
59 length = value ? (
unsigned int)strlen(value) : 0;
61 char* newString =
static_cast<char*
>(malloc(length + 1));
63 memcpy(newString, value, length);
64 newString[length] = 0;
76static ValueAllocator*&
109 allocate == duplicate ?
valueAllocator()->makeMemberName(cstr) : cstr)
116 other.index_ != noDuplication && other.cstr_ != 0
121 ? (other.index_ == noDuplication ? noDuplication : duplicate)
128 if (cstr_ && index_ == duplicate)
135 if (cstr_ && other.
cstr_)
136 return strcmp(cstr_, other.
cstr_) < 0;
138 return index_ < other.
index_;
144 if (cstr_ && other.
cstr_)
145 return strcmp(cstr_, other.
cstr_) == 0;
147 return index_ == other.
index_;
165 return index_ == noDuplication;
210 UNREACHABLE(
"Json::Value::Value(ValueType) : invalid type");
280 UNREACHABLE(
"Json::Value::Value(Value const&) : invalid type");
308 UNREACHABLE(
"Json::Value::~Value : invalid type");
321 : value_(other.value_), type_(other.type_), allocated_(other.allocated_)
324 other.allocated_ = 0;
330 Value tmp(std::move(other));
344 int temp2 = allocated_;
345 allocated_ = other.allocated_;
346 other.allocated_ = temp2;
363 return (i < ui) ? -1 : (i == ui) ? 0 : 1;
409 UNREACHABLE(
"Json::operator<(Value, Value) : invalid type");
455 UNREACHABLE(
"Json::operator==(Value, Value) : invalid type");
493 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to string");
496 UNREACHABLE(
"Json::Value::asString : invalid type");
516 "integer out of signed integer range");
522 "Real out of signed integer range");
530 return beast::lexicalCastThrow<int>(str);
535 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to int");
538 UNREACHABLE(
"Json::Value::asInt : invalid type");
555 "Negative integer can not be converted to unsigned integer");
564 "Real out of unsigned integer range");
572 return beast::lexicalCastThrow<unsigned int>(str);
577 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to uint");
580 UNREACHABLE(
"Json::Value::asUInt : invalid type");
609 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to double");
612 UNREACHABLE(
"Json::Value::asDouble : invalid type");
644 UNREACHABLE(
"Json::Value::asBool : invalid type");
698 UNREACHABLE(
"Json::Value::isConvertible : invalid type");
723 return (*itLast).first.index() + 1;
732 UNREACHABLE(
"Json::Value::size : invalid type");
738Value::operator bool()
const
745 auto s = asCString();
749 return !(isArray() || isObject()) || size();
757 "Json::Value::clear : valid type");
776 "Json::Value::operator[](UInt) : valid type");
787 ObjectValues::value_type defaultValue(key,
null);
797 "Json::Value::operator[](UInt) const : valid type");
822 "Json::Value::resolveReference : valid type");
834 ObjectValues::value_type defaultValue(actualKey,
null);
836 Value& value = (*it).second;
843 const Value* value = &((*this)[index]);
844 return value == &
null ? defaultValue : *value;
850 return index <
size();
858 "Json::Value::operator[](const char*) const : valid type");
875 return (*
this)[key.
c_str()];
881 return (*
this)[key.
c_str()];
893 return (*
this)[
size()] = value;
899 return (*
this)[
size()] = std::move(value);
905 const Value* value = &((*this)[key]);
906 return value == &
null ? defaultValue : *value;
912 return get(key.
c_str(), defaultValue);
920 "Json::Value::removeMember : valid type");
931 Value old(it->second);
948 const Value* value = &((*this)[key]);
949 return value != &
null;
963 "Json::Value::getMemberNames : valid type");
973 for (; it != itEnd; ++it)
1055 return writer.
write(*
this);
virtual ~DefaultValueAllocator()=default
void releaseMemberName(char *memberName) override
char * makeMemberName(const char *memberName) override
char * duplicateStringValue(const char *value, unsigned int length=unknown) override
void releaseStringValue(char *value) override
Lightweight wrapper to tag static string.
constexpr const char * c_str() const
Writes a Value in JSON format in a human friendly way.
std::string write(const Value &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 void releaseMemberName(char *memberName)=0
virtual char * duplicateStringValue(const char *value, unsigned int length=unknown)=0
const iterator for object and array value.
Iterator for object and array value.
bool isStaticString() const
bool operator<(const CZString &other) const
const char * c_str() const
bool operator==(const CZString &other) const
const_iterator begin() const
friend bool operator==(const Value &, const Value &)
Value & resolveReference(const char *key, bool isStatic)
const char * asCString() const
Value get(UInt index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
UInt size() const
Number of values in array or object.
std::string toStyledString() const
const_iterator end() const
bool isObjectOrNull() const
void clear()
Remove all object members and array elements.
union Json::Value::ValueHolder value_
ValueConstIterator const_iterator
Members getMemberNames() const
Return a list of the member names.
Value & append(const Value &value)
Append value to array at the end.
std::vector< std::string > Members
Value & operator=(Value const &other)
void swap(Value &other) noexcept
Swap values.
Value removeMember(const char *key)
Remove and return the named member.
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 isArrayOrNull() const
static const UInt maxUInt
bool isMember(const char *key) const
Return true if the object has a member named key.
Value(ValueType type=nullValue)
Create a default Value of the given type.
std::map< CZString, Value > ObjectValues
bool isConvertibleTo(ValueType other) const
Value & operator[](UInt index)
Access an array element (zero based index ).
JSON (JavaScript Object Notation).
bool operator<(const Value &, const Value &)
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
static ValueAllocator *& valueAllocator()
static int integerCmp(Int i, UInt ui)
DummyValueAllocatorInitializer()