21 #ifndef SEPARATISTA_DEBUG_H 22 #define SEPARATISTA_DEBUG_H 24 #ifdef SEPARATISTADEBUG_BUILDINGDLL 25 # define SEPARATISTADEBUG_EXTERN __declspec(dllexport) 26 #elif defined SEPARATISTADEBUG_USINGDLL 27 # define SEPARATISTADEBUG_EXTERN __declspec(dllimport) 29 # define SEPARATISTADEBUG_EXTERN 32 #ifdef SEPARATISTA_DEBUG 36 #include <unordered_map> 40 #define LOG(message) Separatista::Debug::DebugLogger::log(message, TEXT(__FILE__), __LINE__) 41 #define DEBUG_METHOD Separatista::Debug::DebugLogger __debugLogger(TEXT(__FUNCTION__), this) 42 #define DEBUG_STATIC_METHOD Separatista::Debug::DebugLogger __debugLogger(TEXT(__FUNCTION__)) 51 class SEPARATISTADEBUG_EXTERN DebugLogger
59 DebugLogger(
const wchar_t *pMethodname,
const void* pObject = NULL);
69 static void log(
const wchar_t *pMessage,
const wchar_t *pFilename,
const unsigned int line);
74 const wchar_t *m_pMessage;
76 friend class MemDebug;
79 #ifdef SEPARATISTA_DEBUG_NEW 81 class SEPARATISTADEBUG_EXTERN MemDebug
86 std::wcscpy(m_TypeName, TEXT(
"Unknown"));
89 MemDebug(
const wchar_t *pFilename,
int nLine) :
90 m_pFilename(pFilename),
93 std::wcscpy(m_TypeName, TEXT(
"Unknown"));
102 static void trackMemory(
void *ptr,
const MemDebug &memDebug,
const char *pTypeName);
107 static void releaseMemory(
void *ptr);
119 wchar_t m_TypeName[100];
120 const wchar_t *m_pFilename;
123 static std::unordered_map<const void *, MemDebug>* g_memMap;
125 friend class DebugLogger;
129 template <
class T>
inline T* operator *(
const MemDebug &memDebug, T *p)
131 Separatista::Debug::MemDebug::trackMemory(p, memDebug,
typeid(T).name());
135 #endif //defined SEPARATISTA_DEBUG_NEW 140 #ifdef SEPARATISTA_DEBUG_NEW 143 #pragma warning (disable: 4595) 147 #ifndef SEPARATISTADEBUG_BUILDINGDLL 149 inline void*
operator new(
size_t size)
151 void *p = std::malloc(size);
153 throw std::bad_alloc();
158 inline void*
operator new[](
size_t size)
160 void *p = std::malloc(size);
162 throw std::bad_alloc();
167 inline void operator delete (
void *ptr)
169 Separatista::Debug::MemDebug::releaseMemory(ptr);
173 inline void operator delete [](
void *ptr)
175 Separatista::Debug::MemDebug::releaseMemory(ptr);
179 #define new Separatista::Debug::MemDebug(TEXT(__FILE__), __LINE__) * new 181 #endif // !defined SEPARATISTADEBUG_BUILDINGDLL 182 #endif // !defined SEPARATISTA_DEBUG_NEW 184 #else // !defined SEPARATISTA_DEBUG 189 #endif // defined SEPARATISTA_DEBUG 191 #endif // !defined SEPARATISTA_DEBUG_H