1#ifndef ENTT_PROCESS_PROCESS_HPP
2#define ENTT_PROCESS_PROCESS_HPP
70template<
typename Derived,
typename Delta>
72 enum class state : std::uint8_t {
83 template<
typename Target = Derived>
84 auto next(std::integral_constant<state, state::uninitialized>)
85 ->
decltype(std::declval<Target>().init(),
void()) {
89 template<
typename Target = Derived>
90 auto next(std::integral_constant<state, state::running>,
Delta delta,
void *data)
91 ->
decltype(std::declval<Target>().update(
delta, data),
void()) {
95 template<
typename Target = Derived>
96 auto next(std::integral_constant<state, state::succeeded>)
97 ->
decltype(std::declval<Target>().succeeded(),
void()) {
98 static_cast<Target *
>(
this)->succeeded();
101 template<
typename Target = Derived>
102 auto next(std::integral_constant<state, state::failed>)
103 ->
decltype(std::declval<Target>().failed(),
void()) {
104 static_cast<Target *
>(
this)->failed();
107 template<
typename Target = Derived>
108 auto next(std::integral_constant<state, state::aborted>)
109 ->
decltype(std::declval<Target>().aborted(),
void()) {
110 static_cast<Target *
>(
this)->aborted();
113 template<
typename...
Args>
114 void next(
Args &&...)
const noexcept {}
125 current = state::succeeded;
137 current = state::failed;
148 if(current == state::running) {
149 current = state::paused;
160 if(current == state::paused) {
161 current = state::running;
192 static_assert(std::is_base_of_v<process, Derived>,
"Incorrect use of the class template");
205 current = state::aborted;
218 return current == state::running || current == state::paused;
226 return current == state::finished;
234 return current == state::paused;
242 return current == state::rejected;
252 case state::uninitialized:
253 next(std::integral_constant<state, state::uninitialized>{});
254 current = state::running;
257 next(std::integral_constant<state, state::running>{},
delta, data);
266 case state::succeeded:
267 next(std::integral_constant<state, state::succeeded>{});
268 current = state::finished;
271 next(std::integral_constant<state, state::failed>{});
272 current = state::rejected;
275 next(std::integral_constant<state, state::aborted>{});
276 current = state::rejected;
285 state current{state::uninitialized};
327template<
typename Func,
typename Delta>
334 template<
typename...
Args>
348 [
this]() { this->
fail(); });
Base class for processes.
bool finished() const noexcept
Returns true if a process is already terminated.
process(const process &)=default
Default copy constructor.
void pause() noexcept
Stops a process if it's in a running state.
void succeed() noexcept
Terminates a process with success if it's still alive.
constexpr process()=default
Default constructor.
void unpause() noexcept
Restarts a process if it's paused.
process(process &&) noexcept=default
Default move constructor.
Delta delta_type
Type used to provide elapsed time.
bool rejected() const noexcept
Returns true if a process terminated with errors.
void fail() noexcept
Terminates a process with errors if it's still alive.
bool alive() const noexcept
Returns true if a process is either running or paused.
void tick(const Delta delta, void *data=nullptr)
Updates a process and its internal state if required.
void abort(const bool immediate=false)
Aborts a process if it's still alive.
bool paused() const noexcept
Returns true if a process is currently paused.
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
Adaptor for lambdas and functors to turn them into processes.
void update(const Delta delta, void *data)
Updates a process and its internal state if required.
process_adaptor(Args &&...args)
Constructs a process adaptor from a lambda or a functor.