Fix Assert functions

This commit is contained in:
2023-10-03 15:06:29 +02:00
parent 0b8b5f88a6
commit 6112e36c22
2 changed files with 50 additions and 8 deletions

View File

@@ -23,7 +23,7 @@
/** @def DEBUG(msg)
* @brief Writes a debug message
*
* This function writes a debug message that includes the filename,
* This macro writes a debug message that includes the filename,
* line number, and a custom message. The function is wrapped in an ifdef
* that checks if DBG is defined, so one can choose to display the debug
* messages by adding the -DDBG flag when compiling.
@@ -35,7 +35,14 @@
#define DEBUG(msg)
#endif
#define ASSERT(expr) m_assert(expr, #expr, __FUNCTION__, __FILE__, __LINE__)
/** @def ASSERT(expr)
* @brief A prettier assertion function.
*
* This macro calls the m_assert function which is a more informative
* assertion function than the regular assert function from cassert.
* */
#define ASSERT(expr, msg) m_assert(expr, #expr, __FUNCTION__, __FILE__, \
__LINE__, msg)
/** Code stolen from https://github.com/anderkve/FYS3150
* Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp
@@ -64,6 +71,23 @@ std::string scientific_format(const std::vector<double>& v,
int width=20,
int prec=10);
void m_assert(bool expr, const char* expr_str, const char* func, const char* file, int line);
/** @brief Test an expression, confirm that test is ok, or abort execution.
*
* This function takes in an expression and prints an OK message if it's
* true, or it prints a fail message and aborts execution if it fails.
*
* @param expr The expression to be evaluated
* @param expr_str The stringified version of the expression
* @param func The function name of the caller
* @param file The file of the caller
* @param line The line number where this function is called from
* @param msg The message to be displayed
* */
void m_assert(bool expr,
const char* expr_str,
const char* func,
const char* file,
int line,
const char* msg);
#endif