00001
00002 #ifndef SimManagerH
00003 #define SimManagerH
00004
00005
00006
00007
00008 #include "Interface.h"
00009 #include "Constants.h"
00010 #include "DataTypes.h"
00011
00012 #include <xercesc/dom/dom.hpp>
00013
00014 class clBehaviorBase;
00015 class clXercesErrorHandler;
00016 class clModelEntityResolver;
00017 class clBehaviorManager;
00018 class clPopulationManager;
00019 class clGridManager;
00020 class clPlot;
00021 class clGridBase;
00022 class clPopulationBase;
00023 class clWorkerBase;
00024 class clModelMath;
00025
00063 class clSimManager {
00064 friend class TestSimManager;
00066 protected:
00067
00068 char m_cAppPath[MAX_FILENAME_SIZE];
00073 long m_iActualSeed;
00078 float m_fNumYearsPerTimestep;
00081
00082 int m_iMajorVersion;
00083 int m_iMinorVersion;
00084 int m_iRandomSeed;
00089 unsigned int m_iNumTimesteps;
00090 unsigned int m_iCurrentTimestep;
00092 unsigned int m_iTargetTimestep;
00095
00096 clBehaviorManager *mp_oBehaviorManager;
00097 clPopulationManager *mp_oPopulationManager;
00098 clGridManager *mp_oGridManager;
00100 clPlot *mp_oPlot;
00103 char m_cParFilename[MAX_FILENAME_SIZE];
00106 struct stcCommandList {char cCommand[MAX_COMMAND_LENGTH];
00107 clWorkerBase *p_oObject;
00108 } *mp_commands;
00112 short int m_iNumCommands;
00113 bool m_bUserQuit;
00115
00116 xercesc::DOMBuilder *mp_oXMLParser;
00117 clXercesErrorHandler *mp_oXMLErrorHandler;
00123 void TimestepCleanup();
00124
00129 void EndOfRunCleanup();
00130
00149 void ReadParameterFile(xercesc::DOMDocument *p_oDoc, fileType iFileType);
00150
00161 void ReadTreeFile(xercesc::DOMDocument *p_oDoc, fileType iFileType);
00162
00173 void ReadMapFile(xercesc::DOMDocument *p_oDoc, fileType iFileType);
00174
00180 void DoSetup(xercesc::DOMDocument *p_oDoc);
00181
00185 void GoToNoDataState();
00186
00187 public:
00188
00196 clSimManager(int iMajorVersion, int iMinorVersion, char *cAppPath);
00197
00201 ~clSimManager();
00202
00208 char* GetAppPath() {return m_cAppPath;};
00209
00214 int GetObjectVersion() {return 1;};
00215
00219 enum simState{No_Data,
00221 Initialized,
00223 Paused,
00224 Run_Complete
00225 };
00226
00231 char* GetParFilename() {return m_cParFilename;};
00232
00237 int GetMajorVersion() {return m_iMajorVersion;};
00238
00243 int GetMinorVersion() {return m_iMinorVersion;};
00244
00249 float GetNumberOfYearsPerTimestep() {return m_fNumYearsPerTimestep;};
00250
00256 int GetParameterFileRandomSeed() {return m_iRandomSeed;};
00257
00263 long* GetRandomSeed() {return &m_iActualSeed;};
00264
00269 int GetNumberOfTimesteps() {return m_iNumTimesteps;}
00270
00275 int GetCurrentTimestep() {return m_iCurrentTimestep;}
00276
00282 void SetCurrentTimestep(int iTimestep) {
00283 if (iTimestep > 0 && iTimestep < m_iNumTimesteps)
00284 m_iCurrentTimestep = iTimestep;
00285 };
00286
00291 int GetSimState() {return m_eSimState;}
00292
00298 int GetNumberOfBehaviors();
00299
00305 int GetNumberOfGrids();
00306
00312 int GetNumberOfPopulations();
00313
00334 void ReadFile(char *cFileName);
00335
00351 fileType GetFileType(char *cFileName);
00352
00367 fileType GetFileType(xercesc::DOMDocument *p_oDoc);
00368
00381 unsigned long RunSim(int iNumStepsToRun = 0);
00382
00391 clPopulationBase* GetPopulationObject(char *cPopName);
00392
00402 clPopulationBase* GetPopulationObject(int iIndex);
00403
00410 clGridBase* GetGridObject(char *cGridName);
00411
00419 clGridBase* GetGridObject(int iIndex);
00420
00430 clBehaviorBase* GetBehaviorObject(int iIndex);
00431
00440 clBehaviorBase* GetBehaviorObject(char *cBehaviorName);
00441
00447 clPlot* GetPlotObject() {return mp_oPlot;};
00448
00462 bool DoCommand(char *cCommand, char *cArguments);
00463
00477 void RegisterCommand(char *cCommand, clWorkerBase *p_oObject);
00478
00484 void RunBatch(char *cBatchFile);
00485
00514 clGridBase* CreateGrid(char* cGridName, short int iNumIntVals,
00515 short int iNumFloatVals, short int iNumCharVals, short int iNumBoolVals,
00516 float fXCellLength = 0, float fYCellLength = 0);
00517
00518 protected:
00519
00520 enum simState m_eSimState;
00521 };
00523
00524 extern modelMsg CheckForMessage();
00525
00526 #endif