-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovie.cpp
More file actions
79 lines (69 loc) · 1.75 KB
/
movie.cpp
File metadata and controls
79 lines (69 loc) · 1.75 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
79
/*
* movie.cpp
*
* @authors Juan Arias & Nick Tibbott
*
*/
#include "movie.h"
/*
* Display the Items details
*/
void Movie::display(ostream& os) const {
os << getKey() << "\n\t\t" << this->director << " " <<
this->title << " ";
}
/*
* constructs a Movie with a given title, director, and release year
*/
Movie::Movie(const string& title, const string& director, int releaseYear)
:title(title), director(director), releaseYear(releaseYear) {
}
/*
* Less than operator overload for sorting in map containers
* Special sorting for Movies, sorts by greater than on Movie type (f > c),
* then sorts on less than for movieKey (A < B)
*/
bool Movie::operator<(const Item& other) const {
if (getType() != other.getType()) {
return getType() > other.getType();
}
return getKey() < other.getKey();
}
/*
* Static function to ensure map is initialized before subclasses self register
*/
map<char, MovieFactory*>& MovieType::getMap() {
static map<char, MovieFactory*> factoryMap;
return factoryMap;
}
/*
* Static functions for MovieFactory subclasses to self register
* with char representation
*/
void MovieType::registerType(char type, MovieFactory* factory) {
MovieType::getMap().emplace(type, factory);
}
/*
* Constructor to self register in ItemType class
*/
MovieType::MovieType(const string& type) :ItemType(type) {
ItemType::registerItemType(type, this);
}
/*
* Create and return the right Item from the vector of string
*/
Item* MovieType::create(const vector<string>& tokens) const {
char type = tokens[0][0];
Item* item = nullptr;
if (MovieType::getMap().count(type)) {
MovieFactory* factory = MovieType::getMap().at(type);
item = factory->create(tokens);
}
return item;
}
/*
* Anonymous for self registering
*/
namespace {
MovieType movieType("Movie");
}