-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStand.cpp
116 lines (105 loc) · 2.85 KB
/
Stand.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "Stand.h"
#include "Trace.h"
#include "Order.h"
/* CONSTRUCTORS */
Stand::Stand()
{
this->head = new Order();
this->tail = new Order();
this->head->setNext(this->tail);
this->tail->setPrev(this->head);
this->curr = 0;
this->peak = 0;
// Trace::out("---------------------------------------------------------\n");
// Trace::out(" New Stand: currNumOrders:%d peakNumOrders:%d\n", this->curr, this->peak);
// Trace::out("---------------------------------------------------------\n\n");
}
Stand::Stand(const Stand &in) {
this->head = in.head;
this->tail = in.tail;
this->curr = in.curr;
this->peak = in.peak;
}
Stand & Stand::operator= (const Stand &in) {
delete this->head;
delete this->tail;
this->head = in.head;
this->tail = in.tail;
this->curr = in.curr;
this->peak = in.peak;
return *this;
}
Stand::~Stand() {
Order* p = this->head->getNext();
while (p != this->tail) {
Order* s = p;
p = p->getNext();
// Trace::out(" ---> Cancel order:%s \n", s->orderToString(s->getName()));
delete s;
}
delete head;
//delete p;
delete this->tail;
}
/* ADD/REMOVE */
void Stand::Add(Order* in) {
Order* nOrder = in;
if (head->getNext() == tail) {
this->head->setNext(nOrder);
this->tail->setPrev(nOrder);
nOrder->setNext(this->tail);
nOrder->setPrev(this->head);
this->curr++;
}
else {
nOrder->setPrev(this->tail->getPrev());
this->tail->getPrev()->setNext(nOrder);
nOrder->setNext(this->tail);
this->tail->setPrev(nOrder);
this->curr++;
}
if (this->curr > this->peak)
this->peak = this->curr;
// Trace::out("Add->Order(%s)\n", nOrder->orderToString(nOrder->getName()));
//delete o;
}
void Stand::Remove(Name in) {
Order* pIdx = this->head;
while (pIdx != nullptr) {
pIdx = pIdx->getNext();
if (pIdx->getName() == in)
break;
//Trace::out("%s\n", pIdx->orderToString(pIdx->getName()));
}
// Trace::out("-------------------------------------------------\n");
// Trace::out("\n");
// Trace::out("Remove->Order(%s)\n", pIdx->orderToString(pIdx->getName()));
// Trace::out("\n");
// Trace::out("-------------------------------------------------\n");
// //Order* nNext = pIdx->getNext()->getNext();
//pIdx->getPrev()->setNext(nNext);
//this->curr--;
Order* nNext = pIdx->getNext();
pIdx->getPrev()->setNext(nNext);
nNext->setPrev(pIdx->getPrev());
this->curr--;
//delete nNext;
//this->Print();
delete pIdx;
}
/* PRINT */
void Stand::Print() {
//char* l = "-----------------------------------------------------------";
//if ((this->curr == 0) && (this->peak == 0)) {
//} else
// Trace::out("\n-------------------------------------------------\n");
// Trace::out("\nStand: currNumOrders:%d peakNumOrders:%d\n\n", this->curr, this->peak);
Order* idx = this->head;
while (idx->getNext() != this->tail) {
idx = idx->getNext();
idx->printOrder();
}
//delete idx;
}
// void Stand::printStandstats() {
// }