libcamera: yaml_parser: Delegate YamlObject::get() to helper structure

The YamlObject::get() function is a function template that gets fully
specialized for various types. This works fine for non-template types,
but specializing it for template types (e.g. a std::vector<U>) would
require partial template specialization, which C++ allows for classes
and variables but not functions.

To work around this problem, delegate the implementation to a new
YamlObject::Getter structure template, which will support partial
specialization.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2024-06-13 02:31:07 +03:00
parent 8d6f494844
commit 922686067a
2 changed files with 55 additions and 35 deletions
+11 -1
View File
@@ -162,7 +162,10 @@ public:
std::size_t size() const;
template<typename T>
std::optional<T> get() const;
std::optional<T> get() const
{
return Getter<T>{}.get(*this);
}
template<typename T, typename U>
T get(U &&defaultValue) const
@@ -199,6 +202,8 @@ public:
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)
template<typename T>
friend struct Getter;
friend class YamlParserContext;
enum class Type {
@@ -207,6 +212,11 @@ private:
Value,
};
template<typename T>
struct Getter {
std::optional<T> get(const YamlObject &obj) const;
};
Type type_;
std::string value_;