From c5ff634cd1262613bc5df4884098c026b8f99e34 Mon Sep 17 00:00:00 2001 From: parax0 Date: Sun, 10 Apr 2016 14:59:34 -0600 Subject: [PATCH] Implemented assert macros --- src/Common/Assert.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Common/Assert.h diff --git a/src/Common/Assert.h b/src/Common/Assert.h new file mode 100644 index 00000000..f0ff7c5e --- /dev/null +++ b/src/Common/Assert.h @@ -0,0 +1,38 @@ +#ifndef ASSERT_H +#define ASSERT_H + +#include "TString.h" +#include +#include + +#define __FILE_SHORT__ strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__ + +#define ASSERT_CHECK_BEGIN(Expression) \ + { \ + if (!(Expression)) \ + { + +#define ASSERT_CHECK_END \ + } \ + } + +#define WRITE_FAILURE_TO_LOG(Expression) \ + Log::Write(TString(__FILE_SHORT__) + "(" + TString::FromInt32(__LINE__, 0, 10) + "): ASSERT FAILED: " + #Expression); + +#define BREAK_ONLY_ASSERT(Expression) \ + ASSERT_CHECK_BEGIN(Expression) \ + __debugbreak(); \ + ASSERT_CHECK_END + +#define LOG_ONLY_ASSERT(Expression) \ + ASSERT_CHECK_BEGIN(Expression) \ + WRITE_FAILURE_TO_LOG(Expression) \ + ASSERT_CHECK_END + +#define ASSERT(Expression) \ + ASSERT_CHECK_BEGIN(Expression) \ + WRITE_FAILURE_TO_LOG(Expression) \ + __debugbreak(); \ + ASSERT_CHECK_END + +#endif // ASSERT_H