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

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-11-29 16:34:51 -05:00
parent ea00b406e5
commit acc78a6667
7 changed files with 19 additions and 22 deletions

View File

@ -32,7 +32,7 @@ unsigned int TempQueue :: add(struct track *track)
void TempQueue :: del(struct track *track) void TempQueue :: del(struct track *track)
{ {
queue :: del(track); queue_remove_all(this, track);
deck :: write(); deck :: write();
} }
@ -201,7 +201,7 @@ struct track *deck :: next()
if (!track) if (!track)
track = queue_next(collection :: get_queue()); track = queue_next(collection :: get_queue());
if (track) { if (track) {
recent_queue.del(track); queue_remove_all(&recent_queue, track);
queue_add(&recent_queue, track); queue_add(&recent_queue, track);
recent_queue.q_cur = 0; recent_queue.q_cur = 0;
} }

View File

@ -126,7 +126,7 @@ static void validate_library(void *data)
path = track_path(track); path = track_path(track);
if (g_file_test(path, G_FILE_TEST_EXISTS) == false) { if (g_file_test(path, G_FILE_TEST_EXISTS) == false) {
library_q.del(track); queue_remove_all(&library_q, track);
track_remove(track); track_remove(track);
} }
g_free(path); g_free(path);
@ -225,7 +225,7 @@ void collection :: set_enabled(struct library *library, bool enabled)
if (enabled) if (enabled)
queue_add(&library_q, track); queue_add(&library_q, track);
else else
library_q.del(track); queue_remove_all(&library_q, track);
} }
} }
} }

View File

@ -87,7 +87,8 @@ void playlist :: init()
return; return;
set_for_each(&ent->ie_set, &it) set_for_each(&ent->ie_set, &it)
collection :: get_queue()->del(track_get(it.it_val)); queue_remove_all(collection :: get_queue(),
track_get(it.it_val));
} }
bool playlist :: has(struct track *track, const std::string &name) bool playlist :: has(struct track *track, const std::string &name)
@ -107,7 +108,7 @@ void playlist :: add(struct track *track, const std::string &name)
if (cur_plist == name) if (cur_plist == name)
queue_add(&playlist_q, track); queue_add(&playlist_q, track);
if (name == "Banned") if (name == "Banned")
collection :: get_queue()->del(track); queue_remove_all(collection :: get_queue(), track);
} }
} }
@ -115,7 +116,7 @@ void playlist :: del(struct track *track, const std::string &name)
{ {
index_remove(&playlist_db, name.c_str(), track->tr_dbe.dbe_index); index_remove(&playlist_db, name.c_str(), track->tr_dbe.dbe_index);
if (cur_plist == name) if (cur_plist == name)
playlist_q.del(track); queue_remove_all(&playlist_q, track);
if (name == "Banned") if (name == "Banned")
queue_add(collection :: get_queue(), track); queue_add(collection :: get_queue(), track);
} }

View File

@ -141,11 +141,12 @@ void queue_remove(struct queue *queue, unsigned int index)
queue->q_cur--; queue->q_cur--;
} }
void queue :: del(struct track *track) void queue_remove_all(struct queue *queue, struct track *track)
{ {
for (unsigned int i = 0; i < q_tracks.size(); i++) { for (unsigned int i = 0; i < queue->q_tracks.size(); i++) {
while ((i < q_tracks.size()) && (q_tracks[i] == track)) while (i < queue->q_tracks.size() &&
queue_remove(this, i); queue->q_tracks[i] == track)
queue_remove(queue, i);
} }
} }

View File

@ -98,7 +98,7 @@ static void remove_banned_tracks()
return; return;
set_for_each(&ent->ie_set, &it) set_for_each(&ent->ie_set, &it)
collection :: get_queue()->del(track_get(it.it_val)); queue_remove_all(collection :: get_queue(), track_get(it.it_val));
} }

View File

@ -108,14 +108,6 @@ struct queue {
* @param file File to read Queue data from. * @param file File to read Queue data from.
*/ */
void read(file &); void read(file &);
/**
* Remove all instances of a track from the queue.
*
* @param track Track to remove from the queue.
*/
virtual void del(struct track *);
}; };
@ -154,6 +146,9 @@ unsigned int queue_add(struct queue *, struct track *);
/* Called to remove a track from the queue by index. */ /* Called to remove a track from the queue by index. */
void queue_remove(struct queue *, unsigned int); void queue_remove(struct queue *, unsigned int);
/* Called to remove all instances of the track from the queue. */
void queue_remove_all(struct queue *, struct track *);
/* Called to tell the queue that a track has been updated. */ /* Called to tell the queue that a track has been updated. */
void queue_updated(struct queue *, struct track *); void queue_updated(struct queue *, struct track *);

View File

@ -168,11 +168,11 @@ static void test_stress(unsigned int N)
test_equal(q.q_length, ex_length); test_equal(q.q_length, ex_length);
test_equal(queue_size(&q), ex_size); test_equal(queue_size(&q), ex_size);
/* Queue :: del(struct track *) */ /* queue_remove_all() */
track = track_get(0); track = track_get(0);
ex_length -= track->tr_length * (N / 13); ex_length -= track->tr_length * (N / 13);
ex_size -= (N / 13); ex_size -= (N / 13);
q.del(track); queue_remove_all(&q, track);
test_equal(q.q_length, ex_length); test_equal(q.q_length, ex_length);
test_equal(queue_size(&q), ex_size); test_equal(queue_size(&q), ex_size);