GG
|
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 #include <GG/Export.h> 00033 00034 #include <stdexcept> 00035 #include <string> 00036 00037 00038 namespace GG { 00039 00045 class GG_API ExceptionBase : public std::exception 00046 { 00047 public: 00048 ExceptionBase() throw() {} 00049 ExceptionBase(const std::string& msg) throw() : m_msg(msg) {} 00050 ~ExceptionBase() throw() {} 00051 00052 virtual const char* type() const throw() = 0; 00053 virtual const char* what() const throw() {return m_msg.c_str();} 00054 00055 private: 00056 std::string m_msg; 00057 }; 00058 00061 #define GG_EXCEPTION( name ) \ 00062 class GG_API name : public ExceptionBase \ 00063 { \ 00064 public: \ 00065 name () throw() : ExceptionBase() {} \ 00066 name (const std::string& msg) throw() : ExceptionBase(msg) {} \ 00067 virtual const char* type() const throw() \ 00068 {return "GG::" # name ;} \ 00069 }; 00070 00074 #define GG_ABSTRACT_EXCEPTION( name ) \ 00075 class GG_API name : public ExceptionBase \ 00076 { \ 00077 public: \ 00078 name () throw() : ExceptionBase() {} \ 00079 name (const std::string& msg) throw() : ExceptionBase(msg) {} \ 00080 virtual const char* type() const throw() = 0; \ 00081 }; 00082 00086 #define GG_CONCRETE_EXCEPTION( name, class_name, superclass ) \ 00087 class GG_API name : public superclass \ 00088 { \ 00089 public: \ 00090 name () throw() : superclass () {} \ 00091 name (const std::string& msg) throw() : superclass (msg) {} \ 00092 virtual const char* type() const throw() \ 00093 {return # class_name "::" # name ;} \ 00094 }; 00095 00096 } // namespace GG 00097 00098 #endif // _GG_Enum_h_