src/tools/tError.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef _ERROR_H_
00029 #define _ERROR_H_
00030 
00031 #include "aa_config.h"
00032 #ifdef _MSC_VER
00033 #define __PRETTY_FUNCTION__ ""
00034 #endif
00035 #include <iomanip>
00036 #include <sstream>
00037 #include <iosfwd>
00038 #include <string>
00039 #include <string.h>
00040 #if HAVE_UNISTD_H
00041 // #include <unistd.h>
00042 #endif
00043 
00044 #define tVERIFY( x ) { if ( !( x ) ){ char const * mess = "Assertion " #x " failed";  tERR_ERROR_INT( mess ); } }
00045 
00046 #ifdef DEBUG
00047 
00048 typedef enum {high=0,normal,low,very_low} tLevel;
00049 typedef enum {flow=0,dump}                tChannel;
00050 
00051 extern tLevel st_debugLevel[2];
00052 
00053 int st_debugValid(tLevel l,tChannel c);
00054 
00055 
00056 #define tERR_DUMP(level,stream,stuff) if(st_debugValid(level,stream))  std::cout <<  setw(28) << __FUNCTION__  << " : " << stuff << '\n'
00057 
00058 #define tERR_FLOW() if(st_debugValid(low,flow)) std::cout  <<  std::setw(30) << __PRETTY_FUNCTION__  << '\n'
00059 
00060 #define tERR_FLOW_HIGH() if(st_debugValid(normal,flow)) std::cout  <<  std::setw(30)  << __PRETTY_FUNCTION__  << '\n'
00061 
00062 #define tERR_FLOW_LOW() if(st_debugValid(very_low,flow)) std::cout  <<  std::setw(30) << __PRETTY_FUNCTION__  << '\n'
00063 
00064 #define tASSERT( x ) { if ( !( x ) ){ char const * mess = "Assertion " #x " failed";  tERR_ERROR_INT( mess ); } }
00065 
00066 #define tASSERT_EVAL( x ) { if ( !( x ) ){ char const * mess = "Assertion " #x " failed";  tERR_ERROR_INT( mess ); } }
00067 
00068 #else  /* DEBUG */
00069 #define tERR_DUMP(level,stream,stuff) 
00070 #define tERR_FLOW()
00071 #define tERR_FLOW_HIGH()
00072 #define tERR_FLOW_LOW() 
00073 #define tASSERT( x )
00074 #define tASSERT_EVAL( x ) x
00075 #endif /* DEBUG */
00076 
00077 //extern char ERROR_MESSAGE[1000];
00078 
00079 void st_Breakpoint();
00080 
00081 void st_PresentError( const char* caption, const char *message );
00082 void st_PresentMessage( const char* caption, const char *message );
00083 
00084 /*
00085 #ifndef WIN32
00086 
00087 #define tERR_ERROR_INT(mess) { std::cerr << "Internal error in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n'; st_Breakpoint(); ::exit(-1);}
00088    
00089 #define tERR_ERROR(mess) { std::cerr << "Error in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n'; st_Breakpoint(); ::exit(-1);}
00090 
00091 #else
00092 
00093 #include <windows.h>
00094 
00095 #define tERR_ERROR_INT(mess) { st_Breakpoint(); std::stringstream s(ERROR_MESSAGE,999,ios::out);  s << "Internal error in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << "\nPlease send a Bug report!" << '\0'; MessageBox (NULL, ERROR_MESSAGE , "Internal Error", MB_OK); ::exit(-1);}
00096    
00097 #define tERR_ERROR(mess) {   st_Breakpoint(); std::stringstream s(ERROR_MESSAGE,999,ios::out); s << "Error in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n'; MessageBox (NULL, ERROR_MESSAGE , "Error", MB_OK); ::exit(-1);}
00098 
00099 #endif // WINDOWS
00100 */
00101 
00102 #define tERR_ERROR_INT(mess) { std::ostringstream s;  s << "Internal error in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << "\nPlease send a Bug report!" << '\0'; st_PresentError( "Internal Error", s.str().c_str() );}
00103 
00104 #define tERR_ERROR(mess) {   std::ostringstream s; s << "Error in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n'; st_PresentError( "Error", s.str().c_str() ); }
00105 
00106 #define tERR_MESSAGE(mess) {   std::ostringstream s; s << "Message from " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n'; st_PresentMessage( "Message", s.str().c_str() ); }
00107 
00108 #define tERR_WARN(mess) {con << "Warning in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n';}
00109 
00110 
00111 /*
00112 #define tERR_ERROR_INT(mess) { st_Breakpoint(); exit(-1); }
00113 
00114 #define tERR_ERROR(mess) { st_Breakpoint(); exit(-1); }
00115 
00116 #define tERR_WARN(mess) { st_Breakpoint(); }
00117 */
00118 #endif // _ERROR_H_
00119 

Generated on Sat Mar 15 22:56:00 2008 for Armagetron Advanced by  doxygen 1.5.4