-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscList.cpp
More file actions
53 lines (45 loc) · 1.25 KB
/
DiscList.cpp
File metadata and controls
53 lines (45 loc) · 1.25 KB
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
//Mark Hentges 5814125
//
#include "DiscList.h"
#include <iostream>
DiscList::DiscList() {
discListPtr = std::make_unique<LinkedList<std::shared_ptr<Disk>>>();
}
DiscList::~DiscList() {
std::cout << "DiscList destructor has been called" << std::endl;
}
bool DiscList::isEmpty() {
return discListPtr->isEmpty();
}
int DiscList::getNumberOfDisks() {
return discListPtr->getLength();
}
bool DiscList::insertDisc(std::shared_ptr<Disk> discPtr) {
//trys to insert a disk
try{
discListPtr->insert(1, discPtr);
return true;
}catch(std::exception& e){
//what to do if we fail to insert a disk
return false;
}
}
bool DiscList::removeDisc(std::shared_ptr<Disk> diskPtr) {
//trys to remove a disk
try{
for(int i = 1; i <= discListPtr->getLength(); ++i){
if(discListPtr->getEntry(i)->getTitle() == diskPtr->getTitle()){
discListPtr->remove(i);
return true;
}
}
}catch(std::exception& e){
//returns false if we get an exception
return false;
}
return false;
}
std::shared_ptr<Disk> DiscList::retrieveDisc(int number) {
//trys ot retrieve a disk based off f a nubmer
return discListPtr->getEntry(number);
}