Skip to content

Latest commit

 

History

History
453 lines (265 loc) · 10.4 KB

ArrayNode.md

File metadata and controls

453 lines (265 loc) · 10.4 KB

ArrayNode

class ArrayNode

Inherited from: ValueNode.

Required header: <Eclog/ArrayNode.h>

The ArrayNode abstract class represents an array node in a document tree (See Document).

Member classes

Name Description
Element Provides an interface for accessing an element (value) in the array.
Iterator Provides a STL-style random-access iterator for the array.
ConstIterator Provides a STL-style const random-access iterator for the array.

Member functions

Name Description
clear Removes all elements.
empty Checks if this array 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 Gets the first element.
last Gets the last element.
indexOf Gets the index of the specified element.
at Gets an element by index.
getValue Gets a value by index.
getNull Gets a null value by index.
getBoolean Gets a Boolean value by index.
getString Gets a string value by index.
getNumber Gets a number value by index.
getObject Gets an object value by index.
getArray Gets an array value by index.
append Inserts an element at the end.
insert Inserts an element before the given position.
remove Removes specified elements.
assign Assigns new elements to this array.

clear

virtual void clear();

Removes all elements.

Iterator validity

All iterators and pointers related to this array are invalidated.

Complexity

Linear in the number of elements to remove.


empty

virtual bool empty() const;

Checks if this array is empty.

Return value

bool true if this array is empty, false otherwise.

Complexity

Constant.


size

virtual size_t size() const;

Returns the number of elements.

Return value

size_t Number of elements in this array.

Complexity

Constant.


begin

virtual Iterator begin();
virtual ConstIterator begin() const;

Returns an iterator to the first element.

If this array is empty, the returned iterator will be equal to end.

Return value

Iterator Iterator to the first element.

ConstIterator Iterator to the first element.

Complexity

Constant.


end

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.

Return value

Iterator Iterator to the past-the-end element.

ConstIterator Iterator to the past-the-end element.

Complexity

Constant.


first

Element& first();
const Element& first() const;

Gets the first element.

Return value

Element& Reference to the first element.

const Element& Reference to the first element.

Errors

An OutOfRange fault occurs if this array is empty.

Complexity

Constant.


last

Element& last();
const Element& last() const;

Gets the last element.

Return value

Element& Reference to the last element.

const Element& Reference to the last element.

Errors

An OutOfRange fault occurs if this array is empty.

Complexity

Constant.


indexOf

virtual size_t indexOf(const Element& element) const;

Gets the index of the specified element.

Parameters

const Element& element An element in this array.

Return value

size_t Index of the specified element.

Complexity

Constant.


at

virtual Element& at(size_t index);
virtual const Element& at(size_t index) const;

Gets an element by index.

Parameters

size_t index Index of the element.

Return value

Element& Reference to the element.

const Element& Reference to the element.

Errors

An OutOfRange fault occurs if the specified index is out of bound.

Complexity

Constant.


getValue

ValueNode& getValue(size_t index);
const ValueNode& getValue(size_t index) const;

Gets a value by index.

Parameters

size_t index Index of the element.

Return value

ValueNode& Reference to the value node.

const ValueNode& Reference to the value node.

Errors

An OutOfRange fault occurs if the specified index is out of bound.

Complexity

Constant.


getNull, getBoolean, getString, getNumber, getObject, and getArray

NullNode& getNull(size_t index);
const NullNode& getNull(size_t index) const;

BooleanNode& getBoolean(size_t index);
const BooleanNode& getBoolean(size_t index) const;

StringNode& getString(size_t index);
const StringNode& getString(size_t index) const;

NumberNode& getNumber(size_t index);
const NumberNode& getNumber(size_t index) const;

ObjectNode& getObject(size_t index);
const ObjectNode& getObject(size_t index) const;

ArrayNode& getArray(size_t index);
const ArrayNode& getArray(size_t index) const;

Gets a value by index and casts the value to a specific type.

Parameters

size_t index Index of the element.

Return value

(value node type)& Reference to the value node.

const (value node type)& Reference to the value node.

Errors

An OutOfRange fault occurs if the specified index is out of bound.

A BadCast fault occurs if the value node is not of the specified type.

Complexity

Constant.


append

void append(const Element& element);
void append(const ValueNode& value);
void append(const ValueDesc& value);

Inserts an element at the end.

Parameters

const Element& element The element to be inserted.

const ValueNode& value The value to be inserted.

const ValueDesc& desc The description of the value to be inserted.

Errors

If an error occurs, this array remains untouched.

Iterator validity

If a reallocation happens, all iterators related to this array are invalidated.

Complexity

Amortized constant.


insert

virtual Iterator insert(Iterator pos, const Element& element);
virtual Iterator insert(Iterator pos, const ValueNode& value);
virtual Iterator insert(Iterator pos, const ValueDesc& value);

Inserts an element before the given position.

Parameters

Iterator pos Position in this array where the new element will be inserted before.

const Element& element The element to be inserted.

const ValueNode& value The value to be inserted.

const ValueDesc& desc The description of the value to be inserted.

Return value

Iterator Iterator to the inserted element.

Errors

If an error occurs, this array remains untouched.

Iterator validity

If a reallocation happens, all iterators related to this array are invalidated; otherwise, all iterators to elements before the given position will remain valid.

Complexity

Constant plus linear in the distance between the given position and the end of the container.


remove

virtual void remove(Iterator pos);
virtual void remove(Iterator first, Iterator last);
virtual void remove(size_t index);
virtual void remove(size_t index, size_t count);

Removes specified elements.

Parameters

Iterator pos Iterator to the element to be removed.

Iterator first, last Range of elements to be removed.

size_t index Index of the element to be removed.

size_t count Number of elements to be removed.

Iterator validity

Iterators to removed elements and subsequent elements are invalidated.

Complexity

Linear in the number of elements to be removed.


assign

virtual void assign(const ArrayDesc& desc);
virtual void assign(const ArrayNode& other);

Assigns new elements to this array, replacing its current elements.

Parameters

const ArrayDesc& desc An array description.

const ArrayNode& other Another array.

Errors

If an error occurs, this array remains untouched.

Iterator validity

All iterators related to this array are invalidated.

Complexity

Linear in the number of elements to be removed and to be copied.