YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Task.h
浏览该文件的文档.
1 /*
2  © 2013 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #ifndef YSL_INC_Core_Task_h_
29 #define YSL_INC_Core_Task_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YApplication
33 
34 namespace YSLib
35 {
36 
41 template<typename _fCallable>
42 inline void
44 {
45  PostMessage<SM_Task>(prior, yforward(f));
46 }
47 
48 namespace Messaging
49 {
50 
55 template<typename _fCallable>
56 void
57 Renew(_fCallable update, Priority prior = Messaging::NormalPriority)
58 {
59  PostTask([=]{
60  if(update())
61  Messaging::Renew(update, prior);
62  }, prior);
63 }
64 
69 template<typename _fCallable>
70 class GAutoTask
71 {
72  static_assert(std::is_object<_fCallable>::value,
73  "Callable object type is needed.");
74 public:
76  using Callable = _fCallable;
77 
78  _fCallable Update;
80 
82  template<typename _fUpdater>
83  GAutoTask(_fUpdater f, Priority prior = NormalPriority)
84  : Update(f), TaskPriority(prior)
85  {}
86 
87  virtual DefDeDtor(GAutoTask)
88 
89 
90  DefCvt(ynothrow, Callable&, *this)
92  DefCvt(const ynothrow, const Callable&, *this)
93 };
94 
95 } // namespace Messaging;
96 
97 } // namespace YSLib;
98 
99 #endif
100 
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
_fCallable Callable
Definition: Task.h:76
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
void Renew(_fCallable update, Priority prior=Messaging::NormalPriority)
按更新条件和优先级通过消息队列部署任务。
Definition: Task.h:57
virtual DefDeDtor(GAutoTask) DefCvt(ynothrow
_tWidget _fCallable && f
Definition: ywgtevt.h:597
yconstexpr Priority NormalPriority(0x80)
默认消息优先级。
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:164
可执行更新操作的任务。
Definition: Task.h:70
GAutoTask(_fUpdater f, Priority prior=NormalPriority)
Definition: Task.h:83
void PostTask(_fCallable &&f, Messaging::Priority prior=Messaging::NormalPriority)
通过消息队列部署后任务。
Definition: Task.h:43
u8 Priority
消息优先级。
Definition: ymsg.h:52