1// tAssert.h 
2// 
3// Tacent asserts and warnings. 
4// 
5// Copyright (c) 2004-2006, 2015, 2017 Tristan Grimmer. 
6// Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby 
7// granted, provided that the above copyright notice and this permission notice appear in all copies. 
8// 
9// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 
10// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 
11// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
12// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
13// PERFORMANCE OF THIS SOFTWARE. 
14 
15#pragma once 
16#include <Foundation/tPlatform.h> 
17 
18 
19// Asserts to be used to detect coding errors only. Not for input errors or validation. Asserts are serious and get 
20// compiled out only in profile and ship configurations. 
21void tAssertPrintBreak(const char* expr, const char* fileName, int lineNum, const char* message); 
22#if defined(CONFIG_PROFILE) || defined(CONFIG_SHIP) 
23 #define tAssert(expr) ((void)(expr)); 
24 #define tAssertMsg(expr, msg) ((void)(expr)); 
25#else 
26 #define tAssert(expr) if (!(expr)) tAssertPrintBreak(#expr, __FILE__, __LINE__, nullptr); 
27 #define tAssertMsg(expr, msg) if (!(expr)) tAssertPrintBreak(#expr, __FILE__, __LINE__, msg); 
28#endif 
29 
30#define tStaticAssert(expr) static_assert(expr, #expr) 
31#if defined(PLATFORM_WINDOWS) 
32 #define tStaticAssertMsg(expr, msg) static_assert(expr, #expr##" \""##msg##"\"") 
33#else 
34 #define tStaticAssertMsg(expr, msg) static_assert(expr, #expr " \"" msg "\"") 
35#endif 
36 
37 
38void tAbort(); 
39 
40 
41// These next defines are handy for leaving notes in the code that show in the compiler output. You can also 
42// double-click them to be taken to the precise source code line in the IDE. 
43// 
44// In your source code enter a line like one of the following two: 
45// Todo(Do not forget to fix this) 
46// Note("Here's a note") 
47#if defined(PLATFORM_WINDOWS) 
48#define tMsgHelper2(x) #x 
49#define tMsgHelper1(x) tMsgHelper2(x) 
50#define tMsgToDo __FILE__ "("tMsgHelper1(__LINE__)") : ToDo: " 
51#define tMsgNote __FILE__ "("tMsgHelper1(__LINE__)") : Note: " 
52#define tToDo(x) __pragma(message(tMsgToDo #x)) 
53#define tNote(x) __pragma(message(tMsgNote #x)) 
54#elif defined(PLATFORM_LINUX) 
55#define tToDo(x) _Pragma("message(\"tToDo\")") 
56#define tNote(x) _Pragma("message(\"tNote\")") 
57#else 
58#define tToDo(x) _Pragma(#x) 
59#define tNote(x) _Pragma(#x) 
60#endif 
61