>xabsl   The Extensible Agent Behavior Specification Language

XabslEngine Class Library Reference

 

XabslSymbols.h

Go to the documentation of this file.
00001 /**
00002 * @file XabslSymbols.h
00003 *
00004 * Definition of class Symbols and helper classes
00005 *
00006 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00007 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
00008 */
00009 
00010 #ifndef __XabslSymbols_h_
00011 #define __XabslSymbols_h_
00012 
00013 #include "XabslTools.h"
00014 #include "XabslParameters.h"
00015 
00016 namespace xabsl 
00017 {
00018 
00019 /**
00020 * @class EnumElement
00021 * Represents an enum element that is part of an enumerated input or output symbol.
00022 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00023 */
00024 class EnumElement : public NamedItem
00025 {
00026 public:
00027 /** 
00028 * Constructor 
00029 * @param name The name of the enum element as specified in the XML formalization
00030 * @param value The value for the element from the software environment
00031   */
00032   EnumElement(const char* name, int value)
00033     : NamedItem(name), v(value) {};
00034   
00035   /** The enum value from a function or variable in the software environment */
00036   int v;
00037 };
00038 /**
00039 * @class Enumeration
00040 *
00041 * Represents a list of enum elements
00042 */
00043 class Enumeration : public NamedItem
00044 {
00045 public:
00046   /** 
00047   * Constructor 
00048   * @param name The name of the enumeration as specified in the XML formalization
00049   * @param index Index of the enumeration in array enumerations in corresponding engine
00050   */
00051   Enumeration(const char* name, int index) : NamedItem(name), index(index) {};
00052 
00053   /** Destructor. Deletes the enum elements */
00054   ~Enumeration();
00055 
00056   /** 
00057   * Assigns an enum value from a function or variable in the software environment 
00058   * to the enum-element string in the XML formalization.
00059   */
00060   NamedArray<EnumElement*> enumElements;
00061 
00062   /** Index of the enumeration in array enumerations in corresponding engine */
00063   int index;
00064 };
00065 
00066 /** 
00067 * A Template for the input symbol classes
00068 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00069 */
00070 template<class T> class InputSymbol : public NamedItem
00071 {
00072 public:
00073   /** 
00074   * Constructor 
00075   * @param name The name of the symbol, for debugging purposes
00076   * @param pVariable A pointer to the variable that the symbol stands for
00077   * @param index Index of the symbol in array in corresponding engine
00078   */
00079   InputSymbol(const char* name, const T* pVariable, ErrorHandler& errorHandler, int index)
00080     : NamedItem(name), parameters(errorHandler), pV(pVariable), pF(0), pParametersChanged(0), index(index), lastValue(0)
00081   {};
00082   
00083   
00084   /** Constructor 
00085   * @param name The name of the symbol, for debugging purposes
00086   * @param pFunction A pointer to a boolean returning function in the software environment 
00087   * @param index Index of the symbol in array in corresponding engine
00088   */
00089   InputSymbol(const char* name,
00090     T (*pFunction)(),
00091     ErrorHandler& errorHandler, int index)
00092     : NamedItem(name), parameters(errorHandler), pV(0), pF(pFunction), pParametersChanged(0), index(index), lastValue(0) {};
00093   
00094   /** returns the value of the symbol */
00095   T getValue() 
00096   { if (pF!=0) return lastValue = (*pF)(); else return lastValue = *pV; }
00097 
00098   /** Notify the software environment about a parameter change */
00099   void parametersChanged() const
00100   { if (pParametersChanged!=0) (*pParametersChanged)(); }
00101   
00102   /** The parameters of the input symbol*/
00103   Parameters parameters;
00104 
00105   /** A Pointer to a parameter change notification function in the software environment */
00106   void (*pParametersChanged)();
00107   
00108   /** Index of the symbol in array in corresponding engine */
00109   int index;
00110 
00111   /** Last queried value of the input symbol */
00112   T lastValue;
00113 
00114 private:
00115   /** A pointer to a variable in the software environment */
00116   const T* pV; 
00117   
00118   /** A pointer to a T returning function in the software environment */
00119   T (*pF)(); 
00120 };
00121 
00122 /** 
00123 * @class DecimalInputSymbol
00124 *
00125 * Represents a decimal input symbol of the Engine 
00126 *
00127 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00128 */
00129 class DecimalInputSymbol : public InputSymbol<double>
00130 {
00131 public:
00132   /** 
00133   * Constructor 
00134   * @param name The name of the symbol, for debugging purposes
00135   * @param pVariable A pointer to the variable that the symbol stands for
00136   * @param index Index of the symbol in array in corresponding engine
00137   */
00138   DecimalInputSymbol(const char* name, const double* pVariable, ErrorHandler& errorHandler, int index)
00139     : InputSymbol<double>(name, pVariable, errorHandler, index) 
00140   {};
00141   
00142   /** Constructor 
00143   * @param name The name of the symbol, for debugging purposes
00144   * @param pFunction A pointer to a double returning function in the software environment 
00145   * @param index Index of the symbol in array in corresponding engine
00146   */
00147   DecimalInputSymbol(const char* name,
00148     double (*pFunction)(),
00149     ErrorHandler& errorHandler, int index)
00150     : InputSymbol<double>(name, pFunction, errorHandler, index) {};
00151 };
00152 
00153 /** 
00154 * @class BooleanInputSymbol
00155 *
00156 * Represents a boolean input symbol of the Engine 
00157 *
00158 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00159 */
00160 class BooleanInputSymbol : public InputSymbol<bool>
00161 {
00162 public:
00163   /** 
00164   * Constructor 
00165   * @param name The name of the symbol, for debugging purposes
00166   * @param pVariable A pointer to the variable that the symbol stands for
00167   * @param index Index of the symbol in array in corresponding engine
00168   */
00169   BooleanInputSymbol(const char* name, const bool* pVariable, ErrorHandler& errorHandler, int index)
00170     : InputSymbol<bool>(name, pVariable, errorHandler, index) 
00171   {};
00172   
00173   /** Constructor 
00174   * @param name The name of the symbol, for debugging purposes
00175   * @param pFunction A pointer to a boolean returning function in the software environment 
00176   * @param index Index of the symbol in array in corresponding engine
00177   */
00178   BooleanInputSymbol(const char* name, 
00179     bool (*pFunction)(),
00180     ErrorHandler& errorHandler, int index)
00181     : InputSymbol<bool>(name, pFunction, errorHandler, index) {};
00182 };
00183 
00184 /** 
00185 * @class EnumeratedInputSymbol
00186 *
00187 * Represents a enumerated input symbol of the Engine 
00188 *
00189 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00190 */
00191 class EnumeratedInputSymbol : public InputSymbol<int>
00192 {
00193 public:
00194   /** 
00195   * Constructor 
00196   * @param name The name of the symbol, for debugging purposes
00197   * @param pVariable A pointer to the variable that the symbol stands for
00198   * @param index Index of the symbol in array in corresponding engine
00199   */
00200   EnumeratedInputSymbol(const char* name, Enumeration* enumeration, const int* pVariable, 
00201     ErrorHandler& errorHandler, int index)
00202     : InputSymbol<int>(name, pVariable, errorHandler, index), enumeration(enumeration) 
00203   {};
00204   
00205   /** Constructor 
00206   * @param name The name of the symbol, for debugging purposes
00207   * @param enumeration Pointer to the list of enumeration elements
00208   * @param pFunction A pointer to an int returning function in the software environment 
00209   * @param index Index of the symbol in array in corresponding engine
00210   */
00211   EnumeratedInputSymbol(const char* name, Enumeration* enumeration, 
00212     int (*pFunction)(),
00213     ErrorHandler& errorHandler, int index)
00214     : InputSymbol<int>(name, pFunction, errorHandler, index), enumeration(enumeration) {};
00215 
00216   /** Pointer to the list of enumeration elements */
00217   Enumeration* enumeration;
00218 };
00219 
00220 /** 
00221 * @class OutputSymbol
00222 *
00223 * A Template for the output symbol classes
00224 *
00225 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
00226 */
00227 template<class T> class OutputSymbol : public NamedItem
00228 {
00229 public:
00230   /** 
00231   * Constructor 
00232   * @param name The name of the symbol, for debugging purposes
00233   * @param pVariable A pointer to the variable that the symbol stands for
00234   * @param index Index of the symbol in array in corresponding engine
00235   */
00236   OutputSymbol(const char* name, T* pVariable, int index)
00237     : NamedItem(name), activeValueWasSet(false), pV(pVariable), pSetF(0), pGetF(0), index(index), lastValue(0)
00238   {};
00239   
00240   
00241   /** Constructor 
00242   * @param name The name of the symbol, for debugging purposes
00243   * @param pSetFunction A pointer to a boolean accepting function in the software environment 
00244   * @param pGetFunction A pointer to a boolean returning function in the software environment 
00245   * @param index Index of the symbol in array in corresponding engine
00246   */
00247   OutputSymbol(const char* name,
00248     void (*pSetFunction)(T),
00249     T (*pGetFunction)(), int index)
00250     : NamedItem(name), activeValueWasSet(false), pV(0), pSetF(pSetFunction), pGetF(pGetFunction), index(index), lastValue(0)
00251   {};
00252 
00253 
00254   /** Set the value of the symbol. */
00255   void setValue(T value)
00256   {
00257     if (pSetF!=0) 
00258     {
00259       (*pSetF)(value);
00260     }
00261     else 
00262     {
00263       *pV=value;
00264     }
00265     lastValue = value;
00266     activeValueWasSet = true;
00267   }
00268 
00269   /** Returns the current value of the symbol. */
00270   T getValue() const
00271   {
00272     if (pGetF!=0) 
00273     {
00274       return (*pGetF)();
00275     }
00276     else 
00277     {
00278       return *pV;
00279     }
00280   }
00281 
00282   /** If true, the value was set during the last execution of the option graph. */
00283   bool activeValueWasSet;
00284 
00285   /** Index of the symbol in array in corresponding engine */
00286   int index;
00287 
00288   /** Last set value of the output symbol */
00289   T lastValue;
00290 
00291 private:
00292   /** A pointer to a variable in the software environment */
00293   T* pV; 
00294   
00295   /** A pointer to a function that sets the value of the symbol in the software environment */
00296   void (*pSetF)(T); 
00297 
00298   /** A pointer to a function that gets the value of the symbol from the software environment */
00299   T (*pGetF)(); 
00300 };
00301 
00302 /** 
00303 * @class DecimalOutputSymbol
00304 *
00305 * Represents a decimal output symbol of the Engine 
00306 *
00307 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
00308 */
00309 class DecimalOutputSymbol : public OutputSymbol<double>
00310 {
00311 public:
00312   /** 
00313   * Constructor 
00314   * @param name The name of the symbol, for debugging purposes
00315   * @param pVariable A pointer to the variable that the symbol stands for
00316   * @param index Index of the symbol in array in corresponding engine
00317   */
00318   DecimalOutputSymbol(const char* name, double* pVariable, int index)
00319     : OutputSymbol<double>(name, pVariable, index)
00320   {};
00321     
00322   /** Constructor 
00323   * @param name The name of the symbol, for debugging purposes
00324   * @param pSetFunction A pointer to a function in the software environment that sets the value of the symbol
00325   * @param pGetFunction A pointer to a function in the software environment that returns the value of the symbol
00326   * @param index Index of the symbol in array in corresponding engine
00327   */
00328   DecimalOutputSymbol(const char* name, 
00329     void (*pSetFunction)(double),
00330     double (*pGetFunction)(), int index)
00331     : OutputSymbol<double>(name, pSetFunction, pGetFunction, index)
00332   {};
00333 };
00334 
00335 /** 
00336 * @class BooleanOutputSymbol
00337 *
00338 * Represents a boolean output symbol of the Engine 
00339 *
00340 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
00341 *
00342 */
00343 class BooleanOutputSymbol : public OutputSymbol<bool>
00344 {
00345 public:
00346   /** 
00347   * Constructor 
00348   * @param name The name of the symbol, for debugging purposes
00349   * @param pVariable A pointer to the variable that the symbol stands for
00350   * @param index Index of the symbol in array in corresponding engine
00351   */
00352   BooleanOutputSymbol(const char* name, bool* pVariable, int index)
00353     : OutputSymbol<bool>(name, pVariable, index)
00354   {};
00355     
00356   /** Constructor 
00357   * @param name The name of the symbol, for debugging purposes
00358   * @param pSetFunction A pointer to a function in the software environment that sets the value of the symbol
00359   * @param pGetFunction A pointer to a function in the software environment that returns the value of the symbol
00360   * @param index Index of the symbol in array in corresponding engine
00361   */
00362   BooleanOutputSymbol(const char* name, 
00363     void (*pSetFunction)(bool),
00364     bool (*pGetFunction)(), int index)
00365     : OutputSymbol<bool>(name, pSetFunction, pGetFunction, index)
00366   {};
00367 };
00368 
00369 /** 
00370 * @class EnumeratedOutputSymbol
00371 *
00372 * Represents a enumerated output symbol of the Engine 
00373 *
00374 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00375 */
00376 class EnumeratedOutputSymbol : public OutputSymbol<int>
00377 {
00378 public:
00379   /** 
00380   * Constructor 
00381   * @param name The name of the symbol, for debugging purposes
00382   * @param enumeration Pointer to the list of enumeration elements
00383   * @param pVariable A pointer to the variable that the symbol stands for
00384   * @param index Index of the symbol in array in corresponding engine
00385   */
00386   EnumeratedOutputSymbol(const char* name, Enumeration* enumeration, int* pVariable, int index)
00387     : OutputSymbol<int>(name, pVariable, index), enumeration(enumeration)
00388   {};
00389   
00390   
00391   /** Constructor 
00392   * @param name The name of the symbol, for debugging purposes
00393   * @param enumeration Pointer to the list of enumeration elements
00394   * @param pSetFunction A pointer to a function in the software environment that sets the value of the symbol
00395   * @param pGetFunction A pointer to a function in the software environment that returns the value of the symbol
00396   * @param index Index of the symbol in array in corresponding engine
00397   */
00398   EnumeratedOutputSymbol(const char* name, Enumeration* enumeration,
00399     void (*pSetFunction)(int),
00400     int (*pGetFunction)(), int index)
00401     : OutputSymbol<int>(name, pSetFunction, pGetFunction, index), enumeration(enumeration)
00402   {};
00403   
00404   /** Pointer to the list of enumeration elements */
00405   Enumeration* enumeration;
00406 };
00407 
00408 /**
00409 * @class Symbols
00410 *
00411 * Handles the symbols of the Engine.
00412 *
00413 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00414 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
00415 */
00416 class Symbols
00417 {
00418 public:
00419 /** 
00420 * Constructor.
00421 * @param errorHandler Is invoked when errors occur
00422   */
00423   Symbols(ErrorHandler& errorHandler)
00424     : errorHandler(errorHandler) {};
00425   
00426   /** Destructor */
00427   virtual ~Symbols();
00428   
00429   /**
00430   * Registers an enum element for an enumeration.
00431   * @param enumName The name of the enumeration
00432   * @param name The name of the enum element
00433   * @param value The value of the element
00434   */
00435   void registerEnumElement(const char* enumName, 
00436     const char* name, int value);
00437 
00438   /** 
00439   * Registers the address of a variable for a decimal input symbol.
00440   * @param name The name of the symbol
00441   * @param pVariable A pointer to a variable in the software environment 
00442   */
00443   void registerDecimalInputSymbol(const char* name, const double* pVariable);
00444   
00445   /** 
00446   * Registers the address of a function for a decimal input symbol.
00447   * @param name The name of the symbol
00448   * @param pFunction A pointer to a function that calculates a value for the symbol
00449   */
00450   void registerDecimalInputSymbol(const char* name,
00451     double (*pFunction)());
00452   
00453   /** 
00454   * Registers the address of a function for parameter change notification for a decimal input symbol.
00455   * @param name The name of the symbol
00456   * @param pFunction A pointer to the parameter change notification function
00457   */
00458   void registerDecimalInputSymbolParametersChanged(const char* name,
00459     void (*pFunction)());
00460 
00461   /** 
00462   * Registers a parameter of a parameterized decimal input symbol.
00463   * @param symbolName The name of the symbol
00464   * @param name The name of the parameter
00465   * @param pParam A pointer to the parameter
00466   */
00467   void registerDecimalInputSymbolDecimalParameter(const char* symbolName, 
00468     const char* name, double* pParam);
00469   void registerDecimalInputSymbolBooleanParameter(const char* symbolName, 
00470     const char* name, bool* pParam);
00471   void registerDecimalInputSymbolEnumeratedParameter(const char* symbolName, 
00472     const char* name, const char* enumName, int* pParam);
00473 
00474   /** 
00475   * Registers the address of a variable for a boolean input symbol.
00476   * @param name The name of the symbol
00477   * @param pVariable A pointer to a variable in the software environment 
00478   */
00479   void registerBooleanInputSymbol(const char* name, const bool* pVariable);
00480   
00481   /** 
00482   * Registers the address of a function for a boolean input symbol.
00483   * @param name The name of the symbol
00484   * @param pFunction A pointer to a function that calculates a value for the symbol
00485   */
00486   void registerBooleanInputSymbol(const char* name, 
00487     bool (*pFunction)());
00488   
00489   /** 
00490   * Registers the address of a function for parameter change notification for a boolean input symbol.
00491   * @param name The name of the symbol
00492   * @param pFunction A pointer to the parameter change notification function
00493   */
00494   void registerBooleanInputSymbolParametersChanged(const char* name,
00495     void (*pFunction)());
00496 
00497   /** 
00498   * Registers a parameter of a parameterized boolean input symbol.
00499   * @param symbolName The name of the symbol
00500   * @param name The name of the parameter
00501   * @param pParam A pointer to the parameter
00502   */
00503   void registerBooleanInputSymbolDecimalParameter(const char* symbolName, 
00504     const char* name, double* pParam);
00505   void registerBooleanInputSymbolBooleanParameter(const char* symbolName, 
00506     const char* name, bool* pParam);
00507   void registerBooleanInputSymbolEnumeratedParameter(const char* symbolName, 
00508     const char* name, const char* enumName, int* pParam);
00509 
00510   /** 
00511   * Registers the address of a variable for a enumerated input symbol.
00512   * @param name The name of the symbol
00513   * @param enumName The name of the associated enumeration
00514   * @param pVariable A pointer to a variable in the software environment 
00515   */
00516   void registerEnumeratedInputSymbol(const char* name, const char* enumName, const int* pVariable);
00517   
00518   /** 
00519   * Registers the address of a function for a enumerated input symbol.
00520   * @param name The name of the symbol
00521   * @param enumName The name of the associated enumeration
00522   * @param pFunction A pointer to a function that calculates a value for the symbol
00523   */
00524   void registerEnumeratedInputSymbol(const char* name, const char* enumName, 
00525     int (*pFunction)());
00526   
00527   /** 
00528   * Registers the address of a function for parameter change notification for an enumerated input symbol.
00529   * @param name The name of the symbol
00530   * @param pFunction A pointer to the parameter change notification function
00531   */
00532   void registerEnumeratedInputSymbolParametersChanged(const char* name,
00533     void (*pFunction)());
00534 
00535   /** 
00536   * Registers a parameter of an enumerated input symbol.
00537   * @param symbolName The name of the symbol
00538   * @param name The name of the parameter
00539   * @param pParam A pointer to the parameter
00540   */
00541   void registerEnumeratedInputSymbolDecimalParameter(const char* symbolName, 
00542     const char* name, double* pParam);
00543   void registerEnumeratedInputSymbolBooleanParameter(const char* symbolName, 
00544     const char* name, bool* pParam);
00545   void registerEnumeratedInputSymbolEnumeratedParameter(const char* symbolName, 
00546     const char* name, const char* enumName, int* pParam);
00547 
00548   /** 
00549   * Registers the address of a variable for a decimal output symbol.
00550   * @param name The name of the symbol
00551   * @param pVariable A pointer to a variable in the software environment 
00552   */
00553   void registerDecimalOutputSymbol(const char* name, double* pVariable);
00554 
00555   /** 
00556   * Registers the address of a function for a decimal output symbol.
00557   * @param name The name of the symbol
00558   * @param pSetFunction A pointer to a function that sets a value for the symbol
00559   * @param pGetFunction A pointer to a function that returns a value for the symbol
00560   */
00561   void registerDecimalOutputSymbol(const char* name,
00562     void (*pSetFunction)(double),
00563     double (*pGetFunction)()
00564   );
00565 
00566   /** 
00567   * Registers the address of a variable for a boolean output symbol.
00568   * @param name The name of the symbol
00569   * @param pVariable A pointer to a variable in the software environment 
00570   */
00571   void registerBooleanOutputSymbol(const char* name, bool* pVariable);
00572 
00573   /** 
00574   * Registers the address of a function for a boolean output symbol.
00575   * @param name The name of the symbol
00576   * @param pSetFunction A pointer to a function that sets a value for the symbol
00577   * @param pGetFunction A pointer to a function that returns a value for the symbol
00578   */
00579   void registerBooleanOutputSymbol(const char* name, 
00580     void (*pSetFunction)(bool),
00581     bool (*pGetFunction)()
00582   );
00583 
00584   /** 
00585   * Registers the address of a variable for a enumerated output symbol.
00586   * @param name The name of the symbol
00587   * @param enumName The name of the associated enumeration
00588   * @param pVariable A pointer to a variable in the software environment 
00589   */
00590   void registerEnumeratedOutputSymbol(const char* name, const char* enumName, int* pVariable);
00591   
00592   /** 
00593   * Registers the address of a function for a enumerated output symbol.
00594   * @param name The name of the symbol
00595   * @param enumName The name of the associated enumeration
00596   * @param pSetFunction A pointer to a function that sets a value for the symbol
00597   * @param pGetFunction A pointer to a function that returns a value for the symbol
00598   */
00599   void registerEnumeratedOutputSymbol(const char* name, const char* enumName, 
00600     void (*pSetFunction)(int),
00601     int (*pGetFunction)()
00602   );
00603   
00604   /** Sets all output symbols to unset */
00605   void resetOutputSymbols();
00606   
00607   /** The enumerations */
00608   NamedArray<Enumeration*> enumerations;
00609 
00610   /** The decimal input symbols */
00611   NamedArray<DecimalInputSymbol*> decimalInputSymbols;
00612     
00613   /** The boolean input symbols */
00614   NamedArray<BooleanInputSymbol*> booleanInputSymbols;
00615   
00616   /** The enumerated input symbols */
00617   NamedArray<EnumeratedInputSymbol*> enumeratedInputSymbols;
00618   
00619   /** The decimal output symbols */
00620   NamedArray<DecimalOutputSymbol*> decimalOutputSymbols;
00621 
00622   /** The boolean output symbols */
00623   NamedArray<BooleanOutputSymbol*> booleanOutputSymbols;
00624 
00625   /** The enumerated output symbols */
00626   NamedArray<EnumeratedOutputSymbol*> enumeratedOutputSymbols;
00627 
00628 private:
00629   /** Is invoked when errors occur */
00630   ErrorHandler& errorHandler;
00631 };
00632 
00633 } // namespace
00634 
00635 #endif //__XabslSymbols_h_

Up | Main Page | Generated at Wed Aug 19 17:32:29 2009.