It will sometimes be needed to extract the ownership of a lib object
from a SharedObj, and get the underlying lib object pointer. For
example:
- The value returned by queries
- Messages returned by iterators
Add a SharedObj::release method for that. The return type is a borrowed
object (e.g. bt2::Value::Shared::release returns a bt2::Value), but
conceptually the caller then owns the reference and is responsible for
manually managing it.
After a release, a Shared object becomes invalid, same as when it is moved
from.
Change-Id: Id31855512b8dd3d5223f2e759ff48f81ceadbfbf
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8169
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10825
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
return &*_mObj;
}
+ /*
+ * Transfers the reference of the object which this shared object
+ * wrapper manages and returns it, making the caller become an active
+ * owner.
+ *
+ * This method makes this object invalid.
+ */
+ ObjT release() noexcept
+ {
+ BT_ASSERT_DBG(_mObj);
+ const auto obj = *_mObj;
+ this->_reset();
+ return obj;
+ }
+
private:
/*
* Resets this shared object.