mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-10 17:42:29 +01:00
Add Guard::Assert function with std::source_location default parameter
Part of #12489
This commit is contained in:
@@ -249,6 +249,7 @@ Appreciation for contributors who have provided substantial work, but are no lon
|
||||
* Brendan Heinonen (staticinvocation)
|
||||
* (QuestionableDeer)
|
||||
* David Sungaila (sungaila)
|
||||
* Garrett Leach (GarrettLeach)
|
||||
|
||||
## Toolchain
|
||||
* (Balletie) - macOS
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <format>
|
||||
|
||||
namespace OpenRCT2::Guard
|
||||
{
|
||||
@@ -54,6 +55,15 @@ namespace OpenRCT2::Guard
|
||||
_assertBehaviour = behaviour;
|
||||
}
|
||||
|
||||
void Assert(bool expression, const std::source_location& location)
|
||||
{
|
||||
if (expression)
|
||||
return;
|
||||
|
||||
std::string message = std::format("Assertion failed in {}:{}", location.function_name(), location.line());
|
||||
Assert(expression, message.c_str());
|
||||
}
|
||||
|
||||
void Assert(bool expression, const char* message, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <source_location>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <string>
|
||||
@@ -30,7 +31,8 @@ namespace OpenRCT2::Guard
|
||||
ASSERT_BEHAVIOUR GetAssertBehaviour();
|
||||
void SetAssertBehaviour(ASSERT_BEHAVIOUR behaviour);
|
||||
|
||||
void Assert(bool expression, const char* message = nullptr, ...);
|
||||
void Assert(bool expression, const std::source_location& location = std::source_location::current());
|
||||
void Assert(bool expression, const char* message, ...);
|
||||
void Assert_VA(bool expression, const char* message, va_list args);
|
||||
void Fail(const char* message = nullptr, ...);
|
||||
void Fail_VA(const char* message, va_list args);
|
||||
|
||||
Reference in New Issue
Block a user