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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/**
* @file XabslSymbols.h
*
* Definition of class Symbols and helper classes
*
* @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>
*/

#ifndef __XabslSymbols_h_
#define __XabslSymbols_h_

#include "XabslTools.h"
#include "XabslParameters.h"

namespace xabsl 
{

/**
* @class EnumElement
* Represents an enum element that is part of an enumerated input or output symbol.
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class EnumElement : public NamedItem
{
public:
/** 
* Constructor 
* @param name The name of the enum element as specified in the XML formalization
* @param value The value for the element from the software environment
  */
  EnumElement(const char* name, int value)
    : NamedItem(name), v(value) {};
  
  /** The enum value from a function or variable in the software environment */
  int v;
};
/**
* @class Enumeration
*
* Represents a list of enum elements
*/
class Enumeration : public NamedItem
{
public:
  /** 
  * Constructor 
  * @param name The name of the enumeration as specified in the XML formalization
  * @param index Index of the enumeration in array enumerations in corresponding engine
  */
  Enumeration(const char* name, int index) : NamedItem(name), index(index) {};

  /** Destructor. Deletes the enum elements */
  ~Enumeration();

  /** 
  * Assigns an enum value from a function or variable in the software environment 
  * to the enum-element string in the XML formalization.
  */
  NamedArray<EnumElement*> enumElements;

  /** Index of the enumeration in array enumerations in corresponding engine */
  int index;
};

/** 
* A Template for the input symbol classes
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
template<class T> class InputSymbol : public NamedItem
{
public:
  /** 
  * Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pVariable A pointer to the variable that the symbol stands for
  * @param index Index of the symbol in array in corresponding engine
  */
  InputSymbol(const char* name, const T* pVariable, ErrorHandler& errorHandler, int index)
    : NamedItem(name), parameters(errorHandler), pParametersChanged(0), index(index), lastValue(0), pV(pVariable), pF(0)
  {};
  
  
  /** Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pFunction A pointer to a boolean returning function in the software environment 
  * @param index Index of the symbol in array in corresponding engine
  */
  InputSymbol(const char* name,
    T (*pFunction)(),
    ErrorHandler& errorHandler, int index)
    : NamedItem(name), parameters(errorHandler),  pParametersChanged(0), index(index), lastValue(0), pV(0), pF(pFunction) {};
  
  /** returns the value of the symbol */
  T getValue() 
  { if (pF!=0) return lastValue = (*pF)(); else return lastValue = *pV; }

  /** Notify the software environment about a parameter change */
  void parametersChanged() const
  { if (pParametersChanged!=0) (*pParametersChanged)(); }
  
  /** The parameters of the input symbol*/
  Parameters parameters;

  /** A Pointer to a parameter change notification function in the software environment */
  void (*pParametersChanged)();
  
  /** Index of the symbol in array in corresponding engine */
  int index;

  /** Last queried value of the input symbol */
  T lastValue;

private:
  /** A pointer to a variable in the software environment */
  const T* pV; 
  
  /** A pointer to a T returning function in the software environment */
  T (*pF)(); 
};

/** 
* @class DecimalInputSymbol
*
* Represents a decimal input symbol of the Engine 
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class DecimalInputSymbol : public InputSymbol<double>
{
public:
  /** 
  * Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pVariable A pointer to the variable that the symbol stands for
  * @param index Index of the symbol in array in corresponding engine
  */
  DecimalInputSymbol(const char* name, const double* pVariable, ErrorHandler& errorHandler, int index)
    : InputSymbol<double>(name, pVariable, errorHandler, index) 
  {};
  
  /** Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pFunction A pointer to a double returning function in the software environment 
  * @param index Index of the symbol in array in corresponding engine
  */
  DecimalInputSymbol(const char* name,
    double (*pFunction)(),
    ErrorHandler& errorHandler, int index)
    : InputSymbol<double>(name, pFunction, errorHandler, index) {};
};

/** 
* @class BooleanInputSymbol
*
* Represents a boolean input symbol of the Engine 
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class BooleanInputSymbol : public InputSymbol<bool>
{
public:
  /** 
  * Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pVariable A pointer to the variable that the symbol stands for
  * @param index Index of the symbol in array in corresponding engine
  */
  BooleanInputSymbol(const char* name, const bool* pVariable, ErrorHandler& errorHandler, int index)
    : InputSymbol<bool>(name, pVariable, errorHandler, index) 
  {};
  
  /** Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pFunction A pointer to a boolean returning function in the software environment 
  * @param index Index of the symbol in array in corresponding engine
  */
  BooleanInputSymbol(const char* name, 
    bool (*pFunction)(),
    ErrorHandler& errorHandler, int index)
    : InputSymbol<bool>(name, pFunction, errorHandler, index) {};
};

