Provides assertion and panic mechanisms with optional custom formatting.
More...
#include "PixelBullet/Application/Log.hpp"
#include <fmt/format.h>
#include <cstdlib>
#include <filesystem>
Go to the source code of this file.
|
| #define | DEBUG_BREAK() |
| | Platform-specific debug break.
|
| |
| #define | ASSERT(condition, ...) |
| | Asserts that a condition is true.
|
| |
| #define | DEBUG_ASSERT(condition, ...) |
| | Debug-only assertion.
|
| |
| #define | ASSUME(condition, ...) |
| | Assumes that a condition is true.
|
| |
| #define | PANIC(...) |
| | Unconditionally triggers a panic.
|
| |
| #define | UNREACHABLE(...) |
| | Marks code as unreachable.
|
| |
|
| void | PixelBullet::Fail (const char *file, int line, const char *conditionStr) |
| | Fails an assertion without a custom message.
|
| |
| template<typename... Args> |
| void | PixelBullet::Fail (const char *file, int line, const char *conditionStr, fmt::format_string< Args... > msg, Args &&... args) |
| | Fails an assertion with a custom formatted message.
|
| |
| void | PixelBullet::Panic (const char *file, int line) |
| | Triggers a panic without a custom message.
|
| |
| template<typename... Args> |
| void | PixelBullet::Panic (const char *file, int line, fmt::format_string< Args... > msg, Args &&... args) |
| | Triggers a panic with a custom formatted message.
|
| |
| void | PixelBullet::Unreachable (const char *file, int line) |
| | Handles unreachable code without a custom message.
|
| |
| template<typename... Args> |
| void | PixelBullet::Unreachable (const char *file, int line, fmt::format_string< Args... > msg, Args &&... args) |
| | Handles unreachable code with a custom formatted message.
|
| |
Provides assertion and panic mechanisms with optional custom formatting.
◆ ASSERT
| #define ASSERT |
( |
| condition, |
|
|
| ... ) |
Value: do \
{ \
if (!(condition)) \
{ \
PixelBullet::Fail(__FILE__, __LINE__, #condition, ##__VA_ARGS__); \
} \
} while (0)
Asserts that a condition is true.
Always checks the condition; if it fails, logs an error and aborts the program. A custom formatted message may be provided.
- Parameters
-
| condition | The condition to assert. |
| ... | Optional custom formatted message and its arguments. |
◆ ASSUME
| #define ASSUME |
( |
| condition, |
|
|
| ... ) |
Value:
Assumes that a condition is true.
In debug builds, behaves like ASSERT (i.e., checks the condition). In release builds, provides an optimization hint to the compiler.
- Parameters
-
| condition | The condition to assume. |
| ... | Optional custom formatted message and its arguments. |
◆ DEBUG_ASSERT
| #define DEBUG_ASSERT |
( |
| condition, |
|
|
| ... ) |
Value:
Debug-only assertion.
Checks the condition only in debug builds. In release builds, this macro does nothing.
- Parameters
-
| condition | The condition to assert. |
| ... | Optional custom formatted message and its arguments. |
◆ DEBUG_BREAK
Value:
Platform-specific debug break.
◆ PANIC
Value: do \
{ \
PixelBullet::Panic(__FILE__, __LINE__, ##__VA_ARGS__); \
} while (0)
Unconditionally triggers a panic.
Logs an error and aborts the program. A custom formatted message may be provided.
- Parameters
-
| ... | Optional custom formatted message and its arguments. |
◆ UNREACHABLE
| #define UNREACHABLE |
( |
| ... | ) |
|
Value:
Marks code as unreachable.
In debug builds, logs an error (with an optional custom message) and aborts the program. In release builds, uses compiler intrinsics to mark the code as unreachable.
- Parameters
-
| ... | Optional custom formatted message and its arguments. |
◆ Fail() [1/2]
| void PixelBullet::Fail |
( |
const char * | file, |
|
|
int | line, |
|
|
const char * | conditionStr ) |
|
inline |
Fails an assertion without a custom message.
Logs an error message with the condition string, source file, and line number, then triggers a debug break and aborts the program.
- Parameters
-
| file | The source file where the assertion failed. |
| line | The line number where the assertion failed. |
| conditionStr | A string representation of the failed condition. |
◆ Fail() [2/2]
template<typename... Args>
| void PixelBullet::Fail |
( |
const char * | file, |
|
|
int | line, |
|
|
const char * | conditionStr, |
|
|
fmt::format_string< Args... > | msg, |
|
|
Args &&... | args ) |
Fails an assertion with a custom formatted message.
Logs an error using a custom format string and its arguments, then triggers a debug break and aborts the program.
- Template Parameters
-
| Args | Variadic template parameters for formatting. |
- Parameters
-
| file | The source file where the assertion failed. |
| line | The line number where the assertion failed. |
| conditionStr | A string representation of the failed condition. |
| msg | The custom format string. |
| args | The arguments to be formatted into the message. |
◆ Panic() [1/2]
| void PixelBullet::Panic |
( |
const char * | file, |
|
|
int | line ) |
|
inline |
Triggers a panic without a custom message.
Logs a panic message with the source file and line number, then triggers a debug break and aborts the program.
- Parameters
-
| file | The source file where the panic was triggered. |
| line | The line number where the panic was triggered. |
◆ Panic() [2/2]
template<typename... Args>
| void PixelBullet::Panic |
( |
const char * | file, |
|
|
int | line, |
|
|
fmt::format_string< Args... > | msg, |
|
|
Args &&... | args ) |
Triggers a panic with a custom formatted message.
Logs a custom panic message, then triggers a debug break and aborts the program.
- Template Parameters
-
| Args | Variadic template parameters for formatting. |
- Parameters
-
| file | The source file where the panic was triggered. |
| line | The line number where the panic was triggered. |
| msg | The custom format string. |
| args | The arguments to be formatted into the message. |
◆ Unreachable() [1/2]
| void PixelBullet::Unreachable |
( |
const char * | file, |
|
|
int | line ) |
|
inline |
Handles unreachable code without a custom message.
Logs an error indicating that unreachable code was reached, then triggers a debug break and aborts the program.
- Parameters
-
| file | The source file where the unreachable code was executed. |
| line | The line number where the unreachable code was executed. |
◆ Unreachable() [2/2]
template<typename... Args>
| void PixelBullet::Unreachable |
( |
const char * | file, |
|
|
int | line, |
|
|
fmt::format_string< Args... > | msg, |
|
|
Args &&... | args ) |
Handles unreachable code with a custom formatted message.
Logs a custom error message for unreachable code, then triggers a debug break and aborts the program.
- Template Parameters
-
| Args | Variadic template parameters for formatting. |
- Parameters
-
| file | The source file where the unreachable code was executed. |
| line | The line number where the unreachable code was executed. |
| msg | The custom format string. |
| args | The arguments to be formatted into the message. |