1 #ifndef __PHOTOS_LOG_CLASS_HEADER__
2 #define __PHOTOS_LOG_CLASS_HEADER__
20 using std::stringstream;
30 extern void (*PHOERR)(int,
const char*, double);
31 extern void (*PHOREP)();
48 static ostream&
Debug(
unsigned short int code = 0,
bool count =
true);
49 static ostream& Info(
bool count =
true);
50 static ostream& Warning(
bool count =
true);
51 static ostream& Error(
bool count =
true);
55 static void LogInfo(
bool flag =
true) { iAction = flag; }
56 static void LogWarning(
bool flag =
true) { wAction = flag; }
57 static void LogError(
bool flag =
true) { eAction = flag; }
59 static void LogAll(
bool flag =
true) { iAction = wAction = eAction = flag; dRangeS = 0; dRangeE = 65535; }
62 static void LogPhlupa(
int from,
int to) { phlupy.ipoinm = from; phlupy.ipoin = to; }
66 static void LogDebug(
unsigned short s = 0,
unsigned short e = 65535) { dRangeS = s; dRangeE = e; }
71 static void Assert(
bool check,
char* text = NULL);
75 static void Fatal(
string text,
unsigned short int code = 0);
76 static void Fatal(
unsigned short int code = 0) {
Fatal(NULL, code); }
89 static void RevertOutput() { std::cout.rdbuf(bCout); std::cerr.rdbuf(bCerr); }
101 static void IgnoreFatal(
unsigned short s = 0,
unsigned short e = 65535) { faRangeS = s; faRangeE = e; }
106 static void SetOutput(ostream* newOut) { out = newOut; }
107 static void SetOutput(ostream& newOut) { out = &newOut; }
113 static void PHOERR(
int IMES,
const char* TEXT,
double DATA);
119 static streambuf* bCout, *bCerr;
121 static stringstream buf;
122 static int warnLimit;
123 static int decays[4];
124 static int dCount, dRangeS, dRangeE, faCount, faRangeS, faRangeE;
125 static int iCount, wCount, eCount, asCount, asFailedCount;
126 static bool iAction, wAction, eAction, asAction, rAction;
133 unsigned long address;
138 static list<Pointer*>* PointerList;
140 #ifdef _LOG_DEBUG_MODE_
141 static void NewPointer(
unsigned long address,
unsigned long size,
const char* file,
unsigned long line)
144 PointerList =
new list<Pointer*>();
145 atexit(PrintAllocatedPointers);
147 Pointer* info =
new Pointer();
148 info->address = address;
151 strncpy(info->file, file, 63);
152 PointerList->push_front(info);
154 static void DeletePointer(
unsigned long address)
156 if (!PointerList)
return;
157 for (list<Pointer*>::iterator i = PointerList->begin(); i != PointerList->end(); i++) {
158 if ((*i)->address == address) {
159 PointerList->remove((*i));
164 static bool PointerCompare(Pointer* one, Pointer* two)
166 int eq = strcmp(one->file, two->file);
167 if (eq < 0)
return true;
168 else if (eq > 0)
return false;
169 return (one->line <= two->line);
171 static void PrintAllocatedPointers()
173 if (!PointerList)
return;
174 int pointers = 0, buf = 0;
175 unsigned long total = 0;
177 unsigned int lastL = 0;
178 if (PointerList->size() == 0) {
179 cout <<
"----------------------------UNFREED MEMORY POINTERS----------------------------\n";
180 cout <<
" ... NONE ...\n";
181 cout <<
"-------------------------------------------------------------------------------\n";
184 PointerList->sort(PointerCompare);
185 cout <<
"---------------------------UNFREED MEMORY POINTERS---------------------------\n";
186 for (list<Pointer*>::iterator i = PointerList->begin(); i != PointerList->end(); i++) {
189 if (strcmp(lastS, (*i)->file) == 0) {
190 if (lastL == (*i)->line) {
191 printf(
"%56s%10lub (%lu)\n",
" ", (*i)->size, (*i)->address);
197 printf(
"%s%n:", (*i)->file, &buf);
198 printf(
"%-*lu%10lub (%lu)\n", 55 - buf, (*i)->line, (*i)->size, (*i)->address);
200 cout << endl << total <<
"\tbytes" << endl;
201 cout << pointers <<
"\tpointers" << endl;
202 cout <<
"-------------------------------------------------------------------------------\n";
204 #endif //_LOG_DEBUG_MODE_
207 #ifdef _LOG_DEBUG_MODE_
215 inline void*
operator new(
long unsigned int size,
const char*
filename,
int line)
217 void* ptr = (
void*)malloc(size);
218 Photos::Log::NewPointer((
unsigned long)ptr, size, filename, line);
222 inline void operator delete(
void* p)
224 Photos::Log::DeletePointer((
unsigned long)p);
228 #define new new(__FILE__, __LINE__)
230 #endif //_LOG_DEBUG_MODE_