mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-21 23:55:07 +03:00
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:
parent
cd04b9a96c
commit
5eaf4fed19
2 changed files with 9 additions and 11 deletions
|
@ -42,7 +42,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const T &get() const;
|
T get() const;
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void set(const T &value);
|
void set(const T &value);
|
||||||
|
|
||||||
|
@ -212,13 +212,11 @@ public:
|
||||||
bool contains(unsigned int id) const;
|
bool contains(unsigned int id) const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const T &get(const Control<T> &ctrl) const
|
T get(const Control<T> &ctrl) const
|
||||||
{
|
{
|
||||||
const ControlValue *val = find(ctrl.id());
|
const ControlValue *val = find(ctrl.id());
|
||||||
if (!val) {
|
if (!val)
|
||||||
static T t(0);
|
return T{};
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
return val->get<T>();
|
return val->get<T>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ bool ControlValue::operator==(const ControlValue &other) const
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn template<typename T> const T &ControlValue::get() const
|
* \fn template<typename T> T ControlValue::get() const
|
||||||
* \brief Get the control value
|
* \brief Get the control value
|
||||||
*
|
*
|
||||||
* The control value type shall match the type T, otherwise the behaviour is
|
* The control value type shall match the type T, otherwise the behaviour is
|
||||||
|
@ -177,7 +177,7 @@ bool ControlValue::operator==(const ControlValue &other) const
|
||||||
|
|
||||||
#ifndef __DOXYGEN__
|
#ifndef __DOXYGEN__
|
||||||
template<>
|
template<>
|
||||||
const bool &ControlValue::get<bool>() const
|
bool ControlValue::get<bool>() const
|
||||||
{
|
{
|
||||||
ASSERT(type_ == ControlTypeBool);
|
ASSERT(type_ == ControlTypeBool);
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ const bool &ControlValue::get<bool>() const
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
const int32_t &ControlValue::get<int32_t>() const
|
int32_t ControlValue::get<int32_t>() const
|
||||||
{
|
{
|
||||||
ASSERT(type_ == ControlTypeInteger32);
|
ASSERT(type_ == ControlTypeInteger32);
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ const int32_t &ControlValue::get<int32_t>() const
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
const int64_t &ControlValue::get<int64_t>() const
|
int64_t ControlValue::get<int64_t>() const
|
||||||
{
|
{
|
||||||
ASSERT(type_ == ControlTypeInteger64);
|
ASSERT(type_ == ControlTypeInteger64);
|
||||||
|
|
||||||
|
@ -720,7 +720,7 @@ bool ControlList::contains(unsigned int id) const
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn template<typename T> const T &ControlList::get(const Control<T> &ctrl) const
|
* \fn template<typename T> T ControlList::get(const Control<T> &ctrl) const
|
||||||
* \brief Get the value of control \a ctrl
|
* \brief Get the value of control \a ctrl
|
||||||
* \param[in] ctrl The control
|
* \param[in] ctrl The control
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue