YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ymsg.h
浏览该文件的文档.
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 #ifndef YSL_INC_Core_ymsg_h_
29 #define YSL_INC_Core_ymsg_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YObject
33 #include YFM_YSLib_Adaptor_YContainer
34 #include <ctime>
35 
36 namespace YSLib
37 {
38 
39 namespace Messaging
40 {
41 
46 using ID = yimpl(u32);
47 
52 using Priority = u8;
53 
59 
60 
67 {
68  friend class MessageQueue;
69 
70 private:
71  ID id;
72  ValueObject content; //消息内容。
73 
74 public:
79  Message(ID msg_id = 0)
80  : id(msg_id)
81  {}
87  Message(ID m, const ValueObject& vo)
89  : id(m), content(vo)
90  {}
92  : id(m), content(std::move(vo))
93  {}
95 
105 
106  PDefHOp(Message&, = , const ValueObject& c) ynothrow
107  ImplRet(content = c, *this)
112  PDefHOp(Message&, =, ValueObject&& c) ynothrow
113  ImplRet(content = std::move(c), *this)
114  /*
115  \brief 统一赋值:使用值参数和交换函数进行复制或转移赋值。
116  \since build 331
117  */
118  PDefHOp(Message&, =, Message msg) ynothrow
119  ImplRet(msg.swap(*this), *this)
120 
125  PDefHOp(bool, !, ) const ynothrow
126  ImplRet(!bool(*this))
127 
132  YF_API friend bool
133  operator==(const Message&, const Message&);
134 
139  explicit DefCvt(const ynothrow, bool, id)
140 
141  DefGetter(const ynothrow, ID, MessageID, id)
142  DefGetter(const ynothrow, const ValueObject&, Content, content) \
144 
145  /*
146  \brief 交换。
147  \since build 409
148  */
149  void
150  swap(Message&) ynothrow;
151 };
152 
157 inline DefSwap(ynothrow, Message)
158 
159 
166 class YF_API MessageQueue : private noncopyable,
167  private multimap<Priority, Message, std::greater<Priority>>
168 {
169 public:
171  using BaseType = multimap<Priority, Message, std::greater<Priority>>;
177  using BaseType::iterator;
178  using BaseType::const_iterator;
180 
184  DefDeCtor(MessageQueue)
185  DefDeDtor(MessageQueue)
186 
187 
192  DefGetter(const ynothrow, Priority, MaxPriority,
193  empty() ? 0 : begin()->first)
194 
195 
198  void
199  Merge(MessageQueue&);
200 
206  void
207  Peek(Message&) const;
208 
213  void
214  Pop();
215 
220  void
221  Push(const Message&, Priority);
226  void
227  Push(Message&&, Priority);
228 
233  void
234  Remove(Priority);
235 
237 
238  using BaseType::begin;
239 
240  using BaseType::cbegin;
241 
242  using BaseType::cend;
243 
244  using BaseType::clear;
245 
246  using BaseType::crbegin;
247 
248  using BaseType::crend;
249 
250  using BaseType::empty;
251 
252  using BaseType::end;
253 
254  using BaseType::erase;
255 
256  using BaseType::insert;
257 
258  using BaseType::max_size;
259 
260  using BaseType::rbegin;
261 
262  using BaseType::rend;
263 
264  using BaseType::size;
266 };
267 
268 
275 {
276 public:
277  MessageException(const std::string& msg = "")
278  : LoggedEvent(msg)
279  {}
280 };
281 
282 
289 {
290 public:
291  MessageSignal(const std::string& msg = "")
292  : MessageException(msg)
293  {}
294 };
295 
296 } // namespace Messaging;
297 
298 using Messaging::Message;
299 
300 } // namespace YSLib;
301 
302 #endif
303 
ValueObject content
Definition: ymsg.h:72
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
static auto first(const _tIterator &i) -> decltype((i->first))
Definition: iterator.hpp:759
#define ImplRet(...)
Definition: YBaseMacro.h:97
std::uint32_t u32
Definition: yadaptor.h:69
MessageException(const std::string &msg="")
Definition: ymsg.h:277
#define DefDeCtor(_t)
Definition: YBaseMacro.h:131
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:136
#define YF_API
Definition: Platform.h:64
enum MessageSpace{Null=0x0000, Set=0x0003, Quit=0x0012, Bound=0x0014, Task=0x0016, Paint=0x00AF, Input=0x00FF} MessageID
Definition: ymsgdef.h:54
MessageSignal(const std::string &msg="")
Definition: ymsg.h:291
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
#define yimpl(...)
实现标签。
Definition: ydef.h:177
值类型对象类。
Definition: yobject.h:281
ID id
消息标识。
Definition: ymsg.h:71
Message(ID msg_id=0)
构造:使用消息标识和空消息内容。
Definition: ymsg.h:79
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
不可复制对象:禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: utility.hpp:75
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:141
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
GSStringTemplate< char >::basic_string string
Definition: ycont.h:164
Message(ID m, ValueObject &&vo) ynothrow
Definition: ymsg.h:91
yconstexpr Priority NormalPriority(0x80)
默认消息优先级。
std::uint8_t u8
通用数据类型。
Definition: yadaptor.h:67
记录日志的异常事件类。
Definition: yexcept.h:58
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:164
u8 Priority
消息优先级。
Definition: ymsg.h:52
消息信号:表示单一处理中断的异常。
Definition: ymsg.h:288
yimpl(u32) ID
消息标识。
Definition: ymsg.h:46