-
Notifications
You must be signed in to change notification settings - Fork 1
/
events.cpp
52 lines (44 loc) · 927 Bytes
/
events.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* events.cpp
* for creating and handling Events
*/
#include "discrete_simulator.hpp"
Event::Event()
{
priority = 0;
event_id = Simulator::free_event_id;
Simulator::free_event_id += 1;
event_name = std::string();
repeat_itself = false;
}
Event::~Event()
{
}
std::string Event::get_name()
{
if(event_name.empty()) {
return std::string("Event#" + std::to_string(event_id));
}
else {
return event_name;
}
}
//generator
EventGenerator::EventGenerator()
{
repeat_itself = true;
time = Simulator::start_time;
}
TimeoutWatch::TimeoutWatch(Event* watched, Event* on_timeout, Queue* watched_queue)
{
on_timeout_event = on_timeout;
queued_event = watched;
queue_with_event = watched_queue;
}
void TimeoutWatch::Behaviour()
{
if(queue_with_event->remove_event(queued_event)) {
delete queued_event;
on_timeout_event->Behaviour();
}
}