You.i Engine
YiCallableTask.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_CALLABLE_TASK_H_
3 #define _YI_CALLABLE_TASK_H_
4 
5 #include "thread/YiTask.h"
6 
38 template<typename ResultType = void, typename Callable = void, typename... Args>
39 class CYICallableTask : public CYITask<ResultType>
40 {
41 public:
49  CYICallableTask(Callable callable, Args &&... args);
50 
58  CYICallableTask(CYIFuture<ResultType> future, Callable callable, Args &&... args);
59 
60  virtual ResultType Run() override;
61 
62 private:
63  template<int... Index>
64  inline ResultType Run(std::tuple<typename std::decay<Args>::type...> &arguments, YiIndexSequence<Index...>);
65 
66  inline ResultType Run(std::tuple<typename std::decay<Args>::type...> &arguments);
67 
68  Callable m_callable;
69  std::tuple<typename std::decay<Args>::type...> m_arguments;
70 };
71 
75 template<typename Callable, typename... Args>
76 inline auto YiMakeTask(Callable callable, Args &&... args) -> std::unique_ptr<CYICallableTask<decltype(callable(std::move(args)...)), Callable, Args...>>;
77 
83 template<typename Callable, typename... Args>
84 inline auto YiMakeTask(Callable callable, Args &&... args) -> std::unique_ptr<CYICallableTask<decltype(callable(std::declval<CYITaskBase *>(), std::move(args)...)), Callable, CYITaskBase *, Args...>>;
85 
89 template<typename ResultType, typename Callable, typename... Args>
90 inline auto YiMakeTask(CYIFuture<ResultType> future, Callable callable, Args &&... args) -> std::unique_ptr<CYICallableTask<decltype(callable(std::move(args)...)), Callable, Args...>>;
91 
97 template<typename ResultType, typename Callable, typename... Args>
98 inline auto YiMakeTask(CYIFuture<ResultType> future, Callable callable, Args &&... args) -> std::unique_ptr<CYICallableTask<decltype(callable(std::declval<CYITaskBase *>(), std::move(args)...)), Callable, CYITaskBase *, Args...>>;
99 
104 #include "thread/internal/YiCallableTask.inl"
105 
106 #endif
Definition: YiTask.h:27
auto YiMakeTask(Callable callable, Args &&... args) -> std::unique_ptr< CYICallableTask< decltype(callable(std::move(args)...)), Callable, Args... >>
An utility class used to create a task from a callable object.
Definition: YiCallableTask.h:39
Definition: YiTask.h:148
CYICallableTask(Callable callable, Args &&... args)
Definition: YiTypeTraits.h:617
Definition: YiFuture.h:138
virtual ResultType Run() override