Homepage Demos Overview Downloads Tutorials Reference
Credits

debuget.h

Go to the documentation of this file.
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 //! for historical reasons - the previous compiler give the entire path for __FILE__, for display, just use the filename
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 //! if the bool b is false, std::cout the string
00019 #define ASSERT(b,str) {if(!(b)) std::cout << "ASSERT:"<<_extractFilename(__FILE__)<<'.'<<__LINE__<<':'<< str << std::endl;}
00020 //! if the bool b is false, std::cout the string and return
00021 #define ASSERTRET(b,str) {if(!(b)) { std::cout << "ASSERT:"<<_extractFilename(__FILE__)<<'.'<<__LINE__<<':'<< str << std::endl; return; }}
00022 //! if the bool b is false, std::cout the string and return the value
00023 #define ASSERTRETVAL(b,str,v) {if(!(b)) { std::cout << "ASSERT:"<<_extractFilename(__FILE__)<<'.'<<__LINE__<<':'<< str << std::endl; return v; }}
00024 //! if the bool b is false, std::cout the string and exit(x)
00025 #define ASSERTFATAL(b,str,x) {if(!(b)) { std::cout << "ASSERT:"<<_extractFilename(__FILE__)<<'.'<<__LINE__<<':'<< str << std::endl; exit(x); }}
00026 //#define FILELOG(fname,type,str) { ofstream f(fname,type); f<<str; }
00027 #else
00028 //! if the bool b is false, std::cout the string
00029 #define ASSERT(b,str) {}
00030 //! if the bool b is false, std::cout the string and return
00031 #define ASSERTRET(b,str) {}
00032 //! if the bool b is false, std::cout the string and return the value
00033 #define ASSERTRETVAL(b,str,v) {}
00034 //! if the bool b is false, std::cout the string and exit(x)
00035 #define ASSERTFATAL(b,str,x) {}
00036 #endif
00037 
00038 //! returns the hex char that corresponds to @a c, which should be 0-16 (returns '.' otherwise)
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 //! printf's the two hex digits coresponding to a byte
00050 inline void charhexout(char c) {
00051   printf("%c%c",hexdigit((c>>4)&0x0F),hexdigit(c&0x0F));
00052 }
00053 
00054 //! charhexout's @a n bytes starting at @a p
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         //        std::cout << flush;
00064       }
00065       printf(" ");
00066     }
00067     printf("\n");
00068   }
00069 }
00070 
00071 /*! @file
00072  * @brief Defines several debugging functions and macros, including ::ASSERT (and variations)
00073  * @author ejt (Creator)
00074  *
00075  * $Author: ejt $
00076  * $Name: tekkotsu-2_2 $
00077  * $Revision: 1.2 $
00078  * $State: Rel $
00079  * $Date: 2003/09/25 15:31:53 $
00080  */
00081 
00082 // static void hexout(unsigned int in) {
00083 //   char buf;
00084 //   std::cout << "0x";
00085 //   if (in == 0) std::cout << "0";
00086 //   else {
00087 //     while (in != 0) {
00088 //       if (in % 16 > 9) buf = 'A' + in % 16 - 9;
00089 //       else buf = '0' + in % 16;
00090 //       std::cout << buf;
00091 //       in /= 16;
00092 //     }
00093 //   }
00094 //   std::cout << std::endl;
00095 // }
00096 
00097 #endif

Tekkotsu v2.2
Generated Tue Oct 19 14:19:13 2004 by Doxygen 1.3.9.1