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

Base class for processes. More...

#include <process.hpp>

Inheritance diagram for entt::basic_process< Delta, Allocator >:
Collaboration diagram for entt::basic_process< Delta, Allocator >:

Public Types

using allocator_type = Allocator
 Allocator type.
using delta_type = Delta
 Type used to provide elapsed time.
using handle_type = std::shared_ptr<basic_process>
 Handle type.

Public Member Functions

 basic_process ()
 Default constructor.
 basic_process (const allocator_type &allocator)
 Constructs a scheduler with a given allocator.
 basic_process (const basic_process &)=delete
 Default copy constructor, deleted on purpose.
 basic_process (basic_process &&)=delete
 Default move constructor, deleted on purpose.
virtual ~basic_process ()=default
 Default destructor.
basic_processoperator= (const basic_process &)=delete
 Default copy assignment operator, deleted on purpose.
basic_processoperator= (basic_process &&)=delete
 Default move assignment operator, deleted on purpose.
constexpr allocator_type get_allocator () const noexcept
 Returns the associated allocator.
void abort ()
 Aborts a process if it's still alive, otherwise does nothing.
void succeed () noexcept
 Terminates a process with success if it's still alive, otherwise does nothing.
void fail () noexcept
 Terminates a process with errors if it's still alive, otherwise does nothing.
void pause () noexcept
 Stops a process if it's running, otherwise does nothing.
void unpause () noexcept
 Restarts a process if it's paused, otherwise does nothing.
bool alive () const noexcept
 Returns true if a process is either running or paused.
bool finished () const noexcept
 Returns true if a process is already terminated.
bool paused () const noexcept
 Returns true if a process is currently paused.
bool rejected () const noexcept
 Returns true if a process terminated with errors.
template<typename Type, typename... Args>
basic_processthen (Args &&...args)
 Assigns a child process to run in case of success.
template<typename Func>
basic_processthen (Func func)
 Assigns a child process to run in case of success.
handle_type peek ()
 Returns the child process without releasing ownership, if any.
void tick (const Delta delta, void *data=nullptr)
 Updates a process and its internal state, if required.

Detailed Description

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

Base class for processes.

Derived classes must specify what's the intended type for elapsed times.
A process can implement the following member functions whether required:

  • void update(Delta, void *) override;

    It's invoked once per tick until a process is explicitly aborted or it terminates either with or without errors. Even though it's not mandatory to declare this member function, as a rule of thumb each process should at least define it to work properly. The void * parameter is an opaque pointer to user data (if any) forwarded directly to the process during an update.

  • void succeeded() override;

    It's invoked in case of success, immediately after an update and during the same tick.

  • void failed() override;

    It's invoked in case of errors, immediately after an update and during the same tick.

  • void aborted() override;

    It's invoked only if a process is explicitly aborted. There is no guarantee that it executes in the same tick, this depends solely on whether the process is aborted immediately or not.

Derived classes can change the internal state of a process by invoking the succeed and fail member functions and even pause or unpause the process itself.

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

Definition at line 72 of file process.hpp.

Member Typedef Documentation

◆ allocator_type

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

Allocator type.

Definition at line 94 of file process.hpp.

◆ delta_type

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

Type used to provide elapsed time.

Definition at line 96 of file process.hpp.

◆ handle_type

template<typename Delta, typename Allocator>
using entt::basic_process< Delta, Allocator >::handle_type = std::shared_ptr<basic_process>

Handle type.

Definition at line 98 of file process.hpp.

Constructor & Destructor Documentation

◆ basic_process() [1/2]

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

Default constructor.

Definition at line 101 of file process.hpp.

◆ basic_process() [2/2]

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

Constructs a scheduler with a given allocator.

Parameters
allocatorThe allocator to use.

Definition at line 108 of file process.hpp.

Member Function Documentation

◆ abort()

template<typename Delta, typename Allocator>
void entt::basic_process< Delta, Allocator >::abort ( )
inline

Aborts a process if it's still alive, otherwise does nothing.

Definition at line 142 of file process.hpp.

◆ alive()

template<typename Delta, typename Allocator>
bool entt::basic_process< Delta, Allocator >::alive ( ) const
inlinenodiscardnoexcept

Returns true if a process is either running or paused.

Returns
True if the process is still alive, false otherwise.

Definition at line 186 of file process.hpp.

◆ fail()

template<typename Delta, typename Allocator>
void entt::basic_process< Delta, Allocator >::fail ( )
inlinenoexcept

Terminates a process with errors if it's still alive, otherwise does nothing.

Definition at line 162 of file process.hpp.

◆ finished()

template<typename Delta, typename Allocator>
bool entt::basic_process< Delta, Allocator >::finished ( ) const
inlinenodiscardnoexcept

Returns true if a process is already terminated.

Returns
True if the process is terminated, false otherwise.

Definition at line 194 of file process.hpp.

◆ get_allocator()

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

Returns the associated allocator.

Returns
The associated allocator.

Definition at line 137 of file process.hpp.

◆ operator=() [1/2]

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

Default move assignment operator, deleted on purpose.

Returns
This process scheduler.

◆ operator=() [2/2]

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

Default copy assignment operator, deleted on purpose.

Returns
This process scheduler.

◆ pause()

template<typename Delta, typename Allocator>
void entt::basic_process< Delta, Allocator >::pause ( )
inlinenoexcept

Stops a process if it's running, otherwise does nothing.

Definition at line 169 of file process.hpp.

◆ paused()

template<typename Delta, typename Allocator>
bool entt::basic_process< Delta, Allocator >::paused ( ) const
inlinenodiscardnoexcept

Returns true if a process is currently paused.

Returns
True if the process is paused, false otherwise.

Definition at line 202 of file process.hpp.

◆ peek()

template<typename Delta, typename Allocator>
handle_type entt::basic_process< Delta, Allocator >::peek ( )
inline

Returns the child process without releasing ownership, if any.

Returns
The child process attached to the object, if any.

Definition at line 244 of file process.hpp.

◆ rejected()

template<typename Delta, typename Allocator>
bool entt::basic_process< Delta, Allocator >::rejected ( ) const
inlinenodiscardnoexcept

Returns true if a process terminated with errors.

Returns
True if the process terminated with errors, false otherwise.

Definition at line 210 of file process.hpp.

◆ succeed()

template<typename Delta, typename Allocator>
void entt::basic_process< Delta, Allocator >::succeed ( )
inlinenoexcept

Terminates a process with success if it's still alive, otherwise does nothing.

Definition at line 152 of file process.hpp.

◆ then() [1/2]

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

Assigns a child process to run in case of success.

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

Definition at line 222 of file process.hpp.

◆ then() [2/2]

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

Assigns a child process to run in case of success.

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

Definition at line 234 of file process.hpp.

◆ tick()

template<typename Delta, typename Allocator>
void entt::basic_process< Delta, Allocator >::tick ( const Delta delta,
void * data = nullptr )
inline

Updates a process and its internal state, if required.

Parameters
deltaElapsed time.
dataOptional data.

Definition at line 253 of file process.hpp.

◆ unpause()

template<typename Delta, typename Allocator>
void entt::basic_process< Delta, Allocator >::unpause ( )
inlinenoexcept

Restarts a process if it's paused, otherwise does nothing.

Definition at line 176 of file process.hpp.


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