YSTest: yapp.h 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
yapp.h
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2009 - 2013.
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_yapp_h_
29 #define YSL_INC_Core_yapp_h_ 1
30
31 #include "yfilesys.h"
32 #include "yshell.h"
33
34 YSL_BEGIN
35
36 using Messaging::MessageQueue;
37
42 class YF_API Application : public Shell
43 {
44 public:
45 MessageQueue Queue;
46
47 protected:
52 shared_ptr<Shell> hShell;
53
54 public:
55 //标准程序实例事件。
56 std::function<void()> ApplicationExit;
57 // std::function<void()> Idle;
58
62 Application();
63
67 virtual
68 ~Application();
69
73 DefGetter(const ynothrow, shared_ptr<Shell>, ShellHandle, hShell)
74
75
80 void
81 OnGotMessage(const Message&) override;
82
83 //启动线程消息循环。
84 // void
85 // Run(shared_ptr<Shell>);
86
92 bool
93 Switch(shared_ptr<Shell>&) ynothrow;
100 bool
101 Switch(shared_ptr<Shell>&& h) ynothrow
102 {
103 return Switch(h);
104 }
105 };
106
107
114 extern YF_API Application&
115 FetchAppInstance() ynothrow;
116
122 inline shared_ptr<Shell>
123 FetchShellHandle() ynothrow
124 {
125 return FetchAppInstance().GetShellHandle();
126 }
127
134 inline bool
135 Activate(const shared_ptr<Shell>& hShl)
136 {
137 YAssert(bool(hShl), "Null shell handle found.");
138
139 auto h(hShl);
140
141 return FetchAppInstance().Switch(h);
142 }
143
144
151
152 YF_API void
153 PostMessage(const Message&, Messaging::Priority) ynothrow;
155 inline void
156 PostMessage(Messaging::ID id, Messaging::Priority prior,
157 const ValueObject& vo = {}) ynothrow
158 {
159 PostMessage(Message(id, vo), prior);
160 }
162 inline void
163 PostMessage(Messaging::ID id, Messaging::Priority prior, ValueObject&& c)
164 ynothrow
165 {
166 PostMessage(Message(id, std::move(c)), prior);
167 }
169 template<Messaging::MessageID _vID>
170 inline void
171 PostMessage(Messaging::Priority prior,
172 const typename Messaging::SMessageMap<_vID>::TargetType& target) ynothrow
173 {
174 PostMessage(_vID, prior, ValueObject(target));
175 }
177
181 YF_API void
182 PostQuitMessage(int nExitCode, Messaging::Priority p = 0xF0);
183
184 YSL_END
185
186 #endif
187