EnTT 3.16.0
Loading...
Searching...
No Matches
entt::basic_scheduler< Delta, Allocator > Class Template Reference

Cooperative scheduler for processes. More...

#include <scheduler.hpp>

Public Types

using type = base_type
 Process type.
using allocator_type = Allocator
 Allocator type.
using size_type = std::size_t
 Unsigned integer type.
using delta_type = Delta
 Unsigned integer type.

Public Member Functions

 basic_scheduler ()
 Default constructor.
 basic_scheduler (const allocator_type &allocator)
 Constructs a scheduler with a given allocator.
 basic_scheduler (const basic_scheduler &)=delete
 Default copy constructor, deleted on purpose.
 basic_scheduler (basic_scheduler &&other) noexcept
 Move constructor.
 basic_scheduler (basic_scheduler &&other, const allocator_type &allocator)
 Allocator-extended move constructor.
 ~basic_scheduler ()=default
 Default destructor.
basic_scheduleroperator= (const basic_scheduler &)=delete
 Default copy assignment operator, deleted on purpose.
basic_scheduleroperator= (basic_scheduler &&other) noexcept
 Move assignment operator.
void swap (basic_scheduler &other) noexcept
 Exchanges the contents with those of a given scheduler.
constexpr allocator_type get_allocator () const noexcept
 Returns the associated allocator.
size_type size () const noexcept
 Number of processes currently scheduled.
bool empty () const noexcept
 Returns true if at least a process is currently scheduled.
void clear ()
 Discards all scheduled processes.
template<typename Type, typename... Args>
typeattach (Args &&...args)
 Schedules a process for the next tick.
template<typename Func>
typeattach (Func func)
 Schedules a process for the next tick.
void update (const delta_type delta, void *data=nullptr)
 Updates all scheduled processes.
void abort (const bool immediate=false)
 Aborts all scheduled processes.

Detailed Description

template<typename Delta, typename Allocator>
class entt::basic_scheduler< Delta, Allocator >

Cooperative scheduler for processes.

A cooperative scheduler runs processes and helps managing their life cycles.

Each process is invoked once per tick. If a process terminates, it's removed automatically from the scheduler and it's never invoked again.
A process can also have a child. In this case, the process is replaced with its child when it terminates if it returns with success. In case of errors, both the process and its child are discarded.

In order to invoke all scheduled processes, call the update member function passing it the elapsed time to forward to the tasks.

See also
process
Template Parameters
DeltaType to use to provide elapsed time.
AllocatorType of allocator used to manage memory and elements.

Definition at line 36 of file scheduler.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Delta, typename Allocator>
using entt::basic_scheduler< Delta, Allocator >::allocator_type = Allocator

Allocator type.

Definition at line 46 of file scheduler.hpp.

◆ delta_type

template<typename Delta, typename Allocator>
using entt::basic_scheduler< Delta, Allocator >::delta_type = Delta

Unsigned integer type.

Definition at line 50 of file scheduler.hpp.

◆ size_type

template<typename Delta, typename Allocator>
using entt::basic_scheduler< Delta, Allocator >::size_type = std::size_t

Unsigned integer type.

Definition at line 48 of file scheduler.hpp.

◆ type

template<typename Delta, typename Allocator>
using entt::basic_scheduler< Delta, Allocator >::type = base_type

Process type.

Definition at line 44 of file scheduler.hpp.

Constructor & Destructor Documentation

◆ basic_scheduler() [1/4]

template<typename Delta, typename Allocator>
entt::basic_scheduler< Delta, Allocator >::basic_scheduler ( )
inline

Default constructor.

Definition at line 53 of file scheduler.hpp.

◆ basic_scheduler() [2/4]

template<typename Delta, typename Allocator>
entt::basic_scheduler< Delta, Allocator >::basic_scheduler ( const allocator_type & allocator)
inlineexplicit

Constructs a scheduler with a given allocator.

Parameters
allocatorThe allocator to use.

Definition at line 60 of file scheduler.hpp.

◆ basic_scheduler() [3/4]

template<typename Delta, typename Allocator>
entt::basic_scheduler< Delta, Allocator >::basic_scheduler ( basic_scheduler< Delta, Allocator > && other)
inlinenoexcept

Move constructor.

Parameters
otherThe instance to move from.

Definition at line 70 of file scheduler.hpp.

◆ basic_scheduler() [4/4]

