rlog: Error.h Source File

- Main Page
- Modules
- Classes
- Files
- Related Pages

# Error.h

    00001 /*****************************************************************************
    00002  * Author:   Valient Gough <vgough@pobox.com>
    00003  *
    00004  *****************************************************************************
    00005  * Copyright (c) 2004, Valient Gough
    00006  *
    00007  * This library is free software; you can distribute it and/or modify it under
    00008  * the terms of the GNU Lesser General Public License (LGPL), as published by
    00009  * the Free Software Foundation; either version 2.1 of the License, or (at your
    00010  * option) any later version.
    00011  *
    00012  * This library is distributed in the hope that it will be useful, but WITHOUT
    00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00014  * FITNESS FOR A PARTICULAR PURPOSE.  See the LGPL in the file COPYING for more
    00015  * details.
    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     // Documentation in implementation file
    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 // TODO: implement for no variadics case..
    00077 #endif
    00078
    00079 #endif
    00080