aboutsummaryrefslogtreecommitdiff
path: root/week12/Exercise3/TelecommunicationCompany.cpp
blob: 7b877caf731a9cd929b30346516d9f591fdc88c7 (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
#include "TelecommunicationCompany.h"
#include "MobileDevice.h"

void TelecommunicationCompany::resize() {
	allocated *= 2;
	MobileDevice** moreDevices = new MobileDevice*[allocated];
	for (int i = 0; i < size; i++) {
		moreDevices[i] = devices[i];
	}
	delete[] devices;
	devices = moreDevices;
}

void TelecommunicationCompany::free() {
	for (int i = 0; i < size; i++) {
		delete devices[i];
	}
	delete[] devices;
}

TelecommunicationCompany::TelecommunicationCompany() {
	devices = nullptr;
	allocated = size = 0;
}

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

TelecommunicationCompany::TelecommunicationCompany(TelecommunicationCompany&& other) {
	this->size = other.size;
	this->allocated = other.allocated;
	this->devices = other.devices;
	other.devices = nullptr;
}

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

		this->size = other.size;
		this->allocated = other.allocated;
		this->devices = other.devices;
		other.devices = nullptr;
	}
	return *this;
}