See:


<project-file type=“source”/>

<content> #ifndef SIMAGENT_H #define SIMAGENT_H

#include <simschedule.h> for SimID definition #include <simutil.h> #include <vector> #include <list> class SimProcess; class SimAgentManager; / SimAgent is the abstract base class for all Agents. * An Agent is an object that has a list of events and reacts to them. * At the same time, an agent is a schedule too, because it represents * of all the events it owns */ class SimAgent : public SimSchedule { public: / the default constructor, with a given ID */ SimAgent(SimID id); / destructor */ virtual ~SimAgent(); / Inherited from SimSchedule, it executes the next event of this agent. * The current process is passed to the runnable, so that it can access the neccesory process features */ virtual void handler(float Time, SimProcess *); / id returns the ID of the agent. */ inline const SimID &id() const { return ID; } / owner returns the owner agent. */ inline SimAgent *owner() const { return Owner; } / addAgent adds an agent to be managed by this agent */ virtual void addAgent(SimAgent *p); / removeAgent removes a currently managed agent */ virtual void removeAgent(SimAgent *p); virtual void die(SimProcess *proc); / agents returns the number of managed agent */ inline int agents() { return Agents.size(); } / agent returns the i-th managed agent */ inline SimAgent *agent(int i) { return (i>=Agents.size())?NULL:Agents[i]; } / addManager adds an agent manager */ void addManager(SimAgentManager *); / removeManager removed an agent manager */ void removeManager(SimAgentManager *); / schedule schedules a scheduled event. */ virtual void schedule(SimSchedule *); / unschedule unschedules a given scheduled event. */ virtual void unschedule(SimSchedule *); / clear clears all the events in it */ virtual void clear(); protected: / Index references to the index in the owner's Agents list. */ size_t Index; / Agents holds the list of agents that is managed by this agent. */ std::vector<SimAgent*> Agents; / Managers points to a list of agent managers */ std::list<SimAgentManager *>Managers; private: std::multimap<float, SimSchedule*> Events; /** the globale unique ID */ SimID ID; }; class SimAgentManager { public: SimAgentManager(); virtual ~SimAgentManager(); virtual void addAgent(SimAgent *agent) = 0; virtual void removeAgent(SimAgent *agent) = 0; virtual void agentChangedIndex(int from, int to) = 0; void setOwner(SimAgent *owner) { Owner = owner; } protected: SimAgent *Owner; }; class SimChangeOwnerEvent : public SimSchedule { public: SimChangeOwnerEvent(float time, SimID newowner, SimDistribution *rep); virtual ~SimChangeOwnerEvent(); virtual void handler(float time, SimProcess *proc); protected: SimID NewOwner; SimDistribution *Repetition; }; class SimDieEvent : public SimSchedule { public: SimDieEvent(float time); virtual ~SimDieEvent(); virtual void handler(float time, SimProcess *proc); }; #endif </content> <use name=“”/>