-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferFile.cc
55 lines (47 loc) · 1.16 KB
/
BufferFile.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
#include "BufferFile.h"
BufferFile::BufferFile(int buff_size) {
this->buff_size = buff_size;
curr_pages = new Page[buff_size];
}
// int BufferFile::Create(const char *fpath) {
// file = new File();
// file->Open(0, fpath);
// curr_pagenum = 0;
// return 1;
// }
int BufferFile::Open(const char *fpath) {
file = new File();
file->Open(1, fpath);
this->fpath = fpath;
// starting from the first page
curr_pagenum = 0;
// get n pages
int i = 0;
while (i < buff_size) {
if (file->GetLength() > i + 1) {
file->GetPage((curr_pages + i), i);
i++;
num_pages++;
} else {
break;
}
}
}
int BufferFile::Close(){
return file->Close();
}
void BufferFile::MoveFirst(){
Close();
Open(fpath);
}
int BufferFile::GetNext(Record *fetchme){
if (!(curr_pages + curr_pagenum)->GetFirst(fetchme)) {
// assuming the page is empty here so we move to the next page
if (curr_pagenum < num_pages + 1) {
(curr_pages + ++curr_pagenum)->GetFirst(fetchme);
return 1;
} else {
return 0;
}
}
}