17 #ifndef MBED_FUNCTIONPOINTER_WITH_CONTEXT_H 18 #define MBED_FUNCTIONPOINTER_WITH_CONTEXT_H 55 template <
typename ContextType>
60 typedef void (*pvoidfcontext_t)(ContextType context);
97 _caller(that._caller), _next(NULL) {
108 _caller = that._caller;
123 void attach(
void (*
function)(ContextType context) = NULL)
126 _caller = functioncaller;
142 void attach(T *
object,
void (T::*member)(ContextType context))
150 _caller = &FunctionPointerWithContext::membercaller<T>;
158 void call(ContextType context)
const 160 _caller(
this, context);
223 pFunctionPointerWithContext_t
getNext(
void)
const 253 return rhs._caller == lhs._caller &&
263 static void membercaller(cpFunctionPointerWithContext_t
self, ContextType context) {
264 if (self->_memberFunctionAndPointer._object) {
265 T *o =
static_cast<T *
>(
self->_memberFunctionAndPointer._object);
266 void (T::*m)(ContextType);
267 memcpy((
char*) &m, self->_memberFunctionAndPointer._memberFunction,
sizeof(m));
272 static void functioncaller(cpFunctionPointerWithContext_t
self, ContextType context) {
273 if (self->_function) {
274 self->_function(context);
278 struct MemberFunctionAndPtr {
285 class UndefinedClass;
286 typedef void (UndefinedClass::*UndefinedMemberFunction)(ContextType);
290 char _memberFunction[
sizeof(UndefinedMemberFunction)];
291 UndefinedMemberFunction _alignment;
306 pFunctionPointerWithContext_t _next;
349 template<
typename T,
typename ContextType>
352 void (T::*member)(ContextType context)
362 #endif // ifndef MBED_FUNCTIONPOINTER_WITH_CONTEXT_H FunctionPointerWithContext(const FunctionPointerWithContext &that)
Copy construction.
Function like object adapter over freestanding and member functions.
MemberFunctionAndPtr _memberFunctionAndPointer
object this pointer and pointer to member - _memberFunctionAndPointer._object will be NULL if none at...
pvoidfcontext_t _function
Static function pointer - NULL if none attached.
pFunctionPointerWithContext_t getNext(void) const
Access the next element in the call chain.
void attach(void(*function)(ContextType context)=NULL)
Adapt a freestanding function.
FunctionPointerWithContext< ContextType > makeFunctionPointer(T *object, void(T::*member)(ContextType context))
Factory of adapted member function pointers.
void operator()(ContextType context) const
Call the adapted function and functions chained to the instance.
void call(ContextType context) const
Call the adapted function and functions chained to the instance.
void call(ContextType context)
Call the adapted function and functions chained to the instance.
FunctionPointerWithContext(void(*function)(ContextType context)=NULL)
Create a FunctionPointerWithContext from a pointer to a freestanding function.
Safe conversion of objects in boolean context.
pvoidfcontext_t get_function() const
Access the next element in the call chain.
bool toBool() const
Indicate if a callable object is being adapted.
FunctionPointerWithContext & operator=(const FunctionPointerWithContext &that)
Copy assignment.
friend bool operator==(const FunctionPointerWithContext &lhs, const FunctionPointerWithContext &rhs)
Equal to operator between two FunctionPointerWithContext instances.
void attach(T *object, void(T::*member)(ContextType context))
Adapt a pointer to member function and the instance to use to call it.
void chainAsNext(pFunctionPointerWithContext_t next)
Set a FunctionPointer instance as the next element in the chain of callable objects.
FunctionPointerWithContext(T *object, void(T::*member)(ContextType context))
Create a FunctionPointerWithContext from a pointer to a member function and the instance which is use...