-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cpp
More file actions
112 lines (96 loc) · 2.21 KB
/
User.cpp
File metadata and controls
112 lines (96 loc) · 2.21 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
#include "User.h"
User::User(const std::string& name)
: _name(name)
{
try
{
wall = new(std::nothrow) std::vector<Status*>;
friends = new(std::nothrow) std::vector<User*>;
if(nullptr == wall || nullptr == friends)
throw(std::invalid_argument("Allocation error"));
}
catch(const std::invalid_argument& e)
{
std::cerr << e.what() << '\n';
if(wall)
delete wall;
if(friends)
delete friends;
}
}
User::~User()
{
std::cout << "in user d'tor\n";
for(Status* status : *wall)
{
delete status;
}
delete wall;
delete friends;
}
void User::printWall() const
{
std::cout << "*******************************" << std::endl;
for(int i = 0 ; i < wall->size() ; ++i)
std::cout << *(*wall)[i] << std::endl;
std::cout << "*******************************" << std::endl;
}
void User::printFriends() const
{
std::cout << "*******************************" << std::endl;
for(int i = 0 ; i < friends->size() ; ++i)
(*friends)[i]->print();
std::cout << "*******************************" << std::endl;
}
void User::addStatus(Status* status)
{
wall->push_back(status);
}
void User::addFriend(User* user)
{
friends->push_back(user);
}
const User& operator+=(User& lhs, User& rhs)
{
lhs.friends->push_back(&rhs);
return lhs;
}
const std::string& User::getName() const
{
return _name;
}
bool User::checkIfAlreadyConnected(User* otherUser) const
{
for(User* user : *friends)
{
if(otherUser == user)
return true;
}
return false;
}
bool User::getCanFriendsPost() const
{
return false;
}
bool User::isPerson() const
{
return false;
}
bool User::removeUserFromPageFriendsList(const User* other)
{
for(int i = 0 ; i < friends->size() ; ++i)
{
if((*friends->begin() + i) == other)
friends->erase(friends->begin() + i);
return true;
}
return false;
}
void User::print() const
{
std::cout << _name << std::endl;
}
bool operator>(const User& lhs, const User& rhs)
{
return lhs.friends->size() > rhs.friends->size();
}