/** 
* @class EnumeratedInputSymbol
*
* Represents a enumerated input symbol of the Engine 
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class EnumeratedInputSymbol : public InputSymbol<int>
{
public:
  /** 
  * Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pVariable A pointer to the variable that the symbol stands for
  * @param index Index of the symbol in array in corresponding engine
  */
  EnumeratedInputSymbol(const char* name, Enumeration* enumeration, const int* pVariable, 
    ErrorHandler& errorHandler, int index)
    : InputSymbol<int>(name, pVariable, errorHandler, index), enumeration(enumeration) 
  {};
  
  /** Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param enumeration Pointer to the list of enumeration elements
  * @param pFunction A pointer to an int returning function in the software environment 
  * @param index Index of the symbol in array in corresponding engine
  */
  EnumeratedInputSymbol(const char* name, Enumeration* enumeration, 
    int (*pFunction)(),
    ErrorHandler& errorHandler, int index)
    : InputSymbol<int>(name, pFunction, errorHandler, index), enumeration(enumeration) {};

  /** Pointer to the list of enumeration elements */
  Enumeration* enumeration;
};

/** 
* @class OutputSymbol
*
* A Template for the output symbol classes
*
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
*/
template<class T> class OutputSymbol : public NamedItem
{
public:
  /** 
  * Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pVariable A pointer to the variable that the symbol stands for
  * @param defaultValue The default value
  * @param index Index of the symbol in array in corresponding engine
  */
  OutputSymbol(const char* name, T* pVariable, int index)
    : NamedItem(name), activeValueWasSet(false), index(index), lastValue(0), pV(pVariable), pSetF(0), pGetF(0)
  {};
  
  
  /** Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pSetFunction A pointer to a boolean accepting function in the software environment 
  * @param pGetFunction A pointer to a boolean returning function in the software environment 
  * @param defaultValue The default value
  * @param index Index of the symbol in array in corresponding engine
  */
  OutputSymbol(const char* name,
    void (*pSetFunction)(T),
    T (*pGetFunction)(), int index)
    : NamedItem(name), activeValueWasSet(false), index(index), lastValue(0), pV(0), pSetF(pSetFunction), pGetF(pGetFunction)
  {};


  /** Set the value of the symbol. */
  void setValue(T value)
  {
    if (pSetF!=0) 
    {
      (*pSetF)(value);
    }
    else 
    {
      *pV=value;
    }
    lastValue = value;
    activeValueWasSet = true;
  }

  /** Returns the current value of the symbol. */
  T getValue() const
  {
    if (pGetF!=0) 
    {
      return (*pGetF)();
    }
    else 
    {
      return *pV;
    }
  }

  /** If true, the value was set during the last execution of the option graph. */
  bool activeValueWasSet;

  /** Index of the symbol in array in corresponding engine */
  int index;

  /** Last set value of the output symbol */
  T lastValue;

private:
  /** A pointer to a variable in the software environment */
  T* pV; 
  
  /** A pointer to a function that sets the value of the symbol in the software environment */
  void (*pSetF)(T); 

  /** A pointer to a function that gets the value of the symbol from the software environment */
  T (*pGetF)(); 
};

/** 
* @class DecimalOutputSymbol
*
* Represents a decimal output symbol of the Engine 
*
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
*/
class DecimalOutputSymbol : public OutputSymbol<double>
{
public:
  /** 
  * Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pVariable A pointer to the variable that the symbol stands for
  * @param index Index of the symbol in array in corresponding engine
  */
  DecimalOutputSymbol(const char* name, double* pVariable, int index)
    : OutputSymbol<double>(name, pVariable, index)
  {};
    
  /** Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pSetFunction A pointer to a function in the software environment that sets the value of the symbol
  * @param pGetFunction A pointer to a function in the software environment that returns the value of the symbol
  * @param index Index of the symbol in array in corresponding engine
  */
  DecimalOutputSymbol(const char* name, 
    void (*pSetFunction)(double),
    double (*pGetFunction)(), int index)
    : OutputSymbol<double>(name, pSetFunction, pGetFunction, index)
  {};
};

/** 
* @class BooleanOutputSymbol
*
* Represents a boolean output symbol of the Engine 
*
* @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
*
*/
class BooleanOutputSymbol : public OutputSymbol<bool>
{
public:
  /** 
  * Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pVariable A pointer to the variable that the symbol stands for
  * @param index Index of the symbol in array in corresponding engine
  */
  BooleanOutputSymbol(const char* name, bool* pVariable, int index)
    : OutputSymbol<bool>(name, pVariable, index)
  {};
    
