Message ID | 20200229164254.23604-18-laurent.pinchart@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
On 29/02/2020 16:42, Laurent Pinchart wrote: > 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> Aha, nice - so this is how we then get to 'create' controls like Control{1,2,3,4} or such ? Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > --- > include/libcamera/controls.h | 10 ++++++++++ > src/libcamera/controls.cpp | 6 ++++++ > 2 files changed, 16 insertions(+) > > diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h > index d70a6bc4b83a..f99c90e934c1 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); > > diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp > index f4089c8ffb4e..829eea6f4240 100644 > --- a/src/libcamera/controls.cpp > +++ b/src/libcamera/controls.cpp > @@ -806,6 +806,12 @@ bool ControlList::contains(unsigned int id) const > * object that the list refers to. > */ > > +/** > + * \fn template<typename T, typename V> \ > + * void ControlList::set(const Control<T> &ctrl, const std::initializer_list<V> &value) > + * \copydoc ControlList::set(const Control<T> &ctrl, const V &value) > + */ > + > /** > * \brief Get the value of control \a id > * \param[in] id The control numerical ID >
Hi Kieran, On Tue, Mar 03, 2020 at 12:30:28AM +0000, Kieran Bingham wrote: > On 29/02/2020 16:42, Laurent Pinchart wrote: > > 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> > > Aha, nice - so this is how we then get to 'create' controls like > Control{1,2,3,4} or such ? This is how we can do ControlList &list = ...; list.set(controls::BayerGains, { 1.0, 1.1, 1.2, 1.0 }); > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > > --- > > include/libcamera/controls.h | 10 ++++++++++ > > src/libcamera/controls.cpp | 6 ++++++ > > 2 files changed, 16 insertions(+) > > > > diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h > > index d70a6bc4b83a..f99c90e934c1 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); > > > > diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp > > index f4089c8ffb4e..829eea6f4240 100644 > > --- a/src/libcamera/controls.cpp > > +++ b/src/libcamera/controls.cpp > > @@ -806,6 +806,12 @@ bool ControlList::contains(unsigned int id) const > > * object that the list refers to. > > */ > > > > +/** > > + * \fn template<typename T, typename V> \ > > + * void ControlList::set(const Control<T> &ctrl, const std::initializer_list<V> &value) > > + * \copydoc ControlList::set(const Control<T> &ctrl, const V &value) > > + */ > > + > > /** > > * \brief Get the value of control \a id > > * \param[in] id The control numerical ID
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index d70a6bc4b83a..f99c90e934c1 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); diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index f4089c8ffb4e..829eea6f4240 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -806,6 +806,12 @@ bool ControlList::contains(unsigned int id) const * object that the list refers to. */ +/** + * \fn template<typename T, typename V> \ + * void ControlList::set(const Control<T> &ctrl, const std::initializer_list<V> &value) + * \copydoc ControlList::set(const Control<T> &ctrl, const V &value) + */ + /** * \brief Get the value of control \a id * \param[in] id The control numerical ID
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> --- include/libcamera/controls.h | 10 ++++++++++ src/libcamera/controls.cpp | 6 ++++++ 2 files changed, 16 insertions(+)