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_FULLY_SUPPORTS_CPP14_CONSTEXPR 1
34 #define YI_IS_LITTLE_ENDIAN 1
35 #define YI_NO_INLINE __attribute__((noinline))
36 #define YI_FORCE_INLINE __attribute__((always_inline)) inline
37 #define YI_SYNCHRONIZATION_OBJECT_INIT_VALUE
38 
39 #include <framework/YiPredefPlatform.h>
40 
41 // Common macros
42 #define YI_MIN(a, b) (((a) < (b)) ? (a) : (b))
43 #define YI_MAX(a, b) (((a) < (b)) ? (b) : (a))
44 #define YI_FLOAT_EQUAL(a, b) ((a) >= ((b)-FLT_EPSILON) && (a) <= ((b) + FLT_EPSILON))
45 #define YI_UNUSED(param) (void)(param)
46 
47 // Cause compilation errors if certain unsafe functions are used (CWE-120)
48 #if !defined(YI_DEBUG) && !defined(YI_DISABLE_SECURITY)
49 # include <cstring>
50 # include <wchar.h>
51 # 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).")
52 # 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).")
53 # define gets(str) static_assert(false, "gets: Does not check for buffer overflows (CWE-120, CWE-20). Use fgets() instead.")
54 # 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.")
55 # define wcscat(dst, src) static_assert(false, "wcscat: Does not check for buffer overflows when concatenating to destination (CWE-120).")
56 template<typename T, typename... Args>
57 inline int sprintf(T &&, Args &&...)
58 {
59  static_assert(sizeof(T) != 0, "sprintf: Does not check for buffer overflows (CWE-120). Use YI_SNPRINTF or sprintf_s.");
60  return -1;
61 }
62 #endif
63 
64 // Class definition helpers
65 
69 #define YI_DISALLOW_COPY_AND_ASSIGN(TypeName) \
70  TypeName(const TypeName &) = delete; \
71  TypeName &operator=(const TypeName &) = delete;
72 
76 #define YI_DEFAULT_MOVE_AND_COPY(TypeName) \
77  TypeName &operator=(const TypeName &) = default; \
78  TypeName &operator=(TypeName &&) = default; \
79  TypeName(const TypeName &) = default; \
80  TypeName(TypeName &&) = default;
81 
85 #define YI_DEFAULT_MOVE_NO_COPY(TypeName) \
86  TypeName &operator=(const TypeName &) = delete; \
87  TypeName &operator=(TypeName &&) = default; \
88  TypeName(const TypeName &) = delete; \
89  TypeName(TypeName &&) = default;
90 
94 #define YI_DEFAULT_MOVE(TypeName) \
95  TypeName &operator=(TypeName &&) = default; \
96  TypeName(TypeName &&) = default;
97 
101 #define YI_DEFAULT_COPY(TypeName) \
102  TypeName &operator=(const TypeName &) = default; \
103  TypeName(const TypeName &) = default;
104 
109 // The following are to facilitate upgrades, and will be removed in a future release.
110 #define YI_ASSERT(...) static_assert(false, "Missing #include <utility/YiError.h> in this source file.")
111 #define YI_LOGD(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
112 #define YI_LOGI(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
113 #define YI_LOGW(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
114 #define YI_LOGE(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
115 #define YI_LOGF(...) static_assert(false, "Missing #include <logging/YiLogger.h> in this source file.")
116 #define YI_SLEEP(...) static_assert(false, "Missing #include <utility/YiTimeUtilities.h> in this source file.")
117 #define YI_USLEEP(...) static_assert(false, "Missing #include <utility/YiTimeUtilities.h> in this source file.")
118 #define YI_FILE(...) static_assert(false, "Missing #include <utility/YiFileUtilities.h> in this source file.")
119 #define YI_MEMSET(...) static_assert(false, "Missing #include <utility/YiMemoryUtilities.h> in this source file.")
120 
121 #ifdef YI_DEPRECATED_PREDEF
123 #endif
124 
125 #endif // _YI_PREDEF_H_
int sprintf(T &&, Args &&...)
Definition: YiPredef.h:57