summaryrefslogtreecommitdiff
path: root/src/libcamera/base
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-08-11 19:34:44 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-08-16 23:57:27 +0300
commite77c8951e9ff91bf2bacf81791a882ccb3cee30b (patch)
treeac66ba86468ae1aa5ad619c5fb276687aee65677 /src/libcamera/base
parent5420e359f2416f6d290eea626dddb3a881dd900c (diff)
libcamera: base: extensible: Pass private pointer as unique_ptr<>
The Extensible constructor takes a pointer to a Private instance, whose lifetime it then manages. Make this explicit in the API by passing the pointer as a std::unique_ptr<Private>. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/libcamera/base')
-rw-r--r--src/libcamera/base/class.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libcamera/base/class.cpp b/src/libcamera/base/class.cpp
index d24043c2..9c2d9f21 100644
--- a/src/libcamera/base/class.cpp
+++ b/src/libcamera/base/class.cpp
@@ -147,9 +147,12 @@ namespace libcamera {
/**
* \brief Construct an instance of an Extensible class
* \param[in] d Pointer to the private data instance
+ *
+ * The private data lifetime is managed by the Extensible class, which destroys
+ * it when the Extensible instance is destroyed.
*/
-Extensible::Extensible(Extensible::Private *d)
- : d_(d)
+Extensible::Extensible(std::unique_ptr<Extensible::Private> d)
+ : d_(std::move(d))
{
*const_cast<Extensible **>(&d_->o_) = this;
}
@@ -163,6 +166,10 @@ Extensible::Extensible(Extensible::Private *d)
* overriden _d() functions that return the correct pointer type to the
* corresponding derived Private class.
*
+ * The lifetime of the private data is tied to the Extensible class. The caller
+ * shall not retain any reference to the returned pointer for longer than it
+ * holds a reference to the Extensible instance.
+ *
* \return A pointer to the private data instance
*/