YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ymsgdef.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_ymsgdef_h_
29 #define YSL_INC_CORE_ymsgdef_h_ 1
30 
31 #include "ymsg.h"
32 #include <functional> // for std::function;
33 
35 
36 YSL_BEGIN_NAMESPACE(Messaging)
37 
38 typedef enum MessageSpace
39 {
40  Null = 0x0000,
41  Set = 0x0003,
42 
43  Paint = 0x000F,
44 
45  Quit = 0x0012,
46  Task = 0x0016,
47 
48  Input = 0x00FF
49 
50 } MessageID;
51 
52 
53 #define SM_NULL Messaging::Null
54 #define SM_SET Messaging::Set
55 
56 #define SM_PAINT Messaging::Paint
57 #define SM_QUIT Messaging::Quit
58 
59 #define SM_TASK Messaging::Task
60 
61 #define SM_INPUT Messaging::Input
62 
63 
64 template<MessageID _vID>
66 {};
67 
68 #define DefMessageTarget(_id, _type) \
69  template<> \
70  struct SMessageMap<_id> \
71  { \
72  typedef _type TargetType; \
73  };
74 
76 DefMessageTarget(SM_SET, shared_ptr<Shell>)
78 DefMessageTarget(SM_TASK, std::function<void()>)
80 
81 
82 template<MessageID _vID>
83 inline const typename SMessageMap<_vID>::TargetType&
84 FetchTarget(const Message& msg)
85 {
86  return msg.GetContent().GetObject<typename SMessageMap<_vID>::TargetType>();
87 }
88 
89 YSL_END_NAMESPACE(Messaging)
90 
91 YSL_END
92 
93 #endif
94