20 #include <ripple/basics/contract.h>
21 #include <ripple/json/impl/json_assert.h>
22 #include <ripple/json/to_string.h>
23 #include <ripple/json/json_writer.h>
24 #include <ripple/beast/core/LexicalCast.h>
49 unsigned int length =
unknown )
override
56 length = value ? (
unsigned int)strlen ( value ) : 0;
58 char* newString =
static_cast<char*
> ( malloc ( length + 1 ) );
60 memcpy ( newString, value, length );
61 newString[length] = 0;
104 : cstr_ ( allocate == duplicate ?
valueAllocator ()->makeMemberName (cstr)
106 , index_ ( allocate )
111 : cstr_ ( other.index_ != noDuplication&& other.cstr_ != 0
114 , index_ ( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate)
121 if ( cstr_ && index_ == duplicate )
129 return strcmp ( cstr_, other.
cstr_ ) < 0;
131 return index_ < other.
index_;
138 return strcmp ( cstr_, other.
cstr_ ) == 0;
140 return index_ == other.
index_;
160 return index_ == noDuplication;
207 JSON_ASSERT_UNREACHABLE;
233 , allocated_ ( true )
240 , allocated_ ( true )
243 (
unsigned int)value.
length () );
248 , allocated_ ( false )
261 : type_ ( other.type_ )
290 JSON_ASSERT_UNREACHABLE;
319 JSON_ASSERT_UNREACHABLE;
332 : value_ ( other.value_ )
333 , type_ ( other.type_ )
334 , allocated_ ( other.allocated_ )
337 other.allocated_ = 0;
343 Value tmp(std::move(other));
357 int temp2 = allocated_;
358 allocated_ = other.allocated_;
359 other.allocated_ = temp2;
376 return (i < ui) ? -1 : (i == ui) ? 0 : 1;
422 JSON_ASSERT_UNREACHABLE;
467 JSON_ASSERT_UNREACHABLE;
496 return beast::lexicalCastThrow <std::string> (
value_.
int_);
499 return beast::lexicalCastThrow <std::string> (
value_.
uint_);
502 return beast::lexicalCastThrow <std::string> (
value_.
real_);
506 JSON_ASSERT_MESSAGE (
false,
"Type is not convertible to string" );
509 JSON_ASSERT_UNREACHABLE;
527 JSON_ASSERT_MESSAGE (
value_.
uint_ < (
unsigned)
maxInt,
"integer out of signed integer range" );
540 return beast::lexicalCastThrow <int> (str);
545 JSON_ASSERT_MESSAGE (
false,
"Type is not convertible to int" );
548 JSON_ASSERT_UNREACHABLE;
563 JSON_ASSERT_MESSAGE (
value_.
int_ >= 0,
"Negative integer can not be converted to unsigned integer" );
579 return beast::lexicalCastThrow <unsigned int> (str);
584 JSON_ASSERT_MESSAGE (
false,
"Type is not convertible to uint" );
587 JSON_ASSERT_UNREACHABLE;
616 JSON_ASSERT_MESSAGE (
false,
"Type is not convertible to double" );
619 JSON_ASSERT_UNREACHABLE;
651 JSON_ASSERT_UNREACHABLE;
711 JSON_ASSERT_UNREACHABLE;
737 return (*itLast).first.index () + 1;
746 JSON_ASSERT_UNREACHABLE;
753 Value::operator bool ()
const
760 auto s = asCString();
764 return ! (isArray() || isObject()) || size ();
798 ObjectValues::value_type defaultValue ( key,
null );
845 ObjectValues::value_type defaultValue ( actualKey,
null );
847 Value& value = (*it).second;
854 const Value& defaultValue )
const
856 const Value* value = & ((*this)[index]);
857 return value == &
null ? defaultValue : *value;
864 return index <
size ();
878 ObjectValues::const_iterator it =
value_.
map_->
find ( actualKey );
890 return (*
this)[ key.
c_str () ];
897 return (*
this)[ key.
c_str () ];
909 return (*
this)[
size ()] = value;
915 return (*
this)[
size ()] = std::move(value);
921 const Value& defaultValue )
const
923 const Value* value = & ((*this)[key]);
924 return value == &
null ? defaultValue : *value;
930 const Value& defaultValue )
const
932 return get ( key.
c_str (), defaultValue );
949 Value old (it->second);
966 const Value* value = & ((*this)[key]);
967 return value != &
null;
991 for ( ; it != itEnd; ++it )
1084 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