Implemented assert macros

This commit is contained in:
parax0 2016-04-10 14:59:34 -06:00
parent 61afbabfa4
commit c5ff634cd1
1 changed files with 38 additions and 0 deletions

38
src/Common/Assert.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef ASSERT_H
#define ASSERT_H
#include "TString.h"
#include <cstdlib>
#include <string.h>
#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