  /** Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param pSetFunction A pointer to a function in the software environment that sets the value of the symbol
  * @param pGetFunction A pointer to a function in the software environment that returns the value of the symbol
  * @param index Index of the symbol in array in corresponding engine
  */
  BooleanOutputSymbol(const char* name, 
    void (*pSetFunction)(bool),
    bool (*pGetFunction)(), int index)
    : OutputSymbol<bool>(name, pSetFunction, pGetFunction, index)
  {};
};

/** 
* @class EnumeratedOutputSymbol
*
* Represents a enumerated output symbol of the Engine 
*
* @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
*/
class EnumeratedOutputSymbol : public OutputSymbol<int>
{
public:
  /** 
  * Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param enumeration Pointer to the list of enumeration elements
  * @param pVariable A pointer to the variable that the symbol stands for
  * @param index Index of the symbol in array in corresponding engine
  */
  EnumeratedOutputSymbol(const char* name, Enumeration* enumeration, int* pVariable, int index)
    : OutputSymbol<int>(name, pVariable, index), enumeration(enumeration)
  {};
  
  
  /** Constructor 
  * @param name The name of the symbol, for debugging purposes
  * @param enumeration Pointer to the list of enumeration elements
  * @param pSetFunction A pointer to a function in the software environment that sets the value of the symbol
  * @param pGetFunction A pointer to a function in the software environment that returns the value of the symbol
  * @param index Index of the symbol in array in corresponding engine
  */
  EnumeratedOutputSymbol(const char* name, Enumeration* enumeration,
    void (*pSetFunction)(int),
    int (*pGetFunction)(), int index)
    : OutputSymbol<int>(name, pSetFunction, pGetFunction, index), enumeration(enumeration)
  {};
  
  /** Pointer to the list of enumeration elements */
  Enumeration* enumeration;
};

