mirror of
https://github.com/PrimeDecomp/prime.git
synced 2025-12-12 15:26:08 +00:00
@@ -3,23 +3,36 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
namespace rstl {
|
||||
class CRefData {
|
||||
public:
|
||||
CRefData(void* ptr) : x0_ptr(ptr), x4_refCount(1) {}
|
||||
CRefData(void* ptr, int refCount) : x0_ptr(ptr), x4_refCount(refCount) {}
|
||||
CRefData(const void* ptr) : x0_ptr(ptr), x4_refCount(1) {}
|
||||
CRefData(const void* ptr, int refCount) : x0_ptr(ptr), x4_refCount(refCount) {}
|
||||
|
||||
void* x0_ptr;
|
||||
unsigned int x4_refCount;
|
||||
void* GetPtr() const { return const_cast< void* >(x0_ptr); }
|
||||
int GetRefCount() const { return x4_refCount; }
|
||||
int AddRef() { return ++x4_refCount; }
|
||||
int DelRef() { return --x4_refCount; }
|
||||
|
||||
const void* x0_ptr;
|
||||
int x4_refCount;
|
||||
|
||||
static CRefData sNull;
|
||||
};
|
||||
|
||||
namespace rstl {
|
||||
template < typename T >
|
||||
class rc_ptr {
|
||||
public:
|
||||
rc_ptr(T* ptr) : x0_refData(new CRefData(ptr)) {}
|
||||
~rc_ptr();
|
||||
T* GetPtr() const { return reinterpret_cast< T* >(x0_refData->x0_ptr); }
|
||||
// TODO ReleaseData__Q24rstl20rc_ptr
|
||||
rc_ptr(const T* ptr) : x0_refData(new CRefData(ptr)) {}
|
||||
rc_ptr(const rc_ptr& other) : x0_refData(other.x0_refData) { x0_refData->AddRef(); }
|
||||
~rc_ptr() { ReleaseData(); }
|
||||
T* GetPtr() const { return static_cast< T* >(x0_refData->GetPtr()); }
|
||||
void ReleaseData() {
|
||||
if (x0_refData->DelRef() <= 0) {
|
||||
delete GetPtr();
|
||||
delete x0_refData;
|
||||
}
|
||||
}
|
||||
T* operator->() const { return GetPtr(); }
|
||||
T& operator*() const { return *GetPtr(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user