19 #ifndef MBED_CALLCHAIN_OF_FUNCTION_POINTERS_WITH_CONTEXT_H 20 #define MBED_CALLCHAIN_OF_FUNCTION_POINTERS_WITH_CONTEXT_H 84 template <
typename ContextType>
86 public SafeBool<CallChainOfFunctionPointersWithContext<ContextType> > {
122 pFunctionPointerWithContext_t
add(
void (*
function)(ContextType context))
137 pFunctionPointerWithContext_t
add(T *tptr,
void (T::*mptr)(ContextType context))
167 pFunctionPointerWithContext_t current = chainHead;
168 pFunctionPointerWithContext_t previous = NULL;
171 if(*current == toDetach) {
172 if(previous == NULL) {
173 if(currentCalled == current) {
174 currentCalled = NULL;
176 chainHead = current->
getNext();
178 if(currentCalled == current) {
179 currentCalled = previous;
199 pFunctionPointerWithContext_t fptr = chainHead;
201 pFunctionPointerWithContext_t deadPtr = fptr;
216 return (chainHead != NULL);
234 void call(ContextType context)
const 236 currentCalled = chainHead;
238 while(currentCalled) {
239 currentCalled->
call(context);
241 if(currentCalled == NULL) {
242 currentCalled = chainHead;
244 currentCalled = currentCalled->
getNext();
296 return chainHead != NULL;
305 pFunctionPointerWithContext_t common_add(pFunctionPointerWithContext_t pf)
307 if (chainHead == NULL) {
322 pFunctionPointerWithContext_t chainHead;
334 mutable pFunctionPointerWithContext_t currentCalled;
void clear()
Remove all functions registered in the chain.
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.
pFunctionPointerWithContext_t getNext() 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.
bool hasCallbacksAttached() const
Check whether the callchain contains any callbacks.
void chainAsNext(pFunctionPointerWithContext_t next)
Set a FunctionPointer instance as the next element in the chain of callable objects.