Class CNodeCollection#

Inheritance Relationships#

Base Types#

Derived Types#

Class Documentation#

class CNodeCollection : public toml_parser::CNode, public sdv::toml::INodeCollection, public sdv::toml::INodeCollectionInsert#

Base structure for arrays and tables.

Subclassed by toml_parser::CArray, toml_parser::CTable

Public Functions

virtual uint32_t GetCount() const override#

Returns the amount of nodes. Overload of sdv::toml::INodeCollection::GetCount.

Returns:

The amount of nodes.

virtual IInterfaceAccess *GetNode(uint32_t uiIndex) const override#

Get the node. Overload of sdv::toml::INodeCollection::GetNode.

Parameters:

uiIndex[in] Index of the node to get.

Returns:

Interface to the node object.

std::shared_ptr<CNode> Get(uint32_t uiIndex) const#

Get the node.

Parameters:

uiIndex[in] Index of the node to get.

Returns:

Smart pointer to the node object.

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

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

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!

Attention

For an array, when no indexing is supplied, the latest entry will be returned.

Parameters:

rssPath[in] 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 sdv::IInterfaceAccess *GetNodeDirect(const sdv::u8string &ssPath) const override#

Searches a node by its key in the parse tree.

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:

ssPath[in] The path of the node to searched for.

Returns:

Returns an interface the requested node if available.

virtual sdv::IInterfaceAccess *InsertValue(uint32_t uiIndex, const sdv::u8string &ssName, sdv::any_t anyValue) override#

Insert a value into the collection at the location before the supplied index. Overload of sdv::toml::INodeCollectionInsert::InsertValue.

Parameters:
  • uiIndex[in] The insertion location to insert the node before. Can be npos or any value larger than the collection count to insert the node at the end of the collection. Value nodes cannot be inserted behind external tables and table arrays. If the index is referencing a position behind an external table or a table array, the index is automatically corrected.

  • ssName[in] Name of the node to insert. Will be ignored for an array collection. The name must adhere to the key names defined by the TOML specification. Defining the key multiple times is not allowed. Quotation of key names is done automatically; the parser decides itself whether the key is bare-key, a literal key or a quoted key.

  • anyValue[in] The value of the node, being either an integer, floating point number, boolean value or a string. Conversion is automatically done to int64, double float, bool or u8string.

Returns:

On success the interface to the newly inserted node is returned or NULL otherwise.

virtual sdv::IInterfaceAccess *InsertArray(uint32_t uiIndex, const sdv::u8string &ssName) override#

Insert an array into the collection at the location before the supplied index. Overload of sdv::toml::INodeCollectionInsert::InsertArray.

Parameters:
  • uiIndex[in] The insertion location to insert the node before. Can be npos or any value larger than the collection count to insert the node at the end of the collection. Array nodes cannot be inserted behind external tables and table arrays. If the index is referencing a position behind an external table or a table array, the index is automatically corrected.

  • ssName[in] Name of the array node to insert. Will be ignored if the current node is also an array collection. The name must adhere to the key names defined by the TOML specification. Defining the key multiple times is not allowed. Quotation of key names is done automatically; the parser decides itself whether the key is bare-key, a literal key or a quoted key.

Returns:

On success the interface to the newly inserted node is returned or NULL otherwise.

virtual sdv::IInterfaceAccess *InsertTable(uint32_t uiIndex, const sdv::u8string &ssKeyName) override#

Insert a table into the collection at the location before the supplied index. Overload of sdv::toml::INodeCollectionInsert::InsertTable.

Parameters:
  • uiIndex[in] The insertion location to insert the node before. Can be npos or any value larger than the collection count to insert the node at the end of the collection. Table nodes cannot be inserted before value nodes or arrays. If the index is referencing a position before a value node or an array, the index is automatically corrected.

  • ssKeyName[in] Name of the table node to insert. Will be ignored if the current node is an array collection. The name must adhere to the key names defined by the TOML specification. Defining the key multiple times is not allowed. Quotation of key names is done automatically; the parser decides itself whether the key is bare-key, a literal key or a quoted key.

Returns:

On success the interface to the newly inserted node is returned or NULL otherwise.

