-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaunchCaretaker.cpp
74 lines (73 loc) · 2.17 KB
/
LaunchCaretaker.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "LaunchCaretaker.h"
LaunchCaretaker::LaunchCaretaker(){
FileSize = 0;
file = new LaunchFile*[0];
desc = new string[0];
}
LaunchCaretaker::~LaunchCaretaker(){
for (int i = 0; i < FileSize; i++)
delete file[i];
delete file;
}
LaunchFile* LaunchCaretaker::getFile(int i){
if (i >= FileSize || i < 0) throw std::invalid_argument("Argument outside of range");
return file[i];
}
void LaunchCaretaker::setFile(LaunchFile* newfile){
if (newfile == nullptr) throw std::invalid_argument("Argument is null");
string s = "";
for (int i = 0; i < newfile->getCount(); i++){
s = s + newfile->getLaunch()[i]->getName() +" "+newfile->getLaunch()[i]->getType() +"\n";
}
FileSize++;
LaunchFile** f = new LaunchFile*[FileSize];
string* ss = new string[FileSize];
for (int i = 0; i < FileSize-1; i++){
f[i] = file[i];
ss[i] = desc[i];
}
f[FileSize-1] = newfile;
ss[FileSize-1] = s;
file = f;
desc = ss;
}
string LaunchCaretaker::getDesc(int i){
if (i >= FileSize || i < 0) throw std::invalid_argument("Argument outside of range");
return desc[i];
}
void LaunchCaretaker::removeFile(int i){
if (i >= FileSize || i < 0) throw std::invalid_argument("Argument outside of range");
string* ss = new string[FileSize-1];
LaunchFile** f = new LaunchFile*[FileSize-1];
for (int j = 0; j < i; j++){
f[j] = file[j];
ss[j] = desc[j];
}
for (int j = i; j < FileSize-1; j++){
f[j] = file[j+1];
ss[j] = desc[j+1];
}
delete file[i];
FileSize--;
file = f;
desc = ss;
}
bool LaunchCaretaker::contains(LaunchFile* f){
for (int i = 0; i < FileSize; i++){
for (int j = 0; j < file[i]->getCount(); j++){
if (f->getLaunch()[i]->getName() == file[i]->getLaunch()[i]->getName()) return true;
}
}
return false;
}
bool LaunchCaretaker::contains(Rocketship** r,int k){
for (int i = 0; i < FileSize; i++){
for (int j = 0; j < k; j++){
if (r[j]->getName() == file[i]->getLaunch()[j]->getName()) return true;
}
}
return false;
}
int LaunchCaretaker::getSize(){
return FileSize;
}