diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-06-13 02:31:07 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-06-16 03:28:25 +0300 |
commit | 922686067a2d610a93072cc9bbd3d9758087f4d1 (patch) | |
tree | 4164353bfed8a54c9a2357c1d67049cff2ec7c28 /include | |
parent | 8d6f494844fc30e117bdcac4260d892d7114b429 (diff) |
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/internal/yaml_parser.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 81cc0e25..06a41146 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -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_; |