[glibmm] Glib::RefPtr: add "release()" method
- From: Marcin Kolny <mkolny src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Glib::RefPtr: add "release()" method
- Date: Mon, 27 Jul 2015 20:14:30 +0000 (UTC)
commit 07ba42710cc2f7d15c070c44a4d1c1c64d66de61
Author: Marcin Kolny <marcin kolny gmail com>
Date: Fri Jul 24 09:26:47 2015 +0200
Glib::RefPtr: add "release()" method
https://bugzilla.gnome.org/show_bug.cgi?id=752812
* glib/glibmm/refptr.h: "release" method gives an access to managed
underlying object, releasing RefPtr's ownership. Method is useful
e.g. in wrappers of functions containing transfer-full arguments.
glib/glibmm/refptr.h | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/glib/glibmm/refptr.h b/glib/glibmm/refptr.h
index 1aca555..4a23d96 100644
--- a/glib/glibmm/refptr.h
+++ b/glib/glibmm/refptr.h
@@ -132,6 +132,13 @@ public:
*/
inline void reset();
+ /** Release the ownership of underlying instance.
+ *
+ * RefPtr's underlying instance is set to nullptr, therefore underlying object can't be accessed through
this RefPtr anymore.
+ * @return an underlying instance.
+ */
+ inline T_CppObject* release() __attribute__((warn_unused_result));
+
/** Dynamic cast to derived class.
*
* The RefPtr can't be cast with the usual notation so instead you can use
@@ -355,6 +362,14 @@ void RefPtr<T_CppObject>::reset()
this->swap(temp);
}
+template <class T_CppObject> inline
+T_CppObject* RefPtr<T_CppObject>::release()
+{
+ T_CppObject *tmp = pCppObject_;
+ pCppObject_ = nullptr;
+ return tmp;
+}
+
template <class T_CppObject>
template <class T_CastFrom>
inline
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]