#ifndef WWWI_MIND_AM_H
#define WWWI_MIND_AM_H
#include <iostream>
#include "format.h"
#include "wwwi/singleton.h"
#include "wwwi/string.h"
using WWWI::GetSingleton;
using WWWI::StringDuplicate;
using std::cerr;
using std::endl;
#ifndef NDEBUG
#define AMCTOR(XXX) { GetSingleton<AM<XXX> >()->CTOR(#XXX); FastLog(LF_OBJNEWDEL,LY_DEBUG,FOUT(#XXX"::"#XXX"(",(unsigned)this,")")); }
#define AMDTOR(XXX) { GetSingleton<AM<XXX> >()->DTOR(); FastLog(LF_OBJNEWDEL,LY_DEBUG,FOUT(#XXX"::~"#XXX"(",(unsigned)this,")")); }
#else
#define AMCTOR(XXX)
#define AMDTOR(XXX)
#endif
template <class T> class AM {
public:
AM(void) { m_strName = NULL; m_uCTOR = 0; m_uDTOR = 0; }
void CTOR(const char *ci_strName) {
if (m_strName==NULL) m_strName = StringDuplicate(ci_strName);
m_uCTOR++;
}
void DTOR(void) { m_uDTOR++; }
~AM(void) {
if (m_strName==NULL) return;
cerr << "AM:" << m_strName << ": " << m_uCTOR << " created " << m_uDTOR
<< " destroyed " << sizeof(T) << " bytes each" << endl;
delete[] m_strName;
}
protected:
const char *m_strName;
unsigned m_uCTOR;
unsigned m_uDTOR;
};
#endif