CCAFFEINE  0.8.8
Check.h
00001 #ifndef CCAFE_KERNEL_CHECK // ccafe_kernelcheck
00002 #define CCAFE_KERNEL_CHECK // ccafe_kernelcheck
00003 #include <string>
00004 #include <stdio.h>
00005 
00006 class Thrown : public virtual ::std::exception
00007 {       
00008 private:
00009         ::std::string m;
00010 public:
00011         Thrown() { m = ""; }
00012         Thrown(const char *s) { m = s; }
00013         Thrown(const std::string & s) { m = s; }
00014         virtual ~Thrown() throw() {}
00015         virtual const char *what() const throw() { return m.c_str(); }
00016 };
00017 
00018 class Check {
00019         public:
00020                 static void DC(void *p, char *f, int l) {
00021                         if (p == 0) {
00022                                 ::std::string m = f;
00023                                 char s[40];
00024                                 ::sprintf(s, "%d", l);
00025                                 m += s;
00026                                 ::fprintf(stderr,"dynamic_cast failed at %s:%d.\n",f,l);
00027                                 Thrown t(m);
00028                                 throw t;
00029                         }
00030                 }
00031 };
00032                         
00033 #ifndef CHECKDC
00034 #define CHECKDC(p) Check::DC(p,__FILE__,__LINE__)
00035 #endif
00036 
00037 #endif // ccafe_kernelcheck