-
Notifications
You must be signed in to change notification settings - Fork 0
/
RowData.h
51 lines (42 loc) · 1.11 KB
/
RowData.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
#ifndef HOMEWORK_CPP_ROWDATA_H
#define HOMEWORK_CPP_ROWDATA_H
#include <memory>
#include <vector>
struct Datum {
enum Type { Int, Double } type;
union {
int64_t i;
double d;
};
Datum(int64_t value) : type(Int), i(value) { }
Datum(double value) : type(Double), d(value) { }
int64_t getInt() {
if (type == Double) {
return static_cast<int>(d);
} else {
return i;
}
}
double getDouble() {
if (type == Int) {
return static_cast<double>(i);
} else {
return d;
}
}
Type getType() {
return type;
}
};
typedef int64_t *DatumPtr;
struct RowData {
virtual Datum get(int rowID, size_t pos) = 0;
virtual int64_t getInt(int rowID, size_t pos) = 0;
virtual double getDouble(int rowID, size_t pos) = 0;
virtual std::vector<Datum::Type>& getSchema() = 0;
virtual DatumPtr getColumn(int colId) { return nullptr;}
virtual size_t getSize() = 0;
virtual ~RowData() {}
};
typedef std::shared_ptr<RowData> RowDataPtr;
#endif //HOMEWORK_CPP_ROWDATA_H