]> git.tdb.fi Git - libs/core.git/commitdiff
Move non-oneliner functions out of RefPtr class declaration
authorMikko Rasa <tdb@tdb.fi>
Sat, 6 Feb 2021 09:55:56 +0000 (11:55 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 6 Feb 2021 09:57:55 +0000 (11:57 +0200)
source/core/refptr.h

index 8ab1b7cbfbdb6e752afd4b7634e807a8a836e10a..28666ea816380e0547205a1f6d83b14da0e13016 100644 (file)
@@ -45,14 +45,7 @@ public:
 
        ~RefPtr() { decref(); }
 
-       RefPtr &operator=(T *d)
-       {
-               decref();
-               data = d;
-               counts = (d ? new RefCounts : 0);
-               incref();
-               return *this;
-       }
+       RefPtr &operator=(T *);
 
        // Likewise for the assignment operator
        RefPtr &operator=(const RefPtr &p) { return assign(p); }
@@ -62,35 +55,17 @@ public:
 
 private:
        template<typename U>
-       RefPtr &assign(const RefPtr<U> &p)
-       {
-               decref();
-               data = p.data;
-               counts = p.counts;
-               incref();
-               return *this;
-       }
+       RefPtr &assign(const RefPtr<U> &);
 
 public:
        /** Makes the RefPtr release its reference of the data without deleting it.
        Note that if there are other RefPtrs left with the same data, it might
        still get deleted automatically. */
-       T *release()
-       {
-               T *d = data;
-               data = 0;
-               decref();
-               counts = 0;
-               return d;
-       }
+       T *release();
 
        /** Marks the data to not be deleted.  This affects all RefPtrs with the
        same data. */
-       void keep()
-       {
-               if(counts)
-                       counts->count |= RefCounts::KEEP;
-       }
+       void keep() { if(counts) counts->count |= RefCounts::KEEP; }
 
        T *get() const { return data; }
        T &operator*() const { return *data; }
@@ -104,31 +79,61 @@ public:
        { return RefPtr<T>(dynamic_cast<T *>(p.data), p.counts); }
 
 private:
-       void incref()
+       void incref() { if(counts) ++counts->count; }
+       void decref();
+};
+
+
+template<typename T>
+RefPtr<T> &RefPtr<T>::operator=(T *d)
+{
+       decref();
+       data = d;
+       counts = (d ? new RefCounts : 0);
+       incref();
+       return *this;
+}
+
+template<typename T>
+template<typename U>
+RefPtr<T> &RefPtr<T>::assign(const RefPtr<U> &p)
+{
+       decref();
+       data = p.data;
+       counts = p.counts;
+       incref();
+       return *this;
+}
+
+template<typename T>
+T *RefPtr<T>::release()
+{
+       T *d = data;
+       data = 0;
+       decref();
+       counts = 0;
+       return d;
+}
+
+template<typename T>
+void RefPtr<T>::decref()
+{
+       if(!counts) return;
+       --counts->count;
+       if(!counts->count)
        {
-               if(!counts) return;
-               ++counts->count;
+               delete data;
+               delete counts;
+               data = 0;
+               counts = 0;
        }
-
-       void decref()
+       else if(counts->count==RefCounts::KEEP)
        {
-               if(!counts) return;
-               --counts->count;
-               if(!counts->count)
-               {
-                       delete data;
-                       delete counts;
-                       data = 0;
-                       counts = 0;
-               }
-               else if(counts->count==RefCounts::KEEP)
-               {
-                       delete counts;
-                       data = 0;
-                       counts = 0;
-               }
+               delete counts;
+               data = 0;
+               counts = 0;
        }
-};
+}
 
 } // namespace Msp