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 00163 /* 00164 * Change Log 00165 * 00166 * $Log: Xabsl2Engine.h,v $ 00167 * Revision 1.1.1.1 2004/05/22 17:37:56 cvsadm 00168 * created new repository GT2004_WM 00169 * 00170 * Revision 1.3 2003/12/16 18:53:22 loetzsch 00171 * The XabslEngine now checks for loops 00172 * 00173 * Revision 1.2 2003/10/08 11:50:09 loetzsch 00174 * made the Xabsl2Engine really platform independent 00175 * (removed inclusion of Platform/SystemCall.h) 00176 * A time function is given to the engine by parameter. 00177 * 00178 * Revision 1.1 2003/10/07 10:13:25 cvsadm 00179 * Created GT2004 (M.J.) 00180 * 00181 * Revision 1.4 2003/09/30 10:51:11 dueffert 00182 * typos fixed 00183 * 00184 * Revision 1.3 2003/09/16 13:27:21 loetzsch 00185 * changed all occurrences of "option tree" to "option graph" 00186 * 00187 * Revision 1.2 2003/08/04 16:02:50 loetzsch 00188 * ::setSelectedAgent doesn't throw error messages when anymore 00189 * 00190 * Revision 1.1.1.1 2003/07/02 09:40:29 cvsadm 00191 * created new repository for the competitions in Padova from the 00192 * tamara CVS (Tuesday 2:00 pm) 00193 * 00194 * removed unused solutions 00195 * 00196 * Revision 1.12 2003/01/28 18:07:47 loetzsch 00197 * no message 00198 * 00199 * Revision 1.11 2003/01/28 17:51:35 loetzsch 00200 * added function setOptionParameter() 00201 * 00202 * Revision 1.10 2003/01/19 13:04:52 loetzsch 00203 * xabsl2 agents now can be changed by using the Module and SolutionRequest 00204 * mechanism 00205 * 00206 * Revision 1.9 2003/01/12 14:54:04 loetzsch 00207 * continued creation of option tree: Xabsl2Statement and derivates added 00208 * 00209 * Revision 1.8 2003/01/11 14:41:42 loetzsch 00210 * continued creation of the option tree 00211 * 00212 * Revision 1.7 2003/01/09 17:28:33 loetzsch 00213 * introduced Xabsl2Agent, continued Xabsl2Option 00214 * 00215 * Revision 1.6 2003/01/08 15:22:33 loetzsch 00216 * - started implementation of the option tree 00217 * - started the reading of the intermediate code 00218 * 00219 * Revision 1.5 2002/12/11 12:23:31 loetzsch 00220 * basic behaviors register their parameters in their constructor 00221 * the parameters array contains only references to doubles in the basic behavior 00222 * 00223 * Revision 1.4 2002/12/06 21:13:37 loetzsch 00224 * Decimal input symbols can now be registered at the engine 00225 * 00226 * Revision 1.3 2002/12/02 19:56:32 loetzsch 00227 * - Xabsl2Array now seems to work for more than 1 element 00228 * - Basic behaviors now can be registered at the engine 00229 * - Basic behaviors have access to their parameters 00230 * 00231 * Revision 1.2 2002/12/01 17:54:30 loetzsch 00232 * continued Xabsl2Engine: Xabsl2Array seems to work now 00233 * 00234 * Revision 1.1 2002/12/01 13:45:58 loetzsch 00235 * first version of Xabsl2Engine 00236 * 00237 */ 00238