|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Fluent builder for creating dag_job instances. More...
#include <dag_job_builder.h>

Public Member Functions | |
| dag_job_builder (const std::string &name="dag_job") | |
| Constructs a new builder with an optional job name. | |
| dag_job_builder (dag_job_builder &&) noexcept=default | |
| Move constructor. | |
| auto | operator= (dag_job_builder &&) noexcept -> dag_job_builder &=default |
| Move assignment operator. | |
| dag_job_builder (const dag_job_builder &)=delete | |
| Copy constructor (deleted - use move semantics) | |
| auto | operator= (const dag_job_builder &) -> dag_job_builder &=delete |
| Copy assignment operator (deleted - use move semantics) | |
| ~dag_job_builder ()=default | |
| Destructor. | |
| auto | work (std::function< common::VoidResult()> callable) -> dag_job_builder & |
| Sets the work function to execute. | |
| template<typename T > | |
| auto | work_with_result (std::function< common::Result< T >()> callable) -> dag_job_builder & |
| Sets the work function with result. | |
| template<typename T > | |
| auto | returns () -> dag_job_builder & |
| Specifies the result type for the job. | |
| auto | depends_on (job_id dependency) -> dag_job_builder & |
| Adds a single dependency. | |
| auto | depends_on (std::initializer_list< job_id > dependencies) -> dag_job_builder & |
| Adds multiple dependencies from initializer list. | |
| auto | depends_on (const std::vector< job_id > &dependencies) -> dag_job_builder & |
| Adds multiple dependencies from vector. | |
| auto | on_failure (std::function< common::VoidResult()> fallback) -> dag_job_builder & |
| Sets the fallback function for failure recovery. | |
| auto | is_valid () const -> bool |
| Validates the builder configuration. | |
| auto | get_validation_error () const -> std::optional< std::string > |
| Gets the validation error message. | |
| auto | build () -> std::unique_ptr< dag_job > |
| Builds and returns the configured dag_job. | |
| auto | reset () -> dag_job_builder & |
| Resets the builder to its initial state. | |
Private Attributes | |
| std::string | name_ |
| std::function< common::VoidResult()> | work_func_ |
| std::function< common::VoidResult(dag_job &)> | work_with_result_func_ |
| std::function< common::VoidResult()> | fallback_func_ |
| std::vector< job_id > | dependencies_ |
| bool | has_return_type_ {false} |
Fluent builder for creating dag_job instances.
The dag_job_builder provides a convenient way to construct dag_job objects with dependencies, work functions, and other properties using a fluent API.
This class implements the Builder pattern with method chaining (fluent interface). Each setter method returns a reference to the builder, allowing calls to be chained.
Definition at line 56 of file dag_job_builder.h.
|
explicit |
Constructs a new builder with an optional job name.
| name | Human-readable name for the job (default: "dag_job") |
Definition at line 10 of file dag_job_builder.cpp.
|
defaultnoexcept |
Move constructor.
|
delete |
Copy constructor (deleted - use move semantics)
|
default |
Destructor.
|
nodiscard |
Builds and returns the configured dag_job.
Validates the configuration before building. If validation fails, returns nullptr. Use is_valid() to check before building, or get_validation_error() to get the error message.
After calling build(), the builder is reset and can be reused.
Definition at line 74 of file dag_job_builder.cpp.
| auto kcenon::thread::dag_job_builder::depends_on | ( | const std::vector< job_id > & | dependencies | ) | -> dag_job_builder& |
Adds multiple dependencies from vector.
| dependencies | Vector of job IDs to depend on |
Definition at line 42 of file dag_job_builder.cpp.
References kcenon::thread::INVALID_JOB_ID.
| auto kcenon::thread::dag_job_builder::depends_on | ( | job_id | dependency | ) | -> dag_job_builder& |
Adds a single dependency.
| dependency | The job ID to depend on |
Definition at line 21 of file dag_job_builder.cpp.
References kcenon::thread::INVALID_JOB_ID.
| auto kcenon::thread::dag_job_builder::depends_on | ( | std::initializer_list< job_id > | dependencies | ) | -> dag_job_builder& |
Adds multiple dependencies from initializer list.
| dependencies | List of job IDs to depend on |
Definition at line 30 of file dag_job_builder.cpp.
References kcenon::thread::INVALID_JOB_ID.
|
nodiscard |
Gets the validation error message.
Definition at line 65 of file dag_job_builder.cpp.
References work_func_, and work_with_result_func_.
|
nodiscard |
Validates the builder configuration.
Checks that:
Definition at line 60 of file dag_job_builder.cpp.
References work_func_, and work_with_result_func_.
| auto kcenon::thread::dag_job_builder::on_failure | ( | std::function< common::VoidResult()> | fallback | ) | -> dag_job_builder& |
Sets the fallback function for failure recovery.
| fallback | The function to execute on failure |
The fallback function is called when the main work function fails and the DAG scheduler is configured with dag_failure_policy::fallback.
Definition at line 54 of file dag_job_builder.cpp.
References kcenon::thread::fallback.
|
delete |
Copy assignment operator (deleted - use move semantics)
|
defaultnoexcept |
Move assignment operator.
| auto kcenon::thread::dag_job_builder::reset | ( | ) | -> dag_job_builder& |
Resets the builder to its initial state.
Clears all configured settings (work function, dependencies, fallback) while preserving the job name. This allows the builder to be reused for creating multiple jobs.
Definition at line 113 of file dag_job_builder.cpp.
|
inline |
Specifies the result type for the job.
| T | The result type |
This method is used in combination with work() when the work function will set the result manually via the job's set_result() method.
Definition at line 148 of file dag_job_builder.h.
References has_return_type_.
| auto kcenon::thread::dag_job_builder::work | ( | std::function< common::VoidResult()> | callable | ) | -> dag_job_builder& |
Sets the work function to execute.
| callable | The function to execute |
The callable should return common::VoidResult:
Definition at line 15 of file dag_job_builder.cpp.
|
inline |
Sets the work function with result.
| T | The result type |
| callable | The function to execute |
The result will be stored in the job and can be retrieved by dependent jobs.
Definition at line 111 of file dag_job_builder.h.
References kcenon::thread::result< T >::is_ok(), kcenon::thread::result< T >::value(), and work_with_result_func_.

|
private |
Definition at line 228 of file dag_job_builder.h.
|
private |
Definition at line 227 of file dag_job_builder.h.
|
private |
|
private |
Definition at line 224 of file dag_job_builder.h.
|
private |
Definition at line 225 of file dag_job_builder.h.
Referenced by get_validation_error(), and is_valid().
|
private |
Definition at line 226 of file dag_job_builder.h.
Referenced by get_validation_error(), is_valid(), and work_with_result().