Check for unsigned underflow
[openal-soft.git] / al / direct_defs.h
blob4119182f01585c832b83f26da72f308449a41183
1 #ifndef AL_DIRECT_DEFS_H
2 #define AL_DIRECT_DEFS_H
4 namespace detail_ {
6 template<typename T>
7 constexpr T DefaultVal() noexcept { return T{}; }
9 template<>
10 constexpr void DefaultVal() noexcept { }
12 } // namespace detail_
14 #define DECL_FUNC(R, Name) \
15 auto AL_APIENTRY Name() noexcept -> R \
16 { \
17 auto context = GetContextRef(); \
18 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
19 return Name##Direct(context.get()); \
22 #define DECL_FUNC1(R, Name, T1,n1) \
23 auto AL_APIENTRY Name(T1 n1) noexcept -> R \
24 { \
25 auto context = GetContextRef(); \
26 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
27 return Name##Direct(context.get(), n1); \
30 #define DECL_FUNC2(R, Name, T1,n1, T2,n2) \
31 auto AL_APIENTRY Name(T1 n1, T2 n2) noexcept -> R \
32 { \
33 auto context = GetContextRef(); \
34 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
35 return Name##Direct(context.get(), n1, n2); \
38 #define DECL_FUNC3(R, Name, T1,n1, T2,n2, T3,n3) \
39 auto AL_APIENTRY Name(T1 n1, T2 n2, T3 n3) noexcept -> R \
40 { \
41 auto context = GetContextRef(); \
42 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
43 return Name##Direct(context.get(), n1, n2, n3); \
46 #define DECL_FUNC4(R, Name, T1,n1, T2,n2, T3,n3, T4,n4) \
47 auto AL_APIENTRY Name(T1 n1, T2 n2, T3 n3, T4 n4) noexcept -> R \
48 { \
49 auto context = GetContextRef(); \
50 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
51 return Name##Direct(context.get(), n1, n2, n3, n4); \
54 #define DECL_FUNC5(R, Name, T1,n1, T2,n2, T3,n3, T4,n4, T5,n5) \
55 auto AL_APIENTRY Name(T1 n1, T2 n2, T3 n3, T4 n4, T5 n5) noexcept -> R \
56 { \
57 auto context = GetContextRef(); \
58 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
59 return Name##Direct(context.get(), n1, n2, n3, n4, n5); \
63 #define DECL_FUNCEXT(R, Name,Ext) \
64 auto AL_APIENTRY Name##Ext() noexcept -> R \
65 { \
66 auto context = GetContextRef(); \
67 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
68 return Name##Direct##Ext(context.get()); \
71 #define DECL_FUNCEXT1(R, Name,Ext, T1,n1) \
72 auto AL_APIENTRY Name##Ext(T1 n1) noexcept -> R \
73 { \
74 auto context = GetContextRef(); \
75 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
76 return Name##Direct##Ext(context.get(), n1); \
79 #define DECL_FUNCEXT2(R, Name,Ext, T1,n1, T2,n2) \
80 auto AL_APIENTRY Name##Ext(T1 n1, T2 n2) noexcept -> R \
81 { \
82 auto context = GetContextRef(); \
83 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
84 return Name##Direct##Ext(context.get(), n1, n2); \
87 #define DECL_FUNCEXT3(R, Name,Ext, T1,n1, T2,n2, T3,n3) \
88 auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3) noexcept -> R \
89 { \
90 auto context = GetContextRef(); \
91 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
92 return Name##Direct##Ext(context.get(), n1, n2, n3); \
95 #define DECL_FUNCEXT4(R, Name,Ext, T1,n1, T2,n2, T3,n3, T4,n4) \
96 auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3, T4 n4) noexcept -> R \
97 { \
98 auto context = GetContextRef(); \
99 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
100 return Name##Direct##Ext(context.get(), n1, n2, n3, n4); \
103 #define DECL_FUNCEXT5(R, Name,Ext, T1,n1, T2,n2, T3,n3, T4,n4, T5,n5) \
104 auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3, T4 n4, T5 n5) noexcept -> R \
106 auto context = GetContextRef(); \
107 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
108 return Name##Direct##Ext(context.get(), n1, n2, n3, n4, n5); \
111 #define DECL_FUNCEXT6(R, Name,Ext, T1,n1, T2,n2, T3,n3, T4,n4, T5,n5, T6,n6) \
112 auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3, T4 n4, T5 n5, T6 n6) noexcept -> R \
114 auto context = GetContextRef(); \
115 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
116 return Name##Direct##Ext(context.get(), n1, n2, n3, n4, n5, n6); \
119 #define DECL_FUNCEXT8(R, Name,Ext, T1,n1, T2,n2, T3,n3, T4,n4, T5,n5, T6,n6, T7,n7, T8,n8) \
120 auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3, T4 n4, T5 n5, T6 n6, T7 n7, T8 n8) noexcept -> R \
122 auto context = GetContextRef(); \
123 if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
124 return Name##Direct##Ext(context.get(), n1, n2, n3, n4, n5, n6, n7, n8); \
127 #endif /* AL_DIRECT_DEFS_H */