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   
00335   /** 
00336   * Registers the address of a parameterized decimal input function.
00337   * @param name The name of the function
00338   * @param pFunction A pointer to the function.
00339   * @param pInstance A pointer to an object that provides the function.
00340   */
00341   void registerDecimalInputFunction(const char* name, Xabsl2FunctionProvider* pInstance,
00342     double (Xabsl2FunctionProvider::*pFunction)());
00343   
00344   /** 
00345   * Registers a parameter of a parameterized decimal input function.
00346   * @param functionName The name of the function
00347   * @param name The name of the parameter
00348   * @param param A reference to the parameter
00349   */
00350   void registerDecimalInputFunctionParameter(const char* functionName, 
00351     const char* name, double& param);
00352   
00353   /** 
00354   * Returns a decimal input function for a given name
00355   * Note that the function crashes if the function does not exist.
00356     * @param name The name of the function
00357     * @return A pointer to the function
00358   */
00359   Xabsl2DecimalInputFunction* getDecimalInputFunction(const char* name);
00360   
00361   /** Returns whether a decimal input function exists */
00362   bool existsDecimalInputFunction(const char* name);
00363 
00364   
00365   /** 
00366   * Registers the address of a variable for a boolean input symbol.
00367   * @param name The name of the symbol
00368   * @param pVariable A pointer to a variable in the software environment 
00369   */
00370   void registerBooleanInputSymbol(const char* name, const bool* pVariable);
00371   
00372   /** 
00373   * Registers the address of a function for a boolean input symbol.
00374   * @param name The name of the symbol
00375   * @param pFunction A pointer to a function that calculates a value for the symbol
00376   * @param pInstance A pointer to an object that provides the function
00377   */
00378   void registerBooleanInputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00379     bool (Xabsl2FunctionProvider::*pFunction)());
00380   
00381     /** 
00382     * Returns a boolean input symbol for a given name
00383     * Note that the function crashes if the symbol does not exist.
00384     * @param name The name of the symbol
00385     * @return A pointer to the symbol
00386   */
00387   Xabsl2BooleanInputSymbol* getBooleanInputSymbol(const char* name);
00388   
00389   /** Returns whether a boolean input symbol exists */
00390   bool existsBooleanInputSymbol(const char* name);
00391   
00392   /** 
00393   * Registers the address of a variable for a enumerated input symbol.
00394   * @param name The name of the symbol
00395   * @param pVariable A pointer to a variable in the software environment 
00396   */
00397   void registerEnumeratedInputSymbol(const char* name, const int* pVariable);
00398   
00399   /** 
00400   * Registers the address of a function for a enumerated input symbol.
00401   * @param name The name of the symbol
00402   * @param pFunction A pointer to a function that calculates a value for the symbol
00403   * @param pInstance A pointer to an object that provides the function
00404   */
00405   void registerEnumeratedInputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00406     int (Xabsl2FunctionProvider::*pFunction)());
00407   
00408     /** 
00409     * Returns a enumerated input symbol for a given name
00410     * Note that the function crashes if the symbol does not exist.
00411     * @param name The name of the symbol
00412     * @return A pointer to the symbol
00413   */
00414   Xabsl2EnumeratedInputSymbol* getEnumeratedInputSymbol(const char* name);
00415   
00416   /**
00417   * Registers an enum element for an enumerated input symbol.
00418   * @param symbolName The name of the symbol
00419   * @param name The name of the enum element
00420   * @param value The value of the element
00421   */
00422   void registerEnumeratedInputSymbolEnumElement(const char* symbolName, 
00423     const char* name, int value);
00424   
00425   /** Returns whether a boolean input symbol exists */
00426   bool existsEnumeratedInputSymbol(const char* name);
00427   
00428   
00429   /** 
00430   * Registers the address of a variable for a enumerated output symbol.
00431   * @param name The name of the symbol
00432   * @param pVariable A pointer to a variable in the software environment 
00433   */
00434   void registerEnumeratedOutputSymbol(const char* name, int* pVariable);
00435   
00436   /** 
00437   * Registers the address of a function for a enumerated output symbol.
00438   * @param name The name of the symbol
00439   * @param pFunction A pointer to a function that sets a value for the symbol
00440   * @param pInstance A pointer to an object that provides the function
00441   */
00442   void registerEnumeratedOutputSymbol(const char* name, Xabsl2FunctionProvider* pInstance,
00443     void (Xabsl2FunctionProvider::*pFunction)(int));
00444   
00445     /** 
00446     * Returns a enumerated output symbol for a given name
00447     * Note that the function crashes if the symbol does not exist.
00448     * @param name The name of the symbol
00449     * @return A pointer to the symbol
00450   */
00451   Xabsl2EnumeratedOutputSymbol* getEnumeratedOutputSymbol(const char* name);
00452   
00453   /**
00454   * Registers an enum element for an enumerated output symbol.
00455   * @param symbolName The name of the symbol
00456   * @param name The name of the enum element
00457   * @param value The value of the element
00458   */
00459   void registerEnumeratedOutputSymbolEnumElement(const char* symbolName, 
00460     const char* name, int value);
00461   
00462   /** Returns whether a boolean output symbol exists */
00463   bool existsEnumeratedOutputSymbol(const char* name);
00464   
00465   /** Sets the output symbols to the software environment */
00466   void setOutputSymbols();
00467   
00468 private:
00469   /** The decimal input symbols */
00470   Xabsl2Array<Xabsl2DecimalInputSymbol*> decimalInputSymbols;
00471   
00472   /** The decimal input functions */
00473   Xabsl2Array<Xabsl2DecimalInputFunction*> decimalInputFunctions;
00474   
00475   /** The decimal input symbols */
00476   Xabsl2Array<Xabsl2BooleanInputSymbol*> booleanInputSymbols;
00477   
00478   /** The enumerated input symbols */
00479   Xabsl2Array<Xabsl2EnumeratedInputSymbol*> enumeratedInputSymbols;
00480   
00481   /** The enumerated output symbols */
00482   Xabsl2Array<Xabsl2EnumeratedOutputSymbol*> enumeratedOutputSymbols;
00483   
00484   /** Is invoked when errors occur */
00485   Xabsl2ErrorHandler& errorHandler;
00486 };
00487 
00488 
00489 
00490 #endif //__Xabsl2Symbols_h_
00491 
00492 /*
00493 * Change Log:
00494 *
00495 * $Log: Xabsl2Symbols.h,v $
00496 * Revision 1.1.1.1  2004/05/22 17:37:58  cvsadm
00497 * created new repository GT2004_WM
00498 *
00499 * Revision 1.2  2004/03/19 15:34:01  tim
00500 * added some const qualifiers
00501 *
00502 * Revision 1.1  2003/10/07 10:13:25  cvsadm
00503 * Created GT2004 (M.J.)
00504 *
00505 * Revision 1.4  2003/09/30 10:51:11  dueffert
00506 * typos fixed
00507 *
00508 * Revision 1.3  2003/09/16 13:27:21  loetzsch
00509 * changed all occurrences of "option tree" to "option graph"
00510 *
00511 * Revision 1.2  2003/08/09 14:53:10  dueffert
00512 * files and docu beautified
00513 *
00514 * Revision 1.1.1.1  2003/07/02 09:40:29  cvsadm
00515 * created new repository for the competitions in Padova from the 
00516 * tamara CVS (Tuesday 2:00 pm)
00517 *
00518 * removed unused solutions
00519 *
00520 * Revision 1.12  2003/05/25 22:36:32  loetzsch
00521 * only when an output symbol was set during the execution of the graph,
00522 * coresponding function is invoked or the coresponding variable is changed.
00523 *
00524 * Revision 1.11  2003/03/06 11:44:33  dueffert
00525 * re-order warnings removed
00526 *
00527 * Revision 1.10  2003/01/28 18:07:47  loetzsch
00528 * no message
00529 *
00530 * Revision 1.9  2003/01/13 13:18:44  loetzsch
00531 * removed "#include <string.h>"
00532 *
00533 * Revision 1.8  2003/01/09 17:27:59  loetzsch
00534 * changed comments
00535 *
00536 * Revision 1.7  2003/01/09 10:03:00  dueffert
00537 * added missing chars
00538 *
00539 * Revision 1.6  2003/01/09 10:01:20  loetzsch
00540 * added interfaces to the Xabsl2 Dialog in the RobotControl application
00541 *
00542 * Revision 1.5  2003/01/08 11:07:12  loetzsch
00543 * all kinds of symbols now can be registered at the Xabsl2Engine
00544 *
00545 * Revision 1.4  2002/12/18 16:22:56  dueffert
00546 * doxygen docu corrected
00547 *
00548 * Revision 1.3  2002/12/16 14:19:58  loetzsch
00549 * added boolean input symbols
00550 *
00551 * Revision 1.2  2002/12/07 12:34:13  loetzsch
00552 * added debug interfaces
00553 *
00554 * Revision 1.1  2002/12/06 21:13:37  loetzsch
00555 * Decimal input symbols can now be registered at the engine
00556 *
00557 */

Generated on Thu Sep 23 19:57:42 2004 for GT2004 by doxygen 1.3.6