00001 #ifndef NMWR_GB_PRE_POST_CONDITION_H
00002 #define NMWR_GB_PRE_POST_CONDITION_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <iostream>
00021 #include <stdlib.h>
00022
00023 #ifdef GRAL_NO_ABORT
00024 #include <exception>
00025 #endif
00026
00028
00029
00053
00054
00055
00056 #define GRAL_ERRORLOG ::std::cerr
00057 #define GRAL_ABORT ::abort()
00058 #define GRAL_DATE_INFO " (compiled on " << __DATE__ << " at " __TIME__ << " )"
00059
00060
00061 #ifdef GRAL_NO_ABORT
00062 #undef GRAL_ABORT
00063 #define GRAL_ABORT throw ::std::exception()
00064 #endif
00065
00066 #ifdef GRAL_NO_SHOW_DATE
00067 #undef GRAL_DATE_INFO
00068 #define GRAL_DATE_INFO ""
00069 #endif
00070
00071 #ifdef GRAL_NO_SHOW_FUNCTION
00072 #define GRAL_FUNCTION_INFO ""
00073 #else
00074 #define GRAL_FUNCTION_INFO " FUNCTION " << __FUNCTION__ << ", "
00075 #endif
00076
00077 #ifdef GRAL_NO_SHOW_LINE
00078 #define GRAL_LINE_INFO ""
00079 #else
00080 #define GRAL_LINE_INFO " LINE " << __LINE__ << ", "
00081 #endif
00082
00083
00084
00085 #define GRAL_ERROR GRAL_ERRORLOG \
00086 << "\n" \
00087 << "GRAL_ERROR in FILE " << __FILE__ << "\n" \
00088 << GRAL_FUNCTION_INFO \
00089 << GRAL_LINE_INFO \
00090 << GRAL_DATE_INFO << "\n"
00091
00092
00093 #define GRAL_PRECONDITION_ERROR GRAL_ERROR << " precondition violated: "
00094 #define GRAL_POSTCONDITION_ERROR GRAL_ERROR << " postcondition violated: "
00095
00096
00097
00098
00099 #define REQUIRE_ALWAYS(condition, error_msg, severity)\
00100 if(! (condition)) { GRAL_PRECONDITION_ERROR << #condition << ' ' << error_msg << ::std::endl; GRAL_ABORT;}
00101
00102 #define ENSURE_ALWAYS(condition, error_msg, severity)\
00103 if(! (condition)) { GRAL_POSTCONDITION_ERROR << #condition << ' ' << error_msg << ::std::endl; GRAL_ABORT;}
00104
00105 #ifdef NMWR_DEBUG
00106
00107 #define REQUIRE(condition, error_msg, severity) REQUIRE_ALWAYS(condition, error_msg, severity)
00108
00109
00110 #define ENSURE(condition, error_msg, severity) ENSURE_ALWAYS(condition, error_msg, severity)
00111
00112
00113 #else
00114 #define REQUIRE(condition, error_msg, severity)
00115 #define ENSURE(condition, error_msg, severity)
00116 #endif
00117
00119
00120 #endif
00121