ComSquare
Public Member Functions | Private Attributes | List of all members
ComSquare::Callback< Types > Class Template Reference

A callback where you can subscribe to and emit it. More...

#include <Callback.hpp>

Collaboration diagram for ComSquare::Callback< Types >:

Public Member Functions

template<typename Func >
int addCallback (Func callback)
 Add a method to be called when this callback is invoked. More...
 
void removeCallback (int id)
 Remove a function from this callback. More...
 
void operator() (Types ...args) const
 
 Callback ()=default
 A default constructor. More...
 
 Callback (const Callback &)=default
 A default copy constructor. More...
 
 ~Callback ()=default
 A default destructor. More...
 
Callbackoperator= (const Callback &)=default
 A default assignment operator. More...
 
template<typename Func >
 Callback (Func callback)
 Implicitly transform a callable into a callback. More...
 

Private Attributes

int _nextID = 0
 
std::unordered_map< int, std::function< void(Types...)> > _functions = {}
 The list of functions to call. More...
 

Detailed Description

template<typename ... Types>
class ComSquare::Callback< Types >

A callback where you can subscribe to and emit it.

Constructor & Destructor Documentation

◆ Callback() [1/3]

template<typename ... Types>
ComSquare::Callback< Types >::Callback ( )
default

A default constructor.

◆ Callback() [2/3]

template<typename ... Types>
ComSquare::Callback< Types >::Callback ( const Callback< Types > &  )
default

A default copy constructor.

◆ ~Callback()

template<typename ... Types>
ComSquare::Callback< Types >::~Callback ( )
default

A default destructor.

◆ Callback() [3/3]

template<typename ... Types>
template<typename Func >
ComSquare::Callback< Types >::Callback ( Func  callback)
inline

Implicitly transform a callable into a callback.

Member Function Documentation

◆ addCallback()

template<typename ... Types>
template<typename Func >
int ComSquare::Callback< Types >::addCallback ( Func  callback)
inline

Add a method to be called when this callback is invoked.

Parameters
callbackThe list of arguments of the callback method
Returns
A unique ID for this callback. That can be used to remove the callback later.

◆ operator()()

template<typename ... Types>
void ComSquare::Callback< Types >::operator() ( Types ...  args) const
inline

◆ operator=()

template<typename ... Types>
Callback& ComSquare::Callback< Types >::operator= ( const Callback< Types > &  )
default

A default assignment operator.

◆ removeCallback()

template<typename ... Types>
void ComSquare::Callback< Types >::removeCallback ( int  id)
inline

Remove a function from this callback.

Parameters
idThe ID of the function.

Member Data Documentation

◆ _functions

template<typename ... Types>
std::unordered_map<int, std::function<void (Types...)> > ComSquare::Callback< Types >::_functions = {}
private

The list of functions to call.

◆ _nextID

template<typename ... Types>
int ComSquare::Callback< Types >::_nextID = 0
private

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