YSTest: ytimer.h 源文件

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
45 class YF_API HighResolutionClock
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
61 HighResolutionClock::now() ynothrow
62 {
63 return time_point(std::chrono::nanoseconds(GetHighResolutionTicks()));
64 }
65
66
72 using Duration = HighResolutionClock::duration;
73
78 using TimePoint = HighResolutionClock::time_point;
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:
104 TimePoint nBase;
105
106 public:
111 Duration Interval;
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
YSLib::Timers::Timer::nBase
TimePoint nBase
时间基点：计时的起点。
Definition: ytimer.h:104
YSLib::UI::Refresh
void Refresh(PaintEventArgs &&) override
刷新：按指定参数绘制界面并更新状态。
DefDeDtor
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
ImplRet
#define ImplRet(...)
Definition: YBaseMacro.h:97
YSLib::Timers::HighResolutionClock::period
duration::period period
Definition: ytimer.h:50
YF_API
#define YF_API
Definition: Platform.h:64
YSLib::Timers::HighResolutionClock::duration
std::chrono::nanoseconds duration
Definition: ytimer.h:48
YSLib::Timers::HighResolutionClock::rep
duration::rep rep
Definition: ytimer.h:49
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
YSLib::Timers::Timer::Interval
Duration Interval
重复刷新有效的最小时间间隔。
Definition: ytimer.h:111
YSLib::Timers::HighResolutionClock::time_point
std::chrono::time_point< HighResolutionClock, duration > time_point
Definition: ytimer.h:51
ystdex::noncopyable
不可复制对象：禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: utility.hpp:75
YSLib::Timers::Delay
YF_API void Delay(const TimeSpan &)
阻塞延时。
Definition: ytimer.cpp:63
ImplExpr
#define ImplExpr(...)
Definition: YBaseMacro.h:93
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
platform::GetHighResolutionTicks
YF_API std::uint64_t GetHighResolutionTicks()
取高精度 tick 数。
Definition: Timer.cpp:157
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
YSLib::Timers::TimePoint
HighResolutionClock::time_point TimePoint
时刻。
Definition: ytimer.h:78
YSLib::Timers::Duration
HighResolutionClock::duration Duration
高精度时间间隔。
Definition: ytimer.h:72
YSLib::Timers::HighResolutionClock
高精度时钟。
Definition: ytimer.h:45
YSLib::Timers::TimeSpan
std::chrono::milliseconds TimeSpan
低精度时间间隔。
Definition: ytimer.h:85
YModules.h
YSLib::Timers::Timer
计时器。
Definition: ytimer.h:100
YSLib::Timers::Activate
void Activate(Timer &tmr)
Definition: ytimer.cpp:118