-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollection.cpp
More file actions
127 lines (109 loc) · 2.08 KB
/
Collection.cpp
File metadata and controls
127 lines (109 loc) · 2.08 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include "Member.h"
#include "Collection.h"
using namespace std;
int Collection::count = 0;
Collection::Collection()
{
ID = 0;
name = "";
bookList.clear();
subcribeUser.clear();
}
Collection::Collection(string name)
{
ID = ++count;
this->name = name;
bookList.clear();
subcribeUser.clear();
}
Collection::~Collection()
{
if (!bookList.empty()) {
for (int i = 0; i < bookList.size(); i++) {
if (bookList[i]) {
delete bookList[i];
}
}
bookList.clear();
}
if (!subcribeUser.empty()) {
for (int i = 0; i < subcribeUser.size(); i++) {
if (subcribeUser[i]) {
delete subcribeUser[i];
}
}
subcribeUser.clear();
}
}
void Collection::setId(int id)
{
ID = id;
}
void Collection::setName(string name)
{
this->name = name;
}
void Collection::addBook(Book* book)
{
bookList.push_back(book);
}
void Collection::addUser(Member* user)
{
subcribeUser.push_back(user);
}
int Collection::getId()
{
return ID;
}
string Collection::getName()
{
return name;
}
vector<Book*> Collection::getBookList()
{
vector<Book*> books;
for (int i = 0; i < bookList.size(); i++) {
books.push_back(bookList[i]);
}
return books;
}
vector<Member*> Collection::getUserList()
{
vector<Member*> Member;
for (int i = 0; i < subcribeUser.size(); i++) {
Member.push_back(subcribeUser[i]);
}
return Member;
}
int Collection::getBookListSize()
{
return bookList.size();
}
int Collection::getsSubcribeUserSize()
{
return subcribeUser.size();
}
void Collection::addBook(Book* book, Member* user)
{
bookList.push_back(book);
subcribeUser.push_back(user);
}
void Collection::removeUser(Member* user)
{
// Find the user in the subscribed user list
auto it = find(subcribeUser.begin(), subcribeUser.end(), user);
// If user is found, remove it
if (it != subcribeUser.end()) {
subcribeUser.erase(it);
}
}
Book* Collection::getBook(int index)
{
if (index >= 0 && index <= bookList.size()) {
return bookList[index];
}
else {
return NULL;
}
}