-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathE34.h
116 lines (96 loc) · 1.97 KB
/
E34.h
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
#ifndef E34_H
#define E34_H
#include <string>
using std::string;
#include <set>
using std::set;
class Folder;
class Message{
friend class Folder;
public:
explicit Message(const string& s = ""):contents(s){};
Message(const Message&);
Message& operator=(const Message&);
~Message();
void save(Folder&);
void remove(Folder&);
private:
string contents;
set<Folder*> folders;
void add_to_Folders(const Message&);
void remove_from_Folders();
void addFldr(Folder *f) {folders.insert(f);}
void remFldr(Folder *f) {folders.erase(f); }
};
class Folder{
friend class Message;
public:
Folder() = default;
Folder(const Folder&);
Folder& operator=(const Folder&);
~Folder();
private:
set<Message*> message;
void remMsg(Message*);
void addMsg(Message*);
void remove_to_Message();
void add_to_Message(const Folder&);
};
void Message::add_to_Folders(const Message& m){ // put the message to now folder
for(auto f : m.folders){
f->addMsg(this);
}
}
void Message::remove_from_Folders(){
for(auto f : folders){
f->remMsg(this);
}
}
Message::Message(const Message& m):contents(m.contents), folders(m.folders){
add_to_Folders(m);
}
Message::~Message(){
remove_from_Folders();
}
Message& Message::operator=(const Message& m){
remove_from_Folders();
contents = m.contents;
folders = m.folders;
add_to_Folders(m);
return *this;
}
void Message::save(Folder& f){
folders.insert(&f);
f.addMsg(this);
}
void Message::remove(Folder& f){
folders.erase(&f);
f.remMsg(this);
}
void Folder::add_to_Message(const Folder& f){
for(auto m : f.message){
m->addFldr(this);
}
}
void Folder::remove_to_Message(){
for(auto m : message){
m->remFldr(this);
}
message.clear();
}
Folder::Folder(const Folder& f): message(f.message){
add_to_Message(f);
}
Folder& Folder::operator=(const Folder& f){
remove_to_Message();
message = f.message;
add_to_Message(f);
return *this;
}
void Folder::addMsg(Message* m){
message.insert(m);
}
void Folder::remMsg(Message* m){
message.erase(m);
}
#endif