You.i Engine
YiPredef.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_PREDEF_H_
3 #define _YI_PREDEF_H_
4 
5 #define YI_DRAW_SKIP
6 
12 #if defined(__x86_64__) || defined(__powerpc64__) || defined(__powerpc64__) || defined(_WIN64) || \
13  defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || \
14  defined(__s390x__) || defined(__arm64) || defined(__aarch64__) || defined(__amd64__) || \
15  defined(_M_AMD64) || defined(_M_X64)
16  #define YI_ENV_64 1
17 #else
18  #define YI_ENV_32 1
19 #endif
20 
21 // Enforce debuging preprocessor directive
22 #if !defined(YI_DEBUG) && !defined(_DEBUG) && !defined(DEBUG) && !defined(NDEBUG)
23  #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.
24 #endif
25 #if defined(YI_DEBUG) || defined(_DEBUG) || defined(DEBUG)
26  #if !defined(YI_DEBUG)
27  #define YI_DEBUG 1
28  #endif
29  #if !defined(_DEBUG)
30  #define _DEBUG 1
31  #endif
32  #if !defined(DEBUG)
33  #define DEBUG 1
34  #endif
35 #endif
36 #if defined(YI_DEBUG) && defined(NDEBUG)
37  #error YI_DEBUG and NDEBUG cannot both be defined at the same time.
38 #endif
39 
40 #include <framework/YiPredefPlatform.h>
42 
43 // Mandatory CWE-120 preventions
44 #if !defined(YI_DISABLE_SECURITY)
45 #define strcat(dst, src) YI_ERROR("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).")
46 #define strcpy(dst, src) YI_ERROR("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).")
47 #define sprintf(str, fmt, ...) YI_ERROR("sprintf: Does not check for buffer overflows (CWE-120). Use YI_SNPRINTF, YI_VSNPRINTF, or sprintf_s.")
48 #define gets(str) YI_ERROR("gets: Does not check for buffer overflows (CWE-120, CWE-20). Use fgets() instead.")
49 #define wcscpy(dst, src) YI_ERROR("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.")
50 #define wcscat(dst, src) YI_ERROR("wcscat: Does not check for buffer overflows when concatenating to destination (CWE-120).")
51 #define swprintf(str, fmt, ...) YI_ERROR("swprintf: Does not check for buffer overflows (CWE-120). Use YI_SNPRINTF, YI_VSNPRINTF, or sprintf_s.")
52 #endif
53 
54 // By default, allow printing of URLs to the console for debug builds
55 #ifndef NDEBUG
56 #define YI_DISABLE_URL_SECURITY
57 #endif
58 
59 #include <cstdint>
60 
61 #define YI_WTEXT(quote) (const wchar_t *)L##quote
62 #define YI_TEXT(quote) (const char *)quote
63 #define YI_TEXT16(quote) (const char16_t *)L##quote
64 #define YI_TEXT32(quote) (const char32_t *)L##quote
65 
66 // framework/YiPredefXXXXX.h should define YI_HASINLINE if platform supports
67 // however the double underscored __inline is Microsoft specific and no other platforms define YI_HASINLINE at the moment
68 // presumably they would use inline
69 #ifdef YI_HASINLINE
70 #define YI_INLINE __inline
71 #define YI_EXTERNINLINE extern __inline
72 #else
73 #define YI_INLINE
74 #define YI_EXTERNINLINE
75 #endif
76 #define YI_SEEK_SET 0
77 #define YI_SEEK_END 1
78 #define YI_SEEK_CUR 2
79 #define YI_MAX_PATH 260
80 #define YI_MAX_BUFFER 1024
81 
82 #define YI_MIN(a, b) (((a) < (b)) ? (a) : (b))
83 #define YI_MAX(a, b) (((a) < (b)) ? (b) : (a))
84 #define YI_FLOAT_EQUAL(a, b) ((a) >= ((b) - FLT_EPSILON) && (a) <= ((b) + FLT_EPSILON))
85 #define YI_UNUSED(param) (void)(param)
86 //#define YI_HASPROFILER //Show a time profiler of various functions.
87 
88 #if defined(_MSC_VER)
89 #define YI_UNUSED_ATTRIBUTE
90 #else
91 #define YI_UNUSED_ATTRIBUTE __attribute__((unused))
92 #endif
93 
94 #if defined(__clang__) || defined(__GNUC__)
95 #define YI_FORCE_INLINE __attribute__((always_inline)) inline
96 #elif defined(_MSC_VER)
97 #define YI_FORCE_INLINE __forceinline
98 #else
99 #define YI_FORCE_INLINE inline
100 #endif
101 
102 // Detect if template specialization of templated functions is fully supported
103 #if defined(_MSC_VER)
104 # if _MSC_VER != 1800 // there's a bug in vs2013 that prevents template specializations from working in some cases (e.g. when used with YiEnableIf)
105 # define YI_FUNCTION_SPECIALIZATION_FULLY_SUPPORTED
106 # endif
107 #else
108 # define YI_FUNCTION_SPECIALIZATION_FULLY_SUPPORTED
109 #endif
110 
114 #define YI_DISALLOW_COPY_AND_ASSIGN(TypeName) \
115  TypeName(const TypeName &) = delete; \
116  TypeName &operator=(const TypeName &) = delete;
117 
121 #define YI_DEFAULT_MOVE_AND_COPY(TypeName) \
122  TypeName &operator=(const TypeName &) = default; \
123  TypeName &operator=(TypeName &&) = default; \
124  TypeName(const TypeName &) = default; \
125  TypeName(TypeName &&) = default;
126 
130 #define YI_DEFAULT_MOVE_NO_COPY(TypeName) \
131  TypeName &operator=(const TypeName &) = delete; \
132  TypeName &operator=(TypeName &&) = default; \
133  TypeName(const TypeName &) = delete; \
134  TypeName(TypeName &&) = default;
135 
139 #define YI_DEFAULT_MOVE(TypeName) \
140  TypeName &operator=(TypeName &&) = default; \
141  TypeName(TypeName &&) = default;
142 
146 #define YI_DEFAULT_COPY(TypeName) \
147  TypeName &operator=(const TypeName &) = default; \
148  TypeName(const TypeName &) = default;
149 
150 #if !defined(DOXY) && defined(YI_WIN32)
151  #define YI_REMOVE_CONSTANT_CONDITION(x) \
152  __pragma(warning(push)) \
153  __pragma(warning(disable:4127)) \
154  do { x } while ((void)0, 0) \
155  __pragma(warning(pop))
156 #else
157 
166  #define YI_REMOVE_CONSTANT_CONDITION(x) do { x } while ((void)0, 0)
167 #endif
168 
169 // Structures
170 
171 struct YI_POINT
172 {
173  int32_t nX;
174  int32_t nY;
175 };
176 
178 {
179  float fX;
180  float fY;
181 };
182 
183 struct YI_RECT
184 {
185  int32_t nLeft;
186  int32_t nTop;
187  int32_t nRight;
188  int32_t nBottom;
189 
190  bool operator<(YI_RECT const& other) const
191  {
192  if(nLeft < other.nLeft)
193  {
194  return true;
195  }
196  else if(nLeft == other.nLeft)
197  {
198  if(nTop < other.nTop)
199  {
200  return true;
201  }
202  else if(nTop == other.nTop)
203  {
204  if(nRight < other.nRight)
205  {
206  return true;
207  }
208  else if(nRight == other.nRight)
209  {
210  if(nBottom < other.nBottom)
211  {
212  return true;
213  }
214  }
215  }
216  }
217  return false;
218  }
219 };
220 
221 inline bool operator==(const YI_RECT &rLHS, const YI_RECT &rRHS)
222 {
223  return (rLHS.nLeft == rRHS.nLeft ) &&
224  (rLHS.nTop == rRHS.nTop ) &&
225  (rLHS.nRight == rRHS.nRight ) &&
226  (rLHS.nBottom == rRHS.nBottom );
227 }
228 
229 inline bool operator!=(const YI_RECT &rLHS, const YI_RECT &rRHS)
230 {
231  return !(rLHS == rRHS);
232 }
233 
235 {
236  YI_RECT_REL() : nX(0), nY(0), nWidth(0), nHeight(0)
237  {}
238 
239  YI_RECT_REL(int32_t x, int32_t y, int32_t width, int32_t height) :
240  nX(x),
241  nY(y),
242  nWidth(width),
243  nHeight(height)
244  {}
245 
246  void Set(int32_t x, int32_t y, int32_t width, int32_t height)
247  {
248  nX = x;
249  nY = y;
250  nWidth = width;
251  nHeight = height;
252  }
253 
254  int32_t nX;
255  int32_t nY;
256  int32_t nWidth;
257  int32_t nHeight;
258 };
259 
260 inline bool operator==(const YI_RECT_REL &rLHS, const YI_RECT_REL &rRHS)
261 {
262  return (rLHS.nX == rRHS.nX ) &&
263  (rLHS.nY == rRHS.nY ) &&
264  (rLHS.nWidth == rRHS.nWidth ) &&
265  (rLHS.nHeight == rRHS.nHeight );
266 }
267 
268 inline bool operator!=(const YI_RECT_REL &rLHS, const YI_RECT_REL &rRHS)
269 {
270  return !(rLHS == rRHS);
271 }
272 
274 {
275  float fLeft;
276  float fTop;
277  float fRight;
278  float fBottom;
279 };
280 
281 
282 inline bool operator<(const YI_FLOAT_RECT &lhs, const YI_FLOAT_RECT &rhs)
283 {
284  if (lhs.fLeft < rhs.fLeft)
285  {
286  return true;
287  }
288  else if (lhs.fLeft > rhs.fLeft)
289  {
290  return false;
291  }
292 
293  if (lhs.fTop < rhs.fTop)
294  {
295  return true;
296  }
297  else if (lhs.fTop > rhs.fTop)
298  {
299  return false;
300  }
301 
302  if (lhs.fRight < rhs.fRight)
303  {
304  return true;
305  }
306  else if (lhs.fRight > rhs.fRight)
307  {
308  return false;
309  }
310 
311  return lhs.fBottom < rhs.fBottom;
312 }
313 
314 inline bool operator>(const YI_FLOAT_RECT &lhs, const YI_FLOAT_RECT &rhs)
315 {
316  return rhs < lhs;
317 }
318 
319 inline bool operator<=(const YI_FLOAT_RECT &lhs, const YI_FLOAT_RECT &rhs)
320 {
321  return !(rhs < lhs);
322 }
323 
324 inline bool operator>=(const YI_FLOAT_RECT &lhs, const YI_FLOAT_RECT &rhs)
325 {
326  return !(lhs < rhs);
327 }
328 
329 inline bool operator==(const YI_FLOAT_RECT &rLHS, const YI_FLOAT_RECT &rRHS)
330 {
331  return YI_FLOAT_EQUAL(rLHS.fLeft, rRHS.fLeft) &&
332  YI_FLOAT_EQUAL(rLHS.fTop, rRHS.fTop) &&
333  YI_FLOAT_EQUAL(rLHS.fRight, rRHS.fRight) &&
334  YI_FLOAT_EQUAL(rLHS.fBottom, rRHS.fBottom);
335 }
336 
337 inline bool operator!=(const YI_FLOAT_RECT &rLHS, const YI_FLOAT_RECT &rRHS)
338 {
339  return !(rLHS == rRHS);
340 }
341 
343 {
344  YI_FLOAT_RECT_REL() : fX(0), fY(0), fWidth(0), fHeight(0)
345  {}
346 
347  YI_FLOAT_RECT_REL(float x, float y, float width, float height) :
348  fX(x),
349  fY(y),
350  fWidth(width),
351  fHeight(height)
352  {}
353 
354  void Set(float x, float y, float width, float height)
355  {
356  fX = x;
357  fY = y;
358  fWidth = width;
359  fHeight = height;
360  }
361 
362  float fX;
363  float fY;
364  float fWidth;
365  float fHeight;
366 };
367 
368 inline bool operator==(const YI_FLOAT_RECT_REL &rLHS, const YI_FLOAT_RECT_REL &rRHS)
369 {
370  return YI_FLOAT_EQUAL(rLHS.fX, rRHS.fX) &&
371  YI_FLOAT_EQUAL(rLHS.fY, rRHS.fY) &&
372  YI_FLOAT_EQUAL(rLHS.fWidth, rRHS.fWidth) &&
373  YI_FLOAT_EQUAL(rLHS.fHeight, rRHS.fHeight);
374 }
375 
376 inline bool operator!=(const YI_FLOAT_RECT_REL &rLHS, const YI_FLOAT_RECT_REL &rRHS)
377 {
378  return !(rLHS == rRHS);
379 }
380 
381 /*****************************************************************************
382  Bitmap rotation modes
383 ****************************************************************************/
385 {
393 };
394 
395 // Macros to help with endianess
396 #if defined(__BIG_ENDIAN__)
397 #define YI_LITTLE_ENDIAN_16(a) (((a & 0xff) << 8) | ((a & 0xff00) >> 8))
398 #define YI_LITTLE_ENDIAN_24(a) (((a >> 16) & 0xff) | (a & 0xff00)| ((a&0xff)<<16))
399 #define YI_LITTLE_ENDIAN_32(a) (((a >> 24) & 0xff) | ((a >> 8) & 0xff00) | ((a & 0xff00) << 8) | ((a & 0xff) << 24))
400 #ifdef _MSC_VER
401 #define YI_LITTLE_ENDIAN_64(a) (((a >> 56) & 0xff) | ((a >> 40) & 0xff00) | ((a >> 24) & 0xff0000) | ((a >> 8) & 0xff000000) | \
402  ((a << 8) & DECL_U64(0xff00000000)) | ((a << 24) & DECL_U64(0xff0000000000)) | \
403  ((a << 40) & DECL_U64(0xff000000000000)) | ((a << 56) & DECL_U64(0xff00000000000000)))
404 #else
405 #define YI_LITTLE_ENDIAN_64(a) (((a >> 56) & 0xff) | ((a >> 40) & 0xff00) | ((a >> 24) & 0xff0000) | ((a >> 8) & 0xff000000) | \
406  ((a << 8) & 0xff00000000LLU) | ((a << 24) & 0xff0000000000LLU) | \
407  ((a << 40) & 0xff000000000000LLU) | ((a << 56) & 0xff00000000000000LLU))
408 #endif
409 #else
410 #define YI_LITTLE_ENDIAN_16(a) (a)
411 #define YI_LITTLE_ENDIAN_24(a) (a)
412 #define YI_LITTLE_ENDIAN_32(a) (a)
413 #define YI_LITTLE_ENDIAN_64(a) (a)
414 #endif
415 
421 
422 #endif // _YI_PREDEF_H_
YI_FLOAT_RECT_REL(float x, float y, float width, float height)
Definition: YiPredef.h:347
Definition: YiPredef.h:392
float fX
Definition: YiPredef.h:362
bool operator>=(const YI_FLOAT_RECT &lhs, const YI_FLOAT_RECT &rhs)
Definition: YiPredef.h:324
int32_t nHeight
Definition: YiPredef.h:257
YI_FLOAT_RECT_REL()
Definition: YiPredef.h:344
int32_t nBottom
Definition: YiPredef.h:188
Definition: YiPredef.h:234
float fWidth
Definition: YiPredef.h:364
void Set(float x, float y, float width, float height)
Definition: YiPredef.h:354
int32_t nTop
Definition: YiPredef.h:186
Definition: YiPredef.h:183
bool operator==(const YI_RECT &rLHS, const YI_RECT &rRHS)
Definition: YiPredef.h:221
float fRight
Definition: YiPredef.h:277
Definition: YiPredef.h:390
float fBottom
Definition: YiPredef.h:278
float fX
Definition: YiPredef.h:179
Definition: YiPredef.h:387
bool operator<(const YI_FLOAT_RECT &lhs, const YI_FLOAT_RECT &rhs)
Definition: YiPredef.h:282
Definition: YiPredef.h:273
float fLeft
Definition: YiPredef.h:275
Definition: YiPredef.h:388
Definition: YiPredef.h:386
YI_RECT_REL(int32_t x, int32_t y, int32_t width, int32_t height)
Definition: YiPredef.h:239
YI_BUFFER_REORENT
Definition: YiPredef.h:384
int32_t nY
Definition: YiPredef.h:174
bool operator!=(const YI_RECT &rLHS, const YI_RECT &rRHS)
Definition: YiPredef.h:229
float fY
Definition: YiPredef.h:180
float fHeight
Definition: YiPredef.h:365
int32_t nRight
Definition: YiPredef.h:187
Definition: YiPredef.h:171
float fTop
Definition: YiPredef.h:276
int32_t nY
Definition: YiPredef.h:255
bool operator<(YI_RECT const &other) const
Definition: YiPredef.h:190
Definition: YiPredef.h:342
int32_t nX
Definition: YiPredef.h:173
void Set(int32_t x, int32_t y, int32_t width, int32_t height)
Definition: YiPredef.h:246
YI_RECT_REL()
Definition: YiPredef.h:236
int32_t nWidth
Definition: YiPredef.h:256
int32_t nLeft
Definition: YiPredef.h:185
Definition: YiPredef.h:177
bool operator<=(const YI_FLOAT_RECT &lhs, const YI_FLOAT_RECT &rhs)
Definition: YiPredef.h:319
bool operator>(const YI_FLOAT_RECT &lhs, const YI_FLOAT_RECT &rhs)
Definition: YiPredef.h:314
Definition: YiPredef.h:389
float fY
Definition: YiPredef.h:363
#define YI_FLOAT_EQUAL(a, b)
Definition: YiPredef.h:84
int32_t nX
Definition: YiPredef.h:254
Definition: YiPredef.h:391