00001
00002
00004
00006
00007
00008
00009
00010
00016 #ifndef _Exception_h
00017 #define _Exception_h
00018
00019 #if !defined(_WIN32)
00020 #define EXPORT_SRM_CPP_DLL
00021 #elif defined(BUILD_SRM_CPP)
00022 #if !defined(EXPORT_SRM_CPP_DLL)
00023 #if defined(_LIB)
00024 #define EXPORT_SRM_CPP_DLL
00025 #elif defined(_USRDLL)
00026 #define EXPORT_SRM_CPP_DLL __declspec(dllexport)
00027 #else
00028 #define EXPORT_SRM_CPP_DLL __declspec(dllimport)
00029 #endif
00030 #endif
00031 #else
00032 #define EXPORT_SRM_CPP_DLL
00033 #endif
00034
00035 #include "srm_types.h"
00036
00043 namespace srm
00044 {
00045
00051 class EXPORT_SRM_CPP_DLL Exception
00052 {
00053 public:
00054
00055 enum {
00057 MAX_EXCEPTION_STR_LEN = 2000
00058 };
00059
00061 Exception( SRM_Status_Code code );
00063 Exception( SRM_Status_Code code, const char *what );
00065 Exception( const Exception &other );
00067 virtual ~Exception() {}
00068
00070 Exception &operator =( const Exception &other );
00071
00073 virtual void setCodeAndWhat( SRM_Status_Code code, const char *what )
00074 {
00075 int i=0;
00076 _code = code;
00077 while (what && *what && i < MAX_EXCEPTION_STR_LEN)
00078 _what[i] = *what, i++, what++;
00079 _what[i] = 0;
00080 }
00081
00083 virtual SRM_Status_Code getCode() const { return _code; }
00085 virtual const char *getWhat() const { return _what; }
00086
00087 protected:
00088
00089 SRM_Status_Code _code;
00090 char _what[MAX_EXCEPTION_STR_LEN+1];
00091 };
00092
00093
00095
00096 inline Exception::Exception( SRM_Status_Code code )
00097 {
00098 setCodeAndWhat(code, "No details");
00099 }
00100
00101
00102 inline Exception::Exception( SRM_Status_Code code, const char *what )
00103 {
00104 setCodeAndWhat(code, what);
00105 }
00106
00107
00108 inline Exception::Exception( const Exception &other )
00109 {
00110 setCodeAndWhat(other.getCode(), other.getWhat());
00111 }
00112
00113
00114 inline Exception &Exception::operator =( const Exception &other )
00115 {
00116 setCodeAndWhat(other.getCode(), other.getWhat());
00117 return *this;
00118 }
00119
00120
00121 }
00122
00123 #endif // _Exception_h