00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef OM_HGUARD_OMERROR_H
00024 #define OM_HGUARD_OMERROR_H
00025
00026 #include <string>
00027
00028 #include "om/omtypes.h"
00029
00030 class OmErrorHandler;
00031
00033 class OmError {
00034 friend class OmErrorHandler;
00035 private:
00037 std::string msg;
00038
00040 std::string context;
00041
00043 std::string type;
00044
00046 int errno_value;
00047
00049 bool has_been_handled;
00050
00052 void operator=(const OmError ©me);
00053 protected:
00057 OmError(const std::string &msg_,
00058 const std::string &context_,
00059 const std::string &type_,
00060 int errno_value_);
00061
00062 OmError(const OmError ©me)
00063 : msg(copyme.msg),
00064 context(copyme.context),
00065 type(copyme.type),
00066 errno_value(copyme.errno_value),
00067 has_been_handled(copyme.has_been_handled) {}
00068 public:
00072 std::string get_msg() const
00073 {
00074 return msg;
00075 }
00076
00078 std::string get_type() const
00079 {
00080 return type;
00081 }
00082
00084 std::string get_context() const
00085 {
00086 return context;
00087 }
00088
00090 int get_errno() const
00091 {
00092 return errno_value;
00093 }
00094
00096
00097
00098 virtual ~OmError();
00099 };
00100
00101 inline OmError::~OmError() {}
00102
00103 #define DEFINE_ERROR_BASECLASS(a, b) \
00104 class a : public b { \
00105 protected: \
00106 \
00107 a(const std::string &msg_, \
00108 const std::string &context_, \
00109 const std::string &type_, \
00110 int errno_value_) : b(msg_, context_, type_, errno_value_) {}; \
00111 }
00112
00113 #define DEFINE_ERROR_CLASS(a, b) \
00114 class a : public b { \
00115 public: \
00116 \
00117 a(const std::string &msg_, \
00118 const std::string &context_ = "", \
00119 int errno_value_ = 0) : b(msg_, context_, #a, errno_value_) {}; \
00120 \
00121 a(const std::string &msg_, \
00122 int errno_value_) : b(msg_, "", #a, errno_value_) {}; \
00123 protected: \
00124 \
00125 a(const std::string &msg_, \
00126 const std::string &context_, \
00127 const std::string &type_, \
00128 int errno_value_) : b(msg_, context_, type_, errno_value_) {}; \
00129 }
00130
00131 #include "om/omerrortypes.h"
00132
00133 #undef DEFINE_ERROR_BASECLASS
00134 #undef DEFINE_ERROR_CLASS
00135
00136 #endif