YSTest: yapp.cpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
yapp.cpp
浏览该文件的文档.
1 /*
2 © 2009-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 #include "YSLib/Core/YModules.h"
29 #include YFM_YSLib_Core_YApplication
30
31 namespace YSLib
32 {
33
34 Application::Application()
35 : Shell(), qMain(), hShell()
36 {}
37 Application::~Application()
38 {
39 // NOTE: It is necessary to cleanup to make sure all shells are destroyed.
40 qMain.clear();
41 // hShell = {};
42 // NOTE: All shells must have been released.
43 YAssert(!hShell, "Active shell found.");
44 if(ApplicationExit)
45 ApplicationExit();
46 }
47
48 void
49 Application::OnGotMessage(const Message& msg)
50 {
51 const auto hShl(GetShellHandle());
52
53 YAssert(bool(hShl), "Null handle found.");
54 try
55 {
56 hShl->OnGotMessage(msg);
57 }
58 catch(Messaging::MessageSignal&)
59 {}
60 }
61
62 bool
63 Application::Switch(shared_ptr<Shell>& h) ynothrow
64 {
65 if(YB_LIKELY(hShell != h))
66 {
67 std::swap(hShell, h);
68 return true;
69 }
70 return false;
71 }
72
73
74 void
75 PostMessage(const Message& msg, Messaging::Priority prior) ynothrow
76 {
77 FetchAppInstance().AccessQueue([=, &msg](MessageQueue& mq){
78 mq.Push(msg, prior);
79 });
80 }
81
82 void
83 PostQuitMessage(int nExitCode, Messaging::Priority prior)
84 {
85 PostMessage<SM_Set>(prior, shared_ptr<Shell>());
86 PostMessage<SM_Quit>(prior, nExitCode);
87 }
88
89 } // namespace YSLib;
90
YSLib::FetchAppInstance
YF_API Application & FetchAppInstance() ynothrow
取应用程序实例。
Definition: GUIApplication.cpp:135
YSLib::PostMessage
YF_API void PostMessage(const Message &, Messaging::Priority) ynothrow
全局默认队列消息发送函数。
Definition: yapp.cpp:75
YModules.h
YSLib::PostQuitMessage
YF_API void PostQuitMessage(int nExitCode, Messaging::Priority p=0xF0)
以优先级 p 发起 Shell 终止请求，返回 nExitCode。
Definition: yapp.cpp:83
YSLib::Application::Application
Application()
无参数构造。
Definition: yapp.cpp:34
YSLib::Application::ApplicationExit
std::function< void()> ApplicationExit
资源释放函数。
Definition: yapp.h:71
YSLib::Application::hShell
shared_ptr< Shell > hShell
当前 Shell 句柄：指示当前线程空间中运行的 Shell 。
Definition: yapp.h:67
ystdex::swap
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::Application::~Application
virtual ~Application()
析构：释放 Shell 所有权和其它资源。
Definition: yapp.cpp:37
YB_LIKELY
#define YB_LIKELY(expr)
Definition: ydef.h:297
YSLib::Application::OnGotMessage
void OnGotMessage(const Message &) override
处理消息：分发消息。
Definition: yapp.cpp:49
YSLib::Application::qMain
MessageQueue qMain
Definition: yapp.h:62
YSLib::Messaging::Priority
u8 Priority
消息优先级。
Definition: ymsg.h:52
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:73
YSLib::Messaging::MessageSignal
消息信号：表示单一处理中断的异常。
Definition: ymsg.h:288
YSLib::Application::Switch
bool Switch(shared_ptr< Shell > &) ynothrow
线程切换：若参数非空，和线程空间中当前运行的 Shell 的句柄交换。
Definition: yapp.cpp:63