-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.cpp
62 lines (48 loc) · 1.14 KB
/
queue.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
#include "queue.hpp"
#include <stdexcept>
void PlayQueue::current(const std::string &path)
{
if (path.empty())
return;
if (!queue.current.empty())
{
queue.prev.push_back(std::move(queue.current));
if (queue.prev.size() > max_prev_backlog)
{
queue.prev.erase(queue.prev.begin() + queue.prev.size() - max_prev_backlog,
queue.prev.end());
}
}
queue.current = path;
}
const std::string& PlayQueue::current()
{
if (queue.current.empty())
next();
return queue.current;
}
void PlayQueue::prev()
{
if (queue.prev.empty())
throw std::logic_error("No files in prev queue.");
if (!queue.current.empty())
queue.next.push_front(std::move(queue.current));
queue.current = std::move(queue.prev.back());
queue.prev.pop_back();
}
void PlayQueue::next()
{
if (queue.next.empty())
throw std::logic_error("No files in next queue.");
current(std::move(queue.next.front()));
queue.next.pop_front();
}
void PlayQueue::clear()
{
queue.prev.clear();
queue.next.clear();
}
void PlayQueue::add(const std::string &path)
{
queue.next.push_back(path);
}