mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 17:07:41 +00:00
CIOWinManager implementation
This commit is contained in:
@@ -22,19 +22,63 @@ public:
|
||||
*/
|
||||
class CRefData
|
||||
{
|
||||
void* m_ptr;
|
||||
int m_refCount;
|
||||
void* x0_ptr;
|
||||
int x4_refCount;
|
||||
public:
|
||||
CRefData() : m_ptr(nullptr), m_refCount(0xffffff) {}
|
||||
CRefData(void* ptr) : m_ptr(ptr), m_refCount(0) {}
|
||||
CRefData() : x0_ptr(nullptr), x4_refCount(0xffffff) {}
|
||||
CRefData(void* ptr) : x0_ptr(ptr), x4_refCount(0) {}
|
||||
|
||||
void* GetPtr() const {return m_ptr;}
|
||||
int AddRef() {return ++m_refCount;}
|
||||
int DelRef() {return --m_refCount;}
|
||||
void* GetPtr() const {return x0_ptr;}
|
||||
int AddRef() {return ++x4_refCount;}
|
||||
int DelRef() {return --x4_refCount;}
|
||||
|
||||
static CRefData sNull;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class ncrc_ptr;
|
||||
|
||||
/**
|
||||
* @brief Reference-counted shared smart pointer
|
||||
*/
|
||||
template<class T>
|
||||
class rc_ptr
|
||||
{
|
||||
CRefData* m_aux;
|
||||
friend class ncrc_ptr<T>;
|
||||
public:
|
||||
rc_ptr() : m_aux(&CRefData::sNull) {m_aux->AddRef();}
|
||||
rc_ptr(void* ptr) : m_aux(new CRefData(ptr)) {m_aux->AddRef();}
|
||||
rc_ptr(const rc_ptr<T>& other) : m_aux(other.m_aux) {m_aux->AddRef();}
|
||||
rc_ptr(rc_ptr<T>&& other) : m_aux(other.m_aux) {other.m_aux = nullptr;}
|
||||
rc_ptr(const ncrc_ptr<T>& other) : m_aux(other.m_aux) {m_aux->AddRef();}
|
||||
~rc_ptr()
|
||||
{
|
||||
if (m_aux && !m_aux->DelRef())
|
||||
{
|
||||
delete static_cast<T*>(m_aux->GetPtr());
|
||||
delete m_aux;
|
||||
}
|
||||
}
|
||||
|
||||
T* operator->() const {return static_cast<T*>(m_aux->GetPtr());}
|
||||
T& operator*() const {return *static_cast<T*>(m_aux->GetPtr());}
|
||||
T* get() const {return static_cast<T*>(m_aux->GetPtr());}
|
||||
operator bool() {return m_aux->GetPtr() != nullptr;}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Non-reference-counted shared smart pointer
|
||||
*/
|
||||
template<class T>
|
||||
class ncrc_ptr
|
||||
{
|
||||
CRefData* m_aux;
|
||||
friend class rc_ptr<T>;
|
||||
public:
|
||||
ncrc_ptr(const rc_ptr<T>& other) : m_aux(other.m_aux) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RSTL_HPP__
|
||||
|
||||
Reference in New Issue
Block a user