diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-02-27 01:05:59 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-03-06 18:10:29 +0200 |
commit | 3556ae95ecb049eb7befb4c2115aa1646c5b4daf (patch) | |
tree | 5a1dadbb180dca132edf19d2114c50e286978ff8 /include | |
parent | 1fa4b43402a0af7cc41bb22b58cede687663cc7b (diff) |
libcamera: controls: Allow passing an std::initializer list to set()
For array controls, the ControlList::set() function takes a value as a
type convertible to Span<T>. This allows passing an std::array or an
std::vector in addition to an explicit Span, but doesn't accept an
std::initializer list as Span has no constructor that takes an
initializer list. Callers are thus forced to create temporary objects
explicitly, which isn't nice.
Fix the issue by providing a ControlList::set() function that takes an
std::initializer_list, and convert it to a Span internally.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/controls.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 1e24ae30..2102d571 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -335,6 +335,16 @@ public: val->set<T>(value); } + template<typename T, typename V> + void set(const Control<T> &ctrl, const std::initializer_list<V> &value) + { + ControlValue *val = find(ctrl.id()); + if (!val) + return; + + val->set<T>(Span<const typename std::remove_cv_t<V>>{ value.begin(), value.size() }); + } + const ControlValue &get(unsigned int id) const; void set(unsigned int id, const ControlValue &value); |