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