Miosix  2.0alpha1
miosix::Callback< N > Class Template Reference

#include <callback.h>

Inheritance diagram for miosix::Callback< N >:
Collaboration diagram for miosix::Callback< N >:

Public Member Functions

 Callback ()
 
template<typename T >
 Callback (T functor)
 
 Callback (const Callback &rhs)
 
Callbackoperator= (const Callback &rhs)
 
template<typename T >
Callbackoperator= (T functor)
 
void clear ()
 
void operator() ()
 
 operator SafeBool () const
 
 ~Callback ()
 

Detailed Description

template<unsigned N>
class miosix::Callback< N >

A Callback works just like an std::tr1::function, but has some additional limitations. First, it can only accept function objects that take void as a parameter and return void, and second if the size of the implementation-defined type returned by bind is larger than N a compile-time error is generated. Also, calling an empty Callback does nothing, while doing the same on a tr1::function results in an exception being thrown.

The reason why one would want to use this class is because, other than the limitations, this class also offers a guarantee: it will never allocate data on the heap. It is not just a matter of code speed: in Miosix calling new/delete/malloc/free from an interrupt routine produces undefined behaviour, so this class enables binding function calls form an interrupt safely.

Parameters
Nthe size in bytes that an instance of this class reserves to store the function objects. If the line starting with 'typedef char check1' starts failing it means it is time to increase this number. The size of an instance of this object is N+sizeof(void (*)()), but with N rounded by excess to four byte boundaries.

Constructor & Destructor Documentation

template<unsigned N>
miosix::Callback< N >::Callback ( )
inline

Default constructor. Produces an empty callback.

template<unsigned N>
template<typename T >
miosix::Callback< N >::Callback ( functor)
inline

Constructor. Not explicit by design.

Parameters
functorfunction object a copy of which is stored internally
template<unsigned N>
miosix::Callback< N >::Callback ( const Callback< N > &  rhs)
inline

Copy constructor

Parameters
rhsobject to copy
template<unsigned N>
miosix::Callback< N >::~Callback ( )
inline

Destructor

Member Function Documentation

template<unsigned N>
void miosix::Callback< N >::clear ( )
inline

Removes any function object stored in this class

template<unsigned N>
miosix::Callback< N >::operator SafeBool ( ) const
inline
Returns
true if the object contains a callback
template<unsigned N>
void miosix::Callback< N >::operator() ( )
inline

Call the callback, or do nothing if no callback is set

template<unsigned N>
Callback< N > & miosix::Callback< N >::operator= ( const Callback< N > &  rhs)

Operator =

Parameters
rhsobject to copy
Returns
*this
template<unsigned N>
template<typename T >
Callback& miosix::Callback< N >::operator= ( functor)

Assignment operation, assigns a function object to this callback.

Parameters
funtorfunction object a copy of which is stored internally

The documentation for this class was generated from the following file: