1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-29 17:54:50 +01:00

Merge pull request #24032 from garrettleach/assert-with-source_location

Add Guard::Assert function with std::source_location default parameter
This commit is contained in:
Michał Janiszewski
2025-03-24 08:55:52 +01:00
committed by GitHub
3 changed files with 18 additions and 1 deletions

View File

@@ -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

View File

@@ -23,6 +23,7 @@
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <sstream>
namespace OpenRCT2::Guard
{
@@ -54,6 +55,19 @@ namespace OpenRCT2::Guard
_assertBehaviour = behaviour;
}
void Assert(bool expression, const std::source_location& location)
{
if (expression)
return;
std::stringstream messageStream;
messageStream << "Assertion failed in " << location.file_name() << ":" << location.line();
std::string message = messageStream.str();
Assert(expression, message.c_str());
}
void Assert(bool expression, const char* message, ...)
{
va_list args;

View File

@@ -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);