2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _TONESTATIC
|
|
|
|
#define _TONESTATIC
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
class TOneStatic {
|
|
|
|
public:
|
|
|
|
void* operator new(unsigned long sz, const char*, const char*); /* {
|
|
|
|
ReferenceCount()++;
|
|
|
|
return GetAllocSpace();
|
|
|
|
}*/
|
|
|
|
void* operator new(unsigned long 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:
|
|
|
|
static void* GetAllocSpace() {
|
2022-10-09 05:37:23 +00:00
|
|
|
static uchar sAllocSpace[sizeof(T)];
|
2022-04-10 00:17:06 +00:00
|
|
|
return &sAllocSpace;
|
|
|
|
}
|
2022-10-14 10:01:20 +00:00
|
|
|
static uint& ReferenceCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
uint& TOneStatic< T >::ReferenceCount() {
|
2022-09-05 04:01:13 +00:00
|
|
|
static uint sReferenceCount = 0;
|
2022-04-10 00:17:06 +00:00
|
|
|
return sReferenceCount;
|
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()--;
|
|
|
|
}
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _TONESTATIC
|