[RFC PATCH v2 03/12] ipa: libipa: vector: Add copy constructor and assignment operator
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon Nov 18 14:09:37 CET 2024
On Mon, Nov 18, 2024 at 01:23:06PM +0100, Milan Zamazal wrote:
> Laurent Pinchart <laurent.pinchart at ideasonboard.com> writes:
>
> > 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>
>
> Is this needed for copying the array?
No, it's not needed. It belongs to patch 05/12. I'll move it there.
> Reviewed-by: Milan Zamazal <mzamazal at redhat.com>
>
> > #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