00001 /** 00002 * @file Xabsl2BooleanExpression.h 00003 * 00004 * Definition of Xabsl2BooleanExpression and derivates 00005 * 00006 * @author Martin Lötzsch 00007 */ 00008 00009 #ifndef __Xabsl2BooleanExpression_h_ 00010 #define __Xabsl2BooleanExpression_h_ 00011 00012 #include "Xabsl2DecimalExpression.h" 00013 00014 // class prototype needed for the subsequentOption paramer of some classes 00015 class Xabsl2Option; 00016 00017 /** 00018 * @class Xabsl2BooleanExpression 00019 * 00020 * Base class for all boolean expressions inside an option graph. 00021 * 00022 * @author Martin Lötzsch 00023 */ 00024 class Xabsl2BooleanExpression 00025 { 00026 public: 00027 /** Evaluates the boolean expression. */ 00028 virtual bool getValue() = 0; 00029 00030 /** 00031 * Creates a boolean expression depending on the input. 00032 * @param input An input source for the intermediate code. It must be opened and read until 00033 * A position where a boolean expression starts. 00034 * @param subsequentOption The subsequent option of the state. 0 if the subsequent behavior is a basic behavior 00035 * @param errorHandler A reference to a Xabsl2ErrorHandler instance 00036 * @param parameters The parameters of the option 00037 * @param symbols All available symbols 00038 * @param timeOfOptionExecution The time how long the option is already active 00039 * @param timeOfStateExecution The time how long the state is already active 00040 */ 00041 static Xabsl2BooleanExpression* create(Xabsl2InputSource& input, 00042 Xabsl2Option* subsequentOption, 00043 Xabsl2ErrorHandler& errorHandler, 00044 Xabsl2Array<double>& parameters, 00045 Xabsl2Symbols& symbols, 00046 unsigned long& timeOfOptionExecution, 00047 unsigned long& timeOfStateExecution); 00048 00049 /** Destructor */ 00050 virtual ~Xabsl2BooleanExpression() = 0; 00051 private: 00052 /** 00053 * Creates a boolean expression depending on the input. 00054 * Used by the create() function to create boolean operands. 00055 * @param operand The expression to be created 00056 * @param input An input source for the intermediate code. It must be opened and read until 00057 * A position where a boolean operand starts. 00058 * @param subsequentOption The subsequent option of the state. 0 if the subsequent behavior is a basic behavior 00059 * @param errorHandler A reference to a Xabsl2ErrorHandler instance 00060 * @param parameters The parameters of the option 00061 * @param symbols All available symbols 00062 * @param timeOfOptionExecution The time how long the option is already active 00063 * @param timeOfStateExecution The time how long the state is already active 00064 * @return If the creation was successful 00065 */ 00066 static bool createOperand( 00067 Xabsl2BooleanExpression*& operand, 00068 Xabsl2InputSource& input, 00069 Xabsl2Option* subsequentOption, 00070 Xabsl2ErrorHandler& errorHandler, 00071 Xabsl2Array<double>& parameters, 00072 Xabsl2Symbols& symbols, 00073 unsigned long& timeOfOptionExecution, 00074 unsigned long& timeOfStateExecution); 00075 }; 00076 00077 /** 00078 * @class Xabsl2AndOperator 00079 * 00080 * Represents an 'and' element of the option graph 00081 * 00082 * @author Martin Lötzsch 00083 */ 00084 class Xabsl2AndOperator : public Xabsl2BooleanExpression 00085 { 00086 public: 00087 /** Constructor */ 00088 Xabsl2AndOperator(); 00089 00090 /** Destructor. Deletes the two operands */ 00091 ~Xabsl2AndOperator(); 00092 00093 /** Evaluates the boolean expression.*/ 00094 virtual bool getValue(); 00095 00096 /** Adds an operand to the operands array */ 00097 void addOperand(Xabsl2BooleanExpression* operand); 00098 00099 private: 00100 /** the 2+n operands of the operator */ 00101 Xabsl2Array<Xabsl2BooleanExpression*> operands; 00102 }; 00103 00104 /** 00105 * @class Xabsl2OrOperator 00106 * 00107 * Represents an 'or' element of the option graph 00108 * 00109 * @author Martin Lötzsch 00110 */ 00111 class Xabsl2OrOperator : public Xabsl2BooleanExpression 00112 { 00113 public: 00114 /** Constructor */ 00115 Xabsl2OrOperator(); 00116 00117 /** Destructor. Deletes the two operands */ 00118 ~Xabsl2OrOperator(); 00119 00120 /** Evaluates the boolean expression. */ 00121 virtual bool getValue(); 00122 00123 /** Adds an operand to the operands array */ 00124 void addOperand(Xabsl2BooleanExpression* operand); 00125 00126 private: 00127 /** the 2+n operands of the operator */ 00128 Xabsl2Array<Xabsl2BooleanExpression*> operands; 00129 }; 00130 00131 00132 /** 00133 * @class Xabsl2NotOperator 00134 * 00135 * Represents an 'not' element of the option graph 00136 * 00137 * @author Martin Lötzsch 00138 */ 00139 class Xabsl2NotOperator : public Xabsl2BooleanExpression 00140 { 00141 public: 00142 /** 00143 * Constructor. Creates the element. 00144 * @param operand1 A boolean expression 00145 */ 00146 Xabsl2NotOperator(Xabsl2BooleanExpression* operand1); 00147 00148 /** Destructor. Deletes the operand */ 00149 ~Xabsl2NotOperator(); 00150 00151 /** Evaluates the boolean expression. */ 00152 virtual bool getValue(); 00153 00154 private: 00155 /** operand 1 */ 00156 Xabsl2BooleanExpression* operand1; 00157 }; 00158 00159 /** 00160 * @class Xabsl2BooleanInputSymbolRef 00161 * 00162 * Represents an 'boolean-input-symbol-ref' element of the option graph 00163 * 00164 * @author Martin Lötzsch 00165 */ 00166 class Xabsl2BooleanInputSymbolRef : public Xabsl2BooleanExpression 00167 { 00168 public: 00169 /** 00170 * Constructor. Creates the element. 00171 * @param input An input source for the intermediate code. It must be opened and read until 00172 * A position where the symbol starts. 00173 * @param errorHandler A reference to a Xabsl2ErrorHandler instance 00174 * @param symbols All available symbols 00175 */ 00176 Xabsl2BooleanInputSymbolRef(Xabsl2InputSource& input, 00177 Xabsl2ErrorHandler& errorHandler, Xabsl2Symbols& symbols); 00178 00179 /** Evaluates the boolean expression. */ 00180 virtual bool getValue(); 00181 00182 private: 00183 /** The referenced symbol */ 00184 Xabsl2BooleanInputSymbol* symbol; 00185 }; 00186 00187 /** 00188 * @class Xabsl2subsequentOptionReachedTargetStateCondition 00189 * 00190 * Represents an 'subsequent-option-reached-target-state' element of the option graph 00191 * 00192 * @author Martin Lötzsch 00193 */ 00194 class Xabsl2subsequentOptionReachedTargetStateCondition : public Xabsl2BooleanExpression 00195 { 00196 public: 00197 /** 00198 * Constructor. Creates the element. 00199 * @param subsequentOption The subsequent option of the state. 0 if the subsequent behavior is a basic behavior 00200 * @param errorHandler A reference to a Xabsl2ErrorHandler instance 00201 */ 00202 Xabsl2subsequentOptionReachedTargetStateCondition( 00203 Xabsl2Option* subsequentOption, 00204 Xabsl2ErrorHandler& errorHandler); 00205 00206 /** Evaluates the boolean expression. */ 00207 virtual bool getValue(); 00208 00209 private: 00210 /** The subsequent option of that state */ 00211 Xabsl2Option* subsequentOption; 00212 }; 00213 00214 /** 00215 * @class Xabsl2EnumeratedInputSymbolComparison 00216 * 00217 * Represents an 'enumerated-input-symbol-comparison' element of the option graph 00218 * 00219 * @author Martin Lötzsch 00220 */ 00221 class Xabsl2EnumeratedInputSymbolComparison : public Xabsl2BooleanExpression 00222 { 00223 public: 00224 /** 00225 * Constructor. Creates the element. 00226 * @param input An input source for the intermediate code. It must be opened and read until 00227 * A position where the element starts. 00228 * @param errorHandler A reference to a Xabsl2ErrorHandler instance 00229 * @param symbols All available symbols 00230 */ 00231 Xabsl2EnumeratedInputSymbolComparison(Xabsl2InputSource& input, 00232 Xabsl2ErrorHandler& errorHandler, Xabsl2Symbols& symbols); 00233 00234 /** Evaluates the boolean expression. */ 00235 virtual bool getValue(); 00236 00237 private: 00238 /** The referenced symbol */ 00239 Xabsl2EnumeratedInputSymbol* symbol; 00240 00241 /** The value to compare */ 00242 int value; 00243 }; 00244 00245 /** 00246 * @class Xabsl2RelationalAndEqualityOperator 00247 * 00248 * Base class for the operators <, <=, >, >=, == and != 00249 * 00250 * @author Martin Lötzsch 00251 */ 00252 class Xabsl2RelationalAndEqualityOperator : public Xabsl2BooleanExpression 00253 { 00254 public: 00255 /** 00256 * Creates the element. 00257 * @param operand1 A decimal expression 00258 * @param operand2 A decimal expression 00259 */ 00260 void create(Xabsl2DecimalExpression* operand1, 00261 Xabsl2DecimalExpression* operand2); 00262 00263 /** Destructor. Deletes the two operands */ 00264 ~Xabsl2RelationalAndEqualityOperator(); 00265 00266 /** Evaluates the boolean expression.*/ 00267 virtual bool getValue() = 0; 00268 00269 protected: 00270 /** operand 1 */ 00271 Xabsl2DecimalExpression* operand1; 00272 00273 /** operand 2 */ 00274 Xabsl2DecimalExpression* operand2; 00275 }; 00276 00277 /** 00278 * @class Xabsl2EqualToOperator 00279 * 00280 * Represents an 'equal-to' element of the option graph 00281 * 00282 * @author Martin Lötzsch 00283 */ 00284 class Xabsl2EqualToOperator : public Xabsl2RelationalAndEqualityOperator 00285 { 00286 public: 00287 /** Evaluates the boolean expression.*/ 00288 virtual bool getValue(); 00289 }; 00290 00291 /** 00292 * @class Xabsl2NotEqualToOperator 00293 * 00294 * Represents an 'not-equal-to' element of the option graph 00295 * 00296 * @author Martin Lötzsch 00297 */ 00298 class Xabsl2NotEqualToOperator : public Xabsl2RelationalAndEqualityOperator 00299 { 00300 public: 00301 /** Evaluates the boolean expression.*/ 00302 virtual bool getValue(); 00303 }; 00304 00305 /** 00306 * @class Xabsl2LessThanOperator 00307 * 00308 * Represents an 'less-than' element of the option graph 00309 * 00310 * @author Martin Lötzsch 00311 */ 00312 class Xabsl2LessThanOperator : public Xabsl2RelationalAndEqualityOperator 00313 { 00314 public: 00315 /** Evaluates the boolean expression.*/ 00316 virtual bool getValue(); 00317 }; 00318 00319 /** 00320 * @class Xabsl2LessThanOrEqualToOperator 00321 * 00322 * Represents an 'less-than-or-equal-to' element of the option graph 00323 * 00324 * @author Martin Lötzsch 00325 */ 00326 class Xabsl2LessThanOrEqualToOperator : public Xabsl2RelationalAndEqualityOperator 00327 { 00328 public: 00329 /** Evaluates the boolean expression.*/ 00330 virtual bool getValue(); 00331 }; 00332 00333 /** 00334 * @class Xabsl2GreaterThanOperator 00335 * 00336 * Represents an 'greater-than' element of the option graph 00337 * 00338 * @author Martin Lötzsch 00339 */ 00340 class Xabsl2GreaterThanOperator : public Xabsl2RelationalAndEqualityOperator 00341 { 00342 public: 00343 /** Evaluates the boolean expression.*/ 00344 virtual bool getValue(); 00345 }; 00346 00347 /** 00348 * @class Xabsl2GreaterThanOrEqualToOperator 00349 * 00350 * Represents an 'greater-than-or-equal-to' element of the option graph 00351 * 00352 * @author Martin Lötzsch 00353 */ 00354 class Xabsl2GreaterThanOrEqualToOperator : public Xabsl2RelationalAndEqualityOperator 00355 { 00356 public: 00357 /** Evaluates the boolean expression.*/ 00358 virtual bool getValue(); 00359 }; 00360 00361 00362 #endif //__Xabsl2BooleanExpression_h_ 00363 00364 /* 00365 * Change Log: 00366 * 00367 * $Log: Xabsl2BooleanExpression.h,v $ 00368 * Revision 1.1.1.1 2004/05/22 17:37:54 cvsadm 00369 * created new repository GT2004_WM 00370 * 00371 * Revision 1.1 2003/10/07 10:13:25 cvsadm 00372 * Created GT2004 (M.J.) 00373 * 00374 * Revision 1.6 2003/09/30 10:51:10 dueffert 00375 * typos fixed 00376 * 00377 * Revision 1.5 2003/09/20 16:34:15 loetzsch 00378 * renamed "following-option-..." to "subsequent-option-.." and 00379 * "following-basic-behavior-.." to "subsequent-basic-behavior-.." 00380 * for consistency with publications 00381 * 00382 * Revision 1.4 2003/09/16 13:27:21 loetzsch 00383 * changed all occurrences of "option tree" to "option graph" 00384 * 00385 * Revision 1.3 2003/07/23 22:25:52 loetzsch 00386 * implemented question mark operator 00387 * 00388 * Revision 1.2 2003/07/21 19:18:06 loetzsch 00389 * - Xabsl2 AND and OR operators now can contain more than 2 operands 00390 * - speed improvements and cleanup 00391 * 00392 * Revision 1.1.1.1 2003/07/02 09:40:29 cvsadm 00393 * created new repository for the competitions in Padova from the 00394 * tamara CVS (Tuesday 2:00 pm) 00395 * 00396 * removed unused solutions 00397 * 00398 * Revision 1.3 2003/05/05 17:47:55 loetzsch 00399 * added in Xabsl2: 00400 * - marking of states as target-states with attribute is-target-state="true" 00401 * - boolean expression "subsequent-option-reached-target-state" 00402 * - common-decision-tree 00403 * 00404 * Revision 1.2 2003/01/15 01:18:46 timrie 00405 * corrected doxygen comments 00406 * 00407 * Revision 1.1 2003/01/13 13:18:18 loetzsch 00408 * Creation of boolean and decimal expressions finished. 00409 * 00410 */