[+] AuCastPointer because C++ is a big pile of shit (TODO: port to AuROXTL)

This commit is contained in:
Reece Wilson 2024-02-14 06:35:43 +00:00
parent f049053776
commit 3dc82bf1cb
2 changed files with 68 additions and 0 deletions

View File

@ -347,6 +347,20 @@ namespace Aurora::Memory
return AuUPtr<T, decltype(&Heap::DeleteThat<T>)>(nullptr, &Heap::RetardedSpecWrittenByRetards<T>);
}
template <class Z, class T>
cstatic AuUPtr<Z, decltype(&Heap::DeleteThat<Z>)> CastPointer(AuUPtr<T, decltype(&Heap::DeleteThat<T>)> &&pInPointer)
{
if (!pInPointer)
{
return NullUniquePointer<Z>();
}
else
{
auto deleter = decltype(&Heap::DeleteThat<Z>)(pInPointer.get_deleter());
return AuUPtr<Z, decltype(&Heap::DeleteThat<Z>)>(AuStaticCast<Z>(pInPointer.release()), deleter);
}
}
template<typename T>
static AuSPtr<T> ToSmartPointer(AuSPtr<Heap> heap,
T *pHead,

View File

@ -154,4 +154,58 @@ template <class T, class ...Args>
AuSPtr<T> AuNewClass(Args &&...args)
{
return Aurora::Memory::GetDefaultDiscontiguousHeap()->NewClass<T, Args...>(AuForward<Args>(args)...);
}
template <class T, class ...Args>
AuHUPOf_t<T> AuNewClassArrayUnique(Aurora::Memory::Heap *pHeap, AuUInt uElements, Args &&... fillCtr)
{
return pHeap->NewClassArrayUnique<T, Args...>(uElements, AuForward<Args>(fillCtr)...);
}
template <class T, class ...Args>
AuSPtr<T> AuNewClassArray(Aurora::Memory::Heap *pHeap, AuUInt uElements, Args &&... fillCtr)
{
return pHeap->NewClassArray<T, Args...>(uElements, AuForward<Args>(fillCtr)...);
}
template <class T, class ...Args>
AuHUPOf_t<T> AuNewClassUnique(Aurora::Memory::Heap *pHeap, Args &&...args)
{
return pHeap->NewClassUnique<T, Args...>(AuForward<Args>(args)...);
}
template <class T, class ...Args>
AuSPtr<T> AuNewClass(Aurora::Memory::Heap *pHeap, Args &&...args)
{
return pHeap->NewClass<T, Args...>(AuForward<Args>(args)...);
}
template <class T, class ...Args>
AuHUPOf_t<T> AuNewClassArrayUnique(const AuSPtr<Aurora::Memory::Heap> &pHeap, AuUInt uElements, Args &&... fillCtr)
{
return pHeap->NewClassArrayUnique<T, Args...>(uElements, AuForward<Args>(fillCtr)...);
}
template <class T, class ...Args>
AuSPtr<T> AuNewClassArray(const AuSPtr<Aurora::Memory::Heap> &pHeap, AuUInt uElements, Args &&... fillCtr)
{
return pHeap->NewClassArray<T, Args...>(uElements, AuForward<Args>(fillCtr)...);
}
template <class T, class ...Args>
AuHUPOf_t<T> AuNewClassUnique(const AuSPtr<Aurora::Memory::Heap> &pHeap, Args &&...args)
{
return pHeap->NewClassUnique<T, Args...>(AuForward<Args>(args)...);
}
template <class T, class ...Args>
AuSPtr<T> AuNewClass(const AuSPtr<Aurora::Memory::Heap> &pHeap, Args &&...args)
{
return pHeap->NewClass<T, Args...>(AuForward<Args>(args)...);
}
template <class Z, class T>
AuHUPOf_t<Z> AuCastPointer(AuHUPOf_t<T> &&pInPointer)
{
return Aurora::Memory::Heap::CastPointer<Z>(AuMove(pInPointer));
}