core/tags/album: Convert Album class to a struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
75d4bd2af3
commit
e6bdf65606
|
@ -8,7 +8,7 @@ extern "C" {
|
|||
#include <glib.h>
|
||||
|
||||
|
||||
static database<Album> album_db;
|
||||
static database<album> album_db;
|
||||
|
||||
static const std::string make_key(const std::string &name, unsigned int year)
|
||||
{
|
||||
|
@ -20,17 +20,17 @@ static const std::string make_key(const std::string &name, unsigned int year)
|
|||
}
|
||||
|
||||
|
||||
Album :: Album() : GenericTag(), _year(0) {}
|
||||
album :: album() : GenericTag(), al_year(0) {}
|
||||
|
||||
Album :: Album(const std::string &name, unsigned int year)
|
||||
: GenericTag(name), _year(year)
|
||||
album :: album(const std::string &name, unsigned int year)
|
||||
: GenericTag(name), al_year(year)
|
||||
{
|
||||
}
|
||||
|
||||
Album :: Album(const std::string &key)
|
||||
album :: album(const std::string &key)
|
||||
{
|
||||
gchar *name, *lower;
|
||||
sscanf(key.c_str(), "%u/%m[^\n]", &_year, &name);
|
||||
sscanf(key.c_str(), "%u/%m[^\n]", &al_year, &name);
|
||||
|
||||
lower = string_lowercase(name);
|
||||
_name = name;
|
||||
|
@ -40,26 +40,26 @@ Album :: Album(const std::string &key)
|
|||
g_free(lower);
|
||||
}
|
||||
|
||||
const std::string Album :: primary_key() const
|
||||
const std::string album :: primary_key() const
|
||||
{
|
||||
return make_key(GenericTag :: primary_key(), _year);
|
||||
return make_key(GenericTag :: primary_key(), al_year);
|
||||
}
|
||||
|
||||
void Album :: read(file &file)
|
||||
void album :: read(file &file)
|
||||
{
|
||||
file_readf(&file, "%u", &_year);
|
||||
file_readf(&file, "%u", &al_year);
|
||||
GenericTag :: read(file);
|
||||
}
|
||||
|
||||
void Album :: write(file &file)
|
||||
void album :: write(file &file)
|
||||
{
|
||||
file_writef(&file, "%u ", _year);
|
||||
file_writef(&file, "%u ", al_year);
|
||||
GenericTag :: write(file);
|
||||
}
|
||||
|
||||
unsigned int Album :: year()
|
||||
unsigned int album :: year()
|
||||
{
|
||||
return _year;
|
||||
return al_year;
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,12 +69,12 @@ void tags :: init_album_db()
|
|||
db_load(&album_db);
|
||||
}
|
||||
|
||||
Album *tags :: get_album(const std::string &name, unsigned int year)
|
||||
struct album *tags :: get_album(const std::string &name, unsigned int year)
|
||||
{
|
||||
return db_find(&album_db, make_key(name, year).c_str());
|
||||
}
|
||||
|
||||
Album *tags ::get_album(const unsigned int index)
|
||||
struct album *tags ::get_album(const unsigned int index)
|
||||
{
|
||||
return db_at(&album_db, index);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ Track :: Track()
|
|||
_count(0), _length(0), _track(0)
|
||||
{}
|
||||
|
||||
Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library,
|
||||
Track :: Track(struct album *album, Artist *artist, Genre *genre, Library *library,
|
||||
const std::string &filepath, const std::string &name,
|
||||
unsigned int length, unsigned int track)
|
||||
: GenericTag(name),
|
||||
|
@ -59,7 +59,7 @@ Track :: ~Track()
|
|||
_library->dec_size();
|
||||
}
|
||||
|
||||
Album *Track :: album() { return _album; }
|
||||
struct album *Track :: album() { return _album; }
|
||||
Artist *Track :: artist() { return _artist; }
|
||||
Genre *Track :: genre() { return _genre; }
|
||||
Library *Track :: library() { return _library; }
|
||||
|
@ -148,7 +148,7 @@ void tags :: init_track_db()
|
|||
db_load(&track_db);
|
||||
}
|
||||
|
||||
Track *tags :: add_track(Album *album, Artist *artist, Genre *genre,
|
||||
Track *tags :: add_track(struct album *album, Artist *artist, Genre *genre,
|
||||
Library *library, const std::string &filepath,
|
||||
const std::string &name, unsigned int length,
|
||||
unsigned int track)
|
||||
|
|
|
@ -17,12 +17,10 @@
|
|||
* ... << year2 << GenericTag::write()
|
||||
* ... << year3 << GenericTag::write()
|
||||
*/
|
||||
class Album : public GenericTag {
|
||||
private:
|
||||
unsigned int _year; /**< The year associated with this Album. */
|
||||
struct album : public GenericTag {
|
||||
unsigned int al_year; /* Ths album's year. */
|
||||
|
||||
public:
|
||||
Album(); /**< Album tag constructor */
|
||||
album(); /**< Album tag constructor */
|
||||
|
||||
/**
|
||||
* Album tag constructor
|
||||
|
@ -30,8 +28,8 @@ public:
|
|||
* @param name Album name
|
||||
* @param year Album year
|
||||
*/
|
||||
Album(const std::string &, unsigned int);
|
||||
Album(const std::string &);
|
||||
album(const std::string &, unsigned int);
|
||||
album(const std::string &);
|
||||
|
||||
/**
|
||||
* The album's primary key is the concatenation of year
|
||||
|
@ -79,7 +77,7 @@ namespace tags
|
|||
* @param year The year of the album.
|
||||
* @return A matching Album tag.
|
||||
*/
|
||||
Album *get_album(const std::string &, unsigned int);
|
||||
struct album *get_album(const std::string &, unsigned int);
|
||||
|
||||
/**
|
||||
* Called to look up an Album tag by tag index.
|
||||
|
@ -87,7 +85,7 @@ namespace tags
|
|||
* @param index The index of the Album tag.
|
||||
* @return A matching Album tag or NULL.
|
||||
*/
|
||||
Album *get_album(const unsigned int);
|
||||
struct album *get_album(const unsigned int);
|
||||
|
||||
} /* Namespace: tags */
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ extern "C" {
|
|||
*/
|
||||
class Track : public GenericTag {
|
||||
private:
|
||||
Album *_album; /**< Pointer to the Album containing this track. */
|
||||
struct album *_album; /**< Pointer to the Album containing this track. */
|
||||
Artist *_artist; /**< Pointer to the Artist performing this track. */
|
||||
Genre *_genre; /**< Pointer to the Genre describing this track. */
|
||||
Library *_library; /**< Pointer to the Library containing this track. */
|
||||
|
@ -45,7 +45,7 @@ public:
|
|||
* @param length The length of this track (in seconds).
|
||||
* @param track The track number of this track.
|
||||
*/
|
||||
Track(Album *, Artist *, Genre *, Library *, const std::string &,
|
||||
Track(struct album *, Artist *, Genre *, Library *, const std::string &,
|
||||
const std::string &, unsigned int, unsigned int);
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
~Track(); /**< Track destructor. */
|
||||
|
||||
|
||||
Album *album(); /**< @return Track::_album. */
|
||||
struct album *album(); /**< @return Track::_album. */
|
||||
Artist *artist(); /**< @return Track::_artist. */
|
||||
Genre *genre(); /**< @return Track::_genre. */
|
||||
Library *library(); /**< @return Track::_library. */
|
||||
|
@ -135,7 +135,7 @@ namespace tags
|
|||
* @return A new Track tag, or NULL if this Track is already in
|
||||
* the track_db.
|
||||
*/
|
||||
Track *add_track(Album *, Artist *, Genre *, Library *,
|
||||
Track *add_track(album *, Artist *, Genre *, Library *,
|
||||
const std::string &, const std::string &,
|
||||
unsigned int, unsigned int);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <core/tags/album.h>
|
||||
#include "../test.h"
|
||||
|
||||
static void test_verify_empty(Album *album)
|
||||
static void test_verify_empty(struct album *album)
|
||||
{
|
||||
test_equal(album->name(), "");
|
||||
test_equal(album->lowercase(), "");
|
||||
|
@ -12,7 +12,7 @@ static void test_verify_empty(Album *album)
|
|||
test_equal(album->primary_key(), "0/");
|
||||
}
|
||||
|
||||
static void test_verify_hyrule(Album *album)
|
||||
static void test_verify_hyrule(struct album *album)
|
||||
{
|
||||
test_equal(album->name(), "Hyrule Symphony");
|
||||
test_equal(album->lowercase(), "hyrule symphony");
|
||||
|
@ -22,7 +22,7 @@ static void test_verify_hyrule(Album *album)
|
|||
|
||||
static void test_album()
|
||||
{
|
||||
Album *album = new Album("Hyrule Symphony", 1998);
|
||||
struct album *album = new struct album("Hyrule Symphony", 1998);
|
||||
file f;
|
||||
|
||||
test_verify_hyrule(album);
|
||||
|
@ -34,7 +34,7 @@ static void test_album()
|
|||
file_close(&f);
|
||||
delete album;
|
||||
|
||||
album = new Album();
|
||||
album = new struct album();
|
||||
test_verify_empty(album);
|
||||
|
||||
file_open(&f, OPEN_READ);
|
||||
|
@ -49,8 +49,8 @@ static void test_album()
|
|||
|
||||
static void test_album_compare()
|
||||
{
|
||||
Album *twilight = new Album("Twilight Princess", 2006);
|
||||
Album *skyward = new Album("skyward sword", 2011);
|
||||
struct album *twilight = new struct album("Twilight Princess", 2006);
|
||||
struct album *skyward = new struct album("skyward sword", 2011);
|
||||
|
||||
test_equal(twilight->compare(twilight), 0);
|
||||
test_equal(twilight->compare(skyward), 1);
|
||||
|
@ -62,8 +62,8 @@ static void test_album_compare()
|
|||
|
||||
static void test_album_db()
|
||||
{
|
||||
database<Album> album_db;
|
||||
Album *album;
|
||||
database<struct album> album_db;
|
||||
struct album *album;
|
||||
|
||||
tags :: init_album_db();
|
||||
album = tags :: get_album("Hyrule Symphony", 1998);
|
||||
|
@ -72,7 +72,7 @@ static void test_album_db()
|
|||
|
||||
test_equal(tags :: get_album("Hyrule Symphony", 1998), album);
|
||||
test_equal(tags :: get_album(0), album);
|
||||
test_equal(tags :: get_album(1), (Album *)NULL);
|
||||
test_equal(tags :: get_album(1), (struct album *)NULL);
|
||||
|
||||
db_init(&album_db, "album.db", false);
|
||||
db_load(&album_db);
|
||||
|
|
|
@ -14,7 +14,7 @@ extern "C" {
|
|||
|
||||
|
||||
static Artist *artist = NULL;
|
||||
static Album *album = NULL;
|
||||
static struct album *album = NULL;
|
||||
static Genre *genre = NULL;
|
||||
static Library *library = NULL;
|
||||
const std::string MUSIC_DIR = "/home/Zelda/Music";
|
||||
|
@ -24,7 +24,7 @@ static void test_track_tag_default()
|
|||
{
|
||||
Track track;
|
||||
|
||||
test_equal(track.album(), (Album *)NULL);
|
||||
test_equal(track.album(), (struct album *)NULL);
|
||||
test_equal(track.artist(), (Artist *)NULL);
|
||||
test_equal(track.genre(), (Genre *)NULL);
|
||||
test_equal(track.library(), (Library *)NULL);
|
||||
|
|
Loading…
Reference in New Issue