Chemical Data Processing Library C++ API - Version 1.4.0
Macros
Check.hpp File Reference

Definition of various preprocessor macros for error checking. More...

#include <algorithm>

Go to the source code of this file.

Macros

#define CDPL_MATH_CHECK(expr, msg, e)
 Throws the exception e with message msg when the boolean expression expr evaluates to false. More...
 
#define CDPL_MATH_CHECK_SIZE_EQUALITY(size1, size2, e)   checkSizeEquality<e>(size1, size2)
 Throws the exception e if size1 differs from size2, otherwise returns std::min(size1, size2). More...
 
#define CDPL_MATH_CHECK_MAX_SIZE(size, max_size, e)   checkMaxSize<e>(size, max_size)
 Throws the exception e if size exceeds max_size, otherwise returns std::min(size, max_size). More...
 

Detailed Description

Definition of various preprocessor macros for error checking.

Macro Definition Documentation

◆ CDPL_MATH_CHECK

#define CDPL_MATH_CHECK (   expr,
  msg,
 
)
Value:
if (!(expr)) { \
throw e(msg); \
}

Throws the exception e with message msg when the boolean expression expr evaluates to false.

Expands to an empty statement when the macro CDPL_MATH_CHECKS_DISABLE is defined at compile time, allowing release builds to elide the check.

Parameters
exprThe boolean condition that must hold.
msgThe C-string error message passed to the exception constructor.
eThe exception type to throw when expr is false.

◆ CDPL_MATH_CHECK_SIZE_EQUALITY

#define CDPL_MATH_CHECK_SIZE_EQUALITY (   size1,
  size2,
 
)    checkSizeEquality<e>(size1, size2)

Throws the exception e if size1 differs from size2, otherwise returns std::min(size1, size2).

Intended for size compatibility checks (e.g. matching vector dimensions in arithmetic expressions). Subject to compile-time elision via CDPL_MATH_CHECKS_DISABLE (see CDPL_MATH_CHECK).

Parameters
size1The first size value.
size2The second size value.
eThe exception type to throw on size mismatch.

◆ CDPL_MATH_CHECK_MAX_SIZE

#define CDPL_MATH_CHECK_MAX_SIZE (   size,
  max_size,
 
)    checkMaxSize<e>(size, max_size)

Throws the exception e if size exceeds max_size, otherwise returns std::min(size, max_size).

Intended for upper-bound size checks. Subject to compile-time elision via CDPL_MATH_CHECKS_DISABLE.

Parameters
sizeThe size value to test.
max_sizeThe upper bound the size must respect.
eThe exception type to throw on overflow.