Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsSmartException.h

Go to the documentation of this file.
00001 /* 
00002  * $Id: dsSmartException.h,v 1.7 2004/09/28 10:43:18 dsamersoff Exp $
00003  */
00004 #ifndef dsSmartException_h
00005 #define dsSmartException_h
00006 
00007 #ifdef HAVE_CONFIG_H
00008 # include <config.h>
00009 #endif
00010 
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <string.h>
00014 #include <stdarg.h>
00015 #ifdef HAVE_SYSLOG_H      
00016 #include <syslog.h>
00017 #endif
00018 
00019 #include <dsStrstream.h>
00020 #include <dsform.h>
00021 
00022 
00023 #define DECLARE_EXCEPTION(tag) class  tag##Exception:public dsSmartException\
00024                         { public:\
00025                              tag##Exception(){ }\
00026                              tag##Exception(const char *format, ... )\
00027                                { va_list ap; va_start(ap, format); fire(#tag, (char *) format, ap); va_end(ap); }\
00028                              tag##Exception(int xfacility, const char *format, ... )\
00029                                { va_list ap; va_start(ap, format); fire(xfacility, #tag, (char *) format, ap); va_end(ap); }\
00030                         }
00031 
00032 
00033 #define DECLARE_EXCEPTION2(tag, parent) class  tag##Exception:public parent##Exception\
00034                         { public:\
00035                              tag##Exception(){ }\
00036                              tag##Exception(const char *format, ... )\
00037                                { va_list ap; va_start(ap, format); fire(#tag, (char *) format, ap); va_end(ap); }\
00038                              tag##Exception(int xfacility, const char *format, ... )\
00039                                { va_list ap; va_start(ap, format); fire(xfacility, #tag, (char *) format, ap); va_end(ap); }\
00040                         }
00041 
00045 class dsSmartException
00046 {
00047 protected:
00048     dsStrstream _message; 
00049     dsStrstream _tag;
00050     int _facility;
00051 
00052 
00053 public:
00054     virtual const char *msg() { return _message.str();  }
00055     virtual const char *tag() { return _tag.str();      }
00056       
00057     dsSmartException();
00058     dsSmartException(char * tag, char *format, ... );
00059     dsSmartException(int facility, char * tag, char *format, ... );
00060 
00061     virtual ~dsSmartException();
00062 
00063     void fire(int facility, char * tag, char *format, va_list ap );
00064 
00065     void fire(char *format, va_list ap );
00066     void fire(char * tag, char *format, va_list ap );
00067 
00068     virtual std::ostream& print(std::ostream& os = std::cerr);
00069      
00070     int operator ==(char *val){ return ( strcmp(_tag.str(), val) == 0 ); }  
00071 
00072     friend std::ostream &operator<<(std::ostream &stream, dsSmartException &e);
00073 };
00074 
00075 
00076 inline std::ostream &operator<<(std::ostream &stream, dsSmartException &e)
00077 { 
00078         return  e.print(stream);
00079 }
00080 
00081 #endif

Generated on Mon May 16 18:26:58 2005 for libdms4 by doxygen1.3-rc2