2014-11-08 13:43:23 -05:00
|
|
|
/**
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-10-22 13:19:09 -04:00
|
|
|
extern "C" {
|
|
|
|
#include <core/string.h>
|
|
|
|
}
|
2014-11-08 13:43:23 -05:00
|
|
|
#include <core/tags/artist.h>
|
|
|
|
|
2014-11-16 10:08:12 -05:00
|
|
|
|
2015-10-22 11:28:45 -04:00
|
|
|
static database<struct artist> artist_db;
|
2014-11-16 10:08:12 -05:00
|
|
|
|
|
|
|
|
2015-10-22 13:19:09 -04:00
|
|
|
artist :: artist() {}
|
2014-11-08 13:43:23 -05:00
|
|
|
|
2015-11-02 16:59:55 -05:00
|
|
|
static db_entry *artist_alloc(const gchar *name)
|
2014-11-08 13:43:23 -05:00
|
|
|
{
|
2015-11-02 16:59:55 -05:00
|
|
|
struct artist *artist = new struct artist;
|
|
|
|
gchar *lower = string_lowercase(name);
|
2015-10-22 13:19:09 -04:00
|
|
|
|
2015-11-02 16:59:55 -05:00
|
|
|
artist->ar_name = name;
|
|
|
|
artist->ar_lower = lower;
|
2015-10-22 13:19:09 -04:00
|
|
|
|
|
|
|
g_free(lower);
|
2015-11-02 16:59:55 -05:00
|
|
|
return artist;
|
2015-10-22 13:19:09 -04:00
|
|
|
}
|
|
|
|
|
2015-09-30 09:15:15 -04:00
|
|
|
static void artist_free(struct db_entry *dbe)
|
|
|
|
{
|
|
|
|
delete (struct artist *)dbe;
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:19:09 -04:00
|
|
|
const std::string artist :: primary_key() const
|
|
|
|
{
|
|
|
|
return ar_name;
|
|
|
|
}
|
|
|
|
|
2015-09-22 09:24:19 -04:00
|
|
|
struct db_entry *artist_read(struct file *file)
|
2015-10-22 13:19:09 -04:00
|
|
|
{
|
2015-09-22 09:24:19 -04:00
|
|
|
gchar *name = file_readl(file);
|
|
|
|
struct artist *artist = (struct artist *)artist_alloc(name);
|
2015-10-22 13:19:09 -04:00
|
|
|
g_free(name);
|
2015-09-22 09:24:19 -04:00
|
|
|
return artist;
|
2015-10-22 13:19:09 -04:00
|
|
|
}
|
|
|
|
|
2015-09-22 15:54:21 -04:00
|
|
|
static void artist_write(struct file *file, struct db_entry *dbe)
|
2015-10-22 13:19:09 -04:00
|
|
|
{
|
2015-09-22 15:54:21 -04:00
|
|
|
struct artist *artist = (struct artist *)dbe;
|
|
|
|
file_writef(file, "%s", artist->ar_name.c_str());
|
2014-11-08 13:43:23 -05:00
|
|
|
}
|
2014-11-16 10:08:12 -05:00
|
|
|
|
|
|
|
|
2015-11-03 10:39:06 -05:00
|
|
|
static const struct db_ops artist_ops = {
|
2015-11-02 16:59:55 -05:00
|
|
|
artist_alloc,
|
2015-09-30 09:15:15 -04:00
|
|
|
artist_free,
|
2015-09-22 09:24:19 -04:00
|
|
|
artist_read,
|
2015-10-05 20:12:32 -04:00
|
|
|
NULL,
|
2015-09-22 15:54:21 -04:00
|
|
|
artist_write,
|
2015-11-03 10:39:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-10-22 13:06:12 -04:00
|
|
|
void artist_db_init()
|
2014-11-16 10:08:12 -05:00
|
|
|
{
|
2015-11-03 10:39:06 -05:00
|
|
|
db_init(&artist_db, "artist.db", true, &artist_ops);
|
2015-09-17 08:12:25 -04:00
|
|
|
db_load(&artist_db);
|
2014-11-16 10:08:12 -05:00
|
|
|
}
|
|
|
|
|
2015-10-22 13:06:12 -04:00
|
|
|
void artist_db_deinit()
|
|
|
|
{
|
|
|
|
db_deinit(&artist_db);
|
|
|
|
}
|
|
|
|
|
2015-10-22 12:05:28 -04:00
|
|
|
struct artist *artist_find(const std::string &name)
|
2014-11-16 10:08:12 -05:00
|
|
|
{
|
2015-10-20 10:10:26 -04:00
|
|
|
return db_find(&artist_db, name.c_str());
|
2014-11-16 10:08:12 -05:00
|
|
|
}
|
|
|
|
|
2015-10-22 12:01:25 -04:00
|
|
|
struct artist *artist_get(const unsigned int index)
|
2014-11-16 10:08:12 -05:00
|
|
|
{
|
2015-10-20 08:19:47 -04:00
|
|
|
return db_at(&artist_db, index);
|
2014-11-16 10:08:12 -05:00
|
|
|
}
|
2015-10-22 13:19:09 -04:00
|
|
|
|
|
|
|
int artist_compare(struct artist *lhs, struct artist *rhs)
|
|
|
|
{
|
|
|
|
return string_compare(lhs->ar_lower.c_str(), rhs->ar_lower.c_str());
|
|
|
|
}
|
2015-11-03 10:39:06 -05:00
|
|
|
|
|
|
|
#ifdef CONFIG_TESTING
|
|
|
|
const struct db_ops *test_artist_ops() { return &artist_ops; }
|
|
|
|
#endif /* CONFIG_TESTING */
|