See
- The implementation simprocess.cpp
- The description Simulation process
<project-file type=“source”/>
<content> #ifndef SIMPROCESS_H #define SIMPROCESS_H
#include <map>
#include <simagent.h> #include <ostream>
class SimProcess; class SimEventLogger {
public: virtual bool loggable(SimSchedule *event) const = 0; virtual void log(SimProcess *process, float time, const SimAgent *, const SimSchedule*) = 0;
};
/ SimProcess encapisulates the simulation process. Each process will be independently * and co-operatively running, and communicating by communicators. */ class SimProcess : public SimAgent { public: / constructor */
SimProcess(std::ostream &log); /** destructor */ virtual ~SimProcess(); /** run is the main method that runs the simulation */ virtual void run(); /** quit stops and quits the simulation. */ virtual void quit();
/** registerAgent makes the agent mappable by its ID */ void registerAgent(SimAgent *p); /** unregisterAgent unmaps the agent from its ID */ void unregisterAgent(SimAgent *p);
/** agentWithID returns the agent with a given ID */ SimAgent *agentWithID(const SimID &id); /** idle is called between the processing of events */ virtual void idle();
/** logger returns the Logger stream */ std::ostream &logger() { return Logger; } /** register an event logger */ static void registerEventLogger(SimEventLogger*); /** unregister an event logger */ static void unregisterEventLogger(SimEventLogger*); /** log logs an event of an agent at a given time */ void log(float time, SimAgent *agent, SimSchedule *event);
protected:
/** Quit is a flag indicating that we need to quit the simulation */ bool Quit; /** Time is time of the simulation clock. */ float Time; /** Logger is the event logger. */ std::ostream &Logger; /** RegisteredAgents maps an ID to an agent */ std::map<SimID, SimAgent*> RegisteredAgents; static std::list<SimEventLogger*> EventLoggers;
};
/ SimQuitEvent is the event that terminates the simulation. */ class SimQuitEvent: public SimSchedule { public: / constructor */
SimQuitEvent(float time); virtual ~SimQuitEvent();
/** event handler. */ virtual void handler(float Time, SimProcess *process);
};
#endif
</content> <use name=“simagent.h”/>