2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _TONESTATIC
|
|
|
|
#define _TONESTATIC
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-12-22 04:26:49 +00:00
|
|
|
#include "stdio.h"
|
2023-10-08 05:57:42 +00:00
|
|
|
#include "types.h"
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
class TOneStatic {
|
|
|
|
public:
|
2023-10-08 05:57:42 +00:00
|
|
|
void* operator new(size_t sz, const char*, const char*);
|
2024-10-12 22:58:00 +00:00
|
|
|
void* operator new(size_t sz) { return operator new(sz, "\?\?(\?\?)", nullptr); }
|
2022-10-06 11:04:05 +00:00
|
|
|
void operator delete(void* ptr);
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
private:
|
2023-10-08 05:57:42 +00:00
|
|
|
static void* GetAllocSpace();
|
2022-10-14 10:01:20 +00:00
|
|
|
static uint& ReferenceCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
uint& TOneStatic< T >::ReferenceCount() {
|
2023-10-08 05:57:42 +00:00
|
|
|
static uint sReferenceCount = 0;
|
|
|
|
return sReferenceCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
void* TOneStatic< T >::GetAllocSpace() {
|
|
|
|
static char sAllocSpace[sizeof(T)];
|
|
|
|
return &sAllocSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
void* TOneStatic< T >::operator new(size_t sz, const char*, const char*) {
|
|
|
|
ReferenceCount()++;
|
|
|
|
return GetAllocSpace();
|
2022-10-14 10:01:20 +00:00
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-10-06 11:04:05 +00:00
|
|
|
template < typename T >
|
|
|
|
void TOneStatic< T >::operator delete(void* ptr) {
|
|
|
|
ReferenceCount()--;
|
|
|
|
}
|
|
|
|
|
2023-10-08 05:57:42 +00:00
|
|
|
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _TONESTATIC
|