Loading...
Searching...
No Matches
libcamera::YamlParser Class Referencefinal

A helper class for parsing a YAML file. More...

## Static Public Member Functions

static std::unique_ptr< YamlObject > | parse (File &file)
| Parse a YAML file as a YamlObject.

## Detailed Description

A helper class for parsing a YAML file.

The YamlParser class provides an easy interface to parse the contents of a YAML file into a tree of YamlObject instances.

Example usage:

name:
"John"
numbers:
- 1
- 2

The following code illustrates how to parse the above YAML file:

std::unique_ptr<YamlObject> root = YamlParser::parse(fh);
if (!root)
return;
if (!root->isDictionary())
return;
const YamlObject &name = (*root)["name"];
std::cout << name.get<std::string>("") << std::endl;
const YamlObject &numbers = (*root)["numbers"];
if (!numbers.isList())
return;
for (std::size_t i = 0; i < numbers.size(); i++)
std::cout << numbers[i].get<int32_t>(0) << std::endl;
libcamera::YamlObject
A class representing the tree structure of the YAML content.
Definition yaml_parser.h:28
libcamera::YamlObject::get
std::optional< T > get() const
Parse the YamlObject as a T value.
Definition yaml_parser.h:175
libcamera::YamlParser::parse
static std::unique_ptr< YamlObject > parse(File &file)
Parse a YAML file as a YamlObject.
Definition yaml_parser.cpp:765

The YamlParser::parse() function takes an open FILE, parses its contents, and returns a pointer to a YamlObject corresponding to the root node of the YAML document.

The parser preserves the order of items in the YAML file, for both lists and dictionaries.

## Member Function Documentation

## parse()

std::unique_ptr< YamlObject > libcamera::YamlParser::parse | ( | File & | file | ) |

static

Parse a YAML file as a YamlObject.

Parameters

  [in] | file | The YAML file to parse

The YamlParser::parse() function takes a file, parses its contents, and returns a pointer to a YamlObject corresponding to the root node of the YAML document.

Returns
  Pointer to result YamlObject on success or nullptr otherwise

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

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