summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-07-26 04:33:19 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-07-28 13:47:13 +0300
commitfeb8c9be78474599f85f37ae733e564a4bda4e06 (patch)
tree1a33fdfa4f75b8a8798f341506ab36b5bc27fab0 /include
parent22ffeae04de2e7ce6b2476a35233c790beafb67f (diff)
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Naushir Patuck <naush@raspberrypi.com> Tested-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/yaml_parser.h9
1 files changed, 8 insertions, 1 deletions
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 <iterator>
#include <map>
+#include <optional>
#include <string>
#include <vector>
@@ -165,7 +166,13 @@ public:
#else
template<typename T>
#endif
- T get(const T &defaultValue, bool *ok = nullptr) const;
+ std::optional<T> get() const;
+
+ template<typename T>
+ T get(const T &defaultValue) const
+ {
+ return get<T>().value_or(defaultValue);
+ }
DictAdapter asDict() const { return DictAdapter{ dictionary_ }; }
ListAdapter asList() const { return ListAdapter{ list_ }; }