Skip to content

Instantly share code, notes, and snippets.

@szastupov
Created May 23, 2011 23:40
Show Gist options
  • Save szastupov/987870 to your computer and use it in GitHub Desktop.
Save szastupov/987870 to your computer and use it in GitHub Desktop.
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