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
28 #ifndef CUSTOM_ASSERT_H
\r
29 #define CUSTOM_ASSERT_H
\r
31 namespace assert_ns { namespace Assert
\r
39 typedef FailBehavior (*Handler)(const char* condition,
\r
44 Handler GetHandler();
\r
45 void SetHandler(Handler newHandler);
\r
47 FailBehavior ReportFailure(const char* condition,
\r
50 const char* msg, ...);
\r
53 #if defined(_MSC_VER)
\r
54 # define X_HALT() __debugbreak()
\r
55 #elif defined(__GNUC__)
\r
56 # define X_HALT() __builtin_trap()
\r
58 # define X_HALT() exit(__LINE__)
\r
61 #define X_UNUSED(x) do { (void)sizeof(x); } while(0)
\r
64 #define X_ASSERT(cond) \
\r
69 if (assert_ns::Assert::ReportFailure(#cond, __FILE__, __LINE__, 0) == \
\r
70 assert_ns::Assert::Halt) \
\r
75 #define X_ASSERT_MSG(cond, msg, ...) \
\r
80 if (assert_ns::Assert::ReportFailure(#cond, __FILE__, __LINE__, (msg), __VA_ARGS__) == \
\r
81 assert_ns::Assert::Halt) \
\r
86 #define X_ASSERT_FAIL(msg, ...) \
\r
89 if (assert_ns::Assert::ReportFailure(0, __FILE__, __LINE__, (msg), __VA_ARGS__) == \
\r
90 assert_ns::Assert::Halt) \
\r
94 #define X_VERIFY(cond) X_ASSERT(cond)
\r
95 #define X_VERIFY_MSG(cond, msg, ...) X_ASSERT_MSG(cond, msg, ##__VA_ARGS__)
\r
97 #define X_ASSERT(condition) \
\r
98 do { X_UNUSED(condition); } while(0)
\r
99 #define X_ASSERT_MSG(condition, msg, ...) \
\r
100 do { X_UNUSED(condition); X_UNUSED(msg); } while(0)
\r
101 #define X_ASSERT_FAIL(msg, ...) \
\r
102 do { X_UNUSED(msg); } while(0)
\r
103 #define X_VERIFY(cond) (void)(cond)
\r
104 #define X_VERIFY_MSG(cond, msg, ...) \
\r
105 do { (void)(cond); X_UNUSED(msg); } while(0)
\r
108 #define X_STATIC_ASSERT(x) \
\r
109 typedef char StaticAssert[(x) ? 1 : -1];
\r
111 #endif // CUSTOM_ASSERT_H
\r