diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2021-04-08 16:43:58 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2021-04-08 16:43:58 +0200 |
commit | a3c405074db4c53e9da042a8772135fb9bf6caa2 (patch) | |
tree | 3417be8827d1eed95a415e7ee68dbc4263085405 /EASTL/source/assert.cpp | |
parent | ac1b72946c226eb3cd4f3f0b8f13a8330142ebe8 (diff) | |
parent | e59cf7b09e7388d369e8d2bf73501cde79c28708 (diff) |
Merge commit 'e59cf7b09e7388d369e8d2bf73501cde79c28708' as 'EASTL'
Diffstat (limited to 'EASTL/source/assert.cpp')
-rw-r--r-- | EASTL/source/assert.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/EASTL/source/assert.cpp b/EASTL/source/assert.cpp new file mode 100644 index 0000000..7d32d5e --- /dev/null +++ b/EASTL/source/assert.cpp @@ -0,0 +1,108 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) Electronic Arts Inc. All rights reserved. +/////////////////////////////////////////////////////////////////////////////// + + +#include <EASTL/internal/config.h> +#include <EASTL/string.h> +#include <EABase/eabase.h> + +#if defined(EA_PLATFORM_MICROSOFT) + EA_DISABLE_ALL_VC_WARNINGS(); + #if defined(EA_COMPILER_MSVC) + #include <crtdbg.h> + #endif + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #include <Windows.h> + EA_RESTORE_ALL_VC_WARNINGS(); +#elif defined(EA_PLATFORM_ANDROID) + #include <android/log.h> +#else + #include <stdio.h> +#endif + + + + +namespace eastl +{ + + /// gpAssertionFailureFunction + /// + /// Global assertion failure function pointer. Set by SetAssertionFailureFunction. + /// + EASTL_API EASTL_AssertionFailureFunction gpAssertionFailureFunction = AssertionFailureFunctionDefault; + EASTL_API void* gpAssertionFailureFunctionContext = NULL; + + + + /// SetAssertionFailureFunction + /// + /// Sets the function called when an assertion fails. If this function is not called + /// by the user, a default function will be used. The user may supply a context parameter + /// which will be passed back to the user in the function call. This is typically used + /// to store a C++ 'this' pointer, though other things are possible. + /// + /// There is no thread safety here, so the user needs to externally make sure that + /// this function is not called in a thread-unsafe way. The easiest way to do this is + /// to just call this function once from the main thread on application startup. + /// + EASTL_API void SetAssertionFailureFunction(EASTL_AssertionFailureFunction pAssertionFailureFunction, void* pContext) + { + gpAssertionFailureFunction = pAssertionFailureFunction; + gpAssertionFailureFunctionContext = pContext; + } + + + + /// AssertionFailureFunctionDefault + /// + EASTL_API void AssertionFailureFunctionDefault(const char* pExpression, void* /*pContext*/) + { + #if EASTL_ASSERT_ENABLED + #if defined(EA_PLATFORM_MICROSOFT) + printf("%s\n", pExpression); // Write the message to stdout + if( ::IsDebuggerPresent()) + { + OutputDebugStringA(pExpression); + } + #elif defined(EA_PLATFORM_ANDROID) + __android_log_print(ANDROID_LOG_INFO, "PRINTF", "%s\n", pExpression); + #else + printf("%s\n", pExpression); // Write the message to stdout, which happens to be the trace view for many console debug machines. + #endif + #else + EA_UNUSED(pExpression); + #endif + + EASTL_DEBUG_BREAK(); + } + + + /// AssertionFailure + /// + EASTL_API void AssertionFailure(const char* pExpression) + { + if(gpAssertionFailureFunction) + gpAssertionFailureFunction(pExpression, gpAssertionFailureFunctionContext); + } + + +} // namespace eastl + + + + + + + + + + + + + + + |