You.i Engine
YiStaticTask.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_STATIC_TASK_H_
3 #define _YI_STATIC_TASK_H_
4 
5 #include "thread/YiTask.h"
6 
38 template<typename ResultType = void>
39 class CYIStaticTask : public CYITask<ResultType>
40 {
41 public:
45  CYIStaticTask(CYIFuture<ResultType> future, ResultType (*const pFunc)());
46 
51  template<typename P1>
52  CYIStaticTask(CYIFuture<ResultType> future, ResultType (*const pFunc)(P1), P1 funcParam1);
53 
58  template<typename P1, typename P2>
59  CYIStaticTask(CYIFuture<ResultType> future, ResultType (*const pFunc)(P1, P2), P1 funcParam1, P2 funcParam2);
60 
65  template<typename P1, typename P2, typename P3>
66  CYIStaticTask(CYIFuture<ResultType> future, ResultType (*const pFunc)(P1, P2, P3), P1 funcParam1, P2 funcParam2, P3 funcParam3);
67 
72  template<typename P1, typename P2, typename P3, typename P4>
73  CYIStaticTask(CYIFuture<ResultType> future, ResultType (*const pFunc)(P1, P2, P3, P4), P1 funcParam1, P2 funcParam2, P3 funcParam3, P4 funcParam4);
74 
78  CYIStaticTask(ResultType (*const pFunc)());
79 
84  template<typename P1>
85  CYIStaticTask(ResultType (*const pFunc)(P1), P1 funcParam1);
86 
91  template<typename P1, typename P2>
92  CYIStaticTask(ResultType (*const pFunc)(P1, P2), P1 funcParam1, P2 funcParam2);
93 
98  template<typename P1, typename P2, typename P3>
99  CYIStaticTask(ResultType (*const pFunc)(P1, P2, P3), P1 funcParam1, P2 funcParam2, P3 funcParam3);
100 
105  template<typename P1, typename P2, typename P3, typename P4>
106  CYIStaticTask(ResultType (*const pFunc)(P1, P2, P3, P4), P1 funcParam1, P2 funcParam2, P3 funcParam3, P4 funcParam4);
107 
108  virtual ~CYIStaticTask();
109 
110 protected:
116  virtual ResultType Run() override;
117 
118 private:
122  class CYIStaticTaskDataBase
123  {
124  public:
125  virtual ~CYIStaticTaskDataBase();
126  virtual ResultType ExecuteFunction() = 0;
127  };
128 
129 private:
130  std::unique_ptr<CYIStaticTaskDataBase> m_pFunctionData;
131 
132 private:
133  class CYIStaticTaskData0Args : public CYIStaticTaskDataBase
134  {
135  public:
136  CYIStaticTaskData0Args(ResultType (*const pFunc)());
137  virtual ResultType ExecuteFunction() override;
138 
139  private:
140  ResultType (*m_pFunc)();
141  };
142 
143  template<typename P1>
144  class CYIStaticTaskData1Arg : public CYIStaticTaskDataBase
145  {
146  public:
147  CYIStaticTaskData1Arg(ResultType (*const pFunc)(P1), P1 funcParam1);
148  virtual ResultType ExecuteFunction() override;
149 
150  private:
151  ResultType (*m_pFunc)(P1);
152  P1 m_arg1;
153  };
154 
155  template<typename P1, typename P2>
156  class CYIStaticTaskData2Args : public CYIStaticTaskDataBase
157  {
158  public:
159  CYIStaticTaskData2Args(ResultType (*const pFunc)(P1, P2), P1 funcParam1, P2 funcParam2);
160  virtual ResultType ExecuteFunction() override;
161 
162  private:
163  ResultType (*m_pFunc)(P1, P2);
164  P1 m_arg1;
165  P2 m_arg2;
166  };
167 
168  template<typename P1, typename P2, typename P3>
169  class CYIStaticTaskData3Args : public CYIStaticTaskDataBase
170  {
171  public:
172  CYIStaticTaskData3Args(ResultType (*const pFunc)(P1, P2, P3), P1 funcParam1, P2 funcParam2, P3 funcParam3);
173  virtual ResultType ExecuteFunction() override;
174 
175  private:
176  ResultType (*m_pFunc)(P1, P2, P3);
177  P1 m_arg1;
178  P2 m_arg2;
179  P3 m_arg3;
180  };
181 
182  template<typename P1, typename P2, typename P3, typename P4>
183  class CYIStaticTaskData4Args : public CYIStaticTaskDataBase
184  {
185  public:
186  CYIStaticTaskData4Args(ResultType (*const pFunc)(P1, P2, P3, P4), P1 funcParam1, P2 funcParam2, P3 funcParam3, P4 funcParam4);
187  virtual ResultType ExecuteFunction() override;
188 
189  private:
190  ResultType (*m_pFunc)(P1, P2, P3, P4);
191  P1 m_arg1;
192  P2 m_arg2;
193  P3 m_arg3;
194  P4 m_arg4;
195  };
196 };
197 
202 #include "thread/internal/YiStaticTask.inl"
203 
204 #endif // _YI_STATIC_TASK_H_
CYIStaticTask(CYIFuture< ResultType > future, ResultType(*const pFunc)())
An utility class used to create a task from a static function.
Definition: YiStaticTask.h:39
Definition: YiTask.h:148
Definition: YiFuture.h:138
virtual ResultType Run() override
virtual ~CYIStaticTask()