forked from mooman/Raymond-Tree-Simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageTracker.cpp
67 lines (57 loc) · 1.27 KB
/
MessageTracker.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "MessageTracker.h"
#include "Request.h"
#include <iostream>
#include <list>
using namespace std;
MessageTracker* MessageTracker::pInstance = 0;
MessageTracker::MessageTracker()
{
// empty constructor
}
MessageTracker::~MessageTracker()
{
// remove only existing instance of this object
if (pInstance != 0)
delete pInstance;
}
MessageTracker* MessageTracker::getInstance()
{
// this method will create the only instance of
// this class, once and only once, then return
// it on request
if (pInstance == 0) {
pInstance = new MessageTracker();
}
return pInstance;
}
void MessageTracker::add(Request* r)
{
// add the request to the request list
list_req.push_back(r);
}
Request* MessageTracker::find(int id)
{
list<Request*>::iterator iter;
// search through the list to find the
// request given by the input id
for (iter = list_req.begin(); iter != list_req.end(); iter++)
{
if ((*iter)->site_id == id)
{
// found!
return *iter;
}
}
// if not found return null
return NULL;
}
void MessageTracker::print_messages()
{
list<Request*>::iterator iter;
// just go through the list and print the messages
for (iter = list_req.begin(); iter != list_req.end(); iter++)
{
cout << (*iter)->site_id << ": " << (*iter)->num_messages+1;
cout << endl;
}
}