EHS/include/ehs/WkPtr.h

134 lines
1.6 KiB
C
Raw Normal View History

2024-02-05 22:25:30 -08:00
#pragma once
#include "ShdPtr.h"
namespace ehs
{
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;
}
};
}