[RFC PATCH 03/11] ipa: libipa: vector: Add copy constructor and assignment operator

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sun Nov 17 23:17:04 CET 2024


It is useful to assign a value to an existing vector. Define a copy
constructor and a copy assignment operator.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/ipa/libipa/vector.cpp | 13 +++++++++++++
 src/ipa/libipa/vector.h   | 13 +++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp
index f14f155216f3..df089f8aed9f 100644
--- a/src/ipa/libipa/vector.cpp
+++ b/src/ipa/libipa/vector.cpp
@@ -40,6 +40,19 @@ namespace ipa {
  * The size of \a data must be equal to the dimension size Rows of the vector.
  */
 
+/**
+ * \fn Vector::Vector(const Vector &other)
+ * \brief Construct a Vector by copying \a other
+ * \param[in] other The other Vector value
+ */
+
+/**
+ * \fn Vector &Vector::operator=(const Vector &other)
+ * \brief Replace the content of the Vector with a copy of the content of \a other
+ * \param[in] other The other Vector value
+ * \return This Vector value
+ */
+
 /**
  * \fn T Vector::operator[](size_t i) const
  * \brief Index to an element in the vector
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
index b72ab9851aa3..50e16250acfd 100644
--- a/src/ipa/libipa/vector.h
+++ b/src/ipa/libipa/vector.h
@@ -6,6 +6,7 @@
  */
 #pragma once
 
+#include <algorithm>
 #include <array>
 #include <cmath>
 #include <optional>
@@ -41,6 +42,18 @@ public:
 			data_[i] = data[i];
 	}
 
+	Vector(const Vector &other)
+		: data_(other.data_)
+	{
+	}
+
+	Vector &operator=(const Vector &other)
+	{
+		data_ = other.data_;
+
+		return *this;
+	}
+
 	const T &operator[](size_t i) const
 	{
 		ASSERT(i < data_.size());
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list