LMMS
Loading...
Searching...
No Matches
wdltypes.h
Go to the documentation of this file.
1#ifndef _WDLTYPES_
2#define _WDLTYPES_
3
4#ifdef _MSC_VER
5
6typedef __int64 WDL_INT64;
7typedef unsigned __int64 WDL_UINT64;
8
9#else
10
11typedef long long WDL_INT64;
12typedef unsigned long long WDL_UINT64;
13
14#endif
15
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
23
24#ifdef _WIN32
25 #define WDL_PRI_UINT64 "I64u"
26 #define WDL_PRI_INT64 "I64d"
27#else
28 #define WDL_PRI_UINT64 "llu"
29 #define WDL_PRI_INT64 "lld"
30#endif
31
32#if !defined(_MSC_VER) || _MSC_VER > 1200
33#define WDL_DLGRET INT_PTR CALLBACK
34#else
35#define WDL_DLGRET BOOL CALLBACK
36#endif
37
38
39#ifdef _WIN32
40#include <windows.h>
41#include <stdio.h>
42#else
43#include <stdint.h>
44typedef intptr_t INT_PTR;
45typedef uintptr_t UINT_PTR;
46#endif
47
48#if defined(__ppc__) || !defined(__cplusplus)
49typedef char WDL_bool;
50#else
51typedef bool WDL_bool;
52#endif
53
54#ifndef GWLP_USERDATA
55#define GWLP_USERDATA GWL_USERDATA
56#define GWLP_WNDPROC GWL_WNDPROC
57#define GWLP_HINSTANCE GWL_HINSTANCE
58#define GWLP_HWNDPARENT GWL_HWNDPARENT
59#define DWLP_USER DWL_USER
60#define DWLP_DLGPROC DWL_DLGPROC
61#define DWLP_MSGRESULT DWL_MSGRESULT
62#define SetWindowLongPtr(a,b,c) SetWindowLong(a,b,c)
63#define GetWindowLongPtr(a,b) GetWindowLong(a,b)
64#define SetWindowLongPtrW(a,b,c) SetWindowLongW(a,b,c)
65#define GetWindowLongPtrW(a,b) GetWindowLongW(a,b)
66#define SetWindowLongPtrA(a,b,c) SetWindowLongA(a,b,c)
67#define GetWindowLongPtrA(a,b) GetWindowLongA(a,b)
68
69#define GCLP_WNDPROC GCL_WNDPROC
70#define GCLP_HICON GCL_HICON
71#define GCLP_HICONSM GCL_HICONSM
72#define SetClassLongPtr(a,b,c) SetClassLong(a,b,c)
73#define GetClassLongPtr(a,b) GetClassLong(a,b)
74#endif
75
76
77#ifdef __GNUC__
78// for structures that contain doubles, or doubles in structures that are after stuff of questionable alignment (for OSX/linux)
79 #define WDL_FIXALIGN __attribute__ ((aligned (8)))
80// 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
81 #define WDL_VARARG_WARN(x,n,s) __attribute__ ((format (x,n,s)))
82 #define WDL_STATICFUNC_UNUSED __attribute__((unused))
83
84#else
85 #define WDL_FIXALIGN
86 #define WDL_VARARG_WARN(x,n,s)
87 #define WDL_STATICFUNC_UNUSED
88#endif
89
90#ifndef WDL_WANT_NEW_EXCEPTIONS
91#if defined(__cplusplus)
92#include <new>
93#define WDL_NEW (std::nothrow)
94#endif
95#else
96#define WDL_NEW
97#endif
98
99
100#if !defined(max) && defined(WDL_DEFINE_MINMAX)
101#define max(x,y) ((x)<(y)?(y):(x))
102#define min(x,y) ((x)<(y)?(x):(y))
103#endif
104
105#ifndef wdl_max
106#define wdl_max(x,y) ((x)<(y)?(y):(x))
107#define wdl_min(x,y) ((x)<(y)?(x):(y))
108#define wdl_abs(x) ((x)<0 ? -(x) : (x))
109#define wdl_clamp(x,minv,maxv) ((x) < (minv) ? (minv) : ((x) > (maxv) ? (maxv) : (x)))
110#endif
111
112#ifndef _WIN32
113 #ifndef strnicmp
114 #define strnicmp(x,y,z) strncasecmp(x,y,z)
115 #endif
116 #ifndef stricmp
117 #define stricmp(x,y) strcasecmp(x,y)
118 #endif
119#endif
120
121#ifdef WDL_BACKSLASHES_ARE_ORDINARY
122#define WDL_IS_DIRCHAR(x) ((x) == '/')
123#else
124// for multi-platform applications it seems better to treat backslashes as directory separators even if it
125// isn't supported by the underying system (for resolving filenames, etc)
126 #ifdef _WIN32
127 #define WDL_IS_DIRCHAR(x) ((x) == '\\' || (x) == '/')
128 #else
129 #define WDL_IS_DIRCHAR(x) ((x) == '/' || (x) == '\\')
130 #endif
131#endif
132
133#if defined(_WIN32) && !defined(WDL_BACKSLASHES_ARE_ORDINARY)
134#define WDL_DIRCHAR '\\'
135#define WDL_DIRCHAR_STR "\\"
136#else
137#define WDL_DIRCHAR '/'
138#define WDL_DIRCHAR_STR "/"
139#endif
140
141#if defined(_WIN32) || defined(__APPLE__)
142 // on __APPLE__ we should ideally check the filesystem for case-sensitivity, assuming a case-insensitive-only match
143 #define wdl_filename_cmp(x,y) stricmp(x,y)
144 #define wdl_filename_cmpn(x,y,n) strnicmp(x,y,n)
145#else
146 #define wdl_filename_cmp(x,y) strcmp(x,y)
147 #define wdl_filename_cmpn(x,y,n) strncmp(x,y,n)
148#endif
149
150#if defined(__GNUC__) || defined(__INTEL_COMPILER)
151 #define WDL_likely(x) (__builtin_expect(!!(x),1))
152 #define WDL_unlikely(x) (__builtin_expect(!!(x),0))
153#else
154 #define WDL_likely(x) (!!(x))
155 #define WDL_unlikely(x) (!!(x))
156#endif
157
158#if defined(_DEBUG) || defined(DEBUG)
159#include <assert.h>
160#define WDL_ASSERT(x) assert(x)
161#define WDL_NORMALLY(x) (assert(x),1)
162#define WDL_NOT_NORMALLY(x) (assert(!(x)),0)
163#else
164#define WDL_ASSERT(x)
165#define WDL_NORMALLY(x) WDL_likely(x)
166#define WDL_NOT_NORMALLY(x) WDL_unlikely(x)
167#endif
168
169
170typedef unsigned int WDL_TICKTYPE;
171
172static WDL_bool WDL_STATICFUNC_UNUSED WDL_TICKS_IN_RANGE(WDL_TICKTYPE current, WDL_TICKTYPE refstart, int len) // current >= refstart && current < refstart+len
173{
174 WDL_ASSERT(len > 0);
175 return (current - refstart) < (WDL_TICKTYPE)len;
176}
177
178static WDL_bool WDL_STATICFUNC_UNUSED WDL_TICKS_IN_RANGE_ENDING_AT(WDL_TICKTYPE current, WDL_TICKTYPE refend, int len) // current >= refend-len && current < refend
179{
180 const WDL_TICKTYPE refstart = refend - len;
181 WDL_ASSERT(len > 0);
182 return (current - refstart) < (WDL_TICKTYPE)len;
183 //return ((refend-1) - current) < (WDL_TICKTYPE)len;
184}
185
186// use this if you want validate that nothing that includes wdltypes.h calls fopen() directly on win32
187// #define WDL_CHECK_FOR_NON_UTF8_FOPEN
188
189#if defined(WDL_CHECK_FOR_NON_UTF8_FOPEN) && !defined(_WDL_WIN32_UTF8_H_)
190 #ifdef fopen
191 #undef fopen
192 #endif
193 #include <stdio.h>
194 static WDL_STATICFUNC_UNUSED FILE *WDL_fopenA(const char *fn, const char *mode) { return fopen(fn,mode); }
195 #define fopen this_should_be_fopenUTF8_include_win32_utf8.h
196#else
197 // callers of WDL_fopenA don't mind being non-UTF8-compatible on win32
198 // (this could map to either fopen() or fopenUTF8()
199 #define WDL_fopenA(fn,mode) fopen(fn,mode)
200#endif
201
202#ifndef WDL_ALLOW_UNSIGNED_DEFAULT_CHAR
203typedef char wdl_assert_failed_unsigned_char[((char)-1) > 0 ? -1 : 1];
204#endif
205
206// wdl_log() / printf() wrapper. no-op on release builds
207#if !defined(_DEBUG) && !defined(WDL_LOG_ON_RELEASE)
208 static void WDL_STATICFUNC_UNUSED WDL_VARARG_WARN(printf,1,2) wdl_log(const char *format, ...) { }
209#elif defined(_WIN32)
210 static void WDL_STATICFUNC_UNUSED WDL_VARARG_WARN(printf,1,2) wdl_log(const char *format, ...)
211 {
212 int rv;
213 va_list va;
214
215 char tmp[3800];
216 va_start(va,format);
217 tmp[0]=0;
218 rv=_vsnprintf(tmp,sizeof(tmp),format,va); // returns -1 if over, and does not null terminate, ugh
219 va_end(va);
220
221 if (rv < 0 || rv>=(int)sizeof(tmp)-1) tmp[sizeof(tmp)-1]=0;
222 OutputDebugStringA(tmp);
223 }
224#else
225 #define wdl_log printf
226#endif
227
228#endif
png_structrp int mode
Definition png.h:1139
#define __int64
const char const char const char const char char * fn
Definition swell-functions.h:168
uintptr_t UINT_PTR
Definition swell-types.h:43
intptr_t INT_PTR
Definition swell-types.h:42
_WDL_CSTRING_PREFIX void INT_PTR const char * format
Definition wdlcstring.h:263
#define WDL_VARARG_WARN(x, n, s)
Definition wdltypes.h:86
long long WDL_INT64
Definition wdltypes.h:11
#define WDL_STATICFUNC_UNUSED
Definition wdltypes.h:87
unsigned long long WDL_UINT64
Definition wdltypes.h:12
#define WDL_fopenA(fn, mode)
Definition wdltypes.h:199
char wdl_assert_failed_unsigned_char[((char) -1) > 0 ? -1 :1]
Definition wdltypes.h:203
unsigned int WDL_TICKTYPE
Definition wdltypes.h:170
#define WDL_ASSERT(x)
Definition wdltypes.h:164
static WDL_bool WDL_STATICFUNC_UNUSED WDL_TICKS_IN_RANGE_ENDING_AT(WDL_TICKTYPE current, WDL_TICKTYPE refend, int len)
Definition wdltypes.h:178
static WDL_bool WDL_STATICFUNC_UNUSED WDL_TICKS_IN_RANGE(WDL_TICKTYPE current, WDL_TICKTYPE refstart, int len)
Definition wdltypes.h:172
char WDL_bool
Definition wdltypes.h:49
#define const
Definition zconf.h:137