ImFusion SDK 4.3
Assertion Library

Assertion library. More...

+ Collaboration diagram for Assertion Library:

Detailed Description

Assertion library.

More powerful and flexible alternative to the basic assert() of the C standard library. The assertion macro takes a condition to check and an optional message to display on failure.

IMFUSION_ASSERT(value > 0); // will trap if value is less or equal 0
IMFUSION_ASSERT(value > 0, "Need at least one item"); // will additionally print the message on failure
#define IMFUSION_ASSERT(...)
ImFusion assertion macro, supports two overloads:
Definition Assert.h:102

Assertions are only checked if IMFUSION_ENABLE_ASSERTIONS is defined.

As a library developer you can register a custom HanderFunction that should be called in case an assertion fails. The default 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.

Macros

#define IMFUSION_ASSERT(...)
 ImFusion assertion macro, supports two overloads:
 

Typedefs

using HandlerFunction
 Alias for a function pointer that can be used to handle trapped assertions.
 

Functions

IMFUSION_CORE_API HandlerFunction handler ()
 Returns the currently set assertion handler function.
 
IMFUSION_CORE_API void setHandler (HandlerFunction handler)
 Sets the assertion handler function to use.
 
IMFUSION_CORE_API void 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.
 

Macro Definition Documentation

◆ IMFUSION_ASSERT

#define IMFUSION_ASSERT ( ...)

#include <ImFusion/Core/Assert.h>

Value:
IMFUSION_ASSERT_EXPAND(IMFUSION_ASSERT_GET_MACRO(__VA_ARGS__, IMFUSION_ASSERT_2, IMFUSION_ASSERT_1)(__VA_ARGS__))

ImFusion assertion macro, supports two overloads:

IMFUSION_ASSERT(value > 0); // will trap if value is less or equal 0
IMFUSION_ASSERT(value > 0, "Need at least one item"); // will additionally print the message on failure

Assertions are only checked if IMFUSION_ENABLE_ASSERTIONS is defined.

Note
You can use the alternative assertion macro IMFUSION_ASSERT_NOFUNCNAME() which 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.
Examples
Filesystem.cpp.

Typedef Documentation

◆ HandlerFunction

#include <ImFusion/Core/Assert.h>

Initial value:
void (*)(const char* condition, const char* message, const char* fileName, const char* functionName, int line)

Alias for a function pointer that can be used to handle trapped assertions.

Parameters
conditionVerbatim code of the assertion condition that trapped.
messageMessage that was attached to the assertion.
fileNameFilename in which the assertion trapped.
functionNameFunction name where the assertion trapped.
lineLine number in fileName where the assertion trapped.

Function Documentation

◆ handler()

IMFUSION_CORE_API HandlerFunction handler ( )

#include <ImFusion/Core/Assert.h>

Returns the currently set assertion handler function.

Note
This function returns global state.

◆ setHandler()

IMFUSION_CORE_API void setHandler ( HandlerFunction handler)

#include <ImFusion/Core/Assert.h>

Sets the assertion handler function to use.

Note
This function modifies global state.

◆ defaultHandler()

IMFUSION_CORE_API void defaultHandler ( 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 assertions.

Will offer the user the choice of ignoring once, ignoring always, debug trap, or quitting the application.

Search Tab / S to search, Esc to close