Kouta
A small application framework based on Boost
kouta::base::callback::BaseCallback< TArgs > Class Template Reference

Safe function pointer wrapper. More...

#include <base-callback.hpp>

Public Types

using Callable = std::function< void(TArgs...)>
 The type of the callable the Callback points to. More...
 

Public Member Functions

 BaseCallback ()=default
 Default constructor. More...
 
 BaseCallback (const BaseCallback &)=default
 
BaseCallbackoperator= (const BaseCallback &)=default
 
 BaseCallback (BaseCallback &&)=default
 
BaseCallbackoperator= (BaseCallback &&)=default
 
virtual ~BaseCallback ()=default
 
void operator() (TArgs... args) const
 Invoke the underlying callable. More...
 

Protected Member Functions

void set_callable (Callable &&callable)
 Set the callable. More...
 

Private Attributes

Callable m_callable
 

Detailed Description

template<class... TArgs>
class kouta::base::callback::BaseCallback< TArgs >

Safe function pointer wrapper.

A Callback can be used to store pointers to callable such as free functions, lambdas, or member methods.

This class serves as a base for custom Callback implementations that may need to take into account details such as event loops or scheduling, depending on the target of the Callback.

Template Parameters
TArgsCallable arguments.

Member Typedef Documentation

◆ Callable

template<class... TArgs>
using kouta::base::callback::BaseCallback< TArgs >::Callable = std::function<void(TArgs...)>

The type of the callable the Callback points to.

Constructor & Destructor Documentation

◆ BaseCallback() [1/3]

template<class... TArgs>
kouta::base::callback::BaseCallback< TArgs >::BaseCallback ( )
default

Default constructor.

Callbacks may be default-constructed, allowing for "optional callbacks" that may or may not be specified at runtime. Do note that calling a callback that has not been initialized will throw an exception (which is intended behaviour).

◆ BaseCallback() [2/3]

template<class... TArgs>
kouta::base::callback::BaseCallback< TArgs >::BaseCallback ( const BaseCallback< TArgs > &  )
default

◆ BaseCallback() [3/3]

template<class... TArgs>
kouta::base::callback::BaseCallback< TArgs >::BaseCallback ( BaseCallback< TArgs > &&  )
default

◆ ~BaseCallback()

template<class... TArgs>
virtual kouta::base::callback::BaseCallback< TArgs >::~BaseCallback ( )
virtualdefault

Member Function Documentation

◆ operator()()

template<class... TArgs>
void kouta::base::callback::BaseCallback< TArgs >::operator() ( TArgs...  args) const
inline

Invoke the underlying callable.

Parameters
[in]argsArguments to provide to the invokation.

◆ operator=() [1/2]

template<class... TArgs>
BaseCallback& kouta::base::callback::BaseCallback< TArgs >::operator= ( BaseCallback< TArgs > &&  )
default

◆ operator=() [2/2]

template<class... TArgs>
BaseCallback& kouta::base::callback::BaseCallback< TArgs >::operator= ( const BaseCallback< TArgs > &  )
default

◆ set_callable()

template<class... TArgs>
void kouta::base::callback::BaseCallback< TArgs >::set_callable ( Callable &&  callable)
inlineprotected

Set the callable.

This method exists to allow inheriting from the Callback to add custom constructors that may, for instance, interface with event loops by posting events

Parameters
[in]callableCallable to use internally.

Member Data Documentation

◆ m_callable

template<class... TArgs>
Callable kouta::base::callback::BaseCallback< TArgs >::m_callable
private

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