-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter.cc
141 lines (123 loc) · 3.75 KB
/
printer.cc
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
//printer.cc
#include "printer.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
Printer::Printer( unsigned int numStudents, unsigned int numVendingMachines, unsigned int numCouriers ) :
numStudents(numStudents), numVendingMachines(numVendingMachines), numCouriers(numCouriers) {
//first 6
waitList[Parent] = new printInfo;
waitList[Groupoff] = new printInfo;
waitList[WATCardOffice] = new printInfo;
waitList[NameServer] = new printInfo;
waitList[Truck] = new printInfo;
waitList[BottlingPlant] = new printInfo;
waitList[Student] = new printInfo[numStudents];
waitList[Vending] = new printInfo[numVendingMachines];
waitList[Courier] = new printInfo[numCouriers];
//first lines
cout << "Parent\tGropoff\tWATOff\tNames\tTruck\tPlant\t";
for (unsigned int i = 0; i < numStudents; ++i)
cout << "Stud" << i << "\t";
for (unsigned int i = 0; i < numVendingMachines; ++i)
cout << "Mach" << i << "\t";
for (unsigned int i = 0; i < numCouriers; ++i) {
cout << "Cour" << i;
if (i<numCouriers-1) cout << "\t";
}
cout << endl;
for (unsigned int i = 0; i < 5 + numStudents + numVendingMachines + numCouriers; ++i)
cout << "*******\t";
cout << "*******" << endl;
}
Printer::~Printer() {
flush(); // remember
cout << "***********************" << endl;
delete waitList[Parent];
delete waitList[Groupoff];
delete waitList[WATCardOffice];
delete waitList[NameServer];
delete waitList[Truck];
delete waitList[BottlingPlant];
delete [] waitList[Student];
delete [] waitList[Vending];
delete [] waitList[Courier];
}
static unsigned int tab_count;
void Printer::flush() {
tab_count = 0;
print8char(waitList[Parent]);
print8char(waitList[Groupoff]);
print8char(waitList[WATCardOffice]);
print8char(waitList[NameServer]);
print8char(waitList[Truck]);
print8char(waitList[BottlingPlant]);
for (unsigned int i = 0; i < numStudents; ++i)
print8char(&(waitList[Student][i]));
for (unsigned int i = 0; i < numVendingMachines; ++i)
print8char(&(waitList[Vending][i]));
for (unsigned int i = 0; i < numCouriers; ++i)
print8char(&(waitList[Courier][i]));
cout << endl;
}
void Printer::print8char(struct printInfo *info) {
if (info->count == -1) {
++tab_count;
return; // Nothing to print
}
for (unsigned int i = 0; i < tab_count; ++i) {
cout << "\t";
}
tab_count = 1;
if (info->count == 0) {
cout << info->ch;
} else if (info->count == 1) {
cout << info->ch << info->v1;
} else if (info->count == 2) {
cout << info->ch << info->v1 << "," << info->v2;
}
info->count = -1;
}
void Printer::print( Kind kind, char state ) {
if (waitList[kind]->count != -1)
flush();
waitList[kind]->count = 0;
waitList[kind]->ch = state;
}
void Printer::print( Kind kind, char state, int value1 ) {
if (waitList[kind]->count != -1)
flush();
waitList[kind]->count = 1;
waitList[kind]->ch = state;
waitList[kind]->v1 = value1;
}
void Printer::print( Kind kind, char state, int value1, int value2 ) {
if (waitList[kind]->count != -1)
flush();
waitList[kind]->count = 2;
waitList[kind]->ch = state;
waitList[kind]->v1 = value1;
waitList[kind]->v2 = value2;
}
void Printer::print( Kind kind, unsigned int lid, char state ) {
if (waitList[kind][lid].count != -1)
flush();
waitList[kind][lid].count = 0;
waitList[kind][lid].ch = state;
}
void Printer::print( Kind kind, unsigned int lid, char state, int value1 ) {
if (waitList[kind][lid].count != -1)
flush();
waitList[kind][lid].count = 1;
waitList[kind][lid].ch = state;
waitList[kind][lid].v1 = value1;
}
void Printer::print( Kind kind, unsigned int lid, char state, int value1, int value2 ) {
if (waitList[kind][lid].count != -1)
flush();
waitList[kind][lid].count = 2;
waitList[kind][lid].ch = state;
waitList[kind][lid].v1 = value1;
waitList[kind][lid].v2 = value2;
}