Exception.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003-2008 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@gmail.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 
00059 class GG_API ExceptionBase : public std::exception
00060 {
00061 public:
00062     ExceptionBase() throw() {}                                      
00063     ExceptionBase(const std::string& msg) throw() : m_msg(msg) {}   
00064     ~ExceptionBase() throw() {}                                     
00065 
00066     virtual const char* type() const throw() = 0;                   
00067     virtual const char* what() const throw() {return m_msg.c_str();}
00068 
00069 private:
00070     std::string m_msg; 
00071 };
00072 
00075 #define GG_EXCEPTION( name )                                            \
00076     class GG_API name : public ExceptionBase                            \
00077     {                                                                   \
00078     public:                                                             \
00079         name () throw() : ExceptionBase() {}                            \
00080         name (const std::string& msg) throw() : ExceptionBase(msg) {}   \
00081         virtual const char* type() const throw()                        \
00082             {return "GG::" # name ;}                                    \
00083     };
00084 
00088 #define GG_ABSTRACT_EXCEPTION( name )                                   \
00089     class GG_API name : public ExceptionBase                            \
00090     {                                                                   \
00091     public:                                                             \
00092         name () throw() : ExceptionBase() {}                            \
00093         name (const std::string& msg) throw() : ExceptionBase(msg) {}   \
00094         virtual const char* type() const throw() = 0;                   \
00095     };
00096 
00100 #define GG_CONCRETE_EXCEPTION( name, class_name, superclass )           \
00101     class GG_API name : public superclass                               \
00102     {                                                                   \
00103     public:                                                             \
00104         name () throw() : superclass () {}                              \
00105         name (const std::string& msg) throw() : superclass (msg) {}     \
00106         virtual const char* type() const throw()                        \
00107             {return # class_name "::" # name ;}                         \
00108     };
00109 
00110 } // namespace GG
00111 
00112 #endif // _GG_Enum_h_

Generated on Sat Mar 26 07:08:37 2011 for GG by  doxygen 1.5.9