]> git.tdb.fi Git - libs/core.git/commitdiff
Add a refcount function to RefPtr
authorMikko Rasa <tdb@tdb.fi>
Mon, 18 May 2020 23:27:15 +0000 (02:27 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 18 May 2020 23:27:15 +0000 (02:27 +0300)
Sometimes it may be useful to check if there are any other users for the
data.

source/core/refptr.h

index d245b34a7e90bab8fb14f5e26cc691a1385f761c..0328340eb242242b29fa614d0b7b815eddcc8f3b 100644 (file)
@@ -88,6 +88,8 @@ public:
        T *operator->() const { return data; }
        operator bool() const { return data!=0; }
 
+       unsigned refcount() const { return (data ? *count : 0); }
+
        template<typename U>
        static RefPtr<T> cast_dynamic(const RefPtr<U> &p)
        { return RefPtr<T>(dynamic_cast<T *>(p.data), p.count); }