[glibmm/glibmm-2-56] Glib::RefPtr: Add get()
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/glibmm-2-56] Glib::RefPtr: Add get()
- Date: Wed, 21 Mar 2018 09:16:42 +0000 (UTC)
commit e5424da39f95898f1bcb628c87502fd3e462486f
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Wed Mar 21 10:13:20 2018 +0100
Glib::RefPtr: Add get()
Analogous to std::shared_ptr::get(). Bug 495762
glib/glibmm/refptr.h | 16 ++++++++++++++--
tests/glibmm_refptr/main.cc | 5 +++++
2 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/glib/glibmm/refptr.h b/glib/glibmm/refptr.h
index 981dd79..74ed041 100644
--- a/glib/glibmm/refptr.h
+++ b/glib/glibmm/refptr.h
@@ -42,7 +42,7 @@ namespace Glib
* RefPtr<> can store any class that has reference() and unreference() methods,
* and whose destructor is noexcept (the default for destructors).
* In gtkmm, that is anything derived from Glib::ObjectBase, such as
- * Gdk::Pixmap.
+ * Gdk::Pixbuf.
*
* See the "Memory Management" section in the "Programming with gtkmm"
* book for further information.
@@ -136,7 +136,7 @@ public:
template <class T_CastFrom>
inline RefPtr& operator=(RefPtr<T_CastFrom>&& src) noexcept;
- /** Copy from different, but castable type).
+ /** Copy from different, but castable type.
*
* Increments the reference count.
*/
@@ -156,6 +156,12 @@ public:
*/
inline T_CppObject* operator->() const noexcept;
+ /** Returns the stored pointer.
+ *
+ * @newin{2,56}
+ */
+ inline T_CppObject* get() const noexcept;
+
/** Test whether the RefPtr<> points to any underlying instance.
*
* Mimics usage of ordinary pointers:
@@ -396,6 +402,12 @@ RefPtr<T_CppObject>::operator!=(const RefPtr& src) const noexcept
}
template <class T_CppObject>
+inline T_CppObject* RefPtr<T_CppObject>::get() const noexcept
+{
+ return pCppObject_;
+}
+
+template <class T_CppObject>
inline RefPtr<T_CppObject>::operator bool() const noexcept
{
return (pCppObject_ != nullptr);
diff --git a/tests/glibmm_refptr/main.cc b/tests/glibmm_refptr/main.cc
index 53a7449..4caea0c 100644
--- a/tests/glibmm_refptr/main.cc
+++ b/tests/glibmm_refptr/main.cc
@@ -91,6 +91,11 @@ test_initial_refcount()
Glib::RefPtr<Something> refSomething(new Something());
g_assert_cmpint(refSomething->ref_count(), ==, 1);
g_assert_cmpint(refSomething->max_ref_count(), ==, 1);
+
+ // Test the get() method:
+ g_assert_cmpint(refSomething.get()->ref_count(), ==, 1);
+ refSomething.reset();
+ g_assert(refSomething.get() == nullptr);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]