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 TITANIC_MESSAGE_TARGET_H
23 #define TITANIC_MESSAGE_TARGET_H
24 
25 #include "titanic/core/saveable_object.h"
26 
27 namespace Titanic {
28 
29 class CMessageTarget;
30 class CMessage;
31 
32 typedef bool (CMessageTarget::*PMSG)(CMessage *msg);
33 
34 struct MSGMAP_ENTRY {
35  PMSG _fn;
36  const ClassDef * const *_class;
37 };
38 
39 struct MSGMAP {
40  const MSGMAP *(* pFnGetBaseMap)();
41  const MSGMAP_ENTRY *lpEntries;
42 };
43 
44 #define DECLARE_MESSAGE_MAP \
45 protected: \
46  static const MSGMAP *getThisMessageMap(); \
47  const MSGMAP *getMessageMap() const override
48 
49 #define BEGIN_MESSAGE_MAP(theClass, baseClass) \
50  const MSGMAP *theClass::getMessageMap() const \
51  { return getThisMessageMap(); } \
52  const MSGMAP *theClass::getThisMessageMap() \
53  { \
54  typedef theClass ThisClass; \
55  typedef baseClass TheBaseClass; \
56  typedef bool (theClass::*FNPTR)(CMessage *msg); \
57  static const MSGMAP_ENTRY _messageEntries[] = {
58 
59 #define ON_MESSAGE(msgClass) \
60  { static_cast<PMSG>((FNPTR)&ThisClass::msgClass), &C##msgClass::_type },
61 
62 #define END_MESSAGE_MAP() \
63  { (PMSG)nullptr, nullptr } \
64  }; \
65  static const MSGMAP messageMap = \
66  { &TheBaseClass::getThisMessageMap, &_messageEntries[0] }; \
67  return &messageMap; \
68  }
69 
70 #define EMPTY_MESSAGE_MAP(theClass, baseClass) \
71  const MSGMAP *theClass::getMessageMap() const \
72  { return getThisMessageMap(); } \
73  const MSGMAP *theClass::getThisMessageMap() \
74  { \
75  typedef baseClass TheBaseClass; \
76  static const MSGMAP_ENTRY _messageEntries[] = { \
77  { (PMSG)nullptr, nullptr } \
78  }; \
79  static const MSGMAP messageMap = \
80  { &TheBaseClass::getThisMessageMap, &_messageEntries[0] }; \
81  return &messageMap; \
82  } \
83  enum { DUMMY }
84 
86 protected:
87  static const MSGMAP *getThisMessageMap();
88  virtual const MSGMAP *getMessageMap() const;
89 
90 public:
91  CLASSDEF;
92 
96  void save(SimpleFile *file, int indent) override;
97 
101  void load(SimpleFile *file) override;
102 };
103 
104 } // End of namespace Titanic
105 
106 #endif /* TITANIC_MESSAGE_TARGET_H */
Definition: simple_file.h:49
Definition: saveable_object.h:35
Definition: message_target.h:34
Definition: message_target.h:39
Definition: arm.h:30
Definition: saveable_object.h:58
Definition: message_target.h:85