1 #ifndef __base_object_h
2 #define __base_object_h
6 // #define OBJECT_DEBUG
8 #include <lib/base/smartptr.h>
10 #include <lib/base/eerror.h>
18 /* we don't allow the default operator here, as it would break the refcount. */
19 void operator=(const iObject &);
21 virtual ~iObject() { }
23 virtual void AddRef()=0;
24 virtual void Release()=0;
31 oRefCount(): ref(0) { }
32 operator int&() { return ref; }
35 if (ref) eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, ref); else eDebug("OBJECT_DEBUG refcount ok! (%p)", this);
41 #define DECLARE_REF(x) private: oRefCount ref; public: void AddRef(); void Release();
43 extern int object_total_remaining;
44 #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; }
46 #define DEFINE_REF(c) void c::AddRef() { ++ref; } void c::Release() { if (!--ref) delete this; }
49 #define DECLARE_REF(x) private: void AddRef(); void Release();