1 #ifndef __PHOTOS_LOG_CLASS_HEADER__
2 #define __PHOTOS_LOG_CLASS_HEADER__
20 using std::stringstream;
31 extern void (*PHOERR)(int,
const char*,double);
32 extern void (*PHOREP)();
50 static ostream&
Debug(
unsigned short int code=0,
bool count=
true);
51 static ostream& Info(
bool count=
true);
52 static ostream& Warning(
bool count=
true);
53 static ostream& Error(
bool count=
true);
57 static void LogInfo (
bool flag=
true) { iAction=flag; }
58 static void LogWarning(
bool flag=
true) { wAction=flag; }
59 static void LogError (
bool flag=
true) { eAction=flag; }
61 static void LogAll (
bool flag=
true) { iAction=wAction=eAction=flag; dRangeS=0; dRangeE=65535; }
64 static void LogPhlupa(
int from,
int to) { phlupy.ipoinm=from; phlupy.ipoin=to; }
68 static void LogDebug(
unsigned short s=0,
unsigned short e=65535) { dRangeS=s; dRangeE=e; }
73 static void Assert(
bool check,
char *text=NULL);
77 static void Fatal(
string text,
unsigned short int code=0);
78 static void Fatal(
unsigned short int code=0) {
Fatal(NULL,code); }
91 static void RevertOutput() { std::cout.rdbuf(bCout); std::cerr.rdbuf(bCerr); }
103 static void IgnoreFatal(
unsigned short s=0,
unsigned short e=65535) { faRangeS=s; faRangeE=e; }
109 static void SetOutput(ostream &newOut) { out=&newOut; }
115 static void PHOERR(
int IMES,
const char *TEXT,
double DATA);
121 static streambuf *bCout,*bCerr;
123 static stringstream buf;
124 static int warnLimit;
125 static int decays[4];
126 static int dCount,dRangeS,dRangeE,faCount,faRangeS,faRangeE;
127 static int iCount, wCount, eCount, asCount, asFailedCount;
128 static bool iAction,wAction,eAction,asAction,rAction;
136 unsigned long address;
141 static list<Pointer*> *PointerList;
143 #ifdef _LOG_DEBUG_MODE_
144 static void NewPointer(
unsigned long address,
unsigned long size,
const char *file,
unsigned long line)
148 PointerList =
new list<Pointer *>();
149 atexit(PrintAllocatedPointers);
151 Pointer *info =
new Pointer();
152 info->address = address;
155 strncpy(info->file, file, 63);
156 PointerList->push_front(info);
158 static void DeletePointer(
unsigned long address)
160 if(!PointerList)
return;
161 for(list<Pointer*>::iterator i = PointerList->begin(); i!=PointerList->end(); i++)
163 if((*i)->address == address)
165 PointerList->remove((*i));
170 static bool PointerCompare(Pointer *one, Pointer *two)
172 int eq = strcmp(one->file,two->file);
173 if(eq<0)
return true;
174 else if(eq>0)
return false;
175 return (one->line <= two->line);
177 static void PrintAllocatedPointers()
179 if(!PointerList)
return;
180 int pointers=0,buf=0;
181 unsigned long total=0;
183 unsigned int lastL=0;
184 if(PointerList->size()==0)
186 cout<<
"----------------------------UNFREED MEMORY POINTERS----------------------------\n";
187 cout<<
" ... NONE ...\n";
188 cout<<
"-------------------------------------------------------------------------------\n";
191 PointerList->sort(PointerCompare);
192 cout<<
"---------------------------UNFREED MEMORY POINTERS---------------------------\n";
193 for(list<Pointer*>::iterator i = PointerList->begin(); i!=PointerList->end(); i++)
197 if(strcmp(lastS,(*i)->file)==0)
199 if(lastL==(*i)->line)
201 printf(
"%56s%10lub (%lu)\n",
" ",(*i)->size,(*i)->address);
207 printf(
"%s%n:",(*i)->file,&buf);
208 printf(
"%-*lu%10lub (%lu)\n",55-buf,(*i)->line,(*i)->size,(*i)->address);
210 cout<<endl<<total<<
"\tbytes"<<endl;
211 cout<<pointers<<
"\tpointers"<<endl;
212 cout<<
"-------------------------------------------------------------------------------\n";
214 #endif //_LOG_DEBUG_MODE_
217 #ifdef _LOG_DEBUG_MODE_
225 inline void*
operator new(
long unsigned int size,
const char *filename,
int line)
227 void *ptr = (
void *)malloc(size);
228 Photos::Log::NewPointer((
unsigned long)ptr, size, filename, line);
232 inline void operator delete(
void *p)
234 Photos::Log::DeletePointer((
unsigned long)p);
238 #define new new(__FILE__, __LINE__)
240 #endif //_LOG_DEBUG_MODE_
static void PHOERR(int IMES, const char *TEXT, double DATA)
static void AddDecay(int type)
static void SummaryAtExit()
static void IgnoreFatal(unsigned short s=0, unsigned short e=65535)
static void RedirectOutput(void(*func)(), ostream &where=*out)
static void IgnoreFailedAssert(bool flag=true)
static void Assert(bool check, char *text=NULL)
static void Fatal(string text, unsigned short int code=0)
static void LogInfo(bool flag=true)
static void SetOutput(ostream *newOut)
static void LogDebug(unsigned short s=0, unsigned short e=65535)
static ostream & Debug(unsigned short int code=0, bool count=true)
static void RevertOutput()
static void IgnoreRedirection(bool flag=true)
static void SetWarningLimit(int x)