1 // LAF Base Library
2 // Copyright (c) 2001-2016 David Capello
3 //
4 // This file is released under the terms of the MIT license.
5 // Read LICENSE.txt for more information.
6 
7 #ifndef BASE_DEBUG_H_INCLUDED
8 #define BASE_DEBUG_H_INCLUDED
9 #pragma once
10 
11 int base_assert(const char* condition, const char* file, int lineNum);
12 void base_trace(const char* msg, ...);
13 
14 #undef ASSERT
15 #undef TRACE
16 
17 #ifdef _DEBUG
18   #ifdef _WIN32
19     #include <crtdbg.h>
20     #define base_break() _CrtDbgBreak()
21   #else
22     #include <signal.h>
23     #define base_break() raise(SIGTRAP)
24   #endif
25 
26   #define ASSERT(condition) {                                             \
27     if (!(condition)) {                                                   \
28       if (base_assert(#condition, __FILE__, __LINE__)) {                  \
29         base_break();                                                     \
30       }                                                                   \
31     }                                                                     \
32   }
33 
34   #define TRACE base_trace
35 #else
36   #define ASSERT(condition)
37   #define TRACE(...)
38 #endif
39 
40 #endif
41