![]() |
PIP 5.6.1
Platform-Independent Primitives
|
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 PIString & | name () const |
| Returns the name of the current PIValueTree object. | |
| void | setName (const PIString &n) |
| Sets the name of the current PIValueTree object. | |
| const PIString & | comment () const |
| Returns the comment for the current PIValueTree object. | |
| void | setComment (const PIString &c) |
| Sets the comment for the current PIValueTree object. | |
| const PIVariant & | value () const |
| Returns the value of the current PIValueTree object. | |
| void | setValue (const PIVariant &v) |
| Sets the value of the current PIValueTree object. | |
| const PIVariantMap & | attributes () const |
| Returns the set of attributes for the current PIValueTree object. | |
| PIVariantMap & | attributes () |
| 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. More... | |
| void | applyValues (const PIValueTree &root, bool recursive=true) |
| Applies the values of a given PIValueTree object to the current PIValueTree object. More... | |
| void | merge (const PIValueTree &root) |
| Set or add 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 > | |
| PIValueTree & | readChildValue (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 PIValueTree & | child (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 PIValueTree & | child (const PIStringList &path) const |
| Returns a const reference to the child node with a given path, or null node if it doesn't exists. | |
| PIValueTree & | child (const PIString &name) |
| Returns a reference to the child node with a given name, or null node if it doesn't exists. | |
| PIValueTree & | child (const PIStringList &path) |
| Returns a reference to the child node with a given path, or null node if it doesn't exists. | |
| PIValueTree & | insertChild (int index, const PIValueTree &n) |
| Inserts a node at a given index. Returns a reference to the current PIValueTree object. | |
| PIValueTree & | addChild (const PIValueTree &n) |
| Adds a node to the end of the list of children. Returns a reference to the current PIValueTree object. | |
| PIValueTree & | addChildren (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. | |
| PIValueTree & | remove (const PIString &name) |
| Removes a child node with a given name. Returns a reference to the current PIValueTree object. | |
| PIValueTree & | operator[] (const PIString &name) |
| Returns a reference to the child node with a given name, creating it if it does not exist. | |
| PIValueTree & | operator[] (const PIStringList &path) |
| Returns a reference to the child node with a given path, creating it if it does not exist. | |
| const PIValueTree & | operator[] (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 ".". More... | |
Static Public Member Functions | |
| static const PIStringList & | standardAttributes () |
| Returns a list of standard attribute names. | |
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.
| void PIValueTree::mergeAttributes | ( | const PIVariantMap & | a | ) |
Merges a set of attributes into the current set of attributes for the PIValueTree object.
Merges the provided attributes map into the current attributes, overwriting any existing attributes with the same name.
| void PIValueTree::applyValues | ( | const PIValueTree & | root, |
| bool | recursive = true |
||
| ) |
Applies the values of a given PIValueTree object to the current PIValueTree object.
| root | The PIValueTree object whose values are to be applied. |
| recursive | Whether to apply values recursively to child nodes. |
| void PIValueTree::merge | ( | const PIValueTree & | root | ) |
Set or add the values of a given PIValueTree object to the current PIValueTree object.
| root | The PIValueTree object whose values are to be merged. |
| 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.
| child_name | The name of the child node. |
| default_value | The default value to be returned if the child node is not found. |
| exists | If not null, set to true if the child node exists, false otherwise. |
| 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.
| child_path | The path of the child node. |
| default_value | The default value to be returned if the child node is not found. |
| exists | If not null, set to true if the child node exists, false otherwise. |
| void PIValueTree::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 ".".
Recursively calls the provided function for every node in the tree. The path parameter contains the full path to the node, with ancestor names joined by dots.