Exception.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003 T. Zachary Laine
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License
00007    as published by the Free Software Foundation; either version 2.1
00008    of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014     
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA
00019 
00020    If you do not wish to comply with the terms of the LGPL please
00021    contact the author as other terms are available for a fee.
00022     
00023    Zach Laine
00024    whatwasthataddress@hotmail.com */
00025    
00029 #ifndef _GG_Exception_h_
00030 #define _GG_Exception_h_
00031 
00032 #ifndef GG_API
00033 # ifdef _MSC_VER
00034 #  define WIN32_LEAN_AND_MEAN
00035 #  include <windows.h>
00036 #  undef min
00037 #  undef max
00038 #  ifdef GIGI_EXPORTS
00039 #   define GG_API __declspec(dllexport)
00040 #  else
00041 #   define GG_API __declspec(dllimport)
00042 #  endif
00043 # else
00044 #  define GG_API
00045 # endif
00046 #endif
00047 
00048 #include <stdexcept>
00049 #include <string>
00050 
00051 
00052 namespace GG {
00053 
00057 class GG_API ExceptionBase : public std::exception
00058 {
00059 public:
00060     ExceptionBase() throw() {}                                      
00061     ExceptionBase(const std::string& msg) throw() : m_msg(msg) {}   
00062     ~ExceptionBase() throw() {}                                     
00063 
00064     virtual const char* type() const throw() = 0;                   
00065     virtual const char* what() const throw() {return m_msg.c_str();}
00066 
00067 private:
00068     std::string m_msg; 
00069 };
00070 
00072 #define GG_EXCEPTION( name )                                            \
00073     class GG_API name : public ExceptionBase                            \
00074     {                                                                   \
00075     public:                                                             \
00076         name () throw() : ExceptionBase() {}                            \
00077         name (const std::string& msg) throw() : ExceptionBase(msg) {}   \
00078         virtual const char* type() const throw()                        \
00079             {return "GG::" # name ;}                                    \
00080     };
00081 
00085 #define GG_ABSTRACT_EXCEPTION( name )                                   \
00086     class GG_API name : public ExceptionBase                            \
00087     {                                                                   \
00088     public:                                                             \
00089         name () throw() : ExceptionBase() {}                            \
00090         name (const std::string& msg) throw() : ExceptionBase(msg) {}   \
00091         virtual const char* type() const throw() = 0;                   \
00092     };
00093 
00096 #define GG_CONCRETE_EXCEPTION( name, class_name, superclass )           \
00097     class GG_API name : public superclass                               \
00098     {                                                                   \
00099     public:                                                             \
00100         name () throw() : superclass () {}                              \
00101         name (const std::string& msg) throw() : superclass (msg) {}     \
00102         virtual const char* type() const throw()                        \
00103             {return # class_name "::" # name ;}                         \
00104     };
00105 
00106 } // namespace GG
00107 
00108 #endif // _GG_Enum_h_

Generated on Wed Mar 26 14:35:41 2008 for GG by  doxygen 1.5.2