Various pointer changes

This commit is contained in:
SimoneN64
2024-07-03 21:11:03 +02:00
parent 15838db5b6
commit d90e26ac0c
13 changed files with 144 additions and 150 deletions

View File

@@ -6,46 +6,6 @@
#include <functional>
namespace Util {
template <class T, typename... Args>
struct AutoRelease {
AutoRelease(void (*dtor)(T*), const char* name = "") : dtor(dtor), name(name) { }
AutoRelease(T* (*ctor)(Args...), void (*dtor)(T*), const char* name = "", Args... args) : dtor(dtor), name(name) {
thing = ctor(args...);
}
T* get() {
if (!thing) {
Util::panic("AutoRelease::{} is null!", name);
}
return thing;
}
void Construct(T* (*ctor)(Args...), Args... args) {
if(thing) {
dtor(thing);
}
thing = ctor(args...);
}
void Destroy() {
if(thing) {
dtor(thing);
}
}
~AutoRelease() {
if(thing) {
dtor(thing);
}
}
private:
const char* name = "";
T* thing = nullptr;
void (*dtor)(T*) = nullptr;
};
template<typename T>
static FORCE_INLINE T ReadAccess(const u8* data, u32 index) {
if constexpr (sizeof(T) == 8) {