From ff0c2a09a84dbfd9c7f0a7a55a8afe58d6773c8c Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 19 Nov 2015 13:50:08 -0500 Subject: [PATCH] core/queue: Move queue_at() out of the queue struct Signed-off-by: Anna Schumaker --- core/queue.cpp | 5 ----- gui/queue/model.cpp | 4 ++-- gui/queue/window.cpp | 2 +- include/core/queue.h | 14 ++++++-------- tests/core/deck.cpp | 4 ++-- tests/core/queue.cpp | 27 ++++++++++++++++++++------- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/core/queue.cpp b/core/queue.cpp index c9ca49a3..0141ad39 100644 --- a/core/queue.cpp +++ b/core/queue.cpp @@ -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]; -} diff --git a/gui/queue/model.cpp b/gui/queue/model.cpp index d85fb91f..72d7932b 100644 --- a/gui/queue/model.cpp +++ b/gui/queue/model.cpp @@ -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: diff --git a/gui/queue/window.cpp b/gui/queue/window.cpp index f980a79d..ef2d4b63 100644 --- a/gui/queue/window.cpp +++ b/gui/queue/window.cpp @@ -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) diff --git a/include/core/queue.h b/include/core/queue.h index 941eb642..6cf3ec39 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -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); diff --git a/tests/core/deck.cpp b/tests/core/deck.cpp index 6499b62c..20238dc8 100644 --- a/tests/core/deck.cpp +++ b/tests/core/deck.cpp @@ -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 diff --git a/tests/core/queue.cpp b/tests/core/queue.cpp index 49d0e277..dd8841cd 100644 --- a/tests/core/queue.cpp +++ b/tests/core/queue.cpp @@ -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();