core/queue: Move queue_size() out of the queue struct

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-11-19 13:48:59 -05:00
parent 331e56716a
commit c259177dde
11 changed files with 70 additions and 76 deletions

View File

@ -208,7 +208,7 @@ struct track *deck :: next()
continue;
track = queue_next(&(*it));
if (it->size() == 0)
if (queue_size(&(*it)) == 0)
_destroy(it);
break;
}

View File

@ -18,7 +18,7 @@ public:
void clear()
{
while (size() > 0)
while (queue_size(this) > 0)
del((unsigned)0);
}

View File

@ -160,7 +160,7 @@ void queue_selected(struct queue *queue, unsigned int index)
struct track *queue_next(struct queue *queue)
{
unsigned int size = queue->size();
unsigned int size = queue_size(queue);
struct track *res;
if (!(queue->q_flags & Q_ENABLED))
@ -180,11 +180,6 @@ struct track *queue_next(struct queue *queue)
return res;
}
unsigned int queue :: size()
{
return q_tracks.size();
}
class SortTracks {
public:
std::vector<struct sort_info> fields;

View File

@ -108,7 +108,7 @@ QueueTab :: ~QueueTab()
void QueueTab :: on_track_removed(unsigned int row)
{
this->Tab :: on_track_removed(row);
if (tab_pq->size() == 0)
if (queue_size(tab_pq) == 0)
delete this;
}

View File

@ -33,7 +33,7 @@ CollectionLabel :: CollectionLabel(BaseObjectType *cobject,
void CollectionLabel :: set_size()
{
gchar *size = g_strdup_printf("%u", _queue->size());
gchar *size = g_strdup_printf("%u", queue_size(_queue));
collection_size->set_text(size);
g_free(size);
}
@ -49,7 +49,7 @@ HistoryLabel :: HistoryLabel(BaseObjectType *cobject,
void HistoryLabel :: set_size()
{
gchar *size = g_strdup_printf("%u", _queue->size());
gchar *size = g_strdup_printf("%u", queue_size(_queue));
history_size->set_text(size);
g_free(size);
}
@ -81,7 +81,7 @@ void TempLabel :: set_sensitive(bool sensitive)
void TempLabel :: set_size()
{
gchar *size = g_strdup_printf("%u", _queue->size());
gchar *size = g_strdup_printf("%u", queue_size(_queue));
temp_size->set_text(size);
g_free(size);
}

View File

@ -155,13 +155,13 @@ bool QueueModel::iter_next_vfunc(const Gtk::TreeIter &iter,
int QueueModel::iter_n_root_children_vfunc() const
{
return _queue->size();
return queue_size(_queue);
}
bool QueueModel::iter_nth_root_child_vfunc(int n, Gtk::TreeIter &iter) const
{
iter = Gtk::TreeIter();
if (n >= (int)_queue->size())
if (n >= (int)queue_size(_queue))
return false;
iter.set_stamp(_stamp);

View File

@ -164,14 +164,6 @@ struct queue {
void updated(struct track *);
/**
* Find the size of the queue.
*
* @return The number of tracks on the queue.
*/
unsigned int size();
/**
* Add a new sort field to the queue. If the field is already in the
* _sort_order then it's ascending or descending value will be toggled.
@ -194,6 +186,13 @@ struct queue {
};
/* Called to find the size of the queue. */
static inline unsigned int queue_size(struct queue *queue)
{
return queue->q_tracks.size();
}
/* Called to tell the queue that a specific index has been selected. */
void queue_selected(struct queue *, unsigned int);

View File

@ -30,12 +30,12 @@ static void test_init()
test_equal(deck :: get_queues().size(), (size_t)2);
it = deck :: get_queues().begin();
test_equal(it->size(), (unsigned)4);
test_equal(queue_size(&(*it)), (unsigned)4);
for (unsigned int i = 0; i < 4; i++)
test_equal((*it)[i]->tr_dbe.dbe_index, i);
it++;
test_equal(it->size(), (unsigned)5);
test_equal(queue_size(&(*it)), (unsigned)5);
for (unsigned int i = 0; i < 5; i++)
test_equal((*it)[i]->tr_dbe.dbe_index, i + 4);
@ -121,7 +121,7 @@ static void test_next_prev()
q0->add(track_get(i));
test_not_equal(q, Q_NULL);
test_equal(q->size(), (unsigned)0);
test_equal(queue_size(q), (unsigned)0);
test_equal(deck :: prev(), TRACK_NULL);
for (unsigned int i = 0; i < 2; i++) {
@ -129,7 +129,7 @@ static void test_next_prev()
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)1);
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)2);
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)3);
test_equal(q->size(), (unsigned)4);
test_equal(queue_size(q), (unsigned)4);
}
for (unsigned int i = 0; i < 2; i++) {
@ -146,9 +146,9 @@ static void test_next_prev()
q1->unset_flag(Q_ENABLED);
collection :: get_queue()->unset_flag(Q_RANDOM);
test_equal(q1->size(), (unsigned)5);
test_equal(queue_size(q1), (unsigned)5);
deck :: next();
test_equal(q1->size(), (unsigned)5);
test_equal(queue_size(q1), (unsigned)5);
q1->set_flag(Q_ENABLED);
for (unsigned int i = 0; i < 5; i++)

View File

@ -25,7 +25,7 @@ static void test_init()
tags_init();
collection :: init();
test_equal(q->size(), (unsigned)24);
test_equal(queue_size(q), (unsigned)24);
}
static void test_enable()
@ -34,22 +34,22 @@ static void test_enable()
struct library *library = library_get(0);
collection :: set_enabled(LIB_NULL, true);
test_equal(q->size(), (unsigned)24);
test_equal(queue_size(q), (unsigned)24);
collection :: set_enabled(library, false);
test_equal(q->size(), (unsigned)0);
test_equal(queue_size(q), (unsigned)0);
collection :: set_enabled(library, true);
test_equal(q->size(), (unsigned)24);
test_equal(queue_size(q), (unsigned)24);
collection :: set_enabled(library, true);
test_equal(q->size(), (unsigned)24);
test_equal(queue_size(q), (unsigned)24);
collection :: set_enabled(library, false);
test_equal(q->size(), (unsigned)0);
test_equal(queue_size(q), (unsigned)0);
collection :: set_enabled(library, true);
test_equal(q->size(), (unsigned)24);
test_equal(queue_size(q), (unsigned)24);
}
static void test_remove()
@ -58,13 +58,13 @@ static void test_remove()
struct library *library = library_get(0);
collection :: remove(LIB_NULL);
test_equal(q->size(), (unsigned)24);
test_equal(queue_size(q), (unsigned)24);
collection :: remove(library);
test_equal(q->size(), (unsigned)0);
test_equal(queue_size(q), (unsigned)0);
collection :: remove(library);
test_equal(q->size(), (unsigned)0);
test_equal(queue_size(q), (unsigned)0);
}
static void test_add()
@ -74,13 +74,13 @@ static void test_add()
test_generate_library();
collection :: add("/tmp/ocarina/");
test_equal(q->size(), (unsigned)0);
test_equal(queue_size(q), (unsigned)0);
test_equal(idle_run_task(), true);
test_equal(q->size(), (unsigned)0);
test_equal(queue_size(q), (unsigned)0);
for (unsigned int i = 0; i < 6; i++) {
test_equal(idle_run_task(), (i < 5) ? true : false);
test_equal(q->size(), i * 7);
test_equal(queue_size(q), i * 7);
}
}
@ -91,22 +91,22 @@ static void test_update()
collection :: update_all();
test_equal(idle_run_task(), true);
test_equal(q->size(), (unsigned)21);
test_equal(queue_size(q), (unsigned)21);
for (unsigned int i = 0; i < 4; i++)
test_equal(idle_run_task(), (i < 3) ? true : false);
test_equal(q->size(), (unsigned)21);
test_equal(queue_size(q), (unsigned)21);
test_generate_library();
collection :: update_all();
test_equal(idle_run_task(), true);
test_equal(q->size(), (unsigned)21);
test_equal(queue_size(q), (unsigned)21);
for (unsigned int i = 0; i < 6; i++)
test_equal(idle_run_task(), (i < 5) ? true : false);
test_equal(q->size(), (unsigned)35);
test_equal(queue_size(q), (unsigned)35);
}
DECLARE_UNIT_TESTS(

View File

@ -33,7 +33,7 @@ static void test_init()
ent = playlist :: get_tracks("Banned");
test_equal(set_size(&ent->ie_set), (size_t)4);
test_equal(collection :: get_queue()->size(), (unsigned)20);
test_equal(queue_size(collection :: get_queue()), (unsigned)20);
ent = playlist :: get_tracks("Favorites");
test_equal(set_size(&ent->ie_set), (size_t)8);
ent = playlist :: get_tracks("No Such Playlist");
@ -45,19 +45,19 @@ static void test_queue()
queue *q = playlist :: get_queue();
playlist :: select("Banned");
test_equal(q->size(), (unsigned)4);
test_equal(queue_size(q), (unsigned)4);
playlist :: select("Favorites");
test_equal(q->size(), (unsigned)8);
test_equal(queue_size(q), (unsigned)8);
playlist :: select("Unplayed");
test_equal(q->size(), (unsigned)3);
test_equal(queue_size(q), (unsigned)3);
playlist :: select("Most Played");
test_equal(q->size(), (unsigned)10);
test_equal(queue_size(q), (unsigned)10);
playlist :: select("Least Played");
test_equal(q->size(), (unsigned)12);
test_equal(queue_size(q), (unsigned)12);
}
static void test_add()
@ -71,14 +71,14 @@ static void test_add()
playlist :: add(track_get(5), "Banned");
ent = playlist :: get_tracks("Banned");
test_equal(set_size(&ent->ie_set), (size_t)5);
test_equal(q->size(), (unsigned)8);
test_equal(l->size(), (unsigned)19);
test_equal(queue_size(q), (unsigned)8);
test_equal(queue_size(l), (unsigned)19);
playlist :: add(track_get(16), "Favorites");
playlist :: add(track_get(5), "Favorites");
ent = playlist :: get_tracks("Favorites");
test_equal(set_size(&ent->ie_set), (size_t)9);
test_equal(q->size(), (unsigned)9);
test_equal(queue_size(q), (unsigned)9);
playlist :: add(track_get(6), "No Playlist");
test_equal(playlist :: get_tracks("No Playlist"), IDX_NULL);
@ -93,13 +93,13 @@ static void test_delete()
playlist :: del(track_get(5), "Banned");
ent = playlist :: get_tracks("Banned");
test_equal(set_size(&ent->ie_set), (size_t)4);
test_equal(q->size(), (unsigned)9);
test_equal(l->size(), (unsigned)20);
test_equal(queue_size(q), (unsigned)9);
test_equal(queue_size(l), (unsigned)20);
playlist :: del(track_get(5), "Favorites");
ent = playlist :: get_tracks("Favorites");
test_equal(set_size(&ent->ie_set), (size_t)8);
test_equal(q->size(), (unsigned)8);
test_equal(queue_size(q), (unsigned)8);
playlist :: del(track_get(6), "No Playlist");
test_equal(playlist :: get_tracks("No Playlist"), IDX_NULL);

