Merge pull request #113 from tesselode/fix-multi-targets
[wdl/wdl-ol.git] / WDL / wdltypes.h
blobb839094d57f5ce50414bb2bacc7b7cf7a480bf2c
1 #ifndef _WDLTYPES_
2 #define _WDLTYPES_
4 #ifdef _MSC_VER
6 typedef __int64 WDL_INT64;
7 typedef unsigned __int64 WDL_UINT64;
9 #else
11 typedef long long WDL_INT64;
12 typedef unsigned long long WDL_UINT64;
14 #endif
16 #ifdef _MSC_VER
17 #define WDL_UINT64_CONST(x) (x##ui64)
18 #define WDL_INT64_CONST(x) (x##i64)
19 #else
20 #define WDL_UINT64_CONST(x) (x##ULL)
21 #define WDL_INT64_CONST(x) (x##LL)
22 #endif
25 #if !defined(_MSC_VER) || _MSC_VER > 1200
26 #define WDL_DLGRET INT_PTR CALLBACK
27 #else
28 #define WDL_DLGRET BOOL CALLBACK
29 #endif
32 #ifdef _WIN32
33 #include <windows.h>
34 #else
35 #include <stdint.h>
36 typedef intptr_t INT_PTR;
37 typedef uintptr_t UINT_PTR;
38 #endif
40 #if defined(__ppc__) || !defined(__cplusplus)
41 typedef char WDL_bool;
42 #else
43 typedef bool WDL_bool;
44 #endif
46 #ifndef GWLP_USERDATA
47 #define GWLP_USERDATA GWL_USERDATA
48 #define GWLP_WNDPROC GWL_WNDPROC
49 #define GWLP_HINSTANCE GWL_HINSTANCE
50 #define GWLP_HWNDPARENT GWL_HWNDPARENT
51 #define DWLP_USER DWL_USER
52 #define DWLP_DLGPROC DWL_DLGPROC
53 #define DWLP_MSGRESULT DWL_MSGRESULT
54 #define SetWindowLongPtr(a,b,c) SetWindowLong(a,b,c)
55 #define GetWindowLongPtr(a,b) GetWindowLong(a,b)
56 #define SetWindowLongPtrW(a,b,c) SetWindowLongW(a,b,c)
57 #define GetWindowLongPtrW(a,b) GetWindowLongW(a,b)
58 #define SetWindowLongPtrA(a,b,c) SetWindowLongA(a,b,c)
59 #define GetWindowLongPtrA(a,b) GetWindowLongA(a,b)
61 #define GCLP_WNDPROC GCL_WNDPROC
62 #define GCLP_HICON GCL_HICON
63 #define GCLP_HICONSM GCL_HICONSM
64 #define SetClassLongPtr(a,b,c) SetClassLong(a,b,c)
65 #define GetClassLongPtr(a,b) GetClassLong(a,b)
66 #endif
69 #ifdef __GNUC__
70 // for structures that contain doubles, or doubles in structures that are after stuff of questionable alignment (for OSX/linux)
71 #define WDL_FIXALIGN __attribute__ ((aligned (8)))
72 // 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
73 #define WDL_VARARG_WARN(x,n,s) __attribute__ ((format (x,n,s)))
74 #define WDL_STATICFUNC_UNUSED __attribute__((unused))
76 #else
77 #define WDL_FIXALIGN
78 #define WDL_VARARG_WARN(x,n,s)
79 #define WDL_STATICFUNC_UNUSED
80 #endif
82 #ifndef WDL_WANT_NEW_EXCEPTIONS
83 #if defined(__cplusplus)
84 #include <new>
85 #define WDL_NEW (std::nothrow)
86 #endif
87 #else
88 #define WDL_NEW
89 #endif
92 #if !defined(max) && defined(WDL_DEFINE_MINMAX)
93 #define max(x,y) ((x)<(y)?(y):(x))
94 #define min(x,y) ((x)<(y)?(x):(y))
95 #endif
97 #ifndef wdl_max
98 #define wdl_max(x,y) ((x)<(y)?(y):(x))
99 #define wdl_min(x,y) ((x)<(y)?(x):(y))
100 #define wdl_abs(x) ((x)<0 ? -(x) : (x))
101 #endif
103 #ifndef _WIN32
104 #ifndef strnicmp
105 #define strnicmp(x,y,z) strncasecmp(x,y,z)
106 #endif
107 #ifndef stricmp
108 #define stricmp(x,y) strcasecmp(x,y)
109 #endif
110 #endif
112 #ifdef WDL_BACKSLASHES_ARE_ORDINARY
113 #define WDL_IS_DIRCHAR(x) ((x) == '/')
114 #else
115 // for multi-platform applications it seems better to treat backslashes as directory separators even if it
116 // isn't supported by the underying system (for resolving filenames, etc)
117 #ifdef _WIN32
118 #define WDL_IS_DIRCHAR(x) ((x) == '\\' || (x) == '/')
119 #else
120 #define WDL_IS_DIRCHAR(x) ((x) == '/' || (x) == '\\')
121 #endif
122 #endif
124 #if defined(_WIN32) && !defined(WDL_BACKSLASHES_ARE_ORDINARY)
125 #define WDL_DIRCHAR '\\'
126 #define WDL_DIRCHAR_STR "\\"
127 #else
128 #define WDL_DIRCHAR '/'
129 #define WDL_DIRCHAR_STR "/"
130 #endif
132 #if defined(_WIN32) || defined(__APPLE__)
133 // on __APPLE__ we should ideally check the filesystem for case-sensitivity, assuming a case-insensitive-only match
134 #define wdl_filename_cmp(x,y) stricmp(x,y)
135 #define wdl_filename_cmpn(x,y,n) strnicmp(x,y,n)
136 #else
137 #define wdl_filename_cmp(x,y) strcmp(x,y)
138 #define wdl_filename_cmpn(x,y,n) strncmp(x,y,n)
139 #endif
141 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
142 #define WDL_likely(x) (__builtin_expect(!!(x),1))
143 #define WDL_unlikely(x) (__builtin_expect(!!(x),0))
144 #else
145 #define WDL_likely(x) (!!(x))
146 #define WDL_unlikely(x) (!!(x))
147 #endif
149 #if defined(_DEBUG) || defined(DEBUG)
150 #include <assert.h>
151 #define WDL_ASSERT(x) assert(x)
152 #define WDL_NORMALLY(x) (assert(x),1)
153 #define WDL_NOT_NORMALLY(x) (assert(!(x)),0)
154 #else
155 #define WDL_ASSERT(x)
156 #define WDL_NORMALLY(x) WDL_likely(x)
157 #define WDL_NOT_NORMALLY(x) WDL_unlikely(x)
158 #endif
160 #endif