exception.h

00001
00002 /***************************************************************************
00003  *  exception.h - basic exception
00004  *
00005  *  Generated: Thu Feb 09 13:02:37 2006 (from FireVision)
00006  *  Copyright  2005-2006  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __CORE_EXCEPTION_H_
00025 #define __CORE_EXCEPTION_H_
00026 
00027 // needed for va_list
00028 #include <cstdarg>
00029 #include <exception>
00030
00031 namespace fawkes {
00032
00033
00034 class Mutex;
00035
00036 class Exception : public std::exception {
00037  public:
00038
00039   Exception(const char *format, ...) throw();
00040   Exception(int errno, const char *format, ...) throw();
00041   Exception(const Exception &exc) throw();
00042   virtual ~Exception() throw();
00043
00044   virtual void raise();
00045   void prepend(const char *format, ...) throw();
00046   void append(const char *format, ...) throw();
00047   void append_va(const char *format, va_list va) throw();
00048   void append(const Exception &e) throw();
00049   void print_trace() throw();
00050   void print_backtrace() const throw();
00051   char *  generate_backtrace() const throw();
00052
00053   int errno() throw();
00054
00055   virtual const char* what() const throw();
00056
00057   Exception& operator=(const Exception &exc) throw();
00058
00059  protected:
00060    /** Internal exception message list */
00061    struct message_list_t {
00062      message_list_t  *next;   /**< pointer to next element, NULL if last element */
00063      char            *msg;    /**< pointer to message, may not be NULL, will be freed
00064                                *   in dtor */
00065    };
00066
00067  public:
00068   class iterator
00069   {
00070     friend class Exception;
00071    private:
00072     iterator(message_list_t *message_list);
00073    public:
00074     iterator(const iterator &i);
00075     iterator();
00076
00077     iterator &    operator++ ();        // prefix
00078     iterator      operator++ (int inc); // postfix
00079
00080     bool          operator== (const iterator & i) const;
00081     bool          operator!= (const iterator & i) const;
00082
00083     const char *  operator*  () const;
00084     iterator &    operator=  (const iterator & i);
00085
00086    private:
00087     message_list_t *mlist;
00088   };
00089
00090   iterator begin() throw();
00091   iterator end() throw();
00092
00093  protected:
00094   Exception() throw();
00095
00096   void append_nolock(const char *format, ...) throw();
00097   void append_nolock_va(const char *format, va_list va) throw();
00098   void append_nolock_nocopy(char *msg) throw();
00099   void prepend_nolock_va(const char *format, va_list va) throw();
00100   void copy_messages(const Exception &exc) throw();
00101
00102   message_list_t  *messages;
00103   message_list_t  *messages_iterator;
00104   message_list_t  *messages_end;
00105   Mutex           *messages_mutex;
00106
00107   int              _errno;
00108 };
00109
00110
00111 } // end namespace fawkes
00112
00113 #endif