#ifndef __DEBUGDEF_H__ #define __DEBUGDEF_H__ #include "config.h" #define DBG_FUNC_NAME(name) static char dbgCharFncName[] = #name; #define fast_guard(name) {DBG_FUNC_NAME(name) #define fast_unguard() } #ifdef guard #undef guard #endif #ifdef unguard #undef unguard #endif #ifdef release_trace #undef release_trace #endif #ifdef trace #undef trace #endif #ifdef ENABLE_GUARD #define guard(name) {DBG_FUNC_NAME(name);\ g_pDebugSystem.AddLastFunction(dbgCharFncName); #define unguard() g_pDebugSystem.RemoveLastFunction();} /* }\ // catch(...)\ // {\ // g_pDebugSystem.AddLastFunction(dbgCharFncName);\ // throw;\ // };}; */ #define sreturn {g_pDebugSystem.RemoveLastFunction(); return;} #define sreturn_ret(ret) {g_pDebugSystem.RemoveLastFunction(); return ret;} #ifdef _WIN32 #define TRY_APP __try{ #define CATCH_APP() }__except(AppHandleException(GetExceptionInformation()))\ {} #else #define TRY_APP try{ #define CATCH_APP() }catch(...) {} #endif #else #define TRY_APP { #define CATCH_APP() } #define sreturn return #define sreturn_ret(ret) return ret #ifdef ENABLE_MEM_TRACK #define guard(name) {DBG_FUNC_NAME(name); #define unguard() }; #else #define guard(name) { #define unguard() }; #endif #endif #ifdef ENABLE_MEM_TRACK #define snew(pntr, cnstrctor) pntr = new cnstrctor; g_pDebugSystem.RegisterAlloc(pntr, sizeof(*pntr), dbgCharFncName, __FILE__, __LINE__, TRUE); #define snew_arr(cls, num) (cls *)g_pDebugSystem.RegisterAlloc((new cls[(##num)]), (sizeof(cls) * (##num)), dbgCharFncName, __FILE__, __LINE__, TRUE); #define sdelete(block) {if(block){delete(block); g_pDebugSystem.UnregisterAlloc(block, dbgCharFncName, __FILE__, __LINE__, TRUE); block = NULL;}}; #define sdelete_this() {if(this){delete(this); g_pDebugSystem.UnregisterAlloc(this, dbgCharFncName, __FILE__, __LINE__, TRUE);}}; #define sdelete_arr(block) {if(block){delete [] (block); g_pDebugSystem.UnregisterAlloc(block, dbgCharFncName, __FILE__, __LINE__, TRUE); block = NULL;}}; #define smalloc(size) g_pDebugSystem.SMalloc(size, dbgCharFncName, __FILE__, __LINE__) #define scalloc(nElems, size) g_pDebugSystem.SCalloc(nElems, size, dbgCharFncName, __FILE__, __LINE__) #define srealloc(pointer, size) g_pDebugSystem.SRealloc(pointer, size, dbgCharFncName, __FILE__, __LINE__) #define sfree(block) if(block){g_pDebugSystem.SFree(block, dbgCharFncName, __FILE__, __LINE__); block = NULL; } #else #define snew(cls, cnstrctor) new cls##cnstrctor #define snew_arr(cls, num) new cls[num]() #define sdelete(block) {if(block){delete(block);block = NULL;}} #define sdelete_this() {if(this){delete(this);}}; #define sdelete_arr(block) {if(block){delete[](block);block = NULL;}} #define smalloc(size) malloc(size) #define scalloc(nElems, size) calloc(nElems, size) #define srealloc(pointer, size) realloc(pointer, size) #define sfree(block) if(block){free(block);block = NULL;} #endif #ifdef _APP_DEBUG #define trace g_pDebugSystem.Trace #else #define trace #endif #define SHOW_MEM_STATS() g_pDebugSystem.ShowMemStats() #define GET_ALLOCATED_MEM() g_pDebugSystem.GetAllocatedMem() #define release_trace g_pDebugSystem.Trace #define error_exit g_pDebugSystem.ErrorExit #define OPEN_DBG_CHANNEL(chnl) g_pDebugSystem.OpenDebugChannel(chnl, #chnl); #ifdef ENABLE_ASSERT #ifdef ENABLE_DEBUG_ASSERT #define debug_asserta(channel, condition) {if(!(condition)) g_pDebugSystem.Assert(channel, #condition, dbgCharFncName, __FILE__, __LINE__);} #else #define debug_asserta(channel, condition) {if(!(condition)){release_trace(SYSTEM, #condition);release_trace(SYSTEM, "ASSERT FAILED!!!\n");};}; #endif #define asserta(channel, condition) {if(!(condition)) g_pDebugSystem.Assert(channel, #condition, dbgCharFncName, __FILE__, __LINE__);} #define asserta_txt(channel, condition, txt) {if(!(condition)) g_pDebugSystem.Assert(channel, txt, dbgCharFncName, __FILE__, __LINE__);} #define asserta_ret(channel, condition) {if(!(condition)) {g_pDebugSystem.Assert(channel, #condition, dbgCharFncName, __FILE__, __LINE__);sreturn;}} #else #define debug_asserta(channel, condition) {if(!(condition)){release_trace(SYSTEM, #condition);release_trace(SYSTEM, "ASSERT FAILED - %s!!!\n", #condition);};}; #define asserta(channel, condition) {} #define asserta_txt(channel, condition, txt){} #define asserta_ret(channel, condition) {if(!(condition)){sreturn;}} #endif #endif //__DEBUGDEF_H__