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/spacebar/baglib/parse_object.h"
27 #include "bagel/boflib/string.h"
28 #include "bagel/spacebar/boflib/list.h"
29 
30 namespace Bagel {
31 namespace SpaceBar {
32 
33 class CBagVar : public CBagParseObject, public CBofObject {
34 public:
35  enum VARTYPE {
36  STRING = 0, NUMBER = 1, BOOLEAN = 2
37  };
38 
39 private:
40  CBofString _sVarName; // Name of the variable
41  CBofString _sVarValue; // Value of the variable if not a reference
42  VARTYPE _xVarType; // Type of variable, string
43  bool _bGlobal : 1; // Is the variable a constant
44  bool _bConstant : 1; // Is the variable a constant
45  bool _bReference : 1; // Is the variable a reference to an objects state date
46  bool _bTimer : 1; // Is the variable updated on object timer events
47  bool _bRandom : 1; // Is the variable updated as a random number
48  bool _freeze = false;
49 
50 public:
51  CBagVar();
52  CBagVar(const CBofString &sName, const CBofString &sValue, bool bAddToList);
53  virtual ~CBagVar();
54 
55  ParseCodes setInfo(CBagIfstream &) override;
56 
57  const CBofString &getName() {
58  return _sVarName;
59  }
60  // const CBofString& getValue() { return _sVarValue; }
61  const CBofString &getValue();
62  int getNumValue();
63  bool isGlobal() {
64  return _bGlobal;
65  }
66  bool isConstant() {
67  return _bConstant;
68  }
69  bool isNumeric() {
70  return _xVarType == NUMBER;
71  }
72  bool isBoolean() {
73  return _xVarType == BOOLEAN;
74  }
75  bool isString() {
76  return _xVarType == STRING;
77  }
78  bool isReference() {
79  return _bReference;
80  }
81  bool isTimer() {
82  return _bTimer;
83  }
84  bool isRandom() {
85  return _bRandom;
86  }
87  bool isFrozen() const {
88  return _freeze;
89  }
90  VARTYPE getType() {
91  return _xVarType;
92  }
93 
94  // Whenever setting the name, add this object to the hash table.
95  void setName(const CBofString &s);
96  void setValue(const CBofString &s);
97  void setValue(int nVal);
98  void setBoolValue(bool bVal);
99  void setGlobal(bool bVal = true) {
100  _bGlobal = bVal;
101  }
102  void setConstant(bool bVal = true) {
103  _bConstant = bVal;
104  }
105  void setReference(bool bVal = true) {
106  _bReference = bVal;
107  }
108  void setTimer(bool bVal = true) {
109  _bTimer = bVal;
110  }
111  void setRandom(bool bVal = true) {
112  _bRandom = bVal;
113  }
114  void setFreeze(bool bVal = true) {
115  _freeze = bVal;
116  }
117  void setString() {
118  _xVarType = STRING;
119  }
120  void setNumeric() {
121  _xVarType = NUMBER;
122  }
123  void setBoolean() {
124  _xVarType = BOOLEAN;
125  }
126 
127  void increment();
128 };
129 
130 // This could be templated with the storage device manager
131 #define VAR_HASH_TABLE_SIZE 131
132 
133 class CBagVarManager : public CBagParseObject, public CBofObject {
134 private:
135  static int nVarMngrs;
136  CBofList<CBagVar *> _xVarList;
137 
138 public:
139  CBagVarManager();
140  virtual ~CBagVarManager();
141  static void initialize();
142 
143  ErrorCode registerVariable(CBagVar *pVar);
144  ErrorCode unRegisterVariable(CBagVar *pVar);
145  ErrorCode updateRegistration();
146  ErrorCode releaseVariables(bool bIncludeGlobals = true);
147 
148  ErrorCode incrementTimers();
149  CBagVar *getVariable(const CBofString &sName);
150  CBagVar *getVariable(int i) {
151  return _xVarList[i];
152  }
153  int getNumVars() {
154  return _xVarList.getCount();
155  }
156 
157  // Use a hash table to lookup variables.
158  CBofList<CBagVar *> _xVarHashList[VAR_HASH_TABLE_SIZE];
159 };
160 
161 } // namespace SpaceBar
162 } // namespace Bagel
163 
164 #endif
Definition: ifstream.h:32
Definition: object.h:28
Definition: parse_object.h:48
Definition: var.h:133
Definition: string.h:38
Definition: afxwin.h:27
Definition: list.h:60
Definition: var.h:33