Files
tp/include/JSystem/JAudio2/JASGadget.h
T

71 lines
1.4 KiB
C++
Raw Normal View History

2021-08-28 07:25:03 -07:00
#ifndef JASGADGET_H
#define JASGADGET_H
#include "JSystem/JUtility/JUTAssert.h"
2021-08-28 07:25:03 -07:00
template<class T>
2021-08-28 07:25:03 -07:00
class JASGlobalInstance {
public:
JASGlobalInstance(T* inst) {
sInstance = inst;
}
2021-08-28 07:25:03 -07:00
2023-06-09 11:55:15 +03:00
JASGlobalInstance(bool param_1) {
2023-07-12 10:59:33 +03:00
if (param_1) {
JUT_ASSERT("JASGadget.h", 0xba, sInstance == 0);
2023-07-12 10:59:33 +03:00
sInstance = (T*)this;
}
2023-06-09 11:55:15 +03:00
}
~JASGlobalInstance() {
2023-06-09 11:55:15 +03:00
if (sInstance == (T*)this) {
sInstance = NULL;
2022-12-30 16:19:57 -07:00
}
}
static T* getInstance() { return sInstance; }
2022-12-30 16:19:57 -07:00
static T* sInstance;
2021-08-28 07:25:03 -07:00
};
template<class T>
class JASPtrTable {
public:
JASPtrTable(T** param_0, u32 size) {
mTable = param_0;
mSize = size;
memset(mTable, 0, size * 4);
}
T* get(u32 index) {
if (index >= mSize) {
return NULL;
}
return mTable[index];
}
T* get(u32 index) const {
if (index >= mSize) {
return NULL;
}
return mTable[index];
}
void set(u32 index, T* value) {
JUT_ASSERT("JASGadget.h", 0xe5, index < mSize);
mTable[index] = value;
}
private:
/* 0x00 */ T** mTable;
/* 0x04 */ u32 mSize;
};
template<class T, size_t N>
class JASPtrArray : public JASPtrTable<T> {
public:
JASPtrArray() : JASPtrTable(mArray, N) {}
private:
/* 0x08 */ T* mArray[N];
};
2021-08-28 07:25:03 -07:00
#endif /* JASGADGET_H */