flext  0.6.0
flprefix.h
Go to the documentation of this file.
1 /*
2 flext - C++ layer for Max and Pure Data externals
3 
4 Copyright (c) 2001-2015 Thomas Grill (gr@grrrr.org)
5 For information on usage and redistribution, and for a DISCLAIMER OF ALL
6 WARRANTIES, see the file, "license.txt," in this distribution.
7 */
8 
13 #ifndef __FLEXT_PREFIX_H
14 #define __FLEXT_PREFIX_H
15 
16 // --- definitions for FLEXT_SYS ---------------------
17 #define FLEXT_SYS_UNKNOWN 0
18 
19 #ifndef FLEXT_SYS_MAX
20  #define FLEXT_SYS_MAX 1
21 #else
22  // already defined
23  #undef FLEXT_SYS_MAX
24  #define FLEXT_SYS_MAX 1
25  #define FLEXT_SYS FLEXT_SYS_MAX
26 #endif
27 
28 #ifndef FLEXT_SYS_PD
29  #define FLEXT_SYS_PD 2
30 #else
31  // already defined
32  #undef FLEXT_SYS_PD
33  #define FLEXT_SYS_PD 2
34  #define FLEXT_SYS FLEXT_SYS_PD
35 #endif
36 
37 #ifndef FLEXT_SYS_JMAX
38  #define FLEXT_SYS_JMAX 3
39 #else
40  // already defined
41  #undef FLEXT_SYS_JMAX
42  #define FLEXT_SYS_JMAX 3
43  #define FLEXT_SYS FLEXT_SYS_JMAX
44 #endif
45 
46 // --- definitions for FLEXT_OS ----------------------
47 #define FLEXT_OS_UNKNOWN 0
48 #define FLEXT_OS_WIN 1
49 #define FLEXT_OS_MAC 2
50 #define FLEXT_OS_LINUX 3
51 #define FLEXT_OS_IRIX 4
52 
53 // --- definitions for FLEXT_OS_API ---------------------
54 #define FLEXT_OSAPI_UNKNOWN 0
55 
56 #define FLEXT_OSAPI_UNIX_POSIX 1
57 
58 #define FLEXT_OSAPI_MAC_CLASSIC 2
59 #define FLEXT_OSAPI_MAC_CARBON 3
60 #define FLEXT_OSAPI_MAC_MACH 4
61 
62 #define FLEXT_OSAPI_WIN_NATIVE 5 // WIN32 Platform
63 #define FLEXT_OSAPI_WIN_POSIX 6 // POSIX API (e.g. cygwin)
64 
65 // --- definitions for FLEXT_CPU ---------------------
66 #define FLEXT_CPU_UNKNOWN 0
67 #define FLEXT_CPU_IA32 1
68 #define FLEXT_CPU_PPC 2
69 #define FLEXT_CPU_MIPS 3
70 #define FLEXT_CPU_ALPHA 4
71 
72 #define FLEXT_CPU_IA64 5 // Itanium
73 #define FLEXT_CPU_X86_64 6 // AMD-K8, EMT64
74 #define FLEXT_CPU_PPC64 7 // G5 in 64 bit mode
75 
76 // compatibility
77 #define FLEXT_CPU_INTEL FLEXT_CPU_IA32
78 
79 // --- definitions for FLEXT_THREADS -----------------
80 #define FLEXT_THR_POSIX 1 // pthreads
81 #define FLEXT_THR_WIN32 2 // Win32 native
82 #define FLEXT_THR_MP 3 // MacOS MPThreads
83 
84 // ---------------------------------------------------
85 // support old definitions
86 
87 #ifndef FLEXT_SYS
88  #if defined(MAXMSP)
89  #define FLEXT_SYS FLEXT_SYS_MAX
90  // #undef MAXMSP
91  #elif defined(PD)
92  #define FLEXT_SYS FLEXT_SYS_PD
93  // #undef PD
94  // #undef NT
95  #endif
96 #endif
97 
98 #if defined(_DEBUG) && !defined(FLEXT_DEBUG)
99  #define FLEXT_DEBUG
100 #endif
101 
102 // ---------------------------------------------------
103 
104 // Definition of supported real-time systems
105 #if FLEXT_SYS == FLEXT_SYS_MAX || FLEXT_SYS == FLEXT_SYS_PD
106 #else
107  #error "System must be defined by either FLEXT_SYS_MAX or FLEXT_SYS_PD"
108 #endif
109 
110 // Definition of OS/CPU
111 #if defined(_MSC_VER) || (defined(__ICC) && (FLEXT_OS == FLEXT_OS_WIN || defined(_WIN32)))
112  // Microsoft C++
113  // and Intel C++ (as guessed)
114 
115  #ifndef FLEXT_CPU
116  #if defined(_M_AMD64)
117  #define FLEXT_CPU FLEXT_CPU_X86_64
118  #elif defined(_M_IA64)
119  #define FLEXT_CPU FLEXT_CPU_IA64
120  #elif defined(_M_IX86)
121  #define FLEXT_CPU FLEXT_CPU_IA32
122  #elif defined(_M_PPC)
123  #define FLEXT_CPU FLEXT_CPU_PPC
124  #elif defined(_M_MRX000)
125  #define FLEXT_CPU FLEXT_CPU_MIPS
126  #elif defined(_M_ALPHA)
127  #define FLEXT_CPU FLEXT_CPU_ALPHA
128  #else
129  #define FLEXT_CPU FLEXT_CPU_UNKNOWN
130  #endif
131  #endif
132 
133  #ifndef FLEXT_OS
134  #if defined(_WIN32) || defined(_WIN64)
135  #define FLEXT_OS FLEXT_OS_WIN
136  #define FLEXT_OSAPI FLEXT_OSAPI_WIN_NATIVE
137  #else
138  #define FLEXT_OS FLEXT_OS_UNKNOWN
139  #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
140  #endif
141  #endif
142 
143 
144 #elif defined(__BORLANDC__)
145  // Borland C++
146 
147  #ifndef FLEXT_CPU
148  #define FLEXT_CPU FLEXT_CPU_INTEL
149  #endif
150  #ifndef FLEXT_OS
151  #define FLEXT_OS FLEXT_OS_WIN
152  #define FLEXT_OSAPI FLEXT_OSAPI_WIN_NATIVE
153  #else
154  #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
155  #endif
156 
157 
158 #elif defined(__MWERKS__)
159  // Metrowerks CodeWarrior
160 
161  #ifdef __MACH__
162  // quick fix for OSX Mach-O
163  #ifdef __POWERPC__
164  #ifdef __LP64__
165  #define TARGET_CPU_PPC64 1
166  #else
167  #define TARGET_CPU_PPC 1
168  #endif
169  #else
170  #ifdef __LP64__
171  #define TARGET_CPU_X86_64 1
172  #else
173  #define TARGET_CPU_IA32 1
174  #endif
175  #endif
176  #define TARGET_OS_MAC 1
177  #define TARGET_API_MAC_OSX 1
178  #else
179  #ifndef __CONDITIONALMACROS__
180  #include <ConditionalMacros.h>
181  #endif
182  #endif
183 
184  #ifndef FLEXT_CPU
185  #if TARGET_CPU_X86_64
186  #define FLEXT_CPU FLEXT_CPU_X86_64
187  #elif TARGET_CPU_X86
188  #define FLEXT_CPU FLEXT_CPU_IA32
189  #elif TARGET_CPU_PPC64
190  #define FLEXT_CPU FLEXT_CPU_PPC64
191  #elif TARGET_CPU_PPC
192  #define FLEXT_CPU FLEXT_CPU_PPC
193  #elif TARGET_CPU_MIPS
194  #define FLEXT_CPU FLEXT_CPU_MIPS
195  #elif TARGET_CPU_ALPHA
196  #define FLEXT_CPU FLEXT_CPU_ALPHA
197  #else
198  #define FLEXT_CPU FLEXT_CPU_UNKNOWN
199  #endif
200  #endif
201 
202  #ifndef FLEXT_OS
203  #if TARGET_OS_MAC
204  #define FLEXT_OS FLEXT_OS_MAC
205  #elif TARGET_OS_WIN32
206  // assume Windows
207  #define FLEXT_OS FLEXT_OS_WIN
208  #else
209  #define FLEXT_OS FLEXT_OS_UNKNOWN
210  #endif
211  #endif
212 
213  #ifndef FLEXT_OSAPI
214  #if TARGET_API_MAC_MACH
215  // this is for Mach-O
216  // this has the precedence (MACH also supports Carbon, of course)
217  #define FLEXT_OSAPI FLEXT_OSAPI_MAC_MACH
218  #elif TARGET_API_MAC_CARBON
219  // this is for CFM
220  #define FLEXT_OSAPI FLEXT_OSAPI_MAC_CARBON
221  #else
222  #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
223  #endif
224  #endif
225 
226  // This is important for method and attribute callbacks
227  #pragma enumsalwaysint on
228  // This is important for everything
229  #pragma bool on
230 
231 #elif defined(__GNUG__) || (defined(__ICC) && (FLEXT_OS == FLEXT_OS_LINUX || defined(linux) || defined(__linux__)))
232 
233  // GNU C++
234  // and Intel (as suggested by Tim Blechmann)
235 
236  #ifndef FLEXT_CPU
237  #if defined(__x86_64__)
238  #define FLEXT_CPU FLEXT_CPU_X86_64
239  #elif defined(_X86_) || defined(__i386__) || defined(__i586__) || defined(__i686__)
240  #define FLEXT_CPU FLEXT_CPU_IA32
241  #elif defined(__ppc64__)
242  #define FLEXT_CPU FLEXT_CPU_PPC64
243  #elif defined(__ppc__)
244  #define FLEXT_CPU FLEXT_CPU_PPC
245  #elif defined(__MIPS__)
246  #define FLEXT_CPU FLEXT_CPU_MIPS
247  #else
248  #define FLEXT_CPU FLEXT_CPU_UNKNOWN
249  #endif
250  #endif
251 
252  #ifndef FLEXT_OS
253  #if defined(linux) || defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
254  #define FLEXT_OS FLEXT_OS_LINUX
255  #elif defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(__MINGW32__)
256  #define FLEXT_OS FLEXT_OS_WIN
257  #elif defined(__APPLE__) && defined(__MACH__)
258  #define FLEXT_OS FLEXT_OS_MAC
259  // how about IRIX??
260  #else
261  #define FLEXT_OS FLEXT_OS_UNKNOWN
262  #endif
263  #endif
264 
265  #ifndef FLEXT_OSAPI
266  #if FLEXT_OS == FLEXT_OS_MAC
267  #define FLEXT_OSAPI FLEXT_OSAPI_MAC_MACH
268  #elif FLEXT_OS == FLEXT_OS_WIN
269  #if defined(__MINGW32__)
270  #define FLEXT_OSAPI FLEXT_OSAPI_WIN_NATIVE
271  #else
272  #define FLEXT_OSAPI FLEXT_OSAPI_WIN_POSIX
273  #endif
274  #elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX
275  #define FLEXT_OSAPI FLEXT_OSAPI_UNIX_POSIX
276  #else
277  #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
278  #endif
279  #endif
280 
281 #elif defined(__MRC__) && defined(MPW_CPLUS)
282  // Apple MPW MrCpp
283 
284  #if __MRC__ < 0x500
285  #error Apple MPW MrCpp v.5.0.0 or later compiler required
286  #endif
287 
288  #ifndef FLEXT_CPU
289  #if defined(__POWERPC__)
290  #define FLEXT_CPU FLEXT_CPU_PPC
291  #else
292  #define FLEXT_CPU FLEXT_CPU_UNKNOWN
293  #endif
294  #endif
295 
296  #ifndef FLEXT_OS
297  #if defined(macintosh)
298  #define FLEXT_OS FLEXT_OS_MAC
299  #else
300  #define FLEXT_OS FLEXT_OS_UNKNOWN
301  #endif
302  #endif
303 
304  #ifndef FLEXT_OSAPI
305  #if FLEXT_OS == FLEXT_OS_MAC
306  #define FLEXT_OSAPI FLEXT_OSAPI_MAC_CLASSIC
307  #else
308  #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
309  #endif
310  #endif
311 #endif
312 
313 
314 
315 #if FLEXT_OS == FLEXT_OS_WIN
316 // #pragma message("Compiling for Windows")
317 
318  #if FLEXT_SYS == FLEXT_SYS_MAX
319 // #define WIN_VERSION 1
320  #elif FLEXT_SYS == FLEXT_SYS_PD
321 // #define PD
322 // #define NT
323  #endif
324 #elif FLEXT_OS == FLEXT_OS_LINUX
325 // #pragma message("Compiling for Linux")
326 
327  #if FLEXT_SYS == FLEXT_SYS_PD
328 // #define PD
329  #else
330  #error "Flext SYS/OS combination unknown"
331  #endif
332 #elif FLEXT_OS == FLEXT_OS_IRIX
333 // #pragma message("Compiling for Irix")
334 
335  #if FLEXT_SYS == FLEXT_SYS_PD
336 // #define PD
337  #else
338  #error "Flext SYS/OS combination unknown"
339  #endif
340 #elif FLEXT_OS == FLEXT_OS_MAC
341 // #pragma message("Compiling for MacOS")
342 
343  #if FLEXT_SYS == FLEXT_SYS_PD
344 // #define PD
345  #endif
346 #else
347  #error "Operating system could not be determined"
348 #endif
349 
350 #if FLEXT_SYS == FLEXT_SYS_MAX
351 // #pragma message("Compiling for Max/MSP")
352 #elif FLEXT_SYS == FLEXT_SYS_PD
353 // #pragma message("Compiling for PD")
354 #endif
355 
356 // ----- set threading model -----
357 // shared builds are always threaded
358 #ifdef FLEXT_SHARED
359  #undef FLEXT_THREADS
360  #define FLEXT_THREADS
361 #endif
362 
363 #ifdef FLEXT_THREADS
364  #undef FLEXT_THREADS
365  #if FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_MAC && FLEXT_OSAPI != FLEXT_OSAPI_MAC_MACH
366  // Max for CFM doesn't like posix threads
367  #define FLEXT_THREADS FLEXT_THR_MP
368  #elif FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_WIN
369  // for wmax use native Windows threads
370  #define FLEXT_THREADS FLEXT_THR_WIN32
371  #else
372  #define FLEXT_THREADS FLEXT_THR_POSIX
373  #endif
374 #endif
375 
376 // ----- macros for class names -----
377 /*
378  With linux (flat linker namespace) and more than one flext-based external loaded all calls to static
379  exported functions refer to the first instance loaded!
380  Therefore different class names are used so that the correct type of flext function is called.
381 */
382 #ifdef __DOXYGEN__
383  #define FLEXT_CLASSDEF(CL) CL
384 #elif defined(FLEXT_DEBUG)
385  #if defined(FLEXT_SHARED)
386  #define FLEXT_CLASSDEF(CL) CL##_shared_d
387  #elif defined(FLEXT_THREADS)
388  #define FLEXT_CLASSDEF(CL) CL##_multi_d
389  #else
390  #define FLEXT_CLASSDEF(CL) CL##_single_d
391  #endif
392 #else
393  #if defined(FLEXT_SHARED)
394  #define FLEXT_CLASSDEF(CL) CL##_shared
395  #elif defined(FLEXT_THREADS)
396  #define FLEXT_CLASSDEF(CL) CL##_multi
397  #else
398  #define FLEXT_CLASSDEF(CL) CL##_single
399  #endif
400 #endif
401 
402 
403 /* Set the right calling convention (and exporting) for the OS */
404 
405 #if defined(_MSC_VER)
406  #ifdef FLEXT_SHARED
407  // for compiling a shared flext library FLEXT_EXPORTS must be defined
408  #ifdef FLEXT_EXPORTS
409  #define FLEXT_SHARE __declspec(dllexport)
410  #else
411  #define FLEXT_SHARE __declspec(dllimport)
412  #endif
413  #else
414  #define FLEXT_SHARE
415  #endif
416  #define FLEXT_EXT __declspec(dllexport)
417 #else // other OS's
418  #define FLEXT_SHARE
419  #define FLEXT_EXT
420 #endif
421 
422 
423 // std namespace
424 #ifdef __MWERKS__
425 # define STD std
426 #else
427 # define STD
428 #endif
429 
430 // branching hints
431 #if __GNUC__ >= 3
432 # ifndef LIKELY
433 # define LIKELY(expression) (__builtin_expect(!!(expression), 1))
434 # endif
435 # ifndef UNLIKELY
436 # define UNLIKELY(expression) (__builtin_expect(!!(expression), 0))
437 # endif
438 #else
439 # ifndef LIKELY
440 # define LIKELY(expression) (expression)
441 # endif
442 # ifndef UNLIKELY
443 # define UNLIKELY(expression) (expression)
444 # endif
445 #endif
446 
447 // macro definitions for inline flext usage
448 #ifdef FLEXT_INLINE
449 # define FLEXT_TEMPLATE template<typename flext_T>
450 # define FLEXT_TEMPIMPL(fun) template<typename flext_T> fun<flext_T>
451 # define FLEXT_TEMPINST(fun) fun<void>
452 # define FLEXT_TEMPSUB(fun) typename fun<flext_T>
453 # define FLEXT_TEMP_TYPENAME typename
454 #else
455 # define FLEXT_TEMPLATE
456 # define FLEXT_TEMPIMPL(fun) fun
457 # define FLEXT_TEMPINST(fun) fun
458 # define FLEXT_TEMPSUB(fun) fun
459 # define FLEXT_TEMP_TYPENAME
460 #endif
461 
462 #endif // __FLEXT_PREFIX_H