-
Notifications
You must be signed in to change notification settings - Fork 0
/
File.h
106 lines (71 loc) · 2.28 KB
/
File.h
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
#ifndef FILE_H
#define FILE_H
#include "TwoWayList.h"
#include "Record.h"
#include "Schema.h"
#include "Comparison.h"
#include "ComparisonEngine.h"
class Record;
using namespace std;
class Page {
friend class GenericDBFile;
friend class HeapFile;
friend class SortedFile;
friend class BigQ;
private:
TwoWayList <Record> *myRecs;
int curSizeInBytes;
int numRecs;
// flag used to keep a check on whether the page has been written to disk or not
bool pageToDisk;
public:
// constructor
Page ();
virtual ~Page ();
// this takes a page and writes its binary representation to bits
void ToBinary (char *bits);
// this takes a binary representation of a page and gets the
// records from it
void FromBinary (char *bits);
// retrieves the first record from a page and returns it; returns
// a zero if there were no records on the page
int GetFirst (Record *firstOne);
int GetRecord (Record *firstOne, off_t offset);
// this appends the record to the end of a page. The return value
// is a one on success and a zero if there is no more space
// note that the record is consumed so it will have no value after
int Append (Record *addMe);
// empty it out
void EmptyItOut ();
int numRecords ();
void MoveToStartPage();
};
class File {
friend class GenericDBFile;
friend class HeapFile;
friend class SortedFile;
friend class BigQ;
private:
int myFilDes;
off_t curLength;
public:
File ();
~File ();
// returns the current length of the file, in pages
off_t GetLength ();
// opens the given file; the first parameter tells whether or not to
// create the file. If the parameter is zero, a new file is created
// the file; if notNew is zero, then the file is created and any other
// file located at that location is erased. Otherwise, the file is
// simply opened
void Open (int length, const char *fName);
// allows someone to explicitly get a specified page from the file
void GetPage (Page *putItHere, off_t whichPage);
// allows someone to explicitly write a specified page to the file
// if the write is past the end of the file, all of the new pages that
// are before the page to be written are zeroed out
void AddPage (Page *addMe, off_t whichPage);
// closes the file and returns the file length (in number of pages)
int Close ();
};
#endif