summaryrefslogtreecommitdiff
path: root/include/libcamera/internal/yaml_parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libcamera/internal/yaml_parser.h')
-rw-r--r--include/libcamera/internal/yaml_parser.h35
1 files changed, 15 insertions, 20 deletions
diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h
index 8ca71df8..06a41146 100644
--- a/include/libcamera/internal/yaml_parser.h
+++ b/include/libcamera/internal/yaml_parser.h
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2022, Google Inc.
*
- * yaml_parser.h - libcamera YAML parsing helper
+ * libcamera YAML parsing helper
*/
#pragma once
@@ -161,28 +161,16 @@ public:
std::size_t size() const;
-#ifndef __DOXYGEN__
- template<typename T,
- std::enable_if_t<
- std::is_same_v<bool, T> ||
- std::is_same_v<double, T> ||
- std::is_same_v<int8_t, T> ||
- std::is_same_v<uint8_t, T> ||
- std::is_same_v<int16_t, T> ||
- std::is_same_v<uint16_t, T> ||
- std::is_same_v<int32_t, T> ||
- std::is_same_v<uint32_t, T> ||
- std::is_same_v<std::string, T> ||
- std::is_same_v<Size, T>> * = nullptr>
-#else
template<typename T>
-#endif
- std::optional<T> get() const;
+ std::optional<T> get() const
+ {
+ return Getter<T>{}.get(*this);
+ }
- template<typename T>
- T get(const T &defaultValue) const
+ template<typename T, typename U>
+ T get(U &&defaultValue) const
{
- return get<T>().value_or(defaultValue);
+ return get<T>().value_or(std::forward<U>(defaultValue));
}
#ifndef __DOXYGEN__
@@ -214,6 +202,8 @@ public:
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)
+ template<typename T>
+ friend struct Getter;
friend class YamlParserContext;
enum class Type {
@@ -222,6 +212,11 @@ private:
Value,
};
+ template<typename T>
+ struct Getter {
+ std::optional<T> get(const YamlObject &obj) const;
+ };
+
Type type_;
std::string value_;