summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2022-08-03 12:55:39 +0200
committerJacopo Mondi <jacopo@jmondi.org>2022-08-03 15:07:20 +0200
commit2e77ccbb93a14a0c976bb3ca9d5dbbdc32a12847 (patch)
tree8c79730c86021cfd96157d7f61f47346e7ac1b51
parentac54f2ac6dede6a4d8ed761660c3f74b42a497a3 (diff)
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>
-rw-r--r--src/libcamera/yaml_parser.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp
index 84cb57d6..c96e99e1 100644
--- a/src/libcamera/yaml_parser.cpp
+++ b/src/libcamera/yaml_parser.cpp
@@ -319,7 +319,7 @@ template<typename T,
std::optional<std::vector<T>> YamlObject::getList() const
{
if (type_ != Type::List)
- return {};
+ return std::nullopt;
std::vector<T> values;
values.reserve(list_.size());
@@ -327,7 +327,7 @@ std::optional<std::vector<T>> YamlObject::getList() const
for (const YamlObject &entry : asList()) {
const auto value = entry.get<T>();
if (!value)
- return {};
+ return std::nullopt;
values.emplace_back(*value);
}