prime/include/Kyoto/TOneStatic.hpp

37 lines
771 B
C++
Raw Normal View History

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