YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ytimer.h
浏览该文件的文档.
1 /*
2  © 2010-2014 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_Service_ytimer_h_
29 #define YSL_INC_Service_ytimer_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YShellDefinition
33 #include <chrono>
34 
35 namespace YSLib
36 {
37 
38 namespace Timers
39 {
40 
46 {
47 public:
48  using duration = std::chrono::nanoseconds;
49  using rep = duration::rep;
50  using period = duration::period;
51  using time_point = std::chrono::time_point<HighResolutionClock, duration>;
52 
53  static yconstexpr bool is_steady = {};
54 
56  static time_point
57  now() ynothrow;
58 };
59 
60 inline HighResolutionClock::time_point
62 {
63  return time_point(std::chrono::nanoseconds(GetHighResolutionTicks()));
64 }
65 
66 
73 
79 
85 using TimeSpan = std::chrono::milliseconds;
86 
87 
92 YF_API void
93 Delay(const TimeSpan&);
94 
95 
100 class YF_API Timer : private noncopyable
101 {
102 protected:
105 
106 public:
112 
117  explicit
118  Timer(const Duration& = {}, bool = true);
120  virtual DefDeDtor(Timer)
121 
122  DefGetter(const ynothrow, TimePoint, BaseTick, nBase)
123 
125  YF_API friend void
126  Activate(Timer&);
127 
133  PDefH(void, Delay, const Duration& d)
134  ImplExpr(nBase += d)
135 
141  bool
142  Refresh();
143 
150  Duration
151  RefreshDelta();
152 
159  Duration
160  RefreshRemainder();
161 };
162 
168 inline PDefH(bool, CheckTimeout, Timer& tmr) ynothrow
169  ImplRet(tmr.Interval == Duration::zero() || tmr.Refresh())
170 
176 inline PDefH(bool, Test, const Timer& tmr) ynothrow
177  ImplRet(HighResolutionClock::now() < tmr.GetBaseTick() + tmr.Interval)
178 
179 } // namespace Timers;
180 
181 } // namespace YSLib;
182 
183 #endif
184 
TimePoint nBase
时间基点:计时的起点。
Definition: ytimer.h:104
void Refresh(PaintEventArgs &&) override
刷新:按指定参数绘制界面并更新状态。
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
#define ImplRet(...)
Definition: YBaseMacro.h:97
#define YF_API
Definition: Platform.h:64
std::chrono::nanoseconds duration
Definition: ytimer.h:48
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
Duration Interval
重复刷新有效的最小时间间隔。
Definition: ytimer.h:111
std::chrono::time_point< HighResolutionClock, duration > time_point
Definition: ytimer.h:51
不可复制对象:禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: utility.hpp:75
YF_API void Delay(const TimeSpan &)
阻塞延时。
Definition: ytimer.cpp:63
#define ImplExpr(...)
Definition: YBaseMacro.h:93
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YF_API std::uint64_t GetHighResolutionTicks()
取高精度 tick 数。
Definition: Timer.cpp:157
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
HighResolutionClock::time_point TimePoint
时刻。
Definition: ytimer.h:78
HighResolutionClock::duration Duration
高精度时间间隔。
Definition: ytimer.h:72
高精度时钟。
Definition: ytimer.h:45
std::chrono::milliseconds TimeSpan
低精度时间间隔。
Definition: ytimer.h:85
计时器。
Definition: ytimer.h:100
void Activate(Timer &tmr)
Definition: ytimer.cpp:118