mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-17 21:12:34 +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)
|
* Brendan Heinonen (staticinvocation)
|
||||||
* (QuestionableDeer)
|
* (QuestionableDeer)
|
||||||
* David Sungaila (sungaila)
|
* David Sungaila (sungaila)
|
||||||
|
* Garrett Leach (GarrettLeach)
|
||||||
|
|
||||||
## Toolchain
|
## Toolchain
|
||||||
* (Balletie) - macOS
|
* (Balletie) - macOS
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
namespace OpenRCT2::Guard
|
namespace OpenRCT2::Guard
|
||||||
{
|
{
|
||||||
@@ -54,6 +55,15 @@ namespace OpenRCT2::Guard
|
|||||||
_assertBehaviour = behaviour;
|
_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, ...)
|
void Assert(bool expression, const char* message, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <source_location>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -30,7 +31,8 @@ namespace OpenRCT2::Guard
|
|||||||
ASSERT_BEHAVIOUR GetAssertBehaviour();
|
ASSERT_BEHAVIOUR GetAssertBehaviour();
|
||||||
void SetAssertBehaviour(ASSERT_BEHAVIOUR behaviour);
|
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 Assert_VA(bool expression, const char* message, va_list args);
|
||||||
void Fail(const char* message = nullptr, ...);
|
void Fail(const char* message = nullptr, ...);
|
||||||
void Fail_VA(const char* message, va_list args);
|
void Fail_VA(const char* message, va_list args);
|
||||||
|
|||||||
Reference in New Issue
Block a user