1#ifndef SDL3PP_CALLBACK_WRAPPER_H_
2#define SDL3PP_CALLBACK_WRAPPER_H_
7#include <SDL3/SDL_assert.h>
32template<
class Result,
class... Args>
45 static Result
Call(
void* handle, Args... args)
47 auto& f = Unwrap(handle);
54 auto& f = Unwrap(handle);
72 static Result
CallOnce(
void* handle, Args... args)
74 auto f = release(handle);
81 auto f = release(handle);
94 if (handle ==
nullptr)
return {};
95 auto ptr =
static_cast<ValueType*
>(handle);
107template<
class SELF,
class R,
class... PARAMS>
120 static_assert(
sizeof(func) <=
sizeof(
data),
"Function must fit size_t");
126 wrapper = [](
void* userdata, PARAMS... params) {
127 PunAux aux{.ptr = userdata};
128 return SELF::doCall(aux.func, params...);
130 PunAux aux{.func = func};
140template<
class SELF,
class R,
class... PARAMS>
153 static_assert(
sizeof(func) <=
sizeof(
data),
"Function must fit size_t");
159 wrapper = [](PARAMS... params,
void* userdata) {
160 PunAux aux{.ptr = userdata};
161 return SELF::doCall(aux.func, params...);
163 PunAux aux{.func = func};
177template<
class R,
class... PARAMS>
182 template<std::invocable<PARAMS...> F>
189 template<std::invocable<PARAMS...> F>
190 static R doCall(F& func, PARAMS... params)
192 return func(params...);
205template<
class R,
class... PARAMS>
210 template<std::invocable<PARAMS...> F>
219 template<std::invocable<PARAMS...> F>
220 static R doCall(
const F& func, PARAMS... params)
222 return func(params...);
Main include header for the SDL3pp library.
static Result Call(void *handle, Args... args)
Call.
Definition: SDL3pp_callbackWrapper.h:45
static Result CallOnce(void *handle, Args... args)
Call once and release.
Definition: SDL3pp_callbackWrapper.h:72
static ValueType release(void *handle)
Transfer ownership from the function and delete handle.
Definition: SDL3pp_callbackWrapper.h:92
static Result CallOnceSuffixed(Args... args, void *handle)
Call once and release with suffix handle.
Definition: SDL3pp_callbackWrapper.h:79
static ValueType * Wrap(ValueType &&cb)
Change the callback into a void* pointer.
Definition: SDL3pp_callbackWrapper.h:66
static Result CallSuffixed(Args... args, void *handle)
Call with suffix handle.
Definition: SDL3pp_callbackWrapper.h:52
static const ValueType & Unwrap(void *handle)
Return unwrapped value of handle.
Definition: SDL3pp_callbackWrapper.h:39
std::function< Result(Args...)> ValueType
The wrapped std::function type.
Definition: SDL3pp_callbackWrapper.h:36
Definition: SDL3pp_callbackWrapper.h:20
Lightweight wrapper.
Definition: SDL3pp_callbackWrapper.h:109
void * data
The wrapped data.
Definition: SDL3pp_callbackWrapper.h:114
LightweightCallbackT(const F &func)
ctor
Definition: SDL3pp_callbackWrapper.h:118
R(* wrapper)(void *, PARAMS...)
The wrapper function.
Definition: SDL3pp_callbackWrapper.h:111
Lightweight wrapper.
Definition: SDL3pp_callbackWrapper.h:142
R(* wrapper)(PARAMS..., void *)
The wrapper function.
Definition: SDL3pp_callbackWrapper.h:144
void * data
The wrapped data.
Definition: SDL3pp_callbackWrapper.h:147
LightweightTrailingCallbackT(const F &func)
ctor
Definition: SDL3pp_callbackWrapper.h:151
MakeBackCallback(const F &func)
ctor
Definition: SDL3pp_callbackWrapper.h:211
Definition: SDL3pp_callbackWrapper.h:197
MakeFrontCallback(const F &func)
ctor
Definition: SDL3pp_callbackWrapper.h:183
Definition: SDL3pp_callbackWrapper.h:169