-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDBFile.cc
107 lines (82 loc) · 2.38 KB
/
DBFile.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
#include "DBFile.h"
DBFile::DBFile() {
}
DBFile::~DBFile() {
}
int DBFile::Create(const char *f_path, fType f_type, void *startup) {
// Meta data file path.
PathConfig *pathConfig = PathConfig::GetInstance();
char *metadataPath = pathConfig->GetMetadataFilePath(f_path);
// Open file for writing.
ofstream fOut;
fOut.open(metadataPath);
fOut << f_type << "\n";
switch (f_type) {
case heap: {
myInternalVar = new HeapDBFile();
break;
}
case sorted: {
SortInfo *sortInfo = (SortInfo *) startup;
fOut << sortInfo->runLength << "\n";
fOut << sortInfo->myOrder->ToString() << "\n";
myInternalVar = new SortedDBFile(sortInfo);
break;
}
default: {
cerr << "Not yet implemented";
exit(1);
}
}
fOut.close();
return myInternalVar->Create(f_path);
}
int DBFile::Open(const char *f_path) {
// Meta data file path.
PathConfig *pathConfig = PathConfig::GetInstance();
char *metadataPath = pathConfig->GetMetadataFilePath(f_path);
ifstream fIn;
string readLine;
fIn.open(metadataPath);
if (!fIn.is_open()) return 0;
getline(fIn, readLine);
switch (stoi(readLine)) {
case heap: {
myInternalVar = new HeapDBFile();
break;
}
case sorted: {
SortInfo *sortInfo = new SortInfo();
sortInfo->myOrder = new OrderMaker();
getline(fIn, readLine);
sortInfo->runLength = stoi(readLine);
getline(fIn, readLine);
sortInfo->myOrder->FromString(readLine);
myInternalVar = new SortedDBFile(sortInfo);
break;
}
default:
cerr << "Not yet implemented";
return 0;
}
fIn.close();
return myInternalVar->Open(f_path);
}
void DBFile::Load(Schema &f_schema, const char *loadpath) {
myInternalVar->Load(f_schema, loadpath);
}
void DBFile::Add(Record &rec) {
myInternalVar->Add(rec);
}
void DBFile::MoveFirst() {
myInternalVar->MoveFirst();
}
int DBFile::GetNext(Record &fetchme) {
return myInternalVar->GetNext(fetchme);
}
int DBFile::GetNext(Record &fetchme, CNF &cnf, Record &literal) {
return myInternalVar->GetNext(fetchme, cnf, literal);
}
int DBFile::Close() {
return myInternalVar->Close();
}