aboutsummaryrefslogtreecommitdiff
path: root/week13/Exercise1/IndexArray.cpp
blob: ed7a2126d0383c4abc96aefc5e1a01448ebc2965 (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
#include "IndexArray.h"
#include <cstring>

void IndexArray::free() {
	delete[] indecies;
}

void IndexArray::copyFrom(const IndexArray& other) {
	this->size = other.size;
	this->indecies = new int[size];
	for (int i = 0; i < size; i++) {
		this->indecies[i] = other.indecies[i];
	}
}

IndexArray::IndexArray() {
	this->indecies = nullptr;
	this->size = 0;
}

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

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

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

IndexArray::IndexArray(IndexArray&& other) {
	this->indecies = other.indecies;
	other.indecies = nullptr;
}

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

		this->indecies = other.indecies;
		other.indecies = nullptr;
	}
	return *this;
}