Mistake on this page?
Report an issue in GitHub or email us
Public Types | Public Member Functions | Protected Types | Protected Member Functions
CallChainOfFunctionPointersWithContext< ContextType > Class Template Reference

Function like object hosting a list of FunctionPointerWithContext. More...

#include <CallChainOfFunctionPointersWithContext.h>

Inheritance diagram for CallChainOfFunctionPointersWithContext< ContextType >:
SafeBool< CallChainOfFunctionPointersWithContext< ContextType > > base

Public Types

typedef FunctionPointerWithContext< ContextType > * pFunctionPointerWithContext_t
 Alias of the FunctionPointerWithContext type this object can store. More...
 

Public Member Functions

 CallChainOfFunctionPointersWithContext ()
 Create an empty callchain. More...
 
virtual ~CallChainOfFunctionPointersWithContext ()
 Destruction of the callchain. More...
 
pFunctionPointerWithContext_t add (void(*function)(ContextType context))
 Add a function pointer at the front of the chain. More...
 
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. More...
 
pFunctionPointerWithContext_t add (const FunctionPointerWithContext< ContextType > &func)
 Add a FunctionPointerWithContext at the front of the chain. More...
 
bool detach (const FunctionPointerWithContext< ContextType > &toDetach)
 Detach a function pointer from a callchain. More...
 
void clear ()
 Remove all functions registered in the chain. More...
 
bool hasCallbacksAttached () const
 Check whether the callchain contains any callbacks. More...
 
void call (ContextType context)
 Call sequentially each member of the chain. More...
 
void call (ContextType context) const
 Call sequentially each member of the chain. More...
 
void operator() (ContextType context) const
 Call sequentially each member of the chain. More...
 
bool toBool () const
 Test if the callchain is empty or not. 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...
 

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:

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
ContextTypeType of the parameter accepted by the callbacks hosted in the object.

Definition at line 85 of file common/CallChainOfFunctionPointersWithContext.h.

Member Typedef Documentation

typedef void(base::* BoolType_t) () const
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.

Alias of the FunctionPointerWithContext type this object can store.

Definition at line 91 of file common/CallChainOfFunctionPointersWithContext.h.

Constructor & Destructor Documentation

Create an empty callchain.

Definition at line 97 of file common/CallChainOfFunctionPointersWithContext.h.

Destruction of the callchain.

Definition at line 110 of file common/CallChainOfFunctionPointersWithContext.h.

Member Function Documentation

pFunctionPointerWithContext_t add ( void(*)(ContextType context)  function)

Add a function pointer at the front of the chain.

Parameters
[in]functionA pointer to a void function.
Returns
The FunctionPointerWithContext object created from function.

Definition at line 122 of file common/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]tptrPointer to the object to call the member function on.
[in]mptrPointer to the member function to be called.
Returns
The FunctionPointerWithContext object created from tptr and mptr.

Definition at line 137 of file common/CallChainOfFunctionPointersWithContext.h.

pFunctionPointerWithContext_t add ( const FunctionPointerWithContext< ContextType > &  func)

Add a FunctionPointerWithContext at the front of the chain.

Parameters
[in]funcThe FunctionPointerWithContext to add.
Returns
The function object created for func.

Definition at line 149 of file common/CallChainOfFunctionPointersWithContext.h.

void call ( ContextType  context)

Call sequentially each member of the chain.

Parameters
[in]contextParameter to pass to the functions called.

Definition at line 224 of file common/CallChainOfFunctionPointersWithContext.h.

void call ( ContextType  context) const

Call sequentially each member of the chain.

Parameters
[in]contextParameter to pass to the functions called.

Definition at line 234 of file common/CallChainOfFunctionPointersWithContext.h.

void clear ( )

Remove all functions registered in the chain.

Definition at line 197 of file common/CallChainOfFunctionPointersWithContext.h.

bool detach ( const FunctionPointerWithContext< ContextType > &  toDetach)

Detach a function pointer from a callchain.

Parameters
[in]toDetachFunctionPointerWithContext 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 165 of file common/CallChainOfFunctionPointersWithContext.h.

bool hasCallbacksAttached ( ) const

Check whether the callchain contains any callbacks.

Returns
true if the callchain is not empty and false otherwise.

Definition at line 214 of file common/CallChainOfFunctionPointersWithContext.h.

void invalidTag ( ) const
protectedinherited

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 119 of file common/SafeBool.h.

void operator() ( ContextType  context) const

Call sequentially each member of the chain.

Parameters
[in]contextParameter 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 269 of file common/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.
if (!chain) {
// Do something if the chain is empty.
}
if (chain) {
// Do something if the chain is not empty.
}

Definition at line 294 of file common/CallChainOfFunctionPointersWithContext.h.

void trueTag ( ) const
protectedinherited

Special member function that indicates a true value.

Definition at line 60 of file common/SafeBool.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.