From e59cf7b09e7388d369e8d2bf73501cde79c28708 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Thu, 8 Apr 2021 16:43:58 +0200 Subject: Squashed 'EASTL/' content from commit fad5471 git-subtree-dir: EASTL git-subtree-split: fad54717f8e4ebb13b20095da7efd07a53af0f10 --- source/assert.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 source/assert.cpp (limited to 'source/assert.cpp') diff --git a/source/assert.cpp b/source/assert.cpp new file mode 100644 index 0000000..7d32d5e --- /dev/null +++ b/source/assert.cpp @@ -0,0 +1,108 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) Electronic Arts Inc. All rights reserved. +/////////////////////////////////////////////////////////////////////////////// + + +#include +#include +#include + +#if defined(EA_PLATFORM_MICROSOFT) + EA_DISABLE_ALL_VC_WARNINGS(); + #if defined(EA_COMPILER_MSVC) + #include + #endif + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #include + EA_RESTORE_ALL_VC_WARNINGS(); +#elif defined(EA_PLATFORM_ANDROID) + #include +#else + #include +#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 + + + + + + + + + + + + + + + -- cgit v1.2.3