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_LUA_VARIABLE_H
26 #define AURORA_LUA_VARIABLE_H
27 
28 #include "src/common/ustring.h"
29 
30 #include "src/aurora/lua/types.h"
31 
32 namespace Aurora {
33 
34 namespace Lua {
35 
36 class Variable {
37 public:
38  Variable(Type type, const Common::UString &exactType = "");
39  Variable(bool value);
40  Variable(int32 value);
41  Variable(float value);
42  Variable(const char *value);
43  Variable(const Common::UString &value);
44  Variable(const TableRef &value);
45  Variable(const FunctionRef &value);
46  Variable(void *value, const Common::UString &exactType);
47  Variable(const Variable &var);
48  ~Variable();
49 
50  void setType(Type type, const Common::UString &exactType = "");
51 
52  Variable &operator=(const Variable &var);
53 
54  Variable &operator=(bool value);
55  Variable &operator=(int32 value);
56  Variable &operator=(float value);
57  Variable &operator=(const char *value);
58  Variable &operator=(const Common::UString &value);
59  Variable &operator=(const TableRef &value);
60  Variable &operator=(const FunctionRef &value);
61  Variable &operator=(void *value);
62 
63  bool operator==(const Variable &var) const;
64  bool operator!=(const Variable &var) const;
65 
66  Type getType() const;
67  const Common::UString &getExactType() const;
68 
69  bool getBool() const;
70  int32 getInt() const;
71  float getFloat() const;
73  const Common::UString &getString() const;
74  TableRef &getTable();
75  const TableRef &getTable() const;
76  const FunctionRef &getFunction() const;
77  void *getRawUserType() const;
78 
79  template<typename T>
80  T *getUserType() const;
81 
82 private:
85 
86  union {
87  bool _bool;
88  float _float;
92  void *_data;
93  } _value;
94 };
95 
96 template<typename T>
97 inline T *Variable::getUserType() const {
98  return reinterpret_cast<T *>(getRawUserType());
99 }
100 
101 } // End of namespace Lua
102 
103 } // End of namespace Aurora
104 
105 #endif // AURORA_LUA_VARIABLE_H
void * getRawUserType() const
Definition: variable.cpp:351
FunctionRef * _function
Definition: variable.h:91
A class holding an UTF-8 string.
Definition: ustring.h:48
int32 getInt() const
Definition: variable.cpp:295
const FunctionRef & getFunction() const
Definition: variable.cpp:343
TableRef & getTable()
Definition: variable.cpp:327
Type getType() const
Definition: variable.cpp:279
void setType(Type type, const Common::UString &exactType="")
Definition: variable.cpp:89
bool operator==(const Variable &var) const
Definition: variable.cpp:246
float getFloat() const
Definition: variable.cpp:303
Common::UString _exactType
Definition: variable.h:84
Common::UString & getString()
Definition: variable.cpp:319
bool getBool() const
Definition: variable.cpp:287
T * getUserType() const
Definition: variable.h:97
union Aurora::Lua::Variable::@5 _value
Variable & operator=(const Variable &var)
Definition: variable.cpp:148
Variable(Type type, const Common::UString &exactType="")
Definition: variable.cpp:35
Lua types.
A reference to a Lua function.
Definition: function.h:35
Unicode string handling.
const Common::UString & getExactType() const
Definition: variable.cpp:283
TableRef * _table
Definition: variable.h:90
A reference to a Lua table.
Definition: table.h:37
Common::UString * _string
Definition: variable.h:89
bool operator!=(const Variable &var) const
Definition: variable.cpp:275
int32_t int32
Definition: types.h:203