Class CNodeCollection#
Defined in File parser_node_toml.h
Inheritance Relationships#
Base Types#
public toml_parser::CNode(Class CNode)public sdv::toml::INodeCollection(Struct INodeCollection)public sdv::toml::INodeCollectionInsert(Struct INodeCollectionInsert)public sdv::toml::INodeCollectionConvert(Struct INodeCollectionConvert)
Derived Types#
public toml_parser::CArray(Class CArray)public toml_parser::CTable(Class CTable)
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(bool bRemoveComments) override#
Format the node automatically, remove redundant whitespace. Overload of sdv::toml::INodeInfo::AutomaticFormat.
- Parameters:
bRemoveComments – [in] When set, the comments are removed from the node.
-
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.
-
virtual 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 void RebuildNodeOrder(bool bForce)#
After every insert, deletion and shift, the node order of this and all sub- tables need to be rebuild.
- Parameters:
bForce – [in] Force rebuild, even if locked.
After every insert, deletion and shift, the node order needs to be rebuild.
Adding is done iteratively through the node list. In case the top level flag is set, all nodes are added that are marked explicit or if a node is implicit, the explicit sub-nodes are added. In case this is root view, all sub-nodes which are standard tables or standard table arrays are added. This flattens the hierarchy. When the root view is not set, only the tables and table arrays are added that are a direct child of the node collection. At the end of building the root view, the nodes are sorted using their index. Furthermore, inline nodes are moved to the beginning of the vector and standard nodes to the end.
- Parameters:
rvecNodes – [inout] Reference to the vector being filled with the nodes for the view.
bRootView – [in] Set when the count is top level.
bTopLevel – [in] Set when this is the top level node for adding sub nodes.
-
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 std::pair<std::shared_ptr<CNodeCollection>, std::string> SmartParentCreate(const std::string &rssPath, bool bInsertTableArray = false)#
Get or create the parent nodes automotatically from the path.
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 or a too large index number is supplied, a new entry will be created and returned.
- Parameters:
rssPath – [in] The path of the node to searched for.
bInsertTableArray – [in] Since a table array consists of an array and a table, this is different than the other insertions that only insert one element. Some special treatment is needed at certain points.
- Returns:
Returns a pair with the shared pointer to the parent node and the leftover name. If the creation could not be done, a NULL pointer is returned.
-
virtual sdv::IInterfaceAccess *InsertValue(const sdv::u8string &ssInsertBefore, 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.
Remark
In TOML, inline nodes are located before standard nodes. Since values are presented as inline node, they will be inserted before any standard node (table or table array if defined as standard node).
- Parameters:
ssInsertBefore – [in] Name of the node to insert the value before. In case of an array, can be an index between square brackets. Can be empty, causing the node to be inserted at the end.
ssName – [in] Name of the node to insert. This name can contain parent nodes, which are automatically created if not existing. With arrays, since the value in TOML doesn’t have a name, the name of the value must be an empty string and any names provided are considered parent nodes. 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(const sdv::u8string &ssInsertBefore, const sdv::u8string &ssName) override#
Insert an array into the collection at the location before the supplied index. Overload of sdv::toml::INodeCollectionInsert::InsertArray.
Remark
In TOML, inline nodes are located before standard nodes. Since arrays are presented as inline node, they will be inserted before any standard node (table or table array if defined as standard node).
- Parameters:
ssInsertBefore – [in] Name of the node to insert the value before. In case of an array, can be an index between square brackets. Can be empty, causing the node to be inserted at the end.
ssName – [in] Name of the node to insert. This name can contain parent nodes, which are automatically created if not existing. With arrays, since the value in TOML doesn’t have a name, the name of the value must be an empty string and any names provided are considered parent nodes. 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(const sdv::u8string &ssInsertBefore, const sdv::u8string &ssName, sdv::toml::EInsertPreference ePreference) override#
Insert a table into the collection at the location before the supplied index. Overload of sdv::toml::INodeCollectionInsert::InsertTable.
Remark
In TOML, inline nodes are located before standard nodes. Tables can be inserted as inline node, in which case they will be inserted before any standard node (table or table array if defined as standard node).
- Parameters:
ssInsertBefore – [in] Name of the node to insert the value before. In case of an array, can be an index between square brackets. Can be empty, causing the node to be inserted at the end.
ssName – [in] Name of the node to insert. This name can contain parent nodes, which are automatically created if not existing. With arrays, since the value in TOML doesn’t have a name, the name of the value must be an empty string and any names provided are considered parent nodes. 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(const sdv::u8string &ssInsertBefore, const sdv::u8string &ssName, sdv::toml::EInsertPreference ePreference) override#
Insert a table array into the collection at the location before the supplied index. Overload of sdv::toml::INodeCollectionInsert::InsertTableArray.
Remark
In TOML, inline nodes are located before standard nodes. Table arrays can be inserted as inline node, in which case they will be inserted before any standard node (table or table array if defined as standard node).
- Parameters:
ssInsertBefore – [in] Name of the node to insert the value before. In case of an array, can be an index between square brackets. Can be empty, causing the node to be inserted at the end.
ssName – [in] Name of the node to insert. This name can contain parent nodes, which are automatically created if not existing. With arrays, since the value in TOML doesn’t have a name, the name of the value must be an empty string and any names provided are considered parent nodes. 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(const sdv::u8string &ssInsertBefore, 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.
Remark
In TOML, inline nodes are located before standard nodes. Dependable on the nodes defined in the TOML they might be transferred to inline or they might be inserted at a different location.
- Parameters:
ssInsertBefore – [in] Name of the node to insert the value before. In case of an array, can be an index between square brackets. Can be empty, causing the node to be inserted at the end.
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.
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.
- Parameters:
rptrInsertBefore – [in] The node to insert the TOML nodes before (if possible). Can be NULL, causing the TOML nodes to be inserted at the end.
ssTOML – [in] The TOML string to insert.
bRollbackOnPartly – [in] If only part of the nodes could be inserted, no node will be inserted.
- Returns:
A pair structure with the result of the insertion and a vector of all the inserted nodes.
-
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 Inline() const override#
The derived class from the node collection can be inline or not. Overload of CNode::Inline.
- Returns:
Returns whether the node is an inline node.
-
virtual bool Inline(bool bInline, bool bIncludeChildren = true) override#
With some node collections it is possible to switch between inline and normal. Overload of CNode::Inline.
Remark
Additional node composition information will be removed and the order within the parent node might be changed.
- Parameters:
bInline – [in] When set, try to switch to inline. Otherwise try to switch to normal.
bIncludeChildren – [in] When set and bInline is not set, applicable child nodes are converted as well (only tables and table-arrays can be defined as standard). Making a node inline is always including the children.
- Returns:
Returns whether the switch was successful. A switch to the same type (normal to normal or inline to inline is always successful). When returning false, the switching might not be supported for this type.
-
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(bool bIncludeChildren) override#
Convert the node to a standard node. Overload of sdv::toml::INodeCollectionConvert::MakeStandard.
- Parameters:
bIncludeChildren – [in] When set, applicable child nodes are made are converted to standard nodes as well (only tables and table-arrays can be defined as standard).
- Returns:
Returns whether the conversion was successful. Returns ‘true’ when the node was already defined as standard node.
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.
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.
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.
Generic add 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:
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.
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.
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.
-
virtual void ReassignParser(CParser &rParser) override#
When the parent changes (e.g. when moving items from one parser to the other), the items and all its sub-items need to reasign the parser. Overload of CNode::ReassignParser.
- Parameters:
rParser – [in] Reference to the parser to assign.
-
virtual void AutomaticFormat(bool bRemoveComments) override#