virtual sdv::IInterfaceAccess *InsertTableArray(uint32_t uiIndex, const sdv::u8string &ssName) override#

Insert a table array into the collection at the location before the supplied index. Overload of sdv::toml::INodeCollectionInsert::InsertTableArray.

Parameters:
  • uiIndex[in] The insertion location to insert the node before. Can be npos or any value larger than the collection count to insert the node at the end of the collection. Table array nodes cannot be inserted before value nodes or arrays. If the index is referencing a position before a value node or an array, the index is automatically corrected.

  • ssName[in] Name of the array node to insert. Will be ignored if the current node is also an array collection. The name must adhere to the key names defined by the TOML specification. Defining the key multiple times is not allowed. Quotation of key names is done automatically; the parser decides itself whether the key is bare-key, a literal key or a quoted key.

Returns:

On success the interface to the newly inserted node is returned or NULL otherwise.

virtual sdv::toml::INodeCollectionInsert::EInsertResult InsertTOML(const sdv::u8string &ssTOML, bool bRollbackOnPartly) override#

Insert a TOML string as a child of the current collection node. If the collection is a table, the TOML string should contain values and inline/external/array-table nodes with names. If the collection is an array, the TOML string should contain and inline table nodes without names. Overload of sdv::toml::INodeCollectionInsert::InsertTOML.

Parameters:
  • ssTOML[in] The TOML string to insert.

  • bRollbackOnPartly[in] If only part of the nodes could be inserted, no node will be inserted.

Returns:

The result of the insertion.

virtual bool DeleteNode() override#

Delete the current node. Overload of sdv::toml::INodeDelete::DeleteNode.

Attention

A successful deletion will cause all interfaces to the current node to become inoperable.

Returns:

Returns whether the deletion was successful.

bool RemoveNode(const std::shared_ptr<CNode> &rptrNode)#

Remove a node from the collection.

Remark

The node will not be deleted, but placed in the recycle bin. Deletion will take place at collection destruction.

Parameters:

rptrNode[in] Reference to the smart pointer pointing to the node to remove.

Returns:

Returns whether the removal was successful.

bool RemoveFromView(const std::shared_ptr<CNode> &rptrNode)#

Remove a node from a view.

Parameters:

rptrNode[in] Reference to the smart pointer pointing to the node to remove.

Returns:

Returns whether the removal was successful.

bool CheckLast(const std::shared_ptr<CNode> &rptrNode)#

Check whether this node is the last node in the collection.

Parameters:

rptrNode[in] Reference to the smart pointer pointing to the node to check for.

Returns:

Returns whether the provided node is the last node in the collection.

uint32_t FindIndex(const std::shared_ptr<CNode> &rptrNode)#

Find the index belonging to the provided node.

Parameters:

rptrNode[in] Reference to the smart pointer holding the node to return the index for.

Returns:

Return the node index. Returns npos if the node could not be found.

template<typename TNodeType, typename ...TArgs>
inline std::shared_ptr<CNode> Insert(uint32_t uiIndex, const CTokenRange &rrangeKeyPath, const TArgs&... rtArgs)#

Generic inserting function for nodes.

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’.

Remark

If the node to insert exists already, but is marked implicit, the node will be returned and made explicit. In all other cases the an error will occur that the node already exists.

Attention

Array indexing starts with 0!

Attention

For an array, when no indexing is supplied, the latest entry will be returned.

Parameters:
  • uiIndex[in] The insertion location to insert the node before. Can be npos or any value larger than the collection count to insert the node at the end of the collection. Table array nodes cannot be inserted before value nodes or arrays. If the index is referencing a position before a value node or an array, the index is automatically corrected.

  • rrangeKeyPath[in] Reference to the token range containing the path to the node to insert.

  • rtArgs[in] Zero or more references to arguments passed to the constructor of the node classes being created by this function.

Returns:

Returns a shared pointer to the inserted node. This node is of the requested type, except with table arrays; there the returned node is a table within the table array.

Protected Functions

CNodeCollection(CParser &rparser, const std::string &rssName, const std::string &rssRawName)#

Constructor.

Parameters:
  • rparser[in] Reference to the TOML parser.

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

  • rssRawName[in] Reference to the raw name of the node.