diff options
author | Max Kellermann <max@duempel.org> | 2013-01-06 14:58:54 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-06 18:59:39 +0100 |
commit | 70652abf9750b62d2b4e5857d894494ae6058cf1 (patch) | |
tree | ba38fec9699eb2094cb2dda7a6f3f9dbb427a709 /src | |
parent | e202b407ec18570ad54a04c64341f654b447fb31 (diff) | |
download | mpd-70652abf9750b62d2b4e5857d894494ae6058cf1.tar.gz mpd-70652abf9750b62d2b4e5857d894494ae6058cf1.tar.xz mpd-70652abf9750b62d2b4e5857d894494ae6058cf1.zip |
Queue: add constructor and destructor
Diffstat (limited to 'src')
-rw-r--r-- | src/Playlist.hxx | 4 | ||||
-rw-r--r-- | src/Queue.cxx | 46 | ||||
-rw-r--r-- | src/Queue.hxx | 24 |
3 files changed, 31 insertions, 43 deletions
diff --git a/src/Playlist.hxx b/src/Playlist.hxx index b158d0464..a93c88f05 100644 --- a/src/Playlist.hxx +++ b/src/Playlist.hxx @@ -70,12 +70,10 @@ struct playlist { int queued; playlist(unsigned max_length) - :current(-1), queued(-1) { - queue_init(&queue, max_length); + :queue(max_length), current(-1), queued(-1) { } ~playlist() { - queue_finish(&queue); } }; diff --git a/src/Queue.cxx b/src/Queue.cxx index 485ffb1cc..a8a737540 100644 --- a/src/Queue.cxx +++ b/src/Queue.cxx @@ -300,40 +300,32 @@ queue_clear(struct queue *queue) queue->length = 0; } -void -queue_init(struct queue *queue, unsigned max_length) +queue::queue(unsigned _max_length) + :max_length(_max_length), length(0), + version(1), + items(g_new(struct queue_item, max_length)), + order((unsigned *)g_malloc(sizeof(order[0]) * max_length)), + id_to_position((int *)g_malloc(sizeof(id_to_position[0]) * + max_length * QUEUE_HASH_MULT)), + repeat(false), + single(false), + consume(false), + random(false), + rand(g_rand_new()) { - queue->max_length = max_length; - queue->length = 0; - queue->version = 1; - queue->repeat = false; - queue->random = false; - queue->single = false; - queue->consume = false; - - queue->items = g_new(struct queue_item, max_length); - queue->order = (unsigned *) - g_malloc(sizeof(queue->order[0]) * max_length); - queue->id_to_position = (int *) - g_malloc(sizeof(queue->id_to_position[0]) * - max_length * QUEUE_HASH_MULT); - for (unsigned i = 0; i < max_length * QUEUE_HASH_MULT; ++i) - queue->id_to_position[i] = -1; - - queue->rand = g_rand_new(); + id_to_position[i] = -1; } -void -queue_finish(struct queue *queue) +queue::~queue() { - queue_clear(queue); + queue_clear(this); - g_free(queue->items); - g_free(queue->order); - g_free(queue->id_to_position); + g_free(items); + g_free(order); + g_free(id_to_position); - g_rand_free(queue->rand); + g_rand_free(rand); } static const struct queue_item * diff --git a/src/Queue.hxx b/src/Queue.hxx index 4c6d5ea11..6ab0a833f 100644 --- a/src/Queue.hxx +++ b/src/Queue.hxx @@ -99,6 +99,17 @@ struct queue { /** random number generator for shuffle and random mode */ GRand *rand; + + queue(unsigned max_length); + + /** + * Deinitializes a queue object. It does not free the queue + * pointer itself. + */ + ~queue(); + + queue(const queue &other) = delete; + queue &operator=(const queue &other) = delete; }; static inline unsigned @@ -233,19 +244,6 @@ queue_song_newer(const struct queue *queue, unsigned position, } /** - * Initialize a queue object. - */ -void -queue_init(struct queue *queue, unsigned max_length); - -/** - * Deinitializes a queue object. It does not free the queue pointer - * itself. - */ -void -queue_finish(struct queue *queue); - -/** * Returns the order number following the specified one. This takes * end of queue and "repeat" mode into account. * |