ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
scriptvalue.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MEDIASTATION_MEDIASCRIPT_SCRIPTVALUE_H
23 #define MEDIASTATION_MEDIASCRIPT_SCRIPTVALUE_H
24 
25 #include "common/ptr.h"
26 #include "common/str.h"
27 #include "common/stream.h"
28 
29 #include "mediastation/mediascript/scriptconstants.h"
30 #include "mediastation/mediascript/collection.h"
31 
32 namespace MediaStation {
33 
34 class Asset;
35 
36 class ScriptValue {
37 public:
38  ScriptValue() : _type(kScriptValueTypeEmpty) {}
40 
41  ScriptValueType getType() const { return _type; }
42 
43  void setToFloat(double d);
44  double asFloat() const;
45 
46  void setToBool(bool b);
47  bool asBool() const;
48 
49  void setToTime(double d);
50  double asTime() const;
51 
52  void setToParamToken(uint paramToken);
53  uint asParamToken() const;
54 
55  void setToAssetId(uint assetId);
56  uint asAssetId() const;
57 
58  void setToString(const Common::String &string);
59  Common::String asString() const;
60 
61  void setToCollection(Common::SharedPtr<Collection> collection);
62  Common::SharedPtr<Collection> asCollection() const;
63 
64  void setToFunctionId(uint functionId);
65  uint asFunctionId() const;
66 
67  void setToMethodId(BuiltInMethod methodId);
68  BuiltInMethod asMethodId() const;
69 
70  bool operator==(const ScriptValue &other) const;
71  bool operator!=(const ScriptValue &other) const;
72  bool operator<(const ScriptValue &other) const;
73  bool operator>(const ScriptValue &other) const;
74  bool operator<=(const ScriptValue &other) const;
75  bool operator>=(const ScriptValue &other) const;
76 
77  bool operator||(const ScriptValue &other) const;
78  bool operator^(const ScriptValue &other) const;
79  bool operator&&(const ScriptValue &other) const;
80 
81  ScriptValue operator+(const ScriptValue &other) const;
82  ScriptValue operator-(const ScriptValue &other) const;
83  ScriptValue operator*(const ScriptValue &other) const;
84  ScriptValue operator/(const ScriptValue &other) const;
85  ScriptValue operator%(const ScriptValue &other) const;
86  ScriptValue operator-() const;
87 
88 private:
89  ScriptValueType _type = kScriptValueTypeEmpty;
90  union {
91  double d = 0;
92  bool b;
93  uint paramToken;
94  uint assetId;
95  uint functionId;
96  BuiltInMethod methodId;
97  } _u;
98  Common::String _string;
100 
101  static bool compare(Opcode op, const ScriptValue &left, const ScriptValue &right);
102  static bool compareEmptyValues(Opcode op);
103  static bool compareStrings(Opcode op, const Common::String &left, const Common::String &right);
104  static bool compare(Opcode op, uint left, uint right);
105  static bool compare(Opcode op, bool left, bool right);
106  static bool compare(Opcode op, double left, double right);
107  static bool compare(Opcode op, Common::SharedPtr<Collection> left, Common::SharedPtr<Collection> right);
108 
109  static ScriptValue evalMathOperation(Opcode op, const ScriptValue &left, const ScriptValue &right);
110  static double binaryMathOperation(Opcode op, double left, double right);
111 
112  void issueValueMismatchWarning(ScriptValueType actualType) const;
113 };
114 
115 } // End of namespace MediaStation
116 
117 #endif
Definition: str.h:59
Definition: asset.h:33
Definition: stream.h:745
Definition: ptr.h:159
Definition: scriptvalue.h:36