134 lines
1.6 KiB
C
134 lines
1.6 KiB
C
|
#pragma once
|
||
|
|
||
|
#include "ShdPtr.h"
|
||
|
|
||
|
namespace lwe
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
};
|
||
|
}
|