Deferred Callback implementation. More...
#include <deferred-callback.hpp>
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 | |
DeferredCallback & | operator= (const DeferredCallback &)=default |
DeferredCallback (DeferredCallback &&)=default | |
DeferredCallback & | operator= (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, 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 | |
BaseCallback & | operator= (const BaseCallback &)=default |
BaseCallback & | operator= (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 (Callable &&callable) |
Set the callable. More... | |
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):
The lifetime of the object the Callback points to must be guaranteed to surpass that of the Callback itself.
TArgs | Callable arguments. |
using kouta::base::callback::DeferredCallback< TArgs >::Callable = BaseCallback<TArgs...>::Callable |
The type of the callable the Callback points to.
|
default |
|
default |
|
overridedefault |
|
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.
TClass | Object type. |
[in] | object | Pointer to the object whose method is going to be called. |
[in] | method | Pointer to the method that is going to be called. The arguments of the Callback must match those of this method. |
|
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.
TClass | Object type. |
[in] | object | Pointer to the object whose method is going to be called. |
[in] | callable | Callable to store. For instance, this could be a lambda or anything convertible to std::function . |
|
default |
|
default |