EHS/include/ehs/WkPtr.h
karutoh 1a4a1ecd9c
Some checks failed
Build & Release / Linux-x86_64-Build (push) Successful in 40s
Build & Release / Linux-AARCH64-Build (push) Has been cancelled
First commit.
2024-01-31 22:28:19 -08:00

134 lines
1.6 KiB
C++

#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;
}
};
}