ScummVM API documentation
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 
28 #include "mediastation/datafile.h"
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(uint i);
44  void setToFloat(int i);
45  void setToFloat(double d);
46  double asFloat() const;
47  int asIntFromFloat() const;
48 
49  void setToBool(bool b);
50  bool asBool() const;
51 
52  void setToTime(double d);
53  double asTime() const;
54 
55  void setToParamToken(uint paramToken);
56  uint asParamToken() const;
57 
58  void setToAssetId(uint assetId);
59  uint asAssetId() const;
60 
61  void setToString(const Common::String &string);
62  Common::String asString() const;
63 
64  void setToCollection(Common::SharedPtr<Collection> collection);
65  Common::SharedPtr<Collection> asCollection() const;
66 
67  void setToFunctionId(uint functionId);
68  uint asFunctionId() const;
69 
70  void setToMethodId(BuiltInMethod methodId);
71  BuiltInMethod asMethodId() const;
72 
73  bool operator==(const ScriptValue &other) const;
74  bool operator!=(const ScriptValue &other) const;
75  bool operator<(const ScriptValue &other) const;
76  bool operator>(const ScriptValue &other) const;
77  bool operator<=(const ScriptValue &other) const;
78  bool operator>=(const ScriptValue &other) const;
79 
80  bool operator||(const ScriptValue &other) const;
81  bool operator^(const ScriptValue &other) const;
82  bool operator&&(const ScriptValue &other) const;
83 
84  ScriptValue operator+(const ScriptValue &other) const;
85  ScriptValue operator-(const ScriptValue &other) const;
86  ScriptValue operator*(const ScriptValue &other) const;
87  ScriptValue operator/(const ScriptValue &other) const;
88  ScriptValue operator%(const ScriptValue &other) const;
89  ScriptValue operator-() const;
90 
91 private:
92  ScriptValueType _type = kScriptValueTypeEmpty;
93  union {
94  double d = 0;
95  bool b;
96  uint paramToken;
97  uint assetId;
98  uint functionId;
99  BuiltInMethod methodId;
100  } _u;
101  Common::String _string;
102  Common::SharedPtr<Collection> _collection;
103 
104  static bool compare(Opcode op, const ScriptValue &left, const ScriptValue &right);
105  static bool compareEmptyValues(Opcode op);
106  static bool compareStrings(Opcode op, const Common::String &left, const Common::String &right);
107  static bool compare(Opcode op, uint left, uint right);
108  static bool compare(Opcode op, bool left, bool right);
109  static bool compare(Opcode op, double left, double right);
110  static bool compare(Opcode op, Common::SharedPtr<Collection> left, Common::SharedPtr<Collection> right);
111 
112  static ScriptValue evalMathOperation(Opcode op, const ScriptValue &left, const ScriptValue &right);
113  static double binaryMathOperation(Opcode op, double left, double right);
114 
115  void issueValueMismatchWarning(ScriptValueType actualType) const;
116 };
117 
118 } // End of namespace MediaStation
119 
120 #endif
Definition: str.h:59
Definition: asset.h:32
Definition: ptr.h:159
Definition: datafile.h:74
Definition: scriptvalue.h:36