ocarina/core/tags/album.cpp

63 lines
1.1 KiB
C++

/**
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/string.h>
#include <core/tags/album.h>
static Database<Album> album_db("album.db", true);
static const std::string make_key(const std::string &name, unsigned int year)
{
return string :: utos(year) + "/" + name;
}
Album :: Album() : GenericTag(), _year(0) {}
Album :: Album(const std::string &name, unsigned int year)
: GenericTag(name), _year(year)
{
}
const std::string Album :: primary_key() const
{
return make_key(GenericTag :: primary_key(), _year);
}
void Album :: read(File &file)
{
file >> _year;
GenericTag :: read(file);
}
void Album :: write(File &file)
{
file << _year << " ";
GenericTag :: write(file);
}
unsigned int Album :: year()
{
return _year;
}
void tags :: init_album_db()
{
album_db.load();
}
Album *tags :: get_album(const std::string &name, unsigned int year)
{
Album *ret = album_db.find(make_key(name, year));
if (ret)
return ret;
return album_db.insert(Album(name, year));
}
Album *tags ::get_album(const unsigned int index)
{
return album_db.at(index);
}