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>
12 #include <lib/base/elock.h>
19 /* we don't allow the default operator here, as it would break the refcount. */
20 void operator=(const iObject &);
22 virtual ~iObject() { }
24 virtual void AddRef()=0;
25 virtual void Release()=0;
32 oRefCount(): ref(0) { }
33 operator int&() { return ref; }
36 if (ref) eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, ref); else eDebug("OBJECT_DEBUG refcount ok! (%p)", this);
42 #define DECLARE_REF(x) private: eSingleLock ref_lock; oRefCount ref; public: void AddRef(); void Release();
44 extern int object_total_remaining;
45 #define DEFINE_REF(c) void c::AddRef() { eSingleLocker l(ref_lock); ++object_total_remaining; ++ref; eDebug("OBJECT_DEBUG " #c "+%p now %d", this, (int)ref); } void c::Release() { { eSingleLocker l(ref_lock); --object_total_remaining; --ref; eDebug("OBJECT_DEBUG " #c "-%p now %d", this, ref); } if (!ref) delete this; }
46 #error fix locking for debug
48 #define DEFINE_REF(c) void c::AddRef() { eSingleLocker l(ref_lock); ++ref; } void c::Release() { { eSingleLocker l(ref_lock); --ref; } if (!ref) delete this; }
51 #define DECLARE_REF(x) private: void AddRef(); void Release();