Embedded Artistry Framework
Embedded Systems C++ Framework
Namespaces | Macros | Functions
bounce.hpp File Reference
This graph shows which files directly or indirectly include this file:

Namespaces

 embutil
 Embedded framework utility functions and classes.
 

Macros

#define BOUNCE(c, m)   embutil::bounce<c, decltype(&c::m), &c::m>
 Convenience macro to simplify bounce statement usage. More...
 

Functions

template<class TClass , class Method , Method m, class... Params>
static auto embutil::bounce (void *priv, Params... params) noexcept -> decltype(((*reinterpret_cast< TClass * >(priv)).*m)(params...))
 Enable a C++ member function to work with a C-style callback interface. More...
 

Macro Definition Documentation

◆ BOUNCE

#define BOUNCE (   c,
 
)    embutil::bounce<c, decltype(&c::m), &c::m>

Convenience macro to simplify bounce statement usage.

The BOUNCE() macro simplifies the creation of a bounce function to a class member for use with C-style callbacks. The BOUNCE() macro must be paried with a this pointer to get to the proper class instance.

Example usage with a C-style callback interface.

posixThread is a C++ class, and posixThread::thread_func() is a member function which we want to pass to pthread_create().

// Our interfaces demand a void(*)(void*), so we adapt to posix's requirement
// and simply skip out on the return to the caller's perspective
r = pthread_create(&handle_, &attributes,
reinterpret_cast<void* (*)(void*)>(BOUNCE(posixThread, thread_func)),
reinterpret_cast<void*>(this));
Parameters
cThe class type.
mThe member function in the class
Returns
A bounce function which redirects a C-style callback to a class member function.