Shared/Asserts.h file

Assertions and event tracing.

Enums

enum class TraceLevel { Unknown, Debug, Info, Warning, Error, Assert, Fatal }
Trace level.

Functions

void DEATH_TRACE(TraceLevel level, const char* fmt, ...)
Callback function for writing to the event log.

Defines

#define LOGD(fmt, ...)
Print a formatted message with TraceLevel::Debug to the event log.
#define LOGI(fmt, ...)
Print a formatted message with TraceLevel::Info to the event log.
#define LOGW(fmt, ...)
Print a formatted message with TraceLevel::Warning to the event log.
#define LOGE(fmt, ...)
Print a formatted message with TraceLevel::Error to the event log.
#define LOGF(fmt, ...)
Print a formatted message with TraceLevel::Fatal to the event log.
#define DEATH_ASSERT_BREAK()
Break the execution if DEATH_DEBUG is defined.
#define DEATH_ASSERT(condition, message, returnValue)
Assertion macro.
#define DEATH_DEBUG_ASSERT(condition, ...)
Debug-only assertion macro.
#define DEATH_CONSTEXPR_ASSERT(condition, message)
Constexpr assertion macro.
#define DEATH_DEBUG_CONSTEXPR_ASSERT(condition, message)
Debug-only constexpr assertion macro.
#define DEATH_ASSERT_UNREACHABLE()
Assert that the code is unreachable.

Enum documentation

enum class TraceLevel

Trace level.

Enumerators
Unknown

Unspecified

Debug

Debug

Info

Info

Warning

Warning

Error

Error

Assert

Assert

Fatal

Fatal

Function documentation

void DEATH_TRACE(TraceLevel level, const char* fmt, ...)

Callback function for writing to the event log.

This function needs to be provided by the target application to enable the event tracing. Alternatively, ITraceSink interface can be used instead.

Define documentation

#define DEATH_ASSERT(condition, message, returnValue)

Assertion macro.

Usable for sanity checks on user input, as it prints explanational message on error.

By default, if assertion fails, message is printed with TraceLevel::Assert to the event log, the function returns with returnValue instead and the execution is break (if DEATH_DEBUG is defined). If DEATH_STANDARD_ASSERT is defined, this macro expands to assert(condition), ignoring message. If DEATH_NO_ASSERT is defined (or if both DEATH_TRACE and DEATH_STANDARD_ASSERT are not defined), this macro expands to do{}while(false).

You can override this implementation by placing your own #define DEATH_ASSERT before including the Asserts.h header.

#define DEATH_DEBUG_ASSERT(condition, ...)

Debug-only assertion macro.

Unlike DEATH_ASSERT() this macro expands to do{}while(false) if DEATH_DEBUG is not defined (i.e., in release configuration).

You can override this implementation by placing your own #define DEATH_DEBUG_ASSERT before including the Asserts.h header.

#define DEATH_CONSTEXPR_ASSERT(condition, message)

Constexpr assertion macro.

Unlike DEATH_ASSERT() this macro can be used in C++11 constexpr functions. In a constexpr context, if assertion fails, the code fails to compile. In a non- constexpr context, if assertion fails, message is printed with TraceLevel::Assert to the event log and the execution is break. If DEATH_STANDARD_ASSERT is defined, message is ignored and the standard assert() is called if condition fails. If DEATH_NO_ASSERT is defined (or if both DEATH_TRACE and DEATH_STANDARD_ASSERT are not defined), this macro expands to static_cast<void>(0).

You can override this implementation by placing your own #define DEATH_CONSTEXPR_ASSERT before including the Asserts.h header.

#define DEATH_DEBUG_CONSTEXPR_ASSERT(condition, message)

Debug-only constexpr assertion macro.

Unlike DEATH_CONSTEXPR_ASSERT() this macro expands to static_cast<void>(0) if DEATH_DEBUG is not defined (i.e., in release configuration).

You can override this implementation by placing your own #define DEATH_DEBUG_CONSTEXPR_ASSERT before including the Asserts.h header.

#define DEATH_ASSERT_UNREACHABLE()

Assert that the code is unreachable.

By default, if code marked with this macro is reached, a hint message is printed with TraceLevel::Assert to the event log. and the execution is break (if DEATH_DEBUG is defined). If DEATH_STANDARD_ASSERT is defined, the standard assert(!"Unreachable code") is called. If DEATH_NO_ASSERT is defined (or if both DEATH_TRACE and DEATH_STANDARD_ASSERT are not defined), this macro hints to the compiler that given code is not reachable, possibly helping the optimizer (using a compiler builtin on GCC, Clang and MSVC; calling std::abort() otherwise).

You can override this implementation by placing your own #define DEATH_ASSERT_UNREACHABLE before including the Asserts.h header.