template<typename Delta, typename Allocator>
entt::basic_scheduler< Delta, Allocator >::basic_scheduler ( basic_scheduler< Delta, Allocator > && other,
const allocator_type & allocator )
inline

Allocator-extended move constructor.

Parameters
otherThe instance to move from.
allocatorThe allocator to use.

Definition at line 78 of file scheduler.hpp.

Member Function Documentation

◆ abort()

template<typename Delta, typename Allocator>
void entt::basic_scheduler< Delta, Allocator >::abort ( const bool immediate = false)
inline

Aborts all scheduled processes.

Unless an immediate operation is requested, the abort is scheduled for the next tick. Processes won't be executed anymore in any case.
Once a process is fully aborted and thus finished, it's discarded along with its child, if any.

Parameters
immediateRequests an immediate operation.

Definition at line 211 of file scheduler.hpp.

◆ attach() [1/2]

template<typename Delta, typename Allocator>
template<typename Type, typename... Args>
type & entt::basic_scheduler< Delta, Allocator >::attach ( Args &&... args)
inline

Schedules a process for the next tick.

Template Parameters
TypeType of process to create.
ArgsTypes of arguments to use to initialize the process.
Parameters
argsParameters to use to initialize the process.
Returns
A reference to the newly created process.

Definition at line 154 of file scheduler.hpp.

◆ attach() [2/2]

template<typename Delta, typename Allocator>
template<typename Func>
type & entt::basic_scheduler< Delta, Allocator >::attach ( Func func)
inline

Schedules a process for the next tick.

Template Parameters
FuncType of process to create.
Parameters
funcEither a lambda or a functor to use as a process.
Returns
A reference to the newly created process.

Definition at line 166 of file scheduler.hpp.

◆ clear()

template<typename Delta, typename Allocator>
void entt::basic_scheduler< Delta, Allocator >::clear ( )
inline

Discards all scheduled processes.

Processes aren't aborted. They are discarded along with their children and never executed again.

Definition at line 142 of file scheduler.hpp.

◆ empty()

template<typename Delta, typename Allocator>
bool entt::basic_scheduler< Delta, Allocator >::empty ( ) const
inlinenodiscardnoexcept

Returns true if at least a process is currently scheduled.

Returns
True if there are scheduled processes, false otherwise.

Definition at line 132 of file scheduler.hpp.

◆ get_allocator()

template<typename Delta, typename Allocator>
allocator_type entt::basic_scheduler< Delta, Allocator >::get_allocator ( ) const
inlinenodiscardconstexprnoexcept

Returns the associated allocator.

Returns
The associated allocator.

Definition at line 116 of file scheduler.hpp.

◆ operator=() [1/2]

template<typename Delta, typename Allocator>
basic_scheduler & entt::basic_scheduler< Delta, Allocator >::operator= ( basic_scheduler< Delta, Allocator > && other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe instance to move from.
Returns
This process scheduler.

Definition at line 97 of file scheduler.hpp.

◆ operator=() [2/2]

template<typename Delta, typename Allocator>
basic_scheduler & entt::basic_scheduler< Delta, Allocator >::operator= ( const basic_scheduler< Delta, Allocator > & )
delete

Default copy assignment operator, deleted on purpose.

Returns
This process scheduler.

◆ size()

template<typename Delta, typename Allocator>
size_type entt::basic_scheduler< Delta, Allocator >::size ( ) const
inlinenodiscardnoexcept

Number of processes currently scheduled.

Returns
Number of processes currently scheduled.

Definition at line 124 of file scheduler.hpp.

◆ swap()

template<typename Delta, typename Allocator>
void entt::basic_scheduler< Delta, Allocator >::swap ( basic_scheduler< Delta, Allocator > & other)
inlinenoexcept

Exchanges the contents with those of a given scheduler.

Parameters
otherScheduler to exchange the content with.

Definition at line 107 of file scheduler.hpp.

◆ update()

template<typename Delta, typename Allocator>
void entt::basic_scheduler< Delta, Allocator >::update ( const delta_type delta,
void * data = nullptr )
inline

Updates all scheduled processes.

All scheduled processes are executed in no specific order.
If a process terminates with success, it's replaced with its child, if any. Otherwise, if a process terminates with an error, it's removed along with its child.

Parameters
deltaElapsed time.
dataOptional data.

Definition at line 183 of file scheduler.hpp.


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