forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex13_34_36_37.h
78 lines (60 loc) · 1.76 KB
/
ex13_34_36_37.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
//
// ex13_34_36_37.h
// Exercise 13.34 13.36 13.37
//
// Created by pezy on 1/26/15.
// Copyright (c) 2015 pezy. All rights reserved.
//
// 34: Write the Message class as described in this section.
//
// 36: Design and implement the corresponding Folder class. That class should
// hold a set that points to the Messages in that Folder.
//
// 37: Add members to the Message class to insert or remove a given Folder*
// into folders.
// These members are analogous to Folder’s addMsg and remMsg operations.
#ifndef CP5_ex13_34_36_37_h
#define CP5_ex13_34_36_37_h
#include <set>
#include <string>
class Folder;
class Message {
friend void swap(Message&, Message&);
friend void swap(Folder&, Folder&);
friend class Folder;
public:
explicit Message(const std::string& str = "") : contents(str) {}
Message(const Message&);
Message& operator=(const Message&);
~Message();
void save(Folder&);
void remove(Folder&);
void print_debug();
private:
std::string contents;
std::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); }
};
void swap(Message&, Message&);
class Folder {
friend void swap(Message&, Message&);
friend void swap(Folder&, Folder&);
friend class Message;
public:
Folder() = default;
Folder(const Folder&);
Folder& operator=(const Folder&);
~Folder();
void print_debug();
private:
std::set<Message*> msgs;
void add_to_Messages(const Folder&);
void remove_from_Messages();
void addMsg(Message* m) { msgs.insert(m); }
void remMsg(Message* m) { msgs.erase(m); }
};
void swap(Folder&, Folder&);
#endif // MESSAGE