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/baglib/parse_object.h"
27 #include "bagel/baglib/var.h"
28 #include "bagel/boflib/list.h"
29 
30 namespace Bagel {
31 
32 class CBagExpression : public CBagParseObject, public CBofObject {
33 public:
34  enum OPERATION {
35  OP_NONE,
36  OP_ASSIGN,
37  OP_EQUAL,
38  OP_NOT_EQUAL,
39  OP_LESS_THAN,
40  OP_LESS_THAN_EQUAL,
41  OP_GREATER_THAN,
42  OP_GREATER_THAN_EQUAL,
43  OP_PLUS_ASSIGN,
44  OP_MINUS_ASSIGN,
45  OP_CONTAINS,
46  OP_HAS,
47  OP_CURR_SDEV,
48  OP_PLUS,
49  OP_MINUS,
50  OP_MULTIPLY,
51  OP_DIVIDE,
52  OP_AND,
53  OP_OR,
54  OP_MOD,
55  OP_STATUS
56  };
57 
58 private:
59  CBofList<CBagVar *> _varList; // Right hand operator
60  CBofList<OPERATION> _operList; // Operation to be preformed
61  CBagExpression *_prevExpression; // Not null when when this is an enclosed expression
62 
63  bool _prevNegativeFl; // True if the operation should return Negative results
64  bool _negativeFl; // True if the operation should return Negative results
65 
66  bool evaluate(CBagVar *leftHandOper, CBagVar *rightHandOper, OPERATION oper, CBagVar &result);
67 
68 public:
69  static CBagVar *_tempVar; // Used as a default param
70  static void initialize();
71  static void shutdown();
72 
73  CBagExpression(CBagExpression *prevExpr = nullptr, bool prevNegFl = false);
74  virtual ~CBagExpression();
75 
76  bool evaluate(bool negFl = false, CBagVar &result = *_tempVar);
77 
83  bool evalLeftToRight(bool negFl = false, CBagVar &result = *_tempVar);
84 
85  bool negEvaluate(CBagVar &result = *_tempVar);
86 
87  void setNegative(bool b = true) {
88  _negativeFl = b;
89  }
90  bool isNegative() const {
91  return _negativeFl;
92  }
93 
94  CBagVar *getVariable(int itemPos);
95  OPERATION getOperation(int itemPos);
96 
97  ParseCodes setInfo(CBagIfstream &istr) override;
98  ErrorCode getOperatorFromStream(CBagIfstream &istr, OPERATION &oper);
99 
100  CBagExpression *getPrevExpression() const {
101  return _prevExpression;
102  }
103  void setPrevExpression(CBagExpression *expr) {
104  _prevExpression = expr;
105  }
106 
107  virtual bool onAssign(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
108  virtual bool onEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
109  virtual bool onNotEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
110  virtual bool onLessThan(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
111  virtual bool onGreaterThan(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
112  virtual bool onLessThanEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
113  virtual bool onGreaterThanEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
114  virtual bool onPlusAssign(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
115  virtual bool onMinusAssign(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
116  virtual bool onContains(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
117  virtual bool onHas(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
118  virtual bool onCurrSDev(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
119  virtual bool onPlus(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
120  virtual bool onMinus(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
121  virtual bool onMultiply(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
122  virtual bool onDivide(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
123  virtual bool onMod(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
124  virtual bool onAnd(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
125  virtual bool onOr(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
126  virtual bool onStatus(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper);
127 };
128 
129 } // namespace Bagel
130 
131 #endif
Definition: object.h:28
Definition: ifstream.h:31
Definition: parse_object.h:45
bool evalLeftToRight(bool negFl=false, CBagVar &result= *_tempVar)
Definition: expression.h:32
Definition: bagel.h:31
Definition: var.h:32
Definition: list.h:60