diff options
-rw-r--r-- | glib/glibmm/refptr.h | 16 | ||||
-rw-r--r-- | 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 981dd796..74ed0413 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 53a74492..4caea0c5 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 |