You.i Engine
YiPredef.h
Go to the documentation of this file.
1 // © You i Labs Inc. All rights reserved.
2 #ifndef _YI_PREDEF_H_
3 #define _YI_PREDEF_H_
4 
5 #include <cfloat> // For FLT_EPSILON
6 #include <cstdint> // For fixed-size types (e.g. int32_t)
7 
13 // Enforce debuging preprocessor directive
14 #if !defined(YI_DEBUG) && !defined(_DEBUG) && !defined(DEBUG) && !defined(NDEBUG)
15 # error None of the expected debugging (or release) macros can be found. YI_DEBUG must be defined for debug builds, and NDEBUG must be defined for release builds.
16 #endif
17 #if defined(YI_DEBUG) || defined(_DEBUG) || defined(DEBUG)
18 # if !defined(YI_DEBUG)
19 # define YI_DEBUG 1
20 # endif
21 # if !defined(_DEBUG)
22 # define _DEBUG 1
23 # endif
24 # if !defined(DEBUG)
25 # define DEBUG 1
26 # endif
27 #endif
28 #if defined(YI_DEBUG) && defined(NDEBUG)
29 # error YI_DEBUG and NDEBUG cannot both be defined at the same time.
30 #endif
31 
32 // Common defines (may be modified by the YiPredefPlatform.h include)
33 #define YI_IS_LITTLE_ENDIAN 1
34 #define YI_NO_INLINE __attribute__((noinline))
35 #define YI_FORCE_INLINE __attribute__((always_inline)) inline
36 #define YI_SYNCHRONIZATION_OBJECT_INIT_VALUE
37 
38 #define YI_CONSTEXPR constexpr
39 #define YI_CONSTEXPR_IMPL constexpr
40 
41 #include <framework/YiPredefPlatform.h>
42 
43 // Common macros
44 #define YI_MIN(a, b) (((a) < (b)) ? (a) : (b))
45 #define YI_MAX(a, b) (((a) < (b)) ? (b) : (a))
46 #define YI_FLOAT_EQUAL(a, b) ((a) >= ((b)-FLT_EPSILON) && (a) <= ((b) + FLT_EPSILON))
47 #define YI_UNUSED(param) (void)(param)
48 
49 // Cause compilation errors if certain unsafe functions are used (CWE-120)
50 #if !defined(YI_DEBUG) && !defined(YI_DISABLE_SECURITY)
51 # include <cstring>
52 # include <wchar.h>
53 # define strcat(dst, src) static_assert(false, "strcat: Does not check for buffer overflows when concatenating to destination (CWE-120). Consider using YI_STRNCAT, strcat_s, or strlcat (warning, YI_STRNCAT is easily misused).")
54 # define strcpy(dst, src) static_assert(false, "strcpy: Does not check for buffer overflows when copying to destination (CWE-120). Consider using YI_STRNCPY, strcpy_s, or strlcpy (warning, YI_STRNCAT is easily misused).")
55 # define gets(str) static_assert(false, "gets: Does not check for buffer overflows (CWE-120, CWE-20). Use fgets() instead.")
56 # define wcscpy(dst, src) static_assert(false, "wcscpy: Does not check for buffer overflows when copying to destination (CWE-120). Consider using a function version that stops copying at the end of the buffer.")
57 # define wcscat(dst, src) static_assert(false, "wcscat: Does not check for buffer overflows when concatenating to destination (CWE-120).")
58 template<typename T, typename... Args>
59 inline int sprintf(T &&, Args &&...)
60 {
61  static_assert(sizeof(T) != 0, "sprintf: Does not check for buffer overflows (CWE-120). Use YI_SNPRINTF or sprintf_s.");
62  return -1;
63 }
64 #endif
65 
66 // Class definition helpers
67 
71 #define YI_DISALLOW_COPY_AND_ASSIGN(TypeName) \
72  TypeName(const TypeName &) = delete; \
73  TypeName &operator=(const TypeName &) = delete;
74 
78 #define YI_DEFAULT_MOVE_AND_COPY(TypeName) \
79  TypeName &operator=(const TypeName &) = default; \
80  TypeName &operator=(TypeName &&) = default; \
81  TypeName(const TypeName &) = default; \
82  TypeName(TypeName &&) = default;
83 
87 #define YI_DEFAULT_MOVE_NO_COPY(TypeName) \
88  TypeName &operator=(const TypeName &) = delete; \
89  TypeName &operator=(TypeName &&) = default; \
90  TypeName(const TypeName &) = delete; \
91  TypeName(TypeName &&) = default;
92 
96 #define YI_DEFAULT_MOVE(TypeName) \
97  TypeName &operator=(TypeName &&) = default; \
98  TypeName(TypeName &&) = default;
99 
103 #define YI_DEFAULT_COPY(TypeName) \
104  TypeName &operator=(const TypeName &) = default; \
105  TypeName(const TypeName &) = default;
106 
111 // The following are to facilitate upgrades, and will be removed in a future release.
112 #define YI_ASSERT(...) static_assert(false, "Missing #include <utility/YiError.h> in this source file.")
113 #define YI_LOGD(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
114 #define YI_LOGI(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
115 #define YI_LOGW(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
116 #define YI_LOGE(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
117 #define YI_LOGF(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
118 #define YI_SLEEP(...) static_assert(false, "Missing #include <utility/YiTimeUtilities.h> in this source file.")
119 #define YI_USLEEP(...) static_assert(false, "Missing #include <utility/YiTimeUtilities.h> in this source file.")
120 #define YI_FILE(...) static_assert(false, "Missing #include <utility/YiFileUtilities.h> in this source file.")
121 #define YI_MEMSET(...) static_assert(false, "Missing #include <utility/YiMemoryUtilities.h> in this source file.")
122 
123 #ifdef YI_DEPRECATED_PREDEF
125 #endif
126 
127 #endif // _YI_PREDEF_H_
int sprintf(T &&, Args &&...)
Definition: YiPredef.h:59