forked from MorganBauer/COP-6726-Databases-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Record.h
84 lines (68 loc) · 2.89 KB
/
Record.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
#ifndef RECORD_H
#define RECORD_H
#include <iostream>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "Defs.h"
#include "ParseTree.h"
#include "Schema.h"
#include "File.h"
#include "Comparison.h"
#include "ComparisonEngine.h"
// Basic record data structure. Data is actually stored in "bits" field. The layout of bits is as follows:
// 1) First sizeof(int) bytes: length of the record in bytes
// 2) Next sizeof(int) bytes: byte offset to the start of the first att
// 4) Bits encoding the record's data
class Record {
friend class ComparisonEngine;
friend class Page;
friend class Function;
private:
char * bits;
char * GetBits () const ;
void SetBits (char *bits);
void CopyBits(char *bits, int b_len);
public:
Record ();
Record (const Record & r);
Record & operator = (Record const & r);
bool isNull (); // returns true if null, false if not
void SetNull ();
~Record();
size_t GetSize (void) const;
// return the number of attributes in the record
int GetNumAtts (void);
// suck the contents of the record fromMe into this; note that after
// this call, fromMe will no longer have anything inside of it
// strictly speaking, it will have an invalid reference, NULL to be specific
void Consume (Record *fromMe);
// make a copy of the record copyMe; note that this is far more
// expensive (requiring a bit-by-bit copy) than Consume, which is
// only a pointer operation
void Copy (Record *copyMe);
// reads the next record from a pointer to a text file; also requires
// that the schema be given; returns a 0 if there is no data left or
// if there is an error and returns a 1 otherwise
int SuckNextRecord (Schema *mySchema, FILE *textFile);
int ComposeRecord (Schema *mySchema, const char *src);
// this projects away various attributes...
// the array attsToKeep should be sorted, and lists all of the attributes
// that should still be in the record after Project is called.
//
// numAttsNow tells how many attributes are currently in the record
void Project (int *attsToKeep, int numAttsToKeep, int numAttsNow);
// takes two input records and creates a new record by concatenating them;
// this is useful for a join operation
// attsToKeep[] = {0, 1, 2, 0, 2, 4} --gets 0,1,2 records from left 0, 2, 4 recs from right and startOfRight=3
// startOfRight is the index position in attsToKeep for the first att from right rec
void MergeRecords (Record *left, Record *right, int numAttsLeft,
int numAttsRight, int *attsToKeep, int numAttsToKeep, int startOfRight);
// prints the contents of the record; this requires
// that the schema also be given so that the record can be interpreted
void Print (Schema *mySchema);
// same as above, put prints to an ostream explicitly given, rather than standard out.
void Print (Schema *mySchema, std::ostream & os);
};
#endif