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_ACTIONSCRIPT_VARIABLE_H
26 #define AURORA_ACTIONSCRIPT_VARIABLE_H
27 
28 #include <boost/shared_ptr.hpp>
29 
30 #include "src/common/ustring.h"
31 
33 
34 namespace Aurora {
35 
36 namespace ActionScript {
37 
38 class Object;
39 class Function;
40 
41 typedef boost::shared_ptr<Object> ObjectPtr;
42 
44 class Variable {
45 public:
46  static Variable Null();
47 
48  Variable();
49 
50  Variable(const Common::UString &value);
51  Variable(const char *value);
52  Variable(Object *value);
53  Variable(double value);
54  Variable(unsigned int value);
55  Variable(unsigned long value);
56  Variable(bool value);
57  Variable(ObjectPtr value);
58 
59  Variable(const Variable &variable);
60 
61  ~Variable();
62 
63  bool isUndefined() const;
64  bool isObject() const;
65  bool isString() const;
66  bool isNumber() const;
67  bool isFunction() const;
68 
69  double asNumber() const;
71  const Common::UString &asString() const;
72  bool asBoolean() const;
73 
74  template<typename T> boost::shared_ptr<T> as() const;
75 
76  void operator=(Variable v);
77 
78  bool operator!();
81 
84 
89 
91 
92 private:
94 
95  struct {
97 
98  double number;
99  bool boolean;
100 
102  } _value;
103 };
104 
105 template<typename T> boost::shared_ptr<T> Variable::as() const {
106  return boost::dynamic_pointer_cast<T>(_value.object);
107 }
108 
109 } // End of namespace ActionScript
110 
111 } // End of namespace Aurora
112 
113 #endif // AURORA_ACTIONSCRIPT_VARIABLE_H
Variable operator+(Variable v)
Definition: variable.cpp:225
void operator=(Variable v)
Definition: variable.cpp:152
A class holding an UTF-8 string.
Definition: ustring.h:48
Variable operator/(Variable v)
Definition: variable.cpp:236
Variable operator||(Variable v)
Definition: variable.cpp:190
Variable operator &&(Variable v)
const Common::UString & asString() const
Definition: variable.cpp:137
static Variable Null()
Definition: variable.cpp:33
boost::shared_ptr< T > as() const
Definition: variable.h:105
Variable operator*(Variable v)
Definition: variable.cpp:232
Unicode string handling.
Variable operator-(Variable v)
Definition: variable.cpp:218
Variable operator==(Variable v)
Definition: variable.cpp:197
An action script variable.
Definition: variable.h:44
Types for ActionScript.
struct Aurora::ActionScript::Variable::@0 _value
boost::shared_ptr< Object > ObjectPtr
Definition: object.h:43
Variable operator<(Variable v)
Definition: variable.cpp:211
boost::function< void(class FunctionContext &ctx)> Function
Definition: types.h:56