YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ymsg.cpp
浏览该文件的文档.
1 /*
2  © 2009-2013 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_YMessage
30 #include <ystdex/algorithm.hpp>
31 
32 namespace YSLib
33 {
34 
35 namespace Messaging
36 {
37 
38 void
39 Message::swap(Message& msg) ynothrow
40 {
41  std::swap(id, msg.id),
42  content.swap(msg.content);
43 }
44 
45 bool
46 operator==(const Message& x, const Message& y)
47 {
48  return x.id == y.id && x.content == y.content;
49 }
50 
51 
52 void
53 MessageQueue::Merge(MessageQueue& mq)
54 {
55  std::for_each(mq.begin(), mq.end(), [this](decltype(*mq.begin())& pr){
56  if(pr.second)
57  insert(std::move(pr));
58  });
59  mq.clear();
60 }
61 
62 void
63 MessageQueue::Peek(Message& msg) const
64 {
65  if(!empty())
66  msg = begin()->second;
67 }
68 
69 void
70 MessageQueue::Pop()
71 {
72  if(!empty())
73  erase(begin());
74 }
75 
76 void
77 MessageQueue::Push(const Message& msg, Priority prior)
78 {
79  if(msg)
80  insert(make_pair(prior, msg));
81 }
82 void
83 MessageQueue::Push(Message&& msg, Priority prior)
84 {
85  if(msg)
86  insert(make_pair(prior, std::move(msg)));
87 }
88 
89 void
90 MessageQueue::Remove(Priority p)
91 {
92  erase(upper_bound(p), end());
93 }
94 
95 } // namespace Messaging;
96 
97 } // namespace YSLib;
98 
ValueObject content
Definition: ymsg.h:72
ID id
消息标识。
Definition: ymsg.h:71
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
泛型算法。
bool operator==(const Message &x, const Message &y)
Definition: ymsg.cpp:46
u8 Priority
消息优先级。
Definition: ymsg.h:52