-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.cc
88 lines (69 loc) · 1.25 KB
/
query.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
// query.cc
#include "query.h"
#include <string.h>
using namespace std;
char * strncpy();
void QUERY::set_version()
{
version = 1;
}
QUERY::QUERY()
{
set_version();
query_name[0] = '\0';
}
QUERY::QUERY(char *name)
{
set_version();
strncpy(query_name, name, 127);
query_name[127] = '\0';
}
void QUERY::setname(char * newname)
{
strncpy(query_name, newname, 127);
query_name[127] = '\0';
}
void QUERY::setquestion(P_QUESTION q)
{
query_question = *q;
}
void QUERY::setanswer(P_ANSWER a)
{
query_answer = *a;
}
char * QUERY::getname()
{
return strdup(query_name);
}
P_QUESTION QUERY::getquestion()
{
return &query_question;
}
P_ANSWER QUERY::getanswer()
{
return &query_answer;
}
void QUERY::print()
{
cout << "QUERY NAME " << query_name <<
" QUERY VERSION #" << version << "\n";
query_question.pversion();
query_answer.pversion();
}
void QUERY::readFromDisk(FILE *fp)
{
fscanf(fp, "%d", &version);
fscanf(fp, "\n");
fgetstr(fp, query_name);
fscanf(fp, "\n");
query_question.readFromDisk(fp);
query_answer.readFromDisk(fp);
}
void QUERY::writeToDisk(FILE *fp)
{
fprintf(fp, "%d\n", version);
fputstr(fp, query_name);
fprintf(fp, "\n");
query_question.writeToDisk(fp);
query_answer.writeToDisk(fp);
}