queue: Improve the constructor to take multiple flags at once

It really should have been like this from the beginning.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-04-13 18:38:49 -04:00
parent d939dcab20
commit 6ee68397fd
5 changed files with 26 additions and 13 deletions

View File

@ -13,10 +13,12 @@ enum queue_flags {
Q_ENABLED = (1 << 0),
Q_RANDOM = (1 << 1),
Q_REPEAT = (1 << 2),
Q_NEVER_SORT = (1 << 3),
Q_NO_SORT = (1 << 3),
Q_DISABLE_CHANGED_SIZE = (1 << 31),
};
static const unsigned int Q_FLAG_MASK = Q_ENABLED | Q_RANDOM | Q_REPEAT | Q_NO_SORT | Q_DISABLE_CHANGED_SIZE;
struct sort_info {
sort_t field;
bool ascending;
@ -35,7 +37,7 @@ protected:
public:
Queue();
Queue(queue_flags);
Queue(unsigned int);
~Queue();
void write(File &);
void read(File &);

View File

@ -19,7 +19,7 @@ static bool o_pause_enabled = false;
static unsigned int o_pause_count = 0;
static bool o_should_pause = false;
static Queue o_recently_played(Q_ENABLED);
static Queue o_recently_played(Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_DISABLE_CHANGED_SIZE);
static File f_cur_track("cur_track", FILE_TYPE_DATA);
static void parse_error(GstMessage *error)
@ -117,9 +117,6 @@ void audio :: init(int *argc, char ***argv)
{
GstBus *bus;
o_recently_played.set_flag(Q_REPEAT);
o_recently_played.set_flag(Q_NEVER_SORT);
o_recently_played.set_flag(Q_DISABLE_CHANGED_SIZE);
gst_init(argc, argv);
ocarina_player = gst_element_factory_make("playbin", "ocarina_player");

View File

@ -8,7 +8,7 @@
static std::set<unsigned int> empty_set;
static Index playlist_db("playlist.db", false);
static Queue playlist_pq(Q_ENABLED);
static Queue playlist_pq(Q_ENABLED | Q_REPEAT | Q_NO_SORT);
static std::string cur_pq;
static void import_ban_track(unsigned int track_id)
@ -24,8 +24,6 @@ void playlist :: init()
playlist_pq.add_sort(SORT_ARTIST);
playlist_pq.add_sort(SORT_YEAR);
playlist_pq.add_sort(SORT_TRACK);
playlist_pq.set_flag(Q_REPEAT);
playlist_pq.set_flag(Q_NEVER_SORT);
get_callbacks()->on_library_import_ban = import_ban_track;

View File

@ -18,8 +18,8 @@ Queue :: Queue()
{
}
Queue :: Queue(queue_flags f)
: _cur(-1), _flags(f), _length(0)
Queue :: Queue(unsigned int f)
: _cur(-1), _flags(f & Q_FLAG_MASK), _length(0)
{
}
@ -253,7 +253,7 @@ void Queue :: _add_sort(sort_t field, bool ascending)
void Queue :: add_sort(sort_t field, bool ascending)
{
if (_flags & Q_NEVER_SORT)
if (_flags & Q_NO_SORT)
return;
_add_sort(field, ascending);
@ -266,7 +266,7 @@ void Queue :: add_sort(sort_t field, bool ascending)
void Queue :: reset_sort(sort_t field, bool ascending)
{
if (_flags & Q_NEVER_SORT)
if (_flags & Q_NO_SORT)
return;
if (_sort_order.front().field != field)
_sort_order.clear();

View File

@ -4,15 +4,19 @@
#include <queue.h>
#include "test.h"
class TestQueue : public Queue
{
public:
TestQueue() : Queue() {}
TestQueue(unsigned int f) : Queue(f) {}
unsigned int get_cur() { return _cur; }
unsigned int get_flags() { return _flags; }
unsigned int get_length() { return _length; }
std::list <sort_info> get_sorder() { return _sort_order; };
};
void test_default()
{
TestQueue q;
@ -24,8 +28,20 @@ void test_default()
test :: equal(q.next(), (Track *)NULL);
}
void test_constructor(unsigned int flags)
{
TestQueue q(flags | (1 << 30));
test :: equal(q.get_cur(), (unsigned)-1);
test :: equal(q.get_flags(), flags);
test :: equal(q.get_length(), (unsigned)0);
test :: equal(q.get_sorder().size(), (size_t)0);
test :: equal(q.next(), (Track *)NULL);
}
int main(int argc, char **argv)
{
test_default();
test_constructor(Q_ENABLED | Q_RANDOM);
return 0;
}