libcamera: yaml_parser: Return nullopt on error

The YamlParser::getList<>() function returns an std::optional<> to allow
callers to identify cases where parsing the .yaml file failed from cases
where the parsed list is just empty.

The current implementation returns a default constructed std::optional
in case of errors with

	return {};

The returned value is thus equal to std::nullopt, but the code can be
easily misinterpreted as returning an empty vector by a reader.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Jacopo Mondi 2022-08-03 12:55:39 +02:00
parent ac54f2ac6d
commit 2e77ccbb93

View file

@ -319,7 +319,7 @@ template<typename T,
std::optional<std::vector<T>> YamlObject::getList() const std::optional<std::vector<T>> YamlObject::getList() const
{ {
if (type_ != Type::List) if (type_ != Type::List)
return {}; return std::nullopt;
std::vector<T> values; std::vector<T> values;
values.reserve(list_.size()); values.reserve(list_.size());
@ -327,7 +327,7 @@ std::optional<std::vector<T>> YamlObject::getList() const
for (const YamlObject &entry : asList()) { for (const YamlObject &entry : asList()) {
const auto value = entry.get<T>(); const auto value = entry.get<T>();
if (!value) if (!value)
return {}; return std::nullopt;
values.emplace_back(*value); values.emplace_back(*value);
} }