exception.h

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #ifndef MECHSYS_EXCEPTION_H
00023 #define MECHSYS_EXCEPTION_H
00024 
00025 #include <iostream> // for cout
00026 #include <cstdarg>  // for va_list, va_start, va_end
00027 
00028 #include "util/string.h"
00029 
00030 class Exception
00031 {
00032 public:
00033     // Destructor
00034     virtual ~Exception() {}
00035     // Methods
00036     virtual void Cout     () const =0;
00037     virtual bool IsFatal  () const =0;
00038     virtual bool IsWarning() const =0;
00039     String       Msg      () const { return _msg; }
00040 protected:
00041     // Data
00042     String _msg;
00043 };
00044 
00045 class Message : public Exception
00046 {
00047 public:
00048     // Constructor
00049     Message(String const & Fmt, ...);
00050     // Methods
00051     void Cout     () const { std::cout << "" << "Message: " << _msg.GetSTL() << "" << std::endl; }
00052     bool IsFatal  () const { return false; }
00053     bool IsWarning() const { return false; }
00054 }; // class Message
00055 
00056 class Warning : public Exception
00057 {
00058 public:
00059     // Constructor
00060     Warning(String const & Fmt, ...);
00061     // Methods
00062     void Cout     () const { std::cout << "" << "Warning: " << _msg.GetSTL() << "" << std::endl; }
00063     bool IsFatal  () const { return false; }
00064     bool IsWarning() const { return true;  }
00065 }; // class Warning
00066 
00067 class Fatal : public Exception
00068 {
00069 public:
00070     // Constructor
00071     Fatal(String const & Fmt, ...);
00072     // Methods
00073     void Cout     () const { std::cout << "" << "Fatal: " << _msg.GetSTL() << "" << std::endl; }
00074     bool IsFatal  () const { return true;  }
00075     bool IsWarning() const { return false; }
00076 }; // class Fatal
00077 
00078 
00080 
00081 
00082 inline Message::Message(String const & Fmt, ...) // {{{
00083 {
00084     va_list       arg_list;
00085     va_start     (arg_list, Fmt);
00086     _msg.PrintfV (Fmt, arg_list);
00087     va_end       (arg_list);
00088 } // }}}
00089 
00090 inline Warning::Warning(String const & Fmt, ...) // {{{
00091 {
00092     va_list       arg_list;
00093     va_start     (arg_list, Fmt);
00094     _msg.PrintfV (Fmt, arg_list);
00095     va_end       (arg_list);
00096 } // }}}
00097 
00098 inline Fatal::Fatal(String const & Fmt, ...) // {{{
00099 {
00100     va_list       arg_list;
00101     va_start     (arg_list, Fmt);
00102     _msg.PrintfV (Fmt, arg_list);
00103     va_end       (arg_list);
00104 } // }}}
00105 
00106 #endif // MECHSYS_EXCEPTION_H
00107 
00108 // vim:fdm=marker

Generated on Wed Jan 24 15:56:27 2007 for MechSys by  doxygen 1.4.7