ScummVM API documentation
sys_class.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 /*
23  * This file is based on WME Lite.
24  * http://dead-code.org/redir.php?target=wmelite
25  * Copyright (c) 2011 Jan Nedoma
26  */
27 
28 #ifndef WINTERMUTE_SYSCLASS_H
29 #define WINTERMUTE_SYSCLASS_H
30 
31 #include "engines/wintermute/persistent.h"
32 #include "engines/wintermute/dctypes.h"
33 #include "common/hashmap.h"
34 #include "common/func.h"
35 #include "common/stream.h"
36 
37 namespace Wintermute {
38 class SystemInstance;
39 class BaseGame;
40 class BasePersistenceManager;
41 class SystemClass;
42 
43 }
44 
45 namespace Common {
46 template<typename T> struct Hash;
47 
48 template<> struct Hash<void *> : public UnaryFunction<void *, uint> {
49  uint operator()(void *val) const {
50  return (uint)((size_t)val);
51  }
52 };
53 
54 template<> struct Hash<Wintermute::SystemInstance *> : public UnaryFunction<Wintermute::SystemInstance *, uint> {
55  uint operator()(Wintermute::SystemInstance *val) const {
56  return (uint)((size_t)val);
57  }
58 };
59 
60 
61 }
62 
63 namespace Wintermute {
64 
65 class SystemClass {
66 public:
67  SystemClass(const AnsiString &name, PERSISTBUILD build, PERSISTLOAD load, bool persistentClass);
68  ~SystemClass();
69 
70  int getNumInstances();
71  bool removeInstance(void *instance);
72  SystemInstance *addInstance(void *instance, int id, int savedId = -1);
73  bool removeAllInstances();
74 
75  int getInstanceID(void *pointer);
76  void *idToPointer(int savedID);
77 
78  void setID(int id) {
79  _iD = id;
80  }
81  int getID() const {
82  return _iD;
83  }
84 
85  int getSavedID() const {
86  return _savedID;
87  }
88 
89  bool isPersistent() const {
90  return _persistent;
91  }
92 
93  AnsiString getName() const {
94  return _name;
95  }
96 
97  void saveTable(BaseGame *Game, BasePersistenceManager *PersistMgr);
98  void loadTable(BaseGame *Game, BasePersistenceManager *PersistMgr);
99 
100  void saveInstances(BaseGame *Game, BasePersistenceManager *PersistMgr);
101  void loadInstance(void *instance, BasePersistenceManager *PersistMgr);
102 
103  void instanceCallback(SYS_INSTANCE_CALLBACK lpCallback, void *lpData);
104 
105  void resetSavedIDs();
106 
107  void dump(Common::WriteStream *stream);
108 
109 private:
110  int _numInst;
111  bool _persistent;
112  SystemClass *_next;
113  int _iD;
114  int _savedID;
115  AnsiString _name;
116  PERSISTBUILD _build;
117  PERSISTLOAD _load;
118 
119  //typedef std::set<SystemInstance *> Instances;
121  Instances _instances;
122 
124  InstanceMap _instanceMap;
125 };
126 
127 } // End of namespace Wintermute
128 
129 #endif
Definition: base_game.h:76
Definition: str.h:59
Definition: base_persistence_manager.h:56
Definition: stream.h:77
Definition: func.h:527
Definition: sys_class.h:65
Definition: algorithm.h:29
Definition: sys_instance.h:35
Definition: achievements_tables.h:27