Base class for asynchronous components.
A component provies access to the underlying event loop which, by default, belongs to the parent component. Moreover, specifying a parent will add the component to its children list and make sure that the component is deleted when the parent is destroyed (if the component was allocated on the heap).
virtual kouta::base::Component::~Component |
( |
| ) |
|
|
inlinevirtual |
Component destructor.
The component will go through its list of children and delete them one at a time. This is only useful if the components were allocated in the heap, as stack-allocated ones will probably have been deleted automatically prior to calling this destructor.
In addition, once a component has deleted its children, it will remove itself from its parent.
- Note
- Child deletion happens in reverse order.
template<class... TFuncArgs, class... TArgs>
void kouta::base::Component::post |
( |
const std::function< void(TFuncArgs...)> & |
functor, |
|
|
TArgs... |
args |
|
) |
| |
|
inline |
Post a function call to the event loop for deferred execution.
This allows other components, even those residing in another thread/event loop, to post a function to this specific component.
- Warning
- Arguments are copied before being passed to the event loop.
- Template Parameters
-
TFuncArgs | Types of the arguments that the function accepts. |
TArgs | Types of the arguments provided to the invocation. |
- Parameters
-
[in] | functor | Functor to invoke. Its signature must match void(TArgs...) |
[in] | args | Arguments to invoke the functor with. |
template<class TFunctor >
void kouta::base::Component::post |
( |
TFunctor && |
functor | ) |
|
|
inline |
Post a functor call to the event loop for deferred execution.
This allows other components, even those residing in another thread/event loop, to post a functor to this specific component, for example a lambda.
- Template Parameters
-
- Parameters
-
[in] | functor | Functor to invoke.s |
template<class TClass , class... TMethodArgs, class... TArgs>
void kouta::base::Component::post |
( |
void(TClass::*)(TMethodArgs...) |
method, |
|
|
TArgs... |
args |
|
) |
| |
|
inline |
Post a method call to the event loop for deferred execution.
This allows other components, even those residing in another thread/event loop, to post a call to this specific component.
- Warning
- Arguments are copied before being passed to the event loop.
- Template Parameters
-
TClass | Child class whose method is going to be invoked. |
TMethodArgs | Types of the arguments that the method accepts. |
TArgs | Types of the arguments provided to the invocation. |
- Parameters
-
[in] | method | Method to invoke. Its signature must match void(TArgs...) |
[in] | args | Arguments to invoke the method with. |