ScummVM API documentation
variables.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_VARIABLES_H
29 #define GOB_VARIABLES_H
30 
31 namespace Gob {
32 
33 class Variables {
34 public:
35  enum Type {
36  kVariableType8,
37  kVariableType16,
38  kVariableType32
39  };
40 
41  Variables(uint32 size);
42  virtual ~Variables();
43 
44  uint32 getSize() const;
45 
46  void writeVar8(uint32 var, uint8 value);
47  void writeVar16(uint32 var, uint16 value);
48  void writeVar32(uint32 var, uint32 value);
49 
50  void writeVarString(uint32 var, const char *value);
51 
52  void writeOff8(uint32 offset, uint8 value);
53  void writeOff16(uint32 offset, uint16 value);
54  void writeOff32(uint32 offset, uint32 value);
55 
56  void writeOffString(uint32 offset, const char *value);
57 
58  uint8 readVar8(uint32 var) const;
59  uint16 readVar16(uint32 var) const;
60  uint32 readVar32(uint32 var) const;
61 
62  void readVarString(uint32 var, char *value, uint32 length);
63 
64  uint8 readOff8(uint32 offset) const;
65  uint16 readOff16(uint32 offset) const;
66  uint32 readOff32(uint32 offset) const;
67 
68  void readOffString(uint32 offset, char *value, uint32 length);
69 
70 
71  const uint8 *getAddressVar8(uint32 var) const;
72  uint8 *getAddressVar8(uint32 var);
73 
74  const char *getAddressVarString(uint32 var) const;
75  char *getAddressVarString(uint32 var);
76 
77  const uint8 *getAddressOff8(uint32 offset) const;
78  uint8 *getAddressOff8(uint32 offset);
79 
80  const char *getAddressOffString(uint32 offset) const;
81  char *getAddressOffString(uint32 offset);
82 
83 
84  bool copyTo(uint32 offset, byte *variables, uint32 n) const;
85  bool copyFrom(uint32 offset, const byte *variables, uint32 n);
86 
87 protected:
88  virtual void write8(byte *buf, uint8 data) const = 0;
89  virtual void write16(byte *buf, uint16 data) const = 0;
90  virtual void write32(byte *buf, uint32 data) const = 0;
91 
92  virtual uint8 read8(const byte *buf) const = 0;
93  virtual uint16 read16(const byte *buf) const = 0;
94  virtual uint32 read32(const byte *buf) const = 0;
95 
96 private:
97  uint32 _size;
98  byte *_vars;
99 
100  void clear();
101 };
102 
103 class VariablesLE : public Variables {
104 public:
105  VariablesLE(uint32 size);
106  ~VariablesLE() override;
107 
108 protected:
109  void write8(byte *buf, uint8 data) const override;
110  void write16(byte *buf, uint16 data) const override;
111  void write32(byte *buf, uint32 data) const override;
112 
113  uint8 read8(const byte *buf) const override;
114  uint16 read16(const byte *buf) const override;
115  uint32 read32(const byte *buf) const override;
116 };
117 
118 class VariablesBE : public Variables {
119 public:
120  VariablesBE(uint32 size);
121  ~VariablesBE() override;
122 
123 protected:
124  void write8(byte *buf, uint8 data) const override;
125  void write16(byte *buf, uint16 data) const override;
126  void write32(byte *buf, uint32 data) const override;
127 
128  uint8 read8(const byte *buf) const override;
129  uint16 read16(const byte *buf) const override;
130  uint32 read32(const byte *buf) const override;
131 };
132 
134 public:
136  VariableReference(Variables &vars, uint32 offset,
137  Variables::Type type = Variables::kVariableType32);
139 
140  void set(Variables &vars, uint32 offset, Variables::Type type = Variables::kVariableType32);
141 
142  VariableReference &operator=(uint32 value);
143  VariableReference &operator+=(uint32 value);
144  VariableReference &operator*=(uint32 value);
145  operator uint32();
146 
147 private:
148  Variables *_vars;
149  uint32 _offset;
150  Variables::Type _type;
151 };
152 
154 public:
155  VariableStack(uint32 size);
156  ~VariableStack();
157 
158  void pushData(const Variables &vars, uint32 offset, uint32 size);
159  void pushInt(uint32 value);
160 
161  void pop(Variables &vars, uint32 offset);
162 
163 private:
164  byte *_stack;
165 
166  uint32 _size;
167  uint32 _position;
168 };
169 
170 } // End of namespace Gob
171 
172 #endif // GOB_VARIABLES_H
Definition: variables.h:33
Definition: variables.h:118
Definition: variables.h:103
Definition: variables.h:153
Definition: anifile.h:40
Definition: variables.h:133