Class CArray#
Defined in File parser_node_toml.h
Inheritance Relationships#
Base Type#
public toml_parser::CNodeCollection(Class CNodeCollection)
Derived Type#
public toml_parser::CTableArray(Class CTableArray)
Class Documentation#
-
class CArray : public toml_parser::CNodeCollection#
A dynamic array structure that allows mixed data of multiple values to be assigned to one key.
In most cases an array is inline and is defined similar to value assignments. The table array (an array consisting) only of tables can also be defined as an explicit array as well. Two versions of the inline array exist: the assignment version and the embedded in-an-array-version. Explicit table array:
Not embedded in an array, but inline:<whitespace>[[<whitespace>KEY<whitespace>]]<whitespace> ^ ^ ^ ^ pre-node pre_key_ws post_key_ws post_node
Embedded in an array:<whitespace>KEY<whitespace>.<whitespace>KEY<whitespace>=<whitespace>[ZERO_OR_MORE_VALUES,<whitespace>]<whitespace> ^ ^ ^ ^ ^ ^ ^ pre-node post_key_ws pre_key_ws post_key_ws pre_value_ws post_values post-node
The pre- and post-node whitespace areas are covered by the UpdateNodeCode function of the CNode base class. Multiple optional pre- and post-separator whitespace areas can be defined.<whitespace>[ZERO_OR_MORE_VALUES,<whitespace>]<whitespace> ^ ^ ^ pre-node post_values post-node
Subclassed by toml_parser::CTableArray
Public Functions
-
CArray(CParser &rparser, const std::string &rssName, const std::string &rssRawName, bool bExplicitTableArray = false)#
Constructor.
Remark
If the array is not defined as explicit table array, the array will be inline.
- 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.
bExplicitTableArray – [in] When set, the array is defined as explicit table array. In this case, the array will not be inline and needs at least one child-table.
-
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> 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’.
Remark
The definition of an array in TOML differentiate from the syntax to access the elements. For example an array in TOML could be defined by:
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 Direct function uses the syntax similar to C++:integers = [ 1, 2, 3 ] nested_mixed_array = [ [ 1, 2 ], ["a", "b", "c"] ] [[products]] name = "Hammer" sku = 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] --> gives: 2 nested_mixed_array[1][2] --> gives: "c" products[0].sku --> gives: 738594937
integers.1 --> stores: 2 nested_mixed_array.1.2 --> stores: "c" products.0.sku --> stores: 738594937
- Attention
Array element access indices starts with 0!
- Attention
For an array element inserting, when no indexing is supplied, the latest entry will be returned.
- 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 GenerateTOML(const CGenContext &rContext = CGenContext()) const override#
Create the TOML text based on the content using an optional prefix node. Overload of CNode::GenerateTOML.
- Parameters:
rContext – [in] Reference to the context class to use during TOML code generation.
- Returns:
Return the TOML text string.
-
virtual void UpdateNodeCode(const CNodeTokenRange &rNodeRange) override#
Update the node with TOML code information. Overload of CNode::UpdateNodeCode.
- Parameters:
rNodeRange – [in] Reference to the node range information containing the tokens for the code snippets.
-
bool TableArray() const#
Returns whether the array is defined as a table array (array with only tables and at least one table).
Remark
Table arrays can still be inline.
- Returns:
Returns whether the array is a table array.
-
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) override#
Allow switching between the inline array and a table array. Overload of CNode::Inline.
Most array definitions are inline. An exception to the rule is a table array, which is allowed to be explicit as well. To switch from inline array to an explicit array, at least one member needs to be present and all members need to be tables.
Remark
Additional node composition information will be removed and the order within the parent node might be changed.
- Attention
It is not possible to switch to an explicit array when the array is part of another array, since the atray doesn’t have a name that can be used to define the explicit table array.
- Parameters:
bInline – [in] When set, try to switch to inline. Otherwise try to switch to normal.
- 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.
-
CArray(CParser &rparser, const std::string &rssName, const std::string &rssRawName, bool bExplicitTableArray = false)#