Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
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 28 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
inline

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

Returns
True if task id empty, false otherwise.

Definition at line 134 of file task.hpp.

134{ return task_.empty(); }

◆ Hash()

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

Returns a hash value for this task.

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

Definition at line 242 of file task.hpp.

242 {
243 if (Empty()) [[unlikely]] {
244 return 0;
245 }
246
247 return task_.hash_value();
248}
bool Empty() const
Checks if this task handle is empty (not associated with any task).
Definition task.hpp:134

◆ HasWork()

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

Checks if this task has assigned work.

Returns
True if task has work, false otherwise.

Definition at line 128 of file task.hpp.

128{ return task_.has_work(); }

◆ Name() [1/2]

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

Gets the name of this task.

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

Definition at line 282 of file task.hpp.

282 {
283 if (Empty()) [[unlikely]] {
284 return {};
285 }
286
287 return task_.name();
288}

◆ 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 235 of file task.hpp.

235 {
236 HELIOS_ASSERT(!Empty(), "Failed to set task name: Cannot assign name to empty task!");
237 HELIOS_ASSERT(!name.empty(), "Failed to set task name: 'name' cannot be empty!");
238 task_.name(name);
239 return *this;
240}
#define HELIOS_ASSERT(condition,...)
Assertion macro that aborts execution in debug builds.
Definition assert.hpp:140

◆ operator!=()

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

Definition at line 122 of file task.hpp.

122{ return !(*this == other); }

◆ 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
inline

Definition at line 121 of file task.hpp.

121{ return task_ == other.task_; }

◆ 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 208 of file task.hpp.

208 {
209 HELIOS_ASSERT(!Empty(), "Failed to precede task: Task cannot be empty!");
210 auto view = tasks | std::ranges::views::filter([](const auto& task) { return !task.Empty(); });
211 for (const auto& task : view) {
212 task_.precede(task.task_);
213 }
214 return *this;
215}

◆ 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 201 of file task.hpp.

201 {
202 HELIOS_ASSERT(!Empty(), "Failed to precede task: Task cannot be empty!");
203 return Precede(std::to_array({std::forward<Tasks>(tasks)...}));
204}
Task & Precede(Tasks &&... tasks)
Makes this task run before the specified tasks.
Definition task.hpp:201

◆ PredecessorsCount()

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

Gets the number of tasks this task depends on.

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

Definition at line 258 of file task.hpp.

258 {
259 if (Empty()) [[unlikely]] {
260 return 0;
261 }
262
263 return task_.num_predecessors();
264}

◆ Reset()

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

Resets the task handle to an empty state.

Note
Not thread-safe.

Definition at line 42 of file task.hpp.

42{ task_.reset(); }

◆ ResetWork()

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

Removes the work callable from this task.

Note
Not thread-safe.

Definition at line 48 of file task.hpp.

48{ task_.reset_work(); }

◆ StrongDependenciesCount()

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

Gets the number of strong dependencies this task has.

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

Definition at line 266 of file task.hpp.

266 {
267 if (Empty()) [[unlikely]] {
268 return 0;
269 }
270
271 return task_.num_strong_dependencies();
272}

◆ 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 226 of file task.hpp.

226 {
227 HELIOS_ASSERT(!Empty(), "Failed to succeed task: Task cannot be empty!");
228 auto view = tasks | std::ranges::views::filter([](const auto& task) { return !task.Empty(); });
229 for (const auto& task : view) {
230 task_.succeed(task.task_);
231 }
232 return *this;
233}

◆ 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 219 of file task.hpp.

219 {
220 HELIOS_ASSERT(!Empty(), "Failed to succeed task: Task cannot be empty!");
221 return Succeed(std::to_array({std::forward<Tasks>(tasks)...}));
222}
Task & Succeed(Tasks &&... tasks)
Makes this task run after the specified tasks.
Definition task.hpp:219

◆ SuccessorsCount()

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

Gets the number of tasks that depend on this task.

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

Definition at line 250 of file task.hpp.

250 {
251 if (Empty()) [[unlikely]] {
252 return 0;
253 }
254
255 return task_.num_successors();
256}

◆ Type()

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

Gets the type of this task.

Returns TaskType::Undefined if current task is empty.

Definition at line 290 of file task.hpp.

290 {
291 if (Empty()) [[unlikely]] {
292 return TaskType::Undefined;
293 }
294
295 return details::ConvertTaskType(task_.type());
296}
static constexpr TaskType ConvertTaskType(tf::TaskType type) noexcept
Converts Taskflow task type to Helios task type.
Definition common.hpp:95

◆ WeakDependenciesCount()

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

Gets the number of weak dependencies this task has.

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

Definition at line 274 of file task.hpp.

274 {
275 if (Empty()) [[unlikely]] {
276 return 0;
277 }
278
279 return task_.num_weak_dependencies();
280}

◆ 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 193 of file task.hpp.

193 {
194 HELIOS_ASSERT(!Empty(), "Failed to set task work: Cannot assign work to empty task!");
195 task_.work(std::forward<C>(callable));
196 return *this;
197}

Friends And Related Symbol Documentation

◆ Executor

friend class Executor
friend

Definition at line 189 of file task.hpp.

◆ SubTaskGraph

friend class SubTaskGraph
friend

Definition at line 187 of file task.hpp.

◆ TaskGraph

friend class TaskGraph
friend

Definition at line 186 of file task.hpp.

◆ TaskGraphBuilder

friend class TaskGraphBuilder
friend

Definition at line 188 of file task.hpp.