Mbed OS Reference
|
Function like object adapter over freestanding and member functions. More...
#include <FunctionPointerWithContext.h>
Public Member Functions | |
FunctionPointerWithContext (void(*function)(ContextType context)=NULL) | |
Create a FunctionPointerWithContext from a pointer to a freestanding function. More... | |
template<typename T > | |
FunctionPointerWithContext (T *object, void(T::*member)(ContextType context)) | |
Create a FunctionPointerWithContext from a pointer to a member function and the instance which is used to call it. More... | |
FunctionPointerWithContext (const FunctionPointerWithContext &that) | |
Copy construction. More... | |
FunctionPointerWithContext & | operator= (const FunctionPointerWithContext &that) |
Copy assignment. More... | |
void | attach (void(*function)(ContextType context)=NULL) |
Adapt a freestanding function. More... | |
template<typename T > | |
void | attach (T *object, void(T::*member)(ContextType context)) |
Adapt a pointer to member function and the instance to use to call it. More... | |
void | call (ContextType context) const |
Call the adapted function and functions chained to the instance. More... | |
void | call (ContextType context) |
Call the adapted function and functions chained to the instance. More... | |
void | operator() (ContextType context) const |
Call the adapted function and functions chained to the instance. More... | |
bool | toBool () const |
Indicate if a callable object is being adapted. More... | |
void | chainAsNext (pFunctionPointerWithContext_t next) |
Set a FunctionPointer instance as the next element in the chain of callable objects. More... | |
pFunctionPointerWithContext_t | getNext () const |
Access the next element in the call chain. More... | |
pvoidfcontext_t | get_function () const |
Access the next element in the call chain. More... | |
operator BoolType_t () const | |
Bool operator implementation, derived class must provide a bool toBool() const function. More... | |
Protected Types | |
typedef void(base::* | BoolType_t) () const |
The bool type is a pointer to method that can be used in boolean context. More... | |
Protected Member Functions | |
void | invalidTag () const |
Nonimplemented call, use to disallow conversion between unrelated types. More... | |
void | trueTag () const |
Special member function that indicates a true value. More... | |
Function like object adapter over freestanding and member functions.
Freestanding and member functions are two distinct types in C++. One is not convertible into the other, and the call syntax between the two is different even if conceptually they are similar: Both primitives can be copied, called and produce a result.
To solve incompatibilities, this class adapts freestanding and member functions to a common interface. The interface chosen is similar to the freestanding function pointers interface:
This class also offers a mechanism to chain other instances to it. When an instance is called, all the instances being part of the chain are called.
ContextType | Type of the argument pointee. |
Definition at line 58 of file common/FunctionPointerWithContext.h.
|
protectedinherited |
The bool type is a pointer to method that can be used in boolean context.
Definition at line 50 of file common/SafeBool.h.
FunctionPointerWithContext | ( | void(*)(ContextType context) | function = NULL | ) |
Create a FunctionPointerWithContext from a pointer to a freestanding function.
[in] | function | The freestanding function to attach. |
Definition at line 70 of file common/FunctionPointerWithContext.h.
FunctionPointerWithContext | ( | T * | object, |
void(T::*)(ContextType context) | member | ||
) |
Create a FunctionPointerWithContext from a pointer to a member function and the instance which is used to call it.
[in] | object | Pointer to the instance which is used to invoke member . |
[in] | member | Pointer to the member function to adapt. |
Definition at line 85 of file common/FunctionPointerWithContext.h.
FunctionPointerWithContext | ( | const FunctionPointerWithContext< ContextType > & | that | ) |
Copy construction.
[in] | that | The FunctionPointerWithContext instance used to create this. |
Definition at line 97 of file common/FunctionPointerWithContext.h.
FunctionPointerWithContext & operator= | ( | const FunctionPointerWithContext< ContextType > & | that | ) |
Copy assignment.
[in] | that | The FunctionPointerWithContext instance copied into this. |
Definition at line 107 of file common/FunctionPointerWithContext.h.
void attach | ( | void(*)(ContextType context) | function = NULL | ) |
Adapt a freestanding function.
Previous content adapted is discarded while function
replaces it.
[in] | function | The freestanding function to attach. |
Definition at line 129 of file common/FunctionPointerWithContext.h.
void attach | ( | T * | object, |
void(T::*)(ContextType context) | member | ||
) |
Adapt a pointer to member function and the instance to use to call it.
Previous content adapted is discarded while the adaptation of the pair object
and member
replaces it.
[in] | object | Pointer to the instance is used to invoke member . |
[in] | member | Pointer to the member function to adapt. |
Definition at line 148 of file common/FunctionPointerWithContext.h.
void call | ( | ContextType | context | ) | const |
Call the adapted function and functions chained to the instance.
[in] | context | parameter to pass to chain of adapted functions. |
Definition at line 164 of file common/FunctionPointerWithContext.h.
void call | ( | ContextType | context | ) |
Call the adapted function and functions chained to the instance.
[in] | context | parameter to pass to chain of adapted functions. |
Definition at line 174 of file common/FunctionPointerWithContext.h.
void operator() | ( | ContextType | context | ) | const |
Call the adapted function and functions chained to the instance.
[in] | context | parameter to pass to chain of adapted functions. |
Definition at line 184 of file common/FunctionPointerWithContext.h.
bool toBool | ( | ) | const |
Indicate if a callable object is being adapted.
Definition at line 199 of file common/FunctionPointerWithContext.h.
void chainAsNext | ( | pFunctionPointerWithContext_t | next | ) |
Set a FunctionPointer instance as the next element in the chain of callable objects.
next | The instance to set as the next element in the chain of callable objects. |
Definition at line 216 of file common/FunctionPointerWithContext.h.
pFunctionPointerWithContext_t getNext | ( | ) | const |
Access the next element in the call chain.
If there is no next element in the chain, this function returns NULL.
Definition at line 229 of file common/FunctionPointerWithContext.h.
pvoidfcontext_t get_function | ( | ) | const |
Access the next element in the call chain.
If there is no next element in the chain, this function returns NULL.
Definition at line 242 of file common/FunctionPointerWithContext.h.
|
inherited |
Bool operator implementation, derived class must provide a bool toBool() const function.
Definition at line 119 of file common/SafeBool.h.
|
protectedinherited |
Nonimplemented call, use to disallow conversion between unrelated types.
|
protectedinherited |
Special member function that indicates a true value.
Definition at line 60 of file common/SafeBool.h.
pvoidfcontext_t _function |
Static function pointer - NULL if none attached.
Definition at line 302 of file common/FunctionPointerWithContext.h.
|
mutable |
object this pointer and pointer to member - _memberFunctionAndPointer._object will be NULL if none attached
Definition at line 307 of file common/FunctionPointerWithContext.h.