From feb8c9be78474599f85f37ae733e564a4bda4e06 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 26 Jul 2022 04:33:19 +0300 Subject: libcamera: yaml_parser: Replace ok flag to get() with std::optional The YamlObject::get() function takes a default value and an optional bool ok flag to handle parsing errors. This ad-hoc mechanism complicates error handling in callers. A better API is possible by dropping the default value and ok flag and returning an std::optional. Not only does it simplify the calls, it also lets callers handle errors through the standard std::optional class instead of the current ad-hoc mechanism. Provide a get() wrapper around std::optional::value_or() to further simplify callers that don't need any specific error handling. Signed-off-by: Laurent Pinchart Reviewed-by: Naushir Patuck Tested-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- include/libcamera/internal/yaml_parser.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 064cf443..61f22232 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -165,7 +166,13 @@ public: #else template #endif - T get(const T &defaultValue, bool *ok = nullptr) const; + std::optional get() const; + + template + T get(const T &defaultValue) const + { + return get().value_or(defaultValue); + } DictAdapter asDict() const { return DictAdapter{ dictionary_ }; } ListAdapter asList() const { return ListAdapter{ list_ }; } -- cgit v1.2.1