20 #include <ripple/basics/contract.h>
21 #include <ripple/beast/core/LexicalCast.h>
22 #include <ripple/json/impl/json_assert.h>
23 #include <ripple/json/json_writer.h>
24 #include <ripple/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;
76 static 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 JSON_ASSERT_UNREACHABLE;
280 JSON_ASSERT_UNREACHABLE;
308 JSON_ASSERT_UNREACHABLE;
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 JSON_ASSERT_UNREACHABLE;
455 JSON_ASSERT_UNREACHABLE;
493 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to string");
496 JSON_ASSERT_UNREACHABLE;
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 JSON_ASSERT_UNREACHABLE;
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 JSON_ASSERT_UNREACHABLE;
609 JSON_ASSERT_MESSAGE(
false,
"Type is not convertible to double");
612 JSON_ASSERT_UNREACHABLE;
644 JSON_ASSERT_UNREACHABLE;
698 JSON_ASSERT_UNREACHABLE;
723 return (*itLast).first.index() + 1;
732 JSON_ASSERT_UNREACHABLE;
738 Value::operator bool()
const
745 auto s = asCString();
749 return !(isArray() || isObject()) || size();
784 ObjectValues::value_type defaultValue(key,
null);
827 ObjectValues::value_type defaultValue(actualKey,
null);
829 Value& value = (*it).second;
836 const Value* value = &((*this)[index]);
837 return value == &
null ? defaultValue : *value;
843 return index <
size();
866 return (*
this)[key.
c_str()];
872 return (*
this)[key.
c_str()];
884 return (*
this)[
size()] = value;
890 return (*
this)[
size()] = std::move(value);
896 const Value* value = &((*this)[key]);
897 return value == &
null ? defaultValue : *value;
903 return get(key.
c_str(), defaultValue);
920 Value old(it->second);
937 const Value* value = &((*this)[key]);
938 return value != &
null;
960 for (; it != itEnd; ++it)
1042 return writer.
write(*
this);
Iterator for object and array value.
bool operator<(const Value &x, const Value &y)
bool isValidIndex(UInt index) const
Return true if index < size().
@ arrayValue
array value (ordered list)
void releaseMemberName(char *memberName) override
Value get(UInt index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
void swap(Value &other) noexcept
Swap values.
const char * c_str() const
bool isNull() const
isNull() tests to see if this field is null.
std::string toStyledString() const
const_iterator end() const
std::string write(const Value &root) override
Serialize a Value in JSON format.
constexpr const char * c_str() const
static int integerCmp(Int i, UInt ui)
Experimental do not use: Allocator to customize member name and string value memory management done b...
@ uintValue
unsigned integer value
JSON (JavaScript Object Notation).
Value & append(const Value &value)
Append value to array at the end.
Value & resolveReference(const char *key, bool isStatic)
void releaseStringValue(char *value) override
@ objectValue
object value (collection of name/value pairs).
DummyValueAllocatorInitializer()
static struct Json::DummyValueAllocatorInitializer dummyValueAllocatorInitializer
Writes a Value in JSON format in a human friendly way.
union Json::Value::ValueHolder value_
bool isConvertibleTo(ValueType other) const
bool isArrayOrNull() const
const iterator for object and array value.
std::map< CZString, Value > ObjectValues
bool operator==(const Value &x, const Value &y)
virtual void releaseStringValue(char *value)=0
UInt size() const
Number of values in array or object.
bool isMember(const char *key) const
Return true if the object has a member named key.
@ stringValue
UTF-8 string value.
ValueType
Type of the value held by a Value object.
const char * asCString() const
char * makeMemberName(const char *memberName) override
static ValueAllocator *& valueAllocator()
bool operator<(const CZString &other) const
virtual ~DefaultValueAllocator()=default
bool operator==(const CZString &other) const
virtual char * duplicateStringValue(const char *value, unsigned int length=unknown)=0
Members getMemberNames() const
Return a list of the member names.
Value & operator=(Value const &other)
static const UInt maxUInt
Value removeMember(const char *key)
Remove and return the named member.
virtual void releaseMemberName(char *memberName)=0
void clear()
Remove all object members and array elements.
Lightweight wrapper to tag static string.
@ intValue
signed integer value
Value & operator[](UInt index)
Access an array element (zero based index ).
Value(ValueType type=nullValue)
Create a default Value of the given type.
std::vector< std::string > Members
char * duplicateStringValue(const char *value, unsigned int length=unknown) override
const_iterator begin() const
bool isStaticString() const
bool isObjectOrNull() const
std::string asString() const
Returns the unquoted string value.
ValueConstIterator const_iterator