EHS/include/ehs/WkPtr.h
Karutoh bcd71cf2b5
All checks were successful
Build & Release / Windows-AMD64-Build (push) Successful in 1m8s
Build & Release / Linux-AMD64-Build (push) Successful in 1m30s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m21s
Adjusted workflow.
2024-02-05 22:25:30 -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;
}
};
}