-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBTR.cpp
163 lines (149 loc) · 4.2 KB
/
DBTR.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "DBTR.h"
DBTR::DBTR(){
commandStack = new GenStack<string>();
facultyStack = new GenStack<Faculty*>();
studentStack = new GenStack<Student*>();
advisorIDStack = new GenStack<int>();
adviseeIDStack = new GenStack<int>();
newAdvisorStack = new GenStack<Faculty*>();
}
DBTR::~DBTR(){
delete commandStack;
delete facultyStack;
delete studentStack;
delete advisorIDStack;
delete adviseeIDStack;
delete newAdvisorStack;
}
void DBTR::storeCommandFaculty(string command, Faculty *faculty){
// manages size of stack, then pushes data onto stacks
manageSize();
commandStack->push(command);
facultyStack->push(faculty);
}
void DBTR::storeCommandStudent(string command, Student *student){
manageSize();
commandStack->push(command);
studentStack->push(student);
}
void DBTR::storeCommandAdvisee(string command, int ID, Faculty *advisor){
manageSize();
commandStack->push(command);
adviseeIDStack->push(ID);
facultyStack->push(advisor);
}
void DBTR::storeCommandAdvisor(string command, int ID, Student *student){
manageSize();
commandStack->push(command);
advisorIDStack->push(ID);
studentStack->push(student);
}
void DBTR::storeNewAdvisor(Faculty *newAdvisor){
manageSize();
newAdvisorStack->push(newAdvisor);
}
void DBTR::manageSize(){
// manages size of stack to 5 by popping the bottom element out when the size is 5
if(commandStack->getSize() == 5){
GenStack<string> *reverse = new GenStack<string>();
while(!commandStack->isEmpty()){
reverse->push(commandStack->pop());
}
reverse->pop();
while(!reverse->isEmpty()){
commandStack->push(reverse->pop());
}
delete reverse;
}
if(facultyStack->getSize() == 5){
GenStack<Faculty*> *reverse = new GenStack<Faculty*>();
while(!facultyStack->isEmpty()){
reverse->push(facultyStack->pop());
}
reverse->pop();
while(!reverse->isEmpty()){
facultyStack->push(reverse->pop());
}
delete reverse;
}
if(studentStack->getSize() == 5){
GenStack<Student*> *reverse = new GenStack<Student*>();
while(!studentStack->isEmpty()){
reverse->push(studentStack->pop());
}
reverse->pop();
while(!reverse->isEmpty()){
studentStack->push(reverse->pop());
}
delete reverse;
}
if(advisorIDStack->getSize() == 5){
GenStack<int> *reverse = new GenStack<int>();
while(!advisorIDStack->isEmpty()){
reverse->push(advisorIDStack->pop());
}
reverse->pop();
while(!reverse->isEmpty()){
advisorIDStack->push(reverse->pop());
}
delete reverse;
}
if(adviseeIDStack->getSize() == 5){
GenStack<int> *reverse = new GenStack<int>();
while(!adviseeIDStack->isEmpty()){
reverse->push(adviseeIDStack->pop());
}
reverse->pop();
while(!reverse->isEmpty()){
adviseeIDStack->push(reverse->pop());
}
delete reverse;
}
if(newAdvisorStack->getSize() == 5){
GenStack<Faculty*> *reverse = new GenStack<Faculty*>();
while(!newAdvisorStack->isEmpty()){
reverse->push(newAdvisorStack->pop());
}
reverse->pop();
while(!reverse->isEmpty()){
newAdvisorStack->push(reverse->pop());
}
delete reverse;
}
}
string DBTR::getCommand(){
if(!commandStack->isEmpty()){
return commandStack->pop();
}
return "";
}
Faculty* DBTR::getFaculty(){
if(!facultyStack->isEmpty()){
return facultyStack->pop();
}
return NULL;
}
Student* DBTR::getStudent(){
if(!studentStack->isEmpty()){
return studentStack->pop();
}
return NULL;
}
int DBTR::getAdvisorID(){
if(!advisorIDStack->isEmpty()){
return advisorIDStack->pop();
}
return -1;
}
int DBTR::getAdviseeID(){
if(!adviseeIDStack->isEmpty()){
return adviseeIDStack->pop();
}
return -1;
}
Faculty* DBTR::getNewAdvisor(){
if(!newAdvisorStack->isEmpty()){
return newAdvisorStack->pop();
}
return NULL;
}