-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlaylist.cpp
137 lines (112 loc) · 2.6 KB
/
Playlist.cpp
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
#include "Playlist.h"
#include <ostream>
#include <sstream>
#include <string>
using std::ostream;
using std::string;
using std::stringstream;
Playlist::Playlist() {printstrchanged = changed = true;}
Playlist::Playlist(const string& n) : name(n) {printstrchanged = changed = true;}
Playlist::Playlist(const string& n, const Playlist& b) :
name(n), items(b.items) {
printstrchanged = true;
}
Playlist::Playlist(const string& n, Show& s) :
name(n) {
add(s);
}
void Playlist::add(Show& s) {
items.push_back(s);
printstrchanged = changed = true;
}
void Playlist::add(Show& s, size_t pos) {
if(pos < items.size())
items.insert(items.begin()+pos, s);
else
add(s);
printstrchanged = changed = true;
}
auto Playlist::begin() -> decltype(items.end()) {
return items.begin();
}
void Playlist::change() {
printstrchanged = changed = true;
}
void Playlist::deleteselection(decltype(items.begin()) s) {
if (!items.empty()) {
items.erase(s);
}
}
auto Playlist::end() -> decltype(items.end()) {
return items.end();
}
auto Playlist::first() -> decltype(items.end()) {
unsigned int watched = begin()->getwatched();
for(auto i = begin(); i < end(); ++i)
if(i->getwatched() < watched)
return i;
return begin();
}
const std::string& Playlist::getname() const {
return name;
}
const std::string& Playlist::getoldname() const {
return old_name;
}
bool Playlist::haschanged() {
return changed;
}
unsigned int Playlist::played() {
unsigned int ret = 0;
if(printstrchanged) {
#if __GNUC__ <= 4 && __GNUC_MINOR__ < 6
size_t size = items.size();
for(size_t i = 0; i < size; ++i)
if(items[i].getwatched())
++ret;
#else
for(Show &s: items) {
if(s.getwatched())
++ret;
}
#endif
}
return ret;
}
bool Playlist::operator< (const Playlist& o) const {
return getname() < o.getname();
}
string Playlist::print() {
stringstream out;
if(printstrchanged) {
out << '[' << played() << '/' << items.size() << "]";
// Make all the playlist names line up, assumes max # items 999
auto len = out.str().length();
int dif = 10 - len;
for(;dif;--dif)
out << ' ';
out << '\t' << name;
printstr = out.str();
printstrchanged = false;
}
return printstr;
}
string Playlist::print(size_t pos) {
if(pos >= 0 && pos < items.size()) {
stringstream out;
out << pos << ": " << items[pos].print();
return out.str();
}
return "";
}
void Playlist::printdetail(ostream& o) {
size_t played = 0;
o << played << ' ' << items.size() << ' ' << name;
}
void Playlist::remove(size_t pos) {
if(pos < items.size())
items.erase(items.begin()+pos);
}
const size_t Playlist::size() {
return items.size();
}