From a430b3e203f06a17b03e93224c800556ce5f9f76 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 24 May 2026 03:06:03 -0400 Subject: [PATCH] Add Q_ASSERT_RETURN and friends --- include/core/assert_return.h | 26 ++++++++++++++++++++++++++ porymap.pro | 1 + 2 files changed, 27 insertions(+) create mode 100644 include/core/assert_return.h diff --git a/include/core/assert_return.h b/include/core/assert_return.h new file mode 100644 index 00000000..5a099dcd --- /dev/null +++ b/include/core/assert_return.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +// A series of wrappers around Qt assert macros, +// with the addition that each will return if the test fails. +// This makes it easy to raise asserts in situations where you +// may want to do an early return even if debug is disabled. + +#define Q_ASSERT_RETURN(test, ...) \ +do { \ + Q_ASSERT(test); \ + if (!test) return __VA_ARGS__; \ +} while (false); + +#define Q_ASSERT_RETURN_X(test, where, what, ...) \ +do { \ + Q_ASSERT_X(test, where, what); \ + if (!test) return __VA_ARGS__; \ +} while (false); + +#define Q_CHECK_PTR_RETURN(pointer, ...) \ +do { \ + Q_CHECK_PTR(pointer); \ + if (pointer == nullptr) return __VA_ARGS__; \ +} while (false); diff --git a/porymap.pro b/porymap.pro index 6c0920d0..d2463f5d 100644 --- a/porymap.pro +++ b/porymap.pro @@ -179,6 +179,7 @@ HEADERS += include/config/keyvalueconfigbase.h \ include/config/projectconfig.h \ include/config/shortcutsconfig.h \ include/config/userconfig.h \ + include/core/assert_return.h \ include/core/advancemapparser.h \ include/core/block.h \ include/core/bitpacker.h \