wdltypes.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef _WDLTYPES_
  2. #define _WDLTYPES_
  3. #ifdef _MSC_VER
  4. typedef __int64 WDL_INT64;
  5. typedef unsigned __int64 WDL_UINT64;
  6. #else
  7. typedef long long WDL_INT64;
  8. typedef unsigned long long WDL_UINT64;
  9. #endif
  10. #ifdef _MSC_VER
  11. #define WDL_UINT64_CONST(x) (x##ui64)
  12. #define WDL_INT64_CONST(x) (x##i64)
  13. #else
  14. #define WDL_UINT64_CONST(x) (x##ULL)
  15. #define WDL_INT64_CONST(x) (x##LL)
  16. #endif
  17. #if !defined(_MSC_VER) || _MSC_VER > 1200
  18. #define WDL_DLGRET INT_PTR CALLBACK
  19. #else
  20. #define WDL_DLGRET BOOL CALLBACK
  21. #endif
  22. #ifdef _WIN32
  23. #include <windows.h>
  24. #else
  25. #include <stdint.h>
  26. typedef intptr_t INT_PTR;
  27. typedef uintptr_t UINT_PTR;
  28. #endif
  29. #if defined(__ppc__) || !defined(__cplusplus)
  30. typedef char WDL_bool;
  31. #else
  32. typedef bool WDL_bool;
  33. #endif
  34. #ifndef GWLP_USERDATA
  35. #define GWLP_USERDATA GWL_USERDATA
  36. #define GWLP_WNDPROC GWL_WNDPROC
  37. #define GWLP_HINSTANCE GWL_HINSTANCE
  38. #define GWLP_HWNDPARENT GWL_HWNDPARENT
  39. #define DWLP_USER DWL_USER
  40. #define DWLP_DLGPROC DWL_DLGPROC
  41. #define DWLP_MSGRESULT DWL_MSGRESULT
  42. #define SetWindowLongPtr(a,b,c) SetWindowLong(a,b,c)
  43. #define GetWindowLongPtr(a,b) GetWindowLong(a,b)
  44. #define SetWindowLongPtrW(a,b,c) SetWindowLongW(a,b,c)
  45. #define GetWindowLongPtrW(a,b) GetWindowLongW(a,b)
  46. #define SetWindowLongPtrA(a,b,c) SetWindowLongA(a,b,c)
  47. #define GetWindowLongPtrA(a,b) GetWindowLongA(a,b)
  48. #define GCLP_WNDPROC GCL_WNDPROC
  49. #define GCLP_HICON GCL_HICON
  50. #define GCLP_HICONSM GCL_HICONSM
  51. #define SetClassLongPtr(a,b,c) SetClassLong(a,b,c)
  52. #define GetClassLongPtr(a,b) GetClassLong(a,b)
  53. #endif
  54. #ifdef __GNUC__
  55. // for structures that contain doubles, or doubles in structures that are after stuff of questionable alignment (for OSX/linux)
  56. #define WDL_FIXALIGN __attribute__ ((aligned (8)))
  57. // usage: void func(int a, const char *fmt, ...) WDL_VARARG_WARN(printf,2,3); // note: if member function, this pointer is counted as well, so as member function that would be 3,4
  58. #define WDL_VARARG_WARN(x,n,s) __attribute__ ((format (x,n,s)))
  59. #define WDL_STATICFUNC_UNUSED __attribute__((unused))
  60. #else
  61. #define WDL_FIXALIGN
  62. #define WDL_VARARG_WARN(x,n,s)
  63. #define WDL_STATICFUNC_UNUSED
  64. #endif
  65. #ifndef WDL_WANT_NEW_EXCEPTIONS
  66. #if defined(__cplusplus)
  67. #include <new>
  68. #define WDL_NEW (std::nothrow)
  69. #endif
  70. #else
  71. #define WDL_NEW
  72. #endif
  73. #if !defined(max) && defined(WDL_DEFINE_MINMAX)
  74. #define max(x,y) ((x)<(y)?(y):(x))
  75. #define min(x,y) ((x)<(y)?(x):(y))
  76. #endif
  77. #ifndef wdl_max
  78. #define wdl_max(x,y) ((x)<(y)?(y):(x))
  79. #define wdl_min(x,y) ((x)<(y)?(x):(y))
  80. #define wdl_abs(x) ((x)<0 ? -(x) : (x))
  81. #endif
  82. #ifndef _WIN32
  83. #ifndef strnicmp
  84. #define strnicmp(x,y,z) strncasecmp(x,y,z)
  85. #endif
  86. #ifndef stricmp
  87. #define stricmp(x,y) strcasecmp(x,y)
  88. #endif
  89. #endif
  90. #ifdef WDL_BACKSLASHES_ARE_ORDINARY
  91. #define WDL_IS_DIRCHAR(x) ((x) == '/')
  92. #else
  93. // for multi-platform applications it seems better to treat backslashes as directory separators even if it
  94. // isn't supported by the underying system (for resolving filenames, etc)
  95. #ifdef _WIN32
  96. #define WDL_IS_DIRCHAR(x) ((x) == '\\' || (x) == '/')
  97. #else
  98. #define WDL_IS_DIRCHAR(x) ((x) == '/' || (x) == '\\')
  99. #endif
  100. #endif
  101. #if defined(_WIN32) && !defined(WDL_BACKSLASHES_ARE_ORDINARY)
  102. #define WDL_DIRCHAR '\\'
  103. #define WDL_DIRCHAR_STR "\\"
  104. #else
  105. #define WDL_DIRCHAR '/'
  106. #define WDL_DIRCHAR_STR "/"
  107. #endif
  108. #if defined(_WIN32) || defined(__APPLE__)
  109. // on __APPLE__ we should ideally check the filesystem for case-sensitivity, assuming a case-insensitive-only match
  110. #define wdl_filename_cmp(x,y) stricmp(x,y)
  111. #define wdl_filename_cmpn(x,y,n) strnicmp(x,y,n)
  112. #else
  113. #define wdl_filename_cmp(x,y) strcmp(x,y)
  114. #define wdl_filename_cmpn(x,y,n) strncmp(x,y,n)
  115. #endif
  116. #if defined(__GNUC__) || defined(__INTEL_COMPILER)
  117. #define WDL_likely(x) (__builtin_expect(!!(x),1))
  118. #define WDL_unlikely(x) (__builtin_expect(!!(x),0))
  119. #else
  120. #define WDL_likely(x) (!!(x))
  121. #define WDL_unlikely(x) (!!(x))
  122. #endif
  123. #if defined(_DEBUG) || defined(DEBUG)
  124. #include <assert.h>
  125. #define WDL_ASSERT(x) assert(x)
  126. #define WDL_NORMALLY(x) (assert(x),1)
  127. #define WDL_NOT_NORMALLY(x) (assert(!(x)),0)
  128. #else
  129. #define WDL_ASSERT(x)
  130. #define WDL_NORMALLY(x) WDL_likely(x)
  131. #define WDL_NOT_NORMALLY(x) WDL_unlikely(x)
  132. #endif
  133. #endif