00001 #ifndef INCLUDED_debuget_h
00002 #define INCLUDED_debuget_h
00003
00004 #include <stdio.h>
00005
00006 #ifdef DEBUG
00007 #include <iostream>
00008 #include <string.h>
00009 #include <fstream>
00010
00011 inline const char* _extractFilename(const char* path) {
00012 const char * last=path;
00013 while(*path++)
00014 if(*path=='/')
00015 last=path+1;
00016 return last;
00017 }
00018
00019 #define ASSERT(b,str) {if(!(b)) std::cout << "ASSERT:"<<_extractFilename(__FILE__)<<'.'<<__LINE__<<':'<< str << std::endl;}
00020
00021 #define ASSERTRET(b,str) {if(!(b)) { std::cout << "ASSERT:"<<_extractFilename(__FILE__)<<'.'<<__LINE__<<':'<< str << std::endl; return; }}
00022
00023 #define ASSERTRETVAL(b,str,v) {if(!(b)) { std::cout << "ASSERT:"<<_extractFilename(__FILE__)<<'.'<<__LINE__<<':'<< str << std::endl; return v; }}
00024
00025 #define ASSERTFATAL(b,str,x) {if(!(b)) { std::cout << "ASSERT:"<<_extractFilename(__FILE__)<<'.'<<__LINE__<<':'<< str << std::endl; exit(x); }}
00026
00027 #else
00028
00029 #define ASSERT(b,str) {}
00030
00031 #define ASSERTRET(b,str) {}
00032
00033 #define ASSERTRETVAL(b,str,v) {}
00034
00035 #define ASSERTFATAL(b,str,x) {}
00036 #endif
00037
00038
00039 inline char hexdigit(int c) {
00040 if(c<0)
00041 return '.';
00042 if(c<10)
00043 return '0'+c;
00044 if(c<16)
00045 return 'a'+(c-10);
00046 return ',';
00047 }
00048
00049
00050 inline void charhexout(char c) {
00051 printf("%c%c",hexdigit((c>>4)&0x0F),hexdigit(c&0x0F));
00052 }
00053
00054
00055 inline void hexout(const void* p, size_t n) {
00056 printf("%x:\n",reinterpret_cast<unsigned int>(p));
00057 const char* x=(const char*)p;
00058 for(unsigned int i=0; i<n;) {
00059 printf("%6d ",i);
00060 for(unsigned int k=0; k<8 && i<n; k++) {
00061 for(unsigned int j=0; j<4 && i<n; j++, i++) {
00062 charhexout(x[i]);
00063
00064 }
00065 printf(" ");
00066 }
00067 printf("\n");
00068 }
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 #endif