00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef XBASE_H
00016 #define XBASE_H
00017
00018 #include "CString.h"
00019
00021
00024 class XBase {
00025 public:
00027 XBase();
00029 XBase(const CString& msg);
00030 virtual ~XBase();
00031
00033 virtual const char* what() const;
00034
00035 protected:
00037 virtual CString getWhat() const throw() = 0;
00038
00040
00045 virtual CString format(const char* id,
00046 const char* defaultFormat, ...) const throw();
00047
00048 private:
00049 mutable CString m_what;
00050 };
00051
00058 #define XBASE_SUBCLASS(name_, super_) \
00059 class name_ : public super_ { \
00060 public: \
00061 name_() : super_() { } \
00062 name_(const CString& msg) : super_(msg) { } \
00063 }
00064
00071 #define XBASE_SUBCLASS_WHAT(name_, super_) \
00072 class name_ : public super_ { \
00073 public: \
00074 name_() : super_() { } \
00075 name_(const CString& msg) : super_(msg) { } \
00076 \
00077 protected: \
00078 virtual CString getWhat() const throw(); \
00079 }
00080
00089 #define XBASE_SUBCLASS_FORMAT(name_, super_) \
00090 class name_ : public super_ { \
00091 private: \
00092 enum EState { kFirst, kFormat, kDone }; \
00093 \
00094 public: \
00095 name_() : super_(), m_state(kDone) { } \
00096 name_(const CString& msg) : super_(msg), m_state(kFirst) { } \
00097 \
00098 virtual const char* what() const \
00099 { \
00100 if (m_state == kFirst) { \
00101 m_state = kFormat; \
00102 m_formatted = getWhat(); \
00103 m_state = kDone; \
00104 } \
00105 if (m_state == kDone) { \
00106 return m_formatted.c_str(); \
00107 } \
00108 else { \
00109 return super_::what(); \
00110 } \
00111 } \
00112 \
00113 protected: \
00114 virtual CString getWhat() const throw(); \
00115 \
00116 private: \
00117 mutable EState m_state; \
00118 mutable std::string m_formatted; \
00119 }
00120
00121 #endif