/** * Copyright 2014 (c) Anna Schumaker. */ extern "C" { #include } #include static struct database artist_db; 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->ar_dbe; } static void artist_free(struct db_entry *dbe) { delete ARTIST(dbe); } static gchar *artist_key(struct db_entry *dbe) { return g_strdup(ARTIST(dbe)->ar_name.c_str()); } struct db_entry *artist_read(struct file *file) { gchar *name = file_readl(file); struct db_entry *dbe = artist_alloc(name); g_free(name); return dbe; } static void artist_write(struct file *file, struct db_entry *dbe) { file_writef(file, "%s", ARTIST(dbe)->ar_name.c_str()); } static const struct db_ops artist_ops = { artist_alloc, artist_free, artist_key, artist_read, NULL, artist_write, }; void artist_db_init() { db_init(&artist_db, "artist.db", true, &artist_ops); db_load(&artist_db); } void artist_db_deinit() { db_deinit(&artist_db); } struct artist *artist_find(const std::string &name) { return ARTIST(db_find(&artist_db, name.c_str())); } struct artist *artist_get(const unsigned int index) { return ARTIST(db_at(&artist_db, index)); } int artist_compare(struct artist *lhs, struct artist *rhs) { return string_compare(lhs->ar_lower.c_str(), rhs->ar_lower.c_str()); } #ifdef CONFIG_TESTING const struct db_ops *test_artist_ops() { return &artist_ops; } #endif /* CONFIG_TESTING */