00001
00002 #ifndef EVENT_H
00003 #define EVENT_H
00004
00005 #include <iostream>
00006 using namespace std;
00007 #include <boost/shared_ptr.hpp>
00008 #include <boost/utility.hpp>
00009
00010 #include "sim_time.hpp"
00011 #include "utility.hpp"
00012
00019 class Event : boost::noncopyable {
00020
00021 friend class Simulator;
00022 public:
00024 typedef boost::shared_ptr<Event> EventPtr;
00025
00029 virtual ~Event();
00030
00036 virtual void execute() = 0;
00037
00042 inline SimTime getFireTime() const;
00043
00048 inline bool inEventQueue() const;
00049
00050
00053 inline bool operator< (const Event& e) const;
00054
00055 protected:
00056
00058 Event();
00059
00060 private:
00061
00065 SimTime m_timeToFire;
00066
00070 bool m_inEventQueue;
00071
00079 inline void setFireTime(const SimTime& newFireTime);
00080
00087 inline void setInEventQueue(const bool inEventQueue);
00088
00089 };
00090 typedef boost::shared_ptr<Event> EventPtr;
00091 typedef boost::shared_ptr<Event const> ConstEventPtr;
00092
00094
00096
00097 inline void Event::setFireTime(const SimTime& newFireTime)
00098 {
00099 m_timeToFire = newFireTime;
00100 }
00101
00102 inline SimTime Event::getFireTime() const
00103 {
00104 return m_timeToFire;
00105 }
00106
00107 inline bool Event::inEventQueue() const
00108 {
00109 return m_inEventQueue;
00110 }
00111
00112 inline void Event::setInEventQueue(const bool inEventQueue)
00113 {
00114 m_inEventQueue = inEventQueue;
00115 }
00116
00118
00120
00121 inline bool Event::operator< (const Event& e) const {
00122 return m_timeToFire < e.m_timeToFire;
00123 }
00124
00125 inline ostream& operator<< (ostream& s, const Event& event)
00126 {
00127 return s<< "Event state (pointer=" << &event << ", time=" <<
00128 event.getFireTime() << ")";
00129 }
00130
00132
00134
00141 class DummyEvent : public Event {
00142 public:
00144 typedef boost::shared_ptr<DummyEvent> DummyEventPtr;
00145
00150 static inline DummyEventPtr create()
00151 {
00152 DummyEventPtr p(new DummyEvent());
00153 return p;
00154 }
00155
00160 void execute()
00161 {
00162
00163
00164
00165
00166 }
00167 protected:
00168
00170 DummyEvent()
00171 : Event()
00172 {
00173
00174 }
00175 };
00176 typedef boost::shared_ptr<DummyEvent> DummyEventPtr;
00177
00178 #endif // EVENT_H
00179