libcamera: libcamera::YamlObject Class Reference

libcamera v0.7.0 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
libcamera::YamlObject Class Reference

A class representing the tree structure of the YAML content. More...

## Public Member Functions
bool | isValue () const
| Return whether the YamlObject is a value.
bool | isList () const
| Return whether the YamlObject is a list.
bool | isDictionary () const
| Return whether the YamlObject is a dictionary.
bool | isEmpty () const
| Return whether the YamlObject is an empty.
| operator bool () const
| Return whether the YamlObject is a non-empty.
std::size_t | size () const
| Retrieve the number of elements in a dictionary or list YamlObject.
template<typename T>
std::optional< T > | get () const
| Parse the YamlObject as a T value.
template<typename T, typename U>
T | get (U &&defaultValue) const
| Parse the YamlObject as a T value.
template<typename T>
std::optional< std::vector< T > > | getList () const
| Parse the YamlObject as a list of T.
DictAdapter | asDict () const
| Wrap a dictionary YamlObject in an adapter that exposes iterators.
ListAdapter | asList () const
| Wrap a list YamlObject in an adapter that exposes iterators.
const YamlObject & | operator[] (std::size_t index) const
| Retrieve the element from list YamlObject by index.
bool | contains (std::string_view key) const
| Check if an element of a dictionary exists.
const YamlObject & | operator[] (std::string_view key) const
| Retrieve a member by name from the dictionary.

## Friends
template<typename T>
struct | Getter
class | YamlParserContext

## Detailed Description

A class representing the tree structure of the YAML content.

The YamlObject class represents the tree structure of YAML content. A YamlObject can be empty, a dictionary or list of YamlObjects, or a value if a tree leaf.

## Member Function Documentation

## ◆ asDict()

DictAdapter libcamera::YamlObject::asDict | ( |  | ) | const
| inline

Wrap a dictionary YamlObject in an adapter that exposes iterators.

The YamlObject class doesn't directly implement iterators, as the iterator type depends on whether the object is a Dictionary or List. This function wraps a YamlObject of Dictionary type into an adapter that exposes iterators, as well as begin() and end() functions, allowing usage of range-based for loops with YamlObject. As YAML mappings are not ordered, the iteration order is not specified.

The iterator's value_type is a std::pair<const std::string &, const YamlObject &>.

If the YamlObject 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

## ◆ asList()

ListAdapter libcamera::YamlObject::asList | ( |  | ) | const
| inline

Wrap a list YamlObject in an adapter that exposes iterators.

The YamlObject class doesn't directly implement iterators, as the iterator type depends on whether the object is a Dictionary or List. This function wraps a YamlObject of List type into an adapter that exposes iterators, as well as begin() and end() functions, allowing usage of range-based for loops with YamlObject. As YAML lists are ordered, the iteration order is identical to the list order in the YAML data.

The iterator's value_type is a const YamlObject &.

If the YamlObject 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

## ◆ contains()

bool libcamera::YamlObject::contains | ( | std::string_view | key | ) | const

Check if an element of a dictionary exists.

This function check if the YamlObject contains an element. Only YamlObject instances of Dictionary type associate elements with names, calling this function on other types of instances is invalid and results in undefined behaviour.

Returns
  True if an element exists, false otherwise

## ◆ get() [1/2]

template<typename T>

std::optional< T > libcamera::YamlObject::get | ( |  | ) | const
| inline

Parse the YamlObject as a T value.

This function parses the value of the YamlObject as a T object, and returns the value. If parsing fails (usually because the YamlObject doesn't store a T value), std::nullopt is returned.

Returns
  The YamlObject value, or std::nullopt if parsing failed

## ◆ get() [2/2]

template<typename T, typename U>

T libcamera::YamlObject::get | ( | U && | defaultValue | ) | const
| inline

Parse the YamlObject as a T value.

Parameters

  [in] | defaultValue | The default value when failing to parse

This function parses the value of the YamlObject as a T object, and returns the value. If parsing fails (usually because the YamlObject doesn't store a T value), the defaultValue is returned.

Returns
  The YamlObject value, or defaultValue if parsing failed

## ◆ getList()

template<typename T>

std::optional< std::vector< T > > libcamera::YamlObject::getList | ( |  | ) | const

Parse the YamlObject as a list of T.

This function parses the value of the YamlObject as a list of T objects, and returns the value as a std::vector<T>. If parsing fails, std::nullopt is returned.

Returns
  The YamlObject value as a std::vector<T>, or std::nullopt if parsing failed

## ◆ isDictionary()

bool libcamera::YamlObject::isDictionary | ( |  | ) | const
| inline

Return whether the YamlObject is a dictionary.

Returns
  True if the YamlObject is a dictionary, false otherwise

## ◆ isEmpty()

bool libcamera::YamlObject::isEmpty | ( |  | ) | const
| inline

Return whether the YamlObject is an empty.

Returns
  True if the YamlObject is empty, false otherwise

## ◆ isList()

bool libcamera::YamlObject::isList | ( |  | ) | const
| inline

Return whether the YamlObject is a list.

Returns
  True if the YamlObject is a list, false otherwise

## ◆ isValue()

bool libcamera::YamlObject::isValue | ( |  | ) | const
| inline

Return whether the YamlObject is a value.

Returns
  True if the YamlObject is a value, false otherwise

## ◆ operator bool()

libcamera::YamlObject::operator bool | ( |  | ) | const
| inlineexplicit

Return whether the YamlObject is a non-empty.

Returns
  False if the YamlObject is empty, true otherwise

## ◆ operator[]() [1/2]

const YamlObject & libcamera::YamlObject::operator[] | ( | std::size_t | index | ) | const

Retrieve the element from list YamlObject by index.

This function retrieves an element of the YamlObject. Only YamlObject 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 object.

Returns
  The YamlObject as an element of the list

## ◆ operator[]() [2/2]

const YamlObject & libcamera::YamlObject::operator[] | ( | std::string_view | key | ) | const

Retrieve a member by name from the dictionary.

This function retrieve a member of a YamlObject by name. Only YamlObject instances of Dictionary type associate elements with names, calling this function on other types of instances or with a nonexistent key results in an empty object.

Returns
  The YamlObject corresponding to the key member

## ◆ size()

std::size_t libcamera::YamlObject::size | ( |  | ) | const

Retrieve the number of elements in a dictionary or list YamlObject.

This function retrieves the size of the YamlObject, defined as the number of child elements it contains. Only YamlObject instances of Dictionary or List types have a size, calling this function on other types of instances is invalid and results in undefined behaviour.

Returns
  The size of the YamlObject

The documentation for this class was generated from the following files:

- include/libcamera/internal/yaml_parser.h
- src/libcamera/yaml_parser.cpp