-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.cpp
More file actions
96 lines (81 loc) · 2.06 KB
/
table.cpp
File metadata and controls
96 lines (81 loc) · 2.06 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
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include "table.h"
Table::Table(std::string name, std::vector<Column> columns,
std::vector<std::string> primaryKey) {
this->name = name;
this->columns = columns;
this->primaryKey = primaryKey;
}
std::string Table::getName() {
return name;
}
std::vector<Column> Table::getColumns() {
return columns;
}
std::vector<std::string> Table::getPrimaryKey() {
return primaryKey;
}
/*
* get column by name
*/
Column Table::getColumn(std::string name) {
std::vector<Column>::iterator iter;
for (iter = columns.begin(); iter != columns.end(); iter++) {
if ((*iter).getName() == name) {
return *iter;
break;
}
}
// if don't exist, return null
std::vector<int> nul;
std::string fuck = "";
Column col(fuck, nul, false, -1);
return col;
}
Column& Table::getColumnReference(std::string name) {
std::vector<Column>::iterator iter;
for (iter = columns.begin(); iter != columns.end(); iter++) {
if ((*iter).getName() == name) {
return *iter;
break;
}
}
// if don't exist, return null
static std::vector<int> nul;
static std::string fuck = "";
static Column col(fuck, nul, false, -1);
return col;
}
int Table::getNumberOfRows() {
if (columns.size() == 0) return 0;
else return columns[0].getElements().size();
}
/*
* check whether the column is exist
*/
bool Table::isColumnExist(std::string name) {
bool isExist = false;
std::vector<Column>::iterator iter;
for (iter = columns.begin(); iter != columns.end(); iter++) {
if ((*iter).getName().compare(name) == 0) {
isExist = true;
break;
}
}
return isExist;
}
void Table::deleteRows(std::vector<int> rowIndex) {
std::vector<Column>::iterator i;
for (i = columns.begin(); i != columns.end(); i++) {
std::vector<int>::iterator it;
for (it = rowIndex.begin(); it != rowIndex.end(); it++) {
(*i).deleteV(*it);
}
}
}
void Table::deleteAllRows() {
std::vector<Column>::iterator i;
for (i = columns.begin(); i != columns.end(); i++) {
(*i).deleteAll();
}
}