| Message ID | 20260903091843.85548-5-barnabas.pocze@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
On Thu, Sep 03, 2026 at 11:18:42AM +0200, Barnabás Pőcze wrote: > Implement both free and member function `swap()` for `ControlValue`. > The general `std::swap()` swaps two values by combining a move construction > and two move assignments, but for `ControlValue` a simpler implementation > can be provided by just swapping the members. > > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > include/libcamera/controls.h | 13 +++++++++++++ > src/libcamera/controls.cpp | 15 +++++++++++++++ > 2 files changed, 28 insertions(+) > > diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h > index aef17abe07..190a28970c 100644 > --- a/include/libcamera/controls.h > +++ b/include/libcamera/controls.h > @@ -264,6 +264,19 @@ public: > void reserve(ControlType type, bool isArray = false, > std::size_t numElements = 1); > > + void swap(ControlValue &other) noexcept > + { > + std::swap(type_, other.type_); > + std::swap(isArray_, other.isArray_); > + std::swap(numElements_, other.numElements_); > + std::swap(storage_, other.storage_); > + } > + > + friend void swap(ControlValue &a, ControlValue &b) noexcept > + { > + a.swap(b); > + } > + > private: > ControlType type_; > bool isArray_; > diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp > index 588b609373..242072778b 100644 > --- a/src/libcamera/controls.cpp > +++ b/src/libcamera/controls.cpp > @@ -413,6 +413,21 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen > storage_.external = new uint8_t[newSize]; > } > > +/** > + * \fn ControlValue::swap(ControlValue &other) noexcept > + * \brief Swap two control values > + * > + * This function swaps the contained value of \a this with that of \a other. > + */ > + > +/** > + * \fn ControlValue::swap(ControlValue &a, ControlValue &b) noexcept > + * \brief Swap two control values > + * > + * This function swaps the contained value of \a a with that of \a b. > + * \sa ControlValue::swap() > + */ > + > /** > * \class ControlId > * \brief Control static metadata
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index aef17abe07..190a28970c 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -264,6 +264,19 @@ public: void reserve(ControlType type, bool isArray = false, std::size_t numElements = 1); + void swap(ControlValue &other) noexcept + { + std::swap(type_, other.type_); + std::swap(isArray_, other.isArray_); + std::swap(numElements_, other.numElements_); + std::swap(storage_, other.storage_); + } + + friend void swap(ControlValue &a, ControlValue &b) noexcept + { + a.swap(b); + } + private: ControlType type_; bool isArray_; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 588b609373..242072778b 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -413,6 +413,21 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen storage_.external = new uint8_t[newSize]; } +/** + * \fn ControlValue::swap(ControlValue &other) noexcept + * \brief Swap two control values + * + * This function swaps the contained value of \a this with that of \a other. + */ + +/** + * \fn ControlValue::swap(ControlValue &a, ControlValue &b) noexcept + * \brief Swap two control values + * + * This function swaps the contained value of \a a with that of \a b. + * \sa ControlValue::swap() + */ + /** * \class ControlId * \brief Control static metadata