-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelect.h
More file actions
70 lines (62 loc) · 1.66 KB
/
Select.h
File metadata and controls
70 lines (62 loc) · 1.66 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
#ifndef SELECT_H
#define SELECT_H
#include "Operator.h"
#include "Record.h"
#include "FileReader.h"
#include <variant>
#include <any>
class Select : public Operator {
private:
Operator* input;
FileReader fr;
char Sel_op;
string Sel_attr;
string Sel_val;
int recIndex;
vector <Record> inputPage;
public:
// Select constructors
Select(string fileName, string p_attr, string p_op, string p_val) :
fr(fileName)
{
input = &fr;
Sel_attr = p_attr;
Sel_op = p_op[0];
Sel_val = p_val;
recIndex = 0;
}
Select(Operator *op, string p_attr, string p_op, string p_val) {
input = op;
Sel_attr = p_attr;
Sel_op = p_op[0];
Sel_val = p_val;
recIndex = 0;
}
void open() {
input->open();
recIndex = 0;
}
vector<Record> next() {
vector<Record> outPage;
while(outPage.size() < pageSize){
if(recIndex == 0 || recIndex == inputPage.size()){
inputPage = input->next();
recIndex = 0;
}
if(inputPage.empty()){
break;
}
Record rec = inputPage[recIndex];
recIndex++;
if (rec.evaluate_cond(Sel_attr, Sel_val, Sel_op)){
outPage.push_back(rec);
}
}
return outPage;
}
void close() {
input->close();
recIndex = 0;
}
};
#endif