2023-12-17 03:29:08 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ShdPtr.h"
|
|
|
|
|
2023-12-17 15:56:13 -08:00
|
|
|
namespace ehs
|
2023-12-17 03:29:08 -08:00
|
|
|
{
|
|
|
|
template<typename T>
|
|
|
|
class WkPtr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
T* data;
|
|
|
|
|
|
|
|
public:
|
|
|
|
~WkPtr()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WkPtr()
|
|
|
|
: data(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WkPtr(T* data)
|
|
|
|
: data(data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WkPtr(ShdPtr<T>& shdPtr)
|
|
|
|
: data(shdPtr.GetData())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WkPtr(WkPtr&& wkPtr) noexcept
|
|
|
|
: data(wkPtr.data)
|
|
|
|
{
|
|
|
|
wkPtr.data = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
WkPtr(const WkPtr& wkPtr)
|
|
|
|
: data(wkPtr.data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WkPtr& operator=(const ShdPtr<T>& shdPtr)
|
|
|
|
{
|
|
|
|
data = shdPtr.GetData();
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
WkPtr& operator=(WkPtr&& wkPtr) noexcept
|
|
|
|
{
|
|
|
|
if (this == &wkPtr)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
data = wkPtr.data;
|
|
|
|
|
|
|
|
wkPtr.data = nullptr;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
WkPtr& operator=(const WkPtr& wkPtr) noexcept
|
|
|
|
{
|
|
|
|
if (this == &wkPtr)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
data = wkPtr.data;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(ShdPtr<T>& shdPtr)
|
|
|
|
{
|
|
|
|
if (!HasPtrData(data))
|
|
|
|
data = nullptr;
|
|
|
|
|
|
|
|
return data == shdPtr.GetData();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const WkPtr& wkPtr)
|
|
|
|
{
|
|
|
|
if (!HasPtrData(data))
|
|
|
|
data = nullptr;
|
|
|
|
|
|
|
|
return data == wkPtr.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(T* inPtr)
|
|
|
|
{
|
|
|
|
if (!HasPtrData(data))
|
|
|
|
data = nullptr;
|
|
|
|
|
|
|
|
return data == inPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(ShdPtr<T>& shdPtr)
|
|
|
|
{
|
|
|
|
if (!HasPtrData(data))
|
|
|
|
data = nullptr;
|
|
|
|
|
|
|
|
return data != shdPtr.GetData();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const WkPtr& wkPtr)
|
|
|
|
{
|
|
|
|
if (!HasPtrData(data))
|
|
|
|
data = nullptr;
|
|
|
|
|
|
|
|
return data != wkPtr.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(T* inPtr)
|
|
|
|
{
|
|
|
|
if (!HasPtrData(data))
|
|
|
|
data = nullptr;
|
|
|
|
|
|
|
|
return data != inPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Release()
|
|
|
|
{
|
|
|
|
data = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* GetData()
|
|
|
|
{
|
|
|
|
if (!HasPtrData(data))
|
|
|
|
data = nullptr;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|