direct_defs.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef AL_DIRECT_DEFS_H
  2. #define AL_DIRECT_DEFS_H
  3. namespace detail_ {
  4. template<typename T>
  5. constexpr T DefaultVal() noexcept { return T{}; }
  6. template<>
  7. constexpr void DefaultVal() noexcept { }
  8. } // namespace detail_
  9. #define DECL_FUNC(R, Name) \
  10. auto AL_APIENTRY Name() noexcept -> R \
  11. { \
  12. auto context = GetContextRef(); \
  13. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  14. return Name##Direct(context.get()); \
  15. }
  16. #define DECL_FUNC1(R, Name, T1,n1) \
  17. auto AL_APIENTRY Name(T1 n1) noexcept -> R \
  18. { \
  19. auto context = GetContextRef(); \
  20. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  21. return Name##Direct(context.get(), n1); \
  22. }
  23. #define DECL_FUNC2(R, Name, T1,n1, T2,n2) \
  24. auto AL_APIENTRY Name(T1 n1, T2 n2) noexcept -> R \
  25. { \
  26. auto context = GetContextRef(); \
  27. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  28. return Name##Direct(context.get(), n1, n2); \
  29. }
  30. #define DECL_FUNC3(R, Name, T1,n1, T2,n2, T3,n3) \
  31. auto AL_APIENTRY Name(T1 n1, T2 n2, T3 n3) noexcept -> R \
  32. { \
  33. auto context = GetContextRef(); \
  34. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  35. return Name##Direct(context.get(), n1, n2, n3); \
  36. }
  37. #define DECL_FUNC4(R, Name, T1,n1, T2,n2, T3,n3, T4,n4) \
  38. auto AL_APIENTRY Name(T1 n1, T2 n2, T3 n3, T4 n4) noexcept -> R \
  39. { \
  40. auto context = GetContextRef(); \
  41. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  42. return Name##Direct(context.get(), n1, n2, n3, n4); \
  43. }
  44. #define DECL_FUNC5(R, Name, T1,n1, T2,n2, T3,n3, T4,n4, T5,n5) \
  45. auto AL_APIENTRY Name(T1 n1, T2 n2, T3 n3, T4 n4, T5 n5) noexcept -> R \
  46. { \
  47. auto context = GetContextRef(); \
  48. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  49. return Name##Direct(context.get(), n1, n2, n3, n4, n5); \
  50. }
  51. #define DECL_FUNCEXT(R, Name,Ext) \
  52. auto AL_APIENTRY Name##Ext() noexcept -> R \
  53. { \
  54. auto context = GetContextRef(); \
  55. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  56. return Name##Direct##Ext(context.get()); \
  57. }
  58. #define DECL_FUNCEXT1(R, Name,Ext, T1,n1) \
  59. auto AL_APIENTRY Name##Ext(T1 n1) noexcept -> R \
  60. { \
  61. auto context = GetContextRef(); \
  62. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  63. return Name##Direct##Ext(context.get(), n1); \
  64. }
  65. #define DECL_FUNCEXT2(R, Name,Ext, T1,n1, T2,n2) \
  66. auto AL_APIENTRY Name##Ext(T1 n1, T2 n2) noexcept -> R \
  67. { \
  68. auto context = GetContextRef(); \
  69. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  70. return Name##Direct##Ext(context.get(), n1, n2); \
  71. }
  72. #define DECL_FUNCEXT3(R, Name,Ext, T1,n1, T2,n2, T3,n3) \
  73. auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3) noexcept -> R \
  74. { \
  75. auto context = GetContextRef(); \
  76. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  77. return Name##Direct##Ext(context.get(), n1, n2, n3); \
  78. }
  79. #define DECL_FUNCEXT4(R, Name,Ext, T1,n1, T2,n2, T3,n3, T4,n4) \
  80. auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3, T4 n4) noexcept -> R \
  81. { \
  82. auto context = GetContextRef(); \
  83. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  84. return Name##Direct##Ext(context.get(), n1, n2, n3, n4); \
  85. }
  86. #define DECL_FUNCEXT5(R, Name,Ext, T1,n1, T2,n2, T3,n3, T4,n4, T5,n5) \
  87. auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3, T4 n4, T5 n5) noexcept -> R \
  88. { \
  89. auto context = GetContextRef(); \
  90. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  91. return Name##Direct##Ext(context.get(), n1, n2, n3, n4, n5); \
  92. }
  93. #define DECL_FUNCEXT6(R, Name,Ext, T1,n1, T2,n2, T3,n3, T4,n4, T5,n5, T6,n6) \
  94. auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3, T4 n4, T5 n5, T6 n6) noexcept -> R \
  95. { \
  96. auto context = GetContextRef(); \
  97. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  98. return Name##Direct##Ext(context.get(), n1, n2, n3, n4, n5, n6); \
  99. }
  100. #define DECL_FUNCEXT8(R, Name,Ext, T1,n1, T2,n2, T3,n3, T4,n4, T5,n5, T6,n6, T7,n7, T8,n8) \
  101. auto AL_APIENTRY Name##Ext(T1 n1, T2 n2, T3 n3, T4 n4, T5 n5, T6 n6, T7 n7, T8 n8) noexcept -> R \
  102. { \
  103. auto context = GetContextRef(); \
  104. if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
  105. return Name##Direct##Ext(context.get(), n1, n2, n3, n4, n5, n6, n7, n8); \
  106. }
  107. #endif /* AL_DIRECT_DEFS_H */