4.3.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
Classes | Macros | Functions
fcppt.assert

Description

Macros and functions for assertions.

Classes

class  fcppt::assert_::information
 Represents information gathered at the assertion side. More...
 

Macros

#define FCPPT_ASSERT_BASIC_CONDITIONAL(condition, action)
 Asserts that a condition is true. More...
 
#define FCPPT_ASSERT_BASIC_CONDITIONAL_MESSAGE(condition, message, action)
 Asserts that a condition is true, with an extra message on failure. More...
 
#define FCPPT_ASSERT_BASIC_DEFAULT_MESSAGE   FCPPT_TEXT("")
 The default assert message. More...
 
#define FCPPT_ASSERT_BASIC_GATHER_INFORMATION(condition_arg, message_arg)
 Gathers fcppt::assert_::information at the current file and function. More...
 
#define FCPPT_ASSERT_BASIC_MESSAGE_AND_ACTION(macro, message, reason, action)    macro((FCPPT_ASSERT_BASIC_PRINT_MESSAGE(reason, message), action))
 Executes a macro with an action and printing of a message. More...
 
#define FCPPT_ASSERT_BASIC_PRINT_MESSAGE(condition_arg, message_arg)
 Prints an assert message to cerr, containing fcppt::assert_::information. More...
 
#define FCPPT_ASSERT_BASIC_TERMINATE_CONDITIONAL(condition)    FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE_CONDITIONAL(condition, FCPPT_ASSERT_BASIC_DEFAULT_MESSAGE)
 Calls terminate on a failed assertion. More...
 
#define FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE(reason, message)    FCPPT_ASSERT_BASIC_UNCONDITIONAL_MESSAGE(reason, message, std::terminate())
 Prints a message and terminates the program. More...
 
#define FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE_CONDITIONAL(condition, message)    FCPPT_ASSERT_BASIC_CONDITIONAL_MESSAGE(condition, message, std::terminate())
 Calls terminate on a failed assertion, with an extra message on failure. More...
 
#define FCPPT_ASSERT_BASIC_UNCONDITIONAL(action)   action
 Takes an unconditional action. More...
 
#define FCPPT_ASSERT_BASIC_UNCONDITIONAL_MESSAGE(reason, message, action)    FCPPT_ASSERT_BASIC_MESSAGE_AND_ACTION(FCPPT_ASSERT_BASIC_UNCONDITIONAL, message, reason, action)
 Takes an unconditional action, also printing a message. More...
 
#define FCPPT_ASSERT_ERROR(condition)   FCPPT_ASSERT_BASIC_TERMINATE_CONDITIONAL(condition)
 Asserts a condition in the middle of a function. More...
 
#define FCPPT_ASSERT_ERROR_MESSAGE(condition, message)    FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE_CONDITIONAL(condition, message)
 Asserts a condition in the middle of a function, with an extra message on failure. More...
 
#define FCPPT_ASSERT_UNREACHABLE    FCPPT_ASSERT_UNREACHABLE_MESSAGE(FCPPT_ASSERT_BASIC_DEFAULT_MESSAGE)
 Terminates the program. More...
 
#define FCPPT_ASSERT_UNREACHABLE_MESSAGE(message)    FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE(unreachable code, message)
 Terminates the program, also printing a message. More...
 

Functions

fcppt::string fcppt::assert_::make_message (fcppt::assert_::information const &_info)
 Generates a message string from assert information. More...
 

Macro Definition Documentation

◆ FCPPT_ASSERT_BASIC_CONDITIONAL

#define FCPPT_ASSERT_BASIC_CONDITIONAL (   condition,
  action 
)
Value:
if (!(condition)) \
FCPPT_ASSERT_BASIC_UNCONDITIONAL(action)

Asserts that a condition is true.

Asserts that condition is true, taking action if it is not.

Parameters
conditionThe condition to check for
actionThe action to take on failure

◆ FCPPT_ASSERT_BASIC_CONDITIONAL_MESSAGE

#define FCPPT_ASSERT_BASIC_CONDITIONAL_MESSAGE (   condition,
  message,
  action 
)
Value:
if (!(condition)) \
FCPPT_ASSERT_BASIC_UNCONDITIONAL_MESSAGE(condition, message, action)

Asserts that a condition is true, with an extra message on failure.

Asserts that condition is true, taking action if it is not and also printing message.

Parameters
conditionThe condition to check for
messageThe message to print on failure
actionThe action to take on failure

◆ FCPPT_ASSERT_BASIC_DEFAULT_MESSAGE

#define FCPPT_ASSERT_BASIC_DEFAULT_MESSAGE   FCPPT_TEXT("")

The default assert message.

The default assert message, which is empty.

◆ FCPPT_ASSERT_BASIC_GATHER_INFORMATION

#define FCPPT_ASSERT_BASIC_GATHER_INFORMATION (   condition_arg,
  message_arg 
)
Value:

Gathers fcppt::assert_::information at the current file and function.

