libcamera: controls: Return control by value

The ControlList::get() and ControlValue::get() methods return the
control value by reference. This requires the ControlValue class to
store the control value in the same form as the one returned by those
functions. For the array controls that are soon to be added, the
ControlValue class would need to store a span<> instance in addition to
the control value itself, which would increase the required storage
space.

Prepare for support of array controls by returning from get() by value.
As all control values are 8 bytes at most, this doesn't affect
efficiency negatively.

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-15 22:44:03 +02:00
parent cd04b9a96c
commit 5eaf4fed19
2 changed files with 9 additions and 11 deletions

View file

@ -42,7 +42,7 @@ public:
}
template<typename T>
const T &get() const;
T get() const;
template<typename T>
void set(const T &value);
@ -212,13 +212,11 @@ public:
bool contains(unsigned int id) const;
template<typename T>
const T &get(const Control<T> &ctrl) const
T get(const Control<T> &ctrl) const
{
const ControlValue *val = find(ctrl.id());
if (!val) {
static T t(0);
return t;
}
if (!val)
return T{};
return val->get<T>();
}