-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPackage.cpp
93 lines (76 loc) · 1.75 KB
/
Package.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <string>
#include <vector>
#include <sstream>
#include "Package.h"
#include "Client.h"
#include <iostream>
using namespace std;
Package::Package(Client* s, Client* r, float w, Priority p, unsigned int id, int packAge) : sender(s), receiver(r), priority(p), ID(id), age(packAge) {
//cout << "Package this: " << this << endl;
setWeight(w);
s->sendPackage(this);
r->receivePackage(this);
}
void Package::setSender(Client *s)
{
sender = s;
}
Client* Package::getSender() const
{
return sender;
}
void Package::setReceiver(Client *r)
{
receiver = r;
}
Client* Package::getReceiver() const
{
return receiver;
}
void Package::setWeight(const double w)
{
if(w < 0.0)
{
throw invalid_argument("No package has negative weight");
}
weight = w;
}
float Package::getWeight() const
{
return weight;
}
void Package::setPriority(const Priority p)
{
priority = p;
}
Priority Package::getPriority() const
{
//cout << "Package priority: " << static_cast<int>(priority) << endl;
return priority;
}
string Package::getPriorityString() const {
string value;
// Figure out string to return
switch(priority) {
case Priority::REGULAR:
value = "Regular";
break;
case Priority::TWO_DAY:
value = "Two Day";
break;
case Priority::OVERNIGHT:
value = "Overnight";
break;
}
return value;
}
ostream& operator<<(ostream& output, const Package& pack)
{
output << "Sender:" << endl
<< *pack.sender << endl
<< "Receiver:" << endl
<< *pack.receiver << endl
<< "Weight: " << pack.weight << endl
<< "Priority: " << pack.getPriorityString() << endl;
return output;
}