YSTest: YApplication.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

YApplication.h
浏览该文件的文档.
1 /*
2 © 2009-2016 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_YApplication_h_
29 #define YSL_INC_Core_YApplication_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YShell // for Shell, stack,
33 // std::is_nothrow_copy_constructible;
34 #include <ystdex/any.h> // for ystdex::any;
35 #include <ystdex/scope_guard.hpp> // for ystdex::unique_guard;
36
37 namespace YSLib
38 {
39
40 using Messaging::MessageQueue;
41
46 class YF_API Application : public Shell
47 {
48 private:
53 stack<ystdex::any> on_exit{};
54 /*
55 \brief 主消息队列互斥锁。
56 \since build 551
57 */
58 recursive_mutex queue_mutex{};
59
60 protected:
61 /*
62 \brief 主消息队列。
63 \since build 481
64 */
65 MessageQueue qMain{};
70 shared_ptr<Shell> hShell{};
71
72 public:
74 Application();
75
77 ~Application() override;
78
80 DefGetter(const ynothrow, shared_ptr<Shell>, ShellHandle, hShell)
81
82
87 template<typename _func>
88 auto
89 AccessQueue(_func f) -> decltype(f(qMain))
90 {
91 lock_guard<recursive_mutex> lck(queue_mutex);
92
93 return f(qMain);
94 }
95
101 template<typename _tParam>
102 inline void
103 AddExit(_tParam&& arg)
104 {
105 on_exit.push(yforward(arg));
106 }
107
108 template<typename _func>
109 void
110 AddExitGuard(_func f)
111 {
112 static_assert(std::is_nothrow_copy_constructible<_func>(),
113 "Invalid guard function found.");
114
115 TryExpr(AddExit(ystdex::unique_guard(f)))
116 catch(...)
117 {
118 f();
119 throw;
120 }
121 }
123
130 void
131 OnGotMessage(const Message&) override;
132
138 bool
139 Switch(shared_ptr<Shell>&) ynothrow;
146 PDefH(bool, Switch, shared_ptr<Shell>&& h) ynothrow
147 ImplRet(Switch(h))
148 };
149
150
158 extern YF_API Application&
159 FetchAppInstance();
160
166 inline PDefH(shared_ptr<Shell>, FetchShellHandle, ) ynothrow
167 ImplRet(FetchAppInstance().GetShellHandle())
168
175 inline PDefH(bool, Activate, const shared_ptr<Shell>& hShl)
176 ImplRet(FetchAppInstance().Switch(shared_ptr<Shell>(hShl)))
177
178
183 yconstexpr const Messaging::Priority DefaultQuitPriority(0xF0);
184
192 YF_API void
193 PostMessage(const Message&, Messaging::Priority);
194 inline PDefH(void, PostMessage, Messaging::ID id, Messaging::Priority prior,
195 const ValueObject& vo = {})
196 ImplRet(PostMessage(Message(id, vo), prior))
197 inline PDefH(void, PostMessage, Messaging::ID id, Messaging::Priority prior,
198 ValueObject&& c)
199 ImplRet(PostMessage(Message(id, std::move(c)), prior))
200 template<Messaging::MessageID _vID>
201 inline void
202 PostMessage(Messaging::Priority prior,
203 const typename Messaging::SMessageMap<_vID>::TargetType& target)
204 {
205 PostMessage(_vID, prior, ValueObject(target));
206 }
208
213 YF_API void
214 PostQuitMessage(int = 0, Messaging::Priority p = DefaultQuitPriority);
215
216 } // namespace YSLib;
217
218 #endif
219
platform::p
while p p
Definition: YCLib/FileSystem.h:225
YSLib::Messaging::MessageID
enum MessageSpace{Null=0x0000, Set=0x0003, Quit=0x0012, Bound=0x0014, Task=0x0016, Paint=0x00AF, Input=0x00FF} MessageID
Definition: ymsgdef.h:54
YSLib::Application::AddExitGuard
void AddExitGuard(_func f)
Definition: YApplication.h:110
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
YSLib::Activate
Activate
Definition: YApplication.h:175
YSLib::shared_ptr< Shell >
shared_ptr< Shell >
Definition: GUIApplication.h:311
YModules.h
YSLib::PostQuitMessage
YF_API void PostQuitMessage(int=0, Messaging::Priority p=DefaultQuitPriority)
以指定错误码和优先级发起 Shell 终止请求。
Definition: YApplication.cpp:85
YSLib::Messaging::ID
yimpl(std::uint32_t) ID
消息标识。
Definition: YMessage.h:45
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
YSLib::vo
vo
Definition: YApplication.h:196
CHRLib::c
c
Definition: CharacterProcessing.h:81
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::Application
程序实例。
Definition: YApplication.h:46
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
YSLib::Application::AddExit
void AddExit(_tParam &&arg)
Definition: YApplication.h:103
platform::ID
std::uintmax_t ID
YF_Platform_* 宏替换值的公共类型。
Definition: YCommon.h:50
scope_guard.hpp
作用域守护。
YSLib::Messaging::Priority
std::uint8_t Priority
消息优先级。
Definition: YMessage.h:51
ystdex::single_thread::lock_guard
Definition: pseudo_mutex.h:197
YSLib::PostMessage
const shared_ptr< Shell > &hShl ImplRet(FetchAppInstance().Switch(shared_ptr< Shell >(hShl))) yconstexpr const Messaging YF_API void PostMessage(const Message &, Messaging::Priority)
默认退出消息优先级。
Definition: YApplication.cpp:77
YSLib::FetchAppInstance
YF_API Application & FetchAppInstance()
取应用程序实例。
Definition: GUIApplication.cpp:295
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:969
YF_API
#define YF_API
Definition: Platform.h:56
ystdex::single_thread::recursive_mutex
Definition: pseudo_mutex.h:88
YSLib::Application::DefGetter
DefGetter(const ynothrow, shared_ptr< Shell >, ShellHandle, hShell) template< typename _func > auto AccessQueue(_func f) -> decltype(f(qMain))
取得线程空间中当前运行的 Shell 的句柄。
Definition: YApplication.h:80
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
any.h
动态泛型类型。
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:272
ystdex::unique_guard
guard< one_shot< _type > > unique_guard(_type f)
Definition: scope_guard.hpp:92