-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.cc
113 lines (91 loc) · 2.04 KB
/
result.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
#include "result.h"
RESULT::RESULT(char *s, int max) {
strncpy(survey_name, s, 127);
survey_name[127] = '\0';
num_responses = max;
num_excluded = 0;
section_number = 0;
query_number = 0;
cur_response = -1;
thoseExcluded[0] = (char *) 0;
status = NOT_COMPLETED;
}
RESULT::~RESULT() {
int i;
for (i = 0; i < num_excluded; i++)
delete thoseExcluded[i];
for (i = 0; i < num_responses; i++)
delete theResponses[i];
}
void RESULT::addResponse(P_RESPONSE r, int n) {
theResponses[n] = r;
num_responses = n+1;
}
void RESULT::setExcluded(int n, char *s[]) {
int i;
num_excluded = n;
for (i = 0; i < n; i++)
thoseExcluded[i] = s[i];
}
int RESULT::setTo1stResponse() {
if (num_responses == 0)
return (cur_response = -1);
else
return (cur_response = 0);
}
P_RESPONSE RESULT::getNextResponse() {
if (cur_response != -1)
{
if (cur_response >= num_responses)
return (P_RESPONSE) -1;
else
return theResponses[cur_response++];
}
else
return (P_RESPONSE) -1;
}
int RESULT::getNumResponses() {
return raw_location;
}
int RESULT::getLastQueryNum() {
return query_number;
}
int RESULT::getLastSectionNum() {
return section_number;
}
void RESULT::readFromDisk(FILE *fp) {
int i;
char tmp;
fgetstr(fp, survey_name);
fscanf(fp, "%d %d %d %d %d %d\n",
&raw_location, &num_responses,
§ion_number, &query_number,
&num_excluded,
&status);
for (i = 0; i < num_excluded; i++)
{
thoseExcluded[i] = new char[128];
fgetstr(fp, thoseExcluded[i]);
}
for (i = 0; i < num_responses; i++)
{
theResponses[i] = new RESPONSE;
theResponses[i]->readFromDisk(fp);
}
}
void RESULT::writeToDisk(FILE *fp) {
int i;
fputstr(fp, survey_name);
fprintf(fp, "%d %d %d %d %d %d\n",
raw_location, num_responses,
section_number, query_number,
num_excluded,
status);
for (i = 0; i < num_excluded; i++)
fputstr(fp, thoseExcluded[i]);
fprintf(fp, "\n");
for (i = 0; i < num_responses; i++)
{
theResponses[i]->writeToDisk(fp);
}
}