aboutsummaryrefslogtreecommitdiff
path: root/week09/Exercise1/Printer.cpp
blob: b8e619586b7947c99e073c5031bb54b344bcdac3 (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
#include "Printer.h"
#include <cstring>

void Printer::free() {
	delete[] model;
}

void Printer::copyFrom(const Printer& other) {
	this->model = new char[strlen(other.model) + 1];
	strcpy(this->model, other.model);
	this->printedPages = other.printedPages;
}

Printer::Printer() {
	model = nullptr;
	printedPages = 0;
}

Printer::~Printer() {
	free();
}

Printer::Printer(const Printer& other) {
	copyFrom(other);
}

Printer& Printer::operator=(const Printer& other) {
	if (this != &other) {
		free();
		copyFrom(other);
	}
	return *this;
}

Printer::Printer(Printer&& other) {
	this->model = other.model;
	other.model = nullptr;
	this->printedPages = other.printedPages;
}

Printer& Printer::operator=(Printer&& other) {
	if (this != &other) {
		free();

		this->model = other.model;
		other.model = nullptr;
		this->printedPages = other.printedPages;
	}
	return *this;
}