YSTest: YTimer.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

YTimer.h
浏览该文件的文档.
1 /*
2 © 2010-2015 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_YClock
33
34 namespace YSLib
35 {
36
37 namespace Timers
38 {
39
44 template<class _tClock = HighResolutionClock>
45 inline typename _tClock::time_point
46 FetchEpoch()
47 {
48 static auto start_time(_tClock::now());
49
50 return start_time;
51 }
52
57 template<class _tClock = HighResolutionClock>
58 inline typename _tClock::duration
59 FetchElapsed()
60 {
61 return _tClock::now() - Timers::FetchEpoch<_tClock>();
62 }
63
64
69 YF_API void
70 Delay(TimeSpan);
71
72
77 class YF_API Timer
78 {
79 protected:
81 TimePoint nBase;
82
83 public:
88 Duration Interval;
89
94 explicit
95 Timer(Duration = {}, bool = true) ynothrow;
97 DefDeCopyCtor(Timer)
102 virtual ~Timer();
103
105 DefDeCopyAssignment(Timer)
106
107 DefGetter(const ynothrow, TimePoint, BaseTick, nBase)
108
113 friend PDefH(void, Activate, Timer& tmr) ynothrow
114 ImplExpr(tmr.nBase = HighResolutionClock::now())
115
121 PDefH(void, Delay, Duration d)
122 ImplExpr(nBase += d)
123
129 bool
130 Refresh();
131
138 Duration
139 RefreshDelta();
140
147 Duration
148 RefreshRemainder();
149 };
150
156 inline PDefH(bool, CheckTimeout, Timer& tmr) ynothrow
157 ImplRet(tmr.Interval == Duration::zero() || tmr.Refresh())
158
164 inline PDefH(bool, Test, const Timer& tmr) ynothrow
165 ImplRet(HighResolutionClock::now() < tmr.GetBaseTick() + tmr.Interval)
166
167 } // namespace Timers;
168
169 } // namespace YSLib;
170
171 #endif
172
YSLib::Timers::Timer::Interval
Duration Interval
重复刷新有效的最小时间间隔。
Definition: YTimer.h:88
DefDeCopyAssignment
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:186
YSLib::Timers::Timer
计时器。
Definition: YTimer.h:77
YModules.h
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Timers::HighResolutionClock
高精度时钟。
Definition: YClock.h:45
YSLib::Timers::TimePoint
HighResolutionClock::time_point TimePoint
时刻。
Definition: YClock.h:74
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
YSLib::Timers::Delay
YF_API void Delay(TimeSpan)
阻塞延时。
Definition: YTimer.cpp:64
YSLib::Activate
Activate
Definition: YApplication.h:210
YSLib::Timers::FetchElapsed
_tClock::duration FetchElapsed()
取自公共历元以来经历的时间。
Definition: YTimer.h:59
YSLib::Timers::FetchEpoch
_tClock::time_point FetchEpoch()
取公共历元。
Definition: YTimer.h:46
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
Timers
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::Timers::Duration
HighResolutionClock::duration Duration
高精度时间间隔。
Definition: YClock.h:68
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:162
YSLib::Timers::Timer::nBase
TimePoint nBase
时间基点：计时的起点。
Definition: YTimer.h:81
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:139
YSLib::Timers::TimeSpan
std::chrono::duration< Duration::rep, std::milli > TimeSpan
低精度时间间隔。
Definition: YClock.h:81