00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SIMPLE_REF_COUNT_H
00023 #define SIMPLE_REF_COUNT_H
00024
00025 #include "empty.h"
00026 #include "default-deleter.h"
00027 #include <stdint.h>
00028
00029 namespace Binc {
00030
00061 template <typename T, typename PARENT = empty, typename DELETER = DefaultDeleter<T> >
00062 class SimpleRefCount : public PARENT
00063 {
00064 public:
00065 SimpleRefCount ()
00066 : m_count (1)
00067 {}
00068 SimpleRefCount (const SimpleRefCount &o)
00069 : m_count (1)
00070 {}
00071 SimpleRefCount &operator = (const SimpleRefCount &o)
00072 {
00073 return *this;
00074 }
00081 inline void Ref (void) const
00082 {
00083 m_count++;
00084 }
00091 inline void Unref (void) const
00092 {
00093 m_count--;
00094 if (m_count == 0)
00095 {
00096 DELETER::Delete (static_cast<T*> (const_cast<SimpleRefCount *> (this)));
00097 }
00098 }
00099
00104 inline uint32_t GetReferenceCount (void) const
00105 {
00106 return m_count;
00107 }
00108
00109 static void Cleanup (void) {}
00110 private:
00111
00112
00113 mutable uint32_t m_count;
00114 };
00115
00116 }
00117
00118 #endif