|
libcamera v0.7.1
Supporting cameras in Linux since 2019
|
A class representing a tree structure of values. More...
Public Member Functions | |
| template<typename T > | |
| ValueNode (T &&value) | |
| Construct a ValueNode instance with a value. | |
| bool | isValue () const |
| Return whether the ValueNode is a value. | |
| bool | isList () const |
| Return whether the ValueNode is a list. | |
| bool | isDictionary () const |
| Return whether the ValueNode is a dictionary. | |
| bool | isEmpty () const |
| Return whether the ValueNode is an empty. | |
| operator bool () const | |
| Return whether the ValueNode is a non-empty. | |
| std::size_t | size () const |
| Retrieve the number of elements in a dictionary or list ValueNode. | |
| template<typename T > | |
| std::optional< T > | get () const |
| Parse the ValueNode as a T value. | |
| template<typename T , typename U > | |
| T | get (U &&defaultValue) const |
| Parse the ValueNode as a T value. | |
| template<typename T > | |
| void | set (T &&value) |
| Set the value of a ValueNode. | |
| DictAdapter | asDict () |
| Wrap a dictionary ValueNode in an adapter that exposes iterators. | |
| ListAdapter | asList () |
| Wrap a list ValueNode in an adapter that exposes iterators. | |
| ConstDictAdapter | asDict () const |
| Wrap a dictionary ValueNode in an adapter that exposes iterators. | |
| ConstListAdapter | asList () const |
| Wrap a list ValueNode in an adapter that exposes iterators. | |
| ValueNode * | at (std::size_t index) |
| Retrieve the element from list ValueNode by index. | |
| const ValueNode & | operator[] (std::size_t index) const |
| Retrieve the element from list ValueNode by index. | |
| bool | contains (std::string_view key) const |
| Check if an element of a dictionary exists. | |
| ValueNode * | at (std::string_view key) |
| Retrieve a member by key from the dictionary. | |
| const ValueNode & | operator[] (std::string_view key) const |
| Retrieve a member by key from the dictionary. | |
| const ValueNode & | operator[] (std::initializer_list< std::string_view > path) const |
| Retrieve a descendant node by path. | |
| ValueNode * | add (std::unique_ptr< ValueNode > &&child) |
| Add a child node to a list. | |
| ValueNode * | add (std::string key, std::unique_ptr< ValueNode > &&child) |
| Add a child node to a dictionary. | |
| ValueNode * | add (std::initializer_list< std::string_view > path, std::unique_ptr< ValueNode > &&child) |
| Add a child node at the given path. | |
| void | erase (std::string_view key) |
| Erase a child node in a dictionary. | |
| void | erase (std::initializer_list< std::string_view > path) |
| Erase the child node at the given path. | |
Friends | |
| template<typename T > | |
| struct | Accessor |
A class representing a tree structure of values.
The ValueNode class is designed to model a tree of values. Each node in the tree is represented by a ValueNode instance. Intermediate nodes store children either as an ordered list (sequence) or a string-indexed dictionary (mapping). Leaf nodes can be empty or store a string value.
Construct a ValueNode instance with a value.
| T | Type of the value |
| [in] | value | The value |
| ValueNode * libcamera::ValueNode::add | ( | std::initializer_list< std::string_view > | path, |
| std::unique_ptr< ValueNode > && | child | ||
| ) |
Add a child node at the given path.
| [in] | path | The path |
| [in] | child | The child node |
Add the child node at the given path starting at this node. Missing nodes are created along the path. Nodes along the path must be empty (in which case they are converted to the Type::Dictionary type), be a dictionary, or be missing. Otherwise, the function returns a nullptr and the child is not modified.
Path elements are unique in the context of a parent node. If a child with the same key already exist at the end of the path, the function returns a nullptr and the child is not modified.
Add a child node to a dictionary.
| [in] | key | The dictionary key |
| [in] | child | The child node |
Add the child node with the given key to this node's children. This node must be empty, in which case it is converted to the Type::Dictionary type, or be a dictionary. Otherwise, the function returns a nullptr and the child is not modified.
Keys are unique. If a child with the same key already exists, the function returns a nullptr and the child is not modified.
Add a child node to a list.
| [in] | child | The child node |
Append the child node as the last element of this node's children list. This node must be empty, in which case it is converted to the Type::List type, or be a list. Otherwise, the function returns a nullptr and the child is not modified.
|
inline |
Wrap a dictionary ValueNode in an adapter that exposes iterators.
The ValueNode class doesn't directly implement iterators, as the iterator type depends on whether the node is a Dictionary or List. This function wraps a ValueNode of Dictionary type into an adapter that exposes iterators, as well as begin() and end() functions, allowing usage of range-based for loops with ValueNode. As mappings are not ordered, the iteration order is not specified.
The iterator's value_type is a std::pair<const std::string &, const ValueNode &>.
If the ValueNode is not of Dictionary type, the returned adapter operates as an empty container.
|
inline |
Wrap a dictionary ValueNode in an adapter that exposes iterators.
The ValueNode class doesn't directly implement iterators, as the iterator type depends on whether the node is a Dictionary or List. This function wraps a ValueNode of Dictionary type into an adapter that exposes iterators, as well as begin() and end() functions, allowing usage of range-based for loops with ValueNode. As mappings are not ordered, the iteration order is not specified.
The iterator's value_type is a std::pair<const std::string &, const ValueNode &>.
If the ValueNode is not of Dictionary type, the returned adapter operates as an empty container.
|
inline |
Wrap a list ValueNode in an adapter that exposes iterators.
The ValueNode class doesn't directly implement iterators, as the iterator type depends on whether the node is a Dictionary or List. This function wraps a ValueNode of List type into an adapter that exposes iterators, as well as begin() and end() functions, allowing usage of range-based for loops with ValueNode. As lists are ordered, the iteration order matches the order in which child nodes have been added.
The iterator's value_type is a const ValueNode &.
If the ValueNode is not of List type, the returned adapter operates as an empty container.
|
inline |
Wrap a list ValueNode in an adapter that exposes iterators.
The ValueNode class doesn't directly implement iterators, as the iterator type depends on whether the node is a Dictionary or List. This function wraps a ValueNode of List type into an adapter that exposes iterators, as well as begin() and end() functions, allowing usage of range-based for loops with ValueNode. As lists are ordered, the iteration order matches the order in which child nodes have been added.
The iterator's value_type is a const ValueNode &.
If the ValueNode is not of List type, the returned adapter operates as an empty container.
| ValueNode * libcamera::ValueNode::at | ( | std::size_t | index | ) |
Retrieve the element from list ValueNode by index.
| [in] | index | The element index |
This function retrieves an element of the ValueNode. Only ValueNode instances of List type associate elements with an index, calling this function on other types of instances or with an invalid index returns a null pointer.
| ValueNode * libcamera::ValueNode::at | ( | std::string_view | key | ) |
Retrieve a member by key from the dictionary.
| [in] | key | The element key |
This function retrieves a member of a ValueNode by key. Only ValueNode instances of Dictionary type associate elements with keys, calling this function on other types of instances or with a nonexistent key returns a null pointer.
| bool libcamera::ValueNode::contains | ( | std::string_view | key | ) | const |
Check if an element of a dictionary exists.
| [in] | key | The element key |
This function checks if the ValueNode contains an element for the given key. Only ValueNode instances of Dictionary type associate elements with keys, calling this function on other types of instances is invalid and results in undefined behaviour.
| void libcamera::ValueNode::erase | ( | std::initializer_list< std::string_view > | path | ) |
Erase the child node at the given path.
| [in] | path | The path |
Erase the child node at the given path. If no child node exists for the path, the function returns without performing any operation.
| void libcamera::ValueNode::erase | ( | std::string_view | key | ) |
Erase a child node in a dictionary.
| [in] | key | The dictionary key |
Erase the child node referenced by key in a dictionary node. If the key does not exist, or if this node is not a dictionary, the function returns without performing any operation.
|
inline |
Parse the ValueNode as a T value.
| T | Type of the value |
This function parses the value of the ValueNode as a T object, and returns the value. If parsing fails (usually because the ValueNode doesn't store a T value), std::nullopt is returned.
If the type T is an std::vector, the ValueNode will be parsed as a list of values.
|
inline |
Parse the ValueNode as a T value.
| T | Type of the value |
| U | Type of the default value |
| [in] | defaultValue | The default value when failing to parse |
This function parses the value of the ValueNode as a T object, and returns the value. If parsing fails (usually because the ValueNode doesn't store a T value), the defaultValue is returned. Type U must be convertible to type T.
Unlike the get() function, this overload does not support std::vector for the type T.
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineexplicit |
| const ValueNode & libcamera::ValueNode::operator[] | ( | std::initializer_list< std::string_view > | path | ) | const |
Retrieve a descendant node by path.
| [in] | path | The path |
This function retrieves a descendant of a ValueNode by following a path. The path is a list of keys that index nested dictionary nodes. If any node along the path is not a Dictionary node, an empty node is returned.
| const ValueNode & libcamera::ValueNode::operator[] | ( | std::size_t | index | ) | const |
Retrieve the element from list ValueNode by index.
| [in] | index | The element index |
This function retrieves an element of the ValueNode. Only ValueNode instances of List type associate elements with index, calling this function on other types of instances or with an invalid index results in an empty node.
| const ValueNode & libcamera::ValueNode::operator[] | ( | std::string_view | key | ) | const |
Retrieve a member by key from the dictionary.
| [in] | key | The element key |
This function retrieves a member of a ValueNode by key. Only ValueNode instances of Dictionary type associate elements with keys, calling this function on other types of instances or with a nonexistent key results in an empty node.
Set the value of a ValueNode.
| T | Type of the value |
| [in] | value | The value |
This function sets the value stored in a ValueNode to value. The value is converted to a string in an implementation-specific way that guarantees that subsequent calls to get<T>() will return the same value.
Values can only be set on ValueNode of Type::Value type or empty ValueNode. Attempting to set a value on a node of type Type::Dict or Type::List does not modify the ValueNode.
| std::size_t libcamera::ValueNode::size | ( | ) | const |
Retrieve the number of elements in a dictionary or list ValueNode.
This function retrieves the size of the ValueNode, defined as the number of child elements it contains. Only ValueNode instances of Dictionary or List types have a size, calling this function on other types of instances is invalid and results in undefined behaviour.