1 #ifndef __LOG_CLASS_HEADER__
2 #define __LOG_CLASS_HEADER__
20 using std::stringstream;
47 static ostream&
Debug(
unsigned short int code=0,
bool count=
true);
48 static ostream& Info(
bool count=
true);
49 static ostream& Warning(
bool count=
true);
50 static ostream&
Error(
bool count=
true);
54 static void LogInfo (
bool flag=
true) { iAction=flag; }
55 static void LogWarning(
bool flag=
true) { wAction=flag; }
56 static void LogError (
bool flag=
true) { eAction=flag; }
58 static void LogAll (
bool flag=
true) { iAction=wAction=eAction=flag; dRangeS=0; dRangeE=65535; }
62 static void LogDebug(
unsigned short s=0,
unsigned short e=65535) { dRangeS=s; dRangeE=e; }
67 static void Assert(
bool check,
char *text=NULL);
71 static void Fatal(
string text,
unsigned short int code=0);
72 static void Fatal(
unsigned short int code=0) {
Fatal(
"",code); }
85 static void RevertOutput() { std::cout.rdbuf(bCout); std::cerr.rdbuf(bCerr); }
97 static void IgnoreFatal(
unsigned short s=0,
unsigned short e=65535) { faRangeS=s; faRangeE=e; }
103 static void SetOutput(ostream &newOut) { out=&newOut; }
109 static streambuf *bCout,*bCerr;
111 static stringstream buf;
112 static int warnLimit;
113 static int decays[4];
114 static int dCount,dRangeS,dRangeE,faCount,faRangeS,faRangeE;
115 static int iCount, wCount, eCount, asCount, asFailedCount;
116 static bool iAction,wAction,eAction,asAction,rAction;
124 unsigned long address;
129 static list<Pointer*> *PointerList;
131 #ifdef _LOG_DEBUG_MODE_
132 static void NewPointer(
unsigned long address,
unsigned long size,
const char *file,
unsigned long line)
136 PointerList =
new list<Pointer *>();
137 atexit(PrintAllocatedPointers);
140 info->address = address;
143 strncpy(info->file, file, 63);
144 PointerList->push_front(info);
146 static void DeletePointer(
unsigned long address)
148 if(!PointerList)
return;
149 for(list<Pointer*>::iterator i = PointerList->begin(); i!=PointerList->end(); i++)
151 if((*i)->address == address)
153 PointerList->remove((*i));
160 int eq = strcmp(one->file,two->file);
161 if(eq<0)
return true;
162 else if(eq>0)
return false;
163 return (one->line <= two->line);
165 static void PrintAllocatedPointers()
167 if(!PointerList)
return;
168 int pointers=0,buf=0;
169 unsigned long total=0;
172 if(PointerList->size()==0)
174 cout<<
"----------------------------UNFREED MEMORY POINTERS----------------------------\n";
175 cout<<
" ... NONE ...\n";
176 cout<<
"-------------------------------------------------------------------------------\n";
179 PointerList->sort(PointerCompare);
180 cout<<
"---------------------------UNFREED MEMORY POINTERS---------------------------\n";
181 for(list<Pointer*>::iterator i = PointerList->begin(); i!=PointerList->end(); i++)
185 if(strcmp(lastS,(*i)->file)==0)
187 if(lastL==(*i)->line)
189 printf(
"%56s%10lub (%lu)\n",
" ",(*i)->size,(*i)->address);
195 printf(
"%s%n:",(*i)->file,&buf);
196 printf(
"%-*lu%10lub (%lu)\n",55-buf,(*i)->line,(*i)->size,(*i)->address);
198 cout<<endl<<total<<
"\tbytes"<<endl;
199 cout<<pointers<<
"\tpointers"<<endl;
200 cout<<
"-------------------------------------------------------------------------------\n";
202 #endif //_LOG_DEBUG_MODE_
205 #ifdef _LOG_DEBUG_MODE_
213 inline void*
operator new(
size_t size,
const char *filename,
int line)
215 void *ptr = (
void *)malloc(size);
216 Log::NewPointer((
unsigned long)ptr, size, filename, line);
220 inline void operator delete(
void *p)
222 Log::DeletePointer((
unsigned long)p);
226 #define new new(__FILE__, __LINE__)
228 #endif //_LOG_DEBUG_MODE_
static void LogInfo(bool flag=true)
static void SummaryAtExit()
static void IgnoreFailedAssert(bool flag=true)
static void IgnoreRedirection(bool flag=true)
static void AddDecay(int type)
static void SetWarningLimit(int x)
static void SetOutput(ostream *newOut)
static void RedirectOutput(void(*func)(), ostream &where=*out)
static ostream & Debug(unsigned short int code=0, bool count=true)
static void LogDebug(unsigned short s=0, unsigned short e=65535)
static void IgnoreFatal(unsigned short s=0, unsigned short e=65535)
static void Fatal(string text, unsigned short int code=0)
static void Assert(bool check, char *text=NULL)
static void RevertOutput()