-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.cpp
76 lines (56 loc) · 1.32 KB
/
repository.cpp
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
#include "repository.h"
#include "dynamicvector.h"
#include "myexceptions.h"
Repository::Repository() {
selected_recording = 0;
}
void Repository::add(Recording r) {
for (int i = 0; i < container.size(); i++) {
if (container[i].get_title() == r.get_title()) {
cout << "Can't add duplicate elements!\n";
return;
}
}
container.push_back(r);
}
DynamicVector<Recording> Repository::get_container() {
return container;
}
void Repository::remove(string title) {
for (int i = 0; i < container.size(); i++) {
if (container[i].get_title() == title) {
container.remove(i, 1);
return;
}
}
}
Repository::~Repository() {
container.free();
watch_list.free();
}
bool Repository::search(string title) {
for (int i = 0; i < container.size(); i++) {
if (container[i].get_title() == title) {
return true;
}
}
return false;
}
string Repository::next() {
if (selected_recording + 1 < container.size()) {
selected_recording++;
} else {
selected_recording = 0;
}
return container[selected_recording].get_as_string();
}
void Repository::save() {
if (selected_recording >= container.size()) {
IndexError ie("IndexError: You haven't added any recordings!\n");
throw ie;
}
watch_list.push_back(container[selected_recording]);
}
DynamicVector<Recording> Repository::get_watchlist() {
return watch_list;
}