00001
00002
00003
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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifndef NEW_MAT_EXCEPTION_LIB
00050 #define NEW_MAT_EXCEPTION_LIB
00051
00052
00053 #ifdef use_namespace
00054 namespace RBD_COMMON {
00055 #endif
00056
00057
00058 void Terminate();
00059
00060
00061
00062
00063 class BaseException;
00064
00065 class Tracer
00066 {
00067 const char* entry;
00068 Tracer* previous;
00069 public:
00070 Tracer(const char*);
00071 ~Tracer();
00072 void ReName(const char*);
00073 static void PrintTrace();
00074 static void AddTrace();
00075 static Tracer* last;
00076 friend class BaseException;
00077 };
00078
00079
00080 class BaseException
00081 {
00082 protected:
00083 static char* what_error;
00084 static int SoFar;
00085 static int LastOne;
00086 public:
00087 static void AddMessage(const char* a_what);
00088
00089 static void AddInt(int value);
00090 static unsigned long Select;
00091 BaseException(const char* a_what = 0);
00092 static const char* what() { return what_error; }
00093
00094 };
00095
00096 #ifdef TypeDefException
00097 typedef BaseException Exception;
00098 #endif
00099
00100 inline Tracer::Tracer(const char* e)
00101 : entry(e), previous(last) { last = this; }
00102
00103 inline Tracer::~Tracer() { last = previous; }
00104
00105 inline void Tracer::ReName(const char* e) { entry=e; }
00106
00107 #ifdef SimulateExceptions // SimulateExceptions
00108
00109 #include <setjmp.h>
00110
00111
00112
00113
00114
00115 class JumpItem;
00116 class Janitor;
00117
00118 class JumpBase
00119 {
00120 public:
00121 static JumpItem *jl;
00122 static jmp_buf env;
00123 };
00124
00125 class JumpItem
00126 {
00127 public:
00128 JumpItem *ji;
00129 jmp_buf env;
00130 Tracer* trace;
00131 Janitor* janitor;
00132 JumpItem() : ji(JumpBase::jl), trace(0), janitor(0)
00133 { JumpBase::jl = this; }
00134 ~JumpItem() { JumpBase::jl = ji; }
00135 };
00136
00137 void Throw();
00138
00139 inline void Throw(const BaseException&) { Throw(); }
00140
00141 #define Try \
00142 if (!setjmp( JumpBase::jl->env )) { \
00143 JumpBase::jl->trace = Tracer::last; \
00144 JumpItem JI387256156;
00145
00146 #define ReThrow Throw()
00147
00148 #define Catch(EXCEPTION) \
00149 } else if (BaseException::Select == EXCEPTION::Select) {
00150
00151 #define CatchAll } else
00152
00153 #define CatchAndThrow } else Throw();
00154
00155
00156
00157
00158 class Janitor
00159 {
00160 protected:
00161 static bool do_not_link;
00162 bool OnStack;
00163 public:
00164 Janitor* NextJanitor;
00165 virtual void CleanUp() {}
00166 Janitor();
00167 virtual ~Janitor();
00168 };
00169
00170
00171
00172
00173
00174
00175 class JanitorInitializer
00176 {
00177 public:
00178 JanitorInitializer();
00179 private:
00180 static int ref_count;
00181 };
00182
00183 static JanitorInitializer JanInit;
00184
00185 #endif // end of SimulateExceptions
00186
00187 #ifdef UseExceptions
00188
00189 #define Try try
00190 #define Throw(E) throw E
00191 #define ReThrow throw
00192 #define Catch catch
00193 #define CatchAll catch(...)
00194 #define CatchAndThrow {}
00195
00196 #endif // end of UseExceptions
00197
00198
00199 #ifdef DisableExceptions // Disable exceptions
00200
00201 #define Try {
00202 #define ReThrow Throw()
00203 #define Catch(EXCEPTION) } if (false) {
00204 #define CatchAll } if (false)
00205 #define CatchAndThrow }
00206
00207 inline void Throw() { Terminate(); }
00208 inline void Throw(const BaseException&) { Terminate(); }
00209
00210
00211 #endif // end of DisableExceptions
00212
00213 #ifndef SimulateExceptions // ! SimulateExceptions
00214
00215 class Janitor
00216 {
00217 public:
00218 virtual void CleanUp() {}
00219 Janitor() {}
00220 virtual ~Janitor() {}
00221 };
00222
00223 #endif // end of ! SimulateExceptions
00224
00225
00226
00227
00228 #ifdef DO_FREE_CHECK // DO_FREE_CHECK
00229
00230
00231 class FreeCheck;
00232
00233 class FreeCheckLink
00234 {
00235 protected:
00236 FreeCheckLink* next;
00237 void* ClassStore;
00238 FreeCheckLink();
00239 virtual void Report()=0;
00240 friend class FreeCheck;
00241 };
00242
00243 class FCLClass : public FreeCheckLink
00244 {
00245 char* ClassName;
00246 FCLClass(void* t, char* name);
00247 void Report();
00248 friend class FreeCheck;
00249 };
00250
00251 class FCLRealArray : public FreeCheckLink
00252 {
00253 char* Operation;
00254 int size;
00255 FCLRealArray(void* t, char* o, int s);
00256 void Report();
00257 friend class FreeCheck;
00258 };
00259
00260 class FCLIntArray : public FreeCheckLink
00261 {
00262 char* Operation;
00263 int size;
00264 FCLIntArray(void* t, char* o, int s);
00265 void Report();
00266 friend class FreeCheck;
00267 };
00268
00269
00270 class FreeCheck
00271 {
00272 static FreeCheckLink* next;
00273 static int BadDelete;
00274 public:
00275 static void Register(void*, char*);
00276 static void DeRegister(void*, char*);
00277 static void RegisterR(void*, char*, int);
00278 static void DeRegisterR(void*, char*, int);
00279 static void RegisterI(void*, char*, int);
00280 static void DeRegisterI(void*, char*, int);
00281 static void Status();
00282 friend class FreeCheckLink;
00283 friend class FCLClass;
00284 friend class FCLRealArray;
00285 friend class FCLIntArray;
00286 };
00287
00288 #define FREE_CHECK(Class) \
00289 public: \
00290 void* operator new(size_t size) \
00291 { \
00292 void* t = ::operator new(size); FreeCheck::Register(t,#Class); \
00293 return t; \
00294 } \
00295 void operator delete(void* t) \
00296 { FreeCheck::DeRegister(t,#Class); ::operator delete(t); }
00297
00298
00299 #ifdef SimulateExceptions // SimulateExceptions
00300
00301 #define NEW_DELETE(Class) \
00302 public: \
00303 void* operator new(size_t size) \
00304 { \
00305 do_not_link=true; \
00306 void* t = ::operator new(size); FreeCheck::Register(t,#Class); \
00307 return t; \
00308 } \
00309 void operator delete(void* t) \
00310 { FreeCheck::DeRegister(t,#Class); ::operator delete(t); }
00311
00312
00313 #endif // end of SimulateExceptions
00314
00315
00316 #define MONITOR_REAL_NEW(Operation, Size, Pointer) \
00317 FreeCheck::RegisterR(Pointer, Operation, Size);
00318 #define MONITOR_INT_NEW(Operation, Size, Pointer) \
00319 FreeCheck::RegisterI(Pointer, Operation, Size);
00320 #define MONITOR_REAL_DELETE(Operation, Size, Pointer) \
00321 FreeCheck::DeRegisterR(Pointer, Operation, Size);
00322 #define MONITOR_INT_DELETE(Operation, Size, Pointer) \
00323 FreeCheck::DeRegisterI(Pointer, Operation, Size);
00324
00325 #else // DO_FREE_CHECK not defined
00326
00327 #define FREE_CHECK(Class) public:
00328 #define MONITOR_REAL_NEW(Operation, Size, Pointer) {}
00329 #define MONITOR_INT_NEW(Operation, Size, Pointer) {}
00330 #define MONITOR_REAL_DELETE(Operation, Size, Pointer) {}
00331 #define MONITOR_INT_DELETE(Operation, Size, Pointer) {}
00332
00333
00334 #ifdef SimulateExceptions // SimulateExceptions
00335
00336
00337 #define NEW_DELETE(Class) \
00338 public: \
00339 void* operator new(size_t size) \
00340 { do_not_link=true; void* t = ::operator new(size); return t; } \
00341 void operator delete(void* t) { ::operator delete(t); }
00342
00343 #endif // end of SimulateExceptions
00344
00345 #endif // end of ! DO_FREE_CHECK
00346
00347 #ifndef SimulateExceptions // ! SimulateExceptions
00348
00349 #define NEW_DELETE(Class) FREE_CHECK(Class)
00350
00351 #endif // end of ! SimulateExceptions
00352
00353
00354
00355
00356 class Logic_error : public BaseException
00357 {
00358 public:
00359 static unsigned long Select;
00360 Logic_error(const char* a_what = 0);
00361 };
00362
00363 class Runtime_error : public BaseException
00364 {
00365 public:
00366 static unsigned long Select;
00367 Runtime_error(const char* a_what = 0);
00368 };
00369
00370 class Domain_error : public Logic_error
00371 {
00372 public:
00373 static unsigned long Select;
00374 Domain_error(const char* a_what = 0);
00375 };
00376
00377 class Invalid_argument : public Logic_error
00378 {
00379 public:
00380 static unsigned long Select;
00381 Invalid_argument(const char* a_what = 0);
00382 };
00383
00384 class Length_error : public Logic_error
00385 {
00386 public:
00387 static unsigned long Select;
00388 Length_error(const char* a_what = 0);
00389 };
00390
00391 class Out_of_range : public Logic_error
00392 {
00393 public:
00394 static unsigned long Select;
00395 Out_of_range(const char* a_what = 0);
00396 };
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412 class Range_error : public Runtime_error
00413 {
00414 public:
00415 static unsigned long Select;
00416 Range_error(const char* a_what = 0);
00417 };
00418
00419 class Overflow_error : public Runtime_error
00420 {
00421 public:
00422 static unsigned long Select;
00423 Overflow_error(const char* a_what = 0);
00424 };
00425
00426 class Bad_alloc : public BaseException
00427 {
00428 public:
00429 static unsigned long Select;
00430 Bad_alloc(const char* a_what = 0);
00431 };
00432
00433 #ifdef use_namespace
00434 }
00435 #endif
00436
00437
00438 #endif // end of EXCEPTION_LIB
00439
00440
00441
00442
00443
00445