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

Deferred Callback implementation. More...

#include <deferred-callback.hpp>

Inheritance diagram for kouta::base::callback::DeferredCallback< TArgs >:
Collaboration diagram for kouta::base::callback::DeferredCallback< TArgs >:

Public Types

using Callable = BaseCallback< TArgs... >::Callable
 The type of the callable the Callback points to. More...
 
- Public Types inherited from kouta::base::callback::BaseCallback< TArgs... >
using Callable = std::function< void(TArgs...)>
 The type of the callable the Callback points to. More...
 

Public Member Functions

 DeferredCallback (const DeferredCallback &)=default
 
DeferredCallbackoperator= (const DeferredCallback &)=default
 
 DeferredCallback (DeferredCallback &&)=default
 
DeferredCallbackoperator= (DeferredCallback &&)=default
 
 ~DeferredCallback () override=default
 
template<class TClass >
 DeferredCallback (TClass *object, void(TClass::*method)(TArgs...))
 Callback constructor from a bound method. More...
 
template<class TClass >
 DeferredCallback (TClass *object, const DeferredCallback::Callable &callable)
 Callback constructor from a callable. More...
 
- Public Member Functions inherited from kouta::base::callback::BaseCallback< TArgs... >
 BaseCallback ()=default
 Default constructor. More...
 
 BaseCallback (const BaseCallback &)=default
 
 BaseCallback (BaseCallback &&)=default
 
BaseCallbackoperator= (const BaseCallback &)=default
 
BaseCallbackoperator= (BaseCallback &&)=default
 
virtual ~BaseCallback ()=default
 
void operator() (TArgs... args) const
 Invoke the underlying callable. More...
 

Additional Inherited Members

- Protected Member Functions inherited from kouta::base::callback::BaseCallback< TArgs... >
void set_callable (const Callable &callable)
 Set the callable. More...
 

Detailed Description

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

Deferred Callback implementation.

A deferred Callback wraps a callable that is invoked within the destination object's thread, assuming that said object implements a post() method which allows the Callback to deferr the call to its event loop. This is the case for the Component based architecture of this library.

Because calling a deferred Callback posts an event to the destination's thread, arguments passed to the callback must be copied during the call, meaning that the following types of arguments should not be used (or used with much care to prevent invalid memory access or race conditions):

  • Raw pointers
  • Non-copyable objects
  • Objects referencing, but not owning, dynamic memory (e.g. std::span)

The lifetime of the object the Callback points to must be guaranteed to surpass that of the Callback itself.

Template Parameters
TArgsCallable arguments.

Member Typedef Documentation

◆ Callable

template<class... TArgs>
using kouta::base::callback::DeferredCallback< TArgs >::Callable = BaseCallback<TArgs...>::Callable

The type of the callable the Callback points to.

Constructor & Destructor Documentation

◆ DeferredCallback() [1/4]

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

◆ DeferredCallback() [2/4]

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

◆ ~DeferredCallback()

template<class... TArgs>
kouta::base::callback::DeferredCallback< TArgs >::~DeferredCallback ( )
overridedefault

◆ DeferredCallback() [3/4]

template<class... TArgs>
template<class TClass >
kouta::base::callback::DeferredCallback< TArgs >::DeferredCallback ( TClass *  object,
void(TClass::*)(TArgs...)  method 
)
inline

Callback constructor from a bound method.

This constructor initializes the internal callable with a pointer to the specified bound method. The developer must guarantee the lifetime of the object to prevent invalid memory access.

object must implement a post() method to which the invokation can be passed to defer execution.

Template Parameters
TClassObject type.
Parameters
[in]objectPointer to the object whose method is going to be called.
[in]methodPointer to the method that is going to be called. The arguments of the Callback must match those of this method.

◆ DeferredCallback() [4/4]

template<class... TArgs>
template<class TClass >
kouta::base::callback::DeferredCallback< TArgs >::DeferredCallback ( TClass *  object,
const DeferredCallback< TArgs >::Callable callable 
)
inline

Callback constructor from a callable.

This constructor initializes the intenal callable to the one specified in callable , so that it is invoked from within the context of the provided object , which must implement a post() method to which the invokation can be passed to defer execution.

The developer must guarantee the lifetime of the object to rpevent invalid memory access.

Template Parameters
TClassObject type.
Parameters
[in]objectPointer to the object whose method is going to be called.
[in]callableCallable to store. For instance, this could be a lambda or anything convertible to std::function.

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

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