ScummVM API documentation
saveable_object.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_SAVEABLE_OBJECT_H
23 #define TITANIC_SAVEABLE_OBJECT_H
24 
25 #include "common/scummsys.h"
26 #include "common/array.h"
27 #include "common/hash-str.h"
28 #include "common/list.h"
29 #include "titanic/support/simple_file.h"
30 
31 namespace Titanic {
32 
33 class CSaveableObject;
34 
35 class ClassDef {
36 public:
37  const char *_className;
38  ClassDef *_parent;
39 public:
40  ClassDef(const char *className, ClassDef *parent) :
41  _className(className), _parent(parent) {}
42  virtual ~ClassDef() {}
43  virtual CSaveableObject *create();
44 };
45 
46 template<typename T>
47 class TypeTemplate : public ClassDef {
48 public:
49  TypeTemplate(const char *className, ClassDef *parent) :
50  ClassDef(className, parent) {}
51  CSaveableObject *create() override { return new T(); }
52 };
53 
54 #define CLASSDEF \
55  static ClassDef *_type; \
56  ClassDef *getType() const override { return _type; }
57 
59  typedef CSaveableObject *(*CreateFunction)();
60 private:
63  static ClassDefList *_classDefs;
64  static ClassListMap *_classList;
65 public:
69  static void initClassList();
70 
74  static void freeClassList();
75 
79  static CSaveableObject *createInstance(const Common::String &name);
80 public:
81  static ClassDef *_type; \
82  virtual ClassDef *getType() const { return _type; }
83 
84  virtual ~CSaveableObject() {}
85 
86  bool isInstanceOf(const ClassDef *classDef) const;
87 
91  virtual void save(SimpleFile *file, int indent);
92 
96  virtual void load(SimpleFile *file);
97 
102  virtual void saveHeader(SimpleFile *file, int indent);
103 
108  virtual void saveFooter(SimpleFile *file, int indent);
109 };
110 
111 } // End of namespace Titanic
112 
113 #endif /* TITANIC_SAVEABLE_OBJECT_H */
Definition: str.h:59
Definition: list.h:44
Definition: simple_file.h:49
Definition: saveable_object.h:35
Definition: saveable_object.h:47
Definition: hashmap.h:85
Definition: arm.h:30
Definition: saveable_object.h:58