xoreos  0.0.5
variable.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef AURORA_NWSCRIPT_VARIABLE_H
26 #define AURORA_NWSCRIPT_VARIABLE_H
27 
28 #include <vector>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include "src/common/types.h"
33 
34 #include "src/aurora/types.h"
35 
37 
38 namespace Common {
39  class UString;
40 }
41 
42 namespace Aurora {
43 
44 namespace NWScript {
45 
46 class Object;
47 class EngineType;
48 class ObjectReference;
49 
50 struct ScriptState {
52  std::vector<class Variable> globals;
53  std::vector<class Variable> locals;
54 };
55 
56 class Variable {
57 public:
58  typedef std::vector< boost::shared_ptr<Variable> > Array;
59 
60  Variable(Type type = kTypeVoid);
61  Variable(int32 value);
62  Variable(float value);
63  Variable(const Common::UString &value);
64  Variable(Object *value);
65  Variable(const ObjectReference &value);
66  Variable(const EngineType *value);
67  Variable(const EngineType &value);
68  Variable(float x, float y, float z);
69  Variable(const Variable &var);
70  ~Variable();
71 
72  void setType(Type type);
73 
74  Variable &operator=(const Variable &var);
75 
76  Variable &operator=(int32 value);
77  Variable &operator=(float value);
78  Variable &operator=(const Common::UString &value);
79  Variable &operator=(Object *value);
80  Variable &operator=(const ObjectReference &value);
81  Variable &operator=(const EngineType *value);
82  Variable &operator=(const EngineType &value);
83 
84  bool operator==(const Variable &var) const;
85  bool operator!=(const Variable &var) const;
86 
87  Type getType() const;
88 
89  int32 getInt() const;
90  float getFloat() const;
92  const Common::UString &getString() const;
93  Object *getObject() const;
94  EngineType *getEngineType() const;
95 
96  void setVector(float x, float y, float z);
97  void getVector(float &x, float &y, float &z) const;
98 
99  const Array &getArray() const;
100  Array &getArray();
101 
102  size_t getArraySize() const;
103 
104  void growArray(Type type, size_t size);
105 
107  const ScriptState &getScriptState() const;
108 
109  Variable *getReference() const;
110  void setReference(Variable *reference);
111 
112 private:
114 
115  union {
117  float _float;
120  float _vector[3];
124  } _value;
125 
126  boost::shared_ptr<Array> _array;
127 };
128 
129 } // End of namespace NWScript
130 
131 } // End of namespace Aurora
132 
133 #endif // AURORA_NWSCRIPT_VARIABLE_H
void setReference(Variable *reference)
Definition: variable.cpp:415
std::vector< boost::shared_ptr< Variable > > Array
Definition: variable.h:58
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
boost::shared_ptr< Array > _array
Definition: variable.h:126
void growArray(Type type, size_t size)
Definition: variable.cpp:380
ScriptState * _scriptState
Definition: variable.h:121
void getVector(float &x, float &y, float &z) const
Definition: variable.cpp:344
union Aurora::NWScript::Variable::@6 _value
EngineType * getEngineType() const
Definition: variable.cpp:328
Object * getObject() const
Definition: variable.cpp:321
size_t getArraySize() const
Definition: variable.cpp:371
void setVector(float x, float y, float z)
Definition: variable.cpp:335
Variable(Type type=kTypeVoid)
Definition: variable.cpp:38
Low-level type definitions to handle fixed width types portably.
bool operator==(const Variable &var) const
Definition: variable.cpp:247
ScriptState & getScriptState()
Definition: variable.cpp:394
ObjectReference * _object
Definition: variable.h:119
Variable & operator=(const Variable &var)
Definition: variable.cpp:161
bool operator!=(const Variable &var) const
Definition: variable.cpp:285
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
void setType(Type type)
Definition: variable.cpp:98
std::vector< class Variable > locals
Definition: variable.h:53
uint32_t uint32
Definition: types.h:204
const Array & getArray() const
Definition: variable.cpp:353
Common::UString & getString()
Definition: variable.cpp:314
Common::UString * _string
Definition: variable.h:118
EngineType * _engineType
Definition: variable.h:122
NWScript types.
std::vector< class Variable > globals
Definition: variable.h:52
Variable * getReference() const
Definition: variable.cpp:408
int32_t int32
Definition: types.h:203