core/tags/artist: Replace constructor with a backwards pointer
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
5309ea5931
commit
d404579297
|
@ -10,43 +10,40 @@ extern "C" {
|
|||
static struct database artist_db;
|
||||
|
||||
|
||||
artist :: artist() {}
|
||||
|
||||
static db_entry *artist_alloc(const gchar *name)
|
||||
{
|
||||
struct artist *artist = new struct artist;
|
||||
gchar *lower = string_lowercase(name);
|
||||
|
||||
dbe_init(&artist->ar_dbe, artist);
|
||||
artist->ar_name = name;
|
||||
artist->ar_lower = lower;
|
||||
|
||||
g_free(lower);
|
||||
return artist;
|
||||
return &artist->ar_dbe;
|
||||
}
|
||||
|
||||
static void artist_free(struct db_entry *dbe)
|
||||
{
|
||||
delete (struct artist *)dbe;
|
||||
delete ARTIST(dbe);
|
||||
}
|
||||
|
||||
static gchar *artist_key(struct db_entry *dbe)
|
||||
{
|
||||
struct artist *artist = (struct artist *)dbe;
|
||||
return g_strdup(artist->ar_name.c_str());
|
||||
return g_strdup(ARTIST(dbe)->ar_name.c_str());
|
||||
}
|
||||
|
||||
struct db_entry *artist_read(struct file *file)
|
||||
{
|
||||
gchar *name = file_readl(file);
|
||||
struct artist *artist = (struct artist *)artist_alloc(name);
|
||||
struct db_entry *dbe = artist_alloc(name);
|
||||
g_free(name);
|
||||
return artist;
|
||||
return dbe;
|
||||
}
|
||||
|
||||
static void artist_write(struct file *file, struct db_entry *dbe)
|
||||
{
|
||||
struct artist *artist = (struct artist *)dbe;
|
||||
file_writef(file, "%s", artist->ar_name.c_str());
|
||||
file_writef(file, "%s", ARTIST(dbe)->ar_name.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ static void track_write(struct file *file, struct db_entry *dbe)
|
|||
{
|
||||
struct track *track = (struct track *)dbe;
|
||||
file_writef(file, "%u %u %u %u %u ", track->tr_library->dbe_index,
|
||||
track->tr_artist->dbe_index,
|
||||
track->tr_artist->ar_dbe.dbe_index,
|
||||
track->tr_album->al_dbe.dbe_index,
|
||||
track->tr_genre->dbe_index,
|
||||
track->tr_track);
|
||||
|
|
|
@ -13,14 +13,13 @@ extern "C" {
|
|||
* The Artist tag is used to store the name of artists added
|
||||
* to the tag database.
|
||||
*/
|
||||
struct artist : public db_entry {
|
||||
struct artist {
|
||||
std::string ar_name; /* This artist's name. */
|
||||
std::string ar_lower; /* This artist's name (lowercased). */
|
||||
|
||||
artist(); /**< Artist tag constructor. */
|
||||
struct db_entry ar_dbe;
|
||||
};
|
||||
|
||||
#define ARTIST(dbe) ((struct artist *)dbe)
|
||||
#define ARTIST(dbe) ((struct artist *)DBE_DATA(dbe))
|
||||
|
||||
|
||||
/* Called to initialize the artist database. */
|
||||
|
|
|
@ -9,7 +9,7 @@ static void test_verify_empty(struct artist *artist)
|
|||
const struct db_ops *artist_ops = test_artist_ops();
|
||||
test_equal(artist->ar_name, "");
|
||||
test_equal(artist->ar_lower, "");
|
||||
test_str_equal(artist_ops->dbe_key(artist), "");
|
||||
test_str_equal(artist_ops->dbe_key(&artist->ar_dbe), "");
|
||||
}
|
||||
|
||||
static void test_verify_koji(struct artist *artist)
|
||||
|
@ -17,7 +17,7 @@ static void test_verify_koji(struct artist *artist)
|
|||
const struct db_ops *artist_ops = test_artist_ops();
|
||||
test_equal(artist->ar_name, "Koji Kondo");
|
||||
test_equal(artist->ar_lower, "koji kondo");
|
||||
test_str_equal(artist_ops->dbe_key(artist), "Koji Kondo");
|
||||
test_str_equal(artist_ops->dbe_key(&artist->ar_dbe), "Koji Kondo");
|
||||
}
|
||||
|
||||
static void test_artist()
|
||||
|
@ -27,27 +27,27 @@ static void test_artist()
|
|||
unsigned int i;
|
||||
file f;
|
||||
|
||||
artist = (struct artist *)artist_ops->dbe_alloc("Koji Kondo");
|
||||
artist = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
|
||||
test_verify_koji(artist);
|
||||
|
||||
file_init(&f, "artist_tag", 0);
|
||||
file_open(&f, OPEN_WRITE);
|
||||
file_writef(&f, "1 \n1 ");
|
||||
artist_ops->dbe_write(&f, artist);
|
||||
artist_ops->dbe_write(&f, &artist->ar_dbe);
|
||||
file_close(&f);
|
||||
artist_ops->dbe_free(artist);
|
||||
artist_ops->dbe_free(&artist->ar_dbe);
|
||||
|
||||
file_open(&f, OPEN_READ);
|
||||
file_readf(&f, "%u", &i);
|
||||
artist = (struct artist *)artist_ops->dbe_read(&f);
|
||||
artist = ARTIST(artist_ops->dbe_read(&f));
|
||||
test_verify_empty(artist);
|
||||
artist_ops->dbe_free(artist);
|
||||
artist_ops->dbe_free(&artist->ar_dbe);
|
||||
|
||||
file_readf(&f, "%u", &i);
|
||||
artist = (struct artist *)artist_ops->dbe_read(&f);
|
||||
artist = ARTIST(artist_ops->dbe_read(&f));
|
||||
file_close(&f);
|
||||
test_verify_koji(artist);
|
||||
artist_ops->dbe_free(artist);
|
||||
artist_ops->dbe_free(&artist->ar_dbe);
|
||||
}
|
||||
|
||||
static void test_artist_compare()
|
||||
|
@ -55,15 +55,15 @@ static void test_artist_compare()
|
|||
const struct db_ops *artist_ops = test_artist_ops();
|
||||
struct artist *koji, *hajime;
|
||||
|
||||
koji = (struct artist *)artist_ops->dbe_alloc("Koji Kondo");
|
||||
hajime = (struct artist *)artist_ops->dbe_alloc("hajime wakai");
|
||||
koji = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
|
||||
hajime = ARTIST(artist_ops->dbe_alloc("hajime wakai"));
|
||||
|
||||
test_equal(artist_compare(koji, koji), 0);
|
||||
test_equal(artist_compare(koji, hajime), 1);
|
||||
test_equal(artist_compare(hajime, koji), -1);
|
||||
|
||||
artist_ops->dbe_free(koji);
|
||||
artist_ops->dbe_free(hajime);
|
||||
artist_ops->dbe_free(&koji->ar_dbe);
|
||||
artist_ops->dbe_free(&hajime->ar_dbe);
|
||||
}
|
||||
|
||||
static void test_artist_db()
|
||||
|
|
Loading…
Reference in New Issue