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

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-11-19 13:50:08 -05:00
parent c259177dde
commit ff0c2a09a8
6 changed files with 31 additions and 25 deletions

View File

@ -216,8 +216,3 @@ void queue :: sort(compare_t field, bool reset)
for (unsigned int i = 0; i < q_tracks.size(); i++)
q_notify->on_track_updated(i);
}
struct track *queue :: operator[](unsigned int index)
{
return q_tracks[index];
}

View File

@ -61,7 +61,7 @@ unsigned int QueueModel :: iter_to_id(const Gtk::TreeIter &iter) const
unsigned int QueueModel::path_to_id(const Gtk::TreePath &path) const
{
return _queue->operator[](path[0])->tr_dbe.dbe_index;
return queue_at(_queue, path[0])->tr_dbe.dbe_index;
}
@ -105,7 +105,7 @@ void QueueModel::get_value_vfunc(const Gtk::TreeIter &iter, int column,
column > get_n_columns_vfunc())
return;
track = _queue->operator[](iter_to_id(iter));
track = queue_at(_queue, iter_to_id(iter));
switch (column) {
case 0:

View File

@ -50,7 +50,7 @@ bool QueueWindow :: filter_ids(const Gtk::TreeIter &iter)
return true;
id = q_model->iter_to_id(iter);
return set_has(&_q_search_res, _queue->operator[](id)->tr_dbe.dbe_index);
return set_has(&_q_search_res, queue_at(_queue, id)->tr_dbe.dbe_index);
}
bool QueueWindow :: on_key_press(GdkEventKey *event)

View File

@ -175,14 +175,6 @@ struct queue {
* @param reset Set to true if current sort data should be discarded.
*/
virtual void sort(compare_t, bool);
/**
* Access a track by index.
*
* @param index The index to look up.
* @return The track found at the requested index.
*/
struct track *operator[](unsigned int);
};
@ -192,6 +184,12 @@ static inline unsigned int queue_size(struct queue *queue)
return queue->q_tracks.size();
}
/* Called to access the queued track at a given index. */
static inline struct track *queue_at(struct queue *queue, unsigned int index)
{
return queue->q_tracks[index];
}
/* Called to tell the queue that a specific index has been selected. */
void queue_selected(struct queue *, unsigned int);

View File

@ -32,12 +32,12 @@ static void test_init()
it = deck :: get_queues().begin();
test_equal(queue_size(&(*it)), (unsigned)4);
for (unsigned int i = 0; i < 4; i++)
test_equal((*it)[i]->tr_dbe.dbe_index, i);
test_equal(queue_at(&(*it), i)->tr_dbe.dbe_index, i);
it++;
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);
test_equal(queue_at(&(*it), i)->tr_dbe.dbe_index, i + 4);
/*
* Test that we saved the deck in the new format

View File

@ -140,7 +140,7 @@ static void test_stress(unsigned int N)
ex_length -= track->tr_length * (N / 13);
ex_size -= (N / 13);
for (i = 0; i < ex_size; i += 11) {
test_loop_equal(q[i], track, i);
test_loop_equal(queue_at(&q, i), track, i);
q.del(i);
} test_loop_passed();
test_equal(q.q_length, ex_length);
@ -267,26 +267,34 @@ static void test_sorting()
q.sort(COMPARE_COUNT, true);
for (i = 0; i < 13; i++) {
test_loop_equal(q[i]->tr_dbe.dbe_index, ex_count[i], i);
track = queue_at(&q, i);
test_loop_not_equal(track, NULL, i);
test_loop_equal(track->tr_dbe.dbe_index, ex_count[i], i);
} test_loop_passed();
q.set_flag(Q_NO_SORT);
q.sort(COMPARE_TITLE, true);
for (i = 0; i < 13; i++) {
test_loop_equal(q[i]->tr_dbe.dbe_index, ex_count[i], i);
track = queue_at(&q, i);
test_loop_not_equal(track, NULL, i);
test_loop_equal(track->tr_dbe.dbe_index, ex_count[i], i);
} test_loop_passed();
q.unset_flag(Q_NO_SORT);
q.sort(COMPARE_TITLE, true);
for (i = 0; i < 13; i++) {
test_loop_equal(q[i]->tr_dbe.dbe_index, ex_title[i], i);
track = queue_at(&q, i);
test_loop_not_equal(track, NULL, i);
test_loop_equal(track->tr_dbe.dbe_index, ex_title[i], i);
} test_loop_passed();
q.sort(COMPARE_COUNT, true);
q.sort(COMPARE_TITLE, false);
q.sort(COMPARE_COUNT, false);
for (i = 0; i < 13; i++) {
test_loop_equal(q[i]->tr_dbe.dbe_index, ex_co_ti[i], i);
track = queue_at(&q, i);
test_loop_not_equal(track, NULL, i);
test_loop_equal(track->tr_dbe.dbe_index, ex_co_ti[i], i);
} test_loop_passed();
q.sort(COMPARE_ARTIST, true);
@ -294,13 +302,16 @@ static void test_sorting()
q.sort(COMPARE_TRACK, false);
q.sort(COMPARE_TRACK, false);
for (i = 0; i < 13; i++) {
test_loop_equal(q[i]->tr_dbe.dbe_index, 12 - i, i);
track = queue_at(&q, i);
test_loop_not_equal(track, NULL, i);
test_loop_equal(track->tr_dbe.dbe_index, 12 - i, i);
} test_loop_passed();
}
static void test_save_load()
{
struct queue q(Q_RANDOM), r(0);
struct track *track;
unsigned int i;
struct file f;
@ -323,7 +334,9 @@ static void test_save_load()
test_equal(queue_size(&r), 13);
for (i = 0; i < 13; i++) {
test_loop_equal(q[i]->tr_dbe.dbe_index, 12 - i, i);
track = queue_at(&q, i);
test_loop_not_equal(track, NULL ,i);
test_loop_equal(track->tr_dbe.dbe_index, 12 - i, i);
} test_loop_passed();
__test_deinit_core();