Struct process_adaptor
Synopsis
#include <src/entt/process/process.hpp>
template<typename Func, typename Delta>
struct process_adaptor: process<process_adaptor<Func, Delta>, Delta>, private Func
Description
Adaptor for lambdas and functors to turn them into processes.
Lambdas and functors can't be used directly with a scheduler for they are not properly defined processes with managed life cycles.
This class helps in filling the gap and turning lambdas and functors into full featured processes usable by a scheduler.
The signature of the function call operator should be equivalent to the following:
void(Delta delta, void *data, auto succeed, auto fail);
Where:
delta
is the elapsed time.data
is an opaque pointer to user data if any,nullptr
otherwise.succeed
is a function to call when a process terminates with success.fail
is a function to call when a process terminates with errors.
The signature of the function call operator of both succeed
and fail
is equivalent to the following:
void();
Usually users shouldn't worry about creating adaptors. A scheduler will create them internally each and avery time a lambda or a functor is used as a process.
- See
- process
- See
- scheduler
- Template Parameters
Func
- Actual type of process.Delta
- Type to use to provide elapsed time.
Inheritance
Ancestors: process, Func
Methods
process_adaptor | Constructs a process adaptor from a lambda or a functor. | |
update | Updates a process and its internal state if required. |
Source
Lines 310-330 in src/entt/process/process.hpp.
template<typename Func, typename Delta>
struct process_adaptor: process<process_adaptor<Func, Delta>, Delta>, private Func {
/**
* @brief Constructs a process adaptor from a lambda or a functor.
* @tparam Args Types of arguments to use to initialize the actual process.
* @param args Parameters to use to initialize the actual process.
*/
template<typename... Args>
process_adaptor(Args &&... args)
: Func{std::forward<Args>(args)...}
{}
/**
* @brief Updates a process and its internal state if required.
* @param delta Elapsed time.
* @param data Optional data.
*/
void update(const Delta delta, void *data) {
Func::operator()(delta, data, [this]() { this->succeed(); }, [this]() { this->fail(); });
}
};