1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/** 
* @file XabslDecimalExpression.h
*
* Definition of DecimalExpression and derivates
* 
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
* @author <a href="http://www.informatik.hu-berlin.de/~juengel">Matthias Juengel</a>
*/

#ifndef __XabslDecimalExpression_h_
#define __XabslDecimalExpression_h_

#include "XabslSymbols.h"

namespace xabsl 
{

// class prototypes used by symbol parameters / conditional expressions
class BooleanExpression;
class EnumeratedExpression;
class Option;
class State;

/** 
* @class DecimalExpression
* 
* Base class for all decimal expressions inside an option graph.
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
*/
class DecimalExpression
{
public:
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const = 0;
  
  /**
  * Creates a decimal expression depending on the input.
  * @param input An input source for the intermediate code. It must be opened and read until 
  *              A position where a decimal expression starts.
  * @param errorHandler A reference to a ErrorHandler instance
  * @param symbols All available symbols
  * @param option The current option
  * @param state The current state
  */
  static DecimalExpression* create(InputSource& input, 
    ErrorHandler& errorHandler,
    Symbols& symbols,
    Option& option,
    State& state);

  /** Destructor */
  virtual ~DecimalExpression() = 0;
  
  /** 
  * Creates a decimal expression depending on the input. 
  * Uses the create() function to create decimal operands.
  * @param operand The expression to be created
  * @param input An input source for the intermediate code. It must be opened and read until 
  *              A position where a decimal operand starts.
  * @param errorHandler A reference to a ErrorHandler instance
  * @param symbols All available symbols
  * @param option The current option
  * @param state The current state
  * @return If the creation was successful
  */
  static bool createOperand(
    DecimalExpression*& operand,
    InputSource& input, 
    ErrorHandler& errorHandler,
    Symbols& symbols,
    Option& option,
    State& state);
};

/** 
* @class DecimalValue
* 
* Represents a decimal value.
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class DecimalValue : public DecimalExpression
{
public:
  /**
  * Constructor. Creates the value
  * @param input An input source for the intermediate code. It must be opened and read until 
  *              A position where a value starts.
  * @param errorHandler A reference to a ErrorHandler instance
  */
  DecimalValue(InputSource& input, 
    ErrorHandler& errorHandler);

  /**
  * Constructor. Creates an expression for a fixed decimal value
  * @param value The decimal value
  */
  DecimalValue(double value) : value(value) {}
  
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
  
private:
  /** The value */
  double value;
};

/** 
* @class DecimalOptionParameterRef
* 
* Represents a reference to a decimal option parameter.
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
*/
class DecimalOptionParameterRef : public DecimalExpression
{
public:
  /**
  * Constructor. Creates the reference 
  * @param input An input source for the intermediate code. It must be opened and read until 
  *              A position where the expression starts.
  * @param errorHandler A reference to a ErrorHandler instance
  * @param option The current option
  */
  DecimalOptionParameterRef(InputSource& input, 
    ErrorHandler& errorHandler,
    Option& option);
  
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
  
private:
  /** A pointer to the parameter */
  double* parameter;
};

/** 
* @class ArithmeticOperator
* 
* Base class for the +, -, *, / and % operator.
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class ArithmeticOperator : public DecimalExpression
{
public:
/**
* Creates the operator
* @param operand1 The first operand
* @param operand2 The second operand
  */
  void create(DecimalExpression* operand1, DecimalExpression* operand2);
  
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const = 0;
  
  /** Destructor. Deletes the operands */
  ~ArithmeticOperator();
  
protected:
  /** The first operand */
  DecimalExpression* operand1;
  
  /** The second operand */
  DecimalExpression* operand2;
};

/** 
* @class PlusOperator
*
* Represents a + operator in the option graph 
* 
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class PlusOperator : public ArithmeticOperator
{
public:
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
};

/** 
* @class MinusOperator
*
* Represents a - operator in the option graph 
* 
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class MinusOperator : public ArithmeticOperator
{
public:
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
};


/** 
* @class MultiplyOperator
*
* Represents a * operator in the option graph
* 
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class MultiplyOperator : public ArithmeticOperator
{
public:
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
};

/** 
* @class DivideOperator
*
* Represents a / operator in the option graph 
* 
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class DivideOperator : public ArithmeticOperator
{
public:
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
};

/** 
* @class ModOperator
*
* Represents a % operator in the option graph 
* 
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class ModOperator : public ArithmeticOperator
{
public:
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
};

/** 
* @class TimeRef
*
* Represents a time-of-option-execution or time-of-state-execution element in the option graph 
* 
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class TimeRef : public DecimalExpression
{
public:
  /** 
  * Constructor
  * @param errorHandler A reference to a ErrorHandler instance
  * @param time the referenced time
  */
  TimeRef(ErrorHandler& errorHandler,
    unsigned& time);
  
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
  
private:
  /** The referenced time */
  unsigned& time;
};

/** 
* @class DecimalInputSymbolRef
* 
* Represents a reference to a decimal input symbol.
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
*/
class DecimalInputSymbolRef : public DecimalExpression
{
public:
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
  
  /**
  * Constructor. Creates the function call depending on the input.
  * @param input An input source for the intermediate code. It must be opened and read until 
  *              A position where the function reference starts.
  * @param errorHandler A reference to a ErrorHandler instance
  * @param symbols All available symbols
  * @param option The current option
  * @param state The current state
  */
  DecimalInputSymbolRef(InputSource& input, 
    ErrorHandler& errorHandler,
    Symbols& symbols,
    Option& option,
    State& state);
  
  /** Destructor */
  ~DecimalInputSymbolRef();

private:
  /** The referenced symbol */
  DecimalInputSymbol* symbol;

  /** The parameter assignments of the referenced symbol */
  ParameterAssignment* parameters;
};

/** 
* @class DecimalOutputSymbolRef
* 
* Represents a reference to a decimal input symbol.
*
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
*/
class DecimalOutputSymbolRef : public DecimalExpression
{
public:
  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;
  
  /**
  * Constructor. Creates the function call depending on the input.
  * @param input An input source for the intermediate code. It must be opened and read until 
  *              A position where the function reference starts.
  * @param errorHandler A reference to a ErrorHandler instance
  * @param symbols All available symbols
  */
  DecimalOutputSymbolRef(InputSource& input, 
    ErrorHandler& errorHandler,
    Symbols& symbols);

private:
  /** The referenced symbol */
  DecimalOutputSymbol* symbol;
};

/** 
* @class ConditionalDecimalExpression
* 
* Represents an ANSI C (condition?expression:expression) question mark operator
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
*/
class ConditionalDecimalExpression : public DecimalExpression
{
public:
  /**
  * Constructor. Creates the expression
  * @param input An input source for the intermediate code. It must be opened and read until 
  *              A position where a expression starts.
  * @param errorHandler A reference to a ErrorHandler instance
  * @param symbols All available symbols
  * @param option The current option
  * @param state The current state
  */
  ConditionalDecimalExpression(InputSource& input, 
    ErrorHandler& errorHandler,
    Symbols& symbols,
    Option& option,
    State& state);

  /** Destructor */
  ~ConditionalDecimalExpression();

  /** Calculates the value of the decimal expression. */
  virtual double getValue() const;

private:
  /** The condition */
  BooleanExpression* condition;

  /** The expression that is returned when the condition evaluates true */
  DecimalExpression* expression1;

  /** The expression that is returned when the condition evaluates false */
  DecimalExpression* expression2;
};

} // namespace

#endif //__XabslDecimalExpression_h_