-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpackage.h
108 lines (101 loc) · 2.34 KB
/
package.h
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef PACKAGE_H
#define PACKAGE_H
#include <vector>
#include <iostream>
#include <string>
class Package
{
public:
Package(int sender, int recipent, double packageMass):
senderId(sender),
recipentId(recipent),
mass(packageMass),
_status(Announced)
{
SetStatus(Announced);
++_totalCount;
}
~Package()
{
--_totalCount;
}
enum Status
{
Announced,
InPickup,
TransitToPickupBranch,
AwaitingHubTransport,
TransitToHub,
AwaitingBranchTransport,
TransitToDestinationBranch,
AwaitingDelivery,
InDelivery,
Completed
};
Status GetStatus()
{
return _status;
}
friend std::ostream& operator<<(std::ostream& os, const Package & p);
std::string GetStatusString()const;
void SetStatus(Status status)
{
_status = status;
if(reportStatus)
{
std::cout << "Package from " << senderId <<" to " << recipentId << ". status changed to: ";
std::cout << GetStatusString();
std::cout << "\r\n";
}
}
static int TotalCount()
{
return _totalCount;
}
//Sender and recipent//
const int senderId, recipentId;
const double mass;
static bool reportStatus;
private:
Status _status;
static int _totalCount;
};
class PackageContainer
{
public:
using ConstIterator = std::vector<Package*>::const_iterator;
using Iterator = std::vector<Package*>::iterator;
void PutPackage(Package *p)
{
//std::cout << "Loading: " << *p << "\r\n";
_packages.push_back(p);
}
Package *GetPackage(ConstIterator &i)
{
if (i == _packages.end())
throw std::out_of_range("Invalid iterator");
Package *p = const_cast<Package *>(*i);
Iterator in = _packages.erase(i, i);
//std::cout << "Removing: " << *p << " Packages size: " << _packages.size() - 1<<"\r\n";
i = _packages.erase(in);
//if (i != _packages.end())
// std::cout << "Iterator points to: " << (*i)->recipentId << "\r\n";
return p;
}
double GetWeight();
ConstIterator FindId(int customerId);
ConstIterator begin()
{
return _packages.begin();
}
ConstIterator end()
{
return _packages.end();
}
void Print();
protected:
std::vector<Package*> _packages;
unsigned int _workStart;
unsigned int _workEnd;
};
#endif // PACKAGE_H