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

84 lines
1.5 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"
#include "string.h"
2021-08-28 07:25:03 -07:00
2024-04-12 00:10:30 -06:00
/**
* @ingroup jsystem-jaudio
*
*/
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) {
2023-09-16 10:17:56 -07:00
JUT_ASSERT(186, 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
};
2024-04-12 00:10:30 -06:00
/**
* @ingroup jsystem-jaudio
*
*/
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) {
2023-09-16 10:17:56 -07:00
JUT_ASSERT(229, index < mSize);
mTable[index] = value;
}
private:
/* 0x00 */ T** mTable;
/* 0x04 */ u32 mSize;
};
2024-04-12 00:10:30 -06:00
/**
* @ingroup jsystem-jaudio
*
*/
template<class T, size_t N>
class JASPtrArray : public JASPtrTable<T> {
public:
2023-09-15 05:20:09 -07:00
JASPtrArray() : JASPtrTable<T>(mArray, N) {}
private:
/* 0x08 */ T* mArray[N];
};
2021-08-28 07:25:03 -07:00
#endif /* JASGADGET_H */