/** * Copyright 2014 (c) Anna Schumaker. */ extern "C" { #include } #include #include static database album_db; static const std::string make_key(const std::string &name, unsigned int year) { gchar *g_res = g_strdup_printf("%u/%s", year, name.c_str()); std :: string res = g_res; g_free(g_res); return res; } album :: album() : GenericTag(), al_year(0) {} album :: album(const std::string &name, unsigned int year) : GenericTag(name), al_year(year) { } album :: album(const std::string &key) { gchar *name, *lower; sscanf(key.c_str(), "%u/%m[^\n]", &al_year, &name); lower = string_lowercase(name); _name = name; _lower = lower; g_free(name); g_free(lower); } const std::string album :: primary_key() const { return make_key(GenericTag :: primary_key(), al_year); } void album :: read(file &file) { file_readf(&file, "%u", &al_year); GenericTag :: read(file); } void album :: write(file &file) { file_writef(&file, "%u ", al_year); GenericTag :: write(file); } unsigned int album :: year() { return al_year; } void tags :: init_album_db() { db_init(&album_db, "album.db", true); db_load(&album_db); } struct album *album_find(const std::string &name, unsigned int year) { return db_find(&album_db, make_key(name, year).c_str()); } struct album *album_get(const unsigned int index) { return db_at(&album_db, index); }