00001 00007 #include "include/Debug.h" 00008 #include "include/generic.h" 00009 #include <sstream> 00010 00011 namespace debug 00012 { 00013 00014 Debug::Debug() 00015 { 00016 verbosity = 0; 00017 } 00018 00019 void Debug::Prntdbg(const char* file, int line, const char* function, int verb, string print) 00020 { 00021 if (debug && verb <= verbosity) 00022 { 00023 cout << "[" << FORE_GREEN << verbosity << ENDCOLOR; 00024 cout << "->" << FORE_PURPLE << verb << ENDCOLOR << "] "; 00025 if (debugcode) 00026 { 00027 cout << "(in: " << FORE_BLUE << file << ENDCOLOR; 00028 cout << " line: " << FORE_RED << line << ENDCOLOR; 00029 cout << ") function: " << FORE_PURPLE << function << "()" << ENDCOLOR << endl << "\t"; 00030 } 00031 cout << print.c_str() << endl; 00032 } 00033 } 00034 00035 void Debug::Prnterr(const char* file, int line, const char* function, string print) 00036 { 00037 if (debugcode) 00038 { 00039 cerr << "(in: " << FORE_BLUE << file << ENDCOLOR; 00040 cerr << " line: " << FORE_RED << line << ENDCOLOR; 00041 cerr << ") function: " << FORE_PURPLE << function << "()" << ENDCOLOR << endl << "\t"; 00042 } 00043 cerr << FORE_RED << "ERROR: " << print.c_str() << ENDCOLOR << endl; 00044 } 00045 00046 void Debug::SetVerbosity(string verbositystr) 00047 { 00048 istringstream buffer(verbositystr); 00049 buffer >> verbosity; 00050 } 00051 00052 string Debug::GetVerbosity() 00053 { 00054 ostringstream buffer; 00055 buffer << verbosity; 00056 return buffer.str(); 00057 } 00058 00059 void Debug::SetDebug(bool debug, bool debugcode) 00060 { 00061 this->debug = debug; 00062 this->debugcode = debugcode; 00063 } 00064 00065 void Debug::StopDebug() 00066 { 00067 cout << FORE_RED << "[ALERT!] Debug Stopped" << ENDCOLOR << endl; 00068 debug = false; 00069 } 00070 00071 void Debug::StartDebug() 00072 { 00073 cout << FORE_BLUE << "Debug Started" << ENDCOLOR << endl; 00074 debug = true; 00075 } 00076 00077 bool Debug::isDebugging() 00078 { 00079 return debug; 00080 } 00081 00082 Debug::~Debug() 00083 { 00084 } 00085 00086 }