Class CNode#

Inheritance Relationships#

Base Types#

Derived Types#

Class Documentation#

class CNode : public std::enable_shared_from_this<CNode>, public sdv::IInterfaceAccess, public sdv::toml::INodeInfo, public sdv::toml::INodeUpdate#

Node to build up the parse tree.

Subclassed by toml_parser::CNodeCollection, toml_parser::CValueNode

Unnamed Group

CNode(const CNode&) = delete#

Deleted since Nodes should only be handled via smart-pointer.

CNode &operator=(const CNode&) = delete#

Deleted since Nodes should only be handled via smart-pointer.

CNode(const CNode&&) = delete#

Deleted since Nodes should only be handled via smart-pointer.

CNode &operator=(const CNode&&) = delete#

Deleted since Nodes should only be handled via smart-pointer.

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 view collection (either the assigned view or the parent). Overload of sdv::toml::INodeInfo::GetIndex.

Returns:

The index of the node within the view 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(sdv::toml::INodeInfo::ECommentType eType, const sdv::u8string &ssComment) override#

Set or replace a comment for the node. Overload of sdv::toml::INodeInfo::SetComment.

Set the comment text for the node. If a comment is provided as text (normal behavior), the comment text will be formatted automatically when generating the TOML text. If the comment text should not contain the comment character ‘#’ before the comment text. Comments inserted before the node will be inserted on the line before the node unless the comment is provided in raw format and is ended with a line-break 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 132 characters if possible. Line-breaks in the text will cause a new comment line to start.

Parameters:
  • eType[in] The comment type to set the comment text for.

  • ssComment[in] String containing the comment text to set.

virtual sdv::u8string GetComment(sdv::toml::INodeInfo::ECommentType eType) override#

Get the current comment for the node. Overload of sdv::toml::INodeInfo::GetComment.

Parameters:

eType[in] The comment type to get the comment text of.

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 bool IsInline() const override#

Is the node inline? Overload of sdv::toml::INodeInfo::IsInline.

Returns:

Returns whether the node is defined as inline node.

virtual bool IsStandard() const override#

Is the node defined as standard node? Overload of sdv::toml::INodeInfo::IsStandard.

Returns:

Returns whether the node is defined as standard node.

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 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, virtual bool 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.

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.

bool IsDeleted() const#

Is this node marked as deleted?

Returns:

Returns whether this node has been deleted.

template<typename TNodeType>
std::shared_ptr<TNodeType> Cast()#

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.

template<typename TNodeType>
std::shared_ptr<const TNodeType> Cast() const#

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.

void SetParentPtr(const std::shared_ptr<CNodeCollection> &rptrParent)#

Set the parent node.

Parameters:

rptrParent[in] Reference to the node to assign to this node as a parent.

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.

std::string GetParentPath() const#

Get the parent path of the node.

Returns:

Return the parent path if existining and not a root.

void SetViewPtr(const std::shared_ptr<CNodeCollection> &rptrView)#

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.

std::shared_ptr<CNodeCollection> GetViewPtr() const#

Gets the view definition node pointer.

Returns:

Returns the store view definition node pointer or an empty pointer when no view was assigned.

bool IsPartOfView(const CGenContext &rContext, const std::shared_ptr<const CNodeCollection> &rptrNode) const#

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.

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 code 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).

Parameters:
  • nIndex[in] The comment type index to get the code for.

  • rssKey[in] Reference to the key to be used for code snippet identification.

Returns:

Reference to the comment structure of the comment.

const CCodeSnippet &CodeSnippet(sdv::toml::INodeInfo::ECommentType eType) const#

Get the code snippet using the comment type.

Parameters:

eType[in] The comment type to get the code for.

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(sdv::toml::INodeInfo::ECommentType eType)#

Get the code snippet (write access) using the comment type.

Parameters:

eType[in] The comment type to get the code for.

Returns:

Reference to the comment structure of the comment. If the provided index is not available in the vector, returns an empty code snippet.

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.

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.

Public Members

const size_t m_nPreNodeCode = 0#

Code snippet before the node. Corresponds to sdv::toml::INodeInfo::ECommentFlags::comment_before.

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.

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.