1 /*
2 
3 *************************************************************************
4 
5 ArmageTron -- Just another Tron Lightcycle Game in 3D.
6 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7 
8 **************************************************************************
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 
24 ***************************************************************************
25 
26 */
27 
28 #ifndef _ERROR_H_
29 #define _ERROR_H_
30 
31 #include "config.h"
32 #ifdef _MSC_VER
33 #define __PRETTY_FUNCTION__ ""
34 #endif
35 #include <iomanip>
36 #include <sstream>
37 #include <iosfwd>
38 #include <string>
39 #include <string.h>
40 #if HAVE_UNISTD_H
41 #include <unistd.h>
42 #endif
43 
44 #define tVERIFY( x ) { if ( !( x ) ){ char const * mess = "Assertion " #x " failed";  tERR_ERROR_INT( mess ); } }
45 
46 #ifdef DEBUG
47 
48 typedef enum {high=0,normal,low,very_low} tLevel;
49 typedef enum {flow=0,dump}                tChannel;
50 
51 extern tLevel st_debugLevel[2];
52 
53 int st_debugValid(tLevel l,tChannel c);
54 
55 
56 #define tERR_DUMP(level,stream,stuff) if(st_debugValid(level,stream))  std::cout <<  setw(28) << __FUNCTION__  << " : " << stuff << '\n'
57 
58 #define tERR_FLOW() if(st_debugValid(low,flow)) std::cout  <<  std::setw(30) << __PRETTY_FUNCTION__  << '\n'
59 
60 #define tERR_FLOW_HIGH() if(st_debugValid(normal,flow)) std::cout  <<  std::setw(30)  << __PRETTY_FUNCTION__  << '\n'
61 
62 #define tERR_FLOW_LOW() if(st_debugValid(very_low,flow)) std::cout  <<  std::setw(30) << __PRETTY_FUNCTION__  << '\n'
63 
64 #define tASSERT( x ) { if ( !( x ) ){ char const * mess = "Assertion " #x " failed";  tERR_ERROR_INT( mess ); } }
65 
66 #define tASSERT_EVAL( x ) { if ( !( x ) ){ char const * mess = "Assertion " #x " failed";  tERR_ERROR_INT( mess ); } }
67 
68 #else  /* DEBUG */
69 #define tERR_DUMP(level,stream,stuff)
70 #define tERR_FLOW()
71 #define tERR_FLOW_HIGH()
72 #define tERR_FLOW_LOW()
73 #define tASSERT( x )
74 #define tASSERT_EVAL( x ) x
75 #endif /* DEBUG */
76 
77 //extern char ERROR_MESSAGE[1000];
78 
79 void st_Breakpoint();
80 
81 void st_PresentError( const char* caption, const char *message );
82 void st_PresentMessage( const char* caption, const char *message );
83 
84 // complaint free check for THIS pointer so dereferencing null objects can get caugt in debug builds
85 bool st_CheckThis(void const *in);
86 #define tASSERT_THIS() tASSERT(st_CheckThis(this));
87 
88 /*
89 #ifndef WIN32
90 
91 #define tERR_ERROR_INT(mess) { std::cerr << "Internal error in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n'; st_Breakpoint(); ::exit(-1);}
92 
93 #define tERR_ERROR(mess) { std::cerr << "Error in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n'; st_Breakpoint(); ::exit(-1);}
94 
95 #else
96 
97 #include <windows.h>
98 
99 #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);}
100 
101 #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);}
102 
103 #endif // WINDOWS
104 */
105 
106 #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() );}
107 
108 #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() ); }
109 
110 #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() ); }
111 
112 #define tERR_WARN(mess) {con << "Warning in " << __PRETTY_FUNCTION__ << " in " << __FILE__<< ':' << __LINE__ << " : \n \t" << mess << '\n';}
113 
114 
115 /*
116 #define tERR_ERROR_INT(mess) { st_Breakpoint(); exit(-1); }
117 
118 #define tERR_ERROR(mess) { st_Breakpoint(); exit(-1); }
119 
120 #define tERR_WARN(mess) { st_Breakpoint(); }
121 */
122 #endif // _ERROR_H_
123 
124