-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFile.h
More file actions
85 lines (58 loc) · 1.98 KB
/
File.h
File metadata and controls
85 lines (58 loc) · 1.98 KB
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
#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 {
private:
TwoWayList<Record> *myRecs;
int numRecs;
int curSizeInBytes;
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);
// the deletes the first record from a page and returns it; returns
// a zero if there were no records on the page
int GetFirst(Record *firstOne);
// this appends the record to the end of a page. The return value
// is a one on success and a aero 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();
};
class File {
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
int Open(int length, 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