]> git.tdb.fi Git - ext/openal.git/blob - examples/common/alhelpers.h
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / examples / common / alhelpers.h
1 #ifndef ALHELPERS_H
2 #define ALHELPERS_H
3
4 #include "AL/al.h"
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 /* Some helper functions to get the name from the format enums. */
11 const char *FormatName(ALenum type);
12
13 /* Easy device init/deinit functions. InitAL returns 0 on success. */
14 int InitAL(char ***argv, int *argc);
15 void CloseAL(void);
16
17 /* Cross-platform timeget and sleep functions. */
18 int altime_get(void);
19 void al_nssleep(unsigned long nsec);
20
21 /* C doesn't allow casting between function and non-function pointer types, so
22  * with C99 we need to use a union to reinterpret the pointer type. Pre-C99
23  * still needs to use a normal cast and live with the warning (C++ is fine with
24  * a regular reinterpret_cast).
25  */
26 #if __STDC_VERSION__ >= 199901L
27 #define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f
28 #elif defined(__cplusplus)
29 #define FUNCTION_CAST(T, ptr) reinterpret_cast<T>(ptr)
30 #else
31 #define FUNCTION_CAST(T, ptr) (T)(ptr)
32 #endif
33
34 #ifdef __cplusplus
35 } // extern "C"
36 #endif
37
38 #endif /* ALHELPERS_H */