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";
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__)
static ostream & Debug(unsigned short int code=0, bool count=true)
Four logging entries.
static void AddDecay(int type)
Adds the decay to the counter.
static void Assert(bool check, char *text=NULL)
Asserts logical value.
static void SetWarningLimit(int x)
Change the limit of warnings that will be displayed.
static void RedirectOutput(void(*func)(), ostream &where= *out)
Redirects output to log.
static void IgnoreFatal(unsigned short s=0, unsigned short e=65535)
Do not exit when Log::Fatal() with the code within the provided range is called.
static void SetOutput(ostream *newOut)
Change the output of the logged messages.
static void LogInfo(bool flag=true)
Turns off or on particular types of messages By default, only debugging messages are turned off.
static void Fatal(string text, unsigned short int code=0)
Terminates the program with added default message or 'text'.
static void PHOREP()
Final report of warnings from internal part of PHOTOS (originally in F77)
static void RevertOutput()
WARNING! If You're redirecting more than one function, do not forget to use RevertOutput() afterwards...
static void IgnoreRedirection(bool flag=true)
Ignores redirections of functions' output.
static void PHOERR(int IMES, const char *TEXT, double DATA)
Warnings on errors from internal part of PHOTOS (originally in F77)
static void SummaryAtExit()
Shows the summary at the end of the program.
static void IgnoreFailedAssert(bool flag=true)
Do not exit when Log::Assert() check is false.
static void LogDebug(unsigned short s=0, unsigned short e=65535)
Sets the range of debug codes that will be printed.
static void Summary()
Shows the summary of all messages.
Memory leak tracking section.