Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::async::Task Class Reference

Represents a single task within a task graph. More...

#include <task.hpp>

Public Member Functions

 Task ()=default
 Task (const Task &)=default
 Task (Task &&)=default
 ~Task ()=default
Taskoperator= (const Task &)=default
Taskoperator= (Task &&)=default
void Reset ()
 Resets the task handle to an empty state.
void ResetWork ()
 Removes the work callable from this task.
template<AnyTask C>
TaskWork (C &&callable)
 Assigns work to this task.
template<typename... Tasks>
requires (std::same_as<std::remove_cvref_t<Tasks>, Task> && ...)
TaskPrecede (Tasks &&... tasks)
 Makes this task run before the specified tasks.
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Task>
TaskPrecede (const R &tasks)
 Makes this task run before all tasks in the specified range.
template<typename... Tasks>
requires (std::same_as<std::remove_cvref_t<Tasks>, Task> && ...)
TaskSucceed (Tasks &&... tasks)
 Makes this task run after the specified tasks.
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Task>
TaskSucceed (const R &tasks)
 Makes this task run after all tasks in the specified range.
TaskName (const std::string &name)
 Assigns a name to this task.
bool operator== (const Task &other) const
bool operator!= (const Task &other) const
bool HasWork () const
 Checks if this task has assigned work.
bool Empty () const
 Checks if this task handle is empty (not associated with any task).
size_t Hash () const
 Returns a hash value for this task.
size_t SuccessorsCount () const
 Gets the number of tasks that depend on this task.
size_t PredecessorsCount () const
 Gets the number of tasks this task depends on.
size_t StrongDependenciesCount () const
 Gets the number of strong dependencies this task has.
size_t WeakDependenciesCount () const
 Gets the number of weak dependencies this task has.
std::string_view Name () const
 Gets the name of this task.
TaskType Type () const
 Gets the type of this task.

Friends

class TaskGraph
class SubTaskGraph
class TaskGraphBuilder
class Executor

Detailed Description

Represents a single task within a task graph.

Task objects are lightweight handles - copying them is safe and efficient. Wraps tf::Task and provides methods to manage task dependencies, work assignment, and metadata. Tasks can be static (simple callable) or dynamic (subtasks). The underlying task data is managed by the TaskGraph.

Note
Not thread-safe.

Definition at line 25 of file task.hpp.

Constructor & Destructor Documentation

◆ Task() [1/3]

helios::async::Task::Task ( )
default

◆ Task() [2/3]

helios::async::Task::Task ( const Task & )
default

◆ Task() [3/3]

helios::async::Task::Task ( Task && )
default

◆ ~Task()

helios::async::Task::~Task ( )
default

Member Function Documentation

◆ Empty()

bool helios::async::Task::Empty ( ) const
inlinenodiscard

Checks if this task handle is empty (not associated with any task).

Returns
True if task id empty, false otherwise.

Definition at line 136 of file task.hpp.

◆ Hash()

size_t helios::async::Task::Hash ( ) const
inlinenodiscard

Returns a hash value for this task.

Returns
Hash of task or 0 if current task is empty.

Definition at line 248 of file task.hpp.

◆ HasWork()

bool helios::async::Task::HasWork ( ) const
inlinenodiscard

Checks if this task has assigned work.

Returns
True if task has work, false otherwise.

Definition at line 130 of file task.hpp.

◆ Name() [1/2]

std::string_view helios::async::Task::Name ( ) const
inlinenodiscard

Gets the name of this task.

Returns
Returns empty std::string_view if current task is empty.

Definition at line 288 of file task.hpp.

◆ Name() [2/2]

Task & helios::async::Task::Name ( const std::string & name)
inline

Assigns a name to this task.

Warning
Triggers assertion if current task is empty.
Parameters
nameName for the task (must not be empty)
Returns
Reference to this task for method chaining

Definition at line 241 of file task.hpp.

◆ operator!=()

bool helios::async::Task::operator!= ( const Task & other) const
inlinenodiscard

Definition at line 122 of file task.hpp.

◆ operator=() [1/2]

Task & helios::async::Task::operator= ( const Task & )
default

◆ operator=() [2/2]

Task & helios::async::Task::operator= ( Task && )
default

◆ operator==()

bool helios::async::Task::operator== ( const Task & other) const
inlinenodiscard

Definition at line 118 of file task.hpp.

