YSTest: YMessage.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

YMessage.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_YMessage_h_
29 #define YSL_INC_Core_YMessage_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YObject
33 #include <ctime>
34
35 namespace YSLib
36 {
37
38 namespace Messaging
39 {
40
45 using ID = yimpl(std::uint32_t);
46
51 using Priority = std::uint8_t;
52
57 yconstexpr const Priority NormalPriority(0x80);
58
59
65 class YF_API Message
66 {
67 friend class MessageQueue;
68
69 private:
70 ID id;
71 ValueObject content{}; //消息内容。
72
73 public:
78 Message(ID msg_id = 0)
79 : id(msg_id)
80 {}
86 Message(ID m, const ValueObject& vo)
88 : id(m), content(vo)
89 {}
90 Message(ID m, ValueObject&& vo) ynothrow
91 : id(m), content(std::move(vo))
92 {}
94
98 DefDeCopyCtor(Message)
103 DefDeMoveCtor(Message)
104
105 PDefHOp(Message&, = , const ValueObject& c) ynothrow
106 ImplRet(content = c, *this)
111 PDefHOp(Message&, =, ValueObject&& c) ynothrow
112 ImplRet(content = std::move(c), *this)
117 PDefHOp(Message&, =, Message msg) ynothrow
118 ImplRet(msg.swap(*this), *this)
119
124 DefBoolNeg(explicit, id)
125
130 YF_API friend bool
131 operator==(const Message&, const Message&);
132
133 DefGetter(const ynothrow, ID, MessageID, id)
134 DefGetter(const ynothrow, const ValueObject&, Content, content) \
136
141 void
142 swap(Message&) ynothrow;
143 };
144
149 inline DefSwap(ynothrow, Message)
150
151
158 class YF_API MessageQueue : private noncopyable,
159 private multimap<Priority, Message, std::greater<Priority>>
160 {
161 public:
163 using BaseType = multimap<Priority, Message, std::greater<Priority>>;
169 using BaseType::iterator;
170 using BaseType::const_iterator;
172
176 DefDeCtor(MessageQueue)
177 DefDeDtor(MessageQueue)
178
179
184 DefGetter(const ynothrow, Priority, MaxPriority,
185 empty() ? 0 : cbegin()->first)
186
187
190 void
191 Merge(MessageQueue&);
192
198 void
199 Peek(Message&) const;
200
205 void
206 Pop();
207
212 void
213 Push(const Message&, Priority);
218 void
219 Push(Message&&, Priority);
220
225 void
226 Remove(Priority);
227
229
230 using BaseType::begin;
231
232 using BaseType::cbegin;
233
234 using BaseType::cend;
235
236 using BaseType::clear;
237
238 using BaseType::crbegin;
239
240 using BaseType::crend;
241
242 using BaseType::empty;
243
244 using BaseType::end;
245
246 using BaseType::erase;
247
248 using BaseType::insert;
249
250 using BaseType::max_size;
251
252 using BaseType::rbegin;
253
254 using BaseType::rend;
255
256 using BaseType::size;
258 };
259
260
266 class YF_API MessageException : public LoggedEvent
267 {
268 public:
270 using LoggedEvent::LoggedEvent;
271
273 DefDeCopyCtor(MessageException)
278 ~MessageException() override;
279 };
280
281
287 class YF_API MessageSignal : public MessageException
288 {
289 public:
291
292 MessageSignal(const std::string& msg = {})
293 : MessageException(msg)
294 {}
295
296 DefDeCopyCtor(MessageSignal)
298 ~MessageSignal() override;
300 };
301
302 } // namespace Messaging;
303
304 using Messaging::Message;
305
306 } // namespace YSLib;
307
308 #endif
309
YSLib::Messaging::MessageID
enum MessageSpace{Null=0x0000, Set=0x0003, Quit=0x0012, Bound=0x0014, Task=0x0016, Paint=0x00AF, Input=0x00FF} MessageID
Definition: ymsgdef.h:54
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
platform::containers::string
basic_string< char > string
Definition: Container.h:101
YSLib::LoggedEvent::LoggedEvent
LoggedEvent(const string_view, RecordLevel=Emergent)
Definition: YException.cpp:39
YModules.h
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
ystdex::cpp2014::cend
auto cend(const _tRange &c) -> decltype(std::end(c))
Definition: range.hpp:87
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::Messaging::ID
yimpl(std::uint32_t) ID
消息标识。
Definition: YMessage.h:45
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Messaging::MessageSignal::MessageSignal
MessageSignal(const std::string &msg={})
Definition: YMessage.h:292
YSLib::Messaging::Message::Message
Message(ID msg_id=0)
构造：使用消息标识和空消息内容。
Definition: YMessage.h:78
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:49
YSLib::vo
vo
Definition: YApplication.h:196
DefDeCtor
#define DefDeCtor(_t)
简单通用成员函数定义。
Definition: YBaseMacro.h:156
CHRLib::c
c
Definition: CharacterProcessing.h:81
YSLib::Messaging::NormalPriority
yconstexpr const Priority NormalPriority(0x80)
默认消息优先级。
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:240
YSLib::Messaging::MessageException
消息异常。
Definition: YMessage.h:266
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
std
Definition: memory.hpp:1100
YSLib::Messaging::Message::Message
Message(ID m, ValueObject &&vo) ynothrow
Definition: YMessage.h:90
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:161
ystdex::cpp2014::crend
auto crend(const _tRange &c) -> decltype(ystdex::rend(c))
Definition: range.hpp:150
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:166
YSLib::Messaging::Message::id
ID id
消息标识。
Definition: YMessage.h:70
YSLib::Messaging::Priority
std::uint8_t Priority
消息优先级。
Definition: YMessage.h:51
DefDeDtor
#define DefDeDtor(_t)
Definition: YBaseMacro.h:176
ystdex::noncopyable
不可复制对象：禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: base.h:41
YSLib::Messaging::MessageSignal
消息信号：表示单一处理中断的异常。
Definition: YMessage.h:287
ystdex::empty
auto empty(const _tRange &c) -> decltype(c.empty())
Definition: range.hpp:255
ystdex::cpp2014::rend
auto rend(_tRange &c) -> decltype(c.rend())
Definition: range.hpp:119
DefBoolNeg
#define DefBoolNeg(_spec,...)
定义表示显式转换 bool 操作符及其否定的 operator! 。
Definition: YBaseMacro.h:227
YF_API
#define YF_API
Definition: Platform.h:56
ystdex::cpp2014::crbegin
auto crbegin(const _tRange &c) -> decltype(ystdex::rbegin(c))
Definition: range.hpp:143
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
YSLib::Messaging::Message
消息。
Definition: YMessage.h:65
ystdex::cpp2014::rbegin
auto rbegin(_tRange &c) -> decltype(c.rbegin())
Definition: range.hpp:94
ystdex::cpp2014::cbegin
auto cbegin(const _tRange &c) -> decltype(std::begin(c))
Definition: range.hpp:79
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:272
ystdex::cpp2011::end
_type * end(_type(&&array)[_vN])
Definition: range.hpp:54