|
| 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.
|
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.
| ValueNode * libcamera::ValueNode::add |
( |
std::initializer_list< std::string_view > | path, |
|
|
std::unique_ptr< ValueNode > && | child ) |
Add a child node at the given path.
- Parameters
-
| [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.
- Note
- Any node added along the path will remain even if this function returns a failure.
- Returns
- A pointer to the child node if successfully added, nullptr otherwise
| ValueNode * libcamera::ValueNode::add |
( |
std::string | key, |
|
|
std::unique_ptr< ValueNode > && | child ) |
Add a child node to a dictionary.
- Parameters
-
| [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.
- Returns
- A pointer to the child node if successfully added, nullptr otherwise
| DictAdapter libcamera::ValueNode::asDict |
( |
| ) |
|
|
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.
- Returns
- An adapter of unspecified type compatible with range-based for loops
| ConstDictAdapter libcamera::ValueNode::asDict |
( |
| ) |
const |
|
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.
- Returns
- An adapter of unspecified type compatible with range-based for loops
| ListAdapter libcamera::ValueNode::asList |
( |
| ) |
|
|
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.
- Returns
- An adapter of unspecified type compatible with range-based for loops
| ConstListAdapter libcamera::ValueNode::asList |
( |
| ) |
const |
|
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.
- Returns
- An adapter of unspecified type compatible with range-based for loops
template<typename T, typename U>
| T libcamera::ValueNode::get |
( |
U && | defaultValue | ) |
const |
|
inline |
Parse the ValueNode as a T value.
- Template Parameters
-
| T | Type of the value |
| U | Type of the default value |
- Parameters
-
| [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.
- Returns
- The ValueNode value, or defaultValue if parsing failed