Sierra Toolkit Version of the Day
assert_eastl.cpp
00001 /*
00002 Copyright (C) 2009-2010 Electronic Arts, Inc.  All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions
00006 are met:
00007 
00008 1.  Redistributions of source code must retain the above copyright
00009     notice, this list of conditions and the following disclaimer.
00010 2.  Redistributions in binary form must reproduce the above copyright
00011     notice, this list of conditions and the following disclaimer in the
00012     documentation and/or other materials provided with the distribution.
00013 3.  Neither the name of Electronic Arts, Inc. ("EA") nor the names of
00014     its contributors may be used to endorse or promote products derived
00015     from this software without specific prior written permission.
00016 
00017 THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
00018 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
00021 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 */
00028 
00030 // EASTL/assert.cpp
00031 //
00032 // Copyright (c) 2005, Electronic Arts. All rights reserved.
00033 // Written and maintained by Paul Pedriana.
00035 
00036 
00037 
00038 #include <stk_util/util/config_eastl.h>
00039 #include <stk_util/util/string_eastl.h>
00040 #include <stk_util/util/eabase_eastl.h>
00041 
00042 #if defined(EA_PLATFORM_MICROSOFT)
00043     #pragma warning(push, 0)
00044     #if defined _MSC_VER
00045         #include <crtdbg.h>
00046     #endif
00047     #if defined(EA_PLATFORM_WINDOWS)
00048         #ifndef WIN32_LEAN_AND_MEAN
00049             #define WIN32_LEAN_AND_MEAN
00050         #endif
00051         #include <windows.h>
00052     #elif defined(EA_PLATFORM_XENON)
00053         #include <comdecl.h>
00054     #endif
00055     #pragma warning(pop)
00056 #else
00057     #include <stdio.h>
00058 #endif
00059 
00060 
00061 
00062 
00063 namespace eastl
00064 {
00065 
00070     EASTL_API EASTL_AssertionFailureFunction gpAssertionFailureFunction        = AssertionFailureFunctionDefault;
00071     EASTL_API void*                          gpAssertionFailureFunctionContext = NULL;
00072 
00073 
00074 
00086     EASTL_API void SetAssertionFailureFunction(EASTL_AssertionFailureFunction pAssertionFailureFunction, void* pContext)
00087     {
00088         gpAssertionFailureFunction        = pAssertionFailureFunction;
00089         gpAssertionFailureFunctionContext = pContext;
00090     }
00091 
00092 
00093 
00096     EASTL_API void AssertionFailureFunctionDefault(const char* pExpression, void* /*pContext*/)
00097     {
00098 #if defined(EA_DEBUG) || defined(_DEBUG)
00099         // We cannot use puts() because it appends a newline.
00100         // We cannot use printf(pExpression) because pExpression might have formatting statements.
00101         #if defined(EA_PLATFORM_MICROSOFT)
00102             OutputDebugStringA(pExpression);
00103             (void)pExpression;
00104         #else
00105             printf("%s", pExpression); // Write the message to stdout, which happens to be the trace view for many console debug machines.
00106         #endif
00107 #endif
00108         EASTL_DEBUG_BREAK();
00109     }
00110 
00111 
00114     EASTL_API void AssertionFailure(const char* pExpression)
00115     {
00116         if(gpAssertionFailureFunction)
00117             gpAssertionFailureFunction(pExpression, gpAssertionFailureFunctionContext);
00118     }
00119 
00120 
00121 } // namespace eastl
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines