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

Function like object adapter over freestanding and member functions. More...

#include <FunctionPointerWithContext.h>

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

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...
 
FunctionPointerWithContextoperator= (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 (void) 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...
 

Friends

bool operator== (const FunctionPointerWithContext &lhs, const FunctionPointerWithContext &rhs)
 Equal to operator between two FunctionPointerWithContext instances. More...
 

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:

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.

Attention
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
ContextTypeType of the argument pointee.

Definition at line 56 of file FunctionPointerWithContext.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 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]functionThe 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]objectPointer to the instance which is used to invoke member.
[in]memberPointer to the member function to adapt.

Definition at line 83 of file FunctionPointerWithContext.h.

FunctionPointerWithContext ( const FunctionPointerWithContext< ContextType > &  that)

Copy construction.

Parameters
[in]thatThe 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]functionThe 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]objectPointer to the instance is used to invoke member.
[in]memberPointer 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]contextparameter 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]contextparameter 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
nextThe 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
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 117 of file SafeBool.h.

void operator() ( ContextType  context) const

Call the adapted function and functions chained to the instance.

Parameters
[in]contextparameter 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]thatThe 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
protectedinherited

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]lhsLeft hand side of the expression.
[in]rhsRight 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.

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.