gr_error_handler.h
Go to the documentation of this file.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
00039
00040
00041
00042
00043 #ifndef INCLUDED_GR_ERROR_HANDLER_H
00044 #define INCLUDED_GR_ERROR_HANDLER_H
00045
00046 #include <stdarg.h>
00047 #include <string>
00048
00053 class gr_error_handler {
00054 public:
00055 enum seriousness {
00056 ERR_DEBUG = 0x00000000,
00057 ERR_MESSAGE = 0x00010000,
00058 ERR_WARNING = 0x00020000,
00059 ERR_ERROR = 0x00030000,
00060 ERR_FATAL = 0x00040000
00061 };
00062
00063 gr_error_handler() {}
00064 virtual ~gr_error_handler();
00065
00066 static gr_error_handler *default_handler();
00067 static gr_error_handler *silent_handler();
00068
00069 static bool has_default_handler();
00070 static void set_default_handler(gr_error_handler *errh);
00071
00072 void debug(const char *format, ...);
00073 void message(const char *format, ...);
00074 void warning(const char *format, ...);
00075 void error(const char *format, ...);
00076 void fatal(const char *format, ...);
00077
00078 virtual int nwarnings() const = 0;
00079 virtual int nerrors() const = 0;
00080 virtual void reset_counts() = 0;
00081
00082 void verror(seriousness s, const char *format, va_list);
00083 void verror_text(seriousness s, const std::string &text);
00084
00085 protected:
00086 virtual void count_error(seriousness s) = 0;
00087 virtual void handle_text(seriousness s, const std::string &str) = 0;
00088 std::string make_text(seriousness s, const char *format, va_list);
00089 };
00090
00091
00092 class gr_base_error_handler : public gr_error_handler {
00093 int d_nwarnings;
00094 int d_nerrors;
00095
00096 public:
00097 gr_base_error_handler() : d_nwarnings(0), d_nerrors(0) {}
00098 int nwarnings() const { return d_nwarnings; }
00099 int nerrors() const { return d_nerrors; }
00100 void reset_counts() { d_nwarnings = d_nerrors = 0; }
00101 void count_error(seriousness s);
00102 };
00103
00104 class gr_file_error_handler : public gr_base_error_handler {
00105 FILE *d_file;
00106 int d_fd;
00107 public:
00108 gr_file_error_handler(FILE *file);
00109 gr_file_error_handler(int file_descriptor);
00110 ~gr_file_error_handler();
00111
00112 void handle_text(seriousness s, const std::string &str);
00113 };
00114
00115 #endif