[+] AuSetAllocator(that, pHeap/refHeap)

[+] auSetAllocator.ipp
[+] auSetAllocator.hpp
This commit is contained in:
Reece Wilson 2024-09-10 08:29:13 +01:00
parent bdb5e3e37a
commit 0b8fbafdca
5 changed files with 558 additions and 0 deletions

View File

@ -0,0 +1,20 @@
/***
Copyright (C) 2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
File: auSetAllocator.hpp
Date: 2024-09-09
Author: Reece
***/
#pragma once
namespace Aurora::Memory
{
struct Heap;
}
template <typename T>
static bool AuSetAllocator(T &that, Aurora::Memory::Heap *pHeap);
template <typename T>
static bool AuSetAllocator(T &that, const AuSPtr<Aurora::Memory::Heap> &pHeap);

View File

@ -0,0 +1,533 @@
/***
Copyright (C) 2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
File: auSetAllocator.ipp
Date: 2024-09-09
Author: Reece
***/
#pragma once
namespace __audetail
{
template <class T>
struct AuHasSetAllocatorRawVoid
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<void (C:: *)(Aurora::Memory::Heap *)>(&C::SetAllocator)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetAllocatorRawBool
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<bool (C:: *)(Aurora::Memory::Heap *)>(&C::SetAllocator)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetHeapRawVoid
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<void (C:: *)(Aurora::Memory::Heap *)>(&C::SetHeap)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetHeapRawBool
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<bool (C:: *)(Aurora::Memory::Heap *)>(&C::SetHeap)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetAllocatorSVoid
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<void (C:: *)(AuSPtr<Aurora::Memory::Heap>)>(&C::SetAllocator)));
template <class C> static constexpr AuTrueType Test(decltype(static_cast<void (C:: *)(const AuSPtr<Aurora::Memory::Heap> &)>(&C::SetAllocator)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetAllocatorSBool
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<bool (C:: *)(AuSPtr<Aurora::Memory::Heap>)>(&C::SetAllocator)));
template <class C> static constexpr AuTrueType Test(decltype(static_cast<bool (C:: *)(const AuSPtr<Aurora::Memory::Heap> &)>(&C::SetAllocator)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetHeapSVoid
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<void (C:: *)(AuSPtr<Aurora::Memory::Heap>)>(&C::SetHeap)));
template <class C> static constexpr AuTrueType Test(decltype(static_cast<void (C:: *)(const AuSPtr<Aurora::Memory::Heap> &)>(&C::SetHeap)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetHeapSBool
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<bool (C:: *)(AuSPtr<Aurora::Memory::Heap>)>(&C::SetHeap)));
template <class C> static constexpr AuTrueType Test(decltype(static_cast<bool (C:: *)(const AuSPtr<Aurora::Memory::Heap> &)>(&C::SetHeap)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetHeapSharedSVoid
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<void (C:: *)(AuSPtr<Aurora::Memory::Heap>)>(&C::SetHeapShared)));
template <class C> static constexpr AuTrueType Test(decltype(static_cast<void (C:: *)(const AuSPtr<Aurora::Memory::Heap> &)>(&C::SetHeapShared)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasSetHeapSharedSBool
{
template <class C> static constexpr AuTrueType Test(decltype(static_cast<bool (C:: *)(AuSPtr<Aurora::Memory::Heap>)>(&C::SetHeapShared)));
template <class C> static constexpr AuTrueType Test(decltype(static_cast<bool (C:: *)(const AuSPtr<Aurora::Memory::Heap> &)>(&C::SetHeapShared)));
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
struct AuHasAllocatorType
{
template <class C> static constexpr AuTrueType Test(typename C::allocator_type *);
template <class C> static constexpr AuFalseType Test(...);
using type = decltype(Test<T>(0));
};
template <class T>
constexpr inline bool AuHasSetAllocatorRawVoid_v = AuHasSetAllocatorRawVoid<T>::type::value;
template <class T>
constexpr inline bool AuHasSetAllocatorRawBool_v = AuHasSetAllocatorRawBool<T>::type::value;
template <class T>
constexpr inline bool AuHasSetAllocatorSharedVoid_v = AuHasSetAllocatorSVoid<T>::type::value;
template <class T>
constexpr inline bool AuHasSetAllocatorSharedBool_v = AuHasSetAllocatorSBool<T>::type::value;
template <class T>
constexpr inline bool AuHasSetHeapRawVoid_v = AuHasSetHeapRawVoid<T>::type::value;
template <class T>
constexpr inline bool AuHasSetHeapRawBool_v = AuHasSetHeapRawBool<T>::type::value;
template <class T>
constexpr inline bool AuHasSetHeapSharedVoid_v = AuHasSetHeapSVoid<T>::type::value;
template <class T>
constexpr inline bool AuHasSetHeapSharedBool_v = AuHasSetHeapSBool<T>::type::value;
template <class T>
constexpr inline bool AuHasSetHeapSharedSharedVoid_v = AuHasSetHeapSharedSVoid<T>::type::value;
template <class T>
constexpr inline bool AuHasSetHeapSharedSharedBool_v = AuHasSetHeapSharedSBool<T>::type::value;
template <class T>
constexpr inline bool AuHasAllocatorType_v = AuHasAllocatorType<T>::type::value;
}
template <typename T>
static bool AuSetAllocator(T &that, Aurora::Memory::Heap *pHeap)
{
if (!pHeap)
{
return false;
}
if constexpr (__audetail::AuHassize_v<T>)
{
if constexpr (__audetail::AuHasSetAllocatorRawVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetAllocator(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetAllocatorRawBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetAllocator(pHeap);
}
if constexpr (__audetail::AuHasSetHeapRawVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetHeap(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetHeapRawBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetHeap(pHeap);
}
if constexpr (__audetail::AuHasSetAllocatorSharedVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetAllocator(AuUnsafeRaiiToShared(pHeap));
return true;
}
if constexpr (__audetail::AuHasSetAllocatorSharedBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetAllocator(AuUnsafeRaiiToShared(pHeap));
}
if constexpr (__audetail::AuHasSetHeapSharedVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetHeap(AuUnsafeRaiiToShared(pHeap));
return true;
}
if constexpr (__audetail::AuHasSetHeapSharedBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetHeap(AuUnsafeRaiiToShared(pHeap));
}
if constexpr (__audetail::AuHasSetHeapSharedSharedVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetHeapShared(AuUnsafeRaiiToShared(pHeap));
return true;
}
if constexpr (__audetail::AuHasSetHeapSharedSharedBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetHeapShared(AuUnsafeRaiiToShared(pHeap));
}
if constexpr (__audetail::AuHasAllocatorType_v<T>)
{
if (that.size())
{
AUROXTL_COMMODITY_TRY
{
T copy { that, typename T::allocator_type { pHeap } };
AuResetMember(that, AuMove(copy));
}
AUROXTL_COMMODITY_CATCH
{
return false;
}
}
else
{
AuResetMember(that, typename T::allocator_type { pHeap });
}
return true;
}
}
else
{
if constexpr (__audetail::AuHasSetAllocatorRawVoid_v<T>)
{
that.SetAllocator(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetAllocatorRawBool_v<T>)
{
return that.SetAllocator(pHeap);
}
if constexpr (__audetail::AuHasSetHeapRawVoid_v<T>)
{
that.SetHeap(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetHeapRawBool_v<T>)
{
return that.SetHeap(pHeap);
}
if constexpr (__audetail::AuHasSetAllocatorSharedVoid_v<T>)
{
that.SetAllocator(AuUnsafeRaiiToShared(pHeap));
return true;
}
if constexpr (__audetail::AuHasSetAllocatorSharedBool_v<T>)
{
return that.SetAllocator(AuUnsafeRaiiToShared(pHeap));
}
if constexpr (__audetail::AuHasSetHeapSharedVoid_v<T>)
{
that.SetHeap(AuUnsafeRaiiToShared(pHeap));
return true;
}
if constexpr (__audetail::AuHasSetHeapSharedBool_v<T>)
{
return that.SetHeap(AuUnsafeRaiiToShared(pHeap));
}
if constexpr (__audetail::AuHasSetHeapSharedSharedVoid_v<T>)
{
that.SetHeapShared(AuUnsafeRaiiToShared(pHeap));
return true;
}
if constexpr (__audetail::AuHasSetHeapSharedSharedBool_v<T>)
{
return that.SetHeapShared(AuUnsafeRaiiToShared(pHeap));
}
}
return false;
}
template <typename T>
static bool AuSetAllocator(T &that, const AuSPtr<Aurora::Memory::Heap> &pHeap)
{
if (!pHeap)
{
return false;
}
if constexpr (__audetail::AuHassize_v<T>)
{
if constexpr (__audetail::AuHasSetAllocatorSharedVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetAllocator(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetAllocatorSharedBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetAllocator(pHeap);
}
if constexpr (__audetail::AuHasSetHeapSharedVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetHeap(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetHeapSharedBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetHeap(pHeap);
}
if constexpr (__audetail::AuHasSetHeapSharedSharedVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetHeapShared(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetHeapSharedSharedBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetHeapShared(pHeap);
}
if constexpr (__audetail::AuHasSetAllocatorRawVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetAllocator(pHeap.get());
return true;
}
if constexpr (__audetail::AuHasSetAllocatorRawBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetAllocator(pHeap.get());
}
if constexpr (__audetail::AuHasSetHeapRawVoid_v<T>)
{
if (that.size())
{
return false;
}
that.SetHeap(pHeap.get());
return true;
}
if constexpr (__audetail::AuHasSetHeapRawBool_v<T>)
{
if (that.size())
{
return false;
}
return that.SetHeap(pHeap.get());
}
if constexpr (__audetail::AuHasAllocatorType_v<T>)
{
if (that.size())
{
AUROXTL_COMMODITY_TRY
{
T copy { that, typename T::allocator_type { pHeap } };
AuResetMember(that, AuMove(copy));
}
AUROXTL_COMMODITY_CATCH
{
return false;
}
}
else
{
AuResetMember(that, typename T::allocator_type { pHeap });
}
return true;
}
}
else
{
if constexpr (__audetail::AuHasSetAllocatorSharedVoid_v<T>)
{
that.SetAllocator(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetAllocatorSharedBool_v<T>)
{
return that.SetAllocator(pHeap);
}
if constexpr (__audetail::AuHasSetHeapSharedVoid_v<T>)
{
that.SetHeap(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetHeapSharedBool_v<T>)
{
return that.SetHeap(pHeap);
}
if constexpr (__audetail::AuHasSetHeapSharedSharedVoid_v<T>)
{
that.SetHeapShared(pHeap);
return true;
}
if constexpr (__audetail::AuHasSetHeapSharedSharedBool_v<T>)
{
return that.SetHeapShared(pHeap);
}
if constexpr (__audetail::AuHasSetAllocatorRawVoid_v<T>)
{
that.SetAllocator(pHeap.get());
return true;
}
if constexpr (__audetail::AuHasSetAllocatorRawBool_v<T>)
{
return that.SetAllocator(pHeap.get());
}
if constexpr (__audetail::AuHasSetHeapRawVoid_v<T>)
{
that.SetHeap(pHeap.get());
return true;
}
if constexpr (__audetail::AuHasSetHeapRawBool_v<T>)
{
return that.SetHeap(pHeap.get());
}
}
return false;
}

View File

@ -457,3 +457,5 @@ inline constexpr bool operator!=(const Aurora::Memory::BaseAuroraRuntimeAllocato
{ {
return false; return false;
} }
#include <auROXTL/MemoryModel/auSetAllocator.hpp>

View File

@ -57,6 +57,7 @@ namespace __audetail
constexpr inline bool AuHas ## name ## _v = AuHas ## name<T>::type::value; constexpr inline bool AuHas ## name ## _v = AuHas ## name<T>::type::value;
_AUROXTL_DETAIAL_HAS(has_value); _AUROXTL_DETAIAL_HAS(has_value);
_AUROXTL_DETAIAL_HAS(capacity) _AUROXTL_DETAIAL_HAS(capacity)
_AUROXTL_DETAIAL_HAS(size)
_AUROXTL_DETAIAL_HAS(reserve) _AUROXTL_DETAIAL_HAS(reserve)
template <class T> template <class T>

View File

@ -76,6 +76,8 @@ namespace __audetail
#include <auROXTL/Objects/SOO.hpp> #include <auROXTL/Objects/SOO.hpp>
#include <auROXTL/MemoryModel/auSetAllocator.ipp>
struct IAuNullDelegate struct IAuNullDelegate
{ {
virtual void OnCall() = 0; virtual void OnCall() = 0;