-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovie.cpp
More file actions
78 lines (66 loc) · 1.89 KB
/
movie.cpp
File metadata and controls
78 lines (66 loc) · 1.89 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Movie.cpp
* Base class Movies, Parent of Classics, Comedy and Drama
*
* @author Olga Kuriatnyk
*/
#include "movie.h"
// constructor
Movie::Movie() {
this->director = "";
this->title = "";
this->year = 0;
this->stock = 0;
this->borrowedNum = 0;
this->mediaType = ' ';
this->movieType = ' ';
}
// register movie type
void Movie::registerType(const char &movieType, MovieFactory *factory) {
getMap().emplace(movieType, factory);
}
// create movie of this type
Movie *Movie::create(const char &movieType) {
if (getMap().count(movieType) == 0) {
cout << "Don't know how to create " << movieType << endl;
return nullptr;
}
return getMap().at(movieType)->create(movieType);
}
// @return char for the movie type
char Movie::getMovieType() const { return this->movieType; }
// @return ItemKey of the object
ItemKey Movie::getItemKey() const { return this->itemKey; }
// @return true if year is valid from 1800 to current year
bool Movie::isYearValid() const {
time_t theTime = time(nullptr);
struct tm *aTime = localtime(&theTime);
int currYear = aTime->tm_year + 1900;
return (year > 1800 && year < currYear);
}
// decrease stock for borrow command
void Movie::decreaseStock() {
this->stock -= 1;
this->borrowedNum += 1;
}
// increase stock for return command
void Movie::increaseStock() {
this->stock += 1;
this->borrowedNum -= 1;
}
// @return true if have 1 or more
// use for borrow command
bool Movie::haveInStock() const { return this->stock > 0; }
// @return true if stack is 0 or more
bool Movie::isStockValid() const { return this->stock >= 0; }
// helper function for read(istream& is) function
string Movie::readNextItem(istream &io, char comma) {
const char space = ' ';
string str;
getline(io, str, comma);
if (str.empty()) {
return str;
}
return str.substr(str.find_first_not_of(space),
str.find_last_not_of(space) + 1);
}