-
Notifications
You must be signed in to change notification settings - Fork 0
/
Member.cpp
48 lines (48 loc) · 1.11 KB
/
Member.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
#include "Member.h"
int Member::counter=0;
map<int,Member&>::iterator it;
Member::Member()
{
id = ++counter;
};
void Member::follow(Member& name)
{
if(this->id != name.id && Following.find(name.id)==Following.end())
{
Following.insert(pair <int,Member&> (name.id,name));
name.Followers.insert(pair<int,Member&> (this->id,*this));
}
}
void Member::unfollow(Member &name)
{
if((it=Following.find(name.id))!=Following.end())
{
Following.erase(it);
name.Followers.erase(name.Followers.find(this->id));
}
}
int Member::numFollowers() const
{
return this->Followers.size();
}
int Member::numFollowing() const
{
return this->Following.size();
}
int Member::count()
{
return Member::counter;
}
Member::~Member(){
counter--;
for(it=Followers.begin();it!=Followers.end();it++)
{
if(it->second.Following.find(this->id)!=it->second.Following.end())
it->second.Following.erase(it->second.Following.find(this->id));
}
for(it=Following.begin();it!=Following.end();it++)
{
if(it->second.Followers.find(this->id)!=it->second.Followers.end())
it->second.Followers.erase(it->second.Followers.find(this->id));
}
}