00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 }
00107
00108 #endif // _GG_Enum_h_