-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovie.h
199 lines (153 loc) · 5.07 KB
/
Movie.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* File: Movie.h
* Author: Benjamin Dickson
* Info: A class containing a single movie
*
* My Movie.h and MovieDatabase files are quite integrated, as the Movie class
* refers back to its parents to determine how the database wishes it to be
* compared to another movie (eg, by title, year, duration etc...)
*
* comments for functions in cpp files
*/
#ifndef MOVIE_H
#define MOVIE_H
#include <cstdlib>
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;
#include "MovieMisc.h"
//class MovieDatabase;
class Movie
{
private:
string title;
unsigned int year;
MovieCertificate* cert;
vector<MovieGenre*> genre;
unsigned int duration;
MovieDatabase* parent;
unsigned int reviewCount;
unsigned int reviewPoints;
public:
friend class MovieDatabase;
friend class Movie;
// constructors / deconstructors
MovieDatabase* ioDatabase();
Movie();
Movie(Movie* cloneMovie, MovieDatabase* newParent);
Movie(MovieDatabase* newParent);
// setters
void setParent(MovieDatabase* newParent);
void setCert(MovieCertificate* newCert);
void setCert(string newCertName);
void setTitle(string newTitle);
void setYear(unsigned int newYear);
void setDuration(unsigned int newDuration);
void addGenre(MovieGenre* newGenre);
void addGenre(string newGenreName);
void removeGenre(MovieGenre* oldGenre);
void setReviewCount(unsigned int newReviewCount);
void setReviewPoints(unsigned int newReviewPoints);
void setReviewAverage(double newReviewAverage);
void addScore(int score);
// getters
MovieDatabase* getParent() const;
string getCert() const;
string getTitle() const;
unsigned int getYear() const;
unsigned int getDuration() const;
bool hasGenre(MovieGenre* findGenre);
string getGenresStr() const;
int getGenreCount() const;
unsigned int getReviewCount() const;
double getAverageScore() const;
};
inline std::ostream& operator<<(ostream &os, Movie &m)
{
return os << '"' << m.getTitle() << '"' << ',' << m.getYear() << ',' <<
'"' << m.getCert() << '"' << ',' << '"' << m.getGenresStr() <<
'"' << ',' << m.getDuration() << ',' << m.getAverageScore() <<
',' << m.getReviewCount();
};
inline std::stringstream& operator>>(stringstream &is, Movie* m)
{
// "The Gold Rush",1925,"NOT RATED","Adventure/Comedy/Drama",95,0,0
// "<title>",<year>,"<certificate>","<genre>/<genre>/...",<duration>,
// <average_review>,<review_count>
string discard;
string streamTitle,streamYear,streamCert,streamGenres,streamDuration;
string streamAverageReview,streamReviewCount;
// discard everything until first "
getline(is,discard,'"');
// title is everything until next "
getline(is,streamTitle,'"');
// proceed to comma
getline(is,discard,',');
// year is everything until next comma
getline(is,streamYear,',');
// discard everything until next "
getline(is,discard,'"');
// certificate is everything until next "
getline(is,streamCert,'"');
// discard everything until next "
getline(is,discard,'"');
// genres are everything until next "
getline(is,streamGenres,'"');
// proceed to comma
getline(is,discard,',');
// duration is everything until next comma
getline(is,streamDuration,',');
// average review is everything until next comma
getline(is,streamAverageReview,',');
// review count is everything left
getline(is,streamReviewCount);
// add the title as this is string
m->setTitle(streamTitle);
// add the ones that are just numbers (cast of unsigned int)
m->setYear((unsigned int)stoi(streamYear));
m->setDuration((unsigned int)stoi(streamDuration));
m->setReviewCount((unsigned int)stoi(streamReviewCount));
m->setReviewAverage(stod(streamAverageReview));
// add the certificate
m->setCert(streamCert);
// add the genres
stringstream ssGenres(streamGenres);
string streamGenre;
while(ssGenres)
{
getline(ssGenres,streamGenre,'/');
m->addGenre(streamGenre);
//m.addGenre((m.ioDatabase())->getGenre(streamGenre));
}
return is;
};
inline bool operator<(const Movie &a, const Movie &b)
{
return CompareHandler::movieLT(a,b,*a.getParent());
}
inline bool operator>(const Movie &a, const Movie &b)
{
return CompareHandler::movieGT(a,b,*a.getParent());
}
inline bool operator==(const Movie &a, const Movie &b)
{
return CompareHandler::movieEQ(a,b,*a.getParent());
}
inline bool operator!=(const Movie &a, const Movie &b)
{
return !CompareHandler::movieEQ(a,b,*a.getParent());
}
inline bool operator<=(const Movie &a, const Movie &b)
{
return !CompareHandler::movieGT(a,b,*a.getParent());
}
inline bool operator>=(const Movie &a, const Movie &b)
{
return !CompareHandler::movieLT(a,b,*a.getParent());
}
#endif /* MOVIE_H */