85 lines
952 B
C
85 lines
952 B
C
|
#pragma once
|
||
|
|
||
|
namespace lwe
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
};
|
||
|
}
|