00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KEOS_SMARTPTRPOLICIES_H
00023 #define KEOS_SMARTPTRPOLICIES_H
00024
00025 #include "KeosPrerequisites.h"
00026
00027 namespace Keos
00028 {
00029
00033 template <class T>
00034 class CRefCount
00035 {
00036 public :
00037
00041 CRefCount() : m_pCounter(new int(1))
00042 {}
00043
00047 T* Clone(T* Ptr)
00048 {
00049 ++*m_pCounter;
00050 return Ptr;
00051 }
00052
00056 void Release(T* pPtr)
00057 {
00058 if (--*m_pCounter == 0)
00059 {
00060 delete m_pCounter;
00061 delete pPtr;
00062 }
00063 }
00064
00068 void Swap(CRefCount& RefCount)
00069 {
00070 std::swap(RefCount.m_pCounter, m_pCounter);
00071 }
00072
00073 private :
00074
00076 int* m_pCounter;
00077 };
00078
00079
00080
00084 template <class T>
00085 class CCOMRefCounted
00086 {
00087 public :
00088
00092 static T* Clone(T* pPtr)
00093 {
00094 if (pPtr)
00095 pPtr->AddRef();
00096 return pPtr;
00097 }
00098
00102 static void Release(T* pPtr)
00103 {
00104 if (pPtr)
00105 pPtr->Release();
00106 }
00107
00111 static void Swap(CCOMRefCounted&)
00112 {}
00113 };
00114
00115 }
00116 ;
00117
00118 #endif // KEOS_SMARTPTRPOLICIES_H