Files
Leviathan/Client/Game/game/Utility/RefCounted.h
T
2026-06-01 12:46:52 +02:00

49 lines
695 B
C++

#pragma once
#include "IntrusivePtr.h"
#include <cassert>
namespace rp {
namespace mixin {
class ref_counted
{
public:
ref_counted() : m_ref_count( 0 )
{
}
virtual ~ref_counted()
{
}
int acquire()
{
return ++m_ref_count;
}
int dispose()
{
assert( m_ref_count > 0 || !"wrong reference counting!" );
int ref = --m_ref_count;
if( !m_ref_count )
delete this;
return ref;
}
int ref_count() const
{
return m_ref_count;
}
private:
int m_ref_count;
};
} // mixin
inline void intrusive_ptr_acquire( mixin::ref_counted* p )
{
p->acquire();
}
inline void intrusive_ptr_dispose( mixin::ref_counted* p )
{
p->dispose();
}
} // rp