19 #ifndef MBED_FUNCTIONPOINTER_WITH_CONTEXT_H 20 #define MBED_FUNCTIONPOINTER_WITH_CONTEXT_H 57 template <
typename ContextType>
62 typedef void (*pvoidfcontext_t)(ContextType context);
99 _caller(that._caller), _next(NULL) {
114 _caller = that._caller;
129 void attach(
void (*
function)(ContextType context) = NULL)
132 _caller = functioncaller;
148 void attach(T *
object,
void (T::*member)(ContextType context))
156 _caller = &FunctionPointerWithContext::membercaller<T>;
164 void call(ContextType context)
const 166 _caller(
this, context);
259 return rhs._caller == lhs._caller &&
269 static void membercaller(cpFunctionPointerWithContext_t
self, ContextType context) {
270 if (self->_memberFunctionAndPointer._object) {
271 T *o =
static_cast<T *
>(
self->_memberFunctionAndPointer._object);
272 void (T::*m)(ContextType);
273 memcpy((
char*) &m, self->_memberFunctionAndPointer._memberFunction,
sizeof(m));
278 static void functioncaller(cpFunctionPointerWithContext_t
self, ContextType context) {
279 if (self->_function) {
280 self->_function(context);
284 struct MemberFunctionAndPtr {
291 class UndefinedClass;
292 typedef void (UndefinedClass::*UndefinedMemberFunction)(ContextType);
296 char _memberFunction[
sizeof(UndefinedMemberFunction)];
297 UndefinedMemberFunction _alignment;
312 pFunctionPointerWithContext_t _next;
354 template<
typename T,
typename ContextType>
357 void (T::*member)(ContextType context)
368 #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...
pFunctionPointerWithContext_t getNext() const
Access the next element in the call chain.
pvoidfcontext_t _function
Static function pointer - NULL if none attached.
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...