/**
* @class Symbols
*
* Handles the symbols of the Engine.
*
* @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 Symbols
{
public:
/** 
* Constructor.
* @param errorHandler Is invoked when errors occur
  */
  Symbols(ErrorHandler& errorHandler)
    : errorHandler(errorHandler) {};
  
  /** Destructor */
  virtual ~Symbols();
  
  /**
  * Registers an enum element for an enumeration.
  * @param enumName The name of the enumeration
  * @param name The name of the enum element
  * @param value The value of the element
  */
  void registerEnumElement(const char* enumName, <--- Function 'registerEnumElement' argument 1 names different: declaration 'enumName' definition 'symbolName'.
    const char* name, int value);

  /** 
  * Registers the address of a variable for a decimal input symbol.
  * @param name The name of the symbol
  * @param pVariable A pointer to a variable in the software environment 
  */
  void registerDecimalInputSymbol(const char* name, const double* pVariable);
  
  /** 
  * Registers the address of a function for a decimal input symbol.
  * @param name The name of the symbol
  * @param pFunction A pointer to a function that calculates a value for the symbol
  */
  void registerDecimalInputSymbol(const char* name,
    double (*pFunction)());
  
  /** 
  * Registers the address of a function for parameter change notification for a decimal input symbol.
  * @param name The name of the symbol
  * @param pFunction A pointer to the parameter change notification function
  */
  void registerDecimalInputSymbolParametersChanged(const char* name,
    void (*pFunction)());

  /** 
  * Registers a parameter of a parameterized decimal input symbol.
  * @param symbolName The name of the symbol
  * @param name The name of the parameter
  * @param pParam A pointer to the parameter
  */
  void registerDecimalInputSymbolDecimalParameter(const char* symbolName, 
    const char* name, double* pParam);
  void registerDecimalInputSymbolBooleanParameter(const char* symbolName, 
    const char* name, bool* pParam);
  void registerDecimalInputSymbolEnumeratedParameter(const char* symbolName, 
    const char* name, const char* enumName, int* pParam);

  /** 
  * Registers the address of a variable for a boolean input symbol.
  * @param name The name of the symbol
  * @param pVariable A pointer to a variable in the software environment 
  */
  void registerBooleanInputSymbol(const char* name, const bool* pVariable);
  
  /** 
  * Registers the address of a function for a boolean input symbol.
  * @param name The name of the symbol
  * @param pFunction A pointer to a function that calculates a value for the symbol
  */
  void registerBooleanInputSymbol(const char* name, 
    bool (*pFunction)());
  
  /** 
  * Registers the address of a function for parameter change notification for a boolean input symbol.
  * @param name The name of the symbol
  * @param pFunction A pointer to the parameter change notification function
  */
  void registerBooleanInputSymbolParametersChanged(const char* name,
    void (*pFunction)());

  /** 
  * Registers a parameter of a parameterized boolean input symbol.
  * @param symbolName The name of the symbol
  * @param name The name of the parameter
  * @param pParam A pointer to the parameter
  */
  void registerBooleanInputSymbolDecimalParameter(const char* symbolName, 
    const char* name, double* pParam);
  void registerBooleanInputSymbolBooleanParameter(const char* symbolName, 
    const char* name, bool* pParam);
  void registerBooleanInputSymbolEnumeratedParameter(const char* symbolName, 
    const char* name, const char* enumName, int* pParam);

  /** 
  * Registers the address of a variable for a enumerated input symbol.
  * @param name The name of the symbol
  * @param enumName The name of the associated enumeration
  * @param pVariable A pointer to a variable in the software environment 
  */
  void registerEnumeratedInputSymbol(const char* name, const char* enumName, const int* pVariable);
  
  /** 
  * Registers the address of a function for a enumerated input symbol.
  * @param name The name of the symbol
  * @param enumName The name of the associated enumeration
  * @param pFunction A pointer to a function that calculates a value for the symbol
  */
  void registerEnumeratedInputSymbol(const char* name, const char* enumName, 
    int (*pFunction)());
  
  /** 
  * Registers the address of a function for parameter change notification for an enumerated input symbol.
  * @param name The name of the symbol
  * @param pFunction A pointer to the parameter change notification function
  */
  void registerEnumeratedInputSymbolParametersChanged(const char* name,
    void (*pFunction)());

  /** 
  * Registers a parameter of an enumerated input symbol.
  * @param symbolName The name of the symbol
  * @param name The name of the parameter
  * @param pParam A pointer to the parameter
  */
  void registerEnumeratedInputSymbolDecimalParameter(const char* symbolName, 
    const char* name, double* pParam);
  void registerEnumeratedInputSymbolBooleanParameter(const char* symbolName, 
    const char* name, bool* pParam);
  void registerEnumeratedInputSymbolEnumeratedParameter(const char* symbolName, 
    const char* name, const char* enumName, int* pParam);

  /** 
  * Registers the address of a variable for a decimal output symbol.
  * @param name The name of the symbol
  * @param pVariable A pointer to a variable in the software environment 
  */
  void registerDecimalOutputSymbol(const char* name, double* pVariable);

  /** 
  * Registers the address of a function for a decimal output symbol.
  * @param name The name of the symbol
  * @param pSetFunction A pointer to a function that sets a value for the symbol
  * @param pGetFunction A pointer to a function that returns a value for the symbol
  */
  void registerDecimalOutputSymbol(const char* name,
    void (*pSetFunction)(double),
    double (*pGetFunction)()
  );

  /** 
  * Registers the address of a variable for a boolean output symbol.
  * @param name The name of the symbol
  * @param pVariable A pointer to a variable in the software environment 
  */
  void registerBooleanOutputSymbol(const char* name, bool* pVariable);

  /** 
  * Registers the address of a function for a boolean output symbol.
  * @param name The name of the symbol
  * @param pSetFunction A pointer to a function that sets a value for the symbol
  * @param pGetFunction A pointer to a function that returns a value for the symbol
  */
  void registerBooleanOutputSymbol(const char* name, 
    void (*pSetFunction)(bool),
    bool (*pGetFunction)()
  );

  /** 
  * Registers the address of a variable for a enumerated output symbol.
  * @param name The name of the symbol
  * @param enumName The name of the associated enumeration
  * @param pVariable A pointer to a variable in the software environment 
  */
  void registerEnumeratedOutputSymbol(const char* name, const char* enumName, int* pVariable);
  
  /** 
  * Registers the address of a function for a enumerated output symbol.
  * @param name The name of the symbol
  * @param enumName The name of the associated enumeration
  * @param pSetFunction A pointer to a function that sets a value for the symbol
  * @param pGetFunction A pointer to a function that returns a value for the symbol
  */
  void registerEnumeratedOutputSymbol(const char* name, const char* enumName, 
    void (*pSetFunction)(int),
    int (*pGetFunction)()
  );
  
  /** Sets all output symbols to unset */
  void resetOutputSymbols();
  
  /** The enumerations */
  NamedArray<Enumeration*> enumerations;

  /** The decimal input symbols */
  NamedArray<DecimalInputSymbol*> decimalInputSymbols;
    
  /** The boolean input symbols */
  NamedArray<BooleanInputSymbol*> booleanInputSymbols;
  
  /** The enumerated input symbols */
  NamedArray<EnumeratedInputSymbol*> enumeratedInputSymbols;
  
  /** The decimal output symbols */
  NamedArray<DecimalOutputSymbol*> decimalOutputSymbols;

  /** The boolean output symbols */
  NamedArray<BooleanOutputSymbol*> booleanOutputSymbols;

  /** The enumerated output symbols */
  NamedArray<EnumeratedOutputSymbol*> enumeratedOutputSymbols;

private:
  /** Is invoked when errors occur */
  ErrorHandler& errorHandler;
};

} // namespace

#endif //__XabslSymbols_h_