ScummVM API documentation
var.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef BAGEL_BAGLIB_VAR_H
24 #define BAGEL_BAGLIB_VAR_H
25 
26 #include "bagel/baglib/parse_object.h"
27 #include "bagel/boflib/string.h"
28 #include "bagel/boflib/list.h"
29 
30 namespace Bagel {
31 
32 class CBagVar : public CBagParseObject, public CBofObject {
33 public:
34  enum VARTYPE { STRING = 0, NUMBER = 1, BOOLEAN = 2 };
35 
36 private:
37  CBofString _sVarName; // Name of the variable
38  CBofString _sVarValue; // Value of the variable if not a reference
39  VARTYPE _xVarType; // Type of variable, string
40  bool _bGlobal : 1; // Is the variable a constant
41  bool _bConstant : 1; // Is the variable a constant
42  bool _bReference : 1; // Is the variable a reference to an objects state date
43  bool _bTimer : 1; // Is the variable updated on object timer events
44  bool _bRandom : 1; // Is the variable updated as a random number
45  bool _freeze = false;
46 
47 public:
48  CBagVar();
49  CBagVar(const CBofString &sName, const CBofString &sValue, bool bAddToList);
50  virtual ~CBagVar();
51 
52  ParseCodes setInfo(CBagIfstream &) override;
53 
54  const CBofString &getName() {
55  return _sVarName;
56  }
57  // const CBofString& getValue() { return _sVarValue; }
58  const CBofString &getValue();
59  int getNumValue();
60  bool isGlobal() {
61  return _bGlobal;
62  }
63  bool isConstant() {
64  return _bConstant;
65  }
66  bool isNumeric() {
67  return _xVarType == NUMBER;
68  }
69  bool isBoolean() {
70  return _xVarType == BOOLEAN;
71  }
72  bool isString() {
73  return _xVarType == STRING;
74  }
75  bool isReference() {
76  return _bReference;
77  }
78  bool isTimer() {
79  return _bTimer;
80  }
81  bool isRandom() {
82  return _bRandom;
83  }
84  bool isFrozen() const {
85  return _freeze;
86  }
87  VARTYPE getType() {
88  return _xVarType;
89  }
90 
91  // Whenever setting the name, add this object to the hash table.
92  void setName(const CBofString &s);
93  void setValue(const CBofString &s);
94  void setValue(int nVal);
95  void setBoolValue(bool bVal);
96  void setGlobal(bool bVal = true) {
97  _bGlobal = bVal;
98  }
99  void setConstant(bool bVal = true) {
100  _bConstant = bVal;
101  }
102  void setReference(bool bVal = true) {
103  _bReference = bVal;
104  }
105  void setTimer(bool bVal = true) {
106  _bTimer = bVal;
107  }
108  void setRandom(bool bVal = true) {
109  _bRandom = bVal;
110  }
111  void setFreeze(bool bVal = true) {
112  _freeze = bVal;
113  }
114  void setString() {
115  _xVarType = STRING;
116  }
117  void setNumeric() {
118  _xVarType = NUMBER;
119  }
120  void setBoolean() {
121  _xVarType = BOOLEAN;
122  }
123 
124  void increment();
125 };
126 
127 // This could be templated with the storage device manager
128 #define VAR_HASH_TABLE_SIZE 131
129 
130 class CBagVarManager : public CBagParseObject, public CBofObject {
131 private:
132  static int nVarMngrs;
133  CBofList<CBagVar *> _xVarList;
134 
135 public:
136  CBagVarManager();
137  virtual ~CBagVarManager();
138  static void initialize();
139 
140  ErrorCode registerVariable(CBagVar *pVar);
141  ErrorCode unRegisterVariable(CBagVar *pVar);
142  ErrorCode updateRegistration();
143  ErrorCode releaseVariables(bool bIncludeGlobals = true);
144 
145  ErrorCode incrementTimers();
146  CBagVar *getVariable(const CBofString &sName);
147  CBagVar *getVariable(int i) {
148  return _xVarList[i];
149  }
150  int getNumVars() {
151  return _xVarList.getCount();
152  }
153 
154  // Use a hash table to lookup variables.
155  CBofList<CBagVar *> _xVarHashList[VAR_HASH_TABLE_SIZE];
156 };
157 
158 } // namespace Bagel
159 
160 #endif
Definition: object.h:28
Definition: ifstream.h:31
Definition: parse_object.h:45
Definition: var.h:130
Definition: string.h:38
Definition: bagel.h:31
Definition: var.h:32
Definition: list.h:60