16 #ifndef MBED_CALLCHAIN_OF_FUNCTION_POINTERS_WITH_CONTEXT_H 17 #define MBED_CALLCHAIN_OF_FUNCTION_POINTERS_WITH_CONTEXT_H 81 template <
typename ContextType>
83 public SafeBool<CallChainOfFunctionPointersWithContext<ContextType> > {
111 pFunctionPointerWithContext_t
add(
void (*
function)(ContextType context))
126 pFunctionPointerWithContext_t
add(T *tptr,
void (T::*mptr)(ContextType context))
156 pFunctionPointerWithContext_t current = chainHead;
157 pFunctionPointerWithContext_t previous = NULL;
160 if(*current == toDetach) {
161 if(previous == NULL) {
162 if(currentCalled == current) {
163 currentCalled = NULL;
165 chainHead = current->
getNext();
167 if(currentCalled == current) {
168 currentCalled = previous;
188 pFunctionPointerWithContext_t fptr = chainHead;
190 pFunctionPointerWithContext_t deadPtr = fptr;
205 return (chainHead != NULL);
223 void call(ContextType context)
const 225 currentCalled = chainHead;
227 while(currentCalled) {
228 currentCalled->
call(context);
230 if(currentCalled == NULL) {
231 currentCalled = chainHead;
233 currentCalled = currentCalled->
getNext();
285 return chainHead != NULL;
294 pFunctionPointerWithContext_t common_add(pFunctionPointerWithContext_t pf)
296 if (chainHead == NULL) {
311 pFunctionPointerWithContext_t chainHead;
323 mutable pFunctionPointerWithContext_t currentCalled;
Function like object adapter over freestanding and member functions.
bool toBool() const
Test if the callchain is empty or not.
void call(ContextType context) const
Call sequentially each member of the chain.
pFunctionPointerWithContext_t add(T *tptr, void(T::*mptr)(ContextType context))
Add a member function bound to its instance at the front of the chain.
bool hasCallbacksAttached(void) const
Check whether the callchain contains any callbacks.
pFunctionPointerWithContext_t getNext(void) const
Access the next element in the call chain.
pFunctionPointerWithContext_t add(const FunctionPointerWithContext< ContextType > &func)
Add a FunctionPointerWithContext at the front of the chain.
pFunctionPointerWithContext_t add(void(*function)(ContextType context))
Add a function pointer at the front of the chain.
FunctionPointerWithContext< ContextType > * pFunctionPointerWithContext_t
Alias of the FunctionPointerWithContext type this object can store.
void call(ContextType context) const
Call the adapted function and functions chained to the instance.
virtual ~CallChainOfFunctionPointersWithContext()
Destruction of the callchain.
void call(ContextType context)
Call sequentially each member of the chain.
bool detach(const FunctionPointerWithContext< ContextType > &toDetach)
Detach a function pointer from a callchain.
Function like object hosting a list of FunctionPointerWithContext.
void operator()(ContextType context) const
Call sequentially each member of the chain.
Safe conversion of objects in boolean context.
CallChainOfFunctionPointersWithContext()
Create an empty callchain.
void clear(void)
Remove all functions registered in the chain.
void chainAsNext(pFunctionPointerWithContext_t next)
Set a FunctionPointer instance as the next element in the chain of callable objects.