core/database: Remove db_entry::index() function
Let's just access the dbe_index variable directly. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
3eb27debfb
commit
847e4c1925
|
@ -18,7 +18,7 @@ static AudioDriver *cur_driver = NULL;
|
|||
static void save_state()
|
||||
{
|
||||
file_open(&f_cur_track, OPEN_WRITE);
|
||||
file_writef(&f_cur_track, "%u\n", cur_track->index());
|
||||
file_writef(&f_cur_track, "%u\n", cur_track->dbe_index);
|
||||
file_close(&f_cur_track);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,3 @@ db_entry :: db_entry()
|
|||
}
|
||||
|
||||
db_entry :: ~db_entry() {}
|
||||
|
||||
const unsigned int db_entry :: index()
|
||||
{
|
||||
return dbe_index;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ void playlist :: init()
|
|||
|
||||
bool playlist :: has(struct track *track, const std::string &name)
|
||||
{
|
||||
return index_has(&playlist_db, name.c_str(), track->index());
|
||||
return index_has(&playlist_db, name.c_str(), track->dbe_index);
|
||||
}
|
||||
|
||||
void playlist :: add(struct track *track, const std::string &name)
|
||||
|
@ -103,7 +103,7 @@ void playlist :: add(struct track *track, const std::string &name)
|
|||
return;
|
||||
|
||||
if (!has(track, name)) {
|
||||
index_insert(&playlist_db, name.c_str(), track->index());
|
||||
index_insert(&playlist_db, name.c_str(), track->dbe_index);
|
||||
if (cur_plist == name)
|
||||
playlist_q.add(track);
|
||||
if (name == "Banned")
|
||||
|
@ -113,7 +113,7 @@ void playlist :: add(struct track *track, const std::string &name)
|
|||
|
||||
void playlist :: del(struct track *track, const std::string &name)
|
||||
{
|
||||
index_remove(&playlist_db, name.c_str(), track->index());
|
||||
index_remove(&playlist_db, name.c_str(), track->dbe_index);
|
||||
if (cur_plist == name)
|
||||
playlist_q.del(track);
|
||||
if (name == "Banned")
|
||||
|
|
|
@ -35,7 +35,7 @@ void Queue :: write(file &file)
|
|||
{
|
||||
file_writef(&file, "%u %zu", _flags, _tracks.size());
|
||||
for (unsigned int i = 0; i < _tracks.size(); i++)
|
||||
file_writef(&file, " %u", _tracks[i]->index());
|
||||
file_writef(&file, " %u", _tracks[i]->dbe_index);
|
||||
}
|
||||
|
||||
void Queue :: read(file &file)
|
||||
|
|
|
@ -18,7 +18,7 @@ static const std::string __track_key(struct library *library, const std::string
|
|||
std :: string res;
|
||||
|
||||
if (library) {
|
||||
gchar *g_res = g_strdup_printf("%u/%s", library->index(),
|
||||
gchar *g_res = g_strdup_printf("%u/%s", library->dbe_index,
|
||||
path.c_str());
|
||||
res = g_res;
|
||||
g_free(g_res);
|
||||
|
@ -71,9 +71,9 @@ track :: track(const std::string &key)
|
|||
tr_lower = lower;
|
||||
|
||||
date_set(&tr_date, 0, 0, 0);
|
||||
filter :: add(tr_title, index());
|
||||
filter :: add(tr_artist->ar_name, index());
|
||||
filter :: add(tr_album->al_name, index());
|
||||
filter :: add(tr_title, dbe_index);
|
||||
filter :: add(tr_artist->ar_name, dbe_index);
|
||||
filter :: add(tr_album->al_name, dbe_index);
|
||||
|
||||
taglib_tag_free_strings();
|
||||
taglib_file_free(file);
|
||||
|
@ -118,17 +118,17 @@ void track :: read(file &file)
|
|||
tr_album = album_get(album_id);
|
||||
tr_genre = genre_get(genre_id);
|
||||
|
||||
filter :: add(tr_title, index());
|
||||
filter :: add(tr_artist->ar_name, index());
|
||||
filter :: add(tr_album->al_name, index());
|
||||
filter :: add(tr_title, dbe_index);
|
||||
filter :: add(tr_artist->ar_name, dbe_index);
|
||||
filter :: add(tr_album->al_name, dbe_index);
|
||||
tr_library->li_size++;
|
||||
}
|
||||
|
||||
void track :: write(file &file)
|
||||
{
|
||||
file_writef(&file, "%u %u %u %u %u ", tr_library->index(),
|
||||
tr_artist->index(), tr_album->index(),
|
||||
tr_genre->index(), tr_track);
|
||||
file_writef(&file, "%u %u %u %u %u ", tr_library->dbe_index,
|
||||
tr_artist->dbe_index, tr_album->dbe_index,
|
||||
tr_genre->dbe_index, tr_track);
|
||||
date_write(&file, &tr_date);
|
||||
file_writef(&file, " %u %u %s\n%s\n", tr_count, tr_length,
|
||||
tr_title.c_str(), tr_path.c_str());
|
||||
|
|
|
@ -35,7 +35,7 @@ static void list_path(struct library *lib)
|
|||
|
||||
if (lib) {
|
||||
row = *(c_list->append());
|
||||
row[c_cols.c_id] = lib->index();
|
||||
row[c_cols.c_id] = lib->dbe_index;
|
||||
row[c_cols.c_enabled] = lib->li_enabled;
|
||||
row[c_cols.c_size] = lib->li_size;
|
||||
row[c_cols.c_path] = lib->primary_key();
|
||||
|
|
|
@ -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])->index();
|
||||
return _queue->operator[](path[0])->dbe_index;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,7 +46,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)->index());
|
||||
return set_has(&_q_search_res, _queue->operator[](id)->dbe_index);
|
||||
}
|
||||
|
||||
void QueueWindow :: on_row_activated(const Gtk::TreePath &path,
|
||||
|
|
|
@ -23,13 +23,6 @@ struct db_entry {
|
|||
db_entry(const std::string);
|
||||
virtual ~db_entry() = 0; /**< Virtual destructor */
|
||||
|
||||
/**
|
||||
* Called to access a DatabaseEntry's index.
|
||||
*
|
||||
* @return DatabaseEntry::_index
|
||||
*/
|
||||
const unsigned int index();
|
||||
|
||||
/**
|
||||
* The primary key of a DatabaseEntry is a unique string representing
|
||||
* a single DatabaseEntry instance. This is used for preventing
|
||||
|
|
|
@ -20,7 +20,7 @@ void db_deinit(struct database<T> *db)
|
|||
{
|
||||
T *t, *u;
|
||||
db_for_each(t, u, db) {
|
||||
db->db_entries[t->index()] = NULL;
|
||||
db->db_entries[t->dbe_index] = NULL;
|
||||
delete t;
|
||||
db->db_size--;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ T *db_insert(struct database<T> *db, T *item)
|
|||
item->dbe_index = db_actual_size(db);
|
||||
db->db_entries.push_back(item);
|
||||
|
||||
db->db_keys[item->primary_key()] = item->index();
|
||||
db->db_keys[item->primary_key()] = item->dbe_index;
|
||||
db->db_size++;
|
||||
db_autosave(db);
|
||||
return db->db_entries[item->dbe_index];
|
||||
|
@ -102,9 +102,9 @@ void db_remove(struct database<T> *db, T *item)
|
|||
{
|
||||
if (item == NULL)
|
||||
return;
|
||||
if (db_at(db, item->index()) != item)
|
||||
if (db_at(db, item->dbe_index) != item)
|
||||
return;
|
||||
db->db_entries[item->index()] = NULL;
|
||||
db->db_entries[item->dbe_index] = NULL;
|
||||
db->db_keys.erase(item->primary_key());
|
||||
delete item;
|
||||
db->db_size--;
|
||||
|
@ -137,7 +137,7 @@ template <class T>
|
|||
T *db_next(const struct database<T> *db, T *ent)
|
||||
{
|
||||
if (ent)
|
||||
return __db_next(db, ent->index() + 1);
|
||||
return __db_next(db, ent->dbe_index + 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ void test_track_controls()
|
|||
|
||||
audio :: pause();
|
||||
audio :: next();
|
||||
test_not_equal(audio :: current_track()->index(), (unsigned)2);
|
||||
test_not_equal(audio :: current_track()->dbe_index, (unsigned)2);
|
||||
test_equal(driver->is_playing(), false);
|
||||
|
||||
audio :: play();
|
||||
|
|
|
@ -37,8 +37,8 @@ static void test_db_entry()
|
|||
struct int_entry *ent = new struct int_entry(1);
|
||||
struct file f;
|
||||
|
||||
test_equal(ent->index(), 0);
|
||||
test_equal(ent->ie_val, 1);
|
||||
test_equal(ent->dbe_index, 0);
|
||||
test_equal(ent->ie_val, 1);
|
||||
test_equal(ent->primary_key(), "1");
|
||||
|
||||
file_init(&f, "test_db_entry", 0);
|
||||
|
@ -91,7 +91,7 @@ static void test_stress(unsigned int N)
|
|||
for (i = 0; i < N; i++) {
|
||||
dbe = db_insert(&db, new int_entry(i));
|
||||
test_loop_not_equal(dbe, NULL, i);
|
||||
test_loop_equal(dbe->index(), i, i);
|
||||
test_loop_equal(dbe->dbe_index, i, i);
|
||||
test_loop_equal(dbe->ie_val, i, i);
|
||||
ptrs.push_back(dbe);
|
||||
} test_loop_passed();
|
||||
|
|
|
@ -30,12 +30,12 @@ static void test_init()
|
|||
it = deck :: get_queues().begin();
|
||||
test_equal(it->size(), (unsigned)4);
|
||||
for (unsigned int i = 0; i < 4; i++)
|
||||
test_equal((*it)[i]->index(), i);
|
||||
test_equal((*it)[i]->dbe_index, i);
|
||||
|
||||
it++;
|
||||
test_equal(it->size(), (unsigned)5);
|
||||
for (unsigned int i = 0; i < 5; i++)
|
||||
test_equal((*it)[i]->index(), i + 4);
|
||||
test_equal((*it)[i]->dbe_index, i + 4);
|
||||
|
||||
/*
|
||||
* Test that we saved the deck in the new format
|
||||
|
@ -123,19 +123,19 @@ static void test_next_prev()
|
|||
test_equal(deck :: prev(), TRACK_NULL);
|
||||
|
||||
for (unsigned int i = 0; i < 2; i++) {
|
||||
test_equal(deck :: next()->index(), (unsigned)0);
|
||||
test_equal(deck :: next()->index(), (unsigned)1);
|
||||
test_equal(deck :: next()->index(), (unsigned)2);
|
||||
test_equal(deck :: next()->index(), (unsigned)3);
|
||||
test_equal(deck :: next()->dbe_index, (unsigned)0);
|
||||
test_equal(deck :: next()->dbe_index, (unsigned)1);
|
||||
test_equal(deck :: next()->dbe_index, (unsigned)2);
|
||||
test_equal(deck :: next()->dbe_index, (unsigned)3);
|
||||
test_equal(q->size(), (unsigned)4);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < 2; i++) {
|
||||
if (i == 1)
|
||||
test_equal(deck :: prev()->index(), (unsigned)3);
|
||||
test_equal(deck :: prev()->index(), (unsigned)2);
|
||||
test_equal(deck :: prev()->index(), (unsigned)1);
|
||||
test_equal(deck :: prev()->index(), (unsigned)0);
|
||||
test_equal(deck :: prev()->dbe_index, (unsigned)3);
|
||||
test_equal(deck :: prev()->dbe_index, (unsigned)2);
|
||||
test_equal(deck :: prev()->dbe_index, (unsigned)1);
|
||||
test_equal(deck :: prev()->dbe_index, (unsigned)0);
|
||||
}
|
||||
|
||||
test_equal(deck :: get_queues().size(), (size_t)1);
|
||||
|
|
|
@ -193,7 +193,7 @@ void test_next()
|
|||
for (unsigned int i = 0; i < 24; i++) {
|
||||
track = q.next();
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_equal(track->index(), i % 24, i);
|
||||
test_loop_equal(track->dbe_index, i % 24, i);
|
||||
} test_loop_passed();
|
||||
test_equal(q.size(), (unsigned)0);
|
||||
test_equal(q.length(), 0);
|
||||
|
@ -207,7 +207,7 @@ void test_next()
|
|||
for (unsigned int i = 0; i < 24; i++) {
|
||||
track = q.next();
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_equal(track->index(), expected_rand[i], i);
|
||||
test_loop_equal(track->dbe_index, expected_rand[i], i);
|
||||
} test_loop_passed();
|
||||
test_equal(q.size(), (unsigned)0);
|
||||
test_equal(q.length(), 0);
|
||||
|
@ -221,7 +221,7 @@ void test_next()
|
|||
for (unsigned int i = 0; i < 48; i++) {
|
||||
track = q.next();
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_equal(track->index(), i % 24, i);
|
||||
test_loop_equal(track->dbe_index, i % 24, i);
|
||||
} test_loop_passed();
|
||||
test_equal(q.size(), (unsigned)24);
|
||||
}
|
||||
|
@ -235,12 +235,12 @@ void test_select()
|
|||
test_equal(q.size(), (unsigned)24);
|
||||
q.track_selected(10);
|
||||
test_equal(q.size(), (unsigned)23);
|
||||
test_equal(q.next()->index(), (unsigned)11);
|
||||
test_equal(q.next()->dbe_index, (unsigned)11);
|
||||
|
||||
q.set_flag(Q_REPEAT);
|
||||
q.track_selected(0);
|
||||
test_equal(q.size(), (unsigned)22);
|
||||
test_equal(q.next()->index(), (unsigned)1);
|
||||
test_equal(q.next()->dbe_index, (unsigned)1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -257,18 +257,18 @@ void test_sorting()
|
|||
test_equal(q.get_sorder().size(), (size_t)1);
|
||||
test_fill_q(&q);
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->index(), exp_sort_title[i], i);
|
||||
test_loop_equal(q[i]->dbe_index, exp_sort_title[i], i);
|
||||
test_loop_passed();
|
||||
|
||||
q.sort(SORT_TITLE, false);
|
||||
test_equal(q.get_sorder().size(), (size_t)1);
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->index(), exp_sort_title[23 - i], i);
|
||||
test_loop_equal(q[i]->dbe_index, exp_sort_title[23 - i], i);
|
||||
test_loop_passed();
|
||||
|
||||
q.sort(SORT_LENGTH, true);
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->index(), i, i);
|
||||
test_loop_equal(q[i]->dbe_index, i, i);
|
||||
test_loop_passed();
|
||||
|
||||
q.sort(SORT_YEAR, true);
|
||||
|
@ -276,7 +276,7 @@ void test_sorting()
|
|||
q.sort(SORT_TITLE, false);
|
||||
test_equal(q.get_sorder().size(), (size_t)2);
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->index(), exp_sort_ye_ti[i], i);
|
||||
test_loop_equal(q[i]->dbe_index, exp_sort_ye_ti[i], i);
|
||||
test_loop_passed();
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ void test_saving()
|
|||
test_equal(r.length(), q.length());
|
||||
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->index(), r[i]->index(), i);
|
||||
test_loop_equal(q[i]->dbe_index, r[i]->dbe_index, i);
|
||||
test_loop_passed();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue