-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocuments.cpp
More file actions
62 lines (49 loc) · 1.42 KB
/
Copy pathdocuments.cpp
File metadata and controls
62 lines (49 loc) · 1.42 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
#include <iostream>
#include <memory>
using namespace std;
class Document {
public:
virtual void display() = 0;
virtual ~Document() = default;
};
class RealDocument : public Document {
private:
string filename;
public:
explicit RealDocument(const string& filename) : filename(filename) {
documentForWho();
}
void display() override {
cout << "Displaying: " << filename << endl;
}
void documentForWho() {
cout << "Access given to: " << filename << endl;
}
};
class SecureDocumentProxy : public Document {
private:
shared_ptr<RealDocument> realDocument;
string filename;
string who;
public:
SecureDocumentProxy(const string& filename, const string& who) : filename(filename), who(who) {}
void display() override {
if (!realDocument) {
realDocument = make_shared<RealDocument>(filename);
}
cout << "Accessing document as: " << who << endl;
realDocument->display();
}
};
int main() {
SecureDocumentProxy documentForAdmin("Admin_Document.txt", "admin");
SecureDocumentProxy documentForManager("Manager_Document.txt", "manager");
SecureDocumentProxy documentForGuest("Guest_Document.txt", "guest");
cout << "admin" << endl;
documentForAdmin.display();
cout << "manager" << endl;
documentForManager.display();
cout << "guest" << endl;
documentForGuest.display();
return 0;
}