25 #ifndef __PHOTOS_LOG_CLASS_HEADER__ 26 #define __PHOTOS_LOG_CLASS_HEADER__ 52 using std::stringstream;
71 static ostream &
Debug(
unsigned short int code = 0,
bool count =
true);
72 static ostream &
Info(
bool count =
true);
73 static ostream &
Warning(
bool count =
true);
74 static ostream &
Error(
bool count =
true);
98 static void LogDebug(
unsigned short s = 0,
unsigned short e = 65535)
107 static void Assert(
bool check,
char *text =
nullptr);
111 static void Fatal(
string text,
unsigned short int code = 0);
112 static void Fatal(
unsigned short int code = 0) {
Fatal(
nullptr, code); }
127 std::cout.rdbuf(
bCout);
128 std::cerr.rdbuf(
bCerr);
141 static void IgnoreFatal(
unsigned short s = 0,
unsigned short e = 65535)
159 static stringstream
buf;
171 unsigned long address;
179 #ifdef _LOG_DEBUG_MODE_ 180 static void NewPointer(
unsigned long address,
unsigned long size,
const char *file,
unsigned long line)
183 PointerList =
new list<Pointer *>();
184 atexit(PrintAllocatedPointers);
190 strncpy(info->
file, file, 63);
191 PointerList->push_front(info);
193 static void DeletePointer(
unsigned long address)
197 for (list<Pointer *>::iterator
i = PointerList->begin();
i != PointerList->end();
i++) {
198 if ((*i)->address == address) {
199 PointerList->remove((*
i));
206 int eq = strcmp(one->
file, two->
file);
213 static void PrintAllocatedPointers()
217 int pointers = 0, buf = 0;
218 unsigned long total = 0;
220 unsigned int lastL = 0;
221 if (PointerList->size() == 0) {
222 cout <<
"----------------------------UNFREED MEMORY POINTERS----------------------------\n";
223 cout <<
" ... NONE ...\n";
224 cout <<
"-------------------------------------------------------------------------------\n";
227 PointerList->sort(PointerCompare);
228 cout <<
"---------------------------UNFREED MEMORY POINTERS---------------------------\n";
229 for (list<Pointer *>::iterator
i = PointerList->begin();
i != PointerList->end();
i++) {
232 if (strcmp(lastS, (*i)->file) == 0) {
233 if (lastL == (*i)->line) {
234 printf(
"%56s%10lub (%lu)\n",
" ", (*i)->size, (*i)->address);
240 printf(
"%s%n:", (*i)->file, &buf);
241 printf(
"%-*lu%10lub (%lu)\n", 55 - buf, (*i)->line, (*i)->size, (*i)->address);
243 cout << endl << total <<
"\tbytes" << endl;
244 cout << pointers <<
"\tpointers" << endl;
245 cout <<
"-------------------------------------------------------------------------------\n";
247 #endif //_LOG_DEBUG_MODE_ 250 #ifdef _LOG_DEBUG_MODE_ 258 inline void *
operator new(
long unsigned int size,
const char *filename,
int line)
260 void *ptr = (
void *)malloc(size);
261 Photos::Log::NewPointer((
unsigned long)ptr, size, filename, line);
265 inline void operator delete(
void *p)
267 Photos::Log::DeletePointer((
unsigned long)p);
271 #define new new (__FILE__, __LINE__) 273 #endif //_LOG_DEBUG_MODE_ static void Assert(bool check, char *text=nullptr)
static ostream & Info(bool count=true)
static ostream & Warning(bool count=true)
static ostream & Error(bool count=true)
static ostream & Debug(unsigned short int code=0, bool count=true)
static void LogPhlupa(int from, int to)
static void LogAll(bool flag=true)
static list< Pointer * > * PointerList
static void SetWarningLimit(int x)
static void Fatal(unsigned short int code=0)
static void IgnoreFailedAssert(bool flag=true)
static void IgnoreFatal(unsigned short s=0, unsigned short e=65535)
static void IgnoreRedirection(bool flag=true)
static void AddDecay(int type)
static void LogError(bool flag=true)
static void LogWarning(bool flag=true)
static void RedirectOutput(void(*func)(), ostream &where= *out)
static void SetOutput(ostream &newOut)
static void SummaryAtExit()
static void Fatal(string text, unsigned short int code=0)
basic_ostream< char, char_traits< char > > ostream
static void LogDebug(unsigned short s=0, unsigned short e=65535)
static void RevertOutput()
static void SetOutput(ostream *newOut)
static void LogInfo(bool flag=true)