prime/include/Kyoto/TOneStatic.hpp
Henrique Gemignani Passos Lima f9c75b90ee Almost match ~CPlayerGun
Former-commit-id: c332d1ef47ec4941b00b47504a7a7be96fc3e7d8
2022-10-06 14:04:05 +03:00

33 lines
692 B
C++

#ifndef _TONESTATIC_HPP
#define _TONESTATIC_HPP
#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); }
void operator delete(void* ptr);
private:
static void* GetAllocSpace() {
static u8 sAllocSpace[sizeof(T)];
return &sAllocSpace;
}
static uint& ReferenceCount() {
static uint sReferenceCount = 0;
return sReferenceCount;
}
};
template < typename T >
void TOneStatic< T >::operator delete(void* ptr) {
ReferenceCount()--;
}
#endif