- fixed dvb scan
[enigma2.git] / lib / base / object.h
1 #ifndef __base_object_h
2 #define __base_object_h
3
4 #include <assert.h>
5
6 // #define OBJECT_DEBUG
7
8 #include <lib/base/smartptr.h>
9 #ifdef OBJECT_DEBUG
10 #include <lib/base/eerror.h>
11 #endif
12
13 typedef int RESULT;
14
15 class iObject
16 {
17 private:
18                 /* we don't allow the default operator here, as it would break the refcount. */
19         void operator=(const iObject &);
20 protected:
21         virtual ~iObject() { }
22 public:
23         virtual void AddRef()=0;
24         virtual void Release()=0;
25 };
26
27 class oRefCount
28 {
29         int ref;
30 public:
31         oRefCount(): ref(0) { }
32         operator int&() { return ref; }
33         ~oRefCount() { 
34 #ifdef OBJECT_DEBUG
35                 if (ref) eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, ref); else eDebug("OBJECT_DEBUG refcount ok! (%p)", this); 
36 #endif
37         }
38 };
39
40 #define DECLARE_REF private: oRefCount ref; public: void AddRef(); void Release();
41 #ifdef OBJECT_DEBUG
42 extern int object_total_remaining;
43 #define DEFINE_REF(c) void c::AddRef() { ++object_total_remaining; ++ref; eDebug("OBJECT_DEBUG " #c "+%p now %d", this, (int)ref); } void c::Release() { --object_total_remaining; eDebug("OBJECT_DEBUG " #c "-%p now %d", this, ref-1); if (!--ref) delete this; }
44 #else
45 #define DEFINE_REF(c) void c::AddRef() { ++ref; } void c::Release() { if (!--ref) delete this; }
46 #endif
47
48 #endif