00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018                                                                                                 
00019                              
00020 #ifndef _Error_incl_
00021 #define _Error_incl_
00022 
00023 #include <stdexcept>
00024 #include <rlog/common.h>
00025 
00026 #include <string>
00027 
00028 namespace rlog
00029 {
00030     class RLOG_DECL RLogChannel;
00031 
00032     
00033     class RLOG_DECL Error : public std::runtime_error
00034     {
00035     public:
00036         Error( const char *component, const char *file, const char *function,
00037                 int line, const char *msg );
00038         Error( const char *component, const char *file, const char *function,
00039                 int line, const std::string &msg );
00040         Error(const Error &src );
00041         virtual ~Error() throw();
00042 
00043         Error &operator = (const Error &src);
00044 
00045         void log( RLogChannel * channel ) const;
00046 
00047         const char *component() const;
00048         const char *file() const;
00049         const char *function() const;
00050         int line() const;
00051         const char *message() const;
00052 
00053     private:
00054         struct ErrorData *data;
00055     };
00056 
00057     std::string _format_msg( const char *fmt, ... ) PRINTF(1,2);
00058 }
00059 
00060 #define _ERROR_IMPL( COMPONENT, MSG ) \
00061     rlog::Error( STR(COMPONENT), __FILE__, __FUNCTION__, __LINE__, MSG )
00062 
00063 #define ERROR( MSG ) _ERROR_IMPL( RLOG_COMPONENT, MSG )
00064 
00065 #if C99_VARIADAC_MACROS
00066 #define _ERROR_IMPL_VA( COMPONENT, FMT, ... ) \
00067     rlog::Error( STR(COMPONENT), __FILE__, __FUNCTION__, __LINE__, \
00068             rlog::_format_msg( FMT, __VA_ARGS__ ) )
00069 #define ERROR_FMT( FMT, ... ) _ERROR_IMPL_VA( RLOG_COMPONENT, FMT, __VA_ARGS__ )
00070 #elif PREC99_VARIADIC_MACROS
00071 #define _ERROR_IMPL_VA( COMPONENT, FMT, ARGS... ) \
00072     rlog::Error( STR(COMPONENT), __FILE__, __FUNCTION__, __LINE__, \
00073             rlog::_format_msg( FMT, ##ARGS ) )
00074 #define ERROR_FMT( FMT, ARGS... ) _ERROR_IMPL_VA( RLOG_COMPONENT, FMT, ##ARGS )
00075 #else
00076 
00077 #endif
00078 
00079 #endif
00080