![]() |
ImFusion C++ SDK 4.5.0
|
Assertion library. More...
Assertion library.
The Assertion Library provides more powerful and flexible alternative to the basic assert() of the C standard library. An assertion is a boolean predicate placed in code that should always evaluate to true when executed. This enables the programmer to encode assumptions in code, improve code readability, and enable the program to detect defects early.
We distinguish between two types of assertions that are syntactically very similar but have different semantic meanings and behave differently:
Debug assertions implement optional run-time checks to ensure that programmer assumptions are met. The program execution may continue also in case of failure and their execution may even be disabled globally.
The debug assertion macro takes a condition to check and an optional message to display on failure.
Assertions are only checked if IMFUSION_ENABLE_DEBUG_ASSERTIONS is defined for the preprocessor. By default, they are disabled for production release builds.
As a library developer you can register a custom debug assertion handler that should be called in case a debug assertion fails. The default debug assertion handler function will print an error message to std::cout and offer the user the choice of ignoring once, ignoring always, debug trap, or quitting the application.
Contract Assertions are non-optional run-time checks to implement design-by-contract. They will always be executed and regular program execution will abort in case of failure. They are primarily intended to enforce correctness guarantees.
The contract assertion macro takes a condition to check and an optional message to display on failure. They are supposed to used to check documented preconditions or invariants that are to be ensured by the programmer.
As a library developer you can register a custom contract assertion handler that should be called in case a contract assertion fails. The default contract assertion handler function will throw a ContractViolation exception.
Namespaces | |
| namespace | ImFusion::Assert |
| Assertion library. | |
Classes | |
| class | ImFusion::Assert::ContractViolation |
| Represents a violation of a contract assertion. More... | |
Macros | |
| #define | IMFUSION_DEBUG_ASSERT(...) |
| ImFusion debug assertion macro, supports two overloads: | |
| #define | IMFUSION_DEBUG_ASSERT_NOFUNCNAME(...) |
| Variant of IMFUSION_DEBUG_ASSERT() that will forward an empty string as functionName to the registered HandlerFunction. | |
| #define | IMFUSION_CONTRACT_ASSERT(...) |
| ImFusion contract assertion macro, supports two overloads: | |
| #define | IMFUSION_CONTRACT_ASSERT_NOFUNCNAME(...) |
| Variant of IMFUSION_CONTRACT_ASSERT() that will forward an empty string as functionName to the registered HandlerFunction. | |
Typedefs | |
| using | ImFusion::Assert::HandlerFunction |
| Alias for a function pointer that can be used to handle trapped assertions. | |
Functions | |
| HandlerFunction | ImFusion::Assert::debugAssertionHandler () |
| Returns the currently assigned handler function for debug asserts. | |
| void | ImFusion::Assert::setDebugAssertionHandler (HandlerFunction handler) |
| Sets the debug assertion handler function to use. | |
| void | ImFusion::Assert::defaultDebugAssertionHandler (const char *condition, const char *message, const char *fileName, const char *functionName, int line) |
| Handler function that is used by default to handle trapped debug assertions. | |
| HandlerFunction | ImFusion::Assert::handler () |
| void | ImFusion::Assert::setHandler (HandlerFunction handler) |
| Sets the assertion handler function to use. | |
| void | ImFusion::Assert::defaultHandler (const char *condition, const char *message, const char *fileName, const char *functionName, int line) |
| Handler function that is used by default to handle trapped assertions. | |
| HandlerFunction | ImFusion::Assert::contractAssertionHandler () |
| Returns the currently assigned handler function for contract asserts. | |
| void | ImFusion::Assert::setContractAssertionHandler (HandlerFunction handler) |
| Sets the contract assertion handler function to use. | |
| void | ImFusion::Assert::defaultContractAssertionHandler (const char *condition, const char *message, const char *fileName, const char *functionName, int line) |
| Handler function that is used by default to handle trapped contract assertions. | |
| #define IMFUSION_DEBUG_ASSERT | ( | ... | ) |
#include <ImFusion/Core/Assert.h>
ImFusion debug assertion macro, supports two overloads:
Debug assertions are only checked if IMFUSION_ENABLE_ASSERTIONS is defined.
| #define IMFUSION_DEBUG_ASSERT_NOFUNCNAME | ( | ... | ) |
#include <ImFusion/Core/Assert.h>
Variant of IMFUSION_DEBUG_ASSERT() that will forward an empty string as functionName to the registered HandlerFunction.
This can help reducing binary bloat in templated header-only code where there are many different instantiations of the same template.
| #define IMFUSION_CONTRACT_ASSERT | ( | ... | ) |
#include <ImFusion/Core/Assert.h>
ImFusion contract assertion macro, supports two overloads:
Contract assertions will always be evaluated and abort local program execution if failed.
| #define IMFUSION_CONTRACT_ASSERT_NOFUNCNAME | ( | ... | ) |
#include <ImFusion/Core/Assert.h>
Variant of IMFUSION_CONTRACT_ASSERT() that will forward an empty string as functionName to the registered HandlerFunction.
This can help reducing binary bloat in templated header-only code where there are many different instantiations of the same template.
#include <ImFusion/Core/Assert.h>
Alias for a function pointer that can be used to handle trapped assertions.
| condition | Verbatim code of the assertion condition that trapped. |
| message | Message that was attached to the assertion. |
| fileName | Filename in which the assertion trapped. |
| functionName | Function name where the assertion trapped. |
| line | Line number in fileName where the assertion trapped. |
| HandlerFunction ImFusion::Assert::debugAssertionHandler | ( | ) |
#include <ImFusion/Core/Assert.h>
Returns the currently assigned handler function for debug asserts.
| void ImFusion::Assert::setDebugAssertionHandler | ( | HandlerFunction | handler | ) |
#include <ImFusion/Core/Assert.h>
Sets the debug assertion handler function to use.
| void ImFusion::Assert::defaultDebugAssertionHandler | ( | const char * | condition, |
| const char * | message, | ||
| const char * | fileName, | ||
| const char * | functionName, | ||
| int | line ) |
#include <ImFusion/Core/Assert.h>
Handler function that is used by default to handle trapped debug assertions.
Will offer the user the choice of ignoring once, ignoring always, debug trap, or quitting the application.
|
inline |
#include <ImFusion/Core/Assert.h>
|
inline |
#include <ImFusion/Core/Assert.h>
Sets the assertion handler function to use.
|
inline |
#include <ImFusion/Core/Assert.h>
Handler function that is used by default to handle trapped assertions.
Will offer the user the choice of ignoring once, ignoring always, debug trap, or quitting the application.
| HandlerFunction ImFusion::Assert::contractAssertionHandler | ( | ) |
#include <ImFusion/Core/Assert.h>
Returns the currently assigned handler function for contract asserts.
| void ImFusion::Assert::setContractAssertionHandler | ( | HandlerFunction | handler | ) |
#include <ImFusion/Core/Assert.h>
Sets the contract assertion handler function to use.
handler must not be null.
| void ImFusion::Assert::defaultContractAssertionHandler | ( | const char * | condition, |
| const char * | message, | ||
| const char * | fileName, | ||
| const char * | functionName, | ||
| int | line ) |
#include <ImFusion/Core/Assert.h>
Handler function that is used by default to handle trapped contract assertions.
Throws an exception of type ContractViolation.