ScummVM API documentation
expression.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef BAGEL_BAGLIB_EXPRESSION_H
24 #define BAGEL_BAGLIB_EXPRESSION_H
25 
26 #include "bagel/spacebar/baglib/parse_object.h"
27 #include "bagel/spacebar/baglib/var.h"
28 #include "bagel/spacebar/boflib/list.h"
29 
30 namespace Bagel {
31 namespace SpaceBar {
32 
33 class CBagExpression : public CBagParseObject, public CBofObject {
34 public:
35  enum OPERATION {
36  OP_NONE,
37  OP_ASSIGN,
38  OP_EQUAL,
39  OP_NOT_EQUAL,
40  OP_LESS_THAN,
41  OP_LESS_THAN_EQUAL,
42  OP_GREATER_THAN,
43  OP_GREATER_THAN_EQUAL,
44  OP_PLUS_ASSIGN,
45  OP_MINUS_ASSIGN,
46  OP_CONTAINS,
47  OP_HAS,
48  OP_CURR_SDEV,
49  OP_PLUS,
50  OP_MINUS,
51  OP_MULTIPLY,
52  OP_DIVIDE,
53  OP_AND,
54  OP_OR,
55  OP_MOD,
56  OP_STATUS
57  };
58 
59 private:
60  CBofList<CBagVar *> _varList; // Right hand operator
61  CBofList<OPERATION> _operList; // Operation to be preformed
62  CBagExpression *_prevExpression; // Not null when when this is an enclosed expression
63 
64  bool _prevNegativeFl; // True if the operation should return Negative results
65  bool _negativeFl; // True if the operation should return Negative results
66 
67  bool evaluate(CBagVar *leftHandOper, CBagVar *rightHandOper, OPERATION oper, CBagVar &result);
68 
69 public:
70  static CBagVar *_tempVar; // Used as a default param
71  static void initialize();
72  static void shutdown();
73 
74  CBagExpression(CBagExpression *prevExpr = nullptr, bool prevNegFl = false);
75  virtual ~CBagExpression();
76 
77  bool evaluate(bool negFl = false, CBagVar &result = *_tempVar);
78 
84  bool evalLeftToRight(bool negFl = false, CBagVar &result = *_tempVar);
85 
86  bool negEvaluate(CBagVar &result = *_tempVar);
87 
88  void setNegative(bool b = true) {
89  _negativeFl = b;
90  }
91  bool isNegative() const {
92  return _negativeFl;
93  }
94 
95  CBagVar *getVariable(int itemPos);
96  OPERATION getOperation(int itemPos);
97 
98  ParseCodes setInfo(CBagIfstream &istr) override;
99  ErrorCode getOperatorFromStream(CBagIfstream &istr, OPERATION &oper);
100 
101  CBagExpression *getPrevExpression() const {
102  return _prevExpression;
103  }
104  void setPrevExpression(CBagExpression *expr) {
105  _prevExpression = expr;
106  }
107 
108  virtual bool onAssign(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
109  virtual bool onEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
110  virtual bool onNotEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
111  virtual bool onLessThan(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
112  virtual bool onGreaterThan(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
113  virtual bool onLessThanEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
114  virtual bool onGreaterThanEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
115  virtual bool onPlusAssign(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
116  virtual bool onMinusAssign(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
117  virtual bool onContains(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
118  virtual bool onHas(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
119  virtual bool onCurrSDev(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
120  virtual bool onPlus(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
121  virtual bool onMinus(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
122  virtual bool onMultiply(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
123  virtual bool onDivide(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
124  virtual bool onMod(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
125  virtual bool onAnd(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
126  virtual bool onOr(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
127  virtual bool onStatus(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
128 };
129 
130 } // namespace SpaceBar
131 } // namespace Bagel
132 
133 #endif
Definition: ifstream.h:32
Definition: object.h:28
Definition: parse_object.h:48
bool evalLeftToRight(bool negFl=false, CBagVar &result= *_tempVar)
Definition: afxwin.h:27
Definition: expression.h:33
Definition: list.h:60
Definition: var.h:33