PIP 5.5.3
Platform-Independent Primitives
Classes | Public Member Functions | Static Public Member Functions | List of all members
PIValueTree Class Reference

The PIValueTree class represents a tree structure of PIVariant values with attributes. More...

#include <pivaluetree.h>

Classes

struct  Attribute
 The Attribute struct contains constants for commonly used attribute names. More...
 

Public Member Functions

 PIValueTree ()
 Constructs an empty PIValueTree object.
 
 PIValueTree (const PIVariant &v)
 Constructs a PIValueTree object with only value.
 
 PIValueTree (const PIString &n, const PIVariant &v, const PIVariantMap &a=PIVariantMap())
 Constructs a PIValueTree object with a name, a value, and a set of attributes.
 
bool isNull () const
 Returns whether the current PIValueTree object is null.
 
bool isValid () const
 Returns whether the current PIValueTree object is valid.
 
bool isArray () const
 Returns whether the current PIValueTree object is an array.
 
bool hasChildren () const
 Returns whether the current PIValueTree object has children.
 
const PIStringname () const
 Returns the name of the current PIValueTree object.
 
void setName (const PIString &n)
 Sets the name of the current PIValueTree object.
 
const PIStringcomment () const
 Returns the comment for the current PIValueTree object.
 
void setComment (const PIString &c)
 Sets the comment for the current PIValueTree object.
 
const PIVariantvalue () const
 Returns the value of the current PIValueTree object.
 
void setValue (const PIVariant &v)
 Sets the value of the current PIValueTree object.
 
const PIVariantMapattributes () const
 Returns the set of attributes for the current PIValueTree object.
 
PIVariantMapattributes ()
 Returns a reference to the set of attributes for the current PIValueTree object.
 
PIVariant attribute (const PIString &an, const PIVariant &def=PIVariant()) const
 Returns the attribute value for a given attribute name, or "def" if the attribute is not found.
 
void setAttribute (const PIString &n, const PIVariant &a)
 Sets the attribute value for a given attribute name.
 
void mergeAttributes (const PIVariantMap &a)
 Merges a set of attributes into the current set of attributes for the PIValueTree object.
 
void applyValues (const PIValueTree &root, bool recursive=true)
 Applies the values of a given PIValueTree object to the current PIValueTree object. More...
 
const PIVector< PIValueTree > & children () const
 Returns the children of the current PIValueTree object.
 
void clearChildren ()
 Clears the children of the current PIValueTree object.
 
PIVariant childValue (const PIString &child_name, const PIVariant &default_value=PIVariant(), bool *exists=nullptr) const
 Returns the value of a child node with a given name. More...
 
PIVariant childValue (const PIStringList &child_path, const PIVariant &default_value=PIVariant(), bool *exists=nullptr) const
 Returns the value of a child node with a given path. More...
 
template<typename T >
PIValueTreereadChildValue (const PIString &child_name, T &read_to)
 Reads the value of a child node with a given name into "read_to". Returns a reference to the current PIValueTree object.
 
bool contains (const PIString &name) const
 Returns whether the current PIValueTree object contains a child node with a given name.
 
bool contains (const PIStringList &path) const
 Returns whether the current PIValueTree object contains a child node with a given path.
 
int childIndex (const PIString &name) const
 Returns the index of the child node with a given name, or -1 if the node is not found.
 
const PIValueTreechild (const PIString &name) const
 Returns a const reference to the child node with a given name, or null node if it doesn`t exists.
 
const PIValueTreechild (const PIStringList &path) const
 Returns a const reference to the child node with a given path, or null node if it doesn`t exists.
 
PIValueTreechild (const PIString &name)
 Returns a reference to the child node with a given name, or null node if it doesn`t exists.
 
PIValueTreechild (const PIStringList &path)
 Returns a reference to the child node with a given path, or null node if it doesn`t exists.
 
PIValueTreeinsertChild (int index, const PIValueTree &n)
 Inserts a node at a given index. Returns a reference to the current PIValueTree object.
 
PIValueTreeaddChild (const PIValueTree &n)
 Adds a node to the end of the list of children. Returns a reference to the current PIValueTree object.
 
PIValueTreeaddChildren (const PIVector< PIValueTree > &n)
 Adds a vector of nodes to the end of the list of children. Returns a reference to the current PIValueTree object.
 
PIValueTreeremove (const PIString &name)
 Removes a child node with a given name. Returns a reference to the current PIValueTree object.
 
PIValueTreeoperator[] (const PIString &name)
 Returns a reference to the child node with a given name, creating it if it does not exist.
 
PIValueTreeoperator[] (const PIStringList &path)
 Returns a reference to the child node with a given path, creating it if it does not exist.
 
const PIValueTreeoperator[] (const PIString &name) const
 Returns a const reference to the child node with a given name, or null node if it doesn`t exists.
 
void forEachRecursive (std::function< void(const PIValueTree &item, const PIString &path)> func)
 Recursive call "func" for every child. "path" is a name with path, joined with ".".
 

Static Public Member Functions

static const PIStringListstandardAttributes ()
 Returns a list of standard attribute names.
 

Detailed Description

The PIValueTree class represents a tree structure of PIVariant values with attributes.

This class allows for easy manipulation of complex hierarchical data structures represented as PIVariant values. Each PIValueTree node has a name, a value, and a set of named attributes. PIValueTree nodes can have child nodes, which allows for the creation of a tree structure.

Member Function Documentation

◆ applyValues()

void PIValueTree::applyValues ( const PIValueTree root,
bool  recursive = true 
)

Applies the values of a given PIValueTree object to the current PIValueTree object.

Parameters
rootThe PIValueTree object whose values are to be applied.
recursiveWhether to apply values recursively to child nodes.

◆ childValue() [1/2]

PIVariant PIValueTree::childValue ( const PIString child_name,
const PIVariant default_value = PIVariant(),
bool *  exists = nullptr 
) const

Returns the value of a child node with a given name.

Parameters
child_nameThe name of the child node.
default_valueThe default value to be returned if the child node is not found.
existsIf not null, set to true if the child node exists, false otherwise.

◆ childValue() [2/2]

PIVariant PIValueTree::childValue ( const PIStringList child_path,
const PIVariant default_value = PIVariant(),
bool *  exists = nullptr 
) const

Returns the value of a child node with a given path.

Parameters
child_pathThe path of the child node.
default_valueThe default value to be returned if the child node is not found.
existsIf not null, set to true if the child node exists, false otherwise.