◆ Precede() [1/2]

template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Task>
Task & helios::async::Task::Precede ( const R & tasks)
inline

Makes this task run before all tasks in the specified range.

Warning
Triggers assertion in next cases:
  • Current task is empty.
  • Any task in the range is empty.
Template Parameters
RRange type containing Task objects
Parameters
tasksRange of tasks that should run after this task
Returns
Reference to this task for method chaining

Definition at line 212 of file task.hpp.

◆ Precede() [2/2]

template<typename... Tasks>
requires (std::same_as<std::remove_cvref_t<Tasks>, Task> && ...)
Task & helios::async::Task::Precede ( Tasks &&... tasks)
inline

Makes this task run before the specified tasks.

Warning
Triggers assertion if current task is empty.
Template Parameters
TasksTask parameter pack
Parameters
tasksTasks that should run after this task
Returns
Reference to this task for method chaining

Definition at line 205 of file task.hpp.

◆ PredecessorsCount()

size_t helios::async::Task::PredecessorsCount ( ) const
inlinenodiscard

Gets the number of tasks this task depends on.

Returns
Count of predecessors or 0 if current task is empty.

Definition at line 264 of file task.hpp.

◆ Reset()

void helios::async::Task::Reset ( )
inline

Resets the task handle to an empty state.

Note
Not thread-safe.

Definition at line 39 of file task.hpp.

◆ ResetWork()

void helios::async::Task::ResetWork ( )
inline

Removes the work callable from this task.

Note
Not thread-safe.

Definition at line 45 of file task.hpp.

◆ StrongDependenciesCount()

size_t helios::async::Task::StrongDependenciesCount ( ) const
inlinenodiscard

Gets the number of strong dependencies this task has.

Returns
Count of strong dependencies or 0 if current task is empty.

Definition at line 272 of file task.hpp.

◆ Succeed() [1/2]

template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Task>
Task & helios::async::Task::Succeed ( const R & tasks)
inline

Makes this task run after all tasks in the specified range.

Warning
Triggers assertion in next cases:
  • Current task is empty.
  • Any task in the range is empty.
Template Parameters
RRange type containing Task objects
Parameters
tasksRange of tasks that should run before this task
Returns
Reference to this task for method chaining

Definition at line 231 of file task.hpp.

◆ Succeed() [2/2]

template<typename... Tasks>
requires (std::same_as<std::remove_cvref_t<Tasks>, Task> && ...)
Task & helios::async::Task::Succeed ( Tasks &&... tasks)
inline

Makes this task run after the specified tasks.

Warning
Triggers assertion in next cases:
  • Current task is empty.
  • Any task in the parameter pack is empty.
Template Parameters
TasksTask parameter pack
Parameters
tasksTasks that should run before this task
Returns
Reference to this task for method chaining

Definition at line 224 of file task.hpp.

◆ SuccessorsCount()

size_t helios::async::Task::SuccessorsCount ( ) const
inlinenodiscard

Gets the number of tasks that depend on this task.

Returns
Count of successors or '0' if current task is empty.

Definition at line 256 of file task.hpp.

◆ Type()

TaskType helios::async::Task::Type ( ) const
inlinenodiscard

Gets the type of this task.

Returns TaskType::Undefined if current task is empty.

Definition at line 296 of file task.hpp.

◆ WeakDependenciesCount()

size_t helios::async::Task::WeakDependenciesCount ( ) const
inlinenodiscard

Gets the number of weak dependencies this task has.

Returns
Count of weak dependencies or 0 if current task is empty.

Definition at line 280 of file task.hpp.

◆ Work()

template<AnyTask C>
Task & helios::async::Task::Work ( C && callable)
inline

Assigns work to this task.

Warning
Triggers assertion if current task is empty.
Template Parameters
CCallable type
Parameters
callableFunction to execute when this task runs
Returns
Reference to this task for method chaining

Definition at line 197 of file task.hpp.

◆ Executor

friend class Executor
friend

Definition at line 193 of file task.hpp.

◆ SubTaskGraph

friend class SubTaskGraph
friend

Definition at line 191 of file task.hpp.

◆ TaskGraph

friend class TaskGraph
friend

Definition at line 190 of file task.hpp.

◆ TaskGraphBuilder

friend class TaskGraphBuilder
friend

Definition at line 192 of file task.hpp.