Add conditional assert

This commit is contained in:
Henrik Stickann 2022-04-19 23:16:27 +02:00
parent de4f610843
commit e8cbdf261c

View File

@ -72,6 +72,21 @@ namespace sta
* @param msg Message shown on failure
*/
# define STA_ASSERT_MSG(expr, msg) ((void)(!(expr) && (sta::assert_failed(msg, __FILE__, __LINE__), 1) && (STA_HALT(), 1)))
/**
* @brief Assert expression if condition is true.
*
* @param cond Condition
* @param expr Expression
*/
# define STA_ASSERT_COND(cond, expr) ((void)((cond) ? STA_ASSERT(expr) : 1))
/**
* @brief Assert expression if condition is true.
*
* @param cond Condition
* @param expr Expression
* @param msg Message shown on failure
*/
# define STA_ASSERT_COND_MSG(cond, expr, msg) ((void)((cond) ? STA_ASSERT_MSG(expr, msg)))
#else // !STA_ASSERT_ENABLE
@ -88,6 +103,21 @@ namespace sta
* @param msg Message shown on failure
*/
# define STA_ASSERT_MSG(expr, msg) ((void)0)
/**
* @brief Assert expression if condition is true.
*
* @param cond Condition
* @param expr Expression
*/
# define STA_ASSERT_COND(cond, expr) ((void)0)
/**
* @brief Assert expression if condition is true.
*
* @param cond Condition
* @param expr Expression
* @param msg Message shown on failure
*/
# define STA_ASSERT_COND_MSG(cond, expr, msg) ((void)0)
#endif // !STA_ASSERT_ENABLE