00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef UTILITY_RUNTIME_ERROR_H
00039 #define UTILITY_RUNTIME_ERROR_H
00040
00041 #include "Utility/String.h"
00042 #include "SysDeps/Debug.h"
00043
00044 namespace Onikiri
00045 {
00046 void SetAssertNoThrow( bool noThrow );
00047 void SuppressWaning( bool suppress );
00048 bool IsInException();
00049
00050 struct RuntimeErrorInfo
00051 {
00052 const char* file;
00053 int line;
00054 const char* func;
00055 const char* name;
00056 const char* cond;
00057 RuntimeErrorInfo(){};
00058 RuntimeErrorInfo(
00059 const char* fileArg,
00060 int lineArg,
00061 const char* funcArg,
00062 const char* nameArg,
00063 const char* condArg
00064 ) :
00065 file( fileArg ),
00066 line( lineArg ),
00067 func( funcArg ),
00068 name( nameArg ),
00069 cond( condArg )
00070 {
00071 };
00072 };
00073
00074 void RuntimeErrorFunction( const RuntimeErrorInfo& info, const char* fmt, ... );
00075 void RuntimeWarningFunction( const RuntimeErrorInfo& info, const char* fmt, ... );
00076
00077 void AssertFunction( const RuntimeErrorInfo& info, bool assertCond, const char* fmt, ... );
00078 void AssertFunction( const RuntimeErrorInfo& info, bool assertCond );
00079
00080
00081 static const char* Who()
00082 {
00083 return "Unknown";
00084 }
00085 #define ONIKIRI_DEBUG_NAME Who()
00086
00087 #define DEBUG_WHERE_ARGS() \
00088 ONIKIRI_DEBUG_FILE , ONIKIRI_DEBUG_LINE, ONIKIRI_DEBUG_FUNCTION, ONIKIRI_DEBUG_NAME
00089
00090 #if defined(COMPILER_IS_GCC)
00091
00092 #define THROW_RUNTIME_ERROR(...) \
00093 RuntimeErrorFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), "" ), ## __VA_ARGS__ )
00094
00095
00096 #define RUNTIME_WARNING(...) \
00097 RuntimeWarningFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), "" ), ## __VA_ARGS__ )
00098 #else
00099
00100 #define THROW_RUNTIME_ERROR(...) \
00101 RuntimeErrorFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), "" ), __VA_ARGS__ )
00102
00103
00104 #define RUNTIME_WARNING(...) \
00105 RuntimeWarningFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), "" ), __VA_ARGS__ )
00106 #endif
00107
00108
00109 #ifdef ONIKIRI_DEBUG
00110 #if defined(COMPILER_IS_GCC)
00111
00112 #define ASSERT(cond, ...) \
00113 if(!(cond)){AssertFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), #cond ), false, ## __VA_ARGS__);}
00114 #else
00115
00116
00117 #define ASSERT(cond, ...) \
00118 if(!(cond)){AssertFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), #cond ), false, __VA_ARGS__);}
00119 #endif
00120 #else
00121 #if defined(COMPILER_IS_MSVC) || defined(COMPILER_IS_GCC)
00122 #define ASSERT(...)
00123 #else
00124 inline void AssertDummy(bool, const char* str, ...){};
00125 inline void AssertDummy(bool){};
00126 #define ASSERT AssertDummy
00127 #endif
00128 #endif
00129
00130
00131 }
00132
00133
00134 #endif