libcamera  v0.2.0+150-2031e2f2
Supporting cameras in Linux since 2019
Classes | Public Member Functions | Friends | List of all members
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. More...
 
bool isList () const
 Return whether the YamlObject is a list. More...
 
bool isDictionary () const
 Return whether the YamlObject is a dictionary. More...
 
std::size_t size () const
 Retrieve the number of elements in a dictionary or list YamlObject. More...
 
template<typename T >
std::optional< T > get () const
 Parse the YamlObject as a T value. More...
 
template<typename T >
get (const T &defaultValue) const
 Parse the YamlObject as a T value. More...
 
template<typename T >
std::optional< std::vector< T > > getList () const
 Parse the YamlObject as a list of T. More...
 
DictAdapter asDict () const
 Wrap a dictionary YamlObject in an adapter that exposes iterators. More...
 
ListAdapter asList () const
 Wrap a list YamlObject in an adapter that exposes iterators. More...
 
const YamlObjectoperator[] (std::size_t index) const
 Retrieve the element from list YamlObject by index. More...
 
bool contains (const std::string &key) const
 Check if an element of a dictionary exists. More...
 
const YamlObjectoperator[] (const std::string &key) const
 Retrieve a member by name from the dictionary. More...
 

Friends

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 a dictionary or list of YamlObjects or a value if a tree leaf.

Member Function Documentation

◆ asDict()

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()

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 ( const std::string &  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 >
template< typename T > libcamera::YamlObject::get< T > ( ) const

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 >
template< typename T > libcamera::YamlObject::get< T > ( const T &  defaultValue) const
inline

Parse the YamlObject as a T value.

Parameters
[in]defaultValueThe 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 >
template< typename T > libcamera::YamlObject::getList< T > ( ) 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()

libcamera::YamlObject::isDictionary ( ) const
inline

Return whether the YamlObject is a dictionary.

Returns
True if the YamlObject is a dictionary, false otherwise

◆ isList()

libcamera::YamlObject::isList ( ) const
inline

Return whether the YamlObject is a list.

Returns
True if the YamlObject is a list, false otherwise

◆ isValue()

libcamera::YamlObject::isValue ( ) const
inline

Return whether the YamlObject is a value.

Returns
True if the YamlObject is a value, false 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 is invalid and results in undefined behaviour.

Returns
The YamlObject as an element of the list

◆ operator[]() [2/2]

const YamlObject & libcamera::YamlObject::operator[] ( const std::string &  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 is invalid and results in undefined behaviour.

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: