(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp cpp_gui
authorKUDr
Sat, 17 Feb 2007 13:06:08 +0000
branchcpp_gui
changeset 6256 220cd0db67a4
parent 6255 7215bc7cb877
child 6257 2ffe947969ca
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
projects/openttd.vcproj
projects/openttd_vs80.vcproj
source.list
src/misc/countedobj.cpp
src/misc/countedptr.hpp
src/window.cpp
src/window.h
--- a/projects/openttd.vcproj	Sat Feb 17 13:01:45 2007 +0000
+++ b/projects/openttd.vcproj	Sat Feb 17 13:06:08 2007 +0000
@@ -1033,6 +1033,9 @@
 				RelativePath=".\..\src\misc\blob.hpp">
 			</File>
 			<File
+				RelativePath=".\..\src\misc\countedobj.cpp">
+			</File>
+			<File
 				RelativePath=".\..\src\misc\countedptr.hpp">
 			</File>
 			<File
--- a/projects/openttd_vs80.vcproj	Sat Feb 17 13:01:45 2007 +0000
+++ b/projects/openttd_vs80.vcproj	Sat Feb 17 13:06:08 2007 +0000
@@ -1316,6 +1316,9 @@
 				RelativePath=".\..\src\misc\blob.hpp">
 			</File>
 			<File
+				RelativePath=".\..\src\misc\countedobj.cpp">
+			</File>
+			<File
 				RelativePath=".\..\src\misc\countedptr.hpp">
 			</File>
 			<File
--- a/source.list	Sat Feb 17 13:01:45 2007 +0000
+++ b/source.list	Sat Feb 17 13:06:08 2007 +0000
@@ -316,6 +316,7 @@
 misc/autoptr.hpp
 misc/binaryheap.hpp
 misc/blob.hpp
+misc/countedobj.cpp
 misc/countedptr.hpp
 misc/crc32.hpp
 misc/fixedsizearray.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/misc/countedobj.cpp	Sat Feb 17 13:06:08 2007 +0000
@@ -0,0 +1,20 @@
+#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;
+}
+
--- a/src/misc/countedptr.hpp	Sat Feb 17 13:01:45 2007 +0000
+++ b/src/misc/countedptr.hpp	Sat Feb 17 13:06:08 2007 +0000
@@ -96,5 +96,31 @@
 	}
 }
 
+/** Simple counted object. Use it as base of your struct/class if you want to use
+ *  basic reference counting. Your struct/class will destroy and free itself when
+ *  last reference to it is released (using Relese() method). The initial reference
+ *  count (when it is created) is zero (don't forget AddRef() at least one time if
+ *  not using CCountedPtr<T>.
+ *
+ *  @see misc/countedobj.cpp for implementation.
+ */
+struct SimpleCountedObject {
+	int32 m_ref_cnt;
+
+	SimpleCountedObject()
+		: m_ref_cnt(0)
+	{}
+
+	virtual ~SimpleCountedObject()
+	{};
+
+	virtual int32 AddRef();
+	virtual int32 Release();
+	virtual void FinalRelease() {};
+};
+
+
+
+
 #endif /* 0 */
 #endif /* COUNTEDPTR_HPP */
--- a/src/window.cpp	Sat Feb 17 13:01:45 2007 +0000
+++ b/src/window.cpp	Sat Feb 17 13:06:08 2007 +0000
@@ -25,22 +25,6 @@
 //Window *_z_windows[lengthof(_windows)];
 //Window **_last_z_window; ///< always points to the next free space in the z-array
 
-int32 CountedObject::AddRef()
-{
-	return ++m_ref_cnt;
-}
-
-int32 CountedObject::Release()
-{
-	int32 res = --m_ref_cnt;
-	assert(res >= 0);
-	if (res == 0) {
-		FinalRelease();
-		delete this;
-	}
-	return res;
-}
-
 void WindowList::Add(Window *w)
 {
 	/* we will add the new window before first vital window or at the end */
--- a/src/window.h	Sat Feb 17 13:01:45 2007 +0000
+++ b/src/window.h	Sat Feb 17 13:06:08 2007 +0000
@@ -268,21 +268,6 @@
 		int lparam;
 } WindowMessage;
 
-struct CountedObject {
-	int32 m_ref_cnt;
-
-	CountedObject()
-		: m_ref_cnt(0)
-	{}
-
-	virtual ~CountedObject()
-	{};
-
-	virtual int32 AddRef();
-	virtual int32 Release();
-	virtual void FinalRelease() {};
-};
-
 struct Window;
 typedef CCountedPtr<Window> WindowPtr;
 
@@ -350,7 +335,7 @@
 	}
 };
 
-struct Window : public CountedObject {
+struct Window : public SimpleCountedObject {
 public:
 	static WindowList s_list;
 
@@ -469,7 +454,7 @@
 	//		default: break;
 	//	}
 	//	if (name != NULL) printf("%s+\n", name);
-	//	return CountedObject::AddRef();
+	//	return SimpleCountedObject::AddRef();
 	//}
 
 	//int32 Release()
@@ -483,7 +468,7 @@
 	//		default: break;
 	//	}
 	//	if (name != NULL) printf("%s-\n", name);
-	//	return CountedObject::Release();
+	//	return SimpleCountedObject::Release();
 	//}
 
 	template <class Tmatch> struct EnumMatch {