aboutsummaryrefslogtreecommitdiff
path: root/lib/base/object.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/base/object.h')
-rw-r--r--lib/base/object.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/base/object.h b/lib/base/object.h
new file mode 100644
index 00000000..744bff19
--- /dev/null
+++ b/lib/base/object.h
@@ -0,0 +1,30 @@
+#ifndef __base_object_h
+#define __base_object_h
+
+#include <assert.h>
+
+// #define OBJECT_DEBUG
+
+#include <lib/base/smartptr.h>
+#ifdef OBJECT_DEBUG
+#include <lib/base/eerror.h>
+#endif
+
+typedef int RESULT;
+
+class iObject
+{
+public:
+ virtual void AddRef()=0;
+ virtual void Release()=0;
+};
+
+#define DECLARE_REF private: int ref; public: void AddRef(); void Release();
+#ifdef OBJECT_DEBUG
+extern int object_total_remaining;
+#define DEFINE_REF(c) void c::AddRef() { ++object_total_remaining; ++ref; eDebug("OBJECT_DEBUG " #c "+%p now %d", this, ref); } void c::Release() { --object_total_remaining; eDebug("OBJECT_DEBUG " #c "-%p now %d", this, ref-1); if (!--ref) delete this; }
+#else
+#define DEFINE_REF(c) void c::AddRef() { ++ref; } void c::Release() { if (!--ref) delete this; }
+#endif
+
+#endif