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  int asIntFromFloat() const;
49 
50  void setToBool(bool b);
51  bool asBool() const;
52 
53  void setToTime(double d);
54  double asTime() const;
55 
56  void setToParamToken(uint paramToken);
57  uint asParamToken() const;
58 
59  void setToActorId(uint actorId);
60  uint asActorId() const;
61 
62  void setToString(const Common::String &string);
63  Common::String asString() const;
64 
65  void setToCollection(Collection *collection);
66  Collection *asCollection() const;
67 
68  void setToFunctionId(uint functionId);
69  uint asFunctionId() const;
70 
71  void setToMethodId(BuiltInMethod methodId);
72  BuiltInMethod asMethodId() const;
73 
74  Common::String getDebugString() const;
75 
76  void operator=(const ScriptValue &other);
77  bool operator==(const ScriptValue &other) const;
78  bool operator!=(const ScriptValue &other) const;
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 
84  bool operator||(const ScriptValue &other) const;
85  bool operator^(const ScriptValue &other) const;
86  bool operator&&(const ScriptValue &other) const;
87 
88  ScriptValue operator+(const ScriptValue &other) const;
89  ScriptValue operator-(const ScriptValue &other) const;
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;
94 
95 private:
96  ScriptValueType _type = kScriptValueTypeEmpty;
97  union {
98  double d = 0;
99  bool b;
100  uint paramToken;
101  uint actorId;
102  uint functionId;
103  BuiltInMethod methodId;
104  } _u;
105  Common::String _string;
106  Collection *_collection = nullptr;
107  void clearCollection();
108  void copyFrom(const ScriptValue &other);
109 
110  static bool compare(Opcode op, const ScriptValue &left, const ScriptValue &right);
111  static bool compareEmptyValues(Opcode op);
112  static bool compareStrings(Opcode op, const Common::String &left, const Common::String &right);
113  static bool compare(Opcode op, uint left, uint right);
114  static bool compare(Opcode op, bool left, bool right);
115  static bool compare(Opcode op, double left, double right);
116  static bool compare(Opcode op, Collection *left, Collection *right);
117 
118  static ScriptValue evalMathOperation(Opcode op, const ScriptValue &left, const ScriptValue &right);
119  static double binaryMathOperation(Opcode op, double left, double right);
120 };
121 
122 } // End of namespace MediaStation
123 
124 #endif
Definition: str.h:59
Definition: actor.h:33
Definition: collection.h:36
Definition: datafile.h:73
Definition: scriptvalue.h:35