1 | // LAF Base Library |
2 | // Copyright (c) 2020 Igara Studio S.A. |
3 | // Copyright (c) 2001-2016 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifndef BASE_BASE_H_INCLUDED |
9 | #define BASE_BASE_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "base/config.h" |
13 | |
14 | #include <math.h> |
15 | |
16 | #ifdef _MSC_VER |
17 | #define LAF_NORETURN(ret, name, args) __declspec(noreturn) ret name args |
18 | #else |
19 | #define LAF_NORETURN(ret, name, args) ret name args __attribute__((noreturn)) |
20 | #endif |
21 | |
22 | #define LAF_ANALYZER_NORETURN |
23 | #if defined(__clang__) |
24 | #if __has_feature(attribute_analyzer_noreturn) |
25 | #undef LAF_ANALYZER_NORETURN |
26 | #define LAF_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) |
27 | #endif |
28 | #endif |
29 | |
30 | #undef NULL |
31 | #ifdef __cplusplus |
32 | #define NULL nullptr |
33 | #else |
34 | #define NULL ((void*)0) |
35 | #endif |
36 | |
37 | #undef ABS |
38 | #undef SGN |
39 | #define ABS(x) (((x) >= 0) ? (x) : (-(x))) |
40 | #define SGN(x) (((x) >= 0) ? 1 : -1) |
41 | |
42 | |
43 | |
44 | ////////////////////////////////////////////////////////////////////// |
45 | // Overloaded new/delete operators to detect memory-leaks |
46 | |
47 | #if defined __cplusplus && defined LAF_MEMLEAK |
48 | |
49 | #include <new> |
50 | |
51 | #ifdef _NOEXCEPT |
52 | #define LAF_NOEXCEPT _NOEXCEPT |
53 | #else |
54 | #define LAF_NOEXCEPT |
55 | #endif |
56 | |
57 | void* operator new(std::size_t size); |
58 | void* operator new[](std::size_t size); |
59 | void operator delete(void* ptr) LAF_NOEXCEPT; |
60 | void operator delete[](void* ptr) LAF_NOEXCEPT; |
61 | |
62 | #endif |
63 | |
64 | #endif |
65 | |