opensurgsim
Modules | Files | Classes | Macros
Assertions

The assertion API used by OpenSurgSim code. More...

Modules

 Internal assertion helpers
 Not meant for public consumption.
 

Files

file  Assert.h
 The header that provides the assertion API.
 

Classes

class  SurgSim::Framework::AssertionFailure
 An exception class thrown by SURGSIM_ASSERT() failures and SURGSIM_FAILURE(). More...
 

Macros

#define SURGSIM_ASSERT(condition)
 Assert that condition is true. More...
 
#define SURGSIM_FAILURE()
 Report that something very bad has happened and abort program execution. More...
 

Detailed Description

The assertion API used by OpenSurgSim code.

See also
Logging API

Macro Definition Documentation

§ SURGSIM_ASSERT

#define SURGSIM_ASSERT (   condition)
Value:
if ((condition)) \
{ \
} \
else \
/* important: no curly braces around this! */ \
::SurgSim::Framework::AssertMessage(SURGSIM_ASSERT_LOGGER) << "*** Assertion failed: " << \
SURGSIM_MAKE_STRING(condition) << " ***" << std::endl << \
" in " << SURGSIM_CURRENT_FUNCTION << std::endl << \
" at " << __FILE__ << ":" << __LINE__ << std::endl
#define SURGSIM_ASSERT_LOGGER
Logger used to log asserts.
Definition: Assert.h:45
#define SURGSIM_CURRENT_FUNCTION
Helper macro to determine the function name currently being compiled.
Definition: Assert.h:61

Assert that condition is true.

If not, abort program execution, printing an error message that will include failText, the condition, source file/line, etc.

Parameters
conditionCondition to test
Returns
Stream to output extra assert information

Example: SURGSIM_ASSERT(index >= 0) << "bad index: " << index;

§ SURGSIM_FAILURE

#define SURGSIM_FAILURE ( )
Value:
::SurgSim::Framework::AssertMessage(SURGSIM_ASSERT_LOGGER) << "*** Failure ***" << std::endl << \
" in " << SURGSIM_CURRENT_FUNCTION << std::endl << \
" at " << __FILE__ << ":" << __LINE__ << std::endl
#define SURGSIM_ASSERT_LOGGER
Logger used to log asserts.
Definition: Assert.h:45
#define SURGSIM_CURRENT_FUNCTION
Helper macro to determine the function name currently being compiled.
Definition: Assert.h:61
An internal message class used for assertion failures.
Definition: AssertMessage.h:45

Report that something very bad has happened and abort program execution.

An error message will be printed, and will include failText, source file/line, etc. This is pretty similar to SURGSIM_ASSERT(true, ...), except "true" won't be included in the resulting message. =)

Returns
Stream to output extra failure information

Example: SURGSIM_FAILURE() << failText;