BLE
Fork of BLE_API by
Diff: ble/CallChainOfFunctionPointersWithContext.h
- Revision:
- 953:8a6c287de1be
- Parent:
- 950:1902cbd0dd83
- Child:
- 954:f6eb43f524b2
--- a/ble/CallChainOfFunctionPointersWithContext.h Thu Nov 26 12:52:09 2015 +0000 +++ b/ble/CallChainOfFunctionPointersWithContext.h Thu Nov 26 12:52:33 2015 +0000 @@ -97,6 +97,34 @@ return common_add(new FunctionPointerWithContext<ContextType>(tptr, mptr)); } + /** + * Detach a function pointer from a callchain + * + * @oaram toDetach FunctionPointerWithContext to detach from this callchain + * + * @return true if a function pointer has been detached and false otherwise + */ + void detach(const FunctionPointerWithContext<ContextType>& toDetach) { + pFunctionPointerWithContext_t current = chainHead; + pFunctionPointerWithContext_t previous = NULL; + + while (current) { + if(*current == toDetach) { + if(previous == NULL) { + chainHead = current->getNext(); + } else { + previous->chainAsNext(current->getNext()); + } + delete current; + return true; + } + + previous = current; + current = current->getNext(); + } + return false; + } + /** Clear the call chain (remove all functions in the chain). */ void clear(void) {