Class CArray#

Inheritance Relationships#

Base Type#

Derived Types#

Class Documentation#

class CArray : public CNodeCollection#

A dynamic array structure that allows mixed data.

The definition of an array in TOML differentiate massively from the syntax to access the elements. For example an array in TOML could be defined by:

integers = [ 1, 2, 3 ]
nested_mixed_array = [ [ 1, 2 ], ["a", "b", "c"] ]
[[products]]
name = "Hammer"
sku = 738594937
The first two examples define the complete array at once. The third example defines one element to be added to an array. Random access to previous definitions is not required. The access functions need random access to each element. The GetDirect function uses the syntax similar to C++:
integers[1]                  --> gives: 2
nested_mixed_array[1][2]     --> gives: "c"
products[0].sku              --> gives: 738594937
To find array elements, the path names are composed of elements separated by a dot. The Add and Find functions use the following syntax:
integers.1                   --> stores: 2
nested_mixed_array.1.2       --> stores: "c"
products.0.sku               --> stores: 738594937

Subclassed by CNormalArray, CTableArray

Public Functions

virtual sdv::toml::ENodeType GetType() const override#

Get the node type. Overload of sdv::toml::INodeInfo::GetType.

Returns:

Type of the node.

virtual std::shared_ptr<CNode> GetDirect(const std::string &rssPath) const override#

Accesses a node by its key in the parse tree. Overload of CNode::GetDirect.

Elements of tables can be accessed and traversed by using ‘.’ to separated the parent name from child name. E.g. ‘parent.child’ would access the ‘child’ element of the ‘parent’ table. Elements of arrays can be accessed and traversed by using the index number in brackets. E.g. ‘array[3]’ would access the fourth element of the array ‘array’. These access conventions can also be chained like ‘table.array[2][1].subtable.integerElement’.

Attention

Array indexing starts with 0!

Parameters:

rssPath[in] Reference to the path of the node to searched for.

Returns:

Returns a shared pointer to the wanted Node if it was found or a node with invalid content if it was not found.

virtual std::string CreateTOMLText(const std::string &rssParent, std::string &rssLastPrintedTable, bool bFirst, bool bEmbedded, bool bAssignment, bool bRoot) const override#

Get the TOML text based on the content. Overload of CNode::CreateTOMLText.

Parameters:
  • rssParent[in] When present, uses the parent node into the TOML text generation.

  • rssLastPrintedTable[in] Reference to the string containing the last printed table. This might be necessary in case a different table was printed in between.

  • bFirst[in] When set, this is the first entry in an array or table.

  • bEmbedded[in] When set, this is an embedded definition in an array or table.

  • bAssignment[in] When set, this is a table assignment.

  • bRoot[in] Only for table entries, when set this is the root entry (suppress the table name).

Returns:

The string containing the TOML text.

virtual void Add(const std::string &rssPath, const std::shared_ptr<CNode> &rptrNode, bool bDefinedExplicitly) override#

Adds a given node to a given path in the tree. Overload of CNode::Add.

Parameters:
  • rssPath[in] Reference to the path in the tree where the new node is to be added.

  • rptrNode[in] Reference top the smart pointer holding the node.

  • bDefinedExplicitly[in] If a table that is created to create the path of the node to be added is defined explicitly

Throws:
  • XInvalidAccessException – Throws an XInvalidAccessException if a ancestor node is not open to add children

  • XDuplicateNameException – Throws a XDuplicateNameException if a node with the same path as the node to be added is already defined explicitly

virtual std::shared_ptr<CNode> Find(const std::string &rssPath) const override#

Searches the subtree of the node for a node at the given location using the provided path. Overload of CNode::Find.

Remark

The path elements of arrays and tables are separated by a dot.

Parameters:

rssPath[in] Reference to the path of the node to find.

Returns:

Returns a shared pointer to the wanted Node if it is found or an error-Node if it is not

Protected Functions

CArray(const std::string &rssName)#

Constructor.

Parameters:

rssName[in] Reference to the name of the node.