00001 /** 00002 * @file Xabsl2Engine.h 00003 * 00004 * Declaration class Xabsl2Engine 00005 * 00006 * @author Matthias Jüngel 00007 * @author Martin Lötzsch 00008 */ 00009 00010 #ifndef __Xabsl2Engine_h_ 00011 #define __Xabsl2Engine_h_ 00012 00013 #include "Xabsl2Agent.h" 00014 00015 /** 00016 * Executes a behavior that was specified in the Xabsl language. 00017 * 00018 * @author Matthias Jüngel 00019 * @author Martin Lötzsch 00020 * 00021 */ 00022 class Xabsl2Engine : public Xabsl2Symbols 00023 { 00024 public: 00025 /** 00026 * Constructor 00027 * @param e Is invoked when there are problems during initialization 00028 * @param pTimeFunction a pointer to a function that returns the system time in ms. 00029 */ 00030 Xabsl2Engine(Xabsl2ErrorHandler& e, unsigned long (*pTimeFunction)()); 00031 00032 /** Destructor */ 00033 ~Xabsl2Engine(); 00034 00035 /** 00036 * Executes the engine for the selected agent starting from the root option. 00037 * (Including the selected basic behavior) 00038 */ 00039 void execute(); 00040 00041 /** Executes only the selected basic behavior */ 00042 void executeSelectedBasicBehavior(); 00043 00044 /** 00045 * Reads the intermediate code from an input source and creates the option graph. 00046 * Note that the basic behaviors and symbols have to be registered before that function is 00047 * called. 00048 */ 00049 void createOptionGraph(Xabsl2InputSource& input); 00050 00051 /** 00052 * Registers a basic behavior at the engine. 00053 * This must be done before the intermediate code is read. 00054 * @param basicBehavior A reference to the basic behavior 00055 */ 00056 void registerBasicBehavior(Xabsl2BasicBehavior& basicBehavior); 00057 00058 /** 00059 * Sets the selected Agent. 00060 * If the last selected agent was different from the new one, 00061 * the root option is changed depending on the new agent. 00062 * @param name The name of the agent 00063 * @return if the requested agent exists 00064 */ 00065 bool setSelectedAgent(const char* name); 00066 00067 private: 00068 /** The agents of the engine */ 00069 Xabsl2Array<Xabsl2Agent*> agents; 00070 00071 /** The selected agent */ 00072 Xabsl2Agent* selectedAgent; 00073 00074 /** The options of the engine */ 00075 Xabsl2Array<Xabsl2Option*> options; 00076 00077 /** The option where the execution of the option graph starts */ 00078 Xabsl2Option* rootOption; 00079 00080 /** The registered basic behaviors of the engine */ 00081 Xabsl2Array<Xabsl2BasicBehavior&> basicBehaviors; 00082 00083 /** The selected basic behavior */ 00084 Xabsl2BasicBehavior* selectedBasicBehavior; 00085 00086 /** Is invoked when there are problems during initialization */ 00087 Xabsl2ErrorHandler& errorHandler; 00088 00089 /** 00090 * A recursive function that is used to check for loops in the option graph. 00091 * @param currenOptionPath An array of the currently traced option path 00092 * @param currentDepth The depth of the current option path 00093 * @return If true, then a loop was detected. 00094 */ 00095 bool checkForLoops(Xabsl2Option* currenOptionPath[], int currentDepth); 00096 00097 /** If true, the engine was successfully initialized */ 00098 bool initialized; 00099 00100 /** A pointer to a function that returns the system time in ms. */ 00101 unsigned long (*pTimeFunction)(); 00102 public: 00103 //!@name Debugging Interface 00104 //!@{ 00105 00106 /** 00107 * Executes the option graph starting from a given option. 00108 * Can be called to test a single option. 00109 * @param name The name of the option 00110 * @return When false, the option is not known to the engine 00111 */ 00112 bool setRootOption(const char* name); 00113 00114 /** 00115 * Sets the root option of the selected agent 00116 */ 00117 void setRootOption(); 00118 00119 /** Returns the selected root option */ 00120 const Xabsl2Option* getRootOption() const; 00121 00122 /** 00123 * Sets a parameter of a option. 00124 * @param name The name of the option 00125 * @param param The name of of the parameter 00126 * @param value The value for the parameter 00127 * @return When false, the option or the parameter does not exist 00128 */ 00129 bool setOptionParameter(const char* name, const char* param, double value); 00130 00131 00132 /** 00133 * Sets the selected basic behavior. 00134 * Can be called to test a single basic behavior. 00135 * @param name The name of the basic behavior. 00136 * @return When false, the basic behavior was not registered 00137 */ 00138 bool setSelectedBasicBehavior(const char* name); 00139 00140 /** 00141 * Sets a parameter of a basic behavior. 00142 * @param name The name of the basic behavior 00143 * @param param The name of of the parameter 00144 * @param value The value for the parameter 00145 * @return When false, the basic behavior or the parameter were not registered 00146 */ 00147 bool setBasicBehaviorParameter(const char* name, const char* param, double value); 00148 00149 /** Returns the name of the selected agent */ 00150 const char* getSelectedAgentName(); 00151 00152 /** Returns the selected basic behavior */ 00153 const Xabsl2BasicBehavior* getSelectedBasicBehavior(); 00154 00155 //!@} 00156 }; 00157 00158 00159 00160 00161 #endif // __Xabsl2Engine_h_ 00162
1.3.6