X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Frefptr.h;fp=source%2Fcore%2Frefptr.h;h=34560ec0389beea43bbfb66fe2db1bd111bb954a;hp=70cb17607361364de990f8828643f80af8d8da00;hb=41363aed34382386f915f17c1a961750b4fdcb14;hpb=26a5878092f6547e701fd1a33abbf1878d26ab70 diff --git a/source/core/refptr.h b/source/core/refptr.h index 70cb176..34560ec 100644 --- a/source/core/refptr.h +++ b/source/core/refptr.h @@ -31,14 +31,14 @@ class RefPtr template friend class WeakPtr; private: - T *data = 0; - RefCounts *counts = 0; + T *data = nullptr; + RefCounts *counts = nullptr; public: RefPtr() = default; - RefPtr(T *d): data(d), counts(data ? new RefCounts : 0) { incref(); } + RefPtr(T *d): data(d), counts(data ? new RefCounts : nullptr) { incref(); } private: - RefPtr(T *d, RefCounts *c): data(d), counts(d ? c : 0) { incref(); } + RefPtr(T *d, RefCounts *c): data(d), counts(d ? c : nullptr) { incref(); } public: /* Must have this or the compiler will generate a default copy-c'tor despite @@ -49,7 +49,7 @@ public: RefPtr(const RefPtr &p): data(p.data), counts(p.counts) { incref(); } template - RefPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : 0) { incref(); } + RefPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : nullptr) { incref(); } ~RefPtr() { decref(); } @@ -81,7 +81,7 @@ public: T *get() const { return data; } T &operator*() const { return *data; } T *operator->() const { return data; } - explicit operator bool() const { return data!=0; } + explicit operator bool() const { return data; } unsigned refcount() const { return (data ? counts->count : 0); } @@ -102,19 +102,19 @@ class WeakPtr template friend class WeakPtr; private: - T *data = 0; - RefCounts *counts = 0; + T *data = nullptr; + RefCounts *counts = nullptr; public: WeakPtr() = default; private: - WeakPtr(T *d, RefCounts *c): data(d), counts(d ? c : 0) { incref(); } + WeakPtr(T *d, RefCounts *c): data(d), counts(d ? c : nullptr) { incref(); } public: - WeakPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : 0) { incref(); } + WeakPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : nullptr) { incref(); } template - WeakPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : 0) { incref(); } + WeakPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : nullptr) { incref(); } template WeakPtr(const RefPtr &p): data(p.data), counts(p.counts) { incref(); } @@ -131,7 +131,7 @@ private: template WeakPtr &assign(const WeakPtr &); - T *get() const { return (counts && counts->count ? data : 0); } + T *get() const { return (counts && counts->count ? data : nullptr); } void incref() { if(counts) ++counts->weak_count; } void decref(); }; @@ -142,7 +142,7 @@ RefPtr &RefPtr::operator=(T *d) { decref(); data = d; - counts = (d ? new RefCounts : 0); + counts = (d ? new RefCounts : nullptr); incref(); return *this; } @@ -162,9 +162,9 @@ template T *RefPtr::release() { T *d = data; - data = 0; + data = nullptr; decref(); - counts = 0; + counts = nullptr; return d; } @@ -176,17 +176,17 @@ void RefPtr::decref() if(!counts->count) { delete data; - data = 0; + data = nullptr; } else if(counts->count==RefCounts::KEEP) - data = 0; + data = nullptr; else return; if(!counts->weak_count) { delete counts; - counts = 0; + counts = nullptr; } } @@ -197,7 +197,7 @@ WeakPtr &WeakPtr::assign(const WeakPtr &p) { decref(); data = p.get(); - counts = (data ? p.counts : 0); + counts = (data ? p.counts : nullptr); incref(); return *this; } @@ -210,8 +210,8 @@ void WeakPtr::decref() if(!counts->weak_count && (!counts->count || counts->count==RefCounts::KEEP)) { delete counts; - data = 0; - counts = 0; + data = nullptr; + counts = nullptr; } }