- add more python stuff
[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 public:
18         virtual void AddRef()=0;
19         virtual void Release()=0;
20 };
21
22 class oRefCount
23 {
24         int ref;
25 public:
26         oRefCount(): ref(0) { }
27         operator int&() { return ref; }
28 };
29
30 #define DECLARE_REF private: oRefCount ref; public: void AddRef(); void Release();
31 #ifdef OBJECT_DEBUG
32 extern int object_total_remaining;
33 #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; }
34 #else
35 #define DEFINE_REF(c) void c::AddRef() { ++ref; } void c::Release() { if (!--ref) delete this; }
36 #endif
37
38 #endif