[v2,5/5] libcamera: controls: Add rvalue overload for `ControlList::set()`
diff mbox series

Message ID 20250421153556.171192-6-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: controls: Move constructor/assignment + swap
Related show

Commit Message

Barnabás Pőcze April 21, 2025, 3:35 p.m. UTC
Add an overload of `ControlList::set()` that takes the `ControlValue` argument
as an rvalue reference, therefore enabling the use of move assignment.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/controls.h |  1 +
 src/libcamera/controls.cpp   | 12 ++++++++++++
 2 files changed, 13 insertions(+)

Comments

Kieran Bingham April 28, 2025, 7:27 a.m. UTC | #1
Quoting Barnabás Pőcze (2025-04-21 16:35:56)
> Add an overload of `ControlList::set()` that takes the `ControlValue` argument
> as an rvalue reference, therefore enabling the use of move assignment.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  include/libcamera/controls.h |  1 +
>  src/libcamera/controls.cpp   | 12 ++++++++++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 62ee5ebd6..611252f20 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -516,6 +516,7 @@ public:
>  
>         const ControlValue &get(unsigned int id) const;
>         void set(unsigned int id, const ControlValue &value);
> +       void set(unsigned int id, ControlValue &&value);
>  
>         const ControlInfoMap *infoMap() const { return infoMap_; }
>         const ControlIdMap *idMap() const { return idmap_; }
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index ae54f8c77..c22c6bdb9 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -1189,6 +1189,18 @@ void ControlList::set(unsigned int id, const ControlValue &value)
>         *val = value;
>  }
>  
> +/**
> + * \copydoc ControlList::set(unsigned int, const ControlValue &)
> + */
> +void ControlList::set(unsigned int id, ControlValue &&value)
> +{
> +       ControlValue *val = find(id);
> +       if (!val)
> +               return;

Should we be reporting an error or log message here?
Though ControlList::set(unsigned int, const ControlValue &) doesn't -

Aha, never mind, I see it would be reported accordingly in ::find().

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +
> +       *val = std::move(value);
> +}
> +
>  /**
>   * \fn ControlList::infoMap()
>   * \brief Retrieve the ControlInfoMap used to construct the ControlList
> -- 
> 2.49.0
>

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 62ee5ebd6..611252f20 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -516,6 +516,7 @@  public:
 
 	const ControlValue &get(unsigned int id) const;
 	void set(unsigned int id, const ControlValue &value);
+	void set(unsigned int id, ControlValue &&value);
 
 	const ControlInfoMap *infoMap() const { return infoMap_; }
 	const ControlIdMap *idMap() const { return idmap_; }
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index ae54f8c77..c22c6bdb9 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -1189,6 +1189,18 @@  void ControlList::set(unsigned int id, const ControlValue &value)
 	*val = value;
 }
 
+/**
+ * \copydoc ControlList::set(unsigned int, const ControlValue &)
+ */
+void ControlList::set(unsigned int id, ControlValue &&value)
+{
+	ControlValue *val = find(id);
+	if (!val)
+		return;
+
+	*val = std::move(value);
+}
+
 /**
  * \fn ControlList::infoMap()
  * \brief Retrieve the ControlInfoMap used to construct the ControlList