-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroom.cpp
More file actions
40 lines (32 loc) · 806 Bytes
/
Copy pathroom.cpp
File metadata and controls
40 lines (32 loc) · 806 Bytes
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
#include "room.h"
Room::Room(std::string name) : name(name) {}
std::string Room::getName() {
return name;
}
void Room::addUser(User* user) {
users.push_back(user);
user->setRoom(this);
}
void Room::removeUser(User* user) {
for (auto it = users.begin(); it != users.end(); it++) {
if (*it == user) {
users.erase(it);
user->setRoom(nullptr);
// 标记为空
if (users.empty()) name = "";
break;
}
}
}
std::string Room::showUsers() {
std::string result;
for (auto user : users) {
result += user->getName() + ", ";
}
result = result.substr(0, result.length() - 2); // remove the last comma and space
return result;
}
std::vector<User*> Room::getUsers()
{
return users;
}