-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlaylist.h
137 lines (117 loc) · 3.01 KB
/
Playlist.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
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include "Show.h"
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
#include "soci/soci/src/core/soci.h"
class Playlist {
private:
//! Keep track of whether or not our string caches need to be updated
bool printstrchanged, changed;
//! String cache of detailed info, name of playlist, prior name of playlist
std::string printstr, name, old_name;
//! List of shows in this playlist
std::vector<Show> items;
public:
Playlist();
Playlist(const std::string& n);
/**
* Only use this constructor when initializing from the database
*/
Playlist(const std::string& n, const Playlist& b);
Playlist(const std::string& n, Show& s);
~Playlist() {}
/**
* Add a new show to the playlist
*/
void add(Show& s);
/**
* Add a new show to the playlist at a given position
*/
void add(Show& s, size_t pos);
/**
* Get the iterator to the first element in the playlist
*/
auto begin() -> decltype(items.end());
/**
* Get the iterator to the last element in the playlist + 1
*/
auto end() -> decltype(items.end());
/**
* Get the first unplayed element in the playlist for this session
* If there is none, returns begin()
*/
auto first() -> decltype(items.end());
//! Operator for sorting
bool operator< (const Playlist& o) const;
/**
* Marks this playlist as modified, for methods that can be more efficient
* with this knowledge
*/
void change();
/**
* Remove the selected item from the playlist
*/
void deleteselection(decltype(items.begin()) s);
/**
* Get the number of times played?
*/
unsigned int played();
/**
* Remove an item at a given position from the playlist
*/
void remove(size_t pos);
/**
* Print the playlist for output of some kind
*/
std::string print();
/**
* Print a more detailed version of the playlist to a given stream
* (mainly for saving to a file)
*/
void printdetail(std::ostream& o);
/**
* Print an element at a given position in the playlist
*/
std::string print(size_t pos);
/**
* Return a const reference to the name
*/
const std::string& getname() const;
/**
* If the name is changed and we need to update it in the database
*/
const std::string& getoldname() const;
/**
* Return the size of the playlist
*/
const size_t size();
/**
* Return if the playlist data has changed
*/
bool haschanged();
/**
* Database type conversion for named identifiers, needs private access
*/
template<class Playlist> friend struct soci::type_conversion;
};
/**
* SOCI type conversion code for database access ease
*/
namespace soci {
template<>
struct type_conversion<Playlist> {
typedef values base_type;
static void from_base(const values& v, indicator /* ind */, Playlist p) {
p.name = v.get<std::string>("NAME");
}
static void to_base(const Playlist& p, values& v, indicator& ind) {
v.set("NAME", p.name);
v.set("OLDNAME", p.old_name);
ind = i_ok;
}
};
}
#endif