26 #ifndef __BIASDEBUG_HH__
27 #define __BIASDEBUG_HH__
29 #include <bias_config.h>
31 #if defined WIN32 && defined(_DLL)
34 #pragma warning(disable: 4251) // disable only STL DLL linking warning noise
92 #define BIASDOUT(flag, arg)\
93 { if ((this->_liDebugLevel & flag)!=0){\
94 std::ostream _cods_(std::cout.rdbuf()); \
95 this->GetDebugStream(_cods_); _cods_ << #flag << ", " << __FILE__ \
96 << ", " << __LINE__ << " : " << arg << std::endl; } }
98 #define BIASFLUSHDOUT \
99 { std::ostream _cods_(std::cout.rdbuf()); \
100 this->GetDebugStream(_cods_); _cods_.flush(); }
102 #define BIASDOUT_THREAD(debuglevel, debugstream, flag, arg)\
103 if ((debuglevel & flag)!=0)\
104 debugstream << #flag << ", " << __FILE__ << ", " << __LINE__ << " : "\
107 #define BIASGDOUT(level, arg)\
108 if (Debug::GlobalDebugLevel >= level)\
109 std::cerr << arg << std::endl;
111 #define BIASDOUT_CLEAN(flag, arg)\
112 { if ((this->_liDebugLevel & flag)!=0){\
113 std::ostream _cods_(std::cout.rdbuf()); \
114 this->GetDebugStream(_cods_); _cods_ << arg << std::endl; } }
116 #define BIASCDOUT(flag, arg)\
117 { if ((this->_liDebugLevel & flag)!=0){\
118 std::ostream _cods_(std::cout.rdbuf()); \
119 this->GetDebugStream(_cods_); _cods_ << arg; } }
121 #define BCDOUT(name, arg)\
122 { if ( (this->_liDebugLevel & Debug::Name2DebugLevel(#name) ) !=0 ){\
123 std::ostream _cods_(std::cout.rdbuf()); \
124 this->GetDebugStream(_cods_); _cods_ << arg; } }
126 # define INFNANCHECK(a) { if (BIAS_ISNAN(a) || BIAS_ISINF(a)){\
127 std::cout << __FILE__<<":"<<__LINE__ << " "<<#a<<" = "<<a<<std::endl; \
128 assert(!BIAS_ISNAN(a) && !BIAS_ISINF(a));\
131 # define INFNANCHECK(a) { if (BIAS_ISNAN(a) || BIAS_ISINF(a)){\
132 std::cout << __FILE__<<":"<<__LINE__ << " "<<#a<<" = "<<a<<std::endl; \
133 assert(!BIAS_ISNAN(a) && !BIAS_ISINF(a));\
139 #define BIASDOUT_CLEAN(flag, arg) {}
140 #define BIASDOUT(flag, arg) {}
141 #define BIASFLUSHDOUT {}
142 #define BIASDOUT_THREAD(debuglevel, debugstream, flag, arg) {}
143 #define BIASGDOUT(level, arg) {}
144 #define BIASCDOUT(flag, arg) {}
145 #define BCDOUT(name, arg) {}
146 #define INFNANCHECK(a) {}
153 #define ABORT std::cout << "Please hit enter to terminate program!" << std::endl << std::flush; \
157 #define ABORT abort();
164 #define PRINTTYPE(thetype) (\
165 (typeid(thetype)==typeid(char))? "char": \
166 (typeid(thetype)==typeid(signed char))?"signed char":\
167 (typeid(thetype)==typeid(unsigned char))?"unsigned char":\
168 (typeid(thetype)==typeid(short))? "short": \
169 (typeid(thetype)==typeid(signed short))? "signed short": \
170 (typeid(thetype)==typeid(unsigned short))?"unsigned short":\
171 (typeid(thetype)==typeid(int))? "int":\
172 (typeid(thetype)==typeid(unsigned int))?"unsigned int":\
173 (typeid(thetype)==typeid(signed int))?"signed int":\
174 (typeid(thetype)==typeid(double))?"double":\
175 (typeid(thetype)==typeid(float))?"float":\
176 (typeid(thetype)==typeid(long))?"long":\
177 "UnknownStorageType")
305 _liNextDebugLevel = 1;
328 SetDebugLevel(Name2DebugLevel(name));
335 return _liDebugLevel;
344 return ((_liDebugLevel & lv)!=0);
352 return DebugLevelIsSet(Name2DebugLevel(name));
358 _liDebugLevel = _liDebugLevel | lv;
365 AddDebugLevel(Name2DebugLevel(name));
372 _liDebugLevel = _liDebugLevel & (~lv);
379 RemoveDebugLevel(Name2DebugLevel(name));
386 #define WS sizeof(long int)*8
387 os <<
"0x" << std::hex << std::setw(
sizeof(
long int)<<1)
388 << std::setfill(
'0') << GetDebugLevel() << std::dec <<
" = ";
389 for (
unsigned i=1; i<=WS; i++){
390 os << !!((1<<(WS-i))&GetDebugLevel());
391 if ((i%4)==0) os <<
" ";
392 if ((i%8)==0) os <<
" ";
401 _zDebugStream.rdbuf(os.rdbuf());
408 return _zDebugStream;
418 os.rdbuf(_zDebugStream.rdbuf());
420 os.rdbuf(std::cout.rdbuf());
427 GlobalDebugLevel = lev;
434 return GlobalDebugLevel;
457 std::map<std::string, long int>::const_iterator it =
458 _String2Debuglevel.find(name);
459 if (it == _String2Debuglevel.end()){
460 std::cerr <<
"Debuglevel \""<<name<<
"\" is unknown. Please use one "
461 <<
"of the following: \n";
462 ShowDebugLevel(std::cerr);
463 std::cerr <<
"\n\n\n";
477 long int res = ConsumeNextFreeDebuglevel_();
478 std::map<std::string, long int>::iterator it
479 = _String2Debuglevel.find(name);
480 if (it != _String2Debuglevel.end()){
481 std::cerr <<
"debuglevel with name \""<<name<<
"\" does already exist, "
482 <<
"please choose a different name!\n\n\n";
485 _String2Debuglevel.insert(make_pair(name, res));
499 std::map<std::string, long int>::const_iterator it;
500 for (it = _String2Debuglevel.begin();
501 it != _String2Debuglevel.end(); it++){
502 os <<
" 0x"<<std::hex<<it->second<<
" : "
503 <<it->first<<std::dec<<std::endl;
522 long dl = _liNextDebugLevel;
524 if ((
long)_liNextDebugLevel > (
long)(1<<30))
526 std::cerr <<
"maximum number of debuglevels reached\n";
529 _liNextDebugLevel = _liNextDebugLevel<<1;
541 #if defined WIN32 && defined(_DLL)
547 #endif // __BIASDEBUG_HH__
static long int GetGlobalDebugLevel()
void SetDebugLevel(const std::string &name)
void AddDebugLevel(const long int lv)
void AddDebugLevel(const std::string &name)
long ConsumeNextFreeDebuglevel_()
returns the next available debuglevel
int GetDebugLevel() const
Debug & operator=(const Debug &deb)
void PrintDebugLevel(std::ostream &os=std::cout) const
bool DebugLevelIsSet(const long int lv) const
long int _liNextDebugLevel
new concept, debuglevel are managed here in the debug class
bool DebugLevelIsSet(const std::string &name) const
long int Name2DebugLevel(const std::string &name) const
looks up a debuglevel in the internal map, returns 0 if not found
void RemoveDebugLevel(const std::string &name)
void SetDebugLevel(const long int lv)
long int NewDebugLevel(const std::string &name)
creates a new debuglevel
std::map< std::string, long int > _String2Debuglevel
static long int GlobalDebugLevel
void ShowDebugLevel(std::ostream &os=std::cout) const
prints all internally known debuglevels
void GetDebugStream(std::ostream &os) const
std::ostream & GetDebugStream() const
static std::ostream _zDebugStream
void RemoveDebugLevel(const long int lv)
static void SetGlobalDebugLevel(long int lev)
void SetDebugStream(const std::ostream &os)