ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
operand.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_OPERAND_H
23 #define MEDIASTATION_MEDIASCRIPT_OPERAND_H
24 
25 #include "common/ptr.h"
26 #include "common/str.h"
27 
28 #include "mediastation/mediascript/scriptconstants.h"
29 #include "mediastation/mediascript/variable.h"
30 
31 namespace MediaStation {
32 
33 class Asset;
34 
35 class Operand {
36 public:
37  Operand() : _type(kOperandTypeEmpty) {}
38  Operand(OperandType type) : _type(type) {}
39 
40  OperandType getType() const {
41  return _type;
42  }
43 
44  void putInteger(int i);
45  int getInteger();
46 
47  void putDouble(double d);
48  double getDouble();
49 
50  void putString(Common::String *string);
51  Common::String *getString();
52 
53  void putVariable(Variable *variable);
54  Variable *getVariable();
55 
56  void putFunctionId(uint functionId);
57  uint getFunctionId();
58 
59  void putMethodId(BuiltInMethod methodId);
60  BuiltInMethod getMethodId();
61 
62  void putAsset(uint32 assetId);
63  Asset *getAsset();
64  uint32 getAssetId();
65 
66  void putCollection(Common::SharedPtr<Collection> collection);
67  Common::SharedPtr<Collection> getCollection();
68 
69  Operand getLiteralValue() const;
70 
71  bool operator==(const Operand &other) const;
72  bool operator<(const Operand &other) const;
73  bool operator>(const Operand &other) const;
74 
75  bool operator||(const Operand &other) const;
76  bool operator!() const;
77  bool operator&&(const Operand &other) const;
78 
79  Operand operator+(const Operand &other) const;
80  Operand operator-(const Operand &other) const;
81  Operand operator*(const Operand &other) const;
82  Operand operator/(const Operand &other) const;
83  Operand operator%(const Operand &other) const;
84  Operand operator-() const;
85 
86 private:
87  bool isInteger() { return getType() == kOperandTypeLiteral1 || getType() == kOperandTypeLiteral2; };
88  bool isDouble() { return getType() == kOperandTypeFloat1 || getType() == kOperandTypeFloat2; };
89  bool isNumber() { return isInteger() || isDouble(); };
90 
91  OperandType _type = kOperandTypeEmpty;
92  union {
93  uint assetId = 0;
94  uint functionId;
95  BuiltInMethod methodId;
96  Common::String *string;
97  Variable *variable;
98  int i;
99  double d;
100  } _u;
101  Common::SharedPtr<Collection> _collection;
102 };
103 
104 } // End of namespace MediaStation
105 
106 #endif
Definition: str.h:59
Definition: asset.h:33
Definition: asset.h:37
Definition: operand.h:35
Definition: variable.h:42
Definition: ptr.h:159