Class CNode#
Defined in File parser_node_toml.h
Nested Relationships#
Nested Types#
Inheritance Relationships#
Base Types#
public std::enable_shared_from_this< CNode >public sdv::IInterfaceAccess(Struct IInterfaceAccess)public sdv::toml::INodeInfo(Struct INodeInfo)public sdv::toml::INodeDelete(Struct INodeDelete)public sdv::toml::INodeUpdate(Struct INodeUpdate)
Derived Types#
public toml_parser::CNodeCollection(Class CNodeCollection)public toml_parser::CValueNode(Class CValueNode)
Class Documentation#
-
class CNode : public std::enable_shared_from_this<CNode>, public sdv::IInterfaceAccess, public sdv::toml::INodeInfo, public sdv::toml::INodeDelete, public sdv::toml::INodeUpdate#
Node to build up the parse tree.
Subclassed by toml_parser::CNodeCollection, toml_parser::CValueNode
Unnamed Group
Public Functions
-
~CNode()#
Destroy the node object.
-
CParser &Parser()#
Get a reference to the TOML parser that generated this node.
- Returns:
Reference to the TOML parse.
-
virtual sdv::u8string GetName() const override#
Get the node name (no conversion to a literal or quoted key is made). Overload of sdv::toml::INodeInfo::GetName.
- Returns:
String containing the name of the node.
-
virtual sdv::u8string GetPath(bool bResolveArrays) const override#
Get the node path following the key rules for bar, literal and quoted keys. Overload of sdv::toml::INodeInfo::GetPath.
- Parameters:
bResolveArrays – [in] When set, include array indices in the path. The path returned without array indices is identical to the code in the TOML file. The path returned with array indices is identical to the direct access of nodes within the parser.
- Returns:
String containing the path of the node.
-
std::list<std::pair<std::string, std::string>> GetRawPath(bool bResolveArrays) const#
Get the raw node path using the original keys if available.
- Parameters:
bResolveArrays – [in] When set, include array indices in the path. The path returned without array indices is identical to the code in the TOML file. The path returned with array indices is identical to the direct access of nodes within the parser.
- Returns:
List containing the keys pairs for each parent until this node. Each key pair contain the name (first) and the raw name as it was defined (second).
-
virtual sdv::any_t GetValue() const override#
The node value.
- Returns:
For boolean, integer, floating point and strings, the function returns a value. Otherwise the function returns empty.
-
virtual uint32_t GetIndex() const override#
Get the index of this node within the parent collection. Overload of sdv::toml::INodeInfo::GetIndex.
- Returns:
The index of the node within the parent collection node or npos when no parent is available.
-
virtual sdv::IInterfaceAccess *GetParent() const override#
Get the parent collection node. Overload of sdv::toml::INodeInfo::GetParent.
- Returns:
Returns the parent collection node or NULL when there is no parent collection node.
-
virtual sdv::u8string GetTOML() const override#
The node value. Overload of sdv::toml::INodeInfo::GetTOML.
- Returns:
For boolean, integer, floating point and strings, the function returns a value. Otherwise the function returns empty.
-
virtual void SetComment(const sdv::u8string &ssComment, uint32_t uiFlags) override#
Set or replace a comment for the node. Overload of sdv::toml::INodeInfo::SetComment.
Remark
This function can also be used to insert whitespace (with or without comments) when used in raw mode. Set the comment text for the node. If a comment is proided as text (normal behavior), the comment text will be formatted automatically when generating the TOML text. If the comment is provided as raw comment, the text should contain all whitespace and the comment ‘#’ character before the comment text. Comments inserted before the enode will be inserted on the line before the node uness the comment is provided in raw format and is ended with a newline and optionally whitespace. Comment inserted behind the node will be inserted on the same line as the node. Comments provided as text is automatically wrapped to 80 characters if possible. Newlines in the text will cause a new comment line to start.
- Parameters:
ssComment – [in] String containing the comment text or the raw comment string to set.
uiFlags – [in] One or more ECommentFlags flags influencing the behavior of the comment.
-
virtual sdv::u8string GetComment(uint32_t uiFlags) override#
Get the current comment for the node. Overload of sdv::toml::INodeInfo::GetComment.
Remark
To receive the whitespace formatting the node, use this function in raw mode.
- Parameters:
uiFlags – [in] One or more ECommentFlags flags identifying the string format of the comment to return.
- Returns:
String with the comment text or an empty string if no comment is available.
-
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 void UpdateNodeCode(const CNodeTokenRange &rNodeRange)#
Update the node with TOML code information. The default implementation takes the comment and whitespace around the node and stores this for node reconstruction.
- Parameters:
rNodeRange – [in] Reference to the node range information containing the tokens for the code snippets.
-
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 IsDeleted() const#
Is this node marked as deleted?
- Returns:
Returns whether this node has been deleted.
-
virtual bool ChangeName(const sdv::u8string &ssNewName) override#
Change the key name of the node (if the node is not a value node of an array). Overload of sdv::toml::INodeUpdate::ChangeName.
- Parameters:
ssNewName – [in] The name to assign to the node. 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:
Returns whether the name change was successful.
-
virtual bool ChangeValue(sdv::any_t anyNewValue) override#
Change the value of the node. Overload of sdv::toml::INodeUpdate::ChangeValue.
Remark
Only valid for value nodes. Changing the value type is not supported.
- Parameters:
anyNewValue – [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:
Returns whether the value change was successful.
-
virtual bool MoveUp() override#
Move up the node in the collection. Overload of sdv::toml::INodeUpdate::MoveUp.
Remark
External tables or table arrays cannot be moved before value nodes.
Remark
Moving if the node is the first node is not possible.
- Returns:
Returns whether the move was successful.
-
virtual bool MoveDown() override#
Move down the node in the collection. Overload of sdv::toml::INodeUpdate::MoveDown.
Remark
Value nodes cannot be moved behind external tables or table arrays.
Remark
Moving if the node is the last node is not possible.
- Returns:
Returns whether the move was successful.
Do a dynamic cast to one of the base types of the node.
- Returns:
Casted shared pointer to the base type if the type is valid, or an empty pointer if not.
Do a dynamic cast to one of the base types of the node.
- Returns:
Casted shared pointer to the base type if the type is valid, or an empty pointer if not.
-
std::shared_ptr<CNodeCollection> GetParentPtr() const#
Gets the parent node pointer.
- Returns:
Returns the parent node pointer or an empty pointer when no parent was assigned or the stored weak pointer could not be locked.
Set the parent node.
- Parameters:
rptrParent – [in] Reference to the node to assign to this node as a parent.
-
std::string GetParentPath() const#
Get the parent path of the node.
- Returns:
Return the parent path if existining and not a root.
Set the view definition node. The view definition node is a parent or grand parent that presents the node when generating TOML code. When not set, the parent node is taking over this role.
- Parameters:
rptrView – [in] Reference to the node to assign to this node as a parent or grand parent.
Checks whether the node is part of the view.
The node is part of the view if the supplied pointer is identical to the view definition pointer, when the view definition pointer is not part of a parent of the topmost node. In all other cases, the node is part of the view.
- Parameters:
rContext – [in] Reference to the context class to use during TOML code generation.
rptrNode – [in] Reference to the node to check whether it registered for a view.
- Returns:
Returns whether this node is part of the view with the supplied pointer.
-
virtual std::shared_ptr<CNode> Direct(const std::string &rssPath) const = 0#
Accesses 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!
- 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 std::string GenerateTOML(const CGenContext &rContext = CGenContext()) const = 0#
Create the TOML text based on the content using an optional prefix node.
- Parameters:
rContext – [in] Reference to the context class to use during TOML code generation.
- Returns:
TOML text string.
-
virtual bool Inline() const = 0#
The derived class from the node collection can be inline or not.
- Returns:
Returns whether the node is an inline node.
-
virtual bool Inline(bool bInline) = 0#
With some node collections it is possible to switch between inline and normal.
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.
- 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 ExplicitlyDefined() const#
Checks whether the table was explicitly defined.
- Returns:
Returns the explicit definition flag.
-
virtual void MakeExplicit()#
If the table was an implicit definition, make it explicit.
Protected Functions
-
CNode(CParser &rparser, const std::string &rssName, const std::string &rssRawName)#
Constructs a new generic node object.
- 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.
-
std::string GetCustomPath(const std::string &rssPrefixKey, const std::string &rssContext) const#
Compose a custom path from the node key path using a key prefix and a context.
- Parameters:
rssPrefixKey – [in] The prefix to insert at as a base to the key tree.
rssContext – [in] The context that is used to define the relative portion of the key. To determine the relative portion, the context string contains the same prefix as is supplied in rssPrefixKey.
- Returns:
Returns the custom path composed of the prefix and the relative portion of the original path.
-
const CCodeSnippet &CodeSnippet(size_t nIndex, const std::string &rssKey = std::string()) const#
Get the code snippet.
- Parameters:
nIndex – [in] The comment type index to get the comment for.
rssKey – [in] Reference to the key to be used for code snippet identification.
- Returns:
Reference to the comment structure of the comment. If the provided index is not available in the vector, returns an empty code snippet.
-
CCodeSnippet &CodeSnippet(size_t nIndex, const std::string &rssKey = std::string())#
Get the code snippet (write access). This allows moving the snippet from one node to the another node.
Remark
Since the request to the code snippet could change the location of the vector allocation, access to the code snippet is valid until the next code snippet is requested.
- Parameters:
nIndex – [in] The comment type index to get the comment for.
rssKey – [in] Reference to the key to be used for code snippet identification.
- Returns:
Reference to the comment structure of the comment.
Protected Attributes
-
const size_t m_nPreNodeCode = 0#
sdv::toml::INodeInfo::ECommentFlags::comment_before.
Code snippet before the node. Corresponds to
-
const size_t m_nPostNodeCode = 1#
Comment behind the node. Corresponds to sdv::toml::INodeInfo::ECommentFlags::comment_behind.
-
const size_t m_nOutOfScopeCodeBefore = 2#
Out of scope comment before the node. Corresponds to sdv::toml::INodeInfo::ECommentFlags::out_of_scope_comment_before.
-
const size_t m_nOutOfScopeCodeBehind = 3#
Out of scope comment behind the node. Corresponds to sdv::toml::INodeInfo::ECommentFlags::out_of_scope_comment_behind.
-
const size_t m_nPreKeyCode = 4#
Code snippet before the key. Is stored in combination with the corresponding key.
-
const size_t m_nPostKeyCode = 5#
Code Snippet behind the key. Is stored in combination with the corresponding key.
-
const size_t m_nPreValueCode = 6#
Code snippet before the value.
-
const size_t m_nPostValueCode = 7#
Code snippet behind the value.
-
const size_t m_nPostValuesArray = 8#
Code snippet at the end of the array values, before the closing character.
-
class CCodeSnippet#
Comment or code snippet structure.
Each node has multiple code snippets used to reproduce the exact code. For example with an assignment:
# This is out of scope comment before # This is comment before var_a = "abc" # comment behind # more comment behind # This is out of scope comment behindThe code snippets are identified as follows:
<out of scope comment before> <comment before> <space before><key><space>=<space><value><comment behind> <out of scope comment behind>
Public Types
-
enum class EComposeMode#
Mode the code snippet composer should run in.
Values:
-
enumerator compose_inline#
Compose as inline whitespace and comment. If there is no token list and no comment string, compose as one space. If there is only a comment string, insert a space, add the comment followed by an obligatory newline, and insert spaces until the next provided position. If there are tokens with a comment token, replace the comment. If there are tokens without comment, add the comment, newline and spaces.
-
enumerator compose_before#
Compose as comment assigned to and located before the node. If there is no token list and no comment string, doesn’t add anything. If there is only a comment string, adds the comment followed by the obligatory newline. If there are tokens with a comment token, replace the comment. If there are tokens without the comment, place the comment before the last newline or when not available, at the end of the tokens followed by a new newline.
-
enumerator compose_behind#
Compose as comment assigned to and located behind the node. If there is no token list and no comment string, add a newline. If there is a comment string and no tokens, add a space, the comment string followed by the obligatory newline. If there is a token list without comment, add a comment before the newline or at the end with an additional newline.
-
enumerator compose_standalone#
Compose as stand-alone comment. Replace any token list if a comment string is available.
-
enumerator compose_inline#
Public Functions
-
std::string &Str()#
Access the comment text string.
- Returns:
Reference to the comment string.
-
std::string Compose(EComposeMode eMode, size_t nAssignmentOffset = 0, size_t nCommentOffset = 0) const#
Compose a conde string from the stored tokens and/or string.
- Parameters:
eMode – [in] The mode the composer should run in.
nAssignmentOffset – [in] The offset for a next assignent; only used for inline composition.
nCommentOffset – [in] The offset to insert a multi-line comment; only used for inline and behind composition.
- Returns:
The composed code string.
-
enum class EComposeMode#
-
~CNode()#