Class CNodeCollection#

Inheritance Relationships#

Base Types#

Derived Types#

Class Documentation#

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

Base structure for arrays and tables.

Subclassed by toml_parser::CArray, toml_parser::CTable

Public Functions

virtual void AutomaticFormat() override#

Format the node automatically. This will remove the whitespace between the elements within the node. Comments will not be changed. Overload of sdv::toml::INodeInfo::AutomaticFormat.

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, virtual bool 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 &ssName, sdv::toml::INodeCollectionInsert::EInsertPreference ePreference) 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.

  • ssName[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.

  • ePreference[in] The preferred form of the node to be inserted.

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, sdv::toml::INodeCollectionInsert::EInsertPreference ePreference) 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.

  • ePreference[in] The preferred form of the node to be inserted.

Returns:

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

virtual sdv::toml::INodeCollectionInsert::EInsertResult InsertTOML(uint32_t uiIndex, 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:
  • 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.

  • 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::INodeUpdate::DeleteNode.

Attention

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

Returns:

Returns whether the deletion was successful.

virtual bool CanMakeInline() const override#

Can the node convert to an inline definition? Overload of sdv::toml::INodeCollectionConvert::CanMakeInline.

Returns:

Returns whether the conversion to inline is possible. Returns ‘true’ when the node is already inline.

virtual bool MakeInline() override#

Convert the node to an inline node. Overload of sdv::toml::INodeCollectionConvert::MakeInline.

Returns:

Returns whether the conversion was successful. Returns ‘true’ when the node was already inline.

virtual bool CanMakeStandard() const override#

Can the node convert to a standard definition? Overload of sdv::toml::INodeCollectionConvert::CanMakeStandard.

Returns:

Returns whether the conversion to standard is possible. Returns ‘true’ when the node is already defined as standard node.

virtual bool MakeStandard() override#

Convert the node to a standard node. Overload of sdv::toml::INodeCollectionConvert::MakeStandard.

Returns:

Returns whether the conversion was successful. Returns ‘true’ when the node was already defined as standard node.

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

Delete 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 InsertIntoView(uint32_t uiIndex, const std::shared_ptr<CNode> &rptrNode)#

Insert the node into the view.

Insert the node into the vector (and remove it from any previous vector if still assigned). Inline nodes can be assigned to stadard and inline nodes. Standard nodes can only be assigned to standard nodes. In the vector, first the inline nodes and then the standard nodes are located. This means that an inline node will be placed before standard nodes and standard nodes behind inline nodes, regardless of the index provided.

Remark

The node must be a descendant (direct child or an indirect child) of the node.

Parameters:
  • uiIndex[in] Location within the vector to insert the node. Could be sdv::toml::npos to insert as last node.

  • rptrNode[in] Reference to the smart pointer to the node to set the view for. If the node is not a direct child node, the view pointer of the node will be set.

Returns:

Returns true when the insertion was successful, false when node (likely because the node to insert is a standard node, whereas this node is an inline node.

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.

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

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.

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

Is the provided child node a direct or indirect child node?

Parameters:

rptrNode[in] Reference to the smart pointer of the potential descendant node.

Returns:

Returns whether the provided node is a descendant of the this node.

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.

virtual bool Combine(const std::shared_ptr<CNodeCollection> &rptrCollection) = 0#

Combine the collection with the provided content (mathematical union).

Update the child nodes with the child nodes of the provided collection. Extend the collection with nodes that do not exist and update the existing nodes with new values.

Parameters:

rptrCollection[in] Reference to the collection being used for this operation.

Returns:

Returns whether the combination was successful.

virtual bool Reduce(const std::shared_ptr<CNodeCollection> &rptrCollection) = 0#

Reduce the collection with by the provided content (mathematical difference).

Reduce the child node with the child nodes already defined and identical in the provided collection. Different nodes or nodes that are not present in the collection remain.

Parameters:

rptrCollection[in] Reference to the collection being used for this operation.

Returns:

Returns whether the reduction was successful.

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.