core/tags/library: Add a library_lookup() function

I want a way to lookup library paths without allocating new ones, so
let's add this now.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-09 10:09:59 -04:00 committed by Anna Schumaker
parent 6e02f75262
commit 938bbc92f2
3 changed files with 14 additions and 1 deletions

View File

@ -81,6 +81,11 @@ struct library *library_find(const gchar *path)
return LIBRARY(db_find(&library_db, path));
}
struct library *library_lookup(const gchar *path)
{
return LIBRARY(db_get(&library_db, path));
}
struct library *library_get(const unsigned int index)
{
return LIBRARY(db_at(&library_db, index));

View File

@ -35,8 +35,13 @@ void library_db_deinit();
/* Called to access the library database. */
const struct database *library_db_get();
/* Called to find a library tag by library path. */
/*
* Called to find a library tag by library path. The difference is that
* library_find() will allocate a new library struct if the requested one
* doesn't exist yet, but library_lookup() will return NULL in this situation.
*/
struct library *library_find(const gchar *);
struct library *library_lookup(const gchar *);
/* Called to get a library tag with a specific index. */
struct library *library_get(const unsigned int);

View File

@ -77,10 +77,13 @@ static void test_library_db()
test_equal(library_db_get()->db_size, 0);
library_db_init();
library = library_lookup("/home/Zelda/Music");
test_equal((void *)library, NULL);
library = library_find("/home/Zelda/Music");
test_verify_zelda(library);
test_equal(library_db_get()->db_size, 1);
test_equal((void *)library_lookup("/home/Zelda/Music"), (void *)library);
test_equal((void *)library_find("/home/Zelda/Music"), (void *)library);
test_equal((void *)library_get(0), (void *)library);
test_equal((void *)library_get(1), NULL);