2 * Copyright (c) 2008, Power of Two Games LLC
\r
3 * 2010, Strahinja Markovic
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions are met:
\r
7 * * Redistributions of source code must retain the above copyright
\r
8 * notice, this list of conditions and the following disclaimer.
\r
9 * * Redistributions in binary form must reproduce the above copyright
\r
10 * notice, this list of conditions and the following disclaimer in the
\r
11 * documentation and/or other materials provided with the distribution.
\r
12 * * Neither the name of Power of Two Games LLC nor the
\r
13 * names of its contributors may be used to endorse or promote products
\r
14 * derived from this software without specific prior written permission.
\r
16 * THIS SOFTWARE IS PROVIDED BY POWER OF TWO GAMES LLC ``AS IS'' AND ANY
\r
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
19 * DISCLAIMED. IN NO EVENT SHALL POWER OF TWO GAMES LLC BE LIABLE FOR ANY
\r
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
\r
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
29 #include "CustomAssert.h"
\r
39 Assert::FailBehavior DefaultHandler(const char* condition,
\r
44 std::printf("%s(%d): Assert Failure: ", file, line);
\r
46 if (condition != NULL)
\r
47 std::printf("'%s' ", condition);
\r
50 std::printf("%s", msg);
\r
54 return Assert::Halt;
\r
57 Assert::Handler& GetAssertHandlerInstance()
\r
59 static Assert::Handler s_handler = &DefaultHandler;
\r
65 Assert::Handler Assert::GetHandler()
\r
67 return GetAssertHandlerInstance();
\r
70 void Assert::SetHandler(Assert::Handler newHandler)
\r
72 GetAssertHandlerInstance() = newHandler;
\r
75 Assert::FailBehavior Assert::ReportFailure(const char* condition,
\r
78 const char* msg, ...)
\r
80 const char* message = NULL;
\r
83 char messageBuffer[1024];
\r
86 va_start(args, msg);
\r
88 #if defined(_MSC_VER)
\r
89 vsnprintf_s(messageBuffer, 1024, 1024, msg, args);
\r
91 vsnprintf(messageBuffer, 1024, msg, args);
\r
97 message = messageBuffer;
\r
100 return GetAssertHandlerInstance()(condition, message, file, line);
\r