summaryrefslogtreecommitdiff
path: root/src/misc/countedobj.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-20 18:44:04 +0000
committerrubidium <rubidium@openttd.org>2007-07-20 18:44:04 +0000
commit478e009ac611c9d67f4c2d12b58b33abf44e3add (patch)
tree5f1f70f105e1d48e5c98012e8393a7374f6668e7 /src/misc/countedobj.cpp
parentf7682403e33612d9bb1b67c036f8129ffe4b2107 (diff)
downloadopenttd-478e009ac611c9d67f4c2d12b58b33abf44e3add.tar.xz
(svn r10644) -Merge (from NoAI): framework for reference counted objects (pointers).
Diffstat (limited to 'src/misc/countedobj.cpp')
-rw-r--r--src/misc/countedobj.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/misc/countedobj.cpp b/src/misc/countedobj.cpp
new file mode 100644
index 000000000..a96537977
--- /dev/null
+++ b/src/misc/countedobj.cpp
@@ -0,0 +1,66 @@
+/* $Id$ */
+
+#include "../stdafx.h"
+
+#include "countedptr.hpp"
+
+int32 SimpleCountedObject::AddRef()
+{
+ return ++m_ref_cnt;
+}
+
+int32 SimpleCountedObject::Release()
+{
+ int32 res = --m_ref_cnt;
+ assert(res >= 0);
+ if (res == 0) {
+ FinalRelease();
+ delete this;
+ }
+ return res;
+}
+
+/* $Id$ */
+
+#include "../stdafx.h"
+
+#include "countedptr.hpp"
+
+int32 SimpleCountedObject::AddRef()
+{
+ return ++m_ref_cnt;
+}
+
+int32 SimpleCountedObject::Release()
+{
+ int32 res = --m_ref_cnt;
+ assert(res >= 0);
+ if (res == 0) {
+ FinalRelease();
+ delete this;
+ }
+ return res;
+}
+
+/* $Id$ */
+
+#include "../stdafx.h"
+
+#include "countedptr.hpp"
+
+int32 SimpleCountedObject::AddRef()
+{
+ return ++m_ref_cnt;
+}
+
+int32 SimpleCountedObject::Release()
+{
+ int32 res = --m_ref_cnt;
+ assert(res >= 0);
+ if (res == 0) {
+ FinalRelease();
+ delete this;
+ }
+ return res;
+}
+