Bike service
Fork of BLE_API by
Diff: ble/CallChainOfFunctionPointersWithContext.h
- Revision:
- 918:2b12b53101ea
- Parent:
- 913:690bea02c431
- Child:
- 919:c5b9fac295f5
--- a/ble/CallChainOfFunctionPointersWithContext.h Thu Nov 26 12:52:04 2015 +0000 +++ b/ble/CallChainOfFunctionPointersWithContext.h Thu Nov 26 12:52:04 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) {