aboutsummaryrefslogtreecommitdiff
path: root/week09/Exercise1/Printer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'week09/Exercise1/Printer.cpp')
-rw-r--r--week09/Exercise1/Printer.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/week09/Exercise1/Printer.cpp b/week09/Exercise1/Printer.cpp
new file mode 100644
index 0000000..b8e6195
--- /dev/null
+++ b/week09/Exercise1/Printer.cpp
@@ -0,0 +1,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;
+}