EnTT 3.14.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
entt::basic_scheduler< Delta, Allocator > Class Template Reference

Cooperative scheduler for processes. More...

#include <scheduler.hpp>

Public Types

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 Proc , typename... Args>
basic_schedulerattach (Args &&...args)
 Schedules a process for the next tick.
 
template<typename Func >
basic_schedulerattach (Func &&func)
 Schedules a process for the next tick.
 
template<typename Proc , typename... Args>
basic_schedulerthen (Args &&...args)
 Sets a process as a continuation of the last scheduled process.
 
template<typename Func >
basic_schedulerthen (Func &&func)
 Sets a process as a continuation of the last scheduled process.
 
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.

Example of use (pseudocode):

scheduler.attach([](auto delta, void *, auto succeed, auto fail) {
// code
Cooperative scheduler for processes.
Definition scheduler.hpp:82
basic_scheduler & attach(Args &&...args)
Schedules a process for the next tick.
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
Definition memory.hpp:219

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 82 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 95 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 99 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 97 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 102 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 109 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 119 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 127 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 352 of file scheduler.hpp.

◆ attach() [1/2]

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

Schedules a process for the next tick.

Returned value can be used to attach a continuation for the last process. The continutation is scheduled automatically when the process terminates and only if the process returns with success.

Example of use (pseudocode):

// schedules a task in the form of a process class
// appends a child in the form of a lambda function
.then([](auto delta, void *, auto succeed, auto fail) {
// code
})
// appends a child in the form of another process class
Template Parameters
ProcType of process to schedule.
ArgsTypes of arguments to use to initialize the process.
Parameters
argsParameters to use to initialize the process.
Returns
This process scheduler.

Definition at line 221 of file scheduler.hpp.

◆ attach() [2/2]

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

Schedules a process for the next tick.

A process can be either a lambda or a functor. The scheduler wraps both of them in a process adaptor internally.
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();

Returned value can be used to attach a continuation for the last process. The continutation is scheduled automatically when the process terminates and only if the process returns with success.

Example of use (pseudocode):

// schedules a task in the form of a lambda function
scheduler.attach([](auto delta, void *, auto succeed, auto fail) {
// code
})
// appends a child in the form of another lambda function
.then([](auto delta, void *, auto succeed, auto fail) {
// code
})
// appends a child in the form of a process class
basic_scheduler & then(Args &&...args)
Sets a process as a continuation of the last scheduled process.
See also
process_adaptor
Template Parameters
FuncType of process to schedule.
Parameters
funcEither a lambda or a functor to use as a process.
Returns
This process scheduler.

Definition at line 281 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 191 of file scheduler.hpp.

◆ empty()

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

Returns true if at least a process is currently scheduled.

Returns
True if there are scheduled processes, false otherwise.

Definition at line 181 of file scheduler.hpp.

◆ get_allocator()

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

Returns the associated allocator.

Returns
The associated allocator.

Definition at line 165 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 146 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
inlinenoexcept

Number of processes currently scheduled.

Returns
Number of processes currently scheduled.

Definition at line 173 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 156 of file scheduler.hpp.

◆ then() [1/2]

template<typename Delta , typename Allocator >
template<typename Proc , typename... Args>
basic_scheduler & entt::basic_scheduler< Delta, Allocator >::then ( Args &&... args)
inline

Sets a process as a continuation of the last scheduled process.

Template Parameters
ProcType of process to use as a continuation.
ArgsTypes of arguments to use to initialize the process.
Parameters
argsParameters to use to initialize the process.
Returns
This process scheduler.

Definition at line 294 of file scheduler.hpp.

◆ then() [2/2]

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

Sets a process as a continuation of the last scheduled process.

Template Parameters
FuncType of process to use as a continuation.
Parameters
funcEither a lambda or a functor to use as a process.
Returns
This process scheduler.

Definition at line 310 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 326 of file scheduler.hpp.


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