core/tags/artist: Add an artist_lookup() function

For looking up artist tags without allocating a new one.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-15 09:47:05 -04:00 committed by Anna Schumaker
parent e41f554b2e
commit b3922cc731
3 changed files with 14 additions and 2 deletions

View File

@ -73,6 +73,11 @@ struct artist *artist_find(const gchar *name)
return ARTIST(db_find(&artist_db, name));
}
struct artist *artist_lookup(const gchar *name)
{
return ARTIST(db_get(&artist_db, name));
}
struct artist *artist_get(const unsigned int index)
{
return ARTIST(db_at(&artist_db, index));

View File

@ -31,8 +31,13 @@ void artist_db_init();
/* Called to clean up the artist database. */
void artist_db_deinit();
/* Called to find an artist tag by name. */
/*
* Called to find an artist tag by name. The difference is that artist_find()
* will allocate a new artiststruct if the requested one doesn't exist yet,
* but library_lookup() will return NULL in this situation.
*/
struct artist *artist_find(const gchar *);
struct artist *artist_lookup(const gchar *);
/* Called to get an artist tag with a specific index. */
struct artist *artist_get(const unsigned int);

View File

@ -80,10 +80,12 @@ static void test_artist_db()
struct artist *artist;
artist_db_init();
artist = artist_lookup("Koji Kondo");
test_equal((void *)artist, NULL);
artist = artist_find("Koji Kondo");
test_verify_koji(artist);
test_equal((void *)artist_lookup("Koji Kondo"), (void *)artist);
test_equal((void *)artist_find("Koji Kondo"), (void *)artist);
test_equal((void *)artist_get(0), (void *)artist);
test_equal((void *)artist_get(1), (void *)NULL);