joque
task orchestration library
job.hpp
Go to the documentation of this file.
1 #pragma once
23 
24 #include "run_result.hpp"
25 #include "traits.hpp"
26 
27 #include <memory>
28 #include <type_traits>
29 
30 namespace joque
31 {
32 
34 struct job_iface
35 {
37  [[nodiscard]] virtual inval_result is_invalidated() = 0;
38 
40  [[nodiscard]] virtual run_result run( const task& ) = 0;
41 
42  virtual ~job_iface() = default;
43 };
44 
48 template < typename T >
49 struct job : job_iface
50 {
51  T thing;
52 
53  job( T thing )
54  : thing( std::move( thing ) )
55  {
56  }
57 
58  [[nodiscard]] inval_result is_invalidated() override
59  {
61  }
62 
63  [[nodiscard]] run_result run( const task& t ) override
64  {
65  return job_traits< T >::run( t, thing );
66  }
67 };
68 
72 struct job_ptr : std::unique_ptr< job_iface >
73 {
74  job_ptr() = default;
75 
76  template < typename T >
77  job_ptr( T&& item )
78  : std::unique_ptr< job_iface >(
79  new job< std::decay_t< T > >{ std::forward< T >( item ) } )
80  {
81  }
82 
83  job_ptr( const job_ptr& ) = delete;
84  job_ptr& operator=( const job_ptr& ) = delete;
85 
86  job_ptr( job_ptr&& ) noexcept = default;
87  job_ptr& operator=( job_ptr&& ) noexcept = default;
88 };
89 
90 } // namespace joque
MIT License.
Definition: dag.hpp:27
Definition: run_result.hpp:65
TODO: hide this Result of single traits run call.
Definition: run_result.hpp:55
Single task that should be executed by the system.
Definition: task.hpp:49
Job interface used by task and execution.
Definition: job.hpp:35
virtual run_result run(const task &)=0
Executes one run of the task.
virtual ~job_iface()=default
virtual inval_result is_invalidated()=0
Returns true in case the job is invalidated.
Custom unique_ptr wrapper that simplifies syntax of tasks.
Definition: job.hpp:73
job_ptr & operator=(const job_ptr &)=delete
job_ptr(const job_ptr &)=delete
job_ptr(T &&item)
Definition: job.hpp:77
job_ptr()=default
job_ptr(job_ptr &&) noexcept=default
static run_result run(const task &t, T &f)
Definition: traits.hpp:41
static inval_result is_invalidated(const T &)
Definition: traits.hpp:36
Implementation of job interface, storing the specific job type that shall be used.
Definition: job.hpp:50
run_result run(const task &t) override
Executes one run of the task.
Definition: job.hpp:63
job(T thing)
Definition: job.hpp:53
inval_result is_invalidated() override
Returns true in case the job is invalidated.
Definition: job.hpp:58
T thing
Definition: job.hpp:51