C++ Library, mos@ua  0.9
cpplib-mos
DbC

Design-by-Contract module. More...

Files

file  dbc.h
 Design-by-Contract module.
 

Macros

#define check(condition, message)
 Checks the verification of an general algorithm assertion. More...
 
#define require(condition, message)
 Checks the verification of a precondition. More...
 
#define ensure(condition, message)
 Checks the verification of a postcondition. More...
 
#define invariant(condition, message)
 Checks the verification of an invariant. More...
 

Detailed Description

Design-by-Contract module.

This module gives a better support for DbC in C++.

When compared with assert.h this module offers the following functionalities:

Debug settings:

Author
Miguel Oliveira e Silva, 2018

Macro Definition Documentation

◆ check

#define check (   condition,
  message 
)
Value:
if (!(condition)) \
do { \
fprintf (stderr, "Assertion fail%s%s, assertion: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \
message[0] ? ": " : "", message, #condition, __FUNCTION__, __LINE__ , __FILE__); \
*((int*)0) = 0; \
abort (); \
} while (0)

Checks the verification of an general algorithm assertion.

This assertion verification can be disabled at compile time by defining the macro NDEBUG_CHECKS.

Parameters
[in]conditionexpression to assert its truthness
[in]messagetext to be presented with error information when the assertion fails

◆ require

#define require (   condition,
  message 
)
Value:
if (!(condition)) \
do { \
fprintf (stderr, "Precondition fail%s%s, assertion: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \
message[0] ? ": " : "", message, #condition, __FUNCTION__, __LINE__ , __FILE__); \
*((int*)0) = 0; \
abort (); \
} while (0)

Checks the verification of a precondition.

This assertion verification can be disabled at compile time by defining the macro NDEBUG_PRECONDITIONS.

Parameters
[in]conditionexpression to assert its truthness
[in]messagetext to be presented with error information when the assertion fails

◆ ensure

#define ensure (   condition,
  message 
)
Value:
if (!(condition)) \
do { \
fprintf (stderr, "Postcondition fail%s%s, assertion: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \
message[0] ? ": " : "", message, #condition, __FUNCTION__, __LINE__ , __FILE__); \
*((int*)0) = 0; \
abort (); \
} while (0)

Checks the verification of a postcondition.

This assertion verification can be disabled at compile time by defining the macro NDEBUG_POSTCONDITIONS.

Parameters
[in]conditionexpression to assert its truthness
[in]messagetext to be presented with error information when the assertion fails

◆ invariant

#define invariant (   condition,
  message 
)
Value:
if (!(condition)) \
do { \
fprintf (stderr, "Invariant fail%s%s, assertion: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \
message[0] ? ": " : "", message, #condition, __FUNCTION__, __LINE__ , __FILE__); \
*((int*)0) = 0; \
abort (); \
} while (0)

Checks the verification of an invariant.

This assertion verification can be disabled at compile time by defining the macro NDEBUG_INVARIANTS.

Parameters
[in]conditionexpression to assert its truthness
[in]messagetext to be presented with error information when the assertion fails