This macro expands to an fcppt::assert_::information, which gathers the current source file, the line of the file, the function name, the failed condition obtained from condition_arg, and the message obtained from message_arg.

Parameters
condition_argThe condition of the assertion
message_argThe message of the assertion

◆ FCPPT_ASSERT_BASIC_MESSAGE_AND_ACTION

#define FCPPT_ASSERT_BASIC_MESSAGE_AND_ACTION (   macro,
  message,
  reason,
  action 
)     macro((FCPPT_ASSERT_BASIC_PRINT_MESSAGE(reason, message), action))

Executes a macro with an action and printing of a message.

Executes macro, passing it an action that consists of printing a message with reason and message and executing action afterwards.

Parameters
macroThe macro to invoke with the new action
messageThe message to print
reasonThe reason for the assertion
actionThe action to execute after printing the message

◆ FCPPT_ASSERT_BASIC_PRINT_MESSAGE

#define FCPPT_ASSERT_BASIC_PRINT_MESSAGE (   condition_arg,
  message_arg 
)
Value:

Prints an assert message to cerr, containing fcppt::assert_::information.

Prints an assert message to cerr, consisting of information gathered at the current code position, like file, line and function name, and also the failed condition condition_arg and message_arg.

◆ FCPPT_ASSERT_BASIC_TERMINATE_CONDITIONAL

#define FCPPT_ASSERT_BASIC_TERMINATE_CONDITIONAL (   condition)     FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE_CONDITIONAL(condition, FCPPT_ASSERT_BASIC_DEFAULT_MESSAGE)

Calls terminate on a failed assertion.

Calls terminate if condition is false.

Parameters
conditionThe condition to check for

◆ FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE

#define FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE (   reason,
  message 
)     FCPPT_ASSERT_BASIC_UNCONDITIONAL_MESSAGE(reason, message, std::terminate())

Prints a message and terminates the program.

Prints message and reason, and then calls std::terminate.

Parameters
reasonThe reason for the assertion to fail
messageThe message to print

◆ FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE_CONDITIONAL

#define FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE_CONDITIONAL (   condition,
  message 
)     FCPPT_ASSERT_BASIC_CONDITIONAL_MESSAGE(condition, message, std::terminate())

Calls terminate on a failed assertion, with an extra message on failure.

Calls terminate if condition is false and also prints message.

Parameters
conditionThe condition to check for
messageThe message to print on failure

◆ FCPPT_ASSERT_BASIC_UNCONDITIONAL

#define FCPPT_ASSERT_BASIC_UNCONDITIONAL (   action)    action

Takes an unconditional action.

Takes the unconditional action action.

Parameters
actionThe action to take

◆ FCPPT_ASSERT_BASIC_UNCONDITIONAL_MESSAGE

#define FCPPT_ASSERT_BASIC_UNCONDITIONAL_MESSAGE (   reason,
  message,
  action 
)     FCPPT_ASSERT_BASIC_MESSAGE_AND_ACTION(FCPPT_ASSERT_BASIC_UNCONDITIONAL, message, reason, action)

Takes an unconditional action, also printing a message.

Takes the unconditional action action, also printing a message with reason and message.

Parameters
reasonThe reason for the assertion to fail
messageThe message to print
actionThe action to take

◆ FCPPT_ASSERT_ERROR

#define FCPPT_ASSERT_ERROR (   condition)    FCPPT_ASSERT_BASIC_TERMINATE_CONDITIONAL(condition)

Asserts a condition in the middle of a function.

Asserts that condition is true, calling std::terminate if it is not. This macro should be used if an error occurs in the middle of a function that should not happen.

Parameters
conditionThe condition to check for

◆ FCPPT_ASSERT_ERROR_MESSAGE

#define FCPPT_ASSERT_ERROR_MESSAGE (   condition,
  message 
)     FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE_CONDITIONAL(condition, message)

Asserts a condition in the middle of a function, with an extra message on failure.

Asserts that condition is true, calling std::terminate if it is not and also printing message. This macro should be used if an error occurs in the middle of a function that should not happen.

Parameters
conditionThe condition to check for
messageThe message to print on failure

◆ FCPPT_ASSERT_UNREACHABLE

Terminates the program.

This macro should be used when an unreachable code part is executed.

◆ FCPPT_ASSERT_UNREACHABLE_MESSAGE

#define FCPPT_ASSERT_UNREACHABLE_MESSAGE (   message)     FCPPT_ASSERT_BASIC_TERMINATE_MESSAGE(unreachable code, message)

Terminates the program, also printing a message.

Prints message and terminates the program. This macro should be used when an unreachable code part is executed.

Parameters
messageThe message to print

Function Documentation

◆ make_message()

fcppt::string fcppt::assert_::make_message ( fcppt::assert_::information const &  _info)
inline

Generates a message string from assert information.

Generates a message string from the assert information contained in _info.

Parameters
_infoThe assert information
Returns
The formatted message