class
#include <taskflow/core/task.hpp>
Task class to create a task handle over a node in a taskflow graph
A task is a wrapper over a node in a taskflow graph. It provides a set of methods for users to access and modify the attributes of the associated node in the taskflow graph. A task is very lightweight object (i.e., only storing a node pointer) that can be trivially copied around, and it does not own the lifetime of the associated node.
Constructors, destructors, conversion operators
Public functions
- auto operator=(const Task&) -> Task&
- replaces the contents with a copy of the other task
-
auto operator=(std::
nullptr_t) -> Task& - replaces the contents with a null pointer
- auto operator==(const Task& rhs) const -> bool
- compares if two tasks are associated with the same graph node
- auto operator!=(const Task& rhs) const -> bool
- compares if two tasks are not associated with the same graph node
-
auto name() const -> const std::
string& - queries the name of the task
- auto num_successors() const -> size_t
- queries the number of successors of the task
- auto num_dependents() const -> size_t
- queries the number of predecessors of the task
- auto num_strong_dependents() const -> size_t
- queries the number of strong dependents of the task
- auto num_weak_dependents() const -> size_t
- queries the number of weak dependents of the task
-
auto name(const std::
string& name) -> Task& - assigns a name to the task
-
template<typename C>auto work(C&& callable) -> Task&
- assigns a callable
-
template<typename T>auto composed_of(T& object) -> Task&
- creates a module task from a taskflow
-
template<typename... Ts>auto precede(Ts && ... tasks) -> Task&
- adds precedence links from this to other tasks
-
template<typename... Ts>auto succeed(Ts && ... tasks) -> Task&
- adds precedence links from other tasks to this
- auto data(void* data) -> Task&
- assigns pointer to user data
- void reset()
- resets the task handle to null
- void reset_work()
- resets the associated work to a placeholder
- auto empty() const -> bool
- queries if the task handle points to a task node
- auto has_work() const -> bool
- queries if the task has a work assigned
-
template<typename V>void for_each_successor(V&& visitor) const
- applies an visitor callable to each successor of the task
-
template<typename V>void for_each_dependent(V&& visitor) const
- applies an visitor callable to each dependents of the task
- auto hash_value() const -> size_t
- obtains a hash value of the underlying node
- auto type() const -> TaskType
- returns the task type
-
void dump(std::
ostream& ostream) const - dumps the task through an output stream
- auto data() const -> void*
- queries pointer to user data
Function documentation
Task& tf:: Task:: name(const std:: string& name)
assigns a name to the task
Parameters | |
---|---|
name | a std:: |
Returns | *this |
template<typename T>
Task& tf:: Task:: composed_of(T& object)
creates a module task from a taskflow
Template parameters | |
---|---|
T | object type |
Parameters | |
object | a custom object that defines T::graph() method |
Returns | *this |
Task& tf:: Task:: data(void* data)
assigns pointer to user data
Parameters | |
---|---|
data | pointer to user data |
Returns | *this |
The following example shows how to attach user data to a task and run the task iteratively while changing the data value:
tf::Executor executor; tf::Taskflow taskflow("attach data to a task"); int data; // create a task and attach it the data auto A = taskflow.placeholder(); A.data(&data).work([A](){ auto d = *static_cast<int*>(A.data()); std::cout << "data is " << d << std::endl; }); // run the taskflow iteratively with changing data for(data = 0; data<10; data++){ executor.run(taskflow).wait(); }