-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab.cpp
More file actions
48 lines (39 loc) · 1013 Bytes
/
Lab.cpp
File metadata and controls
48 lines (39 loc) · 1013 Bytes
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 "Lab.h"
Lab::Lab() : backup_player(nullptr) {}
Lab::Lab(const Lab& other) : backup_player(nullptr) {
if (other.backup_player) {
backup_player = other.backup_player->clone();
}
}
Lab::Lab(Lab&& other) noexcept : backup_player(other.backup_player) {
other.backup_player = nullptr;
}
Lab& Lab::operator=(const Lab& other) {
if (this == &other) return *this;
delete backup_player;
backup_player = nullptr;
if (other.backup_player) {
backup_player = other.backup_player->clone();
}
return *this;
}
Lab& Lab::operator=(Lab&& other) noexcept {
if (this == &other) return *this;
delete backup_player;
backup_player = other.backup_player;
other.backup_player = nullptr;
return *this;
}
Lab::~Lab() {
delete backup_player;
backup_player = nullptr;
}
void Lab::backup(const Player& player) {
delete backup_player;
backup_player = player.clone();
}
void Lab::restore(Player*& player_out) const {
if (!backup_player) return;
delete player_out;
player_out = backup_player->clone();
}