1 /***************************************************************************** 2 * Author: Valient Gough <vgough@pobox.com> 3 * 4 ***************************************************************************** 5 * Copyright (c) 2004, Valient Gough 6 * 7 * This library is free software; you can distribute it and/or modify it under 8 * the terms of the GNU Lesser General Public License (LGPL), as published by 9 * the Free Software Foundation; either version 2.1 of the License, or (at your 10 * option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the LGPL in the file COPYING for more 15 * details. 16 * 17 */ 18 19 20 #ifndef _Error_incl_ 21 #define _Error_incl_ 22 23 #include <stdexcept> 24 #include <rlog/common.h> 25 26 #include <string> 27 28 namespace rlog 29 { 30 class RLOG_DECL RLogChannel; 31 32 // Documentation in implementation file 33 class RLOG_DECL Error : public std::runtime_error 34 { 35 public: 36 Error( const char *component, const char *file, const char *function, 37 int line, const char *msg ); 38 Error( const char *component, const char *file, const char *function, 39 int line, const std::string &msg ); 40 Error(const Error &src ); 41 virtual ~Error() throw(); 42 43 Error &operator = (const Error &src); 44 45 void log( RLogChannel * channel ) const; 46 47 const char *component() const; 48 const char *file() const; 49 const char *function() const; 50 int line() const; 51 const char *message() const; 52 53 private: 54 struct ErrorData *data; 55 }; 56 57 std::string _format_msg( const char *fmt, ... ) PRINTF(1,2); 58 } 59 60 #define _ERROR_IMPL( COMPONENT, MSG ) \ 61 rlog::Error( STR(COMPONENT), __FILE__, __FUNCTION__, __LINE__, MSG ) 62 63 #define ERROR( MSG ) _ERROR_IMPL( RLOG_COMPONENT, MSG ) 64 65 #if C99_VARIADAC_MACROS 66 #define _ERROR_IMPL_VA( COMPONENT, FMT, ... ) \ 67 rlog::Error( STR(COMPONENT), __FILE__, __FUNCTION__, __LINE__, \ 68 rlog::_format_msg( FMT, __VA_ARGS__ ) ) 69 #define ERROR_FMT( FMT, ... ) _ERROR_IMPL_VA( RLOG_COMPONENT, FMT, __VA_ARGS__ ) 70 #elif PREC99_VARIADIC_MACROS 71 #define _ERROR_IMPL_VA( COMPONENT, FMT, ARGS... ) \ 72 rlog::Error( STR(COMPONENT), __FILE__, __FUNCTION__, __LINE__, \ 73 rlog::_format_msg( FMT, ##ARGS ) ) 74 #define ERROR_FMT( FMT, ARGS... ) _ERROR_IMPL_VA( RLOG_COMPONENT, FMT, ##ARGS ) 75 #else 76 // TODO: implement for no variadics case.. 77 #endif 78 79 #endif 80 81