core/tempq: Switch STL list for glib GSList
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
17981f4393
commit
15f5b8fc87
117
core/deck.cpp
117
core/deck.cpp
|
@ -7,26 +7,12 @@ extern "C" {
|
|||
}
|
||||
#include <core/deck.h>
|
||||
#include <core/file.h>
|
||||
#include <glib.h>
|
||||
|
||||
static std::list<struct queue *> queue_deck;
|
||||
static GSList *tempq_list;
|
||||
static struct file deck_file;
|
||||
|
||||
|
||||
static unsigned int __tempq_index(struct queue *queue)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
std::list<struct queue *>::iterator it;
|
||||
|
||||
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
||||
if (*it == queue)
|
||||
return i;
|
||||
i++;
|
||||
}
|
||||
|
||||
return queue_deck.size();
|
||||
}
|
||||
|
||||
|
||||
void tempq_init(struct queue_ops *ops)
|
||||
{
|
||||
unsigned int flags, count, j, id;
|
||||
|
@ -47,34 +33,39 @@ void tempq_init(struct queue_ops *ops)
|
|||
file_readf(&deck_file, "%u", &id);
|
||||
queue_add(queue, track_get(id));
|
||||
}
|
||||
queue_deck.back()->q_ops = ops;
|
||||
queue->q_ops = ops;
|
||||
}
|
||||
file_close(&deck_file);
|
||||
}
|
||||
|
||||
void tempq_deinit()
|
||||
{
|
||||
while (queue_deck.size() > 0) {
|
||||
queue_deinit(*queue_deck.begin());
|
||||
delete *queue_deck.begin();
|
||||
queue_deck.erase(queue_deck.begin());
|
||||
GSList *cur;
|
||||
|
||||
for (cur = tempq_list; cur; cur = g_slist_next(cur)) {
|
||||
queue_deinit((struct queue *)cur->data);
|
||||
delete (struct queue *)cur->data;
|
||||
}
|
||||
|
||||
g_slist_free(tempq_list);
|
||||
tempq_list = NULL;
|
||||
}
|
||||
|
||||
void tempq_save(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
std::list<struct queue *>::iterator it;
|
||||
unsigned int i;
|
||||
GSList *cur;
|
||||
|
||||
if (!file_open(&deck_file, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
file_writef(&deck_file, "%zu\n", queue_deck.size());
|
||||
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
||||
file_writef(&deck_file, "%u %zu", (*it)->q_flags, queue_size(*it));
|
||||
for (i = 0; i < queue_size(*it); i++) {
|
||||
file_writef(&deck_file, "%zu\n", g_slist_length(tempq_list));
|
||||
for (cur = tempq_list; cur; cur = g_slist_next(cur)) {
|
||||
queue = (struct queue *)cur->data;
|
||||
file_writef(&deck_file, "%u %zu", queue->q_flags, queue_size(queue));
|
||||
for (i = 0; i < queue_size(queue); i++) {
|
||||
file_writef(&deck_file, " %u",
|
||||
queue_at(*it, i)->tr_dbe.dbe_index);
|
||||
queue_at(queue, i)->tr_dbe.dbe_index);
|
||||
}
|
||||
file_writef(&deck_file, "\n");
|
||||
}
|
||||
|
@ -86,7 +77,7 @@ struct queue *tempq_alloc(struct queue_ops *ops, unsigned int flags)
|
|||
{
|
||||
struct queue *queue = new struct queue;
|
||||
|
||||
queue_deck.push_back(queue);
|
||||
tempq_list = g_slist_append(tempq_list, queue);
|
||||
queue_init(queue, flags | Q_ENABLED | Q_SAVE_FLAGS | Q_SAVE_SORT, ops);
|
||||
tempq_save(queue, Q_ENABLED);
|
||||
return queue;
|
||||
|
@ -94,74 +85,48 @@ struct queue *tempq_alloc(struct queue_ops *ops, unsigned int flags)
|
|||
|
||||
void tempq_free(struct queue *queue)
|
||||
{
|
||||
std::list<struct queue *>::iterator it;
|
||||
|
||||
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
||||
if (*it == queue) {
|
||||
queue_deck.erase(it);
|
||||
tempq_save(queue, Q_ENABLED);
|
||||
queue_deinit(queue);
|
||||
delete queue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
tempq_list = g_slist_remove(tempq_list, queue);
|
||||
queue_deinit(queue);
|
||||
tempq_save(queue, Q_ENABLED);
|
||||
delete queue;
|
||||
}
|
||||
|
||||
struct queue *tempq_get(unsigned int index)
|
||||
{
|
||||
std::list<struct queue *>::iterator it;
|
||||
unsigned int i;
|
||||
|
||||
it = queue_deck.begin();
|
||||
for (i = 0; i < queue_deck.size(); i++) {
|
||||
if (i == index)
|
||||
return *it;
|
||||
it++;
|
||||
}
|
||||
return NULL;
|
||||
return (struct queue *)g_slist_nth_data(tempq_list, index);
|
||||
}
|
||||
|
||||
void tempq_move(struct queue *queue, unsigned int index)
|
||||
{
|
||||
unsigned int old_pos = __tempq_index(queue);
|
||||
std::list<struct queue *>::iterator it_old = queue_deck.begin();
|
||||
std::list<struct queue *>::iterator it_new = queue_deck.begin();
|
||||
|
||||
for (unsigned int i = 0; i < queue_deck.size(); i++) {
|
||||
if (i < old_pos)
|
||||
it_old++;
|
||||
|
||||
if (i < index)
|
||||
it_new++;
|
||||
GSList *cur = g_slist_find(tempq_list, queue);
|
||||
GSList *nth = g_slist_nth(tempq_list, index);
|
||||
if (cur && nth && (cur != nth)) {
|
||||
tempq_list = g_slist_remove(tempq_list, queue);
|
||||
tempq_list = g_slist_insert_before(tempq_list, nth, queue);
|
||||
tempq_save(queue, Q_ENABLED);
|
||||
}
|
||||
|
||||
if (index > old_pos)
|
||||
it_new++;
|
||||
|
||||
queue_deck.splice(it_new, queue_deck, it_old);
|
||||
tempq_save(queue, Q_ENABLED);
|
||||
}
|
||||
|
||||
struct track *tempq_next()
|
||||
{
|
||||
struct track *track = NULL;
|
||||
std::list<struct queue *>::iterator it;
|
||||
struct queue *queue = NULL;
|
||||
GSList *cur;
|
||||
|
||||
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
||||
if (queue_has_flag(*it, Q_ENABLED) == false)
|
||||
continue;
|
||||
|
||||
track = queue_next(*it);
|
||||
if (queue_size(*it) == 0)
|
||||
tempq_free(*it);
|
||||
break;
|
||||
for (cur = tempq_list; cur; cur = g_slist_next(cur)) {
|
||||
queue = (struct queue *)cur->data;
|
||||
if (queue_has_flag(queue, Q_ENABLED)) {
|
||||
track = queue_next(queue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (queue && queue_size(queue) == 0)
|
||||
tempq_free(queue);
|
||||
return track;
|
||||
}
|
||||
|
||||
unsigned int tempq_count()
|
||||
{
|
||||
return queue_deck.size();
|
||||
return g_slist_length(tempq_list);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
extern "C" {
|
||||
#include <core/queue.h>
|
||||
}
|
||||
#include <list>
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue