Compare commits

...

2 Commits

Author SHA1 Message Date
0b8fbafdca [+] AuSetAllocator(that, pHeap/refHeap)
[+] auSetAllocator.ipp
[+] auSetAllocator.hpp
2024-09-10 08:29:13 +01:00
bdb5e3e37a [*] Split off some auMemoryModel.hpp resources 2024-09-10 08:28:47 +01:00
8 changed files with 629 additions and 36 deletions

View File

@ -0,0 +1,14 @@
/***
Copyright (C) 2023-2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
File: auArraySize.hpp
Date: 2022-02-01 - 2024-09-09
Author: Reece
***/
#pragma once
template <class T, AuUInt Z>
constexpr AuUInt AuArraySize(const T(&array)[Z])
{
return Z;
}

View File

@ -0,0 +1,16 @@
/***
Copyright (C) 2023-2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
File: auOffsetOf.hpp
Date: 2023-02-04 - 2024-09-09
Author: Reece
***/
#pragma once
template <typename T, typename C>
AuUInt AuOffsetOf(C T:: *offset)
{
return AuUInt(
&(((const T *)(nullptr))->*offset)
);
}

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

@ -0,0 +1,38 @@
/***
Copyright (C) 2023-2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
File: auSizeOf.hpp
Date: 2023-02-04 - 2024-09-09
Author: Reece
***/
#pragma once
template <typename T>
constexpr AuUInt AuSizeOf()
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const T &)
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const T *)
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const AuSPtr<T>)
{
return sizeof(T);
}
template <typename T, class Del_t>
constexpr AuUInt AuSizeOf(const AuUPtr<T, Del_t> &)
{
return sizeof(T);
}

View File

@ -59,19 +59,10 @@ static auline void AuMemoryPanic(const char *msg)
#endif
}
template <class T, AuUInt Z>
static constexpr AuUInt AuArraySize(const T(&array)[Z])
{
return Z;
}
#include "MemoryModel/auArraySize.hpp"
#include "MemoryModel/auSizeOf.hpp"
#include "MemoryModel/auOffsetOf.hpp"
template <typename T, typename C>
static AuUInt AuOffsetOf(C T:: *offset)
{
return AuUInt(
&(((const T *)(nullptr))->*offset)
);
}
template <typename T>
static auto AuTryLockMemoryType(T weak) -> decltype(weak.lock())
@ -91,30 +82,6 @@ static auto AuTryLockMemoryType(T weak) -> decltype(weak.lock())
}
}
template <typename T>
constexpr AuUInt AuSizeOf()
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const T &)
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const T *)
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const AuSPtr<T>)
{
return sizeof(T);
}
template <class Z, typename T>
static void auline AuSafeDelete(T *in)
{
@ -490,3 +457,5 @@ inline constexpr bool operator!=(const Aurora::Memory::BaseAuroraRuntimeAllocato
{
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;
_AUROXTL_DETAIAL_HAS(has_value);
_AUROXTL_DETAIAL_HAS(capacity)
_AUROXTL_DETAIAL_HAS(size)
_AUROXTL_DETAIAL_HAS(reserve)
template <class T>

View File

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