-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovie.cpp
More file actions
69 lines (46 loc) · 1.55 KB
/
Movie.cpp
File metadata and controls
69 lines (46 loc) · 1.55 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
#include "Movie.h"
template <class T>
T sum(const T* array, unsigned int size){
T s = 0;
for (unsigned int i = 0; i < size; i++) s += array[i];
return s;
}
Movie::Movie(const int* array, unsigned int length,
std::string name, std::string pathname) :
Video(sum(array, length), name, pathname){
duration_array = nullptr;
setChapiterDuration(array, length);
}
Movie::Movie(const Movie& from) : Video(from){
duration_array = nullptr;
Movie::setChapiterDuration(from.getChapiterDuration(), from.getNumberOfChapiter());
}
Movie::~Movie() {
delete[] duration_array;
}
Movie& Movie::operator=(const Movie& from){
Video::operator=(from);
setChapiterDuration(from.getChapiterDuration(), from.getNumberOfChapiter());
return *this;
}
const int* Movie::getChapiterDuration() const {
return (const int*) duration_array;
}
void Movie::setChapiterDuration(const int* array, unsigned int length) {
delete[] duration_array;
this->duration_array = new int[length];
std::copy(array, array + length, duration_array);
Video::setDuration(sum<int>(array, length));
array_length = length;
}
void Movie::display(std::ostream& stream) const{
Video::display(stream);
for (unsigned int i = 0; i < array_length; i++) {
stream << duration_array[i] << " ";
}
stream << std::endl;
}
void Movie::setDuration(float duration) {
std::cout << "[-] WARNING : You cannot specify the duration of a movie ! "
<< "It's the sum of the duration of each chapiter" << std::endl;
}