Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Xabsl2/Xabsl2Engine/Xabsl2Symbols.h

Go to the documentation of this file.
00001 /**
00002 * @file Xabsl2Symbols.h
00003 *
00004 * Definition of class Xabsl2Symbols and helper classes
00005 *
00006 * @author Martin Lötzsch
00007 */
00008 
00009 #ifndef __Xabsl2Symbols_h_
00010 #define __Xabsl2Symbols_h_
00011 
00012 #include "Xabsl2Tools.h"
00013 
00014 /**
00015 * @class Xabsl2FunctionProvider
00016 *
00017 * Base class for all those classes that want to register functions for symbols
00018 * at a Xabsl2Engine
00019 *
00020 * @author Martin Lötzsch
00021 */
00022 class Xabsl2FunctionProvider {
00023   //virtual void dummy(){}
00024 };
00025 
00026 
00027 /** 
00028 * A Template for the input symbol classes
00029 * @author Martin Lötzsch
00030 */
00031 template<class T> class Xabsl2InputSymbol : public Xabsl2NamedItem
00032 {
00033 public:
00034 /** 
00035 * Constructor 
00036 * @param name The name of the symbol, for debugging purposes
00037 * @param pVariable A pointer to the variable that the symbol stands for
00038   */
00039   Xabsl2InputSymbol(const char* name, const T* pVariable)
00040     : Xabsl2NamedItem(name), pV(pVariable), pI(0), pF(0)
00041   {};
00042   
00043   
00044   /** Constructor 
00045   * @param name The name of the symbol, for debugging purposes
00046   * @param pFunction A pointer to a boolean returning function in the software environment 
00047   * @param pInstance A pointer to the instance that contains the function
00048   */
00049   Xabsl2InputSymbol(const char* name,
00050     Xabsl2FunctionProvider* pInstance,
00051     T (Xabsl2FunctionProvider::*pFunction)())
00052     : Xabsl2NamedItem(name), pV(0), pI(pInstance), pF(pFunction) {};
00053   
00054   /** returns the value of the symbol */
00055   T getValue() const
00056   { if (pF!=0) return (pI->*pF)(); else return *pV; }
00057   
00058 private:
00059   /** A pointer to a variable in the software environment */
00060   const T* pV; 
00061   
00062   /** A pointer to the instance object that contains the function */
00063   Xabsl2FunctionProvider* pI;
00064   
00065   /** A pointer to a T returning function in the software environment */
00066   T (Xabsl2FunctionProvider::*pF)(); 
00067 };
00068 
00069 /** 
00070 * @class Xabsl2DecimalInputSymbol
00071 *
00072 * Represents a decimal input symbol of the Xabsl2Engine 
00073 *
00074 * @author Martin Lötzsch
00075 */
00076 class Xabsl2DecimalInputSymbol : public Xabsl2InputSymbol<double>
00077 {
00078 public:
00079 /** 
00080 * Constructor 
00081 * @param name The name of the symbol, for debugging purposes
00082 * @param pVariable A pointer to the variable that the symbol stands for
00083   */
00084   Xabsl2DecimalInputSymbol(const char* name, const double* pVariable)
00085     : Xabsl2InputSymbol<double>(name, pVariable) 
00086   {};
00087   
00088   
00089   /** Constructor 
00090   * @param name The name of the symbol, for debugging purposes
00091   * @param pFunction A pointer to a double returning function in the software environment 
00092   * @param pInstance A pointer to the instance that contains the function
00093   */
00094   Xabsl2DecimalInputSymbol(const char* name,
00095     Xabsl2FunctionProvider* pInstance,
00096     double (Xabsl2FunctionProvider::*pFunction)())
00097     : Xabsl2InputSymbol<double>(name, pInstance, pFunction) {};
00098 };
00099 
00100 /** 
00101 * @class Xabsl2DecimalInputFunction
00102 *
00103 * Represents a parameterized decimal input function of the Xabsl2Engine 
00104 *
00105 * @author Martin Lötzsch
00106 */
00107 class Xabsl2DecimalInputFunction : public Xabsl2NamedItem
00108 {
00109 public:
00110 /** Constructor 
00111 * @param name The name of the function, for debugging purposes
00112 * @param pFunction A pointer to a double returning function in the software environment 
00113 * @param pInstance A pointer to the instance that contains the function
00114   */
00115   Xabsl2DecimalInputFunction(const char* name,
00116     Xabsl2FunctionProvider* pInstance,
00117     double (Xabsl2FunctionProvider::*pFunction)())
00118     : Xabsl2NamedItem(name), pF(pFunction), pI(pInstance)
00119   {};
00120   
00121   /** 
00122   * Calculates the value of the function. 
00123   * Note that the parameters for the function have to be set before that function is called.
00124   */ 
00125   double getValue() { return (pI->*pF)(); }
00126   
00127   /** References to the function parameters */
00128   Xabsl2Array<double&> parameters;
00129   
00130 private:
00131   /** A pointer to a double returning function in the software environment */
00132   double (Xabsl2FunctionProvider::*pF)(); 
00133   
00134   /** A pointer to the instance object that contains the function */
00135   Xabsl2FunctionProvider* pI;
00136 };
00137 
00138 /** 
00139 * @class Xabsl2BooleanInputSymbol
00140 *
00141 * Represents a boolean input symbol of the Xabsl2Engine 
00142 *
00143 * @author Martin Lötzsch
00144 */
00145 class Xabsl2BooleanInputSymbol : public Xabsl2InputSymbol<bool>
00146 {
00147 public:
00148 /** 
00149 * Constructor 
00150 * @param name The name of the symbol, for debugging purposes
00151 * @param pVariable A pointer to the variable that the symbol stands for
00152   */
00153   Xabsl2BooleanInputSymbol(const char* name, const bool* pVariable)
00154     : Xabsl2InputSymbol<bool>(name, pVariable) 
00155   {};
00156   
00157   
00158   /** Constructor 
00159   * @param name The name of the symbol, for debugging purposes
00160   * @param pFunction A pointer to a boolean returning function in the software environment 
00161   * @param pInstance A pointer to the instance that contains the function
00162   */
00163   Xabsl2BooleanInputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00164     bool (Xabsl2FunctionProvider::*pFunction)())
00165     : Xabsl2InputSymbol<bool>(name, pInstance, pFunction) {};
00166 };
00167 
00168 /**
00169 * @class Xabsl2EnumElement
00170 * Represents an enum element that is part of an enumerated input or output symbol.
00171 * @author Martin Lötzsch
00172 */
00173 class Xabsl2EnumElement : public Xabsl2NamedItem
00174 {
00175 public:
00176 /** 
00177 * Constructor 
00178 * @param name The name of the enum element as specified in the XML formalization
00179 * @param value The value for the element from the software environment
00180   */
00181   Xabsl2EnumElement(const char* name, int value)
00182     : Xabsl2NamedItem(name), v(value) {};
00183   
00184   /** The enum value from a function or variable in the software environment */
00185   int v;
00186 };
00187 
00188 /** 
00189 * @class Xabsl2EnumeratedInputSymbol
00190 *
00191 * Represents a enumerated input symbol of the Xabsl2Engine 
00192 *
00193 * @author Martin Lötzsch
00194 */
00195 class Xabsl2EnumeratedInputSymbol : public Xabsl2InputSymbol<int>
00196 {
00197 public:
00198 /** 
00199 * Constructor 
00200 * @param name The name of the symbol, for debugging purposes
00201 * @param pVariable A pointer to the variable that the symbol stands for
00202   */
00203   Xabsl2EnumeratedInputSymbol(const char* name, const int* pVariable)
00204     : Xabsl2InputSymbol<int>(name, pVariable) 
00205   {};
00206   
00207   
00208   /** Constructor 
00209   * @param name The name of the symbol, for debugging purposes
00210   * @param pFunction A pointer to an int returning function in the software environment 
00211   * @param pInstance A pointer to the instance that contains the function
00212   */
00213   Xabsl2EnumeratedInputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00214     int (Xabsl2FunctionProvider::*pFunction)())
00215     : Xabsl2InputSymbol<int>(name, pInstance, pFunction) {};
00216   
00217   /** Destructor. Deletes the enum elements */
00218   ~Xabsl2EnumeratedInputSymbol();
00219   
00220   /** 
00221   * Assignes a enum value from a function or variable in the software environment 
00222   * to the enum-element string in the XML formalization.
00223   */
00224   Xabsl2Array<Xabsl2EnumElement*> enumElements;
00225 };
00226 
00227 /** 
00228 * @class Xabsl2EnumeratedOutputSymbol
00229 *
00230 * Represents a enumerated output symbol of the Xabsl2Engine 
00231 *
00232 * @author Martin Lötzsch
00233 */
00234 class Xabsl2EnumeratedOutputSymbol : public Xabsl2NamedItem
00235 {
00236 public:
00237 /** 
00238 * Constructor 
00239 * @param name The name of the symbol, for debugging purposes
00240 * @param pVariable A pointer to the variable that the symbol stands for
00241   */
00242   Xabsl2EnumeratedOutputSymbol(const char* name, int* pVariable)
00243     : Xabsl2NamedItem(name), activeValue(0), pV(pVariable), pF(0), pI(0)
00244   {};
00245   
00246   
00247   /** Constructor 
00248   * @param name The name of the symbol, for debugging purposes
00249   * @param pFunction A pointer to a function in the software environment that sets the symbol
00250   * @param pInstance A pointer to the instance that contains the function
00251   */
00252   Xabsl2EnumeratedOutputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00253     void (Xabsl2FunctionProvider::*pFunction)(int))
00254     : Xabsl2NamedItem(name), activeValue(0), activeValueWasSet(false),
00255     pV(0), pF(pFunction), pI(pInstance) {};
00256   
00257   /** Destructor. Deletes the enum elements */
00258   ~Xabsl2EnumeratedOutputSymbol();
00259   
00260   /** 
00261   * Assignes a enum value from a function or variable in the software environment 
00262   * to the enum-element string in the XML formalization.
00263   */
00264   Xabsl2Array<Xabsl2EnumElement*> enumElements;
00265   
00266   /** The value that was set during the last execution of the option graph. */
00267   int activeValue;
00268   
00269   /** If true, the value was set during the last execution of the option graph. */
00270   bool activeValueWasSet;
00271   
00272   /** Sets the current set value to the software environment */
00273   void setActiveValue();
00274   
00275 private:
00276   
00277   /** A pointer to a variable in the software environment */
00278   int* pV; 
00279   
00280   /** A pointer to a function that sets the symbol in the software environment */
00281   void (Xabsl2FunctionProvider::*pF)(int); 
00282   
00283   /** A pointer to the instance object that contains the function */
00284   Xabsl2FunctionProvider* pI;
00285 };
00286 
00287 /**
00288 * @class Xabsl2Symbols
00289 *
00290 * Handles the symbols of the Xabsl2Engine.
00291 *
00292 * @author Martin Lötzsch
00293 */
00294 class Xabsl2Symbols
00295 {
00296 public:
00297 /** 
00298 * Constructor.
00299 * @param errorHandler Is invoked when errors occur
00300   */
00301   Xabsl2Symbols(Xabsl2ErrorHandler& errorHandler)
00302     : errorHandler(errorHandler) {};
00303   
00304   /** Destructor */
00305   ~Xabsl2Symbols();
00306   
00307   /** 
00308   * Registers the address of a variable for a decimal input symbol.
00309   * @param name The name of the symbol
00310   * @param pVariable A pointer to a variable in the software environment 
00311   */
00312   void registerDecimalInputSymbol(const char* name, const double* pVariable);
00313   
00314   /** 
00315   * Registers the address of a function for a decimal input symbol.
00316   * @param name The name of the symbol
00317   * @param pFunction A pointer to a function that calculates a value for the symbol
00318   * @param pInstance A pointer to an object that provides the function
00319   */
00320   void registerDecimalInputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00321     double (Xabsl2FunctionProvider::*pFunction)());
00322   
00323     /** 
00324     * Returns a decimal input symbol for a given name
00325     * Note that the function crashes if the symbol does not exist.
00326     * @param name The name of the symbol
00327     * @return A pointer to the symbol
00328   */
00329   Xabsl2DecimalInputSymbol* getDecimalInputSymbol(const char* name);
00330   
00331   /** Returns whether a decimal input symbol exists */
00332   bool existsDecimalInputSymbol(const char* name);
00333   
00334   /** Returns the number of DecimalInputSymbols */
00335   int numberOfDecimalInputSymbols();
00336   
00337   /** Returns the DecimalInputSymbol at index. 
00338   * @param index The index for the array access 
00339   */
00340   const Xabsl2DecimalInputSymbol* getDecimalInputSymbol( int index);
00341   
00342   /** 
00343   * Registers the address of a parameterized decimal input function.
00344   * @param name The name of the function
00345   * @param pFunction A pointer to the function.
00346   * @param pInstance A pointer to an object that provides the function.
00347   */
00348   void registerDecimalInputFunction(const char* name, Xabsl2FunctionProvider* pInstance,
00349     double (Xabsl2FunctionProvider::*pFunction)());
00350   
00351     /** 
00352     * Registers a parameter of a parameterized decimal input function.
00353     * @param functionName The name of the function
00354     * @param name The name of the parameter
00355     * @param param A reference to the parameter
00356   */
00357   void registerDecimalInputFunctionParameter(const char* functionName, 
00358     const char* name, double& param);
00359   
00360     /** 
00361     * Returns a decimal input function for a given name
00362     * Note that the function crashes if the function does not exist.
00363     * @param name The name of the function
00364     * @return A pointer to the function
00365   */
00366   Xabsl2DecimalInputFunction* getDecimalInputFunction(const char* name);
00367   
00368   /** Returns whether a decimal input function exists */
00369   bool existsDecimalInputFunction(const char* name);
00370   
00371   
00372   /** 
00373   * Registers the address of a variable for a boolean input symbol.
00374   * @param name The name of the symbol
00375   * @param pVariable A pointer to a variable in the software environment 
00376   */
00377   void registerBooleanInputSymbol(const char* name, const bool* pVariable);
00378   
00379   /** 
00380   * Registers the address of a function for a boolean input symbol.
00381   * @param name The name of the symbol
00382   * @param pFunction A pointer to a function that calculates a value for the symbol
00383   * @param pInstance A pointer to an object that provides the function
00384   */
00385   void registerBooleanInputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00386     bool (Xabsl2FunctionProvider::*pFunction)());
00387   
00388     /** 
00389     * Returns a boolean input symbol for a given name
00390     * Note that the function crashes if the symbol does not exist.
00391     * @param name The name of the symbol
00392     * @return A pointer to the symbol
00393   */
00394   Xabsl2BooleanInputSymbol* getBooleanInputSymbol(const char* name);
00395   
00396   
00397   /** Returns whether a boolean input symbol exists */
00398   bool existsBooleanInputSymbol(const char* name);
00399   
00400   /** Returns the number of BooleanInputSymbols */
00401   int numberOfBooleanInputSymbols();
00402   
00403   /** Returns the DecimalInputSymbol at index. 
00404   * @param index The index for the array access 
00405   */
00406   const Xabsl2BooleanInputSymbol* getBooleanInputSymbol( int index);  
00407   /** 
00408   * Registers the address of a variable for a enumerated input symbol.
00409   * @param name The name of the symbol
00410   * @param pVariable A pointer to a variable in the software environment 
00411   */
00412   void registerEnumeratedInputSymbol(const char* name, const int* pVariable);
00413   
00414   /** 
00415   * Registers the address of a function for a enumerated input symbol.
00416   * @param name The name of the symbol
00417   * @param pFunction A pointer to a function that calculates a value for the symbol
00418   * @param pInstance A pointer to an object that provides the function
00419   */
00420   void registerEnumeratedInputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00421     int (Xabsl2FunctionProvider::*pFunction)());
00422   
00423     /** 
00424     * Returns a enumerated input symbol for a given name
00425     * Note that the function crashes if the symbol does not exist.
00426     * @param name The name of the symbol
00427     * @return A pointer to the symbol
00428   */
00429   Xabsl2EnumeratedInputSymbol* getEnumeratedInputSymbol(const char* name);
00430   
00431   /**
00432   * Registers an enum element for an enumerated input symbol.
00433   * @param symbolName The name of the symbol
00434   * @param name The name of the enum element
00435   * @param value The value of the element
00436   */
00437   void registerEnumeratedInputSymbolEnumElement(const char* symbolName, 
00438     const char* name, int value);
00439   
00440   /** Returns whether a boolean input symbol exists */
00441   bool existsEnumeratedInputSymbol(const char* name);
00442   
00443   /** Returns the number of EnumeratedInputSymbols */
00444   int numberOfEnumeratedInputSymbols();
00445   
00446   /** Returns the DecimalInputSymbol at index. 
00447   * @param index The index for the array access 
00448   */
00449   const Xabsl2EnumeratedInputSymbol* getEnumeratedInputSymbol( int index);
00450   
00451   
00452   /** 
00453   * Registers the address of a variable for a enumerated output symbol.
00454   * @param name The name of the symbol
00455   * @param pVariable A pointer to a variable in the software environment 
00456   */
00457   void registerEnumeratedOutputSymbol(const char* name, int* pVariable);
00458   
00459   /** 
00460   * Registers the address of a function for a enumerated output symbol.
00461   * @param name The name of the symbol
00462   * @param pFunction A pointer to a function that sets a value for the symbol
00463   * @param pInstance A pointer to an object that provides the function
00464   */
00465   void registerEnumeratedOutputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00466     void (Xabsl2FunctionProvider::*pFunction)(int));
00467   
00468     /** 
00469     * Returns a enumerated output symbol for a given name
00470     * Note that the function crashes if the symbol does not exist.
00471     * @param name The name of the symbol
00472     * @return A pointer to the symbol
00473   */
00474   Xabsl2EnumeratedOutputSymbol* getEnumeratedOutputSymbol(const char* name);
00475   
00476   /**
00477   * Registers an enum element for an enumerated output symbol.
00478   * @param symbolName The name of the symbol
00479   * @param name The name of the enum element
00480   * @param value The value of the element
00481   */
00482   void registerEnumeratedOutputSymbolEnumElement(const char* symbolName, 
00483     const char* name, int value);
00484   
00485   /** Returns whether a boolean output symbol exists */
00486   bool existsEnumeratedOutputSymbol(const char* name);
00487   
00488   /** Sets the output symbols to the software environment */
00489   void setOutputSymbols();
00490   
00491 private:
00492   /** The decimal input symbols */
00493   Xabsl2Array<Xabsl2DecimalInputSymbol*> decimalInputSymbols;
00494   
00495   /** The decimal input functions */
00496   Xabsl2Array<Xabsl2DecimalInputFunction*> decimalInputFunctions;
00497   
00498   /** The decimal input symbols */
00499   Xabsl2Array<Xabsl2BooleanInputSymbol*> booleanInputSymbols;
00500   
00501   /** The enumerated input symbols */
00502   Xabsl2Array<Xabsl2EnumeratedInputSymbol*> enumeratedInputSymbols;
00503   
00504   /** The enumerated output symbols */
00505   Xabsl2Array<Xabsl2EnumeratedOutputSymbol*> enumeratedOutputSymbols;
00506   
00507   /** Is invoked when errors occur */
00508   Xabsl2ErrorHandler& errorHandler;
00509 };
00510 
00511 
00512 
00513 #endif //__Xabsl2Symbols_h_

Generated on Mon Mar 20 22:00:10 2006 for GT2005 by doxygen 1.3.6