class ObjectNode
Inherited from: ValueNode.
Required header: <Eclog/ObjectNode.h>
The ObjectNode abstract class represents an object node in a document tree (See Document).
Name | Description |
---|---|
Element | Provides an interface for accessing an element (key-value pair) in the object. |
Iterator |
Provides a STL-style bidirectional iterator for the object. |
ConstIterator |
Provides a STL-style const bidirectional iterator for the object. |
Name | Description |
---|---|
clear | Removes all elements. |
empty | Checks if this object is empty. |
size | Returns the number of elements. |
begin | Returns an iterator to the first element. |
end | Returns an iterator to the past-the-end element. |
first | Returns the first element. |
last | Returns the last element. |
contains | Checks if a specified key exists. |
find | Finds an element with a specified key. |
findNull | Finds a null value with a specified key. |
findBoolean | Finds a Boolean value with a specified key. |
findString | Finds a string value with a specified key. |
findNumber | Finds a number value with a specified key. |
findObject | Finds an object value with a specified key. |
findArray | Finds an array value with a specified key. |
get | Gets an element with a specified key. |
getValue | Gets a value with a specified key. |
getNull | Gets a null value with a specified key. |
getBoolean | Gets a Boolean value with a specified key. |
getString | Gets a string value with a specified key. |
getNumber | Gets a number value with a specified key. |
getObject | Gets an object value with a specified key. |
getArray | Gets an array value with a specified key. |
getOrAddValue | Gets or adds a value with a specified key. |
getOrAddNull | Gets or adds a null value with a specified key. |
getOrAddBoolean | Gets or adds a Boolean value with a specified key. |
getOrAddString | Gets or adds a string value with a specified key. |
getOrAddNumber | Gets or adds a number value with a specified key. |
getOrAddObject | Gets or adds an object value with a specified key. |
getOrAddArray | Gets or adds an array value with a specified key. |
append | Inserts an element at the end. |
insert | Inserts an element before a given position. |
appendForce | Inserts an element at the end. |
insertForce | Inserts an element before a given position. |
merge | Merges a patch object into this object. |
remove | Removes specified elements. |
parse | Parses an Eclog text and replaces elements with the parsing result. |
render | Renders this object and outputs the Eclog text result to a given output stream. |
toStdString | Renders this object and returns the Eclog text result as a C++ string. |
assign | Assigns new elements to this object. |
virtual void clear();
Removes all elements.
All iterators related to this object are invalidated, except the end iterators.
Linear in size.
virtual bool empty() const;
Checks if this object is empty.
bool
true if this object is empty, false otherwise.
Constant.
virtual size_t size() const;
Returns the number of elements.
size_t
Number of elements in this object.
Constant.
virtual Iterator begin();
virtual ConstIterator begin() const;
Returns an iterator to the first element.
If this object is empty, the returned iterator will be equal to end.
Iterator
Iterator to the first element.
ConstIterator
Iterator to the first element.
Constant.
virtual Iterator end();
virtual ConstIterator end() const;
Returns an iterator to the past-the-end element.
This element acts as a placeholder; attempting to access it results in OutOfRange
fault.
Iterator
Iterator to the past-the-end element.
ConstIterator
Iterator to the past-the-end element.
Constant.
Element& first();
Returns the first element.
Element&
Reference to the first element.
An OutOfRange
fault occurs if this object is empty.
Constant.
Element& last();
Returns the last element.
Element&
Reference to the last element.
An OutOfRange
fault occurs if this object is empty.
Constant.
virtual bool contains(cstring key) const;
Checks if the specified key exists.
cstring key Key to search for.
bool
true if the specified key exists, false otherwise.
Logarithmic in size.
virtual Iterator find(cstring key);
virtual ConstIterator find(cstring key) const;
Finds an element with the specified key.
cstring key Key of the element to search for.
Iterator
Iterator to the element if found, end otherwise.
ConstIterator
Iterator to the element if found, end otherwise.
Logarithmic in size.
Iterator findNull(cstring key);
ConstIterator findNull(cstring key) const;
Iterator findBoolean(cstring key);
ConstIterator findBoolean(cstring key) const;
Iterator findString(cstring key);
ConstIterator findString(cstring key) const;
Iterator findNumber(cstring key);
ConstIterator findNumber(cstring key) const;
Iterator findObject(cstring key);
ConstIterator findObject(cstring key) const;
Iterator findArray(cstring key);
ConstIterator findArray(cstring key) const;
Finds a value of a specific type with the specified key.
cstring key Key of the element to search for.
Iterator
Iterator to the element if found, end otherwise.
ConstIterator
Iterator to the element if found, end otherwise.
Logarithmic in size.
Element& get(cstring key);
const Element& get(cstring key) const;
Gets an element with the specified key.
cstring key Key of the element to search for.
Element&
Reference to the element.
const
Element&
Reference to the element.
An OutOfRange
fault occurs if the specified key does not exist.
Logarithmic in size.
ValueNode& getValue(cstring key);
const ValueNode& getValue(cstring key) const;
Gets a value with the specified key.
cstring key Key of the element to search for.
ValueNode&
Reference to the value node.
const
ValueNode&
Reference to the value node.
An OutOfRange
fault occurs if the specified key does not exist.
Logarithmic in size.
NullNode& getNull(cstring key);
const NullNode& getNull(cstring key) const;
BooleanNode& getBoolean(cstring key);
const BooleanNode& getBoolean(cstring key) const;
StringNode& getString(cstring key);
const StringNode& getString(cstring key) const;
NumberNode& getNumber(cstring key);
const NumberNode& getNumber(cstring key) const;
ObjectNode& getObject(cstring key);
const ObjectNode& getObject(cstring key) const;
ArrayNode& getArray(cstring key);
const ArrayNode& getArray(cstring key) const;
Gets a value with the specified key and casts the value to a specified type of value.
cstring key Key of the element to search for.
(value node type)&
Reference to the value node.
const
(value node type)&
Reference to the value node.
An OutOfRange
fault occurs if the specified key does not exist.
A BadCast
fault occurs if the value node is not of the specified type.
Logarithmic in size.
ValueNode& getOrAddValue(const KeyDesc& key,
const ValueDesc& defaultValue = null);
Gets a value with the specified key, or inserts a value with the specified key at the end, if the key does not exist.
cstring key Key of the element.
const
ValueDesc&
desc The description of the value to be inserted.
ValueNode&
Reference to the value node.
If an error occurs, this object remains untouched.
Logarithmic in size.
NullNode& getOrAddNull(const KeyDesc& key,
const Null& defaultValue = null);
BooleanNode& getOrAddBoolean(const KeyDesc& key,
bool defaultValue = false);
StringNode& getOrAddString(const KeyDesc& key,
const StringDesc& defaultValue = cstring());
NumberNode& getOrAddNumber(const KeyDesc& key,
const NumberDesc& defaultValue = 0);
ObjectNode& getOrAddObject(const KeyDesc& key,
const ObjectDesc& defaultValue = empty_object);
ArrayNode& getOrAddArray(const KeyDesc& key,
const ArrayDesc& defaultValue = empty_array);
Gets a value with the specified key and casts the value to a specific type, or inserts a value with the specified key at the end, if the key does not exist.
cstring key Key of the element.
bool
defaultValue The Boolean value to be inserted.
const
StringDesc&
defaultValue The description of the string value to be inserted.
const
NumberDesc&
defaultValue The description of the number value to be inserted.
const
ObjectDesc&
defaultValue The description of the object value to be inserted.
const
ArrayDesc&
defaultValue The description of the array value to be inserted.
(value node type)&
Reference to the value node.
const
(value node type)&
Reference to the value node.
A BadCast
fault occurs if the value node is not of the specified type.
If an error occurs, this object remains untouched.
Logarithmic in size.
bool append(const Element& element);
bool append(const KeyNode& key, const ValueNode& value);
bool append(const KeyDesc& key, const ValueNode& value);
bool append(const KeyNode& key, const ValueDesc& value);
bool append(const KeyDesc& key, const ValueDesc& value);
Inserts an element at the end of this object if the specified key does not exist.
const
Element&
element The element to be inserted.
const
KeyNode&
key The key to be inserted.
const
KeyDesc&
key The description of the key to be inserted.
const
ValueNode&
value The value to be inserted.
const
ValueDesc&
value The description of the value to be inserted.
bool
true if the insertion took place, false otherwise.
If an error occurs, this object remains untouched.
No changes.
Logarithmic in size.
virtual Pair<Iterator, bool> insert(Iterator pos,
const Element& element);
virtual Pair<Iterator, bool> insert(Iterator pos,
const KeyNode& key, const ValueNode& value);
virtual Pair<Iterator, bool> insert(Iterator pos,
const KeyDesc& key, const ValueNode& value);
virtual Pair<Iterator, bool> insert(Iterator pos,
const KeyNode& key, const ValueDesc& value);
virtual Pair<Iterator, bool> insert(Iterator pos,
const KeyDesc& key, const ValueDesc& value);
Inserts an element before the given position if the specified key does not exist.
Iterator
pos Position in this object where the new element will be inserted before.
const
Element&
element The element to be inserted.
const
KeyNode&
key The key to be inserted.
const
KeyDesc&
key The description of the key to be inserted.
const
ValueNode&
value The value to be inserted.
const
ValueDesc&
value The description of the value to be inserted.
Pair<Iterator, bool>
A pair consisting of an iterator to the inserted element (or to the element that prevented the insertion) and a Boolean denoting whether the insertion took place.
If an error occurs, this object remains untouched.
No changes.
Logarithmic in size.
void appendForce(const Element& element);
void appendForce(const KeyNode& key, const ValueNode& value);
void appendForce(const KeyDesc& key, const ValueNode& value);
void appendForce(const KeyNode& key, const ValueDesc& value);
void appendForce(const KeyDesc& key, const ValueDesc& value);
Inserts an element at the end.
After the new element is inserted, an old element with the same key is removed if it exists.
const
Element&
element The element to be inserted.
const
KeyNode&
key The key to be inserted.
const
KeyDesc&
key The description of the key to be inserted.
const
ValueNode&
value The value to be inserted.
const
ValueDesc&
value The description of the value to be inserted.
If an error occurs, this object remains untouched.
No changes.
Logarithmic in size.
virtual Iterator insertForce(Iterator pos,
const Element& element);
virtual Iterator insertForce(Iterator pos,
const KeyNode& key, const ValueNode& value);
virtual Iterator insertForce(Iterator pos,
const KeyDesc& key, const ValueNode& value);
virtual Iterator insertForce(Iterator pos,
const KeyNode& key, const ValueDesc& value);
virtual Iterator insertForce(Iterator pos,
const KeyDesc& key, const ValueDesc& value);
Inserts an element before the given position.
After the new element is inserted, an old element with the same key is removed if it exists.
Iterator
pos Position in this object where the new element will be inserted before.
const
Element&
element The element to be inserted.
const
KeyNode&
key The key to be inserted.
const
KeyDesc&
key The description of the key to be inserted.
const
ValueNode&
value The value to be inserted.
const
ValueDesc&
value The description of the value to be inserted.
Iterator
Iterator to the inserted element.
If an error occurs, this object remains untouched.
No changes.
Logarithmic in size.
virtual void merge(const ObjectDesc& patch);
virtual void merge(const ObjectNode& patch);
Merges a patch object into this object.
This function follows the processing rules of JSON Merge Patch (RFC 7386), which is described in the following pseudo-code:
merge(patch)
{
for each key/value pair in patch
{
if value is null
{
if key exists in this {
remove the key/value pair from this
}
}
else if value is object
{
if this[key] is not object {
this[key] = empty object
}
this[key].merge(value)
}
else
{
this[key] = value
}
}
}
const
ObjectDesc&
patch The description of the patch object.
const
ObjectNode&
patch The patch object.
If an error occurs, this object remains untouched.
No changes.
Linear in the number of elements of the patch.
virtual void remove(Iterator pos);
virtual size_t remove(Iterator first, Iterator last);
virtual bool remove(cstring key);
Removes specified elements.
Iterator
pos Iterator to the element to be removed.
Iterator
first, last Range of elements to be removed.
cstring key Key of the element to be removed.
size_t
Number of removed elements.
bool
true if an element was removed, false otherwise.
Iterators referring to removed elements are invalidated.
Linear in the number of elements to be removed.
virtual void parse(Context& ctx);
virtual void parse(Context& ctx, ErrorCode& ec);
virtual void parse(InputStream& stream);
virtual void parse(InputStream& stream, ErrorCode& ec);
virtual void parse(cstring str);
virtual void parse(cstring str, ErrorCode& ec);
virtual void parse(std::istream& stream);
virtual void parse(std::istream& stream, ErrorCode& ec);
virtual void parse(const std::string& str);
virtual void parse(const std::string& str, ErrorCode& ec);
virtual void parse(const char* str);
virtual void parse(const char* str, ErrorCode& ec);
Parses an Eclog text and replaces elements with the parsing result.
Context&
ctx The parsing context.
InputStream&
stream The input stream to be parsed.
cstring str The text string to be parsed.
std::istream&
stream The input stream to be parsed.
const std::string&
str The text string to be parsed.
const char*
str The text string to be parsed.
ErrorCode&
ec Set to indicate what error occurred, if any.
If an error occurs, this object remains untouched.
All iterators related to this object are invalidated, except the end iterators.
virtual void render(OutputStream& stream) const;
virtual void render(OutputStream& stream, ErrorCode& ec) const;
virtual void render(OutputStream& stream, const RendererConfig& rc) const;
virtual void render(OutputStream& stream, const RendererConfig& rc, ErrorCode& ec) const;
virtual void render(std::ostream& stream) const;
virtual void render(std::ostream& stream, ErrorCode& ec) const;
virtual void render(std::ostream& stream, const RendererConfig& rc) const;
virtual void render(std::ostream& stream, const RendererConfig& rc, ErrorCode& ec) const;
Renders this object and outputs the Eclog text result to the given output stream.
OutputStream&
stream The output stream to write to.
std::ostream&
stream The output stream to write to.
const
RendererConfig&
rc The renderer configuration.
ErrorCode&
ec Set to indicate what error occurred, if any.
std::string toStdString() const;
std::string toStdString(ErrorCode& ec) const;
std::string toStdString(const RendererConfig& rc) const;
std::string toStdString(const RendererConfig& rc, ErrorCode& ec) const;
Renders this object and returns the Eclog text result as a C++ string.
const
RendererConfig&
rc The renderer configuration.
ErrorCode&
ec Set to indicate what error occurred, if any.
std::string
The Eclog text result.
virtual void assign(const ObjectDesc& desc);
virtual void assign(const ObjectNode& other);
Assigns new elements to this object, replacing its current elements.
const
ObjectDesc&
desc An object description.
const
ObjectNode&
other Another object.
If an error occurs, this object remains untouched.
All iterators related to this object are invalidated, except the end iterators.
Linear in the number of elements to be removed and to be copied.