View File

@ -124,16 +124,16 @@ static void test_stress(unsigned int N)
test_loop_equal(q.add(track), i, i);
test_loop_equal(count_added, i + 1, i);
} test_loop_passed();
test_equal(q.q_length, ex_length);
test_equal(q.size(), ex_size);
test_equal(q.q_length, ex_length);
test_equal(queue_size(&q), ex_size);
/* Queue :: del(struct track *) */
track = track_get(0);
ex_length -= track->tr_length * (N / 13);
ex_size -= (N / 13);
q.del(track);
test_equal(q.q_length, ex_length);
test_equal(q.size(), ex_size);
test_equal(q.q_length, ex_length);
test_equal(queue_size(&q), ex_size);
/* Queue :: del(unsigned int) */
track = track_get(1);
@ -143,8 +143,8 @@ static void test_stress(unsigned int N)
test_loop_equal(q[i], track, i);
q.del(i);
} test_loop_passed();
test_equal(q.q_length, ex_length);
test_equal(q.size(), ex_size);
test_equal(q.q_length, ex_length);
test_equal(queue_size(&q), ex_size);
/* Queue :: updated(struct track *) */
track = track_get(2);
@ -152,7 +152,7 @@ static void test_stress(unsigned int N)
test_equal(count_updated, N / 13);
test_equal(queue_next(&q), NULL);
test_equal(q.size(), ex_size);
test_equal(queue_size(&q), ex_size);
/* Tracks should not be removed. */
q.set_flag(Q_ENABLED);
@ -160,18 +160,18 @@ static void test_stress(unsigned int N)
for (i = 0; i < ex_size; i++) {
test_loop_equal(queue_next(&q), track_get((i % 11) + 2), i);
queue_selected(&q, i);
test_loop_equal(q.size(), ex_size, i);
test_loop_equal(queue_size(&q), ex_size, i);
} test_loop_passed();
/* Tracks should be removed. */
q.unset_flag(Q_REPEAT);
for (i = 0; i < ex_size; i++) {
test_loop_equal(queue_next(&q), track_get((i % 11) + 2), i);
test_loop_equal(q.size(), ex_size - (i + 1), i);
test_loop_equal(queue_size(&q), ex_size - (i + 1), i);
} test_loop_passed();
test_equal(q.size(), 0);
test_equal(q.q_length, 0);
test_equal(q.q_length, 0);
test_equal(queue_size(&q), 0);
}
static void test_basics() { test_stress(13); }
@ -188,7 +188,7 @@ static void test_rand_select()
/* Call next() on an empty queue. */
for (i = 0; i < 13; i++) {
test_loop_equal(queue_next(&q), NULL, i);
test_loop_equal(q.size(), 0, i);
test_loop_equal(queue_size(&q), 0, i);
} test_loop_passed();
for (i = 0; i < 13; i++)
@ -206,28 +206,28 @@ static void test_rand_select()
/* select = 6, q = { <0>, 2, 3, 4, 5, 6, (7), 8, 9, 10, 11, 12 } */
queue_selected(&q, 6);
test_equal(q.size(), 11);
test_equal(queue_size(&q), 11);
/* rand() = 3, q = { 0, 2, 3, 4, 5, <6>, 8, 9, [10], 11, 12 } */
test_equal(queue_next(&q)->tr_dbe.dbe_index, 10);
/* select = 7, q = { 0, 2, 3, 4, 5, 6, 8, (<9>), 11, 12 } */
queue_selected(&q, 7);
test_equal(q.size(), 9);
test_equal(queue_size(&q), 9);
/* rand() = 4, q = { 0, 2, 3, 4, 5, 6, <8>, [11], 12 } */
test_equal(queue_next(&q)->tr_dbe.dbe_index, 11);
/* select = 2, q = { 0, 2, (3), 4, 5, 6, <8>, 12 } */
queue_selected(&q, 2);
test_equal(q.size(), 7);
test_equal(queue_size(&q), 7);
/* rand() = 1, q = { 0, <2>, [4], 5, 6, 8, 12 } */
test_equal(queue_next(&q)->tr_dbe.dbe_index, 4);
/* select = 1, q = { 0, <2>, 5, 6, 8, (12) } */
queue_selected(&q, 5);
test_equal(q.size(), 5);
test_equal(queue_size(&q), 5);
/* rand() = 1, q = { [0], 2, 5, 6, <8>, } */
test_equal(queue_next(&q)->tr_dbe.dbe_index, 0);
@ -237,14 +237,14 @@ static void test_rand_select()
/* select = 1, q = { <>, 5, (6), 8, } */
queue_selected(&q, 1);
test_equal(q.size(), 2);
test_equal(queue_size(&q), 2);
/* rand() = 1, q = { <5>, [8], } */
test_equal(queue_next(&q)->tr_dbe.dbe_index, 8);
/* select = 1, q = { <[5]> } */
queue_selected(&q, 0);
test_equal(q.size(), 0);
test_equal(queue_size(&q), 0);
/* q = { } */
test_equal(queue_next(&q), NULL);
@ -320,7 +320,7 @@ static void test_save_load()
test_equal(r.has_flag(Q_RANDOM), true);
test_equal(r.q_length, q.q_length);
test_equal(r.size(), 13);
test_equal(queue_size(&r), 13);
for (i = 0; i < 13; i++) {
test_loop_equal(q[i]->tr_dbe.dbe_index, 12 - i, i);