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/str.h"
26 
27 #include "mediastation/datafile.h"
28 #include "mediastation/mediascript/scriptconstants.h"
29 #include "mediastation/mediascript/collection.h"
30 
31 namespace MediaStation {
32 
33 class Actor;
34 
35 class ScriptValue {
36 public:
37  ScriptValue() : _type(kScriptValueTypeEmpty), _collection(nullptr) {}
39  ScriptValue(const ScriptValue &other);
40  ~ScriptValue();
41 
42  ScriptValueType getType() const { return _type; }
43 
44  void setToFloat(uint i);
45  void setToFloat(int i);
46  void setToFloat(double d);
47  double asFloat() const;
48  // Some transitions expect either a float or a time depending on engine version.
49  // To keep things simple, we have a method to try both.
50  double asFloatOrTime() const;
51 
52  void setToBool(bool b);
53  bool asBool() const;
54 
55  void setToTime(double d);
56  double asTime() const;
57 
58  void setToParamToken(uint paramToken);
59  uint asParamToken() const;
60 
61  void setToActorId(uint actorId);
62  uint asActorId() const;
63 
64  void setToString(const Common::String &string);
65  Common::String asString() const;
66 
67  void setToCollection(Collection *collection);
68  Collection *asCollection() const;
69 
70  void setToFunctionId(uint functionId);
71  uint asFunctionId() const;
72 
73  void setToMethodId(BuiltInMethod methodId);
74  BuiltInMethod asMethodId() const;
75 
76  Common::String getDebugString() const;
77 
78  void operator=(const ScriptValue &other);
79  bool operator==(const ScriptValue &other) const;
80  bool operator!=(const ScriptValue &other) const;
81  bool operator<(const ScriptValue &other) const;
82  bool operator>(const ScriptValue &other) const;
83  bool operator<=(const ScriptValue &other) const;
84  bool operator>=(const ScriptValue &other) const;
85 
86  bool operator||(const ScriptValue &other) const;
87  bool operator^(const ScriptValue &other) const;
88  bool operator&&(const ScriptValue &other) const;
89 
90  ScriptValue operator+(const ScriptValue &other) const;
91  ScriptValue operator-(const ScriptValue &other) const;
92  ScriptValue operator*(const ScriptValue &other) const;
93  ScriptValue operator/(const ScriptValue &other) const;
94  ScriptValue operator%(const ScriptValue &other) const;
95  ScriptValue operator-() const;
96 
97 private:
98  ScriptValueType _type = kScriptValueTypeEmpty;
99  union {
100  double d = 0;
101  bool b;
102  uint paramToken;
103  uint actorId;
104  uint functionId;
105  BuiltInMethod methodId;
106  } _u;
107  Common::String _string;
108  Collection *_collection = nullptr;
109  void clearCollection();
110  void copyFrom(const ScriptValue &other);
111 
112  static bool compare(Opcode op, const ScriptValue &left, const ScriptValue &right);
113  static bool compareEmptyValues(Opcode op);
114  static bool compareStrings(Opcode op, const Common::String &left, const Common::String &right);
115  static bool compare(Opcode op, uint left, uint right);
116  static bool compare(Opcode op, bool left, bool right);
117  static bool compare(Opcode op, double left, double right);
118  static bool compare(Opcode op, Collection *left, Collection *right);
119 
120  static ScriptValue evalMathOperation(Opcode op, const ScriptValue &left, const ScriptValue &right);
121  static double binaryMathOperation(Opcode op, double left, double right);
122 };
123 
124 } // End of namespace MediaStation
125 
126 #endif
Definition: str.h:59
Definition: actor.h:34
Definition: collection.h:36
Definition: datafile.h:71
Definition: scriptvalue.h:35