00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef INCLUDE_RSRC_ERROR
00012 #define INCLUDE_RSRC_ERROR
00013
00014 #include "../Surcouche/SurcoucheMultitache.h"
00015 #include "../Tools/Tools.h"
00016 #include "ErrorCode.h"
00017 #include <stdlib.h>
00018 #include <time.h>
00019 #include <stdarg.h>
00020 #include <string>
00021 #include <vector>
00022 #include <iostream>
00023 #include <fstream>
00024
00025 using namespace std;
00026
00027 #define ERROR_DEFLANG "../../files/ErrorCode.FR"
00028 #define ERROR_BUFFER 1024
00029
00030
00031
00032
00033 class FuncInfos
00034 {
00035 public :
00036 string func;
00037 string file;
00038 unsigned int line;
00039
00040
00041
00042
00043
00044
00045 FuncInfos(const char *pFunc, const char *pFile, unsigned int iLine)
00046 {
00047 func = pFunc;
00048 file = pFile;
00049 line = iLine;
00050 };
00051 };
00052
00053
00054
00055
00056 class ThreadCallStack
00057 {
00058 public :
00059 unsigned int id;
00060 vector<FuncInfos *> stack;
00061 unsigned int nbInstance;
00062
00063
00064
00065 ThreadCallStack()
00066 {
00067 id = ThreadId();
00068 nbInstance = 0;
00069 };
00070 };
00071
00072 typedef struct
00073 {
00074 unsigned int no;
00075 string desc;
00076 } ErrorDesc;
00077
00078
00079
00080
00081 class Error
00082 {
00083 private :
00084 static string log;
00085 static string langue;
00086 static vector<ThreadCallStack *> callStacks;
00087 ThreadCallStack *currentCallStack;
00088 static vector<ErrorDesc *> descError;
00089 string loc;
00090 unsigned int line;
00091
00092
00093
00094
00095
00096
00097 void LogError(const char *pBuffer, ...);
00098
00099 public :
00100
00101
00102 Error();
00103
00104
00105
00106 ~Error();
00107
00108
00109
00110
00111
00112 inline void SetLog(const char *pLog)
00113 {
00114 log = pLog;
00115 };
00116
00117
00118
00119
00120
00121 inline void SetLoc(const char *pLoc)
00122 {
00123 loc = pLoc;
00124 };
00125
00126
00127
00128
00129
00130 void SetLangue(const char *pFile);
00131
00132
00133
00134
00135
00136
00137 inline void Throw(unsigned int iLine, unsigned int iCode)
00138 {
00139 line = iLine;
00140 throw iCode;
00141 };
00142
00143
00144
00145
00146
00147
00148 void AddFunc(const char *pFunc, const char *pFile);
00149
00150
00151
00152
00153
00154
00155 void Perror(unsigned int iCode);
00156 };
00157
00158
00159
00160
00161 #define ERRORVAR SysError
00162
00163
00164
00165
00166 #define TRY Error ERRORVAR; try {
00167
00168
00169
00170
00171
00172 #define THROW(code) ERRORVAR.Throw(__LINE__, code);
00173
00174
00175
00176
00177
00178 #define LOG(log) ERRORVAR.SetLog(log);
00179
00180
00181
00182
00183
00184 #define LOC(func) ERRORVAR.SetLoc(func);
00185
00186
00187
00188
00189
00190
00191 #define LANG(fichier) ERRORVAR.SetLangue(fichier);
00192
00193
00194
00195
00196 #define CATCH_PRINT } \
00197 catch(unsigned int iCode) { \
00198 ERRORVAR.AddFunc(__FUNCTION__, __FILE__); \
00199 ERRORVAR.Perror(iCode); \
00200 throw; \
00201 } \
00202 catch(...) { \
00203 ERRORVAR.AddFunc(__FUNCTION__, __FILE__); \
00204 ERRORVAR.Perror(ERROR_C_UNKNOW); \
00205 throw ERROR_C_UNKNOW; \
00206 }
00207
00208
00209
00210
00211 #define CATCH } \
00212 catch(unsigned int iCode) { \
00213 ERRORVAR.AddFunc(__FUNCTION__, __FILE__); \
00214 throw; \
00215 } \
00216 catch(...) { \
00217 ERRORVAR.AddFunc(__FUNCTION__, __FILE__); \
00218 throw ERROR_C_UNKNOW; \
00219 }
00220
00221
00222 #endif