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

#include <CallChainOfFunctionPointersWithContext.h>

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

Public Types

typedef FunctionPointerWithContext< ContextType > * pFunctionPointerWithContext_t
 

Public Member Functions

 CallChainOfFunctionPointersWithContext ()
 
virtual ~CallChainOfFunctionPointersWithContext ()
 
pFunctionPointerWithContext_t add (void(*function)(ContextType context))
 
template<typename T >
pFunctionPointerWithContext_t add (T *tptr, void(T::*mptr)(ContextType context))
 
pFunctionPointerWithContext_t add (const FunctionPointerWithContext< ContextType > &func)
 
bool detach (const FunctionPointerWithContext< ContextType > &toDetach)
 
void clear (void)
 
bool hasCallbacksAttached (void) const
 
void call (ContextType context)
 
void call (ContextType context) const
 
void operator() (ContextType context) const
 
bool toBool () const
 
- Public Member Functions inherited from SafeBool< CallChainOfFunctionPointersWithContext< ContextType > >
 operator BoolType_t () const
 

Additional Inherited Members

- Protected Types inherited from SafeBool_::base
typedef void(base::* BoolType_t) () const
 
- Protected Member Functions inherited from SafeBool_::base
void invalidTag () const
 
void trueTag () const
 

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() {
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.

Member Typedef Documentation

template<typename ContextType>
typedef FunctionPointerWithContext<ContextType>* CallChainOfFunctionPointersWithContext< ContextType >::pFunctionPointerWithContext_t

Alias of the FunctionPointerWithContext type this object can store.

Constructor & Destructor Documentation

template<typename ContextType>
CallChainOfFunctionPointersWithContext< ContextType >::CallChainOfFunctionPointersWithContext ( )
inline

Create an empty callchain.

template<typename ContextType>
virtual CallChainOfFunctionPointersWithContext< ContextType >::~CallChainOfFunctionPointersWithContext ( )
inlinevirtual

Destruction of the callchain.

Member Function Documentation

template<typename ContextType>
pFunctionPointerWithContext_t CallChainOfFunctionPointersWithContext< ContextType >::add ( void(*)(ContextType context)  function)
inline

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.
template<typename ContextType>
template<typename T >
pFunctionPointerWithContext_t CallChainOfFunctionPointersWithContext< ContextType >::add ( T *  tptr,
void(T::*)(ContextType context)  mptr 
)
inline

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.
template<typename ContextType>
pFunctionPointerWithContext_t CallChainOfFunctionPointersWithContext< ContextType >::add ( const FunctionPointerWithContext< ContextType > &  func)
inline

Add a FunctionPointerWithContext at the front of the chain.

Parameters
[in]funcThe FunctionPointerWithContext to add.
Returns
The function object created for func.
template<typename ContextType>
void CallChainOfFunctionPointersWithContext< ContextType >::call ( ContextType  context)
inline

Call sequentially each member of the chain.

Parameters
[in]contextParameter to pass to the functions called.
template<typename ContextType>
void CallChainOfFunctionPointersWithContext< ContextType >::call ( ContextType  context) const
inline

Call sequentially each member of the chain.

Parameters
[in]contextParameter to pass to the functions called.
template<typename ContextType>
void CallChainOfFunctionPointersWithContext< ContextType >::clear ( void  )
inline

Remove all functions registered in the chain.

template<typename ContextType>
bool CallChainOfFunctionPointersWithContext< ContextType >::detach ( const FunctionPointerWithContext< ContextType > &  toDetach)
inline

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.
template<typename ContextType>
bool CallChainOfFunctionPointersWithContext< ContextType >::hasCallbacksAttached ( void  ) const
inline

Check whether the callchain contains any callbacks.

Returns
true if the callchain is not empty and false otherwise.
template<typename ContextType>
void CallChainOfFunctionPointersWithContext< ContextType >::operator() ( ContextType  context) const
inline

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);
template<typename ContextType>
bool CallChainOfFunctionPointersWithContext< ContextType >::toBool ( ) const
inline

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.
}

The documentation for this class was generated from the following file:
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.