DataNode

class DataNode

Class represents the DataNode.

virtual ~DataNode()

The destructor.

Note

A DataNode represents a containment hierarchy. So invocation of the destructor will lead to the children of this node being destroyed.

virtual const SchemaNode &schema() const

Returns the SchemaNode associated with this DataNode.

Returns:SchemaNode associated with this DataNode.
virtual std::string path() const

Returns the path expression representing this Node in in the NodeTree.

Returns:std::string representing the path to this Node.
virtual DataNode &create(const std::string &path)

Creates a DataNode corresponding to the path and set its value.

This methods creates a DataNode tree based on the path passed in. The path expression must identify a single node. If the last node created is of schema type list, leaf-list or anyxml that value is also set in the node.

The returned DataNode is the last node created (the terminal part of the path).

The user is responsible for managing the memory of this returned tree. Use root() to get the root element of the this tree and use that pointer to dispose of the entire tree.

Note

In the case of list nodes the keys must be present in the path expression in the form of predicates.

Parameters:
  • path – The XPath expression identifying the node.
  • value – The string representation of the value to set.
Returns:

Pointer to DataNode created.

Raises:

YCPPInvalidArgumentError In case the argument is invalid.

Raises:

YCPPPathError In case the path is invalid.

virtual DataNode &create(const std::string &path, const std::string &value)

Create a DataNode corresponding to the path and set its value.

This methods creates a DataNode tree based on the path passed in. The path expression must identify a single node. If the last node created is of schema type list, leaf-list or anyxml that value is also set in the node.

The returned DataNode is the last node created (the terminal part of the path).

The user is responsible for managing the memory of this returned tree. Use root() to get the root element of the this tree and use that pointer to dispose of the entire tree.

Note

In the case of list nodes the keys must be present in the path expression in the form of predicates.

Parameters:path – The XPath expression identifying the node.
Returns:Pointer to DataNode created.
Raises:YCPPInvalidArgumentError In case the argument is invalid.
Raises:YCPPPathError In case the path is invalid.
virtual void set(const std::string &value)

Set the value of this DataNode.

Note

  • The DataNode should represent a leaf , leaf-list or anyxml element for this to work. The value should be the string representation of the type of according to the schema.
  • This method does not validate the value being set. To validate please see the ValidationService.
Parameters:value – The value to set. This should be the string representation of the YANG type.
Raises:YCPPInvalidArgumentError if the DataNode‘s value cannot be set (for example it represents a container)
virtual std::string get() const

Returns a copy of the value of this DataNode.

Returns:A std::string representation of the value.
virtual std::vector<std::shared_ptr<DataNode>> find(const std::string &path) const

Finds nodes that satisfy the given path expression. For details about the path expression see how to path.

Parameters:path – The path expression.
Returns:Vector of DataNode that satisfy the path expression supplied.
virtual DataNode *parent() const
Returns:Pointer to the parent of this DataNode or nullptr if None exist.
virtual std::vector<std::shared_ptr<DataNode>> children() const
Returns:Pointer to the children of this DataNode.
virtual const DataNode &root() const
Returns:Pointer to the root DataNode of this tree.
virtual void add_annotation(const Annotation &an)

This method adds the annotation to this Datanode.

Parameters:an – The annotation to add to this DataNode.
Raises:YCPPInvalidArgumentError in case the argument is invalid.
virtual bool remove_annotation(const Annotation &an)

This method will remove the annotation from the given node.

Note

The m_val for annotation is ignored.

Parameters:an – The reference to the annotation.
Returns:bool If true the annotation was found and removed, false otherwise.
virtual std::vector<Annotation> annotations()

Get the annotations associated with this data node.

Returns:Vector of Annotation for this node.