Utility/pre-post-conditions.h File Reference
Some useful macros for checking pre/post conditions.
More...
#include <iostream>
#include <stdlib.h>
Go to the source code of this file.
|
Defines |
|
|
#define | GRAL_ERRORLOG ::std::cerr |
|
#define | GRAL_ABORT ::abort() |
|
#define | GRAL_DATE_INFO " (compiled on " << __DATE__ << " at " __TIME__ << " )" |
|
#define | GRAL_FUNCTION_INFO " FUNCTION " << __FUNCTION__ << ", " |
|
#define | GRAL_LINE_INFO " LINE " << __LINE__ << ", " |
| #define | GRAL_ERROR |
|
#define | GRAL_PRECONDITION_ERROR GRAL_ERROR << " precondition violated: " |
|
#define | GRAL_POSTCONDITION_ERROR GRAL_ERROR << " postcondition violated: " |
|
#define | REQUIRE_ALWAYS(condition, error_msg, severity) if(! (condition)) { GRAL_PRECONDITION_ERROR << #condition << ' ' << error_msg << ::std::endl; GRAL_ABORT;} |
|
#define | ENSURE_ALWAYS(condition, error_msg, severity) if(! (condition)) { GRAL_POSTCONDITION_ERROR << #condition << ' ' << error_msg << ::std::endl; GRAL_ABORT;} |
|
#define | REQUIRE(condition, error_msg, severity) |
|
#define | ENSURE(condition, error_msg, severity) |
Detailed Description
Some useful macros for checking pre/post conditions.
Two different sets of macros are defined:
- REQUIRE/ENSURE (condition, message, severity) are defined only if
NMWR_DEBUG is defined - REQUIRE_ALWAY/ENSURE_ALWAYS (condition, message, severity) are always defined
Example:
int* f(int* p) {
REQUIRE((p != 0), "Pointer null!", 1);
ENSURE((p != 0), "Pointer null!", 1);
}
To modify the default behavior, you can define the macros GRAL_NO_ABORT (to throw an exception instead of aborting) and GRAL_NO_SHOW_DATE to inhibit printing date/time of compilation (useful for regression tests).
Definition in file pre-post-conditions.h.
Define Documentation
Value:
GRAL_ERRORLOG \
<< "\n" \
<< "GRAL_ERROR in FILE " << __FILE__ << "\n" \
<< GRAL_FUNCTION_INFO \
<< GRAL_LINE_INFO \
<< GRAL_DATE_INFO << "\n"
Definition at line 85 of file pre-post-conditions.h.