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.
Fork of BLE_API by
Diff: ble/FunctionPointerWithContext.h
- Revision:
- 1052:b55e1ad3e1b3
- Parent:
- 1049:d99774db03b4
--- a/ble/FunctionPointerWithContext.h Mon Jan 11 08:51:30 2016 +0000 +++ b/ble/FunctionPointerWithContext.h Mon Jan 11 08:51:31 2016 +0000 @@ -18,12 +18,13 @@ #define MBED_FUNCTIONPOINTER_WITH_CONTEXT_H #include <string.h> +#include "SafeBool.h" /** A class for storing and calling a pointer to a static or member void function * that takes a context. */ template <typename ContextType> -class FunctionPointerWithContext { +class FunctionPointerWithContext : public SafeBool<FunctionPointerWithContext<ContextType> > { public: typedef FunctionPointerWithContext<ContextType> *pFunctionPointerWithContext_t; typedef const FunctionPointerWithContext<ContextType> *cpFunctionPointerWithContext_t; @@ -87,21 +88,27 @@ * many FunctionPointers in a chain. */ void call(ContextType context) const { _caller(this, context); + } - /* Propagate the call to next in the chain. */ - if (_next) { - _next->call(context); - } + /** + * @brief Same as above + */ + void operator()(ContextType context) const { + call(context); } /** Same as above, workaround for mbed os FunctionPointer implementation. */ void call(ContextType context) { - _caller(this, context); + ((const FunctionPointerWithContext*) this)->call(context); + } + + typedef void (FunctionPointerWithContext::*bool_type)() const; - /* Propagate the call to next in the chain. */ - if (_next) { - _next->call(context); - } + /** + * implementation of safe bool operator + */ + bool toBool() const { + return (_function || _memberFunctionAndPointer._object); } /**