-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.cc
46 lines (39 loc) · 1003 Bytes
/
db.cc
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
// MP4 miller olsonn!
#include "db.hpp"
void Database::CreateTable(const std::string& table_name) {
tables_[table_name] = new DbTable();
}
void Database::DropTable(const std::string& table_name) {
if (!tables_.contains(table_name)) {
throw std::invalid_argument("");
}
delete tables_.at(table_name);
tables_.erase(table_name);
}
DbTable& Database::GetTable(const std::string& table_name) {
return *tables_[table_name];
}
Database::Database(const Database& rhs) {
for (const auto& [name, table] : rhs.tables_) {
tables_[name] = new DbTable(*table);
}
}
Database& Database::operator=(const Database& rhs) {
if (this != &rhs) {
for (auto& [name, table] : tables_) {
delete table;
}
tables_.clear();
for (const auto& [name, table] : rhs.tables_) {
tables_[name] = new DbTable(*table);
}
}
return *this;
}
Database::~Database() {
for (auto table : tables_) {
delete table.second;
table.second = nullptr;
}
tables_.clear();
}