Package: Utilities        GrAL: Packages | Concepts | Homepage

Utility/pre-post-conditions.h File Reference

Some useful macros for checking pre/post conditions. More...

#include <iostream>
#include <stdlib.h>

Include dependency graph for pre-post-conditions.h:

This graph shows which files directly or indirectly include this file:

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:

Example:

 int* f(int* p) {
  REQUIRE((p != 0), "Pointer null!", 1);
  // work on p ...
  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

#define GRAL_ERROR

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.


©  Guntram Berti 1997-2009. See the GrAL Homepage for up-to-date information.

Generated on Tue Mar 31 18:53:10 2009 for Utilities by doxygen 1.5.8