3 #ifndef __FUTURE_TASK_HPP__
4 #define __FUTURE_TASK_HPP__
27 template<
typename Fn,
typename... Args>
28 void add(Fn && fn, Args &&... args)
29 { deferreds.push_back([=](
int) {
return fn(args...); }); }
32 template<
typename T,
typename Fn,
typename... Args>
33 void add(T * p, Fn && fn, Args &&... args)
34 { deferreds.push_back([=](
int) {
return std::invoke(fn, p, args...); }); }
41 {
return deferreds.size(); }
45 { deferreds.clear(); }
48 std::vector<std::function<bool(
int)>> deferreds;
72 std::unique_ptr<FutureTask>
createTask()
override;
87 std::unique_ptr<FutureTask>
createTask()
override;
91 std::unique_ptr<Private> priv;
Definition: FutureTask.cpp:63
Base class for an abstract factory of FutureTask.
Definition: FutureTask.hpp:56
virtual std::unique_ptr< FutureTask > createTask()=0
Create a managed FutureTask instance.
virtual ~FutureTaskFactory()=default
Virtual destructor.
Base class for a deferred task executor.
Definition: FutureTask.hpp:21
virtual bool dispatch()=0
Dispatch the registered callbacks and returns their joint result.
virtual ~FutureTask()=default
Virtual destructor.
void clear()
Clear internal list of deferred callbacks.
Definition: FutureTask.hpp:44
void add(Fn &&fn, Args &&... args)
Register a deferred callback given a free function.
Definition: FutureTask.hpp:28
unsigned int size() const
Get the number of registered deferred callbacks.
Definition: FutureTask.hpp:40
void add(T *p, Fn &&fn, Args &&... args)
Register a deferred callback given a generic class instance.
Definition: FutureTask.hpp:33
Abstract factory of ParallelTask.
Definition: FutureTask.hpp:80
ParallelTaskFactory(int threads)
Constructor, creates a pool of threads.
Definition: FutureTask.cpp:76
std::unique_ptr< FutureTask > createTask() override
Create a managed FutureTask instance.
Definition: FutureTask.cpp:87
Abstract factory of SequentialTask.
Definition: FutureTask.hpp:70
std::unique_ptr< FutureTask > createTask() override
Create a managed FutureTask instance.
Definition: FutureTask.cpp:82
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6