Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LinkNode_SimpleChatwithSerial
Fork of BLE_API by
Diff: ble/CallChainOfFunctionPointersWithContext.h
- Revision:
- 933:3ec277a0d780
- Parent:
- 932:68a113707ba5
- Child:
- 934:5e3acddfcd82
diff -r 68a113707ba5 -r 3ec277a0d780 ble/CallChainOfFunctionPointersWithContext.h
--- a/ble/CallChainOfFunctionPointersWithContext.h Thu Nov 26 12:52:05 2015 +0000
+++ b/ble/CallChainOfFunctionPointersWithContext.h Thu Nov 26 12:52:06 2015 +0000
@@ -61,9 +61,9 @@
typedef FunctionPointerWithContext<ContextType> *pFunctionPointerWithContext_t;
public:
- /** Create an empty chain.
+ /** Create an empty chain
*
- * @param size (optional) Initial size of the chain.
+ * @param size (optional) Initial size of the chain
*/
CallChainOfFunctionPointersWithContext() : chainHead(NULL) {
/* empty */
@@ -73,71 +73,30 @@
clear();
}
- /** Add a function at the front of the chain.
+ /** Add a function at the front of the chain
*
- * @param function A pointer to a void function.
+ * @param function A pointer to a void function
*
* @returns
- * The function object created for 'function'.
+ * The function object created for 'function'
*/
pFunctionPointerWithContext_t add(void (*function)(ContextType context)) {
return common_add(new FunctionPointerWithContext<ContextType>(function));
}
- /** Add a function at the front of the chain.
+ /** Add a function at the front of the chain
*
- * @param tptr Pointer to the object to call the member function on.
- * @param mptr Pointer to the member function to be called.
+ * @param tptr pointer to the object to call the member function on
+ * @param mptr pointer to the member function to be called
*
* @returns
- * The function object created for 'tptr' and 'mptr'.
+ * The function object created for 'tptr' and 'mptr'
*/
template<typename T>
pFunctionPointerWithContext_t add(T *tptr, void (T::*mptr)(ContextType context)) {
return common_add(new FunctionPointerWithContext<ContextType>(tptr, mptr));
}
- /** Add a function at the front of the chain.
- *
- * @param func The FunctionPointerWithContext to add.
- */
- void add(const FunctionPointerWithContext<ContextType>& func) {
- common_add(new FunctionPointerWithContext<ContextType>(func));
- }
-
- /**
- * 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) {
- if(currentCalled == current) {
- currentCalled = NULL;
- }
- chainHead = current->getNext();
- } else {
- if(currentCalled == current) {
- currentCalled = previous;
- }
- previous->chainAsNext(current->getNext());
- }
- delete current;
- return;
- }
-
- previous = current;
- current = current->getNext();
- }
- }
-
/** Clear the call chain (remove all functions in the chain).
*/
void clear(void) {
@@ -156,45 +115,16 @@
}
/** Call all the functions in the chain in sequence
- * @Note: The stack frames of all the callbacks within the chained
+ * @Note: the stack frames of all the callbacks within the chained
* FunctionPointers will stack up. Hopefully there won't be too many
* chained FunctionPointers.
*/
void call(ContextType context) {
- ((const CallChainOfFunctionPointersWithContext*) this)->call(context);
- }
-
- /**
- * @brief same as above but const
- */
- void call(ContextType context) const {
- currentCalled = chainHead;
-
- while(currentCalled) {
- currentCalled->call(context);
- // if this was the head and the call removed the head
- if(currentCalled == NULL) {
- currentCalled = chainHead;
- } else {
- currentCalled = currentCalled->getNext();
- }
+ if (chainHead) {
+ chainHead->call(context);
}
}
- /**
- * @brief same as above but with function call operator
- */
- void operator()(ContextType context) const {
- call(context);
- }
-
- typedef void (CallChainOfFunctionPointersWithContext::*bool_type)() const;
- void True() const {}
-
- operator bool_type() const {
- return chainHead == NULL ? 0 : &CallChainOfFunctionPointersWithContext::True;
- }
-
private:
pFunctionPointerWithContext_t common_add(pFunctionPointerWithContext_t pf) {
if (chainHead == NULL) {
@@ -209,10 +139,8 @@
private:
pFunctionPointerWithContext_t chainHead;
- mutable pFunctionPointerWithContext_t currentCalled;
-
- /* Disallow copy constructor and assignment operators. */
+ /* disallow copy constructor and assignment operators */
private:
CallChainOfFunctionPointersWithContext(const CallChainOfFunctionPointersWithContext &);
CallChainOfFunctionPointersWithContext & operator = (const CallChainOfFunctionPointersWithContext &);
