aboutsummaryrefslogtreecommitdiff
path: root/lib/base
diff options
context:
space:
mode:
authorFelix Domke <tmbinc@elitedvb.net>2005-07-12 14:00:01 +0000
committerFelix Domke <tmbinc@elitedvb.net>2005-07-12 14:00:01 +0000
commite39c12fcbf218f0964782a48d6e66145e1ce5039 (patch)
tree24e8efbaa96d7c180fd750a38078fbc19c066eae /lib/base
parent98c4b5bb004e9297bffa8e1c3572572741fda933 (diff)
downloadenigma2-e39c12fcbf218f0964782a48d6e66145e1ce5039.tar.gz
enigma2-e39c12fcbf218f0964782a48d6e66145e1ce5039.zip
- add eUsePtr for eDVBChannels
Diffstat (limited to 'lib/base')
-rw-r--r--lib/base/smartptr.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/base/smartptr.h b/lib/base/smartptr.h
index 159eeb2c..7e441ab2 100644
--- a/lib/base/smartptr.h
+++ b/lib/base/smartptr.h
@@ -66,6 +66,81 @@ public:
};
+template<class T>
+class eUsePtr
+{
+protected:
+ T *ptr;
+public:
+ T &operator*() { return *ptr; }
+ eUsePtr(): ptr(0)
+ {
+ }
+ eUsePtr(T *c): ptr(c)
+ {
+ if (c)
+ {
+ c->AddRef();
+ c->AddUse();
+ }
+ }
+ eUsePtr(const eUsePtr &c)
+ {
+ ptr=c.ptr;
+ if (ptr)
+ {
+ ptr->AddRef();
+ ptr->AddUse();
+ }
+ }
+ eUsePtr &operator=(T *c)
+ {
+ if (c)
+ {
+ c->AddRef();
+ c->AddUse();
+ }
+ if (ptr)
+ {
+ ptr->ReleaseUse();
+ ptr->Release();
+ }
+ ptr=c;
+ return *this;
+ }
+
+ eUsePtr &operator=(eUsePtr<T> &c)
+ {
+ if (c.ptr)
+ {
+ c.ptr->AddRef();
+ c.ptr->AddUse();
+ }
+ if (ptr)
+ {
+ ptr->ReleaseUse();
+ ptr->Release();
+ }
+ ptr=c.ptr;
+ return *this;
+ }
+
+ ~eUsePtr()
+ {
+ if (ptr)
+ {
+ ptr->ReleaseUse();
+ ptr->Release();
+ }
+ }
+
+ T* grabRef() { if (!ptr) return 0; ptr->AddRef(); ptr->AddUse(); return ptr; }
+ T* &ptrref() { assert(!ptr); return ptr; }
+ T* operator->() const { assert(ptr); return ptr; }
+ operator T*() const { return this->ptr; }
+};
+
+
#ifndef SWIG
template<class T>