-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.h
43 lines (36 loc) · 1.12 KB
/
Database.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
#include "Relation.h"
#pragma once
class Database {
private:
vector<Relation> relations;
public:
void addRelation(const Relation& relation) {
relations.push_back(relation);
}
Relation& getRelation(const string& name) {
for (Relation& relation : relations) {
if (relation.getName() == name) {
return relation;
}
}
throw std::runtime_error("Relation not found");
}
Relation getRelationCopy(const string& name) {
for (const Relation& relation : relations) {
if (relation.getName() == name) {
return relation;
}
}
throw std::runtime_error("Relation not found");
}
void addTuple(const string& name, const Tuple& tuple) {
getRelation(name).addTuple(tuple);
}
int getTotalTuples() {
int total = 0;
for (const Relation& relation : relations) {
total += relation.getTuples().size();
}
return total;
}
};