-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie.h
109 lines (83 loc) · 2.49 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
/**
* Movie.h
* Base class Movies, Parent of Classics, Comedy and Drama
*
* @author Olga Kuriatnyk
*/
#ifndef MOVIE_H
#define MOVIE_H
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include "itemKey.h"
#include <ctime>
using namespace std;
// declaration of a class movie
class Movie;
class MovieFactory {
public:
// virtual create() function will be overridden for
// drama, comedy, and classic objects separately
virtual Movie *create(const char &movieType) const = 0;
};
class Movie {
public:
// constructor
Movie();
// destructor
virtual ~Movie() = default;
// copy constructor not allowed
Movie(const Movie &c) = delete;
// move not allowed
Movie(Movie &&other) = delete;
// assignment not allowed
Movie &operator=(const Movie &other) = delete;
// move assignment not allowed
Movie &operator=(Movie &&other) = delete;
// register movie type
static void registerType(const char &movieType, MovieFactory *factory);
// create movie of this type
static Movie *create(const char &movieType);
// @return char for the movie type
char getMovieType() const;
// @return ItemKey of the object
ItemKey getItemKey() const;
// virtual function to read the line from the file and sets the values to this
// object
virtual bool read(istream &is) = 0;
// @return true if year is valid from 1800 to current year
bool isYearValid() const;
// For Borrow/Return commands
// decrease stock for borrow command
void decreaseStock();
// increase stock for return command
void increaseStock();
// @return true if have 1 or more
// use for borrow command
bool haveInStock() const;
// virtual function to print out movie object
// should be overridden for drama, comedy, and classic objects separately
virtual void printMovie() const = 0;
// protected variables for child classes
protected:
ItemKey itemKey;
string director, title;
int year, stock, borrowedNum;
char movieType, mediaType;
// @return true if stack is 0 or more
bool isStockValid() const;
// helper function for read(istream& is) function
string readNextItem(istream &io, char comma = ',');
private:
// Storage place for the concrete movie factory
// Having it available only through this function guarantees that
// this static variable is initialized
// when a concrete factory tires to register itself
// @return map
static map<char, MovieFactory *> &getMap() {
static map<char, MovieFactory *> factories;
return factories;
}
};
#endif