1 #ifndef __PHOTOS_LOG_CLASS_HEADER__ 2 #define __PHOTOS_LOG_CLASS_HEADER__ 28 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);
74 static void LogDebug(
unsigned short s = 0,
unsigned short e = 65535)
83 static void Assert(
bool check,
char *text =
nullptr);
87 static void Fatal(
string text,
unsigned short int code = 0);
88 static void Fatal(
unsigned short int code = 0) {
Fatal(
nullptr, code); }
103 std::cout.rdbuf(
bCout);
104 std::cerr.rdbuf(
bCerr);
117 static void IgnoreFatal(
unsigned short s = 0,
unsigned short e = 65535)
135 static stringstream
buf;
147 unsigned long address;
155 #ifdef _LOG_DEBUG_MODE_ 156 static void NewPointer(
unsigned long address,
unsigned long size,
const char *file,
unsigned long line)
159 PointerList =
new list<Pointer *>();
160 atexit(PrintAllocatedPointers);
166 strncpy(info->
file, file, 63);
167 PointerList->push_front(info);
169 static void DeletePointer(
unsigned long address)
173 for (list<Pointer *>::iterator
i = PointerList->begin();
i != PointerList->end();
i++) {
174 if ((*i)->address == address) {
175 PointerList->remove((*
i));
182 int eq = strcmp(one->
file, two->
file);
189 static void PrintAllocatedPointers()
193 int pointers = 0, buf = 0;
194 unsigned long total = 0;
196 unsigned int lastL = 0;
197 if (PointerList->size() == 0) {
198 cout <<
"----------------------------UNFREED MEMORY POINTERS----------------------------\n";
199 cout <<
" ... NONE ...\n";
200 cout <<
"-------------------------------------------------------------------------------\n";
203 PointerList->sort(PointerCompare);
204 cout <<
"---------------------------UNFREED MEMORY POINTERS---------------------------\n";
205 for (list<Pointer *>::iterator
i = PointerList->begin();
i != PointerList->end();
i++) {
208 if (strcmp(lastS, (*i)->file) == 0) {
209 if (lastL == (*i)->line) {
210 printf(
"%56s%10lub (%lu)\n",
" ", (*i)->size, (*i)->address);
216 printf(
"%s%n:", (*i)->file, &buf);
217 printf(
"%-*lu%10lub (%lu)\n", 55 - buf, (*i)->line, (*i)->size, (*i)->address);
219 cout << endl << total <<
"\tbytes" << endl;
220 cout << pointers <<
"\tpointers" << endl;
221 cout <<
"-------------------------------------------------------------------------------\n";
223 #endif //_LOG_DEBUG_MODE_ 226 #ifdef _LOG_DEBUG_MODE_ 234 inline void *
operator new(
long unsigned int size,
const char *filename,
int line)
236 void *ptr = (
void *)malloc(size);
237 Photos::Log::NewPointer((
unsigned long)ptr, size, filename, line);
241 inline void operator delete(
void *p)
243 Photos::Log::DeletePointer((
unsigned long)p);
247 #define new new (__FILE__, __LINE__) 249 #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)