IRSOL
C++ code implementing socket server for interacting with Baumer camera.
Assertion

Assertion macros, types, and functions for the irsol library. More...

Files

file  assert.hpp
 Assertion macros and utilities based on the PPK_ASSERT library.
 

Macros

#define IRSOL_ASSERT_DEBUG   PPK_ASSERT_DEBUG
 Debug-level assertion macro.
 
#define IRSOL_ASSERT_ERROR   PPK_ASSERT_ERROR
 Error-level assertion macro.
 
#define IRSOL_ASSERT_FATAL   PPK_ASSERT_FATAL
 Fatal-level assertion macro.
 
#define IRSOL_ASSERT_FALSE(message)   IRSOL_ASSERT_FATAL(false, message)
 Assertion macro that always fails fatally.
 
#define IRSOL_STATIC_ASSERT   PPK_STATIC_ASSERT
 Compile-time static assertion macro.
 

Functions

void irsol::setAssertHandler (AssertHandler handler)
 Sets a custom assertion handler function.
 
void irsol::initAssertHandler ()
 Initializes the assertion handler system.
 
ppk::assert::implementation::AssertAction::AssertAction irsol::internal::assertHandler (const char *file, int line, const char *function, const char *expression, int level, const char *message)
 Internal default assertion handler implementation.
 

Detailed Description

Assertion macros, types, and functions for the irsol library.

Provides compile-time and runtime assertion mechanisms using the PPK_ASSERT library.

Macro Definition Documentation

◆ IRSOL_ASSERT_DEBUG

#define IRSOL_ASSERT_DEBUG   PPK_ASSERT_DEBUG

Debug-level assertion macro.

Prints assertion failure details to the console and allows interactive user action (e.g., ignore, retry, abort). Typically used for non-critical conditions during development.

Usage:

IRSOL_ASSERT_DEBUG(x > 0, "x must be positive");
#define IRSOL_ASSERT_DEBUG
Debug-level assertion macro.
Definition assert.hpp:133

Definition at line 133 of file assert.hpp.

◆ IRSOL_ASSERT_ERROR

#define IRSOL_ASSERT_ERROR   PPK_ASSERT_ERROR

Error-level assertion macro.

Prints assertion failure details to the console and throws an exception of type irsol::AssertionException. Use for recoverable error conditions that should be handled via exception handling.

Usage:

IRSOL_ASSERT_ERROR(ptr != nullptr, "Pointer must not be null");
#define IRSOL_ASSERT_ERROR
Error-level assertion macro.
Definition assert.hpp:134

Definition at line 134 of file assert.hpp.

◆ IRSOL_ASSERT_FALSE

#define IRSOL_ASSERT_FALSE (   message)    IRSOL_ASSERT_FATAL(false, message)

Assertion macro that always fails fatally.

Prints the provided message and terminates the program immediately. Useful for marking code paths that should never be reached.

Usage:

IRSOL_ASSERT_FALSE("Unreachable code executed");
#define IRSOL_ASSERT_FALSE(message)
Assertion macro that always fails fatally.
Definition assert.hpp:136

Definition at line 136 of file assert.hpp.

◆ IRSOL_ASSERT_FATAL

#define IRSOL_ASSERT_FATAL   PPK_ASSERT_FATAL

Fatal-level assertion macro.

Prints assertion failure details to the console and immediately terminates the program. Use for unrecoverable conditions that require aborting execution.

Usage:

IRSOL_ASSERT_FATAL(connected, "Failed to connect to server");
#define IRSOL_ASSERT_FATAL
Fatal-level assertion macro.
Definition assert.hpp:135

Definition at line 135 of file assert.hpp.

◆ IRSOL_STATIC_ASSERT

#define IRSOL_STATIC_ASSERT   PPK_STATIC_ASSERT

Compile-time static assertion macro.

Evaluates the condition at compile time and terminates compilation if the condition is false, printing the provided message.

Usage:

IRSOL_STATIC_ASSERT(sizeof(int) == 4, "int size must be 4 bytes");
#define IRSOL_STATIC_ASSERT
Compile-time static assertion macro.
Definition assert.hpp:138

Definition at line 138 of file assert.hpp.

Function Documentation

◆ assertHandler()

ppk::assert::implementation::AssertAction::AssertAction irsol::internal::assertHandler ( const char *  file,
int  line,
const char *  function,
const char *  expression,
int  level,
const char *  message 
)

Internal default assertion handler implementation.

Handles assertion failures by processing and dispatching them according to the current assertion policy.

This function should not be called directly; it is called by the PPK_ASSERT framework internally.

Parameters
fileThe source file of the assertion failure.
lineThe line number of the failure.
functionThe function containing the assertion.
expressionThe asserted expression.
levelThe assertion severity level.
messageOptional descriptive message.
Returns
The action to take (e.g., ignore, retry, abort).

Definition at line 22 of file assert.cpp.

29{
30 switch(level) {
31 case ppk::assert::implementation::AssertLevel::Debug: {
33 "Assertion failed at {0}:{1} -> '{2}' is false: {3}.", file, line, expression, message);
34 return ppk::assert::implementation::AssertAction::Ignore;
35 }
36
37 case ppk::assert::implementation::AssertLevel::Error: {
39 "Assertion failed at {0}:{1} -> '{2}' is false: {3}.", file, line, expression, message);
40 return ppk::assert::implementation::AssertAction::Throw;
41 }
42 case ppk::assert::implementation::AssertLevel::Fatal: {
44 "Assertion failed at {0}:{1} ({2}) -> '{3}' is false: {4}.",
45 file,
46 line,
47 function,
48 expression,
49 message);
50 return ppk::assert::implementation::AssertAction::Abort;
51 }
52 default: {
53#ifdef DEBUG
55 "Unknown assertion level: {0}, at {1}:{2} -> '{3}' is false: {4}. Aborting program.",
56 level,
57 file,
58 line,
59 expression,
60 message);
61 return ppk::assert::implementation::AssertAction::Throw;
62#else
64 "Unknown assertion level: {0}, at {1}:{2} -> '{3}' is false: {4}. Aborting program.",
65 level,
66 file,
67 line,
68 expression,
69 message);
70 return ppk::assert::implementation::AssertAction::Abort;
71#endif
72 }
73 }
74}
#define IRSOL_LOG_FATAL(...)
Logs a fatal (critical) message using the default logger.
Definition logging.hpp:95
#define IRSOL_LOG_ERROR(...)
Logs an error-level message using the default logger.
Definition logging.hpp:94
#define IRSOL_LOG_WARN(...)
Logs a warning-level message using the default logger.
Definition logging.hpp:93

◆ initAssertHandler()

void irsol::initAssertHandler ( )

Initializes the assertion handler system.

Call this to configure any required internal state before assertions are used. Typically called at program startup.

Sets a custom assertion handler that captures assertions, and based on the build type reacts to them.

See also
setAssertHandler
irsol::internal::AssertHandler

Definition at line 14 of file assert.cpp.

15{
16 IRSOL_LOG_INFO("Initializing irsol assert handler");
17 setAssertHandler(internal::assertHandler);
18}
void setAssertHandler(AssertHandler handler)
Sets a custom assertion handler function.
#define IRSOL_LOG_INFO(...)
Logs an info-level message using the default logger.
Definition logging.hpp:92

◆ setAssertHandler()

void irsol::setAssertHandler ( AssertHandler  handler)

Sets a custom assertion handler function.

This function installs a user-defined callback that is invoked whenever an assertion fails. The handler controls the response behavior.

Parameters
handlerThe user-defined assertion handler to set.