blob: acd0684316d738b877fdd24bcb13e92f49d78b71 (
plain) (
blame)
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
|
#include "Pager.h"
#include <iostream>
#include <cstring>
#include <fstream>
void Pager::free() {
delete[] fileName;
}
void Pager::copyFrom(const Pager& other) {
this->fileName = new char[strlen(other.fileName) + 1];
strcpy(this->fileName, other.fileName);
}
Pager::Pager() {
this->fileName = nullptr;
}
Pager::~Pager() {
free();
}
Pager::Pager(const Pager& other) {
copyFrom(other);
}
Pager& Pager::operator=(const Pager& other) {
if (this != &other) {
free();
copyFrom(other);
}
return *this;
}
Pager::Pager(Pager&& other) {
this->fileName = other.fileName;
other.fileName = nullptr;
}
Pager& Pager::operator=(Pager&& other) {
if (this != &other) {
free();
this->fileName = other.fileName;
other.fileName = nullptr;
}
return *this;
}
MobileDevice* Pager::clone() {
return new Pager(*this);
}
void Pager::Show() {
std::ofstream outFile(fileName);
if (!outFile.is_open()) {
throw "Coudldn't open file!";
}
outFile << textMessage << std::endl;
outFile.close();
}
|