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>
This commit is contained in:
Laurent Pinchart
2020-02-27 01:05:59 +02:00
parent 1fa4b43402
commit 3556ae95ec
2 changed files with 16 additions and 0 deletions

View File

@@ -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);

View File

@@ -802,6 +802,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