]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/refptr.h
Drop copyright and license notices from source files
[libs/core.git] / source / core / refptr.h
index ddada0b0b64ae92535c4d4a1c1160330fd6569b3..d245b34a7e90bab8fb14f5e26cc691a1385f761c 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspcore
-Copyright © 2006-2007, 2010 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef MSP_CORE_REFPTR_H_
 #define MSP_CORE_REFPTR_H_
 
@@ -17,22 +10,33 @@ destroyed, the data is deleted as well.
 template<typename T>
 class RefPtr
 {
+       template<typename U> friend class RefPtr;
+
 private:
        enum
        {
                KEEP = 1U<<(sizeof(unsigned)*8-1)
        };
 
+       T *data;
+       unsigned *count;
+
 public:
        RefPtr(): data(0), count(0) { }
        RefPtr(T *d): data(d), count(data ? new unsigned(1) : 0) { }
+private:
+       RefPtr(T *d, unsigned *c): data(d), count(d ? c : 0) { incref(); }
 
-       // Must have this or the compiler will generate a default copy-c'tor
+public:
+       /* Must have this or the compiler will generate a default copy-c'tor despite
+       the template version */
        RefPtr(const RefPtr &p): data(p.data), count(p.count) { incref(); }
 
        template<typename U>
        RefPtr(const RefPtr<U> &p): data(p.data), count(p.count) { incref(); }
 
+       ~RefPtr() { decref(); }
+
        RefPtr &operator=(T *d)
        {
                decref();
@@ -46,14 +50,22 @@ public:
 
        template<typename U>
        RefPtr &operator=(const RefPtr<U> &p) { return assign(p); }
-       
-       ~RefPtr() { decref(); }
 
-       /**
-       Makes the RefPtr release its reference of the data.  Note that if there are
-       other RefPtrs left with the same data, it might still get deleted
-       automatically.
-       */
+private:
+       template<typename U>
+       RefPtr &assign(const RefPtr<U> &p)
+       {
+               decref();
+               data = p.data;
+               count = p.count;
+               incref();
+               return *this;
+       }
+
+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;
@@ -63,10 +75,8 @@ public:
                return d;
        }
 
-       /**
-       Marks the data to not be deleted.  This affects all RefPtrs with the same
-       data.
-       */
+       /** Marks the data to not be deleted.  This affects all RefPtrs with the
+       same data. */
        void keep()
        {
                if(count)
@@ -82,23 +92,7 @@ public:
        static RefPtr<T> cast_dynamic(const RefPtr<U> &p)
        { return RefPtr<T>(dynamic_cast<T *>(p.data), p.count); }
 
-       template<typename U> friend class RefPtr;
 private:
-       T *data;
-       unsigned *count;
-
-       RefPtr(T *d, unsigned *c): data(d), count(d ? c : 0) { incref(); }
-
-       template<typename U>
-       RefPtr &assign(const RefPtr<U> &p)
-       {
-               decref();
-               data = p.data;
-               count = p.count;
-               incref();
-               return *this;
-       }
-
        void incref()
        {
                if(!count) return;