![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Rtos API example
CallChainOfFunctionPointersWithContext< ContextType > Class Template Reference
[Common]
Function like object hosting a list of FunctionPointerWithContext. More...
#include <CallChainOfFunctionPointersWithContext.h>
Inherits SafeBool< CallChainOfFunctionPointersWithContext< ContextType > >.
Public Types | |
typedef FunctionPointerWithContext < ContextType > * | pFunctionPointerWithContext_t |
Alias of the FunctionPointerWithContext type this object can store. | |
Public Member Functions | |
CallChainOfFunctionPointersWithContext () | |
Create an empty callchain. | |
virtual | ~CallChainOfFunctionPointersWithContext () |
Destruction of the callchain. | |
pFunctionPointerWithContext_t | add (void(*function)(ContextType context)) |
Add a function pointer at the front of the chain. | |
template<typename T > | |
pFunctionPointerWithContext_t | add (T *tptr, void(T::*mptr)(ContextType context)) |
Add a member function bound to its instance at the front of the chain. | |
pFunctionPointerWithContext_t | add (const FunctionPointerWithContext< ContextType > &func) |
Add a FunctionPointerWithContext at the front of the chain. | |
bool | detach (const FunctionPointerWithContext< ContextType > &toDetach) |
Detach a function pointer from a callchain. | |
void | clear (void) |
Remove all functions registered in the chain. | |
bool | hasCallbacksAttached (void) const |
Check whether the callchain contains any callbacks. | |
void | call (ContextType context) |
Call sequentially each member of the chain. | |
void | call (ContextType context) const |
Call sequentially each member of the chain. | |
void | operator() (ContextType context) const |
Call sequentially each member of the chain. | |
bool | toBool () const |
Test if the callchain is empty or not. | |
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. |
Detailed Description
template<typename ContextType>
class CallChainOfFunctionPointersWithContext< ContextType >
Function like object hosting a list of FunctionPointerWithContext.
Upon call, each FunctionPointerWithContext instance present in the object will be called in sequence with the initial parameters.
It can be seen as a variation of the observer pattern this object being the observable, instances of the FunctionPointerWithContext being the observable and the notify/update operation being the function call.
Example:
CallChainOfFunctionPointersWithContext<void *> chain; void first(void *context) { printf("'first' function.\n"); } void second(void *context) { printf("'second' function.\n"); } class Test { public: void f(void *context) { printf("A::f (class member).\n"); } }; int main() { Test test; chain.add(second); chain.add_front(first); chain.add(&test, &Test::f); // will print: // 'second' function. // 'first' function. // A::f (class member). chain.call(); }
- Note:
- memory allocation is used to add new function like objects into the call chain.
- Template Parameters:
-
ContextType Type of the parameter accepted by the callbacks hosted in the object.
Definition at line 82 of file CallChainOfFunctionPointersWithContext.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.
typedef FunctionPointerWithContext<ContextType>* pFunctionPointerWithContext_t |
Alias of the FunctionPointerWithContext type this object can store.
Definition at line 88 of file CallChainOfFunctionPointersWithContext.h.
Constructor & Destructor Documentation
Create an empty callchain.
Definition at line 94 of file CallChainOfFunctionPointersWithContext.h.
virtual ~CallChainOfFunctionPointersWithContext | ( | ) | [virtual] |
Destruction of the callchain.
Definition at line 99 of file CallChainOfFunctionPointersWithContext.h.
Member Function Documentation
pFunctionPointerWithContext_t add | ( | void(*)(ContextType context) | function ) |
Add a function pointer at the front of the chain.
- Parameters:
-
[in] function A pointer to a void function.
- Returns:
- The FunctionPointerWithContext object created from
function
.
Definition at line 111 of file CallChainOfFunctionPointersWithContext.h.
pFunctionPointerWithContext_t add | ( | T * | tptr, |
void(T::*)(ContextType context) | mptr | ||
) |
Add a member function bound to its instance at the front of the chain.
- Parameters:
-
[in] tptr Pointer to the object to call the member function on. [in] mptr Pointer to the member function to be called.
- Returns:
- The FunctionPointerWithContext object created from
tptr
andmptr
.
Definition at line 126 of file CallChainOfFunctionPointersWithContext.h.
pFunctionPointerWithContext_t add | ( | const FunctionPointerWithContext< ContextType > & | func ) |
Add a FunctionPointerWithContext at the front of the chain.
- Parameters:
-
[in] func The FunctionPointerWithContext to add.
- Returns:
- The function object created for
func
.
Definition at line 138 of file CallChainOfFunctionPointersWithContext.h.
void call | ( | ContextType | context ) | const |
Call sequentially each member of the chain.
- Parameters:
-
[in] context Parameter to pass to the functions called.
Definition at line 223 of file CallChainOfFunctionPointersWithContext.h.
void call | ( | ContextType | context ) |
Call sequentially each member of the chain.
- Parameters:
-
[in] context Parameter to pass to the functions called.
Definition at line 213 of file CallChainOfFunctionPointersWithContext.h.
void clear | ( | void | ) |
Remove all functions registered in the chain.
Definition at line 186 of file CallChainOfFunctionPointersWithContext.h.
bool detach | ( | const FunctionPointerWithContext< ContextType > & | toDetach ) |
Detach a function pointer from a callchain.
- Parameters:
-
[in] toDetach FunctionPointerWithContext instance to detach from this callchain.
- Returns:
- true if a function pointer has been detached and false otherwise.
- Note:
- It is safe to remove a function pointer while call(ContextType) is traversing the chain.
Definition at line 154 of file CallChainOfFunctionPointersWithContext.h.
bool hasCallbacksAttached | ( | void | ) | const |
Check whether the callchain contains any callbacks.
- Returns:
- true if the callchain is not empty and false otherwise.
Definition at line 203 of file CallChainOfFunctionPointersWithContext.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 sequentially each member of the chain.
- Parameters:
-
[in] context Parameter to pass to the functions called.
void first(bool); void second(bool); CallChainOfFunctionPointerWithContext<bool> foo; foo.attach(first); foo.attach(second); // call the callchain like a function foo(true);
Definition at line 258 of file CallChainOfFunctionPointersWithContext.h.
bool toBool | ( | ) | const |
Test if the callchain is empty or not.
- Returns:
- true if the callchain is not empty and false otherwise.
- Note:
- used by SafeBool to offer a safe boolean conversion.
CallChainOfFunctionPointersWithContext<void *> chain; if (!chain) { // Do something if the chain is empty. } if (chain) { // Do something if the chain is not empty. }
Definition at line 283 of file CallChainOfFunctionPointersWithContext.h.
void trueTag | ( | ) | const [protected, inherited] |
Special member function that indicates a true value.
Definition at line 58 of file SafeBool.h.
Generated on Sun Jul 17 2022 08:25:39 by
![doxygen](doxygen.png)