00001
00002
00003 #ifndef CoinError_H
00004 #define CoinError_H
00005
00006 #include <string>
00007 #include <iostream>
00008 #include <cassert>
00009
00010
00011
00012
00013
00014
00015
00016
00030 class CoinError {
00031 friend void CoinErrorUnitTest();
00032
00033 private:
00034 CoinError()
00035 :
00036 message_(),
00037 method_(),
00038 class_(),
00039 file_(),
00040 lineNumber_(-1)
00041 {
00042
00043 }
00044
00045 public:
00046
00047
00048
00049
00052
00053 inline const std::string & message() const
00054 { return message_; }
00056 inline const std::string & methodName() const
00057 { return method_; }
00059 inline const std::string & className() const
00060 { return class_; }
00062 inline const std::string & fileName() const
00063 { return file_; }
00065 inline int lineNumber() const
00066 { return lineNumber_; }
00068 void print() const;
00070
00071
00074
00075 CoinError (
00076 std::string message,
00077 std::string methodName,
00078 std::string className)
00079 :
00080 message_(message),
00081 method_(methodName),
00082 class_(className),
00083 file_(),
00084 lineNumber_(-1)
00085 {
00086
00087 }
00088
00090 CoinError (
00091 const char * message,
00092 const char * methodName,
00093 const char * className)
00094 :
00095 message_(message),
00096 method_(methodName),
00097 class_(className),
00098 file_(),
00099 lineNumber_(-1)
00100 {
00101
00102 }
00103
00105 CoinError (
00106 const char * assertion,
00107 const char * methodName,
00108 const char * hint,
00109 const char * fileName,
00110 int line);
00111
00113 CoinError (const CoinError & source);
00114
00116 CoinError & operator=(const CoinError& rhs);
00117
00119 virtual ~CoinError ()
00120 {
00121
00122 }
00124
00125 private:
00126
00129
00130 std::string message_;
00132 std::string method_;
00134 std::string class_;
00136 std::string file_;
00138 int lineNumber_;
00140 };
00141
00142 #ifndef __GNUC_PREREQ
00143 # define __GNUC_PREREQ(maj, min) (0)
00144 #endif
00145
00146 #ifndef __STRING
00147 #define __STRING(x) #x
00148 #endif
00149
00150 #ifndef COIN_ASSERT
00151 # define CoinAssertDebug(expression) assert(expression)
00152 # define CoinAssertDebugHint(expression,hint) assert(expression)
00153 # define CoinAssert(expression) assert(expression)
00154 # define CoinAssertHint(expression,hint) assert(expression)
00155 #else
00156 # ifdef NDEBUG
00157 # define CoinAssertDebug(expression) {}
00158 # define CoinAssertDebugHint(expression,hint) {}
00159 # else
00160 # if defined(__GNUC__) && __GNUC_PREREQ(2, 6)
00161 # define CoinAssertDebug(expression) { \
00162 if (!(expression)) { \
00163 throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, \
00164 "", __FILE__, __LINE__); \
00165 } \
00166 }
00167 # define CoinAssertDebugHint(expression,hint) { \
00168 if (!(expression)) { \
00169 throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, \
00170 hint, __FILE__,__LINE__); \
00171 } \
00172 }
00173 # else
00174 # define CoinAssertDebug(expression) { \
00175 if (!(expression)) { \
00176 throw CoinError(__STRING(expression), "", \
00177 "", __FILE__,__LINE__); \
00178 } \
00179 }
00180 # define CoinAssertDebugHint(expression,hint) { \
00181 if (!(expression)) { \
00182 throw CoinError(__STRING(expression), "", \
00183 hint, __FILE__,__LINE__); \
00184 } \
00185 }
00186 # endif
00187 # endif
00188 # if defined(__GNUC__) && __GNUC_PREREQ(2, 6)
00189 # define CoinAssert(expression) { \
00190 if (!(expression)) { \
00191 throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, \
00192 "", __FILE__, __LINE__); \
00193 } \
00194 }
00195 # define CoinAssertHint(expression,hint) { \
00196 if (!(expression)) { \
00197 throw CoinError(__STRING(expression), __PRETTY_FUNCTION__, \
00198 hint, __FILE__,__LINE__); \
00199 } \
00200 }
00201 # else
00202 # define CoinAssert(expression) { \
00203 if (!(expression)) { \
00204 throw CoinError(__STRING(expression), "", \
00205 "", __FILE__,__LINE__); \
00206 } \
00207 }
00208 # define CoinAssertHint(expression,hint) { \
00209 if (!(expression)) { \
00210 throw CoinError(__STRING(expression), "", \
00211 hint, __FILE__,__LINE__); \
00212 } \
00213 }
00214 # endif
00215 #endif
00216
00217
00218
00224 void
00225 CoinErrorUnitTest();
00226
00227 #endif