Created
May 23, 2011 23:40
-
-
Save szastupov/987870 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T> | |
class RefCounted { | |
public: | |
void incRef() | |
{ | |
m_refcount++; | |
} | |
void decRef() | |
{ | |
ASSERT(m_refcount > 0); | |
if (--m_refcount == 0) | |
delete static_cast<T*>(this); | |
} | |
unsigned getRef() const | |
{ | |
return m_refcount; | |
} | |
protected: | |
RefCounted() | |
: m_refcount(0) | |
{} | |
private: | |
RefCounted(const RefCounted&); | |
const RefCounted& operator=(const RefCounted&); | |
private: | |
unsigned m_refcount; | |
}; | |
template <class T> | |
void intrusive_ptr_add_ref(RefCounted<T> *p) | |
{ | |
p->incRef(); | |
} | |
template <class T> | |
void intrusive_ptr_release(RefCounted<T> *p) | |
{ | |
p->decRef(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment