![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Rtos API example
FunctionPointerWithContext< ContextType > Class Template Reference
[Common]
Function like object adapter over freestanding and member functions. More...
#include <FunctionPointerWithContext.h>
Inherits SafeBool< FunctionPointerWithContext< ContextType > >.
Public Member Functions | |
FunctionPointerWithContext (void(*function)(ContextType context)=NULL) | |
Create a FunctionPointerWithContext from a pointer to a freestanding function. | |
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. | |
FunctionPointerWithContext (const FunctionPointerWithContext &that) | |
Copy construction. | |
FunctionPointerWithContext & | operator= (const FunctionPointerWithContext &that) |
Copy assignment. | |
void | attach (void(*function)(ContextType context)=NULL) |
Adapt a freestanding function. | |
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. | |
void | call (ContextType context) const |
Call the adapted function and functions chained to the instance. | |
void | call (ContextType context) |
Call the adapted function and functions chained to the instance. | |
void | operator() (ContextType context) const |
Call the adapted function and functions chained to the instance. | |
bool | toBool () const |
Indicate if a callable object is being adapted. | |
void | chainAsNext (pFunctionPointerWithContext_t next) |
Set a FunctionPointer instance as the next element in the chain of callable objects. | |
pFunctionPointerWithContext_t | getNext (void) const |
Access the next element in the call chain. | |
pvoidfcontext_t | get_function () const |
Access the next element in the call chain. | |
operator BoolType_t () const | |
Bool operator implementation, derived class must provide a bool toBool() const function. | |
Protected Types | |
typedef void(base::* | BoolType_t )() const |
The bool type is a pointer to method that can be used in boolean context. | |
Protected Member Functions | |
void | invalidTag () const |
Nonimplemented call, use to disallow conversion between unrelated types. | |
void | trueTag () const |
Special member function that indicates a true value. | |
Friends | |
bool | operator== (const FunctionPointerWithContext &lhs, const FunctionPointerWithContext &rhs) |
Equal to operator between two FunctionPointerWithContext instances. |
Detailed Description
template<typename ContextType>
class FunctionPointerWithContext< ContextType >
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:
- Copyable.
- Nullable.
- Callable.
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.
freestanding or member function adapted must accept a single argument, and this argument is a pointer to ContextType. Adapted primitives do not return anything.
- Template Parameters:
-
ContextType Type of the argument pointee.
Definition at line 56 of file FunctionPointerWithContext.h.
Member Typedef Documentation
typedef void(base::* BoolType_t)() const [protected, inherited] |
The bool type is a pointer to method that can be used in boolean context.
Definition at line 48 of file SafeBool.h.
Constructor & Destructor Documentation
FunctionPointerWithContext | ( | void(*)(ContextType context) | function = NULL ) |
Create a FunctionPointerWithContext from a pointer to a freestanding function.
- Parameters:
-
[in] function The freestanding function to attach.
Definition at line 68 of file 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.
- Parameters:
-
[in] object Pointer to the instance which is used to invoke member
.[in] Pointer to the member function to adapt.
Definition at line 83 of file FunctionPointerWithContext.h.
FunctionPointerWithContext | ( | const FunctionPointerWithContext< ContextType > & | that ) |
Copy construction.
- Parameters:
-
[in] that The FunctionPointerWithContext instance used to create this.
Definition at line 95 of file FunctionPointerWithContext.h.
Member Function Documentation
void attach | ( | void(*)(ContextType context) | function = NULL ) |
Adapt a freestanding function.
Previous content adapted is discarded while function
replaces it.
- Note:
- This function is equivalent to a call to the copy assignment operator.
- Parameters:
-
[in] function The freestanding function to attach.
Definition at line 123 of file 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.
- Note:
- This function is equivalent to a call to the copy assignment operator.
- Parameters:
-
[in] object Pointer to the instance is used to invoke member
.[in] function Pointer to the member function to adapt.
Definition at line 142 of file FunctionPointerWithContext.h.
void call | ( | ContextType | context ) | const |
Call the adapted function and functions chained to the instance.
- Parameters:
-
[in] context parameter to pass to chain of adapted functions.
Definition at line 158 of file FunctionPointerWithContext.h.
void call | ( | ContextType | context ) |
Call the adapted function and functions chained to the instance.
- Parameters:
-
[in] context parameter to pass to chain of adapted functions.
Definition at line 168 of file FunctionPointerWithContext.h.
void chainAsNext | ( | pFunctionPointerWithContext_t | next ) |
Set a FunctionPointer instance as the next element in the chain of callable objects.
- Note:
- Invoking call() on the head FunctionPointer invokes all chained callbacks.
- Refer to CallChainOfFunctionPointerWithContext as an alternative.
- Parameters:
-
next The instance to set as the next element in the chain of callable objects.
Definition at line 210 of file 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.
- Returns:
- A pointer to the next FunctionPointerWithContext instance in the chain.
Definition at line 236 of file FunctionPointerWithContext.h.
pFunctionPointerWithContext_t getNext | ( | void | ) | const |
Access the next element in the call chain.
If there is no next element in the chain, this function returns NULL.
- Returns:
- A pointer to the next FunctionPointerWithContext instance in the chain.
Definition at line 223 of file FunctionPointerWithContext.h.
void invalidTag | ( | ) | const [protected, inherited] |
Nonimplemented call, use to disallow conversion between unrelated types.
operator BoolType_t | ( | ) | const [inherited] |
Bool operator implementation, derived class must provide a bool toBool() const function.
Definition at line 117 of file SafeBool.h.
void operator() | ( | ContextType | context ) | const |
Call the adapted function and functions chained to the instance.
- Parameters:
-
[in] context parameter to pass to chain of adapted functions.
Definition at line 178 of file FunctionPointerWithContext.h.
FunctionPointerWithContext& operator= | ( | const FunctionPointerWithContext< ContextType > & | that ) |
Copy assignment.
- Parameters:
-
[in] that The FunctionPointerWithContext instance copied into this.
Definition at line 105 of file FunctionPointerWithContext.h.
bool toBool | ( | ) | const |
Indicate if a callable object is being adapted.
- Note:
- implementation of safe bool operator.
- Returns:
- true if the content of the instance can be invoked and false otherwise.
Definition at line 193 of file FunctionPointerWithContext.h.
void trueTag | ( | ) | const [protected, inherited] |
Special member function that indicates a true value.
Definition at line 58 of file SafeBool.h.
Friends And Related Function Documentation
bool operator== | ( | const FunctionPointerWithContext< ContextType > & | lhs, |
const FunctionPointerWithContext< ContextType > & | rhs | ||
) | [friend] |
Equal to operator between two FunctionPointerWithContext instances.
- Parameters:
-
[in] lhs Left hand side of the expression. [in] rhs Right hand side of the expression.
- Returns:
- true if lhs and rhs adapt the same object and false otherwise.
Definition at line 249 of file FunctionPointerWithContext.h.
Field Documentation
pvoidfcontext_t _function |
Static function pointer - NULL if none attached.
Definition at line 296 of file FunctionPointerWithContext.h.
MemberFunctionAndPtr _memberFunctionAndPointer [mutable] |
object this pointer and pointer to member - _memberFunctionAndPointer._object will be NULL if none attached
Definition at line 301 of file FunctionPointerWithContext.h.
Generated on Sun Jul 17 2022 08:25:40 by
![doxygen](doxygen.png)