ScummVM API documentation
message_target.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA_SHARED_CORE_MESSAGE_TARGET_H
23 #define ULTIMA_SHARED_CORE_MESSAGE_TARGET_H
24 
25 #include "ultima/shared/core/base_object.h"
26 
27 namespace Ultima {
28 namespace Shared {
29 
30 class MessageTarget;
31 class CMessage;
32 
33 typedef bool (MessageTarget:: *PMSG)(CMessage *msg);
34 
35 struct MSGMAP_ENTRY {
36  PMSG _fn;
37  ClassDefFn _classDef;
38 };
39 
40 struct MSGMAP {
41  const MSGMAP *(*pFnGetBaseMap)();
42  const MSGMAP_ENTRY *lpEntries;
43 };
44 
45 #define DECLARE_MESSAGE_MAP \
46 protected: \
47  static const Ultima::Shared::MSGMAP *getThisMessageMap(); \
48  const Ultima::Shared::MSGMAP *getMessageMap() const override
49 
50 #define DECLARE_MESSAGE_MAP_BASE \
51 protected: \
52  static const Ultima::Shared::MSGMAP *getThisMessageMap(); \
53  virtual const Ultima::Shared::MSGMAP *getMessageMap() const
54 
55 #define BEGIN_MESSAGE_MAP(theClass, baseClass) \
56  Ultima::Shared::ClassDef theClass::type() { return Ultima::Shared::ClassDef(#theClass, &baseClass::type); } \
57  const Ultima::Shared::MSGMAP *theClass::getMessageMap() const \
58  { return getThisMessageMap(); } \
59  const Ultima::Shared::MSGMAP *theClass::getThisMessageMap() \
60  { \
61  typedef theClass ThisClass; \
62  typedef baseClass TheBaseClass; \
63  typedef bool (theClass::*FNPTR)(Ultima::Shared::CMessage *msg); \
64  static const Ultima::Shared::MSGMAP_ENTRY _messageEntries[] = {
65 
66 #define ON_MESSAGE(msgClass) \
67  { static_cast<Ultima::Shared::PMSG>((FNPTR)&ThisClass::msgClass), &C##msgClass::type },
68 
69 #define END_MESSAGE_MAP() \
70  { (Ultima::Shared::PMSG)nullptr, nullptr } \
71  }; \
72  static const Ultima::Shared::MSGMAP messageMap = \
73  { &TheBaseClass::getThisMessageMap, &_messageEntries[0] }; \
74  return &messageMap; \
75  }
76 
77 #define EMPTY_MESSAGE_MAP(theClass, baseClass) \
78  Ultima::Shared::ClassDef theClass::type() { return Ultima::Shared::ClassDef(#theClass, &baseClass::type); } \
79  const Ultima::Shared::MSGMAP *theClass::getMessageMap() const \
80  { return getThisMessageMap(); } \
81  const Ultima::Shared::MSGMAP *theClass::getThisMessageMap() \
82  { \
83  typedef baseClass TheBaseClass; \
84  static const Ultima::Shared::MSGMAP_ENTRY _messageEntries[] = { \
85  { (Ultima::Shared::PMSG)nullptr, nullptr } \
86  }; \
87  static const Ultima::Shared::MSGMAP messageMap = \
88  { &TheBaseClass::getThisMessageMap, &_messageEntries[0] }; \
89  return &messageMap; \
90  } \
91  enum { DUMMY##theClass }
92 
97 class MessageTarget: public BaseObject {
98  DECLARE_MESSAGE_MAP_BASE;
99 public:
100  CLASSDEF;
101 };
102 
103 } // End of namespace Shared
104 } // End of namespace Ultima
105 
106 #endif
Definition: message_target.h:97
Definition: message_target.h:35
Definition: message_target.h:40
Definition: detection.h:27
Definition